qv4l2: refactor window size setting at capture start
authorHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 13:36:08 +0000 (15:36 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Fri, 11 Jul 2014 13:36:08 +0000 (15:36 +0200)
- Renamed resize(), may conflict with inherited QWidget functions
- Clear separation between window size and frame size in setWindowSize()
- Use QSize and its methods where applicable
- Reset (window) size also refactored accordingly

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

index 7c080e8..4b89944 100644 (file)
@@ -107,11 +107,11 @@ void CaptureWin::resetSize()
                showNormal();
 
         // Force resize even if no size change
-       int w = m_origFrameSize.width();
-       int h = m_origFrameSize.height();
+       QSize resetFrameSize = m_origFrameSize;
        m_origFrameSize.setWidth(0);
        m_origFrameSize.setHeight(0);
-       resize(w, h);
+
+       setWindowSize(resetFrameSize);
 }
 
 QSize CaptureWin::cropFrameSize(QSize size)
@@ -163,12 +163,12 @@ QSize CaptureWin::cropFrameSize(QSize size)
 
 void CaptureWin::updateSize()
 {
-       m_crop.updated = 0;
+       m_crop.updated = false;
        if (m_frame.updated) {
                m_scaledSize = scaleFrameSize(m_windowSize, m_frame.size);
                m_crop.delta = cropFrameSize(m_frame.size);
                m_crop.size = m_frame.size - 2 * m_crop.delta;
-               m_crop.updated = 1;
+               m_crop.updated = true;
        }
 }
 
@@ -214,41 +214,37 @@ void CaptureWin::enableScaling(bool enable)
        QCoreApplication::sendEvent(this, &event);
 }
 
-void CaptureWin::resize(int width, int height)
+void CaptureWin::setWindowSize(QSize frameSize)
 {
-       QSize newSize;
-
        // Dont resize window if the frame size is the same in
        // the event the window has been paused when beeing resized.
-       if (width == m_origFrameSize.width() && height == m_origFrameSize.height())
+       if (frameSize == m_origFrameSize)
                return;
 
-       m_origFrameSize.setWidth(width);
-       m_origFrameSize.setHeight(height);
+       m_origFrameSize = frameSize;
 
        QSize margins = getMargins();
-
-       newSize =  margins + pixelAspectFrameSize(m_origFrameSize)
-               - 2 * cropFrameSize(m_origFrameSize);
-
-       width =  newSize.width();
-       height = newSize.height();
-
        QDesktopWidget *screen = QApplication::desktop();
        QRect resolution = screen->screenGeometry();
 
-       if (width > resolution.width())
-               width = resolution.width();
-       if (width < MIN_WIN_SIZE_WIDTH)
-               width = MIN_WIN_SIZE_WIDTH;
+       QSize windowSize =  margins + pixelAspectFrameSize(frameSize)
+               - 2 * cropFrameSize(frameSize);
+
+       if (windowSize.width() > resolution.width())
+               windowSize.setWidth(resolution.width());
+       if (windowSize.width() < MIN_WIN_SIZE_WIDTH)
+               windowSize.setWidth(MIN_WIN_SIZE_WIDTH);
 
-       if (height > resolution.height())
-               height = resolution.height();
-       if (height < MIN_WIN_SIZE_HEIGHT)
-               height = MIN_WIN_SIZE_HEIGHT;
+       if (windowSize.height() > resolution.height())
+               windowSize.setHeight(resolution.height());
+       if (windowSize.height() < MIN_WIN_SIZE_HEIGHT)
+               windowSize.setHeight(MIN_WIN_SIZE_HEIGHT);
 
        QWidget::setMinimumSize(MIN_WIN_SIZE_WIDTH, MIN_WIN_SIZE_HEIGHT);
-       QWidget::resize(width, height);
+
+       m_frame.size = frameSize;
+
+       QWidget::resize(windowSize);
 }
 
 QSize CaptureWin::scaleFrameSize(QSize window, QSize frame)
index c1a1c25..3ba4755 100644 (file)
@@ -62,7 +62,7 @@ public:
        CaptureWin();
        ~CaptureWin();
 
-       void resize(int minw, int minh);
+       void setWindowSize(QSize size);
        void enableScaling(bool enable);
        void setPixelAspectRatio(double ratio);
        virtual void setColorspace(unsigned colorspace) = 0;
index 01df22b..dc9e350 100644 (file)
@@ -1112,9 +1112,9 @@ void ApplicationWindow::capStart(bool start)
                m_frameData = new unsigned char[m_vbiSize];
                m_capImage = new QImage(m_vbiWidth, m_vbiHeight, dstFmt);
                m_capImage->fill(0);
+               m_capture->setWindowSize(QSize(m_vbiWidth, m_vbiHeight));
                m_capture->setFrame(m_capImage->width(), m_capImage->height(),
                                    m_capDestFormat.fmt.pix.pixelformat, m_capImage->bits(), NULL, "No frame");
-               m_capture->resize(m_vbiWidth, m_vbiHeight);
                if (showFrames())
                        m_capture->show();
 
@@ -1185,10 +1185,10 @@ void ApplicationWindow::capStart(bool start)
        m_capture->setColorspace(colorspace);
        m_capture->setField(field);
        m_capture->setDisplayColorspace(m_genTab->getDisplayColorspace());
-       
+
+       m_capture->setWindowSize(QSize(width, height));
        m_capture->setFrame(m_capImage->width(), m_capImage->height(),
                            pixfmt, m_capImage->bits(), NULL, "No frame");
-       m_capture->resize(width, height);
        if (showFrames())
                m_capture->show();