diff --git a/include/widgets/dtitlebar.h b/include/widgets/dtitlebar.h index 859e0386..fb6ca64b 100644 --- a/include/widgets/dtitlebar.h +++ b/include/widgets/dtitlebar.h @@ -119,6 +119,7 @@ private Q_SLOTS: D_PRIVATE_SLOT(void _q_toggleWindowState()) D_PRIVATE_SLOT(void _q_showMinimized()) D_PRIVATE_SLOT(void _q_onTopWindowMotifHintsChanged(quint32)) + D_PRIVATE_SLOT(void _q_closeWindow()) #ifndef QT_NO_MENU D_PRIVATE_SLOT(void _q_addDefaultMenuItems()) diff --git a/src/widgets/dabstractdialog.cpp b/src/widgets/dabstractdialog.cpp index 4a5c5e1c..d698d77f 100644 --- a/src/widgets/dabstractdialog.cpp +++ b/src/widgets/dabstractdialog.cpp @@ -40,11 +40,6 @@ void DAbstractDialogPrivate::init(bool blurIfPossible) // TODO: 这里对dialog特殊处理,dialog不需要设置固定的位置,否则里面的坐标会发生偏移导致点击偏移 // 但是这不是问题的根本原因,还需要进一步分析。该属性在插件中做了特殊处理 q->QDialog::setProperty("DAbstractDialog", true); - auto noTitlebarEnabled = []{ - QFunctionPointer enableNoTitlebar = qApp->platformFunction("_d_isEnableNoTitlebar"); - bool enabled = qApp->platformName() == "dwayland" || qApp->property("_d_isDwayland").toBool(); - return enabled && enableNoTitlebar != nullptr; - }; if (qApp->isDXcbPlatform()) { handle = new DPlatformWindowHandle(q, q); @@ -66,7 +61,7 @@ void DAbstractDialogPrivate::init(bool blurIfPossible) bgBlurWidget->setBlurEnabled(blurIfPossible); q->setAttribute(Qt::WA_TranslucentBackground, blurIfPossible); - } else if (noTitlebarEnabled()) { + } else if (DWindowManagerHelper::instance()->hasNoTitlebar()) { handle = new DPlatformWindowHandle(q, q); if (!handle->enableBlurWindow()) { diff --git a/src/widgets/ddialog.cpp b/src/widgets/ddialog.cpp index 815f1682..f77fb199 100644 --- a/src/widgets/ddialog.cpp +++ b/src/widgets/ddialog.cpp @@ -41,7 +41,7 @@ DDialogPrivate::DDialogPrivate(DDialog *qq) , iconLayout(nullptr) , contentLayout(nullptr) , buttonLayout(nullptr) - , clickedButtonIndex(0) + , clickedButtonIndex(-1) { } @@ -240,9 +240,9 @@ void DDialogPrivate::_q_onButtonClicked() if (button) { int index = buttonList.indexOf(button); q->buttonClicked(index, button->text()); + clickedButtonIndex = index; if (onButtonClickedClose) { - clickedButtonIndex = index; q->done(clickedButtonIndex); } } @@ -1109,19 +1109,7 @@ int DDialog::exec() D_D(DDialog); d->clickedButtonIndex = -1; - int clickedIndex = d->clickedButtonIndex; - - if (d->onButtonClickedClose) { - // 如果设置了WA_DeleteOnClose属性,那么在exec()中将直接delete this - // d->clickedButtonIndex中记录的数据失效,这里通过信号槽更新正确的数据 - connect(this, &DDialog::buttonClicked, this, [ &clickedIndex ] (int index, const QString &) { - clickedIndex = index; - }); - } - - int code = DAbstractDialog::exec(); - - return clickedIndex >= 0 ? clickedIndex : code; + return DAbstractDialog::exec(); } void DDialog::setCloseButtonVisible(bool closeButtonVisible) @@ -1163,10 +1151,11 @@ void DDialog::hideEvent(QHideEvent *event) void DDialog::closeEvent(QCloseEvent *event) { Q_UNUSED(event) + Q_D(DDialog); Q_EMIT aboutToClose(); - done(-1); + done(d->clickedButtonIndex); Q_EMIT visibleChanged(isVisible()); Q_EMIT closed(); diff --git a/src/widgets/dfloatingmessage.cpp b/src/widgets/dfloatingmessage.cpp index fd3aaa48..f6d65340 100644 --- a/src/widgets/dfloatingmessage.cpp +++ b/src/widgets/dfloatingmessage.cpp @@ -12,6 +12,7 @@ #include #include #include +#include class MessageLabel : public QLabel { @@ -79,15 +80,16 @@ void DFloatingMessagePrivate::init() closeButton->setIconSize(DSizeModeHelper::element(QSize(20, 20), QSize(32, 32))); hBoxLayout->addWidget(closeButton); - q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::closeButtonClicked); - if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) - q->connect(closeButton, &DIconButton::clicked, q, [q]() { - q->close(); + q->connect(closeButton, &DIconButton::clicked, q, [q]() { + if (q->windowHandle()) { + q->windowHandle()->close(); + } + if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) { Q_EMIT q->messageClosed(); - }); - else - q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::close); + } + Q_EMIT q->closeButtonClicked(); + }); } if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE) diff --git a/src/widgets/dmainwindow.cpp b/src/widgets/dmainwindow.cpp index 8682ba2a..a739d66f 100644 --- a/src/widgets/dmainwindow.cpp +++ b/src/widgets/dmainwindow.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -42,15 +43,8 @@ DMainWindowPrivate::DMainWindowPrivate(DMainWindow *qq) { titlebar = new DTitlebar(qq); titlebar->setAccessibleName("DMainWindowTitlebar"); - auto noTitlebarEnabled = []{ - if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform)) { - return true; - } - QFunctionPointer enableNoTitlebar = qApp->platformFunction("_d_isEnableNoTitlebar"); - bool enabled = qApp->platformName() == "dwayland" || qApp->property("_d_isDwayland").toBool(); - return enabled && enableNoTitlebar != nullptr; - }; - if (DApplication::isDXcbPlatform() || noTitlebarEnabled()) { + + if (DApplication::isDXcbPlatform() || DWindowManagerHelper::instance()->hasNoTitlebar()) { handle = new DPlatformWindowHandle(qq, qq); qq->setMenuWidget(titlebar); } else { diff --git a/src/widgets/dtitlebar.cpp b/src/widgets/dtitlebar.cpp index c3a23a70..817e62e4 100644 --- a/src/widgets/dtitlebar.cpp +++ b/src/widgets/dtitlebar.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "dpalettehelper.h" @@ -79,6 +80,7 @@ class DTitlebarPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate void _q_toggleWindowState(); void _q_showMinimized(); void _q_onTopWindowMotifHintsChanged(quint32 winId); + void _q_closeWindow(); #ifndef QT_NO_MENU void _q_addDefaultMenuItems(); @@ -572,6 +574,13 @@ void DTitlebarPrivate::_q_toggleWindowState() } } +void DTitlebarPrivate::_q_closeWindow() +{ + if (targetWindow()->windowHandle()) { + targetWindow()->windowHandle()->close(); + } +} + void DTitlebarPrivate::_q_showMinimized() { targetWindow()->showMinimized(); @@ -1533,7 +1542,7 @@ void DTitlebar::setVisible(bool visible) connect(d->maxButton, SIGNAL(clicked()), this, SLOT(_q_toggleWindowState()), Qt::UniqueConnection); connect(this, SIGNAL(doubleClicked()), this, SLOT(_q_toggleWindowState()), Qt::UniqueConnection); connect(d->minButton, SIGNAL(clicked()), this, SLOT(_q_showMinimized()), Qt::UniqueConnection); - connect(d->closeButton, &DWindowCloseButton::clicked, d->targetWindow(), &QWidget::close, Qt::UniqueConnection); + connect(d->closeButton, SIGNAL(clicked()), this, SLOT(_q_closeWindow()), Qt::UniqueConnection); d->updateButtonsState(d->targetWindow()->windowFlags()); } else {