Improve dialog boxes.
authorAkos Polster <polster@marzipan.pipacs.com>
Mon, 26 Jul 2010 20:52:55 +0000 (22:52 +0200)
committerAkos Polster <polster@marzipan.pipacs.com>
Mon, 26 Jul 2010 20:52:55 +0000 (22:52 +0200)
book.h
bookmarkinfodialog.cpp
bookmarksdialog.cpp
bookmarksdialog.h
dialog.cpp
dialog.h
infodialog.cpp

diff --git a/book.h b/book.h
index 048280c..bf8e1c8 100644 (file)
--- a/book.h
+++ b/book.h
@@ -85,7 +85,7 @@ public:
 
     /**
      * Get friendly name.
-     * @return  @see title or path name if title is not available yet.
+     * @return @see title or path name if title is not available yet.
      */
     QString name() const;
 
index 83b6568..ca21963 100644 (file)
@@ -23,7 +23,7 @@ BookmarkInfoDialog::BookmarkInfoDialog(Book *b, int i, QWidget *parent):
     connect(read, SIGNAL(clicked()), this, SLOT(onRead()));
     connect(remove, SIGNAL(clicked()), this, SLOT(onRemove()));
     addButton(read, QDialogButtonBox::ActionRole);
-    addButton(remove, QDialogButtonBox::ActionRole);
+    addButton(remove, QDialogButtonBox::DestructiveRole);
 }
 
 void BookmarkInfoDialog::onRead()
@@ -33,5 +33,10 @@ void BookmarkInfoDialog::onRead()
 
 void BookmarkInfoDialog::onRemove()
 {
-    done(Delete);
+    if (QMessageBox::Yes ==
+        QMessageBox::question(this, tr("Delete bookmark"),
+                              tr("Delete bookmark?"),
+                              QMessageBox::Yes | QMessageBox::No)) {
+        done(Delete);
+    }
 }
index c0d1f1d..f7d2400 100644 (file)
@@ -31,12 +31,11 @@ BookmarksDialog::BookmarksDialog(Book *book_, QWidget *parent):
 #ifndef Q_WS_MAEMO_5
     QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
 
-    QPushButton *goButton = new QPushButton(tr("Go"), this);
+    QPushButton *goButton = new QPushButton(tr("Go to"), this);
     buttonBox->addButton(goButton, QDialogButtonBox::ActionRole);
     connect(goButton, SIGNAL(clicked()), this, SLOT(onGo()));
 
-    QPushButton *closeButton = new QPushButton(tr("Close"), this);
-    buttonBox->addButton(closeButton, QDialogButtonBox::AcceptRole);
+    QPushButton *closeButton = buttonBox->addButton(QDialogButtonBox::Close);
     connect(closeButton, SIGNAL(clicked()), this, SLOT(onClose()));
 
     QPushButton *addButton = new QPushButton(tr("Add"), this);
@@ -72,7 +71,7 @@ void BookmarksDialog::onItemActivated(QListWidgetItem *item)
         onGo();
         break;
     case BookmarkInfoDialog::Delete:
-        onDelete();
+        onDelete(true);
         break;
     default:
         ;
@@ -90,14 +89,23 @@ void BookmarksDialog::onClose()
     close();
 }
 
-void BookmarksDialog::onDelete()
+void BookmarksDialog::onDelete(bool really)
 {
-    if (!list->selectedItems().isEmpty()) {
-        QListWidgetItem *item = list->selectedItems()[0];
-        int row = list->row(item);
-        book->deleteBookmark(row);
-        delete item;
+    if (list->selectedItems().isEmpty()) {
+        return;
+    }
+    if (!really) {
+        if (QMessageBox::Yes !=
+            QMessageBox::question(this, tr("Delete bookmark"),
+                                  tr("Delete bookmark?"),
+                                  QMessageBox::Yes | QMessageBox::No)) {
+            return;
+        }
     }
+    QListWidgetItem *item = list->selectedItems()[0];
+    int row = list->row(item);
+    book->deleteBookmark(row);
+    delete item;
 }
 
 void BookmarksDialog::closeEvent(QCloseEvent *event)
index 6bfab27..3194b9b 100644 (file)
@@ -25,7 +25,7 @@ public slots:
     void onAdd();
     void onItemActivated(QListWidgetItem *);
     void onClose();
-    void onDelete();
+    void onDelete(bool really = false);
 
 protected:
     void closeEvent(QCloseEvent *e);
index e148ea6..f9aa474 100644 (file)
@@ -47,3 +47,8 @@ void Dialog::addButton(QPushButton *button, QDialogButtonBox::ButtonRole role)
 {
     buttonBox->addButton(button, role);
 }
+
+QPushButton *Dialog::addButton(QDialogButtonBox::StandardButton button)
+{
+    return buttonBox->addButton(button);
+}
index 6f7a160..0edd1c1 100644 (file)
--- a/dialog.h
+++ b/dialog.h
@@ -27,6 +27,9 @@ public:
     void addButton(QPushButton *button,
         QDialogButtonBox::ButtonRole role = QDialogButtonBox::AcceptRole);
 
+    /** Add standard button to the dialog button box. */
+    QPushButton *addButton(QDialogButtonBox::StandardButton button);
+
 protected:
     QScrollArea *scroller;
     QWidget *content;
index 202d906..03dcbf4 100644 (file)
@@ -47,7 +47,7 @@ InfoDialog::InfoDialog(Book *b, QWidget *parent): Dialog(parent), book(b)
     connect(read, SIGNAL(clicked()), this, SLOT(onReadBook()));
     connect(remove, SIGNAL(clicked()), this, SLOT(onRemoveBook()));
     addButton(read, QDialogButtonBox::ActionRole);
-    addButton(remove, QDialogButtonBox::ActionRole);
+    addButton(remove, QDialogButtonBox::DestructiveRole);
 }
 
 void InfoDialog::onReadBook()