ctkColorDialog.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 __ctkColorDialog_h
  15. #define __ctkColorDialog_h
  16. // Qt includes
  17. #include <QColorDialog>
  18. // CTK includes
  19. #include "ctkWidgetsExport.h"
  20. class ctkColorDialogPrivate;
  21. /// Customizable QColorDialog.
  22. /// Extra widgets can be added to the left of the dialog into a QStackedWidget
  23. class CTK_WIDGETS_EXPORT ctkColorDialog : public QColorDialog
  24. {
  25. Q_OBJECT
  26. public:
  27. /// Constructor
  28. /// By default, behaves like a QColorDialog
  29. /// \sa QColorDialog()
  30. explicit ctkColorDialog(QWidget* parent = 0);
  31. explicit ctkColorDialog(const QColor& initial, QWidget* parent = 0);
  32. virtual ~ctkColorDialog();
  33. /// Add an extra widget under the file format combobox. If a label is
  34. /// given, it will appear in the first column.
  35. /// The widget is reparented to ctkColorDialog
  36. /// The ownership of the widget is taken.
  37. /// You must manually connect the color changed signal of the widget
  38. /// to ctkColorDialog::setColor(QColor)
  39. void addTab(QWidget* widget, const QString& label);
  40. /// The ownership of widget remains the same. The widget is not deleted,
  41. /// but simply removed from the widget's stacked layout, causing it to be
  42. /// hidden.
  43. /// It is not possible to remove the "Basic Colors" tab
  44. void removeTab(int index);
  45. /// Return the extra widget if any
  46. /// It is not possible to retrieave the "Basic colors" tab
  47. QWidget* widget(int index)const;
  48. /// Returns the index position of the page occupied by the widget w,
  49. /// or -1 if the widget cannot be found
  50. int indexOf(QWidget* widget)const;
  51. /// Pops up a modal color dialog with the given window \a title (or "Select Color" if none is
  52. /// specified), lets the user choose a color, and returns that color. The color is initially set
  53. /// to \a initial. The dialog is a child of \a parent. It returns an invalid (see
  54. /// QColor::isValid()) color if the user cancels the dialog.
  55. ///
  56. /// The \a options argument allows you to customize the dialog;
  57. /// QColorDialog::DontUseNativeDialog is forced
  58. static QColor getColor(const QColor &initial, QWidget *parent,
  59. const QString &title, ColorDialogOptions options = 0);
  60. /// Add a custom widget as an additional tab of the color dialog created by
  61. /// ctkColorDialog::getColor. \a label is title of the tab and \a signal is the signal fired by
  62. /// the widget whenever a QColor is changed, typically: SIGNAL(currentColorChanged(QColor)). It
  63. /// is internally connected to set the current color of the dialog
  64. static void addDefaultTab(QWidget* widget, const QString& label, const char* signal = 0);
  65. public slots:
  66. /// Slotify QColorDialog::setCurrentColor(QColor)
  67. void setColor(const QColor& color);
  68. protected:
  69. QScopedPointer<ctkColorDialogPrivate> d_ptr;
  70. static QList<QWidget*> DefaultTabs;
  71. private:
  72. Q_DECLARE_PRIVATE(ctkColorDialog);
  73. Q_DISABLE_COPY(ctkColorDialog);
  74. };
  75. #endif