1 //===========================================
2 //  Lumina-DE source code
3 //  Copyright (c) 2017, Ken Moore
4 //  Available under the 3-clause BSD license
5 //  See the LICENSE file for full details
6 //===========================================
7 //  This is a container object for embedding a native window into a QWidget
8 //    and maintaining a 1-to-1 mapping of sizing and other properties
9 //    while also providing compositing effects between the two windows
10 //===========================================
11 #ifndef _LUMINA_NATIVE_EMBED_WIDGET_H
12 #define _LUMINA_NATIVE_EMBED_WIDGET_H
13 
14 #include "NativeWindow.h"
15 #include <QWidget>
16 #include <QTimer>
17 #include <QResizeEvent>
18 #include <QShowEvent>
19 #include <QHideEvent>
20 #include <QPaintEvent>
21 #include <QMouseEvent>
22 
23 class NativeEmbedWidget : public QWidget{
24 	Q_OBJECT
25 private:
26 	NativeWindow *WIN;
27 	QSize winSize;
28 	QImage winImage;
29 	bool paused, hasAlphaChannel;
30 
31 private slots:
32 	//Simplification functions
33 	void syncWinSize(QSize sz = QSize());
34 	void syncWidgetSize(QSize sz);
35 	void hideWindow();
36 	void showWindow();
37 	QImage windowImage(QRect geom);
38 
39 	void setWinUnpaused();
40 
41 public:
42 	NativeEmbedWidget(QWidget *parent);
43 
44 	bool embedWindow(NativeWindow *window);
45 	bool detachWindow();
46 	bool isEmbedded(); //status of the embed
isPaused()47 	bool isPaused(){ return paused; }
48 
49 public slots:
50 	void raiseWindow();
51 	void lowerWindow();
52 
53 	//Pause/resume
54 	void pause();
55 	void resume();
56 
57 	void resyncWindow();
58 	void repaintWindow();
59 	void reregisterEvents();
60 
61 protected:
62 	void resizeEvent(QResizeEvent *ev);
63 	void showEvent(QShowEvent *ev);
64 	void hideEvent(QHideEvent *ev);
65 	void paintEvent(QPaintEvent *ev);
66 	void enterEvent(QEvent *ev);
67 	void leaveEvent(QEvent *ev);
68 	void mouseMoveEvent(QMouseEvent *ev);
69 	void mousePressEvent(QMouseEvent *ev);
70 	void mouseReleaseEvent(QMouseEvent *ev);
71 	//bool nativeEvent(const QByteArray &eventType, void *message, long *result);
72 };
73 
74 #endif
75