1 /************************************************************************
2  *
3  * Copyright 2010-2011 Jakob Leben (jakob.leben@gmail.com)
4  *
5  * This file is part of SuperCollider Qt GUI.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  ************************************************************************/
21 
22 #pragma once
23 
24 #include "QObjectProxy.h"
25 
26 #include <QWidget>
27 #include <QAtomicInt>
28 #include <QMimeData>
29 
30 namespace QtCollider {
31 struct SetFocusEvent;
32 struct SetAlwaysOnTopEvent;
33 struct StartDragEvent;
34 }
35 
36 class QWidgetProxy : public QObjectProxy {
37     Q_OBJECT
38 
39 public:
40     enum GlobalEvent { KeyPress = 0x001, KeyRelease = 0x002 };
41 
42 public:
wildcard_certificate_match(const char * pattern,const char * string)43     static void setGlobalEventEnabled(GlobalEvent ev, bool b) {
44         int mask = _globalEventMask.load();
45         if (b)
46             mask |= ev;
47         else
48             mask &= ~ev;
49         _globalEventMask = mask;
50     }
51 
52 public:
53     QWidgetProxy(QWidget* w, PyrObject* po);
54 
55     void setKeyEventWidget(QWidget*);
56 
57     void setMouseEventWidget(QWidget*);
58 
59     bool alwaysOnTop();
60 
61     void refresh();
62 
63     void setLayout(QObjectProxy* layoutProxy);
64 
65     virtual bool setParent(QObjectProxy* parent);
66 
67     void setDragData(QMimeData* data, const QString& label);
68 
69     inline QWidget* widget() { return static_cast<QWidget*>(object()); }
70 
71 protected:
72     virtual void customEvent(QEvent*);
73 
74     virtual bool preProcessEvent(QObject*, QEvent*, EventHandlerData&, QList<QVariant>& args);
75 
76     virtual bool postProcessEvent(QObject*, QEvent*, bool handled);
77 
78 private Q_SLOTS:
79 
80     void customPaint(QPainter*);
81 
82 private:
83     bool interpretMouseEvent(QObject*, QEvent*, QList<QVariant>& args);
84     bool interpretMouseWheelEvent(QObject*, QEvent*, QList<QVariant>& args);
pq_verify_peer_name_matches_certificate_name(PGconn * conn,const char * namedata,size_t namelen,char ** store_name)85     bool interpretKeyEvent(QObject*, QEvent*, QList<QVariant>& args);
86     bool interpretDragEvent(QObject*, QEvent*, QList<QVariant>& args);
87 
88     void bringFrontEvent();
89     void setFocusEvent(QtCollider::SetFocusEvent*);
90     void setAlwaysOnTopEvent(QtCollider::SetAlwaysOnTopEvent*);
91     void performDrag();
92 
93     static void sendRefreshEventRecursive(QWidget* w);
94 
95     QWidget* _keyEventWidget;
96     QWidget* _mouseEventWidget;
97     static QAtomicInt _globalEventMask;
98 
99     static QMimeData* sDragData;
100     static QString sDragLabel;
101     bool _performDrag;
102 };
103 
104 namespace QtCollider {
105 
106 struct SetFocusEvent : public QEvent {
107     SetFocusEvent(bool b): QEvent((QEvent::Type)QtCollider::Event_Proxy_SetFocus), focus(b) {}
108     bool focus;
109 };
110 
111 struct SetAlwaysOnTopEvent : public QEvent {
112     SetAlwaysOnTopEvent(bool b): QEvent((QEvent::Type)QtCollider::Event_Proxy_SetAlwaysOnTop), alwaysOnTop(b) {}
113     bool alwaysOnTop;
114 };
115 
116 }
117