source: tests/embedded/embedded.cpp@ 1010

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

tests: embedded: Don't hide widgets in stack.

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