Fix broken layout of the citation dialog (#10019)

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.
This commit is contained in:
Guillaume Munch 2016-03-16 21:47:32 +00:00
parent 7e33fd7fac
commit b5a2f1c7e5
2 changed files with 48 additions and 3 deletions

View File

@ -625,6 +625,33 @@ bool GuiCitation::initialiseParams(string const & data)
citeCmds_ = documentBuffer().params().citeCommands(); citeCmds_ = documentBuffer().params().citeCommands();
citeStyles_ = documentBuffer().params().citeStyles(); citeStyles_ = documentBuffer().params().citeStyles();
init(); 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; return true;
} }

View File

@ -16,7 +16,7 @@
<property name="sizeGripEnabled"> <property name="sizeGripEnabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4" rowstretch="1,0,0">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
@ -219,7 +219,10 @@
<attribute name="label"> <attribute name="label">
<string>&amp;Search Citation</string> <string>&amp;Search Citation</string>
</attribute> </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"> <item row="0" column="0">
<widget class="QLabel" name="findKeysLA"> <widget class="QLabel" name="findKeysLA">
<property name="text"> <property name="text">
@ -271,6 +274,12 @@
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QComboBox" name="fieldsCO"> <widget class="QComboBox" name="fieldsCO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxVisibleItems"> <property name="maxVisibleItems">
<number>16</number> <number>16</number>
</property> </property>
@ -326,6 +335,12 @@
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QComboBox" name="entriesCO"> <widget class="QComboBox" name="entriesCO">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="insertPolicy"> <property name="insertPolicy">
<enum>QComboBox::NoInsert</enum> <enum>QComboBox::NoInsert</enum>
</property> </property>
@ -374,6 +389,9 @@
<string>For&amp;matting</string> <string>For&amp;matting</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="citationStyleLA"> <widget class="QLabel" name="citationStyleLA">
<property name="text"> <property name="text">
@ -441,7 +459,7 @@
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>21</width> <width>21</width>
<height>20</height> <height>26</height>
</size> </size>
</property> </property>
</spacer> </spacer>