1 /***************************************************************************
2 * Copyright (C) 2010 by Till Theato (root@ttill.de) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #ifndef COLORPICKERWIDGET_H
22 #define COLORPICKERWIDGET_H
34 class MyFrame : public QFrame
38 explicit MyFrame(QWidget* parent = 0);
41 void hideEvent ( QHideEvent * event );
48 * @class ColorPickerWidget
49 * @brief A widget to pick a color anywhere on the screen.
52 * The code is partially based on the color picker in KColorDialog.
55 class ColorPickerWidget : public QWidget
60 /** @brief Sets up the widget. */
61 explicit ColorPickerWidget(QWidget *parent = 0);
62 /** @brief Makes sure the event filter is removed. */
63 virtual ~ColorPickerWidget();
66 virtual void mousePressEvent(QMouseEvent *event);
67 virtual void mouseReleaseEvent(QMouseEvent *event);
68 virtual void mouseMoveEvent(QMouseEvent *event);
69 bool eventFilter(QObject *object, QEvent *event);
72 /** @brief Closes the event filter and makes mouse and keyboard work again on other widgets/windows. */
73 void closeEventFilter();
75 /** @brief Color of the screen at point @param p.
76 * @param p Position of color requested
77 * @param destroyImage (optional) Whether or not to keep the XImage in m_image
78 (needed for fast processing of rects) */
79 QColor grabColor(const QPoint &p, bool destroyImage = true);
83 QFrame *m_grabRectFrame;
91 /** @brief Sets up an event filter for picking a color. */
92 void slotSetupEventFilter();
94 /** @brief Calculates the average color for the pixels in the rect m_grabRect and emits colorPicked. */
95 void slotGetAverageColor();
98 void colorPicked(const QColor&);
99 void displayMessage(const QString&, int);
100 /** @brief When user wants to pick a color, it's better to disable filter so we get proper color values. */
101 void disableCurrentFilter(bool);