From c8381f787322656bb9ae82202a640ddd9aa2de0a Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Tue, 22 Mar 2016 21:57:17 +0000 Subject: [PATCH] LyXToolBox: a QToolBox with minimum size management The purpose of this custom widget is to allow the use of a QToolBox in a limited area. The stock QToolBox does not provide a minimum size hint that depends on the size of the pages; it assumes that there is enough room. This subclass sets the minimal size of the QToolbox. Without this, the size of the QToolbox is only determined by values in the ui file and therefore causes portability and localisation issues. Note that the computation of the minimum size hint depends on the minimum size hints of the page widgets. Therefore page widgets must have a layout with layoutSizeContraint = SetMinimumSize or similar. (cherry picked from commits 576cb5df77604b50175b2410ac006c5c5c110e2b 7e9d0a938bb02510304822f6bce4df3bcfe4bfc9 efbc297b955da58cef7bf2d63dfbc8b2942c671e) --- src/frontends/qt4/GuiCitation.cpp | 1 + src/frontends/qt4/LyXToolBox.cpp | 57 ++++++++++++++++++++++++++++++ src/frontends/qt4/LyXToolBox.h | 46 ++++++++++++++++++++++++ src/frontends/qt4/Makefile.am | 2 ++ src/frontends/qt4/ui/CitationUi.ui | 26 +++++--------- 5 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 src/frontends/qt4/LyXToolBox.cpp create mode 100644 src/frontends/qt4/LyXToolBox.h diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp index 5534100629..44118c79a5 100644 --- a/src/frontends/qt4/GuiCitation.cpp +++ b/src/frontends/qt4/GuiCitation.cpp @@ -17,6 +17,7 @@ #include "GuiCitation.h" #include "GuiSelectionManager.h" +#include "LyXToolBox.h" #include "qt_helpers.h" #include "Buffer.h" diff --git a/src/frontends/qt4/LyXToolBox.cpp b/src/frontends/qt4/LyXToolBox.cpp new file mode 100644 index 0000000000..4e754f98ab --- /dev/null +++ b/src/frontends/qt4/LyXToolBox.cpp @@ -0,0 +1,57 @@ +// -*- C++ -*- +/** + * \file LyXToolBox.cpp + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Guillaume Munch + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "LyXToolBox.h" + +#include +#include + +#include "support/debug.h" + +namespace lyx { +namespace frontend { + + +QSize LyXToolBox::minimumSizeHint() const +{ + QSize s(0,0); + // Compute the max of the minimal sizes of the pages + QWidget * page; + for (int i = 0; (page = widget(i)); ++i) + s = s.expandedTo(page->minimumSizeHint()); + // Add the height of the tabs + if (currentWidget()) + s.rheight() += height() - currentWidget()->height(); + return s; +} + +void LyXToolBox::showEvent(QShowEvent * e) +{ + // Computation of the tab height might be incorrect yet (the proper sizes of + // the pages have only been computed now). + // It might still be incorrect after this. All this would be unnecessary if + // QToolBox made our life easier and exposed more information; for instance + // let us access the scroll areas enclosing the pages (from which one can + // deduce the real tab height). + layout()->invalidate(); + // proceed with geometry update to avoid flicker + qApp->processEvents(QEventLoop::ExcludeUserInputEvents, 50); + QToolBox::showEvent(e); +} + + +} // namespace frontend +} // namespace lyx + +#include "moc_LyXToolBox.cpp" + diff --git a/src/frontends/qt4/LyXToolBox.h b/src/frontends/qt4/LyXToolBox.h new file mode 100644 index 0000000000..03bd00e962 --- /dev/null +++ b/src/frontends/qt4/LyXToolBox.h @@ -0,0 +1,46 @@ +// -*- C++ -*- +/** + * \file LyXToolBox.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Guillaume Munch + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYXTOOLBOX_H +#define LYXTOOLBOX_H + +#include + +namespace lyx { +namespace frontend { + +// The purpose of this custom widget is to allow the use of a QToolBox in a +// limited area. The stock QToolBox does not provide a minimum size hint that +// depends on the size of the pages; it assumes that there is enough room. This +// subclass sets the minimal size of the QToolbox. Without this, the size of the +// QToolbox is only determined by values in the ui file and therefore causes +// portability and localisation issues. Note that the computation of the minimum +// size hint depends on the minimum size hints of the page widgets. Therefore +// page widgets must have a layout with layoutSizeContraint = SetMinimumSize or +// similar. +class LyXToolBox : public QToolBox +{ + Q_OBJECT + +public: + LyXToolBox(QWidget * p = 0, Qt::WindowFlags f = 0) : QToolBox(p, f) {} + QSize minimumSizeHint() const; + +protected: + void showEvent(QShowEvent * e); +}; + + +} // namespace frontend +} // namespace lyx + + +#endif // LYXTOOLBOX_H diff --git a/src/frontends/qt4/Makefile.am b/src/frontends/qt4/Makefile.am index 90514fd2a3..2995a41729 100644 --- a/src/frontends/qt4/Makefile.am +++ b/src/frontends/qt4/Makefile.am @@ -143,6 +143,7 @@ SOURCEFILES = \ InsetParamsWidget.cpp \ LengthCombo.cpp \ LyXFileDialog.cpp \ + LyXToolBox.cpp \ LaTeXHighlighter.cpp \ LayoutBox.cpp \ Menus.cpp \ @@ -252,6 +253,7 @@ MOCHEADER = \ LayoutBox.h \ LengthCombo.h \ LyXFileDialog.h \ + LyXToolBox.h \ Menus.h \ PanelStack.h \ TocModel.h \ diff --git a/src/frontends/qt4/ui/CitationUi.ui b/src/frontends/qt4/ui/CitationUi.ui index d10af983a6..ce407590e9 100644 --- a/src/frontends/qt4/ui/CitationUi.ui +++ b/src/frontends/qt4/ui/CitationUi.ui @@ -194,7 +194,7 @@ - + 0 @@ -208,14 +208,6 @@ 1 - - - 0 - 0 - 572 - 111 - - &Search Citation @@ -377,14 +369,6 @@ - - - 0 - 0 - 572 - 105 - - For&matting @@ -558,6 +542,14 @@ + + + lyx::frontend::LyXToolBox + QToolBox +
LyXToolBox.h
+ 1 +
+
availableLV addPB