BornAgain  1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
DocksController.h
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // BornAgain: simulate and fit reflection and scattering
4 //
5 //! @file GUI/View/Common/DocksController.h
6 //! @brief Defines class DocksController
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
15 #ifndef BORNAGAIN_GUI_VIEW_COMMON_DOCKSCONTROLLER_H
16 #define BORNAGAIN_GUI_VIEW_COMMON_DOCKSCONTROLLER_H
17 
19 #include <QObject>
20 #include <QSize>
21 #include <map>
22 
23 class QMainWindow;
24 class QMenu;
25 class QSettings;
26 
27 //! Handles creation and appearance of docked widgets in the context of QMainWindow. It is used for
28 //! SampleView and JobView which are based on QMainWindow.
29 
30 class DocksController : public QObject {
31  Q_OBJECT
32 
33 public:
34  DocksController(QMainWindow* mainWindow);
35 
36  void addWidget(int id, QWidget* widget, Qt::DockWidgetArea area);
37 
38  void resetLayout();
39  void toggleDock(int id);
40  void setDockVisible(int id, bool visible = true);
41  void setVisibleDocks(const std::vector<int>& visibleDocks);
42 
43  QDockWidget* findDock(int id);
44  QDockWidget* findDock(QWidget* widget);
45  QList<QDockWidget*> dockWidgets() const;
46 
47  void addDockActionsToMenu(QMenu* menu);
48 
49  QHash<QString, QVariant> saveSettings() const;
50  void saveSettings(QSettings* settings) const;
51  void restoreSettings(const QHash<QString, QVariant>& settings);
52  void restoreSettings(const QSettings* settings);
53 
54 public slots:
55  void setDockHeightForWidget(int height);
56  void dockToMinMaxSizes();
57 
58 private:
59  struct DockSizeInfo {
60  QDockWidget* m_dock = nullptr;
61  QSize m_min_size;
62  QSize m_max_size;
63  };
64 
65  QDockWidget* addDockForWidget(QWidget* widget);
66  void setTrackingEnabled(bool enabled);
67  void handleWindowVisibilityChanged(bool visible);
68  bool eventFilter(QObject*, QEvent* event) override;
69 
70  QMainWindow* m_mainWindow;
71  std::map<int, DockWidgetInfo> m_docks;
74 };
75 
76 #endif // BORNAGAIN_GUI_VIEW_COMMON_DOCKSCONTROLLER_H
Defines class DockWidgetInfo.
Handles creation and appearance of docked widgets in the context of QMainWindow. It is used for Sampl...
void setDockVisible(int id, bool visible=true)
bool m_handleDockVisibilityChanges
void restoreSettings(const QHash< QString, QVariant > &settings)
QDockWidget * addDockForWidget(QWidget *widget)
QHash< QString, QVariant > saveSettings() const
void setDockHeightForWidget(int height)
A hack to request update of QDockWidget size if its child (e.g. InfoWidget) wants it....
void addDockActionsToMenu(QMenu *menu)
DockSizeInfo m_dock_info
void addWidget(int id, QWidget *widget, Qt::DockWidgetArea area)
QDockWidget * findDock(int id)
bool eventFilter(QObject *, QEvent *event) override
void handleWindowVisibilityChanged(bool visible)
void setVisibleDocks(const std::vector< int > &visibleDocks)
Show docks with id's from the list. Other docks will be hidden.
DocksController(QMainWindow *mainWindow)
QMainWindow * m_mainWindow
void setTrackingEnabled(bool enabled)
QList< QDockWidget * > dockWidgets() const
void toggleDock(int id)
std::map< int, DockWidgetInfo > m_docks
static QMainWindow * mainWindow
Definition: Globals.h:22