| 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 | 
 | 
|---|
| 12 | class VideoWidget : public QFrame
 | 
|---|
| 13 | {
 | 
|---|
| 14 | public:
 | 
|---|
| 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 | 
 | 
|---|
| 58 | class MainWindow : public QMainWindow
 | 
|---|
| 59 | {
 | 
|---|
| 60 |     Q_OBJECT
 | 
|---|
| 61 | 
 | 
|---|
| 62 | public:
 | 
|---|
| 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 |         {
 | 
|---|
| 118 |             videoWidget->resize (800, 600);
 | 
|---|
| 119 |             resize(size() - stackCentralW->size() + QSize(800, 600));
 | 
|---|
| 120 |         }
 | 
|---|
| 121 | 
 | 
|---|
| 122 | #ifdef Q_WS_PM
 | 
|---|
| 123 |         if (id)
 | 
|---|
| 124 |         {
 | 
|---|
| 125 |             qDebug() << "window handle" << qDebugFmtHex (id);
 | 
|---|
| 126 |             HWND hwnd = id;
 | 
|---|
| 127 |             RECTL rcl;
 | 
|---|
| 128 |             WinQueryWindowRect (hwnd, &rcl);
 | 
|---|
| 129 |             HPS hps = WinGetPS (hwnd);
 | 
|---|
| 130 |             if (hps)
 | 
|---|
| 131 |             {
 | 
|---|
| 132 |                 HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl);
 | 
|---|
| 133 |                 qt_WinProcessWindowObstacles (hwnd, NULL, hrgn, CRGN_DIFF, PWO_Default);
 | 
|---|
| 134 | 
 | 
|---|
| 135 |                 HRGN hrgnOld;
 | 
|---|
| 136 |                 GpiSetClipRegion (hps, hrgn, &hrgnOld);
 | 
|---|
| 137 | 
 | 
|---|
| 138 |                 rcl.xLeft = 0;
 | 
|---|
| 139 |                 rcl.yBottom = 0;
 | 
|---|
| 140 |                 rcl.xRight = videoWidget->size().width();
 | 
|---|
| 141 |                 rcl.yTop = videoWidget->size().height();
 | 
|---|
| 142 | 
 | 
|---|
| 143 |                 qDebug() << rcl.xRight << rcl.yTop;
 | 
|---|
| 144 | 
 | 
|---|
| 145 |                 WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR);
 | 
|---|
| 146 | 
 | 
|---|
| 147 |                 GpiDestroyRegion (hps, hrgnOld);
 | 
|---|
| 148 | 
 | 
|---|
| 149 |                 WinReleasePS (hps);
 | 
|---|
| 150 |             }
 | 
|---|
| 151 |         }
 | 
|---|
| 152 | #endif
 | 
|---|
| 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
 | 
|---|
| 170 |     }
 | 
|---|
| 171 | 
 | 
|---|
| 172 | public slots:
 | 
|---|
| 173 | 
 | 
|---|
| 174 |     void playTriggered (bool checked)
 | 
|---|
| 175 |     {
 | 
|---|
| 176 |         if (checked)
 | 
|---|
| 177 |         {
 | 
|---|
| 178 |             stackCentralW->setCurrentWidget (videoWidget);
 | 
|---|
| 179 |             id = videoWidget->request();
 | 
|---|
| 180 |             timerId = startTimer (1000);
 | 
|---|
| 181 |         }
 | 
|---|
| 182 |         else
 | 
|---|
| 183 |         {
 | 
|---|
| 184 |             videoWidget->release();
 | 
|---|
| 185 |             id = 0;
 | 
|---|
| 186 |             killTimer (timerId);
 | 
|---|
| 187 |             timerId = 0;
 | 
|---|
| 188 |             stackCentralW->setCurrentWidget (bgWidget);
 | 
|---|
| 189 |         }
 | 
|---|
| 190 |     }
 | 
|---|
| 191 | 
 | 
|---|
| 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 | 
 | 
|---|
| 204 | public:
 | 
|---|
| 205 | 
 | 
|---|
| 206 |     QStackedWidget *stackCentralW;
 | 
|---|
| 207 |     QLabel *bgWidget;
 | 
|---|
| 208 |     VideoWidget *videoWidget;
 | 
|---|
| 209 |     WId id;
 | 
|---|
| 210 |     int timerId;
 | 
|---|
| 211 | };
 | 
|---|
| 212 | 
 | 
|---|
| 213 | 
 | 
|---|
| 214 | int 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 | }
 | 
|---|
| 222 | 
 | 
|---|
| 223 | #include "embedded.moc"
 | 
|---|