source: tests/embedded/embedded.cpp@ 1018

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

tests: embedded: Reproduced the #204 problem.

File size: 5.5 KB
RevLine 
[1003]1#include <QDebug>
2#include <QtGui>
3
[1015]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
[1003]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
[1010]36 WId id = stable->winId();
[1015]37#ifdef Q_WS_PM
[1010]38 qDebug() << "stable id" << qDebugHWND (id);
[1015]39#else
40 qDebug() << "stable id" << id;
41#endif
[1010]42 return id;
[1003]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{
[1004]60 Q_OBJECT
61
[1003]62public:
63
64 MainWindow()
[1004]65 : id (0), timerId (0)
[1003]66 {
[1004]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)));
[1010]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);
[1004]82 }
83
84 /* this mimics VLC behavior */
85
[1003]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
[1004]93 stackCentralW = new QStackedWidget (main);
[1003]94
[1010]95 // avoid hiding widgets when tossing the stack (just raise/lower)
96 qobject_cast <QStackedLayout *> (stackCentralW->layout())
97 ->setStackingMode (QStackedLayout::StackAll);
98
[1004]99 bgWidget = new QLabel ("Background");
[1015]100 bgWidget->setAutoFillBackground (true);
[1004]101 stackCentralW->addWidget (bgWidget);
[1003]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 {
[1010]113 static int tickCount = 0;
114 ++ tickCount;
115
116 if (tickCount == 5)
[1018]117 {
118 videoWidget->resize (800, 600);
119 resize(size() - stackCentralW->size() + QSize(800, 600));
120 }
[1015]121
122#ifdef Q_WS_PM
[1004]123 if (id)
[1003]124 {
[1004]125 qDebug() << "window handle" << qDebugFmtHex (id);
126 HWND hwnd = id;
[1015]127 RECTL rcl;
128 WinQueryWindowRect (hwnd, &rcl);
[1004]129 HPS hps = WinGetPS (hwnd);
130 if (hps)
131 {
[1015]132 HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl);
[1018]133 qt_WinProcessWindowObstacles (hwnd, NULL, hrgn, CRGN_DIFF, PWO_Default);
[1003]134
[1015]135 HRGN hrgnOld;
136 GpiSetClipRegion (hps, hrgn, &hrgnOld);
137
[1004]138 rcl.xLeft = 0;
139 rcl.yBottom = 0;
140 rcl.xRight = videoWidget->size().width();
141 rcl.yTop = videoWidget->size().height();
[1003]142
[1004]143 qDebug() << rcl.xRight << rcl.yTop;
[1003]144
[1004]145 WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR);
[1003]146
[1015]147 GpiDestroyRegion (hps, hrgnOld);
148
[1004]149 WinReleasePS (hps);
150 }
[1003]151 }
[1010]152#endif
[1015]153#ifdef Q_WS_WIN
154 if (id)
155 {
156 qDebug() << "window handle" << id;
157 HDC hdc = GetDC (id);
158 RECT rect;
159 rect.left = 0;
160 rect.top = 0;
161 rect.right = videoWidget->size().width();
162 rect.bottom = videoWidget->size().height();
163 SetDCBrushColor (hdc, RGB (0x00, 0x80, 0x00));
164 FillRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH));
165 SetDCBrushColor (hdc, RGB (0xFF, 0x00, 0x00));
166 FrameRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH));
167 ReleaseDC (id, hdc);
168 }
169#endif
[1003]170 }
171
[1004]172public slots:
173
174 void playTriggered (bool checked)
175 {
176 if (checked)
177 {
178 stackCentralW->setCurrentWidget (videoWidget);
179 id = videoWidget->request();
[1010]180 timerId = startTimer (1000);
[1004]181 }
182 else
183 {
184 videoWidget->release();
185 id = 0;
186 killTimer (timerId);
[1010]187 timerId = 0;
[1004]188 stackCentralW->setCurrentWidget (bgWidget);
189 }
190 }
191
[1010]192 void playListTriggered (bool checked)
193 {
194 if (checked)
195 {
196 stackCentralW->setCurrentWidget (bgWidget);
197 }
198 else
199 {
200 stackCentralW->setCurrentWidget (videoWidget);
201 }
202 }
203
[1004]204public:
205
206 QStackedWidget *stackCentralW;
207 QLabel *bgWidget;
[1003]208 VideoWidget *videoWidget;
209 WId id;
[1004]210 int timerId;
[1003]211};
212
213
214int main (int argc, char **argv)
215{
216 QApplication app (argc, argv);
217 MainWindow window;
218 window.resize (400, 300);
219 window.show();
220 return app.exec();
221}
[1004]222
223#include "embedded.moc"
Note: See TracBrowser for help on using the repository browser.