ctkMessageBox.h 4.0 KB

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