refine the layout of dialogs

Use gridlayout and formlayout to make a more beautiful dialog.

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2017-01-01 16:32:36 +08:00
parent 41abbb21d0
commit 9b6afa013d
9 changed files with 53 additions and 38 deletions

View File

@ -38,12 +38,15 @@ void VDirInfoDialog::setupUI()
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
btmLayout->addWidget(cancelBtn); btmLayout->addWidget(cancelBtn);
nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
} }
mainLayout->addLayout(topLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setLayout(mainLayout); setLayout(mainLayout);
setWindowTitle(title); setWindowTitle(title);

View File

@ -20,7 +20,7 @@ void VFileInfoDialog::setupUI()
if (!info.isEmpty()) { if (!info.isEmpty()) {
infoLabel = new QLabel(info); infoLabel = new QLabel(info);
} }
nameLabel = new QLabel(tr("&Name")); nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit(defaultName); nameEdit = new QLineEdit(defaultName);
nameEdit->selectAll(); nameEdit->selectAll();
nameLabel->setBuddy(nameEdit); nameLabel->setBuddy(nameEdit);
@ -38,12 +38,15 @@ void VFileInfoDialog::setupUI()
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
btmLayout->addWidget(cancelBtn); btmLayout->addWidget(cancelBtn);
nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
} }
mainLayout->addLayout(topLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setLayout(mainLayout); setLayout(mainLayout);
setWindowTitle(title); setWindowTitle(title);

View File

@ -33,30 +33,29 @@ void VInsertImageDialog::setupUI()
pathEdit = new QLineEdit(defaultPath); pathEdit = new QLineEdit(defaultPath);
pathLabel->setBuddy(pathEdit); pathLabel->setBuddy(pathEdit);
browseBtn = new QPushButton(tr("&Browse")); browseBtn = new QPushButton(tr("&Browse"));
QHBoxLayout *pathLayout = new QHBoxLayout();
pathLayout->addWidget(pathLabel);
pathLayout->addWidget(pathEdit);
pathLayout->addWidget(browseBtn);
imageTitleLabel = new QLabel(tr("&Title:")); imageTitleLabel = new QLabel(tr("&Image title:"));
imageTitleEdit = new QLineEdit(defaultImageTitle); imageTitleEdit = new QLineEdit(defaultImageTitle);
imageTitleEdit->selectAll(); imageTitleEdit->selectAll();
imageTitleLabel->setBuddy(imageTitleEdit); imageTitleLabel->setBuddy(imageTitleEdit);
QRegExp regExp("[\\w\\(\\)@#%\\*\\-\\+=\\?<>\\,\\.\\s]+"); QRegExp regExp("[\\w\\(\\)@#%\\*\\-\\+=\\?<>\\,\\.\\s]+");
QValidator *validator = new QRegExpValidator(regExp, this); QValidator *validator = new QRegExpValidator(regExp, this);
imageTitleEdit->setValidator(validator); imageTitleEdit->setValidator(validator);
QHBoxLayout *titleLayout = new QHBoxLayout();
titleLayout->addWidget(imageTitleLabel); QGridLayout *topLayout = new QGridLayout();
titleLayout->addWidget(imageTitleEdit); topLayout->addWidget(pathLabel, 0, 0);
topLayout->addWidget(pathEdit, 0, 1);
topLayout->addWidget(browseBtn, 0, 2);
topLayout->addWidget(imageTitleLabel, 1, 0);
topLayout->addWidget(imageTitleEdit, 1, 1, 1, 2);
topLayout->setColumnStretch(0, 0);
topLayout->setColumnStretch(1, 1);
topLayout->setColumnStretch(2, 0);
okBtn = new QPushButton(tr("&OK")); okBtn = new QPushButton(tr("&OK"));
okBtn->setDefault(true); okBtn->setDefault(true);
cancelBtn = new QPushButton(tr("&Cancel")); cancelBtn = new QPushButton(tr("&Cancel"));
QVBoxLayout *topLayout = new QVBoxLayout();
topLayout->addLayout(pathLayout);
topLayout->addLayout(titleLayout);
QHBoxLayout *btmLayout = new QHBoxLayout(); QHBoxLayout *btmLayout = new QHBoxLayout();
btmLayout->addStretch(); btmLayout->addStretch();
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
@ -70,7 +69,7 @@ void VInsertImageDialog::setupUI()
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
mainLayout->addWidget(imagePreviewLabel); mainLayout->addWidget(imagePreviewLabel);
setLayout(mainLayout); setLayout(mainLayout);
layout()->setSizeConstraint(QLayout::SetFixedSize); mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(title); setWindowTitle(title);
} }

View File

@ -37,6 +37,8 @@ void VNewDirDialog::setupUI()
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
btmLayout->addWidget(cancelBtn); btmLayout->addWidget(cancelBtn);
nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
@ -44,7 +46,7 @@ void VNewDirDialog::setupUI()
mainLayout->addLayout(topLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
setLayout(mainLayout); setLayout(mainLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(title); setWindowTitle(title);
} }

View File

@ -37,6 +37,8 @@ void VNewFileDialog::setupUI()
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
btmLayout->addWidget(cancelBtn); btmLayout->addWidget(cancelBtn);
nameEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
@ -44,7 +46,7 @@ void VNewFileDialog::setupUI()
mainLayout->addLayout(topLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
setLayout(mainLayout); setLayout(mainLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(title); setWindowTitle(title);
} }

View File

@ -26,25 +26,25 @@ void VNewNotebookDialog::setupUI()
} }
nameLabel = new QLabel(tr("Notebook &name:")); nameLabel = new QLabel(tr("Notebook &name:"));
nameEdit = new QLineEdit(defaultName); nameEdit = new QLineEdit(defaultName);
nameEdit->selectAll();
nameLabel->setBuddy(nameEdit); nameLabel->setBuddy(nameEdit);
QHBoxLayout *nameLayout = new QHBoxLayout();
nameLayout->addWidget(nameLabel);
nameLayout->addWidget(nameEdit);
QLabel *pathLabel = new QLabel(tr("Notebook &path:")); QLabel *pathLabel = new QLabel(tr("Notebook &path:"));
pathEdit = new QLineEdit(defaultPath); pathEdit = new QLineEdit(defaultPath);
pathLabel->setBuddy(pathEdit); pathLabel->setBuddy(pathEdit);
browseBtn = new QPushButton(tr("&Browse")); browseBtn = new QPushButton(tr("&Browse"));
QHBoxLayout *pathLayout = new QHBoxLayout();
pathLayout->addWidget(pathLabel);
pathLayout->addWidget(pathEdit);
pathLayout->addWidget(browseBtn);
importCheck = new QCheckBox(tr("Import existing notebook"), this); importCheck = new QCheckBox(tr("Import existing notebook"), this);
importCheck->setChecked(true); importCheck->setChecked(true);
importCheck->setToolTip(tr("When checked, VNote won't create a new config file if there already exists one.")); importCheck->setToolTip(tr("When checked, VNote won't create a new config file if there already exists one."));
QGridLayout *topLayout = new QGridLayout();
topLayout->addWidget(nameLabel, 0, 0);
topLayout->addWidget(nameEdit, 0, 1, 1, 2);
topLayout->addWidget(pathLabel, 1, 0);
topLayout->addWidget(pathEdit, 1, 1);
topLayout->addWidget(browseBtn, 1, 2);
topLayout->addWidget(importCheck, 2, 1);
okBtn = new QPushButton(tr("&OK")); okBtn = new QPushButton(tr("&OK"));
okBtn->setDefault(true); okBtn->setDefault(true);
cancelBtn = new QPushButton(tr("&Cancel")); cancelBtn = new QPushButton(tr("&Cancel"));
@ -57,12 +57,10 @@ void VNewNotebookDialog::setupUI()
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
} }
mainLayout->addLayout(nameLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(pathLayout);
mainLayout->addWidget(importCheck);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
setLayout(mainLayout); setLayout(mainLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(title); setWindowTitle(title);
} }
@ -92,3 +90,9 @@ bool VNewNotebookDialog::getImportCheck() const
{ {
return importCheck->isChecked(); return importCheck->isChecked();
} }
void VNewNotebookDialog::showEvent(QShowEvent *event)
{
nameEdit->setFocus();
QDialog::showEvent(event);
}

View File

@ -23,6 +23,9 @@ private slots:
void enableOkButton(); void enableOkButton();
void handleBrowseBtnClicked(); void handleBrowseBtnClicked();
protected:
void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
private: private:
void setupUI(); void setupUI();

View File

@ -25,17 +25,15 @@ void VNotebookInfoDialog::setupUI()
nameEdit = new QLineEdit(defaultName); nameEdit = new QLineEdit(defaultName);
nameEdit->selectAll(); nameEdit->selectAll();
nameLabel->setBuddy(nameEdit); nameLabel->setBuddy(nameEdit);
QHBoxLayout *nameLayout = new QHBoxLayout();
nameLayout->addWidget(nameLabel);
nameLayout->addWidget(nameEdit);
QLabel *pathLabel = new QLabel(tr("Notebook &path:")); QLabel *pathLabel = new QLabel(tr("Notebook &path:"));
pathEdit = new QLineEdit(defaultPath); pathEdit = new QLineEdit(defaultPath);
pathLabel->setBuddy(pathEdit); pathLabel->setBuddy(pathEdit);
pathEdit->setReadOnly(true); pathEdit->setReadOnly(true);
QHBoxLayout *pathLayout = new QHBoxLayout();
pathLayout->addWidget(pathLabel); QFormLayout *topLayout = new QFormLayout();
pathLayout->addWidget(pathEdit); topLayout->addRow(nameLabel, nameEdit);
topLayout->addRow(pathLabel, pathEdit);
okBtn = new QPushButton(tr("&OK")); okBtn = new QPushButton(tr("&OK"));
okBtn->setDefault(true); okBtn->setDefault(true);
@ -45,15 +43,16 @@ void VNotebookInfoDialog::setupUI()
btmLayout->addWidget(okBtn); btmLayout->addWidget(okBtn);
btmLayout->addWidget(cancelBtn); btmLayout->addWidget(cancelBtn);
pathEdit->setMinimumWidth(okBtn->sizeHint().width() * 3);
QVBoxLayout *mainLayout = new QVBoxLayout(); QVBoxLayout *mainLayout = new QVBoxLayout();
if (infoLabel) { if (infoLabel) {
mainLayout->addWidget(infoLabel); mainLayout->addWidget(infoLabel);
} }
mainLayout->addLayout(nameLayout); mainLayout->addLayout(topLayout);
mainLayout->addLayout(pathLayout);
mainLayout->addLayout(btmLayout); mainLayout->addLayout(btmLayout);
setLayout(mainLayout); setLayout(mainLayout);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
setWindowTitle(title); setWindowTitle(title);
} }

View File

@ -158,7 +158,7 @@ bool VNotebookSelector::newNotebook()
QString defaultPath; QString defaultPath;
do { do {
VNewNotebookDialog dialog(tr("Create notebook"), info, defaultName, VNewNotebookDialog dialog(tr("Create Notebook"), info, defaultName,
defaultPath, this); defaultPath, this);
if (dialog.exec() == QDialog::Accepted) { if (dialog.exec() == QDialog::Accepted) {
QString name = dialog.getNameInput(); QString name = dialog.getNameInput();