瀏覽代碼

Add cancel button in ctkSettingsDialog

Hide the reset button by default.
Julien Finet 13 年之前
父節點
當前提交
9f5fbc0c16

+ 1 - 1
Libs/Widgets/Resources/UI/ctkSettingsDialog.ui

@@ -35,7 +35,7 @@
       <enum>Qt::Horizontal</enum>
      </property>
      <property name="standardButtons">
-      <set>QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset|QDialogButtonBox::RestoreDefaults</set>
      </property>
     </widget>
    </item>

+ 27 - 0
Libs/Widgets/ctkSettingsDialog.cpp

@@ -69,6 +69,17 @@ void ctkSettingsDialogPrivate::init()
 
   this->setupUi(q);
 
+  this->SettingsButtonBox->button(QDialogButtonBox::Ok)->setToolTip(
+    q->tr("Apply settings and close dialog."));
+  this->SettingsButtonBox->button(QDialogButtonBox::Cancel)->setToolTip(
+    q->tr("Reject settings changes and close dialog."));
+  this->SettingsButtonBox->button(QDialogButtonBox::Reset)->setToolTip(
+    q->tr("Reset settings to their values when the dialog opened"));
+  this->SettingsButtonBox->button(QDialogButtonBox::RestoreDefaults)->setToolTip(
+    q->tr("Restore settings to their default values."
+    "To cancel a \"Restore\", you can \"Reset\" the settings."));
+  this->setResetButton(false);
+
   q->setSettings(new QSettings(q));
 
   QObject::connect(this->SettingsTreeWidget,
@@ -327,3 +338,19 @@ bool ctkSettingsDialog::event(QEvent* event)
     }
   return this->Superclass::event(event);
 }
+
+// -------------------------------------------------------------------------
+bool ctkSettingsDialog::resetButton()const
+{
+  Q_D(const ctkSettingsDialog);
+  return d->SettingsButtonBox->button(QDialogButtonBox::Reset)->isVisibleTo(
+    const_cast<QDialogButtonBox*>(d->SettingsButtonBox));
+}
+
+// -------------------------------------------------------------------------
+void ctkSettingsDialog::setResetButton(bool show)
+{
+  Q_D(ctkSettingsDialog);
+  d->SettingsButtonBox->button(QDialogButtonBox::Reset)->setVisible(show);
+}
+

+ 9 - 1
Libs/Widgets/ctkSettingsDialog.h

@@ -37,6 +37,11 @@ class ctkSettingsPanel;
 class CTK_WIDGETS_EXPORT ctkSettingsDialog : public QDialog
 {
   Q_OBJECT
+  /// This property controls whether the reset button is visible in the
+  /// button box or not. The Cancel button is a reset button and closes
+  /// the dialog at the same time.
+  Q_PROPERTY(bool resetButton READ resetButton WRITE setResetButton);
+
 public:
   /// Superclass typedef
   typedef QDialog Superclass;
@@ -55,12 +60,15 @@ public:
 
   /// Uses the ctkSettingsPanel::windowTitle property to show in the list
   void addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
-  /// Utility function 
+  /// Utility function
   void addPanel(const QString& label, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
   void addPanel(const QString& label, const QIcon& icon, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
 
   void adjustTreeWidgetToContents();
 
+  bool resetButton()const;
+  void setResetButton(bool show);
+
 public Q_SLOTS:
   void setCurrentPanel(ctkSettingsPanel* panel);
   void setCurrentPanel(const QString& label);