[1010] | 1 | #ifdef __OS2__
|
---|
[1003] | 2 | #include <os2.h>
|
---|
[1010] | 3 | #endif
|
---|
[1003] | 4 |
|
---|
| 5 | #include <QDebug>
|
---|
| 6 | #include <QtGui>
|
---|
| 7 |
|
---|
| 8 | class VideoWidget : public QFrame
|
---|
| 9 | {
|
---|
| 10 | public:
|
---|
| 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 |
|
---|
[1010] | 32 | WId id = stable->winId();
|
---|
| 33 | qDebug() << "stable id" << qDebugHWND (id);
|
---|
| 34 | return id;
|
---|
[1003] | 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 |
|
---|
| 50 | class MainWindow : public QMainWindow
|
---|
| 51 | {
|
---|
[1004] | 52 | Q_OBJECT
|
---|
| 53 |
|
---|
[1003] | 54 | public:
|
---|
| 55 |
|
---|
| 56 | MainWindow()
|
---|
[1004] | 57 | : id (0), timerId (0)
|
---|
[1003] | 58 | {
|
---|
[1004] | 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)));
|
---|
[1010] | 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);
|
---|
[1004] | 74 | }
|
---|
| 75 |
|
---|
| 76 | /* this mimics VLC behavior */
|
---|
| 77 |
|
---|
[1003] | 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 |
|
---|
[1004] | 85 | stackCentralW = new QStackedWidget (main);
|
---|
[1003] | 86 |
|
---|
[1010] | 87 | // avoid hiding widgets when tossing the stack (just raise/lower)
|
---|
| 88 | qobject_cast <QStackedLayout *> (stackCentralW->layout())
|
---|
| 89 | ->setStackingMode (QStackedLayout::StackAll);
|
---|
| 90 |
|
---|
[1004] | 91 | bgWidget = new QLabel ("Background");
|
---|
| 92 | stackCentralW->addWidget (bgWidget);
|
---|
[1003] | 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 | {
|
---|
[1010] | 104 | static int tickCount = 0;
|
---|
| 105 | ++ tickCount;
|
---|
| 106 |
|
---|
| 107 | if (tickCount == 5)
|
---|
| 108 | resize (800, 600);
|
---|
| 109 | #ifdef __OS2__
|
---|
[1004] | 110 | if (id)
|
---|
[1003] | 111 | {
|
---|
[1004] | 112 | qDebug() << "window handle" << qDebugFmtHex (id);
|
---|
| 113 | HWND hwnd = id;
|
---|
| 114 | HPS hps = WinGetPS (hwnd);
|
---|
| 115 | if (hps)
|
---|
| 116 | {
|
---|
| 117 | RECTL rcl;
|
---|
[1010] | 118 | // WinQueryWindowRect (hwnd, &rcl);
|
---|
[1003] | 119 |
|
---|
[1004] | 120 | rcl.xLeft = 0;
|
---|
| 121 | rcl.yBottom = 0;
|
---|
| 122 | rcl.xRight = videoWidget->size().width();
|
---|
| 123 | rcl.yTop = videoWidget->size().height();
|
---|
[1003] | 124 |
|
---|
[1004] | 125 | qDebug() << rcl.xRight << rcl.yTop;
|
---|
[1003] | 126 |
|
---|
[1004] | 127 | WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR);
|
---|
[1003] | 128 |
|
---|
[1004] | 129 | WinReleasePS (hps);
|
---|
| 130 | }
|
---|
[1003] | 131 | }
|
---|
[1010] | 132 | #endif
|
---|
[1003] | 133 | }
|
---|
| 134 |
|
---|
[1004] | 135 | public slots:
|
---|
| 136 |
|
---|
| 137 | void playTriggered (bool checked)
|
---|
| 138 | {
|
---|
| 139 | if (checked)
|
---|
| 140 | {
|
---|
| 141 | stackCentralW->setCurrentWidget (videoWidget);
|
---|
| 142 | id = videoWidget->request();
|
---|
[1010] | 143 | timerId = startTimer (1000);
|
---|
[1004] | 144 | }
|
---|
| 145 | else
|
---|
| 146 | {
|
---|
| 147 | videoWidget->release();
|
---|
| 148 | id = 0;
|
---|
| 149 | killTimer (timerId);
|
---|
[1010] | 150 | timerId = 0;
|
---|
[1004] | 151 | stackCentralW->setCurrentWidget (bgWidget);
|
---|
| 152 | }
|
---|
| 153 | }
|
---|
| 154 |
|
---|
[1010] | 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 |
|
---|
[1004] | 167 | public:
|
---|
| 168 |
|
---|
| 169 | QStackedWidget *stackCentralW;
|
---|
| 170 | QLabel *bgWidget;
|
---|
[1003] | 171 | VideoWidget *videoWidget;
|
---|
| 172 | WId id;
|
---|
[1004] | 173 | int timerId;
|
---|
[1003] | 174 | };
|
---|
| 175 |
|
---|
| 176 |
|
---|
| 177 | int 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 | }
|
---|
[1004] | 185 |
|
---|
| 186 | #include "embedded.moc"
|
---|