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
RevLine 
[1036]1#include <QtGlobal>
[1003]2
[1015]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
[1036]11#include <QtGui>
12#include <QDebug>
13
[1003]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
[1010]38 WId id = stable->winId();
[1015]39#ifdef Q_WS_PM
[1010]40 qDebug() << "stable id" << qDebugHWND (id);
[1015]41#else
42 qDebug() << "stable id" << id;
43#endif
[1010]44 return id;
[1003]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{
[1004]62 Q_OBJECT
63
[1003]64public:
65
66 MainWindow()
[1004]67 : id (0), timerId (0)
[1003]68 {
[1004]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)));
[1010]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);
[1004]84 }
85
86 /* this mimics VLC behavior */
87
[1003]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
[1004]95 stackCentralW = new QStackedWidget (main);
[1003]96
[1010]97 // avoid hiding widgets when tossing the stack (just raise/lower)
98 qobject_cast <QStackedLayout *> (stackCentralW->layout())
99 ->setStackingMode (QStackedLayout::StackAll);
100
[1004]101 bgWidget = new QLabel ("Background");
[1015]102 bgWidget->setAutoFillBackground (true);
[1004]103 stackCentralW->addWidget (bgWidget);
[1003]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 {
[1010]115 static int tickCount = 0;
116 ++ tickCount;
117
118 if (tickCount == 5)
[1018]119 {
120 videoWidget->resize (800, 600);
[1036]121// resize(size() - stackCentralW->size() + QSize(800, 600));
122 }
123
124 if (tickCount == 7)
125 {
126// videoWidget->resize (800, 600);
[1018]127 resize(size() - stackCentralW->size() + QSize(800, 600));
128 }
[1015]129
130#ifdef Q_WS_PM
[1004]131 if (id)
[1003]132 {
[1004]133 qDebug() << "window handle" << qDebugFmtHex (id);
[1036]134 SWP swp;
135 WinQueryWindowPos (videoWidget->internalWinId(), &swp);
136 qDebug() << "---" << swp;
[1004]137 HWND hwnd = id;
[1015]138 RECTL rcl;
139 WinQueryWindowRect (hwnd, &rcl);
[1004]140 HPS hps = WinGetPS (hwnd);
141 if (hps)
142 {
[1036]143#ifdef QT_PM_NATIVEWIDGETMASK
[1015]144 HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl);
[1036]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();
[1003]158
[1036]159 qDebug() << rcl.xRight << rcl.yTop;
[1015]160
[1036]161 WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR);
162
163#ifdef QT_PM_NATIVEWIDGETMASK
164 }
[1003]165
[1036]166 GpiDestroyRegion (hps, hrgn);
167#endif
[1004]168 WinReleasePS (hps);
169 }
[1003]170 }
[1010]171#endif
[1015]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
[1003]189 }
190
[1004]191public slots:
192
193 void playTriggered (bool checked)
194 {
195 if (checked)
196 {
197 stackCentralW->setCurrentWidget (videoWidget);
198 id = videoWidget->request();
[1010]199 timerId = startTimer (1000);
[1004]200 }
201 else
202 {
203 videoWidget->release();
204 id = 0;
205 killTimer (timerId);
[1010]206 timerId = 0;
[1004]207 stackCentralW->setCurrentWidget (bgWidget);
208 }
209 }
210
[1010]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
[1004]223public:
224
225 QStackedWidget *stackCentralW;
226 QLabel *bgWidget;
[1003]227 VideoWidget *videoWidget;
228 WId id;
[1004]229 int timerId;
[1003]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}
[1004]241
242#include "embedded.moc"
Note: See TracBrowser for help on using the repository browser.