2018-03-16 21:46:57 +00:00
|
|
|
#ifndef CUTTERWIDGET_H
|
|
|
|
#define CUTTERWIDGET_H
|
|
|
|
|
2020-05-22 11:49:34 +00:00
|
|
|
#include "CutterCommon.h"
|
2019-01-13 11:40:54 +00:00
|
|
|
#include "common/RefreshDeferrer.h"
|
|
|
|
|
2020-05-22 11:49:34 +00:00
|
|
|
#include <QDockWidget>
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
class MainWindow;
|
|
|
|
|
|
|
|
class CutterDockWidget : public QDockWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-05-22 11:49:34 +00:00
|
|
|
CUTTER_DEPRECATED("Action will be ignored. Use CutterDockWidget(MainWindow*) instead.")
|
|
|
|
CutterDockWidget(MainWindow *parent, QAction *action);
|
|
|
|
|
|
|
|
explicit CutterDockWidget(MainWindow *parent);
|
2019-01-12 17:02:51 +00:00
|
|
|
~CutterDockWidget() override;
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2019-01-12 19:25:43 +00:00
|
|
|
bool isVisibleToUser() { return isVisibleToUserCurrent; }
|
2019-01-12 17:02:51 +00:00
|
|
|
|
2019-04-27 09:46:29 +00:00
|
|
|
/**
|
|
|
|
* @brief Set whether the Widget should be deleted after it is closed.
|
|
|
|
* This is especially important for extra widgets.
|
|
|
|
*/
|
|
|
|
void setTransient(bool v) { isTransient = v; }
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Convenience method for creating and registering a RefreshDeferrer without any parameters
|
|
|
|
* @param refreshNowFunc lambda taking no parameters, called when a refresh should occur
|
2019-01-13 14:26:55 +00:00
|
|
|
*/
|
|
|
|
template<typename Func>
|
|
|
|
RefreshDeferrer *createRefreshDeferrer(Func refreshNowFunc)
|
|
|
|
{
|
|
|
|
auto *deferrer = new RefreshDeferrer(nullptr, this);
|
|
|
|
deferrer->registerFor(this);
|
|
|
|
connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult) {
|
|
|
|
refreshNowFunc();
|
|
|
|
});
|
|
|
|
return deferrer;
|
|
|
|
}
|
|
|
|
|
2019-03-06 20:30:39 +00:00
|
|
|
/**
|
|
|
|
* @brief Convenience method for creating and registering a RefreshDeferrer with a replacing Accumulator
|
|
|
|
* @param replaceIfNull passed to the ReplacingRefreshDeferrerAccumulator
|
|
|
|
* @param refreshNowFunc lambda taking a single parameter of type ParamResult, called when a refresh should occur
|
2019-01-13 14:26:55 +00:00
|
|
|
*/
|
2019-01-13 11:40:54 +00:00
|
|
|
template<class ParamResult, typename Func>
|
2019-01-13 13:59:08 +00:00
|
|
|
RefreshDeferrer *createReplacingRefreshDeferrer(bool replaceIfNull, Func refreshNowFunc)
|
2019-01-13 11:40:54 +00:00
|
|
|
{
|
2019-01-13 13:59:08 +00:00
|
|
|
auto *deferrer = new RefreshDeferrer(new ReplacingRefreshDeferrerAccumulator<ParamResult>(replaceIfNull), this);
|
2019-01-13 11:40:54 +00:00
|
|
|
deferrer->registerFor(this);
|
|
|
|
connect(deferrer, &RefreshDeferrer::refreshNow, this, [refreshNowFunc](const RefreshDeferrerParamsResult paramsResult) {
|
2019-01-13 13:59:08 +00:00
|
|
|
auto *result = static_cast<const ParamResult *>(paramsResult);
|
|
|
|
refreshNowFunc(result);
|
2019-01-13 11:40:54 +00:00
|
|
|
});
|
|
|
|
return deferrer;
|
|
|
|
}
|
2020-05-22 11:49:34 +00:00
|
|
|
/**
|
|
|
|
* @brief Serialize dock properties for saving as part of layout.
|
|
|
|
*
|
|
|
|
* Override this function for saving dock specific view properties. Use
|
|
|
|
* in situations where it makes sense to have different properties for
|
|
|
|
* multiple instances of widget. Don't use for options that are more suitable
|
|
|
|
* as global settings and should be applied equally to all widgets or all
|
|
|
|
* widgets of this kind.
|
|
|
|
*
|
|
|
|
* Keep synchrononized with deserializeViewProperties. When modifying add
|
|
|
|
* project upgrade step in SettingsUpgrade.cpp if necessary.
|
|
|
|
*
|
|
|
|
* @return Dictionary of current dock properties.
|
|
|
|
* @see CutterDockWidget#deserializeViewProperties
|
|
|
|
*/
|
|
|
|
virtual QVariantMap serializeViewProprties();
|
|
|
|
/**
|
|
|
|
* @brief Deserialization half of serialize view properties.
|
|
|
|
*
|
|
|
|
* When a property is not specified in property map dock should reset it
|
|
|
|
* to default value instead of leaving it umodified. Empty map should reset
|
|
|
|
* all properties controlled by serializeViewProprties/deserializeViewProperties
|
|
|
|
* mechanism.
|
|
|
|
*
|
|
|
|
* @param properties to modify for current widget
|
|
|
|
* @see CutterDockWidget#serializeViewProprties
|
|
|
|
*/
|
|
|
|
virtual void deserializeViewProperties(const QVariantMap &properties);
|
2020-07-19 19:00:05 +00:00
|
|
|
/**
|
|
|
|
* @brief Ignore visibility status.
|
|
|
|
* Useful for temporary ignoring visibility changes while this information is unreliable.
|
|
|
|
* @param ignored - set to true for enabling ignoring mode
|
|
|
|
*/
|
|
|
|
void ignoreVisibilityStatus(bool ignored);
|
2019-03-27 08:24:54 +00:00
|
|
|
signals:
|
|
|
|
void becameVisibleToUser();
|
2019-06-18 13:02:41 +00:00
|
|
|
void closed();
|
2019-03-27 08:24:54 +00:00
|
|
|
|
2019-02-07 10:42:53 +00:00
|
|
|
public slots:
|
|
|
|
void toggleDockWidget(bool show);
|
|
|
|
|
2019-03-27 08:24:54 +00:00
|
|
|
protected:
|
|
|
|
virtual QWidget* widgetToFocusOnRaise();
|
|
|
|
|
|
|
|
void closeEvent(QCloseEvent *event) override;
|
2019-07-19 19:21:12 +00:00
|
|
|
QString getDockNumber();
|
2019-02-07 10:42:53 +00:00
|
|
|
|
2019-06-18 18:22:26 +00:00
|
|
|
MainWindow *mainWindow;
|
2019-07-19 19:21:12 +00:00
|
|
|
|
|
|
|
private:
|
2019-04-27 09:46:29 +00:00
|
|
|
bool isTransient = false;
|
|
|
|
|
2019-02-07 10:42:53 +00:00
|
|
|
bool isVisibleToUserCurrent = false;
|
2020-07-19 19:00:05 +00:00
|
|
|
bool ignoreVisibility = false;
|
2019-02-07 10:42:53 +00:00
|
|
|
void updateIsVisibleToUser();
|
2018-03-16 21:46:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CUTTERWIDGET_H
|