1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
//===========================================
// Lumina-desktop source code
// Copyright (c) 2018, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#ifndef _DESKTOP_WINDOW_EMBED_WIDGET_H
#define _DESKTOP_WINDOW_EMBED_WIDGET_H
#include <global-includes.h>
#define USE_QWINDOW_EMBED 1
class EmbedWidget : public QWidget {
Q_OBJECT
private:
NativeWindowObject *WIN;
public:
EmbedWidget(NativeWindowObject *win, QWidget* parent) : QWidget(parent){
WIN = win;
}
~EmbedWidget(){}
public slots:
void submitNewGeom(){
QRect global_geom = QRect( this->mapToGlobal(QPoint(0,0)), this->size() );
WIN->setGeometryNow(global_geom);
}
protected:
void resizeEvent(QResizeEvent *ev){
QWidget::resizeEvent(ev);
submitNewGeom();
}
/*void moveEvent(QMoveEvent *ev){
QWidget::moveEvent(ev);
submitNewGeom();
}*/
void hideEvent(QHideEvent *ev){
QWidget::hideEvent(ev);
qDebug() << "Hide Event";
WIN->requestProperty(NativeWindowObject::Visible, false);
}
void showEvent(QShowEvent *ev){
QWidget::showEvent(ev);
qDebug() << "ShowEvent";
WIN->requestProperty(NativeWindowObject::Visible, true);
}
void enterEvent(QEvent *ev){
QWidget::enterEvent(ev);
qDebug() << "Enter event";
}
void paintEvent(QPaintEvent *){
//Never paint anything with this widget
}
void closeEvent(QCloseEvent *ev){
qDebug() << "Embed Window Closed";
WIN->emit WindowClosed(WIN->id());
QWidget::closeEvent(ev);
}
};
class NativeEmbedWidget : public QObject {
Q_OBJECT
private:
QWidget *embedW;
NativeWindowObject *WIN;
public:
NativeEmbedWidget(QWidget *parent, NativeWindowObject *obj) : QObject(parent){
WIN = obj;
if(USE_QWINDOW_EMBED){
QWindow* _window = QWindow::fromWinId(WIN->id());
embedW = QWidget::createWindowContainer(_window, parent);
QList<WId> related; related << _window->winId();
if(embedW->nativeParentWidget()!=0){ related << embedW->nativeParentWidget()->winId(); }
WIN->setProperty(NativeWindowObject::RelatedWindows, QVariant::fromValue< QList<WId> >(related) );
//connect(_window, SIGNAL(destroyed(QObject*)), WIN, SLOT(announceClosed()) );
}else{
embedW = new EmbedWidget(WIN, parent);
}
}
~NativeEmbedWidget(){}
QWidget* widget(){ return embedW; }
QRect geometry(){ return embedW->geometry(); }
public slots:
void activateWindow(){ WIN->requestActivate(); } //QTimer::singleShot(0, WIN, SLOT(requestActivate())); }
void windowFrameMoved(){}
};
#endif
|