add "hideWhenClose" property
Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
parent
093040ec93
commit
0cff5ff48e
|
@ -51,6 +51,7 @@ class FRAMELESSHELPER_QUICK_API QuickStandardTitleBar : public QQuickRectangle
|
||||||
Q_PROPERTY(QuickStandardSystemButton* closeButton READ closeButton CONSTANT FINAL)
|
Q_PROPERTY(QuickStandardSystemButton* closeButton READ closeButton CONSTANT FINAL)
|
||||||
Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL)
|
Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL)
|
||||||
Q_PROPERTY(bool useAlternativeBackground READ isUsingAlternativeBackground WRITE setUseAlternativeBackground NOTIFY useAlternativeBackgroundChanged FINAL)
|
Q_PROPERTY(bool useAlternativeBackground READ isUsingAlternativeBackground WRITE setUseAlternativeBackground NOTIFY useAlternativeBackgroundChanged FINAL)
|
||||||
|
Q_PROPERTY(bool hideWhenClose READ isHideWhenClose WRITE setHideWhenClose NOTIFY hideWhenCloseChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QuickStandardTitleBar(QQuickItem *parent = nullptr);
|
explicit QuickStandardTitleBar(QQuickItem *parent = nullptr);
|
||||||
|
@ -70,6 +71,9 @@ public:
|
||||||
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
||||||
void setUseAlternativeBackground(const bool value);
|
void setUseAlternativeBackground(const bool value);
|
||||||
|
|
||||||
|
Q_NODISCARD bool isHideWhenClose() const;
|
||||||
|
void setHideWhenClose(const bool value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void itemChange(const ItemChange change, const ItemChangeData &value) override;
|
void itemChange(const ItemChange change, const ItemChangeData &value) override;
|
||||||
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
|
Q_NODISCARD bool eventFilter(QObject *object, QEvent *event) override;
|
||||||
|
@ -87,6 +91,7 @@ Q_SIGNALS:
|
||||||
void titleLabelAlignmentChanged();
|
void titleLabelAlignmentChanged();
|
||||||
void extendedChanged();
|
void extendedChanged();
|
||||||
void useAlternativeBackgroundChanged();
|
void useAlternativeBackgroundChanged();
|
||||||
|
void hideWhenCloseChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
@ -104,6 +109,7 @@ private:
|
||||||
QMetaObject::Connection m_windowTitleChangeConnection = {};
|
QMetaObject::Connection m_windowTitleChangeConnection = {};
|
||||||
bool m_extended = false;
|
bool m_extended = false;
|
||||||
bool m_useAlternativeBackground = false;
|
bool m_useAlternativeBackground = false;
|
||||||
|
bool m_hideWhenClose = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -60,6 +60,9 @@ public:
|
||||||
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
||||||
void setUseAlternativeBackground(const bool value);
|
void setUseAlternativeBackground(const bool value);
|
||||||
|
|
||||||
|
Q_NODISCARD bool isHideWhenClose() const;
|
||||||
|
void setHideWhenClose(const bool value);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void updateMaximizeButton();
|
void updateMaximizeButton();
|
||||||
void updateTitleBarStyleSheet();
|
void updateTitleBarStyleSheet();
|
||||||
|
@ -83,6 +86,7 @@ private:
|
||||||
QSpacerItem *m_labelLeftStretch = nullptr;
|
QSpacerItem *m_labelLeftStretch = nullptr;
|
||||||
QSpacerItem *m_labelRightStretch = nullptr;
|
QSpacerItem *m_labelRightStretch = nullptr;
|
||||||
bool m_useAlternativeBackground = false;
|
bool m_useAlternativeBackground = false;
|
||||||
|
bool m_hideWhenClose = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
FRAMELESSHELPER_END_NAMESPACE
|
FRAMELESSHELPER_END_NAMESPACE
|
||||||
|
|
|
@ -45,6 +45,7 @@ class FRAMELESSHELPER_WIDGETS_API StandardTitleBar : public QWidget
|
||||||
Q_PROPERTY(StandardSystemButton* closeButton READ closeButton CONSTANT FINAL)
|
Q_PROPERTY(StandardSystemButton* closeButton READ closeButton CONSTANT FINAL)
|
||||||
Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL)
|
Q_PROPERTY(bool extended READ isExtended WRITE setExtended NOTIFY extendedChanged FINAL)
|
||||||
Q_PROPERTY(bool useAlternativeBackground READ isUsingAlternativeBackground WRITE setUseAlternativeBackground NOTIFY useAlternativeBackgroundChanged FINAL)
|
Q_PROPERTY(bool useAlternativeBackground READ isUsingAlternativeBackground WRITE setUseAlternativeBackground NOTIFY useAlternativeBackgroundChanged FINAL)
|
||||||
|
Q_PROPERTY(bool hideWhenClose READ isHideWhenClose WRITE setHideWhenClose NOTIFY hideWhenCloseChanged FINAL)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit StandardTitleBar(QWidget *parent = nullptr);
|
explicit StandardTitleBar(QWidget *parent = nullptr);
|
||||||
|
@ -64,6 +65,9 @@ public:
|
||||||
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
Q_NODISCARD bool isUsingAlternativeBackground() const;
|
||||||
void setUseAlternativeBackground(const bool value);
|
void setUseAlternativeBackground(const bool value);
|
||||||
|
|
||||||
|
Q_NODISCARD bool isHideWhenClose() const;
|
||||||
|
void setHideWhenClose(const bool value);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
|
||||||
|
@ -71,6 +75,7 @@ Q_SIGNALS:
|
||||||
void extendedChanged();
|
void extendedChanged();
|
||||||
void titleLabelAlignmentChanged();
|
void titleLabelAlignmentChanged();
|
||||||
void useAlternativeBackgroundChanged();
|
void useAlternativeBackgroundChanged();
|
||||||
|
void hideWhenCloseChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<StandardTitleBarPrivate> d_ptr;
|
QScopedPointer<StandardTitleBarPrivate> d_ptr;
|
||||||
|
|
|
@ -136,6 +136,20 @@ void QuickStandardTitleBar::setUseAlternativeBackground(const bool value)
|
||||||
Q_EMIT useAlternativeBackgroundChanged();
|
Q_EMIT useAlternativeBackgroundChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QuickStandardTitleBar::isHideWhenClose() const
|
||||||
|
{
|
||||||
|
return m_hideWhenClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QuickStandardTitleBar::setHideWhenClose(const bool value)
|
||||||
|
{
|
||||||
|
if (m_hideWhenClose == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_hideWhenClose = value;
|
||||||
|
Q_EMIT hideWhenCloseChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void QuickStandardTitleBar::updateMaximizeButton()
|
void QuickStandardTitleBar::updateMaximizeButton()
|
||||||
{
|
{
|
||||||
const QQuickWindow * const w = window();
|
const QQuickWindow * const w = window();
|
||||||
|
@ -237,7 +251,11 @@ void QuickStandardTitleBar::clickCloseButton()
|
||||||
if (!w) {
|
if (!w) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
w->close();
|
if (m_hideWhenClose) {
|
||||||
|
w->hide();
|
||||||
|
} else {
|
||||||
|
w->close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuickStandardTitleBar::retranslateUi()
|
void QuickStandardTitleBar::retranslateUi()
|
||||||
|
|
|
@ -139,6 +139,21 @@ void StandardTitleBarPrivate::setUseAlternativeBackground(const bool value)
|
||||||
Q_EMIT q->useAlternativeBackgroundChanged();
|
Q_EMIT q->useAlternativeBackgroundChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StandardTitleBarPrivate::isHideWhenClose() const
|
||||||
|
{
|
||||||
|
return m_hideWhenClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
void StandardTitleBarPrivate::setHideWhenClose(const bool value)
|
||||||
|
{
|
||||||
|
if (m_hideWhenClose == value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_hideWhenClose = value;
|
||||||
|
Q_Q(StandardTitleBar);
|
||||||
|
Q_EMIT q->hideWhenCloseChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void StandardTitleBarPrivate::updateMaximizeButton()
|
void StandardTitleBarPrivate::updateMaximizeButton()
|
||||||
{
|
{
|
||||||
const bool max = m_window->isMaximized();
|
const bool max = m_window->isMaximized();
|
||||||
|
@ -251,7 +266,13 @@ void StandardTitleBarPrivate::initialize()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
m_closeButton.reset(new StandardSystemButton(SystemButtonType::Close, q));
|
m_closeButton.reset(new StandardSystemButton(SystemButtonType::Close, q));
|
||||||
connect(m_closeButton.data(), &StandardSystemButton::clicked, m_window, &QWidget::close);
|
connect(m_closeButton.data(), &StandardSystemButton::clicked, this, [this](){
|
||||||
|
if (m_hideWhenClose) {
|
||||||
|
m_window->hide();
|
||||||
|
} else {
|
||||||
|
m_window->close();
|
||||||
|
}
|
||||||
|
});
|
||||||
m_labelLeftStretch = new QSpacerItem(0, 0);
|
m_labelLeftStretch = new QSpacerItem(0, 0);
|
||||||
m_labelRightStretch = new QSpacerItem(0, 0);
|
m_labelRightStretch = new QSpacerItem(0, 0);
|
||||||
const auto titleLabelLayout = new QHBoxLayout;
|
const auto titleLabelLayout = new QHBoxLayout;
|
||||||
|
@ -355,6 +376,18 @@ void StandardTitleBar::setUseAlternativeBackground(const bool value)
|
||||||
d->setUseAlternativeBackground(value);
|
d->setUseAlternativeBackground(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool StandardTitleBar::isHideWhenClose() const
|
||||||
|
{
|
||||||
|
Q_D(const StandardTitleBar);
|
||||||
|
return d->isHideWhenClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StandardTitleBar::setHideWhenClose(const bool value)
|
||||||
|
{
|
||||||
|
Q_D(StandardTitleBar);
|
||||||
|
d->setHideWhenClose(value);
|
||||||
|
}
|
||||||
|
|
||||||
void StandardTitleBar::paintEvent(QPaintEvent *event)
|
void StandardTitleBar::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
|
|
Loading…
Reference in New Issue