ctkSettingsDialog.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. public:
  34. /// Superclass typedef
  35. typedef QDialog Superclass;
  36. /// Constructor
  37. explicit ctkSettingsDialog(QWidget* parent = 0);
  38. /// Destructor
  39. virtual ~ctkSettingsDialog();
  40. QSettings* settings()const;
  41. void setSettings(QSettings* settings);
  42. ctkSettingsPanel* panel(const QString& panel)const;
  43. ctkSettingsPanel* currentPanel()const;
  44. /// Uses the ctkSettingsPanel::windowTitle property to show in the list
  45. void addPanel(ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
  46. /// Utility function
  47. void addPanel(const QString& label, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
  48. void addPanel(const QString& label, const QIcon& icon, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
  49. bool resetButton()const;
  50. void setResetButton(bool show);
  51. /// True if at least one OptionRestartRequired setting is changed.
  52. /// It doesn't mean the user accepted to restart the application
  53. /// \sa restartRequired
  54. bool isRestartRequired()const;
  55. public Q_SLOTS:
  56. void setCurrentPanel(ctkSettingsPanel* panel);
  57. void setCurrentPanel(const QString& label);
  58. void applySettings();
  59. void resetSettings();
  60. void restoreDefaultSettings();
  61. virtual void accept();
  62. virtual void reject();
  63. /// Resize the left panel based on the panels titles.
  64. void adjustTreeWidgetToContents();
  65. Q_SIGNALS:
  66. void settingChanged(const QString& key, const QVariant& value);
  67. /// Signal fired when the user accepts to restart the application because
  68. /// some OptionRestartRequired settings have changed.
  69. /// \sa isrestartRequired
  70. void restartRequested();
  71. protected Q_SLOTS:
  72. void onSettingChanged(const QString& key, const QVariant& newVal);
  73. void onCurrentItemChanged(QTreeWidgetItem* currentItem, QTreeWidgetItem* previous);
  74. void onDialogButtonClicked(QAbstractButton* button);
  75. protected:
  76. virtual bool event(QEvent *);
  77. protected:
  78. QScopedPointer<ctkSettingsDialogPrivate> d_ptr;
  79. private:
  80. Q_DECLARE_PRIVATE(ctkSettingsDialog);
  81. Q_DISABLE_COPY(ctkSettingsDialog);
  82. };
  83. #endif