]> git.lyx.org Git - features.git/commitdiff
Fix broken layout of the citation dialog (#10019)
authorGuillaume Munch <gm@lyx.org>
Wed, 16 Mar 2016 21:47:32 +0000 (21:47 +0000)
committerGuillaume Munch <gm@lyx.org>
Mon, 4 Apr 2016 15:58:16 +0000 (17:58 +0200)
7b1107d7 introduced the following inconveniences which are regressions to 2.1:

* The citation dialog can open with vertical scroll bars in the options

* The citation dialog can open with horizontal scroll bars, especially if the
  translated text is longer than the original text (e.g. in FR)

* Resizing the dialog is inconvenient because it increases the gap between the
  options. This is unlike before when the dialog could let us see more of the
  reference list when enlarging.

This is because the QToolbox that the above commit introduced is not natively
aware of the sizes of its page sub-widgets. The widget is not conceived for this
use, where the space is scarce.

Geometry values provided in the ui file (automatically computed by qtcreator I
suppose) somehow gave the illusion that it worked, but relying on such values is
not portable : it does not take into account the specific theme, font sizes and
localization. This explains why it failed on my side and will probably fail in
other settings too.

Luckily, there is a simple way to make QToolbox suitable for the current use,
which is to add the "missing link" which computes its size based on the minimal
sizes of its pages. The result looks very nice and intuitive. It solves all the
aforementioned issues.

src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/ui/CitationUi.ui

index 8856ebc8668473a79e65e6587beda75254ab8e64..16c0990f7da1f0bd7a87bce1f5ce06fd6f08f4f2 100644 (file)
@@ -625,6 +625,33 @@ bool GuiCitation::initialiseParams(string const & data)
        citeCmds_ = documentBuffer().params().citeCommands();
        citeStyles_ = documentBuffer().params().citeStyles();
        init();
+
+       // Set the minimal size of the QToolbox. Without this, the size of the
+       // QToolbox is only determined by values in the ui file (e.g. computed by
+       // qtcreator) and therefore causes portability and localisation issues. In
+       // the future, this should be integrated into a custom widget if plans are
+       // made to generalise such a use of QToolboxes. Note that the page widgets
+       // must have a layout with layoutSizeContraint = SetMinimumSize or similar.
+       if (!isVisible()) {
+               // only reliable way to get the size calculations up-to-date
+               show();
+               layout()->invalidate();
+               hide();
+               // this does not show any window since hide() is called before
+               // relinquishing control
+       }
+       QSize minimum_size = QSize(0,0);
+       // Compute the max of the minimal sizes of the pages
+       QWidget * page;
+       for (int i = 0; (page = citationTB->widget(i)); ++i)
+               minimum_size = minimum_size.expandedTo(page->minimumSizeHint());
+       // Add the height of the tabs
+       if (citationTB->currentWidget())
+               minimum_size.rheight() += citationTB->height() -
+                       citationTB->currentWidget()->height();
+       citationTB->setMinimumSize(minimum_size);
+       updateGeometry();
+
        return true;
 }
 
index bfbbc0de78666c741580ec822843d0ced455c891..d10af983a670975dff3c58fb864133422a3855fe 100644 (file)
@@ -16,7 +16,7 @@
   <property name="sizeGripEnabled">
    <bool>true</bool>
   </property>
-  <layout class="QGridLayout" name="gridLayout_4">
+  <layout class="QGridLayout" name="gridLayout_4" rowstretch="1,0,0">
    <item row="0" column="0">
     <layout class="QVBoxLayout" name="verticalLayout_2">
      <item>
       <attribute name="label">
        <string>&amp;Search Citation</string>
       </attribute>
-      <layout class="QGridLayout" name="gridLayout_3">
+      <layout class="QGridLayout" name="gridLayout_3" columnstretch="0,1,0,0,0,0">
+       <property name="sizeConstraint">
+        <enum>QLayout::SetMinimumSize</enum>
+       </property>
        <item row="0" column="0">
         <widget class="QLabel" name="findKeysLA">
          <property name="text">
        </item>
        <item row="1" column="1">
         <widget class="QComboBox" name="fieldsCO">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
          <property name="maxVisibleItems">
           <number>16</number>
          </property>
        </item>
        <item row="2" column="1">
         <widget class="QComboBox" name="entriesCO">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
          <property name="insertPolicy">
           <enum>QComboBox::NoInsert</enum>
          </property>
        <string>For&amp;matting</string>
       </attribute>
       <layout class="QGridLayout" name="gridLayout_2">
+       <property name="sizeConstraint">
+        <enum>QLayout::SetMinimumSize</enum>
+       </property>
        <item row="0" column="0">
         <widget class="QLabel" name="citationStyleLA">
          <property name="text">
            <property name="sizeHint" stdset="0">
             <size>
              <width>21</width>
-             <height>20</height>
+             <height>26</height>
             </size>
            </property>
           </spacer>