Browse Source

refine the layout of dialogs

Use gridlayout and formlayout to make a more beautiful dialog.

Signed-off-by: Le Tan <[email protected]>
Le Tan 9 years ago
parent
commit
9b6afa013d

+ 3 - 0
src/dialog/vdirinfodialog.cpp

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

+ 4 - 1
src/dialog/vfileinfodialog.cpp

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

+ 12 - 13
src/dialog/vinsertimagedialog.cpp

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

+ 3 - 1
src/dialog/vnewdirdialog.cpp

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

+ 3 - 1
src/dialog/vnewfiledialog.cpp

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

+ 16 - 12
src/dialog/vnewnotebookdialog.cpp

@@ -26,25 +26,25 @@ void VNewNotebookDialog::setupUI()
     }
     nameLabel = new QLabel(tr("Notebook &name:"));
     nameEdit = new QLineEdit(defaultName);
-    nameEdit->selectAll();
     nameLabel->setBuddy(nameEdit);
-    QHBoxLayout *nameLayout = new QHBoxLayout();
-    nameLayout->addWidget(nameLabel);
-    nameLayout->addWidget(nameEdit);
 
     QLabel *pathLabel = new QLabel(tr("Notebook &path:"));
     pathEdit = new QLineEdit(defaultPath);
     pathLabel->setBuddy(pathEdit);
     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->setChecked(true);
     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->setDefault(true);
     cancelBtn = new QPushButton(tr("&Cancel"));
@@ -57,12 +57,10 @@ void VNewNotebookDialog::setupUI()
     if (infoLabel) {
         mainLayout->addWidget(infoLabel);
     }
-    mainLayout->addLayout(nameLayout);
-    mainLayout->addLayout(pathLayout);
-    mainLayout->addWidget(importCheck);
+    mainLayout->addLayout(topLayout);
     mainLayout->addLayout(btmLayout);
     setLayout(mainLayout);
-
+    mainLayout->setSizeConstraint(QLayout::SetFixedSize);
     setWindowTitle(title);
 }
 
@@ -92,3 +90,9 @@ bool VNewNotebookDialog::getImportCheck() const
 {
     return importCheck->isChecked();
 }
+
+void VNewNotebookDialog::showEvent(QShowEvent *event)
+{
+    nameEdit->setFocus();
+    QDialog::showEvent(event);
+}

+ 3 - 0
src/dialog/vnewnotebookdialog.h

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

+ 8 - 9
src/dialog/vnotebookinfodialog.cpp

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

+ 1 - 1
src/vnotebookselector.cpp

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