1 /* EventFilter.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
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 3 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 #ifndef EVENTFILTER_H
22 #define EVENTFILTER_H
23 
24 #include <QObject>
25 #include <QEvent>
26 #include <QList>
27 
28 class QAction;
29 class QMouseEvent;
30 
31 namespace Gui
32 {
33 	/**
34 	 * @brief The GenericFilter class
35 	 * @ingroup EventFilter
36 	 */
37 	class GenericFilter :
38 			public QObject
39 	{
40 		Q_OBJECT
41 
42 		signals:
43 			void sigEvent(QEvent::Type);
44 
45 		private:
46 			QList<QEvent::Type> m_types;
47 
48 		public:
49 			explicit GenericFilter(const QEvent::Type& type, QObject* parent=nullptr);
50 			explicit GenericFilter(const QList<QEvent::Type>& types, QObject* parent=nullptr);
51 
52 		protected:
53 			bool eventFilter(QObject* o , QEvent* e);
54 	};
55 
56 	/**
57 	 * @brief The KeyPressFilter class
58 	 * @ingroup EventFilter
59 	 */
60 	class KeyPressFilter :
61 			public QObject
62 	{
63 		Q_OBJECT
64 
65 		public:
66 			explicit KeyPressFilter(QObject* parent=nullptr);
67 
68 		signals:
69 			void setKeyPressed(int key);
70 
71 		protected:
72 			bool eventFilter(QObject* o , QEvent* e);
73 	};
74 
75 	/**
76 	 * @brief The ContextMenuFilter class
77 	 * @ingroup EventFilter
78 	 */
79 	class ContextMenuFilter :
80 			public QObject
81 	{
82 		Q_OBJECT
83 
84 		public:
85 			explicit ContextMenuFilter(QObject* parent=nullptr);
86 
87 		signals:
88 			// directly connect this signal to QMenu::popup
89 			void sigContextMenu(const QPoint& p, QAction* action);
90 
91 		protected:
92 			bool eventFilter(QObject* o , QEvent* e);
93 	};
94 
95 	/**
96 	 * @brief The MouseMoveFilter class
97 	 * @ingroup EventFilter
98 	 */
99 	class MouseMoveFilter :
100 			public QObject
101 	{
102 		Q_OBJECT
103 
104 		public:
105 			explicit MouseMoveFilter(QObject* parent=nullptr);
106 
107 		signals:
108 			void sigMouseMoved(QMouseEvent* e);
109 
110 		protected:
111 			bool eventFilter(QObject* o , QEvent* e);
112 	};
113 
114 	/**
115 	 * @brief The MouseMoveFilter class
116 	 * @ingroup EventFilter
117 	 */
118 	class MousePressedFilter :
119 			public QObject
120 	{
121 		Q_OBJECT
122 
123 		public:
124 			explicit MousePressedFilter(QObject* parent=nullptr);
125 
126 		signals:
127 			void sigMousePressed(QMouseEvent* e);
128 
129 		protected:
130 			bool eventFilter(QObject* o , QEvent* e);
131 	};
132 
133 	/**
134 	 * @brief The MouseMoveFilter class
135 	 * @ingroup EventFilter
136 	 */
137 	class MouseReleasedFilter :
138 			public QObject
139 	{
140 		Q_OBJECT
141 
142 		public:
143 			explicit MouseReleasedFilter(QObject* parent=nullptr);
144 
145 		signals:
146 			void sigMouseReleased(QMouseEvent* e);
147 
148 		protected:
149 			bool eventFilter(QObject* o , QEvent* e);
150 	};
151 
152 
153 	/**
154 	 * @brief The MouseEnterFilter class
155 	 * @ingroup EventFilter
156 	 */
157 	class MouseEnterFilter :
158 			public QObject
159 	{
160 		Q_OBJECT
161 
162 		public:
163 			explicit MouseEnterFilter(QObject* parent=nullptr);
164 
165 		signals:
166 			void sigMouseEntered();
167 
168 		protected:
169 			bool eventFilter(QObject* o, QEvent* e);
170 	};
171 
172 
173 	/**
174 	 * @brief The MouseLeaveFilter class
175 	 * @ingroup EventFilter
176 	 */
177 	class MouseLeaveFilter :
178 			public QObject
179 	{
180 		Q_OBJECT
181 
182 		public:
183 			explicit MouseLeaveFilter(QObject* parent=nullptr);
184 
185 		signals:
186 			void sigMouseLeft();
187 
188 		protected:
189 			bool eventFilter(QObject* o, QEvent* e);
190 	};
191 
192 
193 	/**
194 	 * @brief The HideFilter class
195 	 * @ingroup
196 	 */
197 	class HideFilter :
198 			public QObject
199 	{
200 		Q_OBJECT
201 
202 		public:
203 			explicit HideFilter(QObject* parent=nullptr);
204 
205 		signals:
206 			void sigHidden();
207 
208 		protected:
209 			bool eventFilter(QObject* o, QEvent* e);
210 	};
211 
212 
213 	/**
214 	 * @brief The ShowFilter class
215 	 * @ingroup EventFilter
216 	 */
217 	class ShowFilter :
218 			public QObject
219 	{
220 		Q_OBJECT
221 
222 		public:
223 			explicit ShowFilter(QObject* parent=nullptr);
224 
225 		signals:
226 			void sigShown();
227 
228 		protected:
229 			bool eventFilter(QObject* o, QEvent* e);
230 	};
231 
232 
233 
234 	/**
235 	 * @brief The ShowFilter class
236 	 * @ingroup EventFilter
237 	 */
238 	class ResizeFilter :
239 			public QObject
240 	{
241 		Q_OBJECT
242 
243 		public:
244 			explicit ResizeFilter(QObject* parent=nullptr);
245 
246 		signals:
247 			void sigResized(const QSize& newSize);
248 
249 		protected:
250 			bool eventFilter(QObject* o, QEvent* e);
251 	};
252 
253 
254 	/**
255 	 * @brief The PaintFilter class
256 	 * @ingroup EventFilter
257 	 */
258 	class PaintFilter :
259 			public QObject
260 	{
261 		Q_OBJECT
262 
263 		public:
264 			explicit PaintFilter(QObject* parent=nullptr);
265 
266 		signals:
267 			void sigPainted();
268 
269 		protected:
270 			bool eventFilter(QObject* o, QEvent* e);
271 	};
272 }
273 
274 #endif // EVENTFILTER_H
275