mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
GCS: Trying to tidy up splitter code some :)
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1756 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
a01783b2a8
commit
cb9fdc8df6
@ -29,29 +29,11 @@
|
||||
#include "splitterorview.h"
|
||||
#include "uavgadgetview.h"
|
||||
#include "uavgadgetmanager.h"
|
||||
#include "uavgadgetinstancemanager.h"
|
||||
#include "iuavgadget.h"
|
||||
#include "coreimpl.h"
|
||||
#include "minisplitter.h"
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/styledbar.h>
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QComboBox>
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QLabel>
|
||||
#include <QtGui/QMouseEvent>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QStyle>
|
||||
#include <QtGui/QStyleOption>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QClipboard>
|
||||
|
||||
#ifdef Q_WS_MAC
|
||||
#include <qmacstyle_mac.h>
|
||||
@ -60,9 +42,8 @@
|
||||
using namespace Core;
|
||||
using namespace Core::Internal;
|
||||
|
||||
SplitterOrView::SplitterOrView(Core::UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget, bool isRoot) :
|
||||
SplitterOrView::SplitterOrView(Core::UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget) :
|
||||
m_uavGadgetManager(uavGadgetManager),
|
||||
m_isRoot(isRoot),
|
||||
m_splitter(0)
|
||||
{
|
||||
m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget, this);
|
||||
@ -306,28 +287,27 @@ QList<IUAVGadget*> SplitterOrView::gadgets()
|
||||
|
||||
void SplitterOrView::split(Qt::Orientation orientation)
|
||||
{
|
||||
Q_ASSERT(m_view && (m_splitter == 0));
|
||||
Q_ASSERT(m_view);
|
||||
Q_ASSERT(!m_splitter);
|
||||
m_splitter = new MiniSplitter(this);
|
||||
m_splitter->setOrientation(orientation);
|
||||
connect(m_splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(onSplitterMoved(int,int)));
|
||||
m_layout->addWidget(m_splitter);
|
||||
Core::IUAVGadget *ourGadget = m_view->gadget();
|
||||
|
||||
SplitterOrView *view = 0;
|
||||
SplitterOrView *otherView = 0;
|
||||
if (ourGadget) {
|
||||
// Give our gadget to the new left or top SplitterOrView.
|
||||
m_view->removeGadget();
|
||||
m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager, ourGadget)));
|
||||
m_splitter->addWidget((otherView = new SplitterOrView(m_uavGadgetManager)));
|
||||
m_splitter->addWidget(new SplitterOrView(m_uavGadgetManager, ourGadget));
|
||||
m_splitter->addWidget(new SplitterOrView(m_uavGadgetManager));
|
||||
} else {
|
||||
m_splitter->addWidget((otherView = new SplitterOrView(m_uavGadgetManager)));
|
||||
m_splitter->addWidget((view = new SplitterOrView(m_uavGadgetManager)));
|
||||
m_splitter->addWidget(new SplitterOrView(m_uavGadgetManager));
|
||||
m_splitter->addWidget(new SplitterOrView(m_uavGadgetManager));
|
||||
}
|
||||
|
||||
m_layout->setCurrentWidget(m_splitter);
|
||||
|
||||
if (m_view && !m_isRoot) {
|
||||
if (m_view) {
|
||||
m_uavGadgetManager->emptyView(m_view);
|
||||
delete m_view;
|
||||
m_view = 0;
|
||||
@ -341,20 +321,25 @@ void SplitterOrView::onSplitterMoved( int pos, int index ) {
|
||||
m_sizes = m_splitter->sizes();
|
||||
}
|
||||
|
||||
void SplitterOrView::unsplitAll()
|
||||
void SplitterOrView::unsplitAll(IUAVGadget *currentGadget)
|
||||
{
|
||||
Q_ASSERT(m_splitter);
|
||||
Q_ASSERT(!m_view);
|
||||
m_splitter->hide();
|
||||
m_layout->removeWidget(m_splitter); // workaround Qt bug
|
||||
unsplitAll_helper();
|
||||
delete m_splitter;
|
||||
m_splitter = 0;
|
||||
|
||||
m_view = new UAVGadgetView(m_uavGadgetManager, currentGadget, this);
|
||||
m_layout->addWidget(m_view);
|
||||
}
|
||||
|
||||
void SplitterOrView::unsplitAll_helper()
|
||||
{
|
||||
if (!m_isRoot && m_view)
|
||||
if (m_view) {
|
||||
m_uavGadgetManager->emptyView(m_view);
|
||||
}
|
||||
if (m_splitter) {
|
||||
for (int i = 0; i < m_splitter->count(); ++i) {
|
||||
if (SplitterOrView *splitterOrView = qobject_cast<SplitterOrView*>(m_splitter->widget(i))) {
|
||||
|
@ -42,14 +42,13 @@ class SplitterOrView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget = 0, bool root = false);
|
||||
SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget = 0);
|
||||
~SplitterOrView();
|
||||
|
||||
void split(Qt::Orientation orientation);
|
||||
void unsplit();
|
||||
|
||||
inline bool isView() const { return m_view != 0; }
|
||||
inline bool isRoot() const { return m_isRoot; }
|
||||
|
||||
inline bool isSplitter() const { return m_splitter != 0; }
|
||||
inline Core::IUAVGadget *gadget() const { return m_view ? m_view->gadget() : 0; }
|
||||
@ -76,23 +75,33 @@ public:
|
||||
QSize sizeHint() const { return minimumSizeHint(); }
|
||||
QSize minimumSizeHint() const;
|
||||
|
||||
void unsplitAll();
|
||||
void unsplitAll(IUAVGadget *currentGadget);
|
||||
|
||||
protected:
|
||||
// void paintEvent(QPaintEvent *);
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
|
||||
private slots:
|
||||
// Called when the user moves the splitter, and updates our m_sizes.
|
||||
void onSplitterMoved( int pos, int index );
|
||||
|
||||
private:
|
||||
void unsplitAll_helper();
|
||||
SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
|
||||
UAVGadgetManager *m_uavGadgetManager;
|
||||
bool m_isRoot;
|
||||
QStackedLayout *m_layout;
|
||||
UAVGadgetView *m_view;
|
||||
QSplitter *m_splitter;
|
||||
|
||||
// The gadget manager that controls us.
|
||||
QPointer<UAVGadgetManager> m_uavGadgetManager;
|
||||
|
||||
// Our layout, we use stacked so we can change stuff without visual artifacts (I think...)
|
||||
QPointer<QStackedLayout> m_layout;
|
||||
|
||||
// Our view, if we are a view (showing 1 gadget) and not a splitter.
|
||||
QPointer<UAVGadgetView> m_view;
|
||||
|
||||
// Out splitter, if we are a splitter.
|
||||
QPointer<QSplitter> m_splitter;
|
||||
|
||||
// The splitter sizes. We keep our own copy of these, since after loading they can't realiably be retrieved.
|
||||
QList<int> m_sizes;
|
||||
};
|
||||
|
||||
|
@ -266,7 +266,7 @@ UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) :
|
||||
connect(m_d->m_gotoOtherSplitAction, SIGNAL(triggered()), this, SLOT(gotoOtherSplit()));
|
||||
|
||||
// other setup
|
||||
m_d->m_splitterOrView = new SplitterOrView(this, 0, true);
|
||||
m_d->m_splitterOrView = new SplitterOrView(this, 0);
|
||||
// SplitterOrView with 0 as gadget calls our setCurrentGadget, which relies on currentSplitterOrView(),
|
||||
// which needs our m_splitterorView to be set, which isn't set yet at that time.
|
||||
// So directly set our currentGadget to 0, and do it again.
|
||||
@ -604,6 +604,7 @@ void UAVGadgetManager::removeCurrentSplit()
|
||||
closeView(viewToClose->view());
|
||||
}
|
||||
|
||||
// Removes all gadgets and splits in the workspace, except the current/active gadget.
|
||||
void UAVGadgetManager::removeAllSplits()
|
||||
{
|
||||
if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode)
|
||||
@ -611,14 +612,23 @@ void UAVGadgetManager::removeAllSplits()
|
||||
|
||||
if (!m_d->m_splitterOrView->isSplitter())
|
||||
return;
|
||||
IUAVGadget *uavGadget = m_d->m_currentGadget;
|
||||
QList<IUAVGadget*> gadgets = m_d->m_splitterOrView->gadgets();
|
||||
gadgets.removeOne(uavGadget);
|
||||
|
||||
m_d->m_currentGadget = 0; // trigger update below
|
||||
m_d->m_splitterOrView->unsplitAll();
|
||||
m_d->m_splitterOrView->view()->setGadget(uavGadget);
|
||||
setCurrentGadget(uavGadget);
|
||||
// Use a QPointer, just in case we accidently delete the gadget we want to keep.
|
||||
QPointer<IUAVGadget> currentGadget = m_d->m_currentGadget;
|
||||
|
||||
Q_ASSERT(currentGadget);
|
||||
QList<IUAVGadget*> gadgets = m_d->m_splitterOrView->gadgets();
|
||||
Q_ASSERT(gadgets.count(currentGadget) == 1);
|
||||
gadgets.removeOne(currentGadget);
|
||||
|
||||
// Remove all splits and their gadgets, then create a new view with the current gadget.
|
||||
m_d->m_splitterOrView->unsplitAll(currentGadget);
|
||||
|
||||
// Zeroing the current gadget means setCurrentGadget will do something when we call it.
|
||||
m_d->m_currentGadget = 0;
|
||||
setCurrentGadget(currentGadget);
|
||||
|
||||
// Remove all other gadgets from the instance manager.
|
||||
UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager();
|
||||
foreach (IUAVGadget *g, gadgets) {
|
||||
im->removeGadget(g);
|
||||
|
@ -84,8 +84,8 @@ private slots:
|
||||
private:
|
||||
void updateToolBar();
|
||||
|
||||
UAVGadgetManager *m_uavGadgetManager;
|
||||
IUAVGadget *m_uavGadget;
|
||||
QPointer<UAVGadgetManager> m_uavGadgetManager;
|
||||
QPointer<IUAVGadget> m_uavGadget;
|
||||
QWidget *m_toolBar;
|
||||
QComboBox *m_defaultToolBar;
|
||||
QWidget *m_currentToolBar;
|
||||
|
Loading…
x
Reference in New Issue
Block a user