]> git.sesse.net Git - kdenlive/blob - src/colorpickerwidget.h
Replace roles into projectlistview. Turn const int into enum.
[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 QFrame;
29 #ifdef Q_WS_X11
30 #include <X11/Xlib.h>
31 #endif
32
33
34 class MyFrame : public QFrame
35 {
36     Q_OBJECT
37 public:
38     explicit MyFrame(QWidget* parent = 0);
39
40 protected:
41     void hideEvent ( QHideEvent * event );
42
43 signals:
44     void getColor();
45 };
46
47 /**
48  * @class ColorPickerWidget
49  * @brief A widget to pick a color anywhere on the screen.
50  * @author Till Theato
51  *
52  * The code is partially based on the color picker in KColorDialog. 
53  */
54
55 class ColorPickerWidget : public QWidget
56 {
57     Q_OBJECT
58
59 public:
60     /** @brief Sets up the widget. */
61     explicit ColorPickerWidget(QWidget *parent = 0);
62     /** @brief Makes sure the event filter is removed. */
63     virtual ~ColorPickerWidget();
64
65 protected:
66     void mousePressEvent(QMouseEvent *event);
67     void mouseReleaseEvent(QMouseEvent *event);
68     void mouseMoveEvent(QMouseEvent *event);
69     bool eventFilter(QObject *object, QEvent *event);
70
71 private:
72     /** @brief Closes the event filter and makes mouse and keyboard work again on other widgets/windows. */
73     void closeEventFilter();
74
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);
80
81     bool m_filterActive;
82     QRect m_grabRect;
83     QFrame *m_grabRectFrame;
84 #ifdef Q_WS_X11
85     XImage *m_image;
86 #else
87     QImage m_image;
88 #endif
89     
90 private slots:
91     /** @brief Sets up an event filter for picking a color. */
92     void slotSetupEventFilter();
93
94     /** @brief Calculates the average color for the pixels in the rect m_grabRect and emits colorPicked. */
95     void slotGetAverageColor();
96
97 signals:
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);
102 };
103
104 #endif