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#621
  • Loading branch information
deepin-ci-robot committed Nov 23, 2024
1 parent 9c4d4f8 commit 99df307
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
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
2 changes: 1 addition & 1 deletion src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,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(bool)), this, SLOT(_q_quitActionTriggered()), Qt::UniqueConnection);

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

0 comments on commit 99df307

Please sign in to comment.