36 #include <QtCore/QDebug>
39 using namespace Core::Internal;
43 : m_uavGadgetManager(uavGadgetManager)
46 m_view =
new UAVGadgetView(m_uavGadgetManager, uavGadget,
this, restoring);
47 m_layout =
new QStackedLayout(
this);
48 m_layout->addWidget(m_view);
65 if (e->button() != Qt::LeftButton)
68 setFocus(Qt::MouseFocusReason);
69 m_uavGadgetManager->setCurrentGadget(this->
gadget());
79 for (
int i = 0;
i < m_splitter->count(); ++
i) {
81 qobject_cast<SplitterOrView *>(m_splitter->widget(
i)))
98 for (
int i = 0;
i < m_splitter->count(); ++
i) {
100 qobject_cast<SplitterOrView *>(m_splitter->widget(
i)))
116 for (
int i = 0;
i < m_splitter->count(); ++
i) {
118 qobject_cast<SplitterOrView *>(m_splitter->widget(
i)))
134 for (
int i = 0;
i < m_splitter->count(); ++
i) {
136 qobject_cast<SplitterOrView *>(m_splitter->widget(
i))) {
137 if (splitterOrView->hasGadget(uavGadget))
154 for (
int i = 0;
i < m_splitter->count(); ++
i) {
156 qobject_cast<SplitterOrView *>(m_splitter->widget(
i))) {
157 if (splitterOrView == child)
174 return findNextView_helper(view, &found);
179 if (*found && m_view) {
189 for (
int i = 0;
i < m_splitter->count(); ++
i) {
191 qobject_cast<SplitterOrView *>(m_splitter->widget(
i))) {
192 if (
SplitterOrView *result = splitterOrView->findNextView_helper(view, found))
203 return m_splitter->minimumSizeHint();
204 return QSize(64, 64);
209 QSplitter *oldSplitter = m_splitter;
211 m_layout->removeWidget(m_splitter);
212 m_splitter =
nullptr;
220 m_layout->removeWidget(m_view);
231 for (
int i = 0;
i < m_splitter->count(); ++
i) {
233 qobject_cast<SplitterOrView *>(m_splitter->widget(
i))) {
245 Q_ASSERT(!m_splitter);
247 m_splitter->setOrientation(orientation);
248 connect(m_splitter, SIGNAL(splitterMoved(
int,
int)),
this, SLOT(onSplitterMoved(
int,
int)));
249 m_layout->addWidget(m_splitter);
254 m_view->removeGadget();
255 m_splitter->addWidget(
new SplitterOrView(m_uavGadgetManager, ourGadget));
256 m_splitter->addWidget(
new SplitterOrView(m_uavGadgetManager,
nullptr, restoring));
258 m_splitter->addWidget(
new SplitterOrView(m_uavGadgetManager,
nullptr, restoring));
259 m_splitter->addWidget(
new SplitterOrView(m_uavGadgetManager,
nullptr, restoring));
262 m_layout->setCurrentWidget(m_splitter);
265 m_uavGadgetManager->emptyView(m_view);
271 void SplitterOrView::onSplitterMoved(
int pos,
int index)
276 m_sizes = m_splitter->sizes();
281 Q_ASSERT(m_splitter);
284 m_layout->removeWidget(m_splitter);
287 m_splitter =
nullptr;
289 m_view =
new UAVGadgetView(m_uavGadgetManager, currentGadget,
this);
290 m_layout->addWidget(m_view);
293 void SplitterOrView::unsplitAll_helper()
296 m_uavGadgetManager->emptyView(m_view);
299 for (
int i = 0;
i < m_splitter->count(); ++
i) {
301 qobject_cast<SplitterOrView *>(m_splitter->widget(
i))) {
302 splitterOrView->unsplitAll_helper();
312 Q_ASSERT(m_splitter->count() == 1);
314 QSplitter *oldSplitter = m_splitter;
315 m_splitter =
nullptr;
317 if (childSplitterOrView->isSplitter()) {
318 Q_ASSERT(childSplitterOrView->view() ==
nullptr);
319 m_splitter = childSplitterOrView->takeSplitter();
320 m_layout->addWidget(m_splitter);
321 m_layout->setCurrentWidget(m_splitter);
328 m_view->setGadget(
e);
330 m_uavGadgetManager->emptyView(childView);
332 m_view = childSplitterOrView->takeView();
333 m_layout->addWidget(m_view);
335 m_layout->setCurrentWidget(m_view);
344 qSettings->setValue(
"type",
"splitter");
345 qSettings->setValue(
"splitterOrientation", (qint32)m_splitter->orientation());
347 foreach (
int value, m_sizes) {
348 sizesQVariant.append(value);
350 qSettings->setValue(
"splitterSizes", sizesQVariant);
351 qSettings->beginGroup(
"side0");
353 qSettings->endGroup();
354 qSettings->beginGroup(
"side1");
356 qSettings->endGroup();
358 qSettings->setValue(
"type",
"uavGadget");
359 qSettings->setValue(
"classId",
gadget()->classId());
360 qSettings->beginGroup(
"gadget");
362 qSettings->endGroup();
368 QString mode = qSettings->value(
"type").toString();
369 if (mode ==
"splitter") {
370 qint32 orientation = qSettings->value(
"splitterOrientation").toInt();
371 QList<QVariant> sizesQVariant = qSettings->value(
"splitterSizes").toList();
373 foreach (QVariant value, sizesQVariant) {
374 m_sizes.append(value.toInt());
376 split((Qt::Orientation)orientation,
true);
377 m_splitter->setSizes(m_sizes);
378 qSettings->beginGroup(
"side0");
380 qSettings->endGroup();
381 qSettings->beginGroup(
"side1");
383 qSettings->endGroup();
384 }
else if (mode ==
"uavGadget") {
385 QString classId = qSettings->value(
"classId").toString();
386 int index = m_view->indexOfClassId(classId);
387 m_view->selectionActivated(index,
false);
388 if (qSettings->childGroups().contains(
"gadget")) {
389 qSettings->beginGroup(
"gadget");
391 qSettings->endGroup();
void split(Qt::Orientation orientation, bool restoring=false)
QSize minimumSizeHint() const
UAVGadgetView * takeView()
QList< Core::IUAVGadget * > gadgets()
QSplitter * takeSplitter()
SplitterOrView * findSplitter(Core::IUAVGadget *uavGadget)
SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget=nullptr, bool restoring=false)
void saveState(QSettings *) const
Core::IUAVGadget * gadget() const
void unsplitAll(IUAVGadget *currentGadget)
IUAVGadget * gadget() const
virtual void restoreState(QByteArray)
virtual void saveState(QSettings *)
SplitterOrView * findView(Core::IUAVGadget *uavGadget)
void restoreState(QSettings *)
SplitterOrView * findNextView(SplitterOrView *view)
void mousePressEvent(QMouseEvent *e)
SplitterOrView * findFirstView()