From 89b006143dfb6b6f32495cdc383d2ed0ab69d38e Mon Sep 17 00:00:00 2001 From: Nikita Kobzev Date: Wed, 3 Jan 2024 00:34:37 +0300 Subject: [PATCH] Fix buttons order in the InsertDialog --- pbom/ui/CMakeLists.txt | 1 + pbom/ui/insertdialog.ui | 35 +++++++------ pbom/ui/insertdialogbuttons.cpp | 89 +++++++++++++++++++++++---------- pbom/ui/insertdialogbuttons.h | 26 +++++++--- pbom/ui/insertdialogbuttons.ui | 77 ++++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 51 deletions(-) create mode 100644 pbom/ui/insertdialogbuttons.ui diff --git a/pbom/ui/CMakeLists.txt b/pbom/ui/CMakeLists.txt index 59fdc90..a9dcba1 100644 --- a/pbom/ui/CMakeLists.txt +++ b/pbom/ui/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND PROJECT_SOURCES_UI "ui/insertdialog.cpp" "ui/insertdialog.ui" "ui/insertdialogbuttons.cpp" + "ui/insertdialogbuttons.ui" "ui/renamedialog.cpp" "ui/renamedialog.ui" "ui/mainwindow.cpp" diff --git a/pbom/ui/insertdialog.ui b/pbom/ui/insertdialog.ui index 9f3794b..e5ab6cf 100644 --- a/pbom/ui/insertdialog.ui +++ b/pbom/ui/insertdialog.ui @@ -99,11 +99,7 @@ - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + @@ -120,11 +116,14 @@ pboman3::ui::InsertDialogButtons - QDialogButtonBox + QWidget
ui/insertdialogbuttons.h
+ 1 - next() + ok() + cancel() back() + next()
@@ -132,13 +131,13 @@ buttons - accepted() + ok() InsertDialog accept() 393 - 565 + 572 393 @@ -148,13 +147,13 @@ buttons - rejected() + back() InsertDialog - reject() + back() 393 - 565 + 572 393 @@ -164,13 +163,13 @@ buttons - next() + cancel() InsertDialog - next() + reject() 393 - 565 + 572 393 @@ -180,13 +179,13 @@ buttons - back() + next() InsertDialog - back() + next() 393 - 565 + 572 393 diff --git a/pbom/ui/insertdialogbuttons.cpp b/pbom/ui/insertdialogbuttons.cpp index c652d87..45b09ac 100644 --- a/pbom/ui/insertdialogbuttons.cpp +++ b/pbom/ui/insertdialogbuttons.cpp @@ -6,36 +6,73 @@ namespace pboman3::ui { InsertDialogButtons::InsertDialogButtons(QWidget* parent) - : QDialogButtonBox(StandardButtons(Ok | Cancel), parent), - btnNext_(nullptr), - btnBack_(nullptr) { - connect(this, &InsertDialogButtons::clicked, this, &InsertDialogButtons::onButtonClicked); + : QWidget(parent), + ui_(new Ui::InsertDialogButtons) { + ui_->setupUi(this); + ui_->btnNext->hide(); + ui_->btnBack->hide(); + + connect(ui_->btnOk, &QAbstractButton::clicked, this, &InsertDialogButtons::onOkClick); + connect(ui_->btnCancel, &QAbstractButton::clicked, this, &InsertDialogButtons::onCancelClick); + connect(ui_->btnNext, &QAbstractButton::clicked, this, &InsertDialogButtons::onNextClick); + connect(ui_->btnBack, &QAbstractButton::clicked, this, &InsertDialogButtons::onBackClick); + } + + InsertDialogButtons::~InsertDialogButtons() { + delete ui_; } - void InsertDialogButtons::setIsTwoStep() { + void InsertDialogButtons::setIsTwoStep() const { LOG(info, "Set the buttons panel for a 2-step dialog") - btnNext_ = addButton("Next", ActionRole); - btnNext_->setFocus(); - btnBack_ = addButton("Back", ActionRole); - button(Ok)->hide(); - btnBack_->hide(); + + ui_->btnOk->setAutoDefault(false); + ui_->btnOk->setDefault(false); + ui_->btnOk->hide(); + + ui_->btnNext->show(); + ui_->btnNext->setFocus(); + ui_->btnNext->setDefault(true); + ui_->btnNext->setAutoDefault(true); + } + + void InsertDialogButtons::onNextClick() { + LOG(info, "User clicked the Next button") + ui_->btnNext->setAutoDefault(false); + ui_->btnNext->setDefault(false); + ui_->btnNext->hide(); + + ui_->btnOk->show(); + ui_->btnOk->setFocus(); + ui_->btnOk->setDefault(true); + ui_->btnOk->setAutoDefault(true); + + ui_->btnBack->show(); + emit next(); + } + + void InsertDialogButtons::onBackClick() { + LOG(info, "User clicked the Back button") + + ui_->btnOk->setAutoDefault(false); + ui_->btnOk->setDefault(false); + ui_->btnOk->hide(); + + ui_->btnNext->show(); + ui_->btnNext->setFocus(); + ui_->btnNext->setDefault(true); + ui_->btnNext->setAutoDefault(true); + + ui_->btnBack->hide(); + emit back(); + } + + void InsertDialogButtons::onOkClick() { + LOG(info, "User clicked the Ok button") + emit ok(); } - void InsertDialogButtons::onButtonClicked(const QAbstractButton* btn) { - if (btn == btnNext_) { - LOG(info, "User clicked the Next button") - button(Ok)->show(); - button(Ok)->setFocus(); - btnNext_->hide(); - btnBack_->show(); - emit next(); - } else if (btn == btnBack_) { - LOG(info, "User clicked the Back button") - button(Ok)->hide(); - btnNext_->show(); - btnNext_->setFocus(); - btnBack_->hide(); - emit back(); - } + void InsertDialogButtons::onCancelClick() { + LOG(info, "User clicked the Cancel button") + emit cancel(); } } diff --git a/pbom/ui/insertdialogbuttons.h b/pbom/ui/insertdialogbuttons.h index ba1bce8..e198acf 100644 --- a/pbom/ui/insertdialogbuttons.h +++ b/pbom/ui/insertdialogbuttons.h @@ -1,25 +1,37 @@ #pragma once -#include +#include +#include "ui_insertdialogbuttons.h" namespace pboman3::ui { - class InsertDialogButtons : public QDialogButtonBox { - Q_OBJECT + class InsertDialogButtons : public QWidget { + Q_OBJECT public: InsertDialogButtons(QWidget* parent = nullptr); - void setIsTwoStep(); + ~InsertDialogButtons() override; + + void setIsTwoStep() const; signals: void next(); void back(); + void ok(); + + void cancel(); + private: - QPushButton* btnNext_; - QPushButton* btnBack_; + Ui::InsertDialogButtons* ui_; + + void onNextClick(); + + void onBackClick(); + + void onOkClick(); - void onButtonClicked(const QAbstractButton* btn); + void onCancelClick(); }; } diff --git a/pbom/ui/insertdialogbuttons.ui b/pbom/ui/insertdialogbuttons.ui new file mode 100644 index 0000000..3eebc63 --- /dev/null +++ b/pbom/ui/insertdialogbuttons.ui @@ -0,0 +1,77 @@ + + + InsertDialogButtons + + + + 0 + 0 + 538 + 42 + + + + Form + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Back + + + + + + + Next + + + Return + + + true + + + + + + + Ok + + + Return + + + true + + + true + + + + + + + Cancel + + + + + + + +