Warning, file /office/calligra/libs/widgets/KoDualColorButton.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE libraries 0002 0003 Copyright (C) 1999 Daniel M. Duley <mosfet@kde.org> 0004 2006 Tobias Koenig <tokoe@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License version 2 as published by the Free Software Foundation. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KODUALCOLORBUTTON_H 0022 #define KODUALCOLORBUTTON_H 0023 0024 #include "kowidgets_export.h" 0025 0026 #include <QWidget> 0027 0028 class KoColor; 0029 class KoColorDisplayRendererInterface; 0030 0031 /** 0032 * @short A widget for selecting two related colors. 0033 * 0034 * KoDualColorButton allows the user to select two cascaded colors (usually a 0035 * foreground and background color). Other features include drag and drop 0036 * from other KDE color widgets, a reset to black and white control, and a 0037 * swap colors control. 0038 * 0039 * When the user clicks on the foreground or background rectangle the 0040 * rectangle is first sunken and the selectionChanged() signal is emitted. 0041 * Further clicks will present a color dialog and emit either the foregroundColorChanged() 0042 * or backgroundColorChanged() if a new color is selected. 0043 * 0044 * Note: With drag and drop when dropping a color the current selected color 0045 * will be set, while when dragging a color it will use whatever color 0046 * rectangle the mouse was pressed inside. 0047 * 0048 * @author Daniel M. Duley <mosfet@kde.org> 0049 */ 0050 class KOWIDGETS_EXPORT KoDualColorButton : public QWidget 0051 { 0052 Q_OBJECT 0053 Q_ENUMS( Selection ) 0054 Q_PROPERTY( KoColor foregroundColor READ foregroundColor WRITE setForegroundColor ) 0055 Q_PROPERTY( KoColor backgroundColor READ backgroundColor WRITE setBackgroundColor ) 0056 Q_PROPERTY( bool popDialog READ popDialog WRITE setPopDialog ) 0057 0058 0059 public: 0060 enum Selection { 0061 Foreground, 0062 Background 0063 }; 0064 0065 /** 0066 * Constructs a new KoDualColorButton with the supplied foreground and 0067 * background colors. 0068 * 0069 * @param parent The parent widget of the KoDualColorButton. 0070 * @param dialogParent The parent widget of the color selection dialog. 0071 */ 0072 KoDualColorButton(const KoColor &foregroundColor, const KoColor &backgroundColor, 0073 QWidget *parent = nullptr, QWidget* dialogParent = nullptr ); 0074 0075 KoDualColorButton(const KoColor &foregroundColor, const KoColor &backgroundColor, 0076 const KoColorDisplayRendererInterface *displayRenderer, 0077 QWidget *parent = nullptr, QWidget* dialogParent = nullptr); 0078 0079 /** 0080 * Destroys the KoDualColorButton. 0081 */ 0082 ~KoDualColorButton() override; 0083 0084 /** 0085 * Returns the current foreground color. 0086 */ 0087 KoColor foregroundColor() const; 0088 0089 /** 0090 * Returns the current background color. 0091 */ 0092 KoColor backgroundColor() const; 0093 0094 /** 0095 * Returns if a dialog with a color chooser will be popped up when clicking 0096 * If false then you could/should connect to the pleasePopDialog signal 0097 * and pop your own dialog. Just set the current color afterwards. 0098 */ 0099 bool popDialog() const; 0100 0101 /** 0102 * Returns the minimum size needed to display the widget and all its 0103 * controls. 0104 */ 0105 QSize sizeHint() const override; 0106 0107 public Q_SLOTS: 0108 /** 0109 * Sets the foreground color. 0110 */ 0111 void setForegroundColor( const KoColor &color ); 0112 0113 /** 0114 * Sets the background color. 0115 */ 0116 void setBackgroundColor( const KoColor &color ); 0117 0118 /** 0119 * Sets if a dialog with a color chooser should be popped up when clicking 0120 * If you set this to false then you could connect to the pleasePopDialog signal 0121 * and pop your own dialog. Just set the current color afterwards. 0122 */ 0123 void setPopDialog( bool popDialog ); 0124 0125 Q_SIGNALS: 0126 /** 0127 * Emitted when the foreground color is changed. 0128 */ 0129 void foregroundColorChanged( const KoColor &color ); 0130 0131 /** 0132 * Emitted when the background color is changed. 0133 */ 0134 void backgroundColorChanged( const KoColor &color ); 0135 0136 /** 0137 * Emitted when the user clicks one of the two color patches. 0138 * You should/could pop you own color chooser dialog in response. 0139 * Also see the popDialog attribute. 0140 */ 0141 void pleasePopDialog( const KoColor &color ); 0142 0143 protected: 0144 /** 0145 * Sets the supplied rectangles to the proper size and position for the 0146 * current widget size. You can reimplement this to change the layout 0147 * of the widget. Restrictions are that the swap control will always 0148 * be at the top right, the reset control will always be at the bottom 0149 * left, and you must leave at least a 14x14 space in those corners. 0150 */ 0151 virtual void metrics( QRect &foregroundRect, QRect &backgroundRect ); 0152 0153 void paintEvent( QPaintEvent *event ) override; 0154 void mousePressEvent( QMouseEvent *event ) override; 0155 void mouseMoveEvent( QMouseEvent *event ) override; 0156 void mouseReleaseEvent( QMouseEvent *event ) override; 0157 void dragEnterEvent( QDragEnterEvent *event ) override; 0158 void dropEvent( QDropEvent *event ) override; 0159 void changeEvent(QEvent *event) override; 0160 0161 private: 0162 class Private; 0163 Private *const d; 0164 }; 0165 0166 #endif 0167