source: tests/embedded/embedded.cpp@ 1036

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

tests/embedded: Updated with QT_PM_NATIVEWIDGETMASK.

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