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
35 class MyFrame : public QFrame
39 MyFrame(QWidget* parent = 0);
42 virtual void hideEvent ( QHideEvent * event );
49 * @class ColorPickerWidget
50 * @brief A widget to pick a color anywhere on the screen.
53 * The code is partially based on the color picker in KColorDialog.
56 class ColorPickerWidget : public QWidget
61 /** @brief Sets up the widget. */
62 ColorPickerWidget(QWidget *parent = 0);
63 /** @brief Makes sure the event filter is removed. */
64 virtual ~ColorPickerWidget();
67 virtual void mousePressEvent(QMouseEvent *event);
68 virtual void mouseReleaseEvent(QMouseEvent *event);
69 virtual void mouseMoveEvent(QMouseEvent *event);
70 bool eventFilter(QObject *object, QEvent *event);
73 /** @brief Closes the event filter and makes mouse and keyboard work again on other widgets/windows. */
74 void closeEventFilter();
76 /** @brief Color of the screen at point @param p.
77 * @param p Position of color requested
78 * @param destroyImage (optional) Whether or not to keep the XImage in m_image
79 (needed for fast processing of rects) */
80 QColor grabColor(const QPoint &p, bool destroyImage = true);
84 QFrame *m_grabRectFrame;
92 /** @brief Sets up an event filter for picking a color. */
93 void slotSetupEventFilter();
95 /** @brief Calculates the average color for the pixels in the rect m_grabRect and emits colorPicked. */
96 void slotGetAverageColor();
99 void colorPicked(QColor);
100 void displayMessage(const QString&, int);
101 /** @brief When user wants to pick a color, it's better to disable filter so we get proper color values. */
102 void disableCurrentFilter(bool);