source: tests/embedded/embedded.cpp@ 1015

Last change on this file since 1015 was 1015, checked in by Dmitry A. Kuminov, 14 years ago

tests: embedded: Use case qt_WinProcessWindowObstacles().

And also added direct painting code for Windows.

File size: 5.4 KB
Line 
1#include <QDebug>
2#include <QtGui>
3
4#ifdef Q_WS_PM
5#include <qt_os2.h>
6#endif
7
8#ifdef Q_WS_WIN
9#include <qt_windows.h>
10#endif
11
12class VideoWidget : public QFrame
13{
14public:
15
16 VideoWidget()
17 {
18 layout = new QHBoxLayout (this);
19 layout->setContentsMargins (0, 0, 0, 0);
20 setLayout (layout);
21 stable = 0;
22 show();
23 }
24
25 WId request()
26 {
27 stable = new QWidget();
28 QPalette plt = palette();
29 plt.setColor (QPalette::Window, Qt::black);
30 stable->setPalette (plt);
31 stable->setAutoFillBackground (true);
32 stable->setAttribute (Qt::WA_PaintOnScreen, true);
33
34 layout->addWidget (stable);
35
36 WId id = stable->winId();
37#ifdef Q_WS_PM
38 qDebug() << "stable id" << qDebugHWND (id);
39#else
40 qDebug() << "stable id" << id;
41#endif
42 return id;
43 }
44
45 void release()
46 {
47 layout->removeWidget (stable);
48 stable->deleteLater();
49 stable = 0;
50
51 updateGeometry();
52 }
53
54 QHBoxLayout *layout;
55 QWidget *stable;
56};
57
58class MainWindow : public QMainWindow
59{
60 Q_OBJECT
61
62public:
63
64 MainWindow()
65 : id (0), timerId (0)
66 {
67 /* menus */
68 {
69 QAction *playAct = new QAction ("&Play", this);
70 playAct->setShortcut (QKeySequence("Ctrl+P"));
71 playAct->setCheckable (true);
72 connect (playAct, SIGNAL (triggered(bool)), SLOT (playTriggered(bool)));
73
74 QAction *playListAct = new QAction ("Play&list", this);
75 playListAct->setShortcut (QKeySequence("Ctrl+L"));
76 playListAct->setCheckable (true);
77 connect (playListAct, SIGNAL (triggered(bool)), SLOT (playListTriggered(bool)));
78
79 QMenu *actionsMenu = menuBar()->addMenu ("&Actions");
80 actionsMenu->addAction (playAct);
81 actionsMenu->addAction (playListAct);
82 }
83
84 /* this mimics VLC behavior */
85
86 QWidget *main = new QWidget();
87 setCentralWidget (main);
88 QVBoxLayout *mainLayout = new QVBoxLayout (main);
89 main->setContentsMargins (0, 0, 0, 0);
90 mainLayout->setSpacing (0);
91 mainLayout->setMargin (0);
92
93 stackCentralW = new QStackedWidget (main);
94
95 // avoid hiding widgets when tossing the stack (just raise/lower)
96 qobject_cast <QStackedLayout *> (stackCentralW->layout())
97 ->setStackingMode (QStackedLayout::StackAll);
98
99 bgWidget = new QLabel ("Background");
100 bgWidget->setAutoFillBackground (true);
101 stackCentralW->addWidget (bgWidget);
102
103 videoWidget = new VideoWidget();
104 stackCentralW->addWidget (videoWidget);
105
106 mainLayout->insertWidget (1, stackCentralW);
107
108 mainLayout->insertWidget (2, new QLabel ("Controls"));
109 }
110
111 void timerEvent (QTimerEvent *)
112 {
113 static int tickCount = 0;
114 ++ tickCount;
115
116 if (tickCount == 5)
117 resize (800, 600);
118
119#ifdef Q_WS_PM
120 if (id)
121 {
122 qDebug() << "window handle" << qDebugFmtHex (id);
123 HWND hwnd = id;
124 RECTL rcl;
125 WinQueryWindowRect (hwnd, &rcl);
126 HPS hps = WinGetPS (hwnd);
127 if (hps)
128 {
129 HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl);
130 ULONG rc = qt_WinProcessWindowObstacles (hwnd, NULL, hrgn, CRGN_DIFF, PWO_Default);
131
132 HRGN hrgnOld;
133 GpiSetClipRegion (hps, hrgn, &hrgnOld);
134
135 rcl.xLeft = 0;
136 rcl.yBottom = 0;
137 rcl.xRight = videoWidget->size().width();
138 rcl.yTop = videoWidget->size().height();
139
140 qDebug() << rcl.xRight << rcl.yTop;
141
142 WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR);
143
144 GpiDestroyRegion (hps, hrgnOld);
145
146 WinReleasePS (hps);
147 }
148 }
149#endif
150#ifdef Q_WS_WIN
151 if (id)
152 {
153 qDebug() << "window handle" << id;
154 HDC hdc = GetDC (id);
155 RECT rect;
156 rect.left = 0;
157 rect.top = 0;
158 rect.right = videoWidget->size().width();
159 rect.bottom = videoWidget->size().height();
160 SetDCBrushColor (hdc, RGB (0x00, 0x80, 0x00));
161 FillRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH));
162 SetDCBrushColor (hdc, RGB (0xFF, 0x00, 0x00));
163 FrameRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH));
164 ReleaseDC (id, hdc);
165 }
166#endif
167 }
168
169public slots:
170
171 void playTriggered (bool checked)
172 {
173 if (checked)
174 {
175 stackCentralW->setCurrentWidget (videoWidget);
176 id = videoWidget->request();
177 timerId = startTimer (1000);
178 }
179 else
180 {
181 videoWidget->release();
182 id = 0;
183 killTimer (timerId);
184 timerId = 0;
185 stackCentralW->setCurrentWidget (bgWidget);
186 }
187 }
188
189 void playListTriggered (bool checked)
190 {
191 if (checked)
192 {
193 stackCentralW->setCurrentWidget (bgWidget);
194 }
195 else
196 {
197 stackCentralW->setCurrentWidget (videoWidget);
198 }
199 }
200
201public:
202
203 QStackedWidget *stackCentralW;
204 QLabel *bgWidget;
205 VideoWidget *videoWidget;
206 WId id;
207 int timerId;
208};
209
210
211int main (int argc, char **argv)
212{
213 QApplication app (argc, argv);
214 MainWindow window;
215 window.resize (400, 300);
216 window.show();
217 return app.exec();
218}
219
220#include "embedded.moc"
Note: See TracBrowser for help on using the repository browser.