qv4l2: bugfix and dynamic adjustments
authorAnton Arbring <aarbring@cisco.com>
Mon, 14 Jul 2014 14:23:57 +0000 (16:23 +0200)
committerHans Verkuil <hans.verkuil@cisco.com>
Tue, 15 Jul 2014 08:10:20 +0000 (10:10 +0200)
* defined a few hard coded values as consts
* calculate height of window in a more dynamic manner
* recalculate width of columns when subchannels label is changed
* changed horizontal stretch

Signed-off-by: Anton Arbring <aarbring@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
utils/qv4l2/ctrl-tab.cpp
utils/qv4l2/general-tab.cpp
utils/qv4l2/general-tab.h
utils/qv4l2/qv4l2.cpp
utils/qv4l2/qv4l2.h

index a036c7d..0adbd4a 100644 (file)
@@ -63,6 +63,8 @@ void ApplicationWindow::addWidget(QGridLayout *grid, QWidget *w, Qt::Alignment a
                w->setMinimumWidth(m_minWidth);
        if (w->sizeHint().width() > m_maxw[m_col])
                m_maxw[m_col] = w->sizeHint().width();
+       if (w->sizeHint().height() > m_maxh)
+               m_maxh = w->sizeHint().height();
        grid->addWidget(w, m_row, m_col, align | Qt::AlignVCenter);
        m_col++;
        if (m_col == m_cols) {
@@ -182,18 +184,20 @@ void ApplicationWindow::addTabs(int size[])
 
                int totalw = 0;
                int totalh = 0;
+               int diff = 0;
                for (int i = 0; i < m_cols; i++) {
-                       if (i % 2)
-                               totalw += m_maxw[i] + m_pxw;
-                       else
-                               totalw += m_maxw[i];
+                       totalw += m_maxw[i] + m_pxw;
                }
-               totalh = grid->rowCount() * 20;
+               totalh = grid->rowCount() * m_maxh;
                if (totalw > size[0])
                        size[0] = totalw;
+               else {
+                 diff = size[0] - totalw;
+                 grid->setHorizontalSpacing(diff/5);
+               }
                if (totalh > size[1])
                        size[1] = totalh;
-               setMinimumSize(size[0] + 50, size[1] + 150);
+               setMinimumSize(size[0], size[1]);
 
                grid = new QGridLayout(w);
                finishGrid(grid, ctrl_class);
@@ -202,9 +206,8 @@ void ApplicationWindow::addTabs(int size[])
 
 void ApplicationWindow::fixWidth(QGridLayout *grid)
 {
-       double m_pxw = 25.0;
-       grid->setContentsMargins(15, 5, 15, 5);
-       grid->setColumnStretch(1, 1);
+       grid->setContentsMargins(m_vMargin, m_hMargin, m_vMargin, m_hMargin);
+       grid->setColumnStretch(3, 1);
        QList<QWidget *> list = grid->parentWidget()->parentWidget()->findChildren<QWidget *>();
        QList<QWidget *>::iterator it;
 
index e7be8c1..af64986 100644 (file)
@@ -49,6 +49,11 @@ GeneralTab::GeneralTab(const QString &device, v4l2 &fd, int n, QWidget *parent)
        m_row(0),
        m_col(0),
        m_cols(n),
+       m_minWidth(175),
+       m_pxw(25.0),
+       m_vMargin(10),
+       m_hMargin(20),
+       m_maxh(0),
        m_isRadio(false),
        m_isSDR(false),
        m_isVbi(false),
@@ -101,7 +106,6 @@ GeneralTab::GeneralTab(const QString &device, v4l2 &fd, int n, QWidget *parent)
 {
        m_device.append(device);
        setSizeConstraint(QLayout::SetMinimumSize);
-       m_minWidth = 175;
        for (int i = 0; i < n; i++) {
                m_maxw[i] = 0;
        }
@@ -754,9 +758,8 @@ void GeneralTab::cropSection()
 
 void GeneralTab::fixWidth()
 {
-       m_pxw = 25.0;
-       setContentsMargins(20, 10, 20, 10);
-       setColumnStretch(1, 1);
+       setContentsMargins(m_hMargin, m_vMargin, m_hMargin, m_vMargin);
+       setColumnStretch(3, 1);
 
        QList<QWidget *> list = parentWidget()->findChildren<QWidget *>();
        QList<QWidget *>::iterator it;
@@ -770,7 +773,7 @@ void GeneralTab::fixWidth()
        // fix width of subgrids
        QList<QGridLayout *>::iterator i;
        for (i = m_grids.begin(); i != m_grids.end(); ++i) {
-               (*i)->setColumnStretch(1, 1);
+               (*i)->setColumnStretch(3, 1);
                (*i)->setContentsMargins(0, 0, 0, 0);
                for (int n = 0; n < (*i)->count(); n++) {
                        if ((*i)->itemAt(n)->widget()->sizeHint().width() > m_maxw[n % 4]) {
@@ -1047,6 +1050,8 @@ void GeneralTab::addWidget(QWidget *w, Qt::Alignment align)
                w->setMinimumWidth(m_minWidth);
        if (w->sizeHint().width() > m_maxw[m_col])
                m_maxw[m_col] = w->sizeHint().width();
+       if (w->sizeHint().height() > m_maxh)
+               m_maxh = w->sizeHint().height();
        QGridLayout::addWidget(w, m_row, m_col, align | Qt::AlignVCenter);
        m_col++;
        if (m_col == m_cols) {
@@ -1078,19 +1083,15 @@ void GeneralTab::addTitle(const QString &titlename)
 int GeneralTab::getWidth()
 {
        int total = 0;
-
        for (int i = 0; i < m_cols; i++) {
-               if (i % 2)
-                       total += m_maxw[i] + m_pxw;
-               else
-                       total += m_maxw[i];
+               total += m_maxw[i] + m_pxw;
        }
        return total;
 }
 
 int GeneralTab::getHeight()
 {
-       return m_row * 20;
+       return m_row * m_maxh;
 }
 
 bool GeneralTab::isSlicedVbi() const
@@ -1257,7 +1258,9 @@ void GeneralTab::detectSubchansClicked()
        if (m_tuner.signal && m_tuner.afc)
                chans += m_tuner.afc < 0 ? " too low" : " too high";
        chans += ")";
+
        m_subchannels->setText(chans);
+       fixWidth();
 }
 
 void GeneralTab::stereoModeChanged()
@@ -1497,8 +1500,10 @@ void GeneralTab::updateVideoInput()
                        m_freqChannel->setEnabled(enableFreq);
                if (m_detectSubchans) {
                        m_detectSubchans->setEnabled(enableFreq);
-                       if (!enableFreq)
+                       if (!enableFreq) {
                                m_subchannels->setText("");
+                               fixWidth();
+                       }
                        else
                                detectSubchansClicked();
                }
index 4b3fdca..4ee0395 100644 (file)
@@ -189,10 +189,13 @@ private:
        int m_row;
        int m_col;
        int m_cols;
-       int m_minWidth;
-       double m_pxw;
+       const int m_minWidth;
+       const double m_pxw;
+       const int m_vMargin;
+       const int m_hMargin;
        int m_increment;
        int m_maxw[4];
+       int m_maxh;
        bool m_isRadio;
        bool m_isSDR;
        bool m_isVbi;
index dc9e350..02b56c4 100644 (file)
@@ -62,6 +62,11 @@ extern "C" {
 
 ApplicationWindow::ApplicationWindow() :
        m_capture(NULL),
+       m_pxw(25),
+       m_minWidth(175),
+       m_vMargin(15),
+       m_hMargin(5),
+       m_maxh(0),
        m_genTab(NULL),
        m_sigMapper(NULL)
 {
@@ -74,7 +79,6 @@ ApplicationWindow::ApplicationWindow() :
        m_nbuffers = 0;
        m_buffers = NULL;
        m_makeSnapshot = false;
-       m_minWidth = 175;
 
        QAction *openAct = new QAction(QIcon(":/fileopen.png"), "&Open Device", this);
        openAct->setStatusTip("Open a v4l device, use libv4l2 wrapper if possible");
@@ -226,7 +230,7 @@ void ApplicationWindow::setDevice(const QString &device, bool rawOpen)
        int size[2];
        size[0] = m_genTab->getWidth();
        size[1] = m_genTab->getHeight();
-       setMinimumSize(size[0] + 50, size[1] + 150); // +margins, menus
+       setMinimumSize(size[0], size[1]);
 
 #ifdef HAVE_ALSA
        if (m_genTab->hasAlsaAudio()) {
index 2f21ddc..a73ee51 100644 (file)
@@ -105,7 +105,6 @@ private:
        void startAudio();
        void stopAudio();
 
-       int m_maxw[4];
        struct buffer *m_buffers;
        struct v4l2_format m_capSrcFormat;
        struct v4l2_format m_capDestFormat;
@@ -188,8 +187,12 @@ private:
        void updateFreqChannel();
        bool showFrames();
 
-       double m_pxw;
-       double m_minWidth;
+       const double m_pxw;
+       const int m_minWidth;
+       const int m_vMargin;
+       const int m_hMargin;
+       int m_maxw[4];
+       int m_maxh;
        int m_increment;
        GeneralTab *m_genTab;
        VbiTab *m_vbiTab;