mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
refine dialogs
Use QDialogButtonBox in all dialogs.
This commit is contained in:
parent
c83fcf6ce9
commit
517d1ed139
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user