refactor: some mini feature changes in BaseWindow (#6074)

This commit is contained in:
pajlada
2025-03-13 22:20:03 +01:00
committed by GitHub
parent 55031c5108
commit fb375e149b
10 changed files with 86 additions and 68 deletions
+25 -7
View File
@@ -38,9 +38,10 @@ public:
DisableLayoutSave = 1 << 7,
BoundsCheckOnShow = 1 << 8,
ClearBuffersOnDpiChange = 1 << 9,
};
enum ActionOnFocusLoss { Nothing, Delete, Close, Hide };
/// special flag that enables the Qt::Popup flag on Linux
LinuxPopup = 1 << 10,
};
explicit BaseWindow(FlagsEnum<Flags> flags_ = None,
QWidget *parent = nullptr);
@@ -55,9 +56,6 @@ public:
std::function<void()> onClicked);
EffectLabel *addTitleBarLabel(std::function<void()> onClicked);
void setActionOnFocusLoss(ActionOnFocusLoss value);
ActionOnFocusLoss getActionOnFocusLoss() const;
void moveTo(QPoint point, widgets::BoundsChecking mode);
/**
@@ -93,6 +91,25 @@ Q_SIGNALS:
void topMostChanged(bool topMost);
protected:
enum class FocusOutAction : std::uint8_t {
None,
Hide,
};
/// focusOutAction is used when the `FocusOut` event is fired
FocusOutAction focusOutAction = FocusOutAction::None;
enum class WindowDeactivateAction : std::uint8_t {
Nothing,
Delete,
Close,
Hide,
};
/// This action is used when the `WindowDeactivate` event is fired
WindowDeactivateAction windowDeactivateAction =
WindowDeactivateAction::Nothing;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool nativeEvent(const QByteArray &eventType, void *message,
qintptr *result) override;
@@ -118,6 +135,9 @@ protected:
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
QPointF movingRelativePos;
bool moving{};
@@ -132,7 +152,6 @@ private:
void calcButtonsSizes();
void drawCustomWindowFrame(QPainter &painter);
void onFocusLost();
static void applyScaleRecursive(QObject *root, float scale);
@@ -148,7 +167,6 @@ private:
#endif
bool enableCustomFrame_;
ActionOnFocusLoss actionOnFocusLoss_ = Nothing;
bool frameless_;
bool shown_ = false;
FlagsEnum<Flags> flags_;