ctkMessageBox.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 __ctkMessageBox_h
  15. #define __ctkMessageBox_h
  16. // Qt includes
  17. #include <QMessageBox>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkMessageBoxPrivate;
  21. /// \ingroup Widgets
  22. /// ctkMessageBox is an advanced QMessageBox with extra features such as a
  23. /// checkbox to automatically accept the messagebox next time exec() is called.
  24. class CTK_WIDGETS_EXPORT ctkMessageBox : public QMessageBox
  25. {
  26. Q_OBJECT
  27. /// This property controls the visibility of the "Don't show again" checkbox.
  28. /// Even if the checkbox is not visible, the dialog is not not shown if
  29. /// \a dontShowAgain is true.
  30. /// By default, the "Don't show again" checkbox is not visible.
  31. Q_PROPERTY(bool dontShowAgainVisible READ isDontShowAgainVisible WRITE setDontShowAgainVisible)
  32. /// This property holds wether the dialog should be shown next time exec()
  33. /// is called.
  34. /// \a dontShowAgain can be changed programatically by calling
  35. /// setDontShowAgain or when the user checks the "Dont show again"
  36. /// checkbox and the dialog is accepted.
  37. /// If the checkbox is checked by the user but the dialog is rejected (click
  38. /// on Cancel), \a dontShowAgain is not changed.
  39. /// If \a dontShowAgainSettingsKey is set, the \a dontShowAgain is set with
  40. /// the value of the key.
  41. /// By default, dontShowAgain is false.
  42. Q_PROPERTY(bool dontShowAgain READ dontShowAgain WRITE setDontShowAgain)
  43. /// This property holds the settings key that is used to synchronize the state
  44. /// of the checkbox "Don't show this message again"
  45. /// with the given key value within QSettings. If the settings value is !=
  46. /// QMessageBox::InvalidRole, the dialog is shown, otherwise it is skipped by
  47. /// simulating a click on the button corresponding to the settings value (QMessageButton::StandardButton or
  48. /// QMessageBox::ButtonRole)
  49. /// By default, no key is set.
  50. Q_PROPERTY(QString dontShowAgainSettingsKey READ dontShowAgainSettingsKey WRITE setDontShowAgainSettingsKey)
  51. public:
  52. typedef QMessageBox Superclass;
  53. ctkMessageBox(QWidget* newParent = 0);
  54. ctkMessageBox(Icon icon, const QString & title, const QString & text, StandardButtons buttons = NoButton,
  55. QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint );
  56. virtual ~ctkMessageBox();
  57. void setDontShowAgainVisible(bool visible);
  58. bool isDontShowAgainVisible()const;
  59. bool dontShowAgain()const;
  60. void setDontShowAgainSettingsKey(const QString& key);
  61. QString dontShowAgainSettingsKey()const;
  62. /// Utility function that opens a dialog to confirm exit.
  63. /// If \a dontShowAgainKey is empty, the dontShowAgain checkbox is hidden
  64. /// and the message box is always open for the user to confirm exit.
  65. static bool confirmExit(const QString& dontShowAgainKey = QString(),
  66. QWidget* parentWidget = 0);
  67. /// Reimplemented for internal reasons
  68. virtual void setVisible(bool visible);
  69. /// Reimplemented for internal reasons
  70. virtual void done(int resultCode);
  71. public Q_SLOTS:
  72. /// Change the checkbox and the settings if any
  73. void setDontShowAgain(bool dontShow);
  74. protected:
  75. QScopedPointer<ctkMessageBoxPrivate> d_ptr;
  76. private:
  77. Q_DECLARE_PRIVATE(ctkMessageBox);
  78. Q_DISABLE_COPY(ctkMessageBox);
  79. };
  80. #endif