1 // Copyright 2005-2019 The Mumble Developers. All rights reserved.
2 // Use of this source code is governed by a BSD-style license
3 // that can be found in the LICENSE file at the root of the
4 // Mumble source tree or at <https://www.mumble.info/LICENSE>.
5 
6 #ifndef MUMBLE_MUMBLE_OVERLAY_H_
7 #define MUMBLE_MUMBLE_OVERLAY_H_
8 
9 #include <QtCore/QtGlobal>
10 #include <QtCore/QUrl>
11 #include <QtNetwork/QLocalSocket>
12 #if QT_VERSION >= 0x050000
13 # include <QtWidgets/QGraphicsItem>
14 #else
15 # include <QtGui/QGraphicsItem>
16 #endif
17 
18 #include "ConfigDialog.h"
19 #include "OverlayText.h"
20 #include "../../overlay/overlay.h"
21 
22 #include "ui_OverlayEditor.h"
23 
24 class ClientUser;
25 class Overlay;
26 class QLocalServer;
27 class OverlayClient;
28 class OverlayConfig;
29 
30 struct OverlayAppInfo {
31 	static QString applicationIdentifierForPath(const QString &path);
32 	static OverlayAppInfo applicationInfoForId(const QString &identifier);
33 
34 	QString qsDisplayName;
35 	QIcon qiIcon;
36 
37 private:
38 	OverlayAppInfo(QString name, QIcon icon = QIcon());
39 };
40 
41 class OverlayGroup : public QGraphicsItem {
42 	private:
43 		Q_DISABLE_COPY(OverlayGroup);
44 	public:
45 		enum { Type = UserType + 5 };
46 	public:
47 		OverlayGroup();
48 
49 		QRectF boundingRect() const Q_DECL_OVERRIDE;
50 		void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) Q_DECL_OVERRIDE;
51 		int type() const Q_DECL_OVERRIDE;
52 
53 		template <typename T>
54 		QRectF boundingRect() const;
55 };
56 
57 class OverlayMouse : public QGraphicsPixmapItem {
58 	private:
59 		Q_DISABLE_COPY(OverlayMouse)
60 	public:
61 		bool contains(const QPointF &) const Q_DECL_OVERRIDE;
62 		bool collidesWithPath(const QPainterPath &, Qt::ItemSelectionMode = Qt::IntersectsItemShape) const Q_DECL_OVERRIDE;
63 		OverlayMouse(QGraphicsItem * = NULL);
64 };
65 
66 class OverlayPrivate : public QObject {
67 	private:
68 		Q_OBJECT
Q_DISABLE_COPY(OverlayPrivate)69 		Q_DISABLE_COPY(OverlayPrivate)
70 	public:
71 		OverlayPrivate(QObject *p) : QObject(p) {};
72 };
73 
74 class Overlay : public QObject {
75 		friend class OverlayConfig;
76 		friend class OverlayClient;
77 		friend class OverlayUser;
78 	private:
79 		Q_OBJECT
80 		Q_DISABLE_COPY(Overlay)
81 	protected:
82 		OverlayPrivate *d;
83 
84 		QSet<unsigned int> qsQueried;
85 		QSet<unsigned int> qsQuery;
86 		/// A flag indicating if the platformInit has been called already
87 		bool m_initialized;
88 
89 		/// Initializes the overlay, if it hasn't been initialized yet
90 		void initialize();
91 
92 		// These 2 functions (among others) are implemented by the system-specific backend
93 		void platformInit();
94 		void setActiveInternal(bool act);
95 
96 		void createPipe();
97 
98 		QMap<QString, QString> qmOverlayHash;
99 		QLocalServer *qlsServer;
100 		QList<OverlayClient *> qlClients;
101 	protected slots:
102 		void disconnected();
103 		void error(QLocalSocket::LocalSocketError);
104 		void newConnection();
105 	public:
106 		Overlay();
107 		~Overlay() Q_DECL_OVERRIDE;
108 		bool isActive() const;
109 		void verifyTexture(ClientUser *cp, bool allowupdate = true);
110 		void requestTexture(ClientUser *);
111 
112 	public slots:
113 		void updateOverlay();
114 		void setActive(bool act);
115 		void toggleShow();
116 		void forceSettings();
117 };
118 
119 #endif
120