42 #include <QtCore/QDebug>
44 #include <QApplication>
46 #include <QHBoxLayout>
48 #include <QMouseEvent>
51 #include <QStyleOption>
52 #include <QToolButton>
60 using namespace Core::Internal;
63 QWidget *parent,
bool restoring)
65 , m_uavGadgetManager(uavGadgetManager)
66 , m_uavGadget(uavGadget)
67 , m_toolBar(new QWidget(this))
68 , m_defaultToolBar(new QComboBox(this))
69 , m_uavGadgetList(new QComboBox(this))
70 , m_closeButton(new QToolButton(this))
72 , m_activeLabel(new QLabel)
75 tl =
new QVBoxLayout(
this);
80 m_uavGadgetList->setView(
new QListView(m_uavGadgetList));
82 m_uavGadgetList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
83 m_uavGadgetList->setMinimumContentsLength(15);
84 m_uavGadgetList->setMaxVisibleItems(40);
85 m_uavGadgetList->setContextMenuPolicy(Qt::CustomContextMenu);
89 bool startFromOne =
false;
90 foreach (QString classId, sl) {
91 if (classId == QString(
"EmptyGadget")) {
94 m_uavGadgetList->insertItem(0, im->
gadgetName(classId), classId);
95 m_uavGadgetList->setItemIcon(0, im->
gadgetIcon(classId));
96 m_uavGadgetList->insertSeparator(1);
99 int i = startFromOne ? 1 : 0;
100 for (; i < m_uavGadgetList->count(); i++) {
101 if (QString::localeAwareCompare(m_uavGadgetList->itemText(i),
106 m_uavGadgetList->insertItem(i, im->
gadgetName(classId), classId);
107 m_uavGadgetList->setItemIcon(i, im->
gadgetIcon(classId));
112 m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding,
113 QSizePolicy::MinimumExpanding);
114 m_activeToolBar = m_defaultToolBar;
116 QHBoxLayout *toolBarLayout =
new QHBoxLayout(m_toolBar);
117 toolBarLayout->setMargin(0);
118 toolBarLayout->setSpacing(0);
119 toolBarLayout->addWidget(m_defaultToolBar);
121 m_toolBar->setLayout(toolBarLayout);
122 m_toolBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding);
124 QWidget *spacerWidget =
new QWidget(
this);
125 spacerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
127 m_activeLabel->setTextFormat(Qt::RichText);
128 m_activeLabel->setText(
"<font color=#c0392b><b>" + tr(
"Active") +
"</b></font>");
130 m_closeButton->setAutoRaise(
true);
131 m_closeButton->setIcon(QIcon(
":/core/images/closebutton.png"));
134 m_top->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
136 QHBoxLayout *toplayout =
new QHBoxLayout(m_top);
137 toplayout->setSpacing(0);
138 toplayout->setMargin(0);
139 toplayout->addWidget(m_uavGadgetList);
140 toplayout->addWidget(m_toolBar);
141 toplayout->addWidget(spacerWidget);
142 toplayout->addWidget(m_activeLabel);
143 toplayout->addWidget(m_closeButton);
145 m_top->setLayout(toplayout);
146 tl->addWidget(m_top);
148 connect(m_uavGadgetList, SIGNAL(activated(
int)),
this, SLOT(
doReplaceGadget(
int)));
149 connect(m_closeButton, SIGNAL(clicked()),
this, SLOT(
closeView()), Qt::QueuedConnection);
150 connect(m_uavGadgetManager, SIGNAL(currentGadgetChanged(
IUAVGadget *)),
this,
169 return (m_uavGadget == uavGadget);
174 m_top->setHidden(!show);
179 m_uavGadgetManager->closeView(
this);
186 tl->removeWidget(m_uavGadget->widget());
188 m_uavGadget->setParent(
nullptr);
189 m_uavGadget->widget()->setParent(
nullptr);
190 QWidget *toolBar = m_uavGadget->toolBar();
191 if (toolBar !=
nullptr) {
192 if (m_activeToolBar == toolBar) {
193 m_activeToolBar = m_defaultToolBar;
194 m_activeToolBar->setVisible(
true);
196 m_toolBar->layout()->removeWidget(toolBar);
197 toolBar->setParent(
nullptr);
199 m_uavGadget =
nullptr;
213 m_uavGadget = uavGadget;
214 tl->addWidget(m_uavGadget->widget());
215 m_uavGadget->widget()->setParent(
this);
216 m_uavGadget->widget()->show();
218 Q_ASSERT(index >= 0);
219 m_uavGadgetList->setCurrentIndex(index);
224 void UAVGadgetView::updateToolBar()
228 QComboBox *toolBar = m_uavGadget->toolBar();
230 toolBar = m_defaultToolBar;
231 if (m_activeToolBar == toolBar)
233 if (toolBar->count() == 0)
237 toolBar->setView(
new QListView(toolBar));
239 m_toolBar->layout()->addWidget(toolBar);
240 m_activeToolBar->setVisible(
false);
241 m_activeToolBar = toolBar;
255 index = m_defaultIndex;
256 QString classId = m_uavGadgetList->itemData(index).toString();
257 if (m_uavGadget && (m_uavGadget->classId() == classId))
264 m_uavGadgetManager->setCurrentGadget(gadget);
279 return m_uavGadgetList->findData(classId);
284 m_activeLabel->setVisible(m_uavGadget == gadget);
void doReplaceGadget(int index)
Slot called when the user changes the selected gadget on the view's dropbox.
void showToolbar(bool show)
QIcon gadgetIcon(QString classId) const
int indexOfClassId(QString classId)
IUAVGadget * gadget() const
IUAVGadget * createGadget(QString classId, QWidget *parent, bool forceLoadConfiguration=false)
bool hasGadget(IUAVGadget *uavGadget) const
static ICore * instance()
void setGadget(IUAVGadget *uavGadget)
Q_DECLARE_METATYPE(Core::Internal::MenuActionContainer *) using namespace Core
void removeGadget(IUAVGadget *gadget)
QStringList classIds() const
QString gadgetName(QString classId) const
void selectionActivated(int index, bool forceLoadConfiguration)
Function used to select the gadget to show on this view.
virtual UAVGadgetInstanceManager * uavGadgetInstanceManager() const =0