]> git.sesse.net Git - kdenlive/blob - src/colorpickerwidget.h
Disable effect when trying to pick a color from the monitor:
[kdenlive] / src / colorpickerwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2010 by Till Theato (root@ttill.de)                     *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #ifndef COLORPICKERWIDGET_H
22 #define COLORPICKERWIDGET_H
23
24 #include <QtCore>
25 #include <QWidget>
26 #include <QFrame>
27
28 class QSpinBox;
29 class QFrame;
30 #ifdef Q_WS_X11
31 #include <X11/Xlib.h>
32 #endif
33
34
35 class MyFrame : public QFrame
36 {
37     Q_OBJECT
38 public:
39     MyFrame(QWidget* parent = 0);
40
41 protected:
42     virtual void hideEvent ( QHideEvent * event );
43
44 signals:
45     void getColor();
46 };
47
48 /**
49  * @class ColorPickerWidget
50  * @brief A widget to pick a color anywhere on the screen.
51  * @author Till Theato
52  *
53  * The code is partially based on the color picker in KColorDialog. 
54  */
55
56 class ColorPickerWidget : public QWidget
57 {
58     Q_OBJECT
59
60 public:
61     /** @brief Sets up the widget. */
62     ColorPickerWidget(QWidget *parent = 0);
63     /** @brief Makes sure the event filter is removed. */
64     virtual ~ColorPickerWidget();
65
66 protected:
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);
71
72 private:
73     /** @brief Closes the event filter and makes mouse and keyboard work again on other widgets/windows. */
74     void closeEventFilter();
75
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);
81
82     bool m_filterActive;
83     QRect m_grabRect;
84     QFrame *m_grabRectFrame;
85 #ifdef Q_WS_X11
86     XImage *m_image;
87 #else
88     QImage m_image;
89 #endif
90     
91 private slots:
92     /** @brief Sets up an event filter for picking a color. */
93     void slotSetupEventFilter();
94
95     /** @brief Calculates the average color for the pixels in the rect m_grabRect and emits colorPicked. */
96     void slotGetAverageColor();
97
98 signals:
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);
103 };
104
105 #endif