diff --git a/src/dialog/vdirinfodialog.cpp b/src/dialog/vdirinfodialog.cpp index eef7d3dd..a667d812 100644 --- a/src/dialog/vdirinfodialog.cpp +++ b/src/dialog/vdirinfodialog.cpp @@ -9,8 +9,6 @@ VDirInfoDialog::VDirInfoDialog(const QString &title, const QString &info, setupUI(); connect(nameEdit, &QLineEdit::textChanged, this, &VDirInfoDialog::enableOkButton); - connect(okBtn, &QPushButton::clicked, this, &VDirInfoDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VDirInfoDialog::reject); enableOkButton(); } @@ -25,19 +23,16 @@ void VDirInfoDialog::setupUI() nameEdit->selectAll(); nameLabel->setBuddy(nameEdit); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget(nameLabel); topLayout->addWidget(nameEdit); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); - + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -45,7 +40,7 @@ void VDirInfoDialog::setupUI() mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); + mainLayout->addWidget(m_btnBox); mainLayout->setSizeConstraint(QLayout::SetFixedSize); setLayout(mainLayout); @@ -54,6 +49,7 @@ void VDirInfoDialog::setupUI() void VDirInfoDialog::enableOkButton() { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!nameEdit->text().isEmpty()); } diff --git a/src/dialog/vdirinfodialog.h b/src/dialog/vdirinfodialog.h index f84b877f..f3df2b6e 100644 --- a/src/dialog/vdirinfodialog.h +++ b/src/dialog/vdirinfodialog.h @@ -5,7 +5,7 @@ class QLabel; class QLineEdit; -class QPushButton; +class QDialogButtonBox; class QString; class VDirInfoDialog : public QDialog @@ -25,8 +25,7 @@ private: QLabel *infoLabel; QLabel *nameLabel; QLineEdit *nameEdit; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info; diff --git a/src/dialog/vfileinfodialog.cpp b/src/dialog/vfileinfodialog.cpp index a3450a9a..5cc7b9e9 100644 --- a/src/dialog/vfileinfodialog.cpp +++ b/src/dialog/vfileinfodialog.cpp @@ -9,8 +9,6 @@ VFileInfoDialog::VFileInfoDialog(const QString &title, const QString &info, setupUI(); connect(nameEdit, &QLineEdit::textChanged, this, &VFileInfoDialog::enableOkButton); - connect(okBtn, &QPushButton::clicked, this, &VFileInfoDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VFileInfoDialog::reject); enableOkButton(); } @@ -25,19 +23,16 @@ void VFileInfoDialog::setupUI() nameEdit->selectAll(); nameLabel->setBuddy(nameEdit); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget(nameLabel); topLayout->addWidget(nameEdit); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); - + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -45,7 +40,7 @@ void VFileInfoDialog::setupUI() mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); + mainLayout->addWidget(m_btnBox); mainLayout->setSizeConstraint(QLayout::SetFixedSize); setLayout(mainLayout); @@ -54,6 +49,7 @@ void VFileInfoDialog::setupUI() void VFileInfoDialog::enableOkButton() { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!nameEdit->text().isEmpty()); } diff --git a/src/dialog/vfileinfodialog.h b/src/dialog/vfileinfodialog.h index e4f461c1..dc7fe462 100644 --- a/src/dialog/vfileinfodialog.h +++ b/src/dialog/vfileinfodialog.h @@ -5,7 +5,7 @@ class QLabel; class QLineEdit; -class QPushButton; +class QDialogButtonBox; class QString; class VFileInfoDialog : public QDialog @@ -25,8 +25,7 @@ private: QLabel *infoLabel; QLabel *nameLabel; QLineEdit *nameEdit; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info; diff --git a/src/dialog/vinsertimagedialog.cpp b/src/dialog/vinsertimagedialog.cpp index 86d475e6..bf80b316 100644 --- a/src/dialog/vinsertimagedialog.cpp +++ b/src/dialog/vinsertimagedialog.cpp @@ -13,8 +13,6 @@ VInsertImageDialog::VInsertImageDialog(const QString &title, const QString &defa connect(imageTitleEdit, &QLineEdit::textChanged, this, &VInsertImageDialog::enableOkButton); connect(pathEdit, &QLineEdit::textChanged, this, &VInsertImageDialog::enableOkButton); connect(browseBtn, &QPushButton::clicked, this, &VInsertImageDialog::handleBrowseBtnClicked); - connect(okBtn, &QPushButton::clicked, this, &VInsertImageDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VInsertImageDialog::reject); enableOkButton(); } @@ -52,21 +50,17 @@ void VInsertImageDialog::setupUI() topLayout->setColumnStretch(1, 1); topLayout->setColumnStretch(2, 0); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); - - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); imagePreviewLabel = new QLabel(); imagePreviewLabel->setVisible(false); QVBoxLayout *mainLayout = new QVBoxLayout(); mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); + mainLayout->addWidget(m_btnBox); mainLayout->addWidget(imagePreviewLabel); setLayout(mainLayout); mainLayout->setSizeConstraint(QLayout::SetFixedSize); @@ -79,6 +73,7 @@ void VInsertImageDialog::enableOkButton() if (imageTitleEdit->text().isEmpty() || !image) { enabled = false; } + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(enabled); } diff --git a/src/dialog/vinsertimagedialog.h b/src/dialog/vinsertimagedialog.h index e3f1adc4..b16b7cb8 100644 --- a/src/dialog/vinsertimagedialog.h +++ b/src/dialog/vinsertimagedialog.h @@ -9,6 +9,7 @@ class QLabel; class QLineEdit; class QPushButton; +class QDialogButtonBox; class VInsertImageDialog : public QDialog { @@ -40,8 +41,7 @@ private: QLabel *pathLabel; QLineEdit *pathEdit; QPushButton *browseBtn; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QLabel *imagePreviewLabel; QString title; diff --git a/src/dialog/vnewdirdialog.cpp b/src/dialog/vnewdirdialog.cpp index 124883d9..39686939 100644 --- a/src/dialog/vnewdirdialog.cpp +++ b/src/dialog/vnewdirdialog.cpp @@ -8,8 +8,6 @@ VNewDirDialog::VNewDirDialog(const QString &title, const QString &info, const QS setupUI(); connect(nameEdit, &QLineEdit::textChanged, this, &VNewDirDialog::enableOkButton); - connect(okBtn, &QPushButton::clicked, this, &VNewDirDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VNewDirDialog::reject); } void VNewDirDialog::setupUI() @@ -24,19 +22,16 @@ void VNewDirDialog::setupUI() nameEdit->selectAll(); nameLabel->setBuddy(nameEdit); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget(nameLabel); topLayout->addWidget(nameEdit); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); - + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -44,14 +39,15 @@ void VNewDirDialog::setupUI() mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); - setLayout(mainLayout); + mainLayout->addWidget(m_btnBox); mainLayout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(mainLayout); setWindowTitle(title); } void VNewDirDialog::enableOkButton(const QString &editText) { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!editText.isEmpty()); } diff --git a/src/dialog/vnewdirdialog.h b/src/dialog/vnewdirdialog.h index cf3e8e29..bef785df 100644 --- a/src/dialog/vnewdirdialog.h +++ b/src/dialog/vnewdirdialog.h @@ -5,7 +5,7 @@ class QLabel; class QLineEdit; -class QPushButton; +class QDialogButtonBox; class QString; class VNewDirDialog : public QDialog @@ -24,8 +24,7 @@ private: QLabel *nameLabel; QLineEdit *nameEdit; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info; diff --git a/src/dialog/vnewfiledialog.cpp b/src/dialog/vnewfiledialog.cpp index c4f72734..40c5796b 100644 --- a/src/dialog/vnewfiledialog.cpp +++ b/src/dialog/vnewfiledialog.cpp @@ -8,8 +8,6 @@ VNewFileDialog::VNewFileDialog(const QString &title, const QString &info, const setupUI(); connect(nameEdit, &QLineEdit::textChanged, this, &VNewFileDialog::enableOkButton); - connect(okBtn, &QPushButton::clicked, this, &VNewFileDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VNewFileDialog::reject); } void VNewFileDialog::setupUI() @@ -24,19 +22,16 @@ void VNewFileDialog::setupUI() nameEdit->selectAll(); nameLabel->setBuddy(nameEdit); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QHBoxLayout *topLayout = new QHBoxLayout(); topLayout->addWidget(nameLabel); topLayout->addWidget(nameEdit); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); - + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -44,14 +39,16 @@ void VNewFileDialog::setupUI() mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); - setLayout(mainLayout); + mainLayout->addWidget(m_btnBox); mainLayout->setSizeConstraint(QLayout::SetFixedSize); + setLayout(mainLayout); + setWindowTitle(title); } void VNewFileDialog::enableOkButton(const QString &editText) { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!editText.isEmpty()); } diff --git a/src/dialog/vnewfiledialog.h b/src/dialog/vnewfiledialog.h index b5e4e4aa..1ee1cc1f 100644 --- a/src/dialog/vnewfiledialog.h +++ b/src/dialog/vnewfiledialog.h @@ -5,7 +5,7 @@ class QLabel; class QLineEdit; -class QPushButton; +class QDialogButtonBox; class QString; class VNewFileDialog : public QDialog @@ -25,7 +25,7 @@ private: QLabel *nameLabel; QLineEdit *nameEdit; QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info; diff --git a/src/dialog/vnewnotebookdialog.cpp b/src/dialog/vnewnotebookdialog.cpp index 6f168150..650bed8c 100644 --- a/src/dialog/vnewnotebookdialog.cpp +++ b/src/dialog/vnewnotebookdialog.cpp @@ -13,8 +13,6 @@ VNewNotebookDialog::VNewNotebookDialog(const QString &title, const QString &info connect(nameEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::enableOkButton); connect(pathEdit, &QLineEdit::textChanged, this, &VNewNotebookDialog::enableOkButton); connect(browseBtn, &QPushButton::clicked, this, &VNewNotebookDialog::handleBrowseBtnClicked); - connect(okBtn, &QPushButton::clicked, this, &VNewNotebookDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VNewNotebookDialog::reject); enableOkButton(); } @@ -45,20 +43,17 @@ void VNewNotebookDialog::setupUI() topLayout->addWidget(browseBtn, 1, 2); topLayout->addWidget(importCheck, 2, 1); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); QVBoxLayout *mainLayout = new QVBoxLayout(); if (infoLabel) { mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); + mainLayout->addWidget(m_btnBox); setLayout(mainLayout); mainLayout->setSizeConstraint(QLayout::SetFixedSize); setWindowTitle(title); @@ -66,6 +61,7 @@ void VNewNotebookDialog::setupUI() void VNewNotebookDialog::enableOkButton() { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!pathEdit->text().isEmpty() && !nameEdit->text().isEmpty()); } diff --git a/src/dialog/vnewnotebookdialog.h b/src/dialog/vnewnotebookdialog.h index e2a212c1..11d4c6a4 100644 --- a/src/dialog/vnewnotebookdialog.h +++ b/src/dialog/vnewnotebookdialog.h @@ -8,6 +8,7 @@ class QLineEdit; class QPushButton; class QString; class QCheckBox; +class QDialogButtonBox; class VNewNotebookDialog : public QDialog { @@ -35,8 +36,7 @@ private: QLineEdit *pathEdit; QCheckBox *importCheck; QPushButton *browseBtn; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info; diff --git a/src/dialog/vnotebookinfodialog.cpp b/src/dialog/vnotebookinfodialog.cpp index 73b68044..d34149b6 100644 --- a/src/dialog/vnotebookinfodialog.cpp +++ b/src/dialog/vnotebookinfodialog.cpp @@ -10,8 +10,6 @@ VNotebookInfoDialog::VNotebookInfoDialog(const QString &title, const QString &in setupUI(); connect(nameEdit, &QLineEdit::textChanged, this, &VNotebookInfoDialog::enableOkButton); - connect(okBtn, &QPushButton::clicked, this, &VNotebookInfoDialog::accept); - connect(cancelBtn, &QPushButton::clicked, this, &VNotebookInfoDialog::reject); enableOkButton(); } @@ -35,14 +33,12 @@ void VNotebookInfoDialog::setupUI() topLayout->addRow(nameLabel, nameEdit); topLayout->addRow(pathLabel, pathEdit); - okBtn = new QPushButton(tr("&OK")); - okBtn->setDefault(true); - cancelBtn = new QPushButton(tr("&Cancel")); - QHBoxLayout *btmLayout = new QHBoxLayout(); - btmLayout->addStretch(); - btmLayout->addWidget(okBtn); - btmLayout->addWidget(cancelBtn); + // Ok is the default button. + m_btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(m_btnBox, &QDialogButtonBox::accepted, this, &QDialog::accept); + connect(m_btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); pathEdit->setMinimumWidth(okBtn->sizeHint().width() * 3); QVBoxLayout *mainLayout = new QVBoxLayout(); @@ -50,7 +46,7 @@ void VNotebookInfoDialog::setupUI() mainLayout->addWidget(infoLabel); } mainLayout->addLayout(topLayout); - mainLayout->addLayout(btmLayout); + mainLayout->addWidget(m_btnBox); setLayout(mainLayout); mainLayout->setSizeConstraint(QLayout::SetFixedSize); setWindowTitle(title); @@ -58,6 +54,7 @@ void VNotebookInfoDialog::setupUI() void VNotebookInfoDialog::enableOkButton() { + QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok); okBtn->setEnabled(!nameEdit->text().isEmpty()); } diff --git a/src/dialog/vnotebookinfodialog.h b/src/dialog/vnotebookinfodialog.h index ecc7958f..d882a058 100644 --- a/src/dialog/vnotebookinfodialog.h +++ b/src/dialog/vnotebookinfodialog.h @@ -5,7 +5,7 @@ class QLabel; class QLineEdit; -class QPushButton; +class QDialogButtonBox; class QString; class VNotebookInfoDialog : public QDialog @@ -26,8 +26,7 @@ private: QLabel *nameLabel; QLineEdit *nameEdit; QLineEdit *pathEdit; - QPushButton *okBtn; - QPushButton *cancelBtn; + QDialogButtonBox *m_btnBox; QString title; QString info;