ctkSettingsDialog.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkSettingsDialog_h
  15. #define __ctkSettingsDialog_h
  16. // Qt includes
  17. #include <QDialog>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class QAbstractButton;
  21. class QSettings;
  22. class QTreeWidgetItem;
  23. class ctkSettingsDialogPrivate;
  24. class ctkSettingsPanel;
  25. /// \ingroup Widgets
  26. class CTK_WIDGETS_EXPORT ctkSettingsDialog : public QDialog
  27. {
  28. Q_OBJECT
  29. /// This property controls whether the reset button is visible in the
  30. /// button box or not. The Cancel button is a reset button and closes
  31. /// the dialog at the same time.
  32. Q_PROPERTY(bool resetButton READ resetButton WRITE setResetButton);
  33. Q_PROPERTY(QSettings* settings READ settings WRITE setSettings);
  34. Q_PROPERTY(ctkSettingsPanel* currentPanel READ currentPanel WRITE setCurrentPanel);
  35. /// Specifies if a restart required to fully apply changes.
  36. ///
  37. /// This property is \c true if at least one OptionRestartRequired setting is
  38. /// changed. It doesn't imply that the user accepted to restart the
  39. /// application.
  40. Q_PROPERTY(bool restartRequired READ isRestartRequired);
  41. public:
  42. /// Superclass typedef
  43. typedef QDialog Superclass;
  44. /// Constructor
  45. explicit ctkSettingsDialog(QWidget* parent = 0);
  46. /// Destructor
  47. virtual ~ctkSettingsDialog();
  48. QSettings* settings()const;
  49. void setSettings(QSettings* settings);
  50. ctkSettingsPanel* panel(const QString& panel)const;
  51. ctkSettingsPanel* currentPanel()const;
  52. /// Add settings panel to the dialog.
  53. ///
  54. /// This adds the specified settings panel to the dialog. The panel's
  55. /// QWidget::windowTitle property is used as the panel name as shown in the
  56. /// panels list.
  57. Q_INVOKABLE void addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
  58. /// \copybrief addPanel
  59. ///
  60. /// This convenience overload allows the caller to specify the panel name
  61. /// that will be used in the panels list.
  62. Q_INVOKABLE void addPanel(const QString& label, ctkSettingsPanel* panel,
  63. ctkSettingsPanel* parentPanel = 0);
  64. /// \copybrief addPanel
  65. ///
  66. /// This convenience overload allows the caller to specify the panel name
  67. /// that will be used in the panels list, as well as an icon for the panel.
  68. Q_INVOKABLE void addPanel(const QString& label, const QIcon& icon,
  69. ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
  70. bool resetButton()const;
  71. void setResetButton(bool show);
  72. /// \copybrief restartRequired
  73. /// \sa restartRequired, restartRequested
  74. bool isRestartRequired()const;
  75. public Q_SLOTS:
  76. void setCurrentPanel(ctkSettingsPanel* panel);
  77. void setCurrentPanel(const QString& label);
  78. void applySettings();
  79. void resetSettings();
  80. void restoreDefaultSettings();
  81. /// Reload settings for all registered panels.
  82. ///
  83. /// This reloads the settings for all panels, effectively throwing out any
  84. /// values in the UI or the panels' caches and reverting to the values in the
  85. /// associated QSettings. You should call this if you have made changes to
  86. /// the QSettings that were not made through ctkSettingsPanel.
  87. void reloadSettings();
  88. virtual void accept();
  89. virtual void reject();
  90. /// Resize the left panel based on the panels titles.
  91. void adjustTreeWidgetToContents();
  92. Q_SIGNALS:
  93. void settingChanged(const QString& key, const QVariant& value);
  94. /// Signal fired when the user accepts to restart the application because
  95. /// some OptionRestartRequired settings have changed.
  96. /// \sa isrestartRequired
  97. void restartRequested();
  98. protected Q_SLOTS:
  99. void onSettingChanged(const QString& key, const QVariant& newVal);
  100. void onCurrentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previous);
  101. void onDialogButtonClicked(QAbstractButton* button);
  102. protected:
  103. virtual bool event(QEvent *);
  104. protected:
  105. QScopedPointer<ctkSettingsDialogPrivate> d_ptr;
  106. private:
  107. Q_DECLARE_PRIVATE(ctkSettingsDialog);
  108. Q_DISABLE_COPY(ctkSettingsDialog);
  109. };
  110. #endif