]> git.sesse.net Git - nageru/commitdiff
Make the analyzer UI responsive.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 May 2017 21:46:40 +0000 (23:46 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 11 May 2017 23:08:56 +0000 (01:08 +0200)
analyzer.cpp
analyzer.h
ui_analyzer.ui

index a73058f5714118bc8ececbad0d88d8de70c1ed30..90d61ac9f740c1d1fce61ae4b03d73554a579331 100644 (file)
@@ -239,3 +239,100 @@ bool Analyzer::eventFilter(QObject *watched, QEvent *event)
         }
         return false;
 }
+
+void Analyzer::resizeEvent(QResizeEvent* event)
+{
+       QMainWindow::resizeEvent(event);
+
+       // Ask for a relayout, but only after the event loop is done doing relayout
+       // on everything else.
+       QMetaObject::invokeMethod(this, "relayout", Qt::QueuedConnection);
+}
+
+void Analyzer::relayout()
+{
+       double aspect = double(global_flags.width) / global_flags.height;
+
+       // Left pane (2/5 of the width).
+       {
+               int width = ui->left_pane->geometry().width();
+               int height = ui->left_pane->geometry().height();
+
+               // Figure out how much space everything that's non-responsive needs.
+               int remaining_height = height - ui->left_pane->spacing() * (ui->left_pane->count() - 1);
+
+               remaining_height -= ui->grab_btn->geometry().height();
+               ui->left_pane->setStretch(2, ui->grab_btn->geometry().height());
+
+               remaining_height -= ui->histogram_label->geometry().height();
+               ui->left_pane->setStretch(4, ui->histogram_label->geometry().height());
+
+               // The histogram's minimumHeight returns 0, so let's set a reasonable minimum for it.
+               int min_histogram_height = 50;
+               remaining_height -= min_histogram_height;
+
+               // Allocate so that the display is 16:9, if possible.
+               unsigned wanted_display_height = width / aspect;
+               unsigned display_height;
+               unsigned margin = 0;
+               if (remaining_height >= int(wanted_display_height)) {
+                       display_height = wanted_display_height;
+               } else {
+                       display_height = remaining_height;
+                       int display_width = lrint(display_height * aspect);
+                       margin = (width - display_width) / 2;
+               }
+               ui->left_pane->setStretch(1, display_height);
+               ui->display_left_spacer->changeSize(margin, 1);
+               ui->display_right_spacer->changeSize(margin, 1);
+
+               remaining_height -= display_height;
+
+               // Figure out if we can do the histogram at 16:9.
+               remaining_height += min_histogram_height;
+               unsigned histogram_height;
+               if (remaining_height >= int(wanted_display_height)) {
+                       histogram_height = wanted_display_height;
+               } else {
+                       histogram_height = remaining_height;
+               }
+               remaining_height -= histogram_height;
+               ui->left_pane->setStretch(3, histogram_height);
+
+               ui->left_pane->setStretch(0, remaining_height / 2);
+               ui->left_pane->setStretch(5, remaining_height / 2);
+       }
+
+       // Right pane (remaining 3/5 of the width).
+       {
+               int width = ui->right_pane->geometry().width();
+               int height = ui->right_pane->geometry().height();
+
+               // Figure out how much space everything that's non-responsive needs.
+               int remaining_height = height - ui->right_pane->spacing() * (ui->right_pane->count() - 1);
+               remaining_height -= ui->grabbed_frame_sublabel->geometry().height();
+               remaining_height -= ui->coord_label->geometry().height();
+               remaining_height -= ui->color_hbox->geometry().height();
+
+               // Allocate so that the display is 16:9, if possible.
+               unsigned wanted_display_height = width / aspect;
+               unsigned display_height;
+               unsigned margin = 0;
+               if (remaining_height >= int(wanted_display_height)) {
+                       display_height = wanted_display_height;
+               } else {
+                       display_height = remaining_height;
+                       int display_width = lrint(display_height * aspect);
+                       margin = (width - display_width) / 2;
+               }
+               ui->right_pane->setStretch(1, display_height);
+               ui->grabbed_frame_left_spacer->changeSize(margin, 1);
+               ui->grabbed_frame_right_spacer->changeSize(margin, 1);
+               remaining_height -= display_height;
+
+               if (remaining_height < 0) remaining_height = 0;
+
+               ui->right_pane->setStretch(0, remaining_height / 2);
+               ui->right_pane->setStretch(5, remaining_height / 2);
+       }
+}
index 6c7490653b506de489436d60c78cab985d99a873..d9bd8b8052348cf416020474e8876b5b94895f86 100644 (file)
@@ -28,10 +28,14 @@ public:
        ~Analyzer();
        void mixer_shutting_down();
 
+public slots:
+       void relayout();
+
 private:
        void grab_clicked();
        void signal_changed();
        bool eventFilter(QObject *watched, QEvent *event) override;
+       void resizeEvent(QResizeEvent *event) override;
 
        Ui::Analyzer *ui;
        QSurface *surface;
index d73734e210ba3d906b9d7f0405a2373727830eb2..eba57ca3786df74e34721e7519414f986ee907a6 100644 (file)
    <string>Analyzer</string>
   </property>
   <widget class="QWidget" name="centralwidget">
-   <widget class="QLabel" name="label_3">
-    <property name="geometry">
-     <rect>
-      <x>10</x>
-      <y>410</y>
-      <width>321</width>
-      <height>21</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>RGB histogram</string>
-    </property>
-    <property name="alignment">
-     <set>Qt::AlignCenter</set>
-    </property>
-   </widget>
-   <widget class="QLabel" name="label_12">
-    <property name="geometry">
-     <rect>
-      <x>600</x>
-      <y>320</y>
-      <width>191</width>
-      <height>16</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Color (8-bit sRGB):</string>
-    </property>
-    <property name="alignment">
-     <set>Qt::AlignCenter</set>
-    </property>
-   </widget>
-   <widget class="QCustomPlot" name="histogram" native="true">
-    <property name="geometry">
-     <rect>
-      <x>10</x>
-      <y>230</y>
-      <width>320</width>
-      <height>180</height>
-     </rect>
-    </property>
-    <property name="autoFillBackground">
-     <bool>false</bool>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background: rgb(173, 127, 168)</string>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="grab_btn">
-    <property name="geometry">
-     <rect>
-      <x>270</x>
-      <y>190</y>
-      <width>61</width>
-      <height>23</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Grab</string>
-    </property>
-   </widget>
-   <widget class="QComboBox" name="input_box">
-    <property name="geometry">
-     <rect>
-      <x>10</x>
-      <y>190</y>
-      <width>251</width>
-      <height>23</height>
-     </rect>
-    </property>
-   </widget>
-   <widget class="QWidget" name="gridLayoutWidget">
-    <property name="geometry">
-     <rect>
-      <x>600</x>
-      <y>340</y>
-      <width>191</width>
-      <height>80</height>
-     </rect>
-    </property>
-    <layout class="QGridLayout" name="gridLayout">
-     <item row="1" column="0">
-      <widget class="QLabel" name="label_6">
-       <property name="text">
-        <string>Green:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="1" column="1">
-      <widget class="QLabel" name="green_label">
-       <property name="text">
-        <string>127</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="1">
-      <widget class="QLabel" name="blue_label">
-       <property name="text">
-        <string>127</string>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="0">
-      <widget class="QLabel" name="label_2">
-       <property name="text">
-        <string>Hex:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="1">
-      <widget class="QLabel" name="red_label">
-       <property name="text">
-        <string>127</string>
-       </property>
-      </widget>
-     </item>
-     <item row="2" column="0">
-      <widget class="QLabel" name="label_7">
-       <property name="text">
-        <string>Blue:</string>
-       </property>
-      </widget>
-     </item>
-     <item row="3" column="1">
-      <widget class="QLabel" name="hex_label">
-       <property name="text">
-        <string>#7f7f7f</string>
-       </property>
-      </widget>
-     </item>
-     <item row="0" column="0">
-      <widget class="QLabel" name="label_5">
-       <property name="text">
-        <string>Red:</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </widget>
-   <widget class="QLabel" name="grabbed_frame_label">
-    <property name="geometry">
-     <rect>
-      <x>350</x>
-      <y>0</y>
-      <width>480</width>
-      <height>270</height>
-     </rect>
-    </property>
-    <property name="cursor">
-     <cursorShape>CrossCursor</cursorShape>
-    </property>
-    <property name="mouseTracking">
-     <bool>true</bool>
-    </property>
-    <property name="autoFillBackground">
-     <bool>false</bool>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background: color(0,0,0)</string>
-    </property>
-    <property name="text">
-     <string/>
-    </property>
-    <property name="scaledContents">
-     <bool>true</bool>
-    </property>
-   </widget>
-   <widget class="QLabel" name="grabbed_frame_sublabel">
-    <property name="geometry">
-     <rect>
-      <x>350</x>
-      <y>270</y>
-      <width>481</width>
-      <height>21</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Grabbed frame</string>
-    </property>
-    <property name="alignment">
-     <set>Qt::AlignCenter</set>
-    </property>
-   </widget>
-   <widget class="QLabel" name="label">
-    <property name="geometry">
-     <rect>
-      <x>370</x>
-      <y>300</y>
-      <width>421</width>
-      <height>21</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Selected coordinate (x,y): (123,456)</string>
-    </property>
-   </widget>
-   <widget class="GLWidget" name="display" native="true">
-    <property name="geometry">
-     <rect>
-      <x>10</x>
-      <y>0</y>
-      <width>320</width>
-      <height>180</height>
-     </rect>
-    </property>
-    <property name="autoFillBackground">
-     <bool>false</bool>
-    </property>
-    <property name="styleSheet">
-     <string notr="true">background: rgb(233, 185, 110)</string>
-    </property>
-   </widget>
+   <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="2,3">
+    <item>
+     <layout class="QVBoxLayout" name="left_pane" stretch="0,1,0,1,0,0">
+      <item>
+       <spacer name="verticalSpacer">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>5</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="display_centerer" stretch="0,1,0">
+        <property name="spacing">
+         <number>0</number>
+        </property>
+        <item>
+         <spacer name="display_left_spacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>5</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="GLWidget" name="display" native="true">
+          <property name="enabled">
+           <bool>true</bool>
+          </property>
+          <property name="autoFillBackground">
+           <bool>true</bool>
+          </property>
+          <property name="styleSheet">
+           <string notr="true">background: rgb(233, 185, 110)</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="display_right_spacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>5</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="grab_horizontal_layout" stretch="1,0">
+        <item>
+         <widget class="QComboBox" name="input_box"/>
+        </item>
+        <item>
+         <widget class="QPushButton" name="grab_btn">
+          <property name="text">
+           <string>Grab</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <widget class="QCustomPlot" name="histogram" native="true">
+        <property name="autoFillBackground">
+         <bool>false</bool>
+        </property>
+        <property name="styleSheet">
+         <string notr="true">background: rgb(173, 127, 168)</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLabel" name="histogram_label">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="text">
+         <string>RGB histogram</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="verticalSpacer_2">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>5</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </item>
+    <item>
+     <layout class="QVBoxLayout" name="right_pane" stretch="0,1,0,0,0,0">
+      <item>
+       <spacer name="verticalSpacer_3">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>5</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="grabbed_frame_enterer" stretch="0,1,0">
+        <property name="spacing">
+         <number>0</number>
+        </property>
+        <item>
+         <spacer name="grabbed_frame_left_spacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>5</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item>
+         <widget class="QLabel" name="grabbed_frame_label">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Ignored" vsizetype="Ignored">
+            <horstretch>1</horstretch>
+            <verstretch>1</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="cursor">
+           <cursorShape>CrossCursor</cursorShape>
+          </property>
+          <property name="mouseTracking">
+           <bool>true</bool>
+          </property>
+          <property name="autoFillBackground">
+           <bool>false</bool>
+          </property>
+          <property name="styleSheet">
+           <string notr="true">background: color(0,0,0)</string>
+          </property>
+          <property name="text">
+           <string/>
+          </property>
+          <property name="scaledContents">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <spacer name="grabbed_frame_right_spacer">
+          <property name="orientation">
+           <enum>Qt::Horizontal</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>5</width>
+            <height>20</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <widget class="QLabel" name="grabbed_frame_sublabel">
+        <property name="text">
+         <string>Grabbed frame</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QLabel" name="coord_label">
+        <property name="text">
+         <string>Selected coordinate (x,y): (123,456)</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <layout class="QHBoxLayout" name="color_hbox">
+        <item>
+         <layout class="QVBoxLayout" name="verticalLayout_4">
+          <item>
+           <widget class="QLabel" name="label_3">
+            <property name="text">
+             <string>TextLabel</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </item>
+        <item>
+         <layout class="QVBoxLayout" name="verticalLayout_3">
+          <item>
+           <widget class="QLabel" name="label_12">
+            <property name="text">
+             <string>Color (8-bit sRGB):</string>
+            </property>
+            <property name="alignment">
+             <set>Qt::AlignCenter</set>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <layout class="QGridLayout" name="gridLayout">
+            <item row="1" column="0">
+             <widget class="QLabel" name="label_6">
+              <property name="text">
+               <string>Green:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="1">
+             <widget class="QLabel" name="green_label">
+              <property name="text">
+               <string>127</string>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="1">
+             <widget class="QLabel" name="blue_label">
+              <property name="text">
+               <string>127</string>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="0">
+             <widget class="QLabel" name="label_2">
+              <property name="text">
+               <string>Hex:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="1">
+             <widget class="QLabel" name="red_label">
+              <property name="text">
+               <string>127</string>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="0">
+             <widget class="QLabel" name="label_7">
+              <property name="text">
+               <string>Blue:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="1">
+             <widget class="QLabel" name="hex_label">
+              <property name="text">
+               <string>#7f7f7f</string>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="0">
+             <widget class="QLabel" name="label_5">
+              <property name="text">
+               <string>Red:</string>
+              </property>
+             </widget>
+            </item>
+           </layout>
+          </item>
+         </layout>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <spacer name="verticalSpacer_4">
+        <property name="orientation">
+         <enum>Qt::Vertical</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>20</width>
+          <height>5</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+     </layout>
+    </item>
+   </layout>
   </widget>
  </widget>
  <customwidgets>