]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/LyXToolBox.cpp
LyXToolBox: a QToolBox with minimum size management
[lyx.git] / src / frontends / qt4 / LyXToolBox.cpp
1 // -*- C++ -*-
2 /**
3  * \file LyXToolBox.cpp
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Guillaume Munch
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include "LyXToolBox.h"
13
14 #include <QApplication>
15 #include <QLayout>
16
17 #include "support/debug.h"
18
19 namespace lyx {
20 namespace frontend {
21
22
23 QSize LyXToolBox::minimumSizeHint() const
24 {
25         QSize s(0,0);
26         // Compute the max of the minimal sizes of the pages
27         QWidget * page;
28         for (int i = 0; (page = widget(i)); ++i)
29                 s = s.expandedTo(page->minimumSizeHint());
30         // Add the height of the tabs
31         if (currentWidget())
32                 s.rheight() += height() - currentWidget()->height();
33         return s;
34 }
35
36 void LyXToolBox::showEvent(QShowEvent * e)
37 {
38         // Computation of the tab height might be incorrect yet (the proper sizes of
39         // the pages have only been computed now).
40         // It might still be incorrect after this. All this would be unnecessary if
41         // QToolBox made our life easier and exposed more information; for instance
42         // let us access the scroll areas enclosing the pages (from which one can
43         // deduce the real tab height).
44         layout()->invalidate();
45         // proceed with geometry update to avoid flicker
46         qApp->processEvents(QEventLoop::ExcludeUserInputEvents, 50);
47         QToolBox::showEvent(e);
48 }
49
50
51 } // namespace frontend
52 } // namespace lyx
53
54 #include "moc_LyXToolBox.cpp"
55