ctkColorPickerButton.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. ///
  22. /// ctkColorPickerButton is a QPushButton that refers to a color. The color
  23. /// and the name of the color (i.e. #FFFFFF) are displayed on the button.
  24. /// When clicked, a color dialog pops up to select a new color
  25. /// for the QPushButton.
  26. class CTK_WIDGETS_EXPORT ctkColorPickerButton : public QPushButton
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged USER true)
  30. Q_PROPERTY(bool displayColorName READ displayColorName WRITE setDisplayColorName DESIGNABLE true)
  31. public:
  32. /// By default, the color is black
  33. explicit ctkColorPickerButton(QWidget* parent = 0);
  34. /// By default, the color is black
  35. explicit ctkColorPickerButton(const QString& text, QWidget* parent = 0 );
  36. explicit ctkColorPickerButton(const QColor& color, const QString & text, QWidget* parent = 0 );
  37. virtual ~ctkColorPickerButton();
  38. ///
  39. /// Current selected color
  40. QColor color()const;
  41. ///
  42. /// Display the color name after color selection
  43. bool displayColorName()const;
  44. public slots:
  45. ///
  46. /// Set a new current color without opening a dialog
  47. void setColor(const QColor& color);
  48. ///
  49. /// Opens a color dialog to select a new current color.
  50. void changeColor();
  51. ///
  52. /// Toggle the display of the color name after color selection.
  53. /// By default, this is activated.
  54. void setDisplayColorName(bool displayColorName);
  55. signals:
  56. /// colorChanged is fired anytime a new color is set. Programatically or
  57. /// by the user when choosing a color from the color dialog
  58. void colorChanged(QColor);
  59. protected slots:
  60. void onToggled(bool change = true);
  61. protected:
  62. QColor Color;
  63. bool DisplayColorName;
  64. };
  65. #endif