52 #include <QtCore/QDebug>
53 #include <QtCore/QMap>
54 #include <QtCore/QProcess>
55 #include <QtCore/QSet>
58 #include <QApplication>
60 #include <QMainWindow>
62 #include <QPushButton>
64 #include <QStackedLayout>
69 using namespace Core::Internal;
70 using namespace Utils;
74 UAVGadgetManager::UAVGadgetManager(
ICore *core, QString name, QIcon icon,
int priority,
75 QString uniqueName, QWidget *parent)
76 : m_showToolbars(true)
77 , m_splitterOrView(nullptr)
78 , m_currentGadget(nullptr)
82 , m_priority(priority)
83 , m_widget(new QWidget(parent))
89 if (!modeManager->
mode(uniqueName)) {
90 m_uniqueName = uniqueName;
93 m_uniqueName = uniqueName + QString::number(quint64(
this));
95 m_uniqueNameBA = m_uniqueName.toLatin1();
96 m_uniqueModeName = m_uniqueNameBA.data();
98 connect(m_core, SIGNAL(contextAboutToChange(
Core::IContext *)),
this,
101 connect(modeManager, SIGNAL(currentModeChanged(
Core::IMode *)),
this,
111 m_currentGadget =
nullptr;
112 setCurrentGadget(m_splitterOrView->
view()->
gadget());
114 QHBoxLayout *layout =
new QHBoxLayout(m_widget);
115 layout->setMargin(0);
116 layout->setSpacing(0);
117 layout->addWidget(m_splitterOrView);
133 void UAVGadgetManager::modeChanged(
Core::IMode *mode)
138 if (!m_currentGadget) {
142 m_currentGadget->
widget()->setFocus();
152 void UAVGadgetManager::handleContextChange(
Core::IContext *context)
158 setCurrentGadget(uavGadget);
161 void UAVGadgetManager::setCurrentGadget(IUAVGadget *uavGadget)
163 if (m_currentGadget == uavGadget)
167 m_currentGadget = uavGadget;
169 if (oldView != view) {
175 uavGadget->widget()->setFocus();
184 if (!m_splitterOrView)
192 return m_currentGadget;
202 removeGadget(uavGadget);
212 Q_ASSERT(splitterOrView);
213 Q_ASSERT(splitterOrView->
view() == view);
214 if (splitterOrView == m_splitterOrView)
217 IUAVGadget *gadget = view->
gadget();
223 Q_ASSERT(splitterOrView->
hasGadget() ==
false);
225 splitterOrView->hide();
226 delete splitterOrView;
231 Q_ASSERT(newCurrent);
233 setCurrentGadget(newCurrent->
gadget());
236 void UAVGadgetManager::addGadgetToContext(IUAVGadget *gadget)
245 void UAVGadgetManager::removeGadget(IUAVGadget *gadget)
254 if (!m_widget->isVisible())
263 m_showToolbars = show;
270 updateUavGadgetMenus();
273 void UAVGadgetManager::updateUavGadgetMenus()
277 if (!m_splitterOrView)
280 bool hasSplitter = m_splitterOrView->
isSplitter();
286 qSettings->setValue(
"version",
"UAVGadgetManagerV1");
287 qSettings->setValue(
"showToolbars", m_showToolbars);
288 qSettings->beginGroup(
"splitter");
290 qSettings->endGroup();
299 emptyView(m_splitterOrView->
view());
302 QString version = qSettings->value(
"version").toString();
303 if (version !=
"UAVGadgetManagerV1") {
307 m_showToolbars = qSettings->value(
"showToolbars").toBool();
309 QApplication::setOverrideCursor(Qt::WaitCursor);
311 qSettings->beginGroup(
"splitter");
313 qSettings->endGroup();
315 QApplication::restoreOverrideCursor();
321 qs->beginGroup(
"UAVGadgetManager");
336 QString uavGadgetManagerRootKey =
"UAVGadgetManager";
337 if (!qs->childGroups().contains(uavGadgetManagerRootKey)) {
340 qs->beginGroup(uavGadgetManagerRootKey);
365 view->
split(orientation);
369 setCurrentGadget(next->
gadget());
370 updateUavGadgetMenus();
380 split(Qt::Horizontal);
389 if (viewToClose == m_splitterOrView)
391 closeView(viewToClose->
view());
392 updateUavGadgetMenus();
407 Q_ASSERT(currentGadget);
409 Q_ASSERT(gadgets.count(currentGadget) == 1);
410 gadgets.removeOne(currentGadget);
416 m_currentGadget =
nullptr;
417 setCurrentGadget(currentGadget);
424 updateUavGadgetMenus();
438 setCurrentGadget(view->
gadget());
QList< int > context() const
static UniqueIDManager * instance()
IUAVGadget * currentGadget() const
virtual void addContextObject(IContext *context)=0
Registers an additional context object.
void split(Qt::Orientation orientation, bool restoring=false)
int uniqueIdentifier(const QString &id)
void removeCurrentSplit()
QList< Core::IUAVGadget * > gadgets()
static ModeManager * instance()
void doReplaceGadget(int index)
Slot called when the user changes the selected gadget on the view's dropbox.
void showToolbar(bool show)
SplitterOrView * findSplitter(Core::IUAVGadget *uavGadget)
void saveState(QSettings *) const
Core::IUAVGadget * gadget() const
UAVGadgetView * view() const
The ICore class allows access to the different part that make up the basic functionality of the GCS...
void unsplitAll(IUAVGadget *currentGadget)
IUAVGadget * gadget() const
virtual QWidget * widget()=0
void readSettings(QSettings *qs)
IMode * mode(const QString &id) const
IMode * currentMode() const
bool hasGadget(Core::IUAVGadget *uavGadget) const
void showUavGadgetMenus(bool show, bool hasSplitter)
void ensureUAVGadgetManagerVisible()
void saveSettings(QSettings *qs)
void saveState(QSettings *) const
static ICore * instance()
virtual ~UAVGadgetManager()
void showToolbars(bool show)
SplitterOrView * findView(Core::IUAVGadget *uavGadget)
virtual void removeContextObject(IContext *context)=0
Unregisters a context object from the list of know contexts.
void restoreState(QSettings *)
const char * uniqueModeName() const
const char *const C_UAVGADGETMANAGER
SplitterOrView * findNextView(SplitterOrView *view)
Q_DECLARE_METATYPE(Core::IUAVGadget *) using namespace Core
void removeGadget(IUAVGadget *gadget)
virtual ModeManager * modeManager() const =0
Returns the application's mode manager.
void currentGadgetChanged(IUAVGadget *gadget)
virtual UniqueIDManager * uniqueIDManager() const =0
Returns the application's id manager.
void activateMode(const QString &id)
SplitterOrView * findFirstView()
virtual UAVGadgetInstanceManager * uavGadgetInstanceManager() const =0
bool restoreState(QSettings *qSettings)