From b5a2f1c7e5caf6f79b6894b562769a5513b7b13f Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Wed, 16 Mar 2016 21:47:32 +0000 Subject: [PATCH] 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. --- src/frontends/qt4/GuiCitation.cpp | 27 +++++++++++++++++++++++++++ src/frontends/qt4/ui/CitationUi.ui | 24 +++++++++++++++++++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 8856ebc866..16c0990f7d 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -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; } diff --git a/src/frontends/qt4/ui/CitationUi.ui b/src/frontends/qt4/ui/CitationUi.ui index bfbbc0de78..d10af983a6 100644 --- a/src/frontends/qt4/ui/CitationUi.ui +++ b/src/frontends/qt4/ui/CitationUi.ui @@ -16,7 +16,7 @@ true - + @@ -219,7 +219,10 @@ &Search Citation - + + + QLayout::SetMinimumSize + @@ -271,6 +274,12 @@ + + + 0 + 0 + + 16 @@ -326,6 +335,12 @@ + + + 0 + 0 + + QComboBox::NoInsert @@ -374,6 +389,9 @@ For&matting + + QLayout::SetMinimumSize + @@ -441,7 +459,7 @@ 21 - 20 + 26 -- 2.39.2