1 #ifndef CUTTERWIDGET_H
2 #define CUTTERWIDGET_H
3 
4 #include "core/CutterCommon.h"
5 #include "common/RefreshDeferrer.h"
6 
7 #include <QDockWidget>
8 
9 class MainWindow;
10 
11 class CUTTER_EXPORT CutterDockWidget : public QDockWidget
12 {
13     Q_OBJECT
14 
15 public:
16     CUTTER_DEPRECATED("Action will be ignored. Use CutterDockWidget(MainWindow*) instead.")
17     CutterDockWidget(MainWindow *parent, QAction *action);
18 
19     explicit CutterDockWidget(MainWindow *parent);
20     ~CutterDockWidget() override;
21     bool eventFilter(QObject *object, QEvent *event) override;
isVisibleToUser()22     bool isVisibleToUser()      { return isVisibleToUserCurrent; }
23 
24     /**
25      * @brief Set whether the Widget should be deleted after it is closed.
26      * This is especially important for extra widgets.
27      */
setTransient(bool v)28     void setTransient(bool v)   { isTransient = v; }
29 
30     /**
31      * @brief Convenience method for creating and registering a RefreshDeferrer without any parameters
32      * @param refreshNowFunc lambda taking no parameters, called when a refresh should occur
33      */
34     template<typename Func>
createRefreshDeferrer(Func refreshNowFunc)35     RefreshDeferrer *createRefreshDeferrer(Func refreshNowFunc)
36     {
37         auto *deferrer = new RefreshDeferrer(nullptr, this);
38         deferrer->registerFor(this);
39         connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult) {
40             refreshNowFunc();
41         });
42         return deferrer;
43     }
44 
45     /**
46      * @brief Convenience method for creating and registering a RefreshDeferrer with a replacing Accumulator
47      * @param replaceIfNull passed to the ReplacingRefreshDeferrerAccumulator
48      * @param refreshNowFunc lambda taking a single parameter of type ParamResult, called when a refresh should occur
49      */
50     template<class ParamResult, typename Func>
createReplacingRefreshDeferrer(bool replaceIfNull,Func refreshNowFunc)51     RefreshDeferrer *createReplacingRefreshDeferrer(bool replaceIfNull, Func refreshNowFunc)
52     {
53         auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator<ParamResult>(replaceIfNull), this);
54         deferrer->registerFor(this);
55         connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) {
56             auto *result = static_cast<const ParamResult *>(paramsResult);
57             refreshNowFunc(result);
58         });
59         return deferrer;
60     }
61     /**
62      * @brief Serialize dock properties for saving as part of layout.
63      *
64      * Override this function for saving dock specific view properties. Use
65      * in situations where it makes sense to have different properties for
66      * multiple instances of widget. Don't use for options that are more suitable
67      * as global settings and should be applied equally to all widgets or all
68      * widgets of this kind.
69      *
70      * Keep synchrononized with deserializeViewProperties. When modifying add
71      * project upgrade step in SettingsUpgrade.cpp if necessary.
72      *
73      * @return Dictionary of current dock properties.
74      * @see CutterDockWidget#deserializeViewProperties
75      */
76     virtual QVariantMap serializeViewProprties();
77     /**
78      * @brief Deserialization half of serialize view properties.
79      *
80      * When a property is not specified in property map dock should reset it
81      * to default value instead of leaving it umodified. Empty map should reset
82      * all properties controlled by serializeViewProprties/deserializeViewProperties
83      * mechanism.
84      *
85      * @param properties to modify for current widget
86      * @see CutterDockWidget#serializeViewProprties
87      */
88     virtual void deserializeViewProperties(const QVariantMap &properties);
89     /**
90      * @brief Ignore visibility status.
91      * Useful for temporary ignoring visibility changes while this information is unreliable.
92      * @param ignored - set to true for enabling ignoring mode
93      */
94     void ignoreVisibilityStatus(bool ignored);
95 
96     void raiseMemoryWidget();
97 signals:
98     void becameVisibleToUser();
99     void closed();
100 
101 public slots:
102     void toggleDockWidget(bool show);
103 
104 protected:
105     virtual QWidget* widgetToFocusOnRaise();
106 
107     void closeEvent(QCloseEvent *event) override;
108     QString getDockNumber();
109 
110     MainWindow *mainWindow;
111 
112 private:
113     bool isTransient = false;
114 
115     bool isVisibleToUserCurrent = false;
116     bool ignoreVisibility = false;
117     void updateIsVisibleToUser();
118 };
119 
120 #endif // CUTTERWIDGET_H
121