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