#include #ifdef Q_WS_PM #include #endif #ifdef Q_WS_WIN #include #endif #include #include class VideoWidget : public QFrame { public: VideoWidget() { layout = new QHBoxLayout (this); layout->setContentsMargins (0, 0, 0, 0); setLayout (layout); stable = 0; show(); } WId request() { stable = new QWidget(); QPalette plt = palette(); plt.setColor (QPalette::Window, Qt::black); stable->setPalette (plt); stable->setAutoFillBackground (true); stable->setAttribute (Qt::WA_PaintOnScreen, true); layout->addWidget (stable); WId id = stable->winId(); #ifdef Q_WS_PM qDebug() << "stable id" << qDebugHWND (id); #else qDebug() << "stable id" << id; #endif return id; } void release() { layout->removeWidget (stable); stable->deleteLater(); stable = 0; updateGeometry(); } QHBoxLayout *layout; QWidget *stable; }; class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow() : id (0), timerId (0) { /* menus */ { QAction *playAct = new QAction ("&Play", this); playAct->setShortcut (QKeySequence("Ctrl+P")); playAct->setCheckable (true); connect (playAct, SIGNAL (triggered(bool)), SLOT (playTriggered(bool))); QAction *playListAct = new QAction ("Play&list", this); playListAct->setShortcut (QKeySequence("Ctrl+L")); playListAct->setCheckable (true); connect (playListAct, SIGNAL (triggered(bool)), SLOT (playListTriggered(bool))); QMenu *actionsMenu = menuBar()->addMenu ("&Actions"); actionsMenu->addAction (playAct); actionsMenu->addAction (playListAct); } /* this mimics VLC behavior */ QWidget *main = new QWidget(); setCentralWidget (main); QVBoxLayout *mainLayout = new QVBoxLayout (main); main->setContentsMargins (0, 0, 0, 0); mainLayout->setSpacing (0); mainLayout->setMargin (0); stackCentralW = new QStackedWidget (main); // avoid hiding widgets when tossing the stack (just raise/lower) qobject_cast (stackCentralW->layout()) ->setStackingMode (QStackedLayout::StackAll); bgWidget = new QLabel ("Background"); bgWidget->setAutoFillBackground (true); stackCentralW->addWidget (bgWidget); videoWidget = new VideoWidget(); stackCentralW->addWidget (videoWidget); mainLayout->insertWidget (1, stackCentralW); mainLayout->insertWidget (2, new QLabel ("Controls")); } void timerEvent (QTimerEvent *) { static int tickCount = 0; ++ tickCount; if (tickCount == 5) { videoWidget->resize (800, 600); // resize(size() - stackCentralW->size() + QSize(800, 600)); } if (tickCount == 7) { // videoWidget->resize (800, 600); resize(size() - stackCentralW->size() + QSize(800, 600)); } #ifdef Q_WS_PM if (id) { qDebug() << "window handle" << qDebugFmtHex (id); SWP swp; WinQueryWindowPos (videoWidget->internalWinId(), &swp); qDebug() << "---" << swp; HWND hwnd = id; RECTL rcl; WinQueryWindowRect (hwnd, &rcl); HPS hps = WinGetPS (hwnd); if (hps) { #ifdef QT_PM_NATIVEWIDGETMASK HRGN hrgn = GpiCreateRegion(hps, 1L, &rcl); ULONG rc = qt_WinProcessWindowObstacles (hwnd, NULL, hrgn, CRGN_DIFF, PWO_Default); qDebug() << "rc" << rc; if (rc == RGN_RECT || rc == RGN_COMPLEX) { HRGN hrgnOld; GpiSetClipRegion (hps, hrgn, &hrgnOld); hrgn = hrgnOld; #endif rcl.xLeft = 0; rcl.yBottom = 0; rcl.xRight = videoWidget->size().width(); rcl.yTop = videoWidget->size().height(); qDebug() << rcl.xRight << rcl.yTop; WinDrawBorder (hps, &rcl, 3, 3, CLR_RED, CLR_DARKGREEN, DB_INTERIOR); #ifdef QT_PM_NATIVEWIDGETMASK } GpiDestroyRegion (hps, hrgn); #endif WinReleasePS (hps); } } #endif #ifdef Q_WS_WIN if (id) { qDebug() << "window handle" << id; HDC hdc = GetDC (id); RECT rect; rect.left = 0; rect.top = 0; rect.right = videoWidget->size().width(); rect.bottom = videoWidget->size().height(); SetDCBrushColor (hdc, RGB (0x00, 0x80, 0x00)); FillRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH)); SetDCBrushColor (hdc, RGB (0xFF, 0x00, 0x00)); FrameRect (hdc, &rect, (HBRUSH) GetStockObject (DC_BRUSH)); ReleaseDC (id, hdc); } #endif } public slots: void playTriggered (bool checked) { if (checked) { stackCentralW->setCurrentWidget (videoWidget); id = videoWidget->request(); timerId = startTimer (1000); } else { videoWidget->release(); id = 0; killTimer (timerId); timerId = 0; stackCentralW->setCurrentWidget (bgWidget); } } void playListTriggered (bool checked) { if (checked) { stackCentralW->setCurrentWidget (bgWidget); } else { stackCentralW->setCurrentWidget (videoWidget); } } public: QStackedWidget *stackCentralW; QLabel *bgWidget; VideoWidget *videoWidget; WId id; int timerId; }; int main (int argc, char **argv) { QApplication app (argc, argv); MainWindow window; window.resize (400, 300); window.show(); return app.exec(); } #include "embedded.moc"