ctkColorPickerButton.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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.commontk.org/LICENSE
  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 __ctkColorPickerButton_h
  15. #define __ctkColorPickerButton_h
  16. // Qt includes
  17. #include <QPushButton>
  18. #include <QColor>
  19. // CTK includes
  20. #include "ctkWidgetsExport.h"
  21. class ctkColorPickerButtonPrivate;
  22. ///
  23. /// ctkColorPickerButton is a QPushButton that refers to a color. The color
  24. /// and the name of the color (i.e. #FFFFFF) are displayed on the button.
  25. /// When clicked, a color dialog pops up to select a new color
  26. /// for the QPushButton.
  27. class CTK_WIDGETS_EXPORT ctkColorPickerButton : public QPushButton
  28. {
  29. Q_OBJECT
  30. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)
  31. Q_PROPERTY(bool displayColorName READ displayColorName WRITE setDisplayColorName DESIGNABLE true)
  32. Q_PROPERTY(bool showAlpha READ showAlpha WRITE setShowAlpha DESIGNABLE true)
  33. public:
  34. /// By default, the color is black
  35. explicit ctkColorPickerButton(QWidget* parent = 0);
  36. /// By default, the color is black. The text will be shown on the button if
  37. /// displayColorName is false, otherwise the color name is shown.
  38. /// \sa QPushButton::setText
  39. explicit ctkColorPickerButton(const QString& text, QWidget* parent = 0 );
  40. /// The text will be shown on the button if
  41. /// displayColorName is false, otherwise the color name is shown.
  42. /// \sa setColor, QPushButton::setText
  43. explicit ctkColorPickerButton(const QColor& color, const QString & text, QWidget* parent = 0 );
  44. virtual ~ctkColorPickerButton();
  45. ///
  46. /// Current selected color
  47. QColor color()const;
  48. ///
  49. /// Display the color name after color selection
  50. bool displayColorName()const;
  51. ///
  52. /// Returns true if alpha is shown on the color dialog
  53. /// \sa QColorDialog::ShowAlphaChannel
  54. void setShowAlpha(bool show);
  55. bool showAlpha()const;
  56. public slots:
  57. ///
  58. /// Set a new current color without opening a dialog
  59. void setColor(const QColor& color);
  60. ///
  61. /// Opens a color dialog to select a new current color.
  62. void changeColor();
  63. ///
  64. /// Toggle the display of the color name after color selection.
  65. /// By default, this is activated.
  66. void setDisplayColorName(bool displayColorName);
  67. signals:
  68. /// colorChanged is fired anytime a new color is set. Programatically or
  69. /// by the user when choosing a color from the color dialog
  70. void colorChanged(QColor);
  71. protected slots:
  72. void onToggled(bool change = true);
  73. protected:
  74. virtual void paintEvent(QPaintEvent* event);
  75. QScopedPointer<ctkColorPickerButtonPrivate> d_ptr;
  76. private :
  77. Q_DECLARE_PRIVATE(ctkColorPickerButton);
  78. Q_DISABLE_COPY(ctkColorPickerButton);
  79. };
  80. #endif