qv4l2: improve full-screen handling
authorHans Verkuil <hans.verkuil@cisco.com>
Sat, 19 Jul 2014 20:29:24 +0000 (22:29 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Sat, 19 Jul 2014 20:29:24 +0000 (22:29 +0200)
Improved the full screen handling. In particular selecting the fullscreen
mode will no longer automatically start streaming, that was not meant to
happen. Also route all fullscreen handling through the correct QAction
rather than duplicating it in the capture window. This ensures a consistent
internal state.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/capture-win.cpp
utils/qv4l2/capture-win.h
utils/qv4l2/qv4l2.cpp
utils/qv4l2/qv4l2.h

index afca6bd..479c0d5 100644 (file)
@@ -41,15 +41,14 @@ CaptureWin::CaptureWin(ApplicationWindow *aw) :
        connect(m_hotkeyClose, SIGNAL(activated()), this, SLOT(close()));
        m_hotkeyScaleReset = new QShortcut(Qt::CTRL+Qt::Key_F, this);
        connect(m_hotkeyScaleReset, SIGNAL(activated()), this, SLOT(resetSize()));
+       connect(aw->m_resetScalingAct, SIGNAL(triggered()), this, SLOT(resetSize()));
        m_hotkeyExitFullscreen = new QShortcut(Qt::Key_Escape, this);
        connect(m_hotkeyExitFullscreen, SIGNAL(activated()), this, SLOT(escape()));
        m_hotkeyToggleFullscreen = new QShortcut(Qt::Key_F, this);
-       connect(m_hotkeyToggleFullscreen, SIGNAL(activated()), this, SLOT(fullScreen()));
+       connect(m_hotkeyToggleFullscreen, SIGNAL(activated()), aw->m_makeFullScreenAct, SLOT(toggle()));
        m_exitFullScreen = new QAction(QIcon(":/fullscreenexit.png"), "Exit Fullscreen", this);
-       m_exitFullScreen->setShortcut(Qt::Key_Escape);
        connect(m_exitFullScreen, SIGNAL(triggered()), this, SLOT(escape()));
        m_enterFullScreen = new QAction(QIcon(":/fullscreen.png"), "Show Fullscreen", this);
-       m_enterFullScreen->setShortcut(Qt::Key_F);
        connect(m_enterFullScreen, SIGNAL(triggered()), this, SLOT(fullScreen()));
        m_frame.format = 0;
        m_frame.size.setWidth(0);
@@ -117,7 +116,7 @@ void CaptureWin::buildWindow(QWidget *videoSurface)
        m_fullscreenButton->setMaximumWidth(200);
        m_fullscreenButton->setMinimumWidth(100);
        hbox->addWidget(m_fullscreenButton, 1, Qt::AlignVCenter);
-       connect(m_fullscreenButton, SIGNAL(clicked()), SLOT(fullScreen()));
+       connect(m_fullscreenButton, SIGNAL(clicked()), appWin->m_makeFullScreenAct, SLOT(toggle()));
        vbox->addWidget(bottom, 0, Qt::AlignBottom);
        vbox->getContentsMargins(&l, &t, &r, &b);
        vbox->setSpacing(t+b);
@@ -128,10 +127,8 @@ void CaptureWin::buildWindow(QWidget *videoSurface)
 
 void CaptureWin::resetSize()
 {
-       if (isFullScreen())
-               toggleFullScreen();
-       if (isMaximized())
-               showNormal();
+       if (appWin->m_makeFullScreenAct->isChecked())
+               escape();
 
         // Force resize even if no size change
        QSize resetFrameSize = m_origFrameSize;
@@ -301,9 +298,9 @@ void CaptureWin::setPixelAspectRatio(double ratio)
        resetSize();
 }
 
-void CaptureWin::mouseDoubleClickEvent( QMouseEvent * e )
+void CaptureWin::mouseDoubleClickEvent(QMouseEvent *e)
 {
-       toggleFullScreen();
+       appWin->m_makeFullScreenAct->toggle();
 }
 
 bool CaptureWin::eventFilter(QObject *target, QEvent *event)
@@ -327,20 +324,25 @@ bool CaptureWin::eventFilter(QObject *target, QEvent *event)
        return false;
 }
 
-void CaptureWin::fullScreen()
+void CaptureWin::escape()
 {
-       toggleFullScreen();
+       appWin->m_makeFullScreenAct->setChecked(false);
 }
 
-void CaptureWin::escape()
+void CaptureWin::fullScreen()
 {
-       if(isFullScreen())
-               toggleFullScreen();
+       appWin->m_makeFullScreenAct->setChecked(true);
 }
 
-void CaptureWin::toggleFullScreen()
+void CaptureWin::makeFullScreen(bool enable)
 {
-       if (isFullScreen()) {
+       if (enable) {
+               showFullScreen();
+               m_fullscreenButton->setText("Exit Fullscreen");
+               setStyleSheet("background-color:#000000;");
+               m_fullscreenButton->hide();
+               m_information.hide();
+       } else {
                showNormal();
                bottom->setMinimumHeight(0);
                bottom->setMaximumHeight(height());
@@ -349,18 +351,12 @@ void CaptureWin::toggleFullScreen()
                bottom->setStyleSheet("background-color:none;");
                m_fullscreenButton->show();
                m_information.show();
-       } else {
-               showFullScreen();
-               m_fullscreenButton->setText("Exit Fullscreen");
-               setStyleSheet("background-color:#000000;");
-               m_fullscreenButton->hide();
-               m_information.hide();
        }
 }
 
 void CaptureWin::customMenuRequested(QPoint pos)
 {
-       QMenu *menu=new QMenu(this);
+       QMenu *menu = new QMenu(this);
        
        if (isFullScreen()) {
                menu->addAction(m_exitFullScreen);
index 8f49ebd..ad851ca 100644 (file)
@@ -73,7 +73,7 @@ public:
        virtual void setDisplayColorspace(unsigned colorspace) = 0;
        virtual void setBlending(bool enable) = 0;
        void setCropMethod(CropMethod crop);
-       void toggleFullScreen();
+       void makeFullScreen(bool);
        QAction *m_exitFullScreen;
        QAction *m_enterFullScreen;
 
@@ -155,8 +155,8 @@ public slots:
        void customMenuRequested(QPoint pos);
 
 private slots:
-       void fullScreen();
        void escape();
+       void fullScreen();
 
 protected:
        void closeEvent(QCloseEvent *event);
index 197d7ad..cc12d3a 100644 (file)
@@ -145,6 +145,7 @@ ApplicationWindow::ApplicationWindow() :
        m_scalingAct->setCheckable(true);
        m_scalingAct->setChecked(true);
        connect(m_scalingAct, SIGNAL(toggled(bool)), this, SLOT(enableScaling(bool)));
+
        m_resetScalingAct = new QAction("Resize to &Frame Size", this);
        m_resetScalingAct->setStatusTip("Resizes the capture window to match frame size");
        m_resetScalingAct->setShortcut(Qt::CTRL+Qt::Key_F);
@@ -153,7 +154,6 @@ ApplicationWindow::ApplicationWindow() :
        captureMenu->addAction(m_capStartAct);
        captureMenu->addAction(m_showFramesAct);
        captureMenu->addAction(m_scalingAct);
-       captureMenu->addAction(m_resetScalingAct);
 
        if (CaptureWinGL::isSupported()) {
                m_renderMethod = QV4L2_RENDER_GL;
@@ -162,24 +162,26 @@ ApplicationWindow::ApplicationWindow() :
                m_useGLAct->setStatusTip("Use GPU with OpenGL for video capture if set.");
                m_useGLAct->setCheckable(true);
                m_useGLAct->setChecked(true);
-               connect(m_useGLAct, SIGNAL(triggered()), this, SLOT(setRenderMethod()));
+               connect(m_useGLAct, SIGNAL(toggled(bool)), this, SLOT(setRenderMethod(bool)));
                captureMenu->addAction(m_useGLAct);
 
                m_useBlendingAct = new QAction("Enable &Blending", this);
                m_useBlendingAct->setStatusTip("Enable blending to test the alpha component in the image");
                m_useBlendingAct->setCheckable(true);
                m_useBlendingAct->setChecked(false);
-               connect(m_useBlendingAct, SIGNAL(triggered()), this, SLOT(setBlending()));
+               connect(m_useBlendingAct, SIGNAL(toggled(bool)), this, SLOT(setBlending(bool)));
                captureMenu->addAction(m_useBlendingAct);
        } else {
                m_renderMethod = QV4L2_RENDER_QT;
        }
+       captureMenu->addAction(m_resetScalingAct);
        
-       m_startFullScreenAct = new QAction(QIcon(":/fullscreen.png"), "Enter Fullscreen Mode", this);
-       m_startFullScreenAct->setStatusTip("Start capturing in fullscreen mode");
-       connect(m_startFullScreenAct, SIGNAL(triggered()), this, SLOT(startFullScreen()));
-       captureMenu->addAction(m_startFullScreenAct);
-       toolBar->addAction(m_startFullScreenAct);
+       m_makeFullScreenAct = new QAction(QIcon(":/fullscreen.png"), "Show Fullscreen", this);
+       m_makeFullScreenAct->setStatusTip("Capture in fullscreen mode");
+       m_makeFullScreenAct->setCheckable(true);
+       connect(m_makeFullScreenAct, SIGNAL(toggled(bool)), this, SLOT(makeFullScreen(bool)));
+       captureMenu->addAction(m_makeFullScreenAct);
+       toolBar->addAction(m_makeFullScreenAct);
 
 #ifdef HAVE_ALSA
        captureMenu->addSeparator();
@@ -298,27 +300,23 @@ void ApplicationWindow::openrawdev()
                setDevice(d.selectedFiles().first(), true);
 }
 
-void ApplicationWindow::setRenderMethod()
+void ApplicationWindow::setRenderMethod(bool checked)
 {
        if (m_capStartAct->isChecked()) {
                m_useGLAct->setChecked(m_renderMethod == QV4L2_RENDER_GL);
                return;
        }
 
-       if (m_useGLAct->isChecked()) {
-               m_renderMethod = QV4L2_RENDER_GL;
-       } else {
-               m_renderMethod = QV4L2_RENDER_QT;
-       }
+       m_renderMethod = checked ? QV4L2_RENDER_GL : QV4L2_RENDER_QT;
        m_useBlendingAct->setEnabled(m_renderMethod == QV4L2_RENDER_GL);
 
        newCaptureWin();
 }
 
-void ApplicationWindow::setBlending()
+void ApplicationWindow::setBlending(bool checked)
 {
        if (m_capture)
-               m_capture->setBlending(m_useBlendingAct->isChecked());
+               m_capture->setBlending(checked);
 }
 
 void ApplicationWindow::setAudioBufferSize()
@@ -408,7 +406,6 @@ void ApplicationWindow::newCaptureWin()
        m_capture->setPixelAspectRatio(1.0);
        m_capture->enableScaling(m_scalingAct->isChecked());
         connect(m_capture, SIGNAL(close()), this, SLOT(closeCaptureWin()));
-       connect(m_resetScalingAct, SIGNAL(triggered()), m_capture, SLOT(resetSize()));
 }
 
 void ApplicationWindow::capVbiFrame()
@@ -1222,6 +1219,7 @@ void ApplicationWindow::capStart(bool start)
        m_capture->setWindowSize(QSize(width, height));
        m_capture->setFrame(m_capImage->width(), m_capImage->height(),
                            pixfmt, m_capImage->bits(), NULL, "No frame");
+       m_capture->makeFullScreen(m_makeFullScreenAct->isChecked());
        if (showFrames())
                m_capture->show();
 
@@ -1232,16 +1230,10 @@ void ApplicationWindow::capStart(bool start)
        }
 }
 
-void ApplicationWindow::startFullScreen()
+void ApplicationWindow::makeFullScreen(bool checked)
 {
-       if (!m_capture || !m_capStartAct->isChecked()){
-               newCaptureWin();
-               m_capStartAct->setChecked(true);
-               m_capture->toggleFullScreen();
-       } else {
-               m_capStartAct->setChecked(true);
-               m_capture->toggleFullScreen();
-       }  
+       if (m_capture && m_capStartAct->isChecked())
+               m_capture->makeFullScreen(checked);
 }
 
 void ApplicationWindow::closeDevice()
index d33f82c..949e6a4 100644 (file)
@@ -78,10 +78,13 @@ struct buffer {
                                 V4L2_CTRL_FLAG_INACTIVE | \
                                 V4L2_CTRL_FLAG_GRABBED)
 
+class CaptureWin;
+
 class ApplicationWindow: public QMainWindow, public v4l2
 {
        Q_OBJECT
 
+       friend CaptureWin;
 public:
        ApplicationWindow();
        virtual ~ApplicationWindow();
@@ -118,14 +121,14 @@ private:
 
 private slots:
        void capStart(bool);
-       void startFullScreen();
+       void makeFullScreen(bool);
        void capFrame();
        void ctrlEvent();
        void snapshot();
        void capVbiFrame();
        void saveRaw(bool);
-       void setRenderMethod();
-       void setBlending();
+       void setRenderMethod(bool);
+       void setBlending(bool);
        void changeAudioDevice();
 
        // gui
@@ -206,7 +209,7 @@ private:
        QAction *m_showAllAudioAct;
        QAction *m_audioBufferAct;
        QAction *m_scalingAct;
-       QAction *m_startFullScreenAct;
+       QAction *m_makeFullScreenAct;
        QString m_filename;
        QSignalMapper *m_sigMapper;
        QTabWidget *m_tabs;