changeset 341:1fc2e0269ae0 help

Add Help button to multi-choice dialog
author Chris Cannam
date Tue, 15 Mar 2011 12:36:26 +0000
parents bb189827f6d1
children 0329bbd4b57c
files mainwindow.cpp multichoicedialog.cpp multichoicedialog.h
diffstat 3 files changed, 32 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mainwindow.cpp	Tue Mar 15 12:00:31 2011 +0000
+++ b/mainwindow.cpp	Tue Mar 15 12:36:26 2011 +0000
@@ -1053,6 +1053,7 @@
         MultiChoiceDialog *d = new MultiChoiceDialog
                                (tr("Open Repository"),
                                 tr("<qt><big>What would you like to open?</big></qt>"),
+                                tr("https://code.soundsoftware.ac.uk/projects/easyhg/wiki/HelpOpenDialog"),
                                 this);
 
         d->addChoice("local",
@@ -1134,6 +1135,7 @@
     MultiChoiceDialog *d = new MultiChoiceDialog
         (tr("Change Remote Location"),
          tr("<qt><big>Change the remote location</big></qt>"),
+         "",
          this);
 
     d->addChoice("remote",
--- a/multichoicedialog.cpp	Tue Mar 15 12:00:31 2011 +0000
+++ b/multichoicedialog.cpp	Tue Mar 15 12:36:26 2011 +0000
@@ -27,10 +27,13 @@
 #include <QFont>
 #include <QDir>
 #include <QFileDialog>
+#include <QDesktopServices>
 #include <QUrl>
 
-MultiChoiceDialog::MultiChoiceDialog(QString title, QString heading, QWidget *parent) :
-    QDialog(parent)
+MultiChoiceDialog::MultiChoiceDialog(QString title, QString heading,
+                                     QString helpUrl, QWidget *parent) :
+    QDialog(parent),
+    m_helpUrl(helpUrl)
 {
     setModal(true);
     setWindowTitle(title);
@@ -77,11 +80,21 @@
     outer->addWidget(m_browseButton, 4, 2);
     connect(m_browseButton, SIGNAL(clicked()), this, SLOT(browse()));
 
-    QDialogButtonBox *bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
-                                                  QDialogButtonBox::Cancel);
+    outer->addItem(new QSpacerItem(2, 12), 5, 0);
+
+    QDialogButtonBox *bbox;
+    if (helpUrl != "") {
+        bbox = new QDialogButtonBox(QDialogButtonBox::Help |
+                                    QDialogButtonBox::Ok |
+                                    QDialogButtonBox::Cancel);
+    } else {
+        bbox = new QDialogButtonBox(QDialogButtonBox::Ok |
+                                    QDialogButtonBox::Cancel);
+    }        
     connect(bbox, SIGNAL(accepted()), this, SLOT(accept()));
     connect(bbox, SIGNAL(rejected()), this, SLOT(reject()));
-    outer->addWidget(bbox, 5, 0, 1, 3);
+    connect(bbox, SIGNAL(helpRequested()), this, SLOT(helpRequested()));
+    outer->addWidget(bbox, 6, 0, 1, 3);
 
     m_okButton = bbox->button(QDialogButtonBox::Ok);
     updateOkButton();
@@ -89,6 +102,12 @@
     setMinimumWidth(480);
 }
 
+void
+MultiChoiceDialog::helpRequested()
+{
+    QDesktopServices::openUrl(m_helpUrl);
+}
+
 QString
 MultiChoiceDialog::getCurrentChoice()
 {
--- a/multichoicedialog.h	Tue Mar 15 12:00:31 2011 +0000
+++ b/multichoicedialog.h	Tue Mar 15 12:36:26 2011 +0000
@@ -36,7 +36,9 @@
 {
     Q_OBJECT
 public:
-    explicit MultiChoiceDialog(QString title, QString heading,
+    explicit MultiChoiceDialog(QString title,
+                               QString heading,
+                               QString helpUrl = "",
                                QWidget *parent = 0);
 
     enum ArgType {
@@ -62,11 +64,14 @@
     void choiceChanged();
     void urlChanged(const QString &);
     void fileChanged(const QString &);
+    void helpRequested();
     void browse();
 
 private:
     void updateOkButton();
     
+    QString m_helpUrl;
+
     QMap<QString, QString> m_texts;
     QMap<QString, QString> m_descriptions;
     QMap<QString, ArgType> m_argTypes;