Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / plugins / coreplugin / uavgadgetmanager / splitterorview.h
blob1e4aa724ff0d0490b65498c95a11dc4c21b36bbc
1 /**
2 ******************************************************************************
4 * @file splitterorview.h
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @addtogroup GCSPlugins GCS Plugins
8 * @{
9 * @addtogroup CorePlugin Core Plugin
10 * @{
11 * @brief The Core GCS plugin
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #ifndef SPLITTERORVIEW_H
30 #define SPLITTERORVIEW_H
32 #include "uavgadgetmanager.h"
33 #include "uavgadgetview.h"
35 #include <QWidget>
36 #include <QMouseEvent>
37 #include <QSplitter>
39 class QSettings;
41 namespace Core {
42 namespace Internal {
43 class SplitterOrView : public QWidget {
44 Q_OBJECT
45 public:
46 SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget = 0);
47 ~SplitterOrView();
49 void split(Qt::Orientation orientation);
51 void unsplit(IUAVGadget *gadget);
53 // un-split all and keep only the specified gadget
54 void unsplitAll(IUAVGadget *gadget);
56 inline bool isView() const
58 return m_view != 0;
61 inline bool isSplitter() const
63 return m_splitter != 0;
65 inline Core::IUAVGadget *gadget() const
67 return m_view ? m_view->gadget() : 0;
69 inline bool hasGadget(Core::IUAVGadget *uavGadget) const
71 return m_view && m_view->hasGadget(uavGadget);
73 inline bool hasGadget() const
75 return m_view && (m_view->gadget() != 0);
77 inline UAVGadgetView *view() const
79 return m_view;
81 inline QSplitter *splitter() const
83 return m_splitter;
85 QList<Core::IUAVGadget *> gadgets();
86 QSplitter *takeSplitter();
87 UAVGadgetView *takeView();
89 void saveState(QSettings &) const;
90 void restoreState(QSettings &);
92 SplitterOrView *findView(Core::IUAVGadget *uavGadget);
93 SplitterOrView *findView(UAVGadgetView *view);
94 SplitterOrView *findFirstView();
95 SplitterOrView *findSplitter(Core::IUAVGadget *uavGadget);
96 SplitterOrView *findSplitter(SplitterOrView *child);
98 SplitterOrView *findNextView(SplitterOrView *view);
100 QSize sizeHint() const
102 return minimumSizeHint();
104 QSize minimumSizeHint() const;
106 protected:
107 void mousePressEvent(QMouseEvent *e);
109 private slots:
110 // Called when the user moves the splitter, and updates our m_sizes.
111 void onSplitterMoved(int pos, int index);
113 private:
114 // private "copy" constructor
115 SplitterOrView(SplitterOrView &splitterOrView, QWidget *parent);
117 static void unsplitAll_helper(UAVGadgetManager *uavGadgetManager, QSplitter *splitter);
118 SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
120 // The gadget manager that controls us.
121 QPointer<UAVGadgetManager> m_uavGadgetManager;
123 // Our view, if we are a view (showing 1 gadget) and not a splitter.
124 QPointer<UAVGadgetView> m_view;
126 // Our splitter, if we are a splitter.
127 QPointer<QSplitter> m_splitter;
129 // The splitter sizes. We keep our own copy of these, since after loading they can't realiably be retrieved.
130 QList<int> m_sizes;
134 #endif // SPLITTERORVIEW_H