Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#622
  • Loading branch information
deepin-ci-robot committed Nov 27, 2024
1 parent 9c4d4f8 commit ce43c2a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
7 changes: 1 addition & 6 deletions src/widgets/dabstractdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()) {
Expand Down
21 changes: 5 additions & 16 deletions src/widgets/ddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DDialogPrivate::DDialogPrivate(DDialog *qq)
, iconLayout(nullptr)
, contentLayout(nullptr)
, buttonLayout(nullptr)
, clickedButtonIndex(0)
, clickedButtonIndex(-1)
{

}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/widgets/dfloatingmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QLabel>
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QWindow>

class MessageLabel : public QLabel
{
Expand Down Expand Up @@ -83,7 +84,9 @@ void DFloatingMessagePrivate::init()

if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE)
q->connect(closeButton, &DIconButton::clicked, q, [q]() {
q->close();
if (q->windowHandle()) {
q->windowHandle()->close();
}
Q_EMIT q->messageClosed();
});
else
Expand Down
12 changes: 3 additions & 9 deletions src/widgets/dmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <qwidgetaction.h>
#include <QScreen>

#include <DWindowManagerHelper>
#include <DAnchors>
#include <DConfig>

Expand All @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QScreen>
#include <QWindow>
#include <QActionGroup>
#include <qnamespace.h>
#include <qpa/qplatformwindow.h>

#include "dpalettehelper.h"
Expand Down Expand Up @@ -1533,7 +1534,12 @@ 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, &DWindowCloseButton::clicked, d->targetWindow(), [this]() {
D_D(DTitlebar);
if (d->targetWindow()->windowHandle()) {
d->targetWindow()->windowHandle()->close();
}
}, Qt::QueuedConnection);

d->updateButtonsState(d->targetWindow()->windowFlags());
} else {
Expand Down

0 comments on commit ce43c2a

Please sign in to comment.