ctkMessageBox.h 3.5 KB

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