color_selector.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * \file
  3. *
  4. * \author Mattia Basaglia
  5. *
  6. * \copyright Copyright (C) 2013-2020 Mattia Basaglia
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #ifndef COLOR_SELECTOR_HPP
  23. #define COLOR_SELECTOR_HPP
  24. #include "color_preview.hpp"
  25. #include "color_wheel.hpp"
  26. namespace color_widgets {
  27. /**
  28. * Color preview that opens a color dialog
  29. */
  30. class QCP_EXPORT ColorSelector : public ColorPreview
  31. {
  32. Q_OBJECT
  33. Q_ENUMS(UpdateMode)
  34. Q_PROPERTY(UpdateMode updateMode READ updateMode WRITE setUpdateMode NOTIFY updateModeChanged)
  35. Q_PROPERTY(Qt::WindowModality dialogModality READ dialogModality WRITE setDialogModality NOTIFY dialogModalityChanged)
  36. Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
  37. Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
  38. Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
  39. public:
  40. enum UpdateMode {
  41. Confirm, ///< Update color only after the dialog has been accepted
  42. Continuous ///< Update color as it's being modified in the dialog
  43. };
  44. explicit ColorSelector(QWidget *parent = 0);
  45. ~ColorSelector();
  46. void setUpdateMode(UpdateMode m);
  47. UpdateMode updateMode() const;
  48. Qt::WindowModality dialogModality() const;
  49. void setDialogModality(Qt::WindowModality m);
  50. ColorWheel::ShapeEnum wheelShape() const;
  51. ColorWheel::ColorSpaceEnum colorSpace() const;
  52. bool wheelRotating() const;
  53. Q_SIGNALS:
  54. void wheelShapeChanged(ColorWheel::ShapeEnum shape);
  55. void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
  56. void wheelRotatingChanged(bool rotating);
  57. void updateModeChanged(UpdateMode);
  58. void dialogModalityChanged(Qt::WindowModality);
  59. /// Emitted when a color is selected by the user
  60. void colorSelected(const QColor& c);
  61. public Q_SLOTS:
  62. void showDialog();
  63. void setWheelShape(ColorWheel::ShapeEnum shape);
  64. void setColorSpace(ColorWheel::ColorSpaceEnum space);
  65. void setWheelRotating(bool rotating);
  66. private Q_SLOTS:
  67. void accept_dialog();
  68. void reject_dialog();
  69. void update_old_color(const QColor &c);
  70. protected:
  71. void dragEnterEvent(QDragEnterEvent *event);
  72. void dropEvent(QDropEvent * event);
  73. private:
  74. /// Connect/Disconnect colorChanged based on UpdateMode
  75. void connect_dialog();
  76. /// Disconnect from dialog update
  77. void disconnect_dialog();
  78. class Private;
  79. Private * const p;
  80. };
  81. } // namespace color_widgets
  82. #endif // COLOR_SELECTOR_HPP