dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
splitterorview.h
Go to the documentation of this file.
1 
13 /*
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.
18  *
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.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #ifndef SPLITTERORVIEW_H
29 #define SPLITTERORVIEW_H
30 
31 #include <QWidget>
32 #include <QMouseEvent>
33 #include "uavgadgetmanager.h"
34 #include "uavgadgetview.h"
35 
36 namespace Core {
37 
38 namespace Internal {
39 
40  class SplitterOrView : public QWidget
41  {
42  Q_OBJECT
43  public:
44  SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget = nullptr,
45  bool restoring = false);
47 
48  void split(Qt::Orientation orientation, bool restoring = false);
49  void unsplit();
50 
51  inline bool isView() const { return m_view != nullptr; }
52 
53  inline bool isSplitter() const { return m_splitter != nullptr; }
54  inline Core::IUAVGadget *gadget() const { return m_view ? m_view->gadget() : nullptr; }
55  inline bool hasGadget(Core::IUAVGadget *uavGadget) const
56  {
57  return m_view && m_view->hasGadget(uavGadget);
58  }
59  inline bool hasGadget() const { return m_view && (m_view->gadget() != nullptr); }
60  inline UAVGadgetView *view() const { return m_view; }
61  inline QSplitter *splitter() const { return m_splitter; }
63  QSplitter *takeSplitter();
65 
66  void saveState(QSettings *) const;
67  void restoreState(QSettings *);
68 
74 
76 
77  QSize sizeHint() const { return minimumSizeHint(); }
78  QSize minimumSizeHint() const;
79 
80  void unsplitAll(IUAVGadget *currentGadget);
81 
82  protected:
83  // void paintEvent(QPaintEvent *);
84  void mousePressEvent(QMouseEvent *e);
85 
86  private slots:
87  // Called when the user moves the splitter, and updates our m_sizes.
88  void onSplitterMoved(int pos, int index);
89 
90  private:
91  void unsplitAll_helper();
92  SplitterOrView *findNextView_helper(SplitterOrView *view, bool *found);
93 
94  // The gadget manager that controls us.
95  QPointer<UAVGadgetManager> m_uavGadgetManager;
96 
97  // Our layout, we use stacked so we can change stuff without visual artifacts (I think...)
98  QPointer<QStackedLayout> m_layout;
99 
100  // Our view, if we are a view (showing 1 gadget) and not a splitter.
101  QPointer<UAVGadgetView> m_view;
102 
103  // Out splitter, if we are a splitter.
104  QPointer<QSplitter> m_splitter;
105 
106  // The splitter sizes. We keep our own copy of these, since after loading they can't
107  // realiably be retrieved.
108  QList<int> m_sizes;
109  };
110 }
111 }
112 #endif // SPLITTERORVIEW_H
void split(Qt::Orientation orientation, bool restoring=false)
QList< Core::IUAVGadget * > gadgets()
SplitterOrView * findSplitter(Core::IUAVGadget *uavGadget)
SplitterOrView(UAVGadgetManager *uavGadgetManager, Core::IUAVGadget *uavGadget=nullptr, bool restoring=false)
void saveState(QSettings *) const
Core::IUAVGadget * gadget() const
UAVGadgetView * view() const
void unsplitAll(IUAVGadget *currentGadget)
bool hasGadget(Core::IUAVGadget *uavGadget) const
SplitterOrView * findView(Core::IUAVGadget *uavGadget)
QSplitter * splitter() const
SplitterOrView * findNextView(SplitterOrView *view)
void mousePressEvent(QMouseEvent *e)
SplitterOrView * findFirstView()
e
Definition: OPPlots.m:99