• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm/lib

  • sources
  • kde-4.12
  • kdepim
  • kalarm
  • lib
stackedwidgets.cpp
Go to the documentation of this file.
1 /*
2  * stackedwidgets.cpp - group of stacked widgets
3  * Program: kalarm
4  * Copyright © 2008 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #include "stackedwidgets.h"
22 #include "desktop.h"
23 
24 #include <kdialog.h>
25 #include <kdebug.h>
26 
27 #include <QStyle>
28 
29 
30 StackedScrollWidget::StackedScrollWidget(StackedScrollGroup* group, QWidget* parent)
31  : StackedWidgetT<QScrollArea>(group, parent)
32 {
33  setFrameStyle(QFrame::NoFrame);
34  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
35  setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
36  setWidgetResizable(true);
37  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
38 }
39 
40 StackedScrollGroup::StackedScrollGroup(KDialog* dlg, QObject* tabParent)
41  : StackedGroupT<QScrollArea>(tabParent),
42  mDialog(dlg),
43  mMinHeight(-1),
44  mHeightReduction(0),
45  mSized(false)
46 {
47 }
48 
49 /******************************************************************************
50 * Return the minimum size for the tab, adjusted if necessary to a height that
51 * fits the screen.
52 * In order to make the QStackedWidget containing the tabs take the correct
53 * size, the value returned is actually the minimum size of the largest tab.
54 * Otherwise, only the currently visible tab would be taken into account with
55 * the result that the dialog would initially be displayed too small.
56 */
57 QSize StackedScrollGroup::minimumSizeHint() const
58 {
59  QSize s = maxMinimumSizeHint();
60  if (!s.isEmpty() && mMinHeight > 0 && mMinHeight < s.height())
61  return QSize(s.width() + mWidgets[0]->style()->pixelMetric(QStyle::PM_ScrollBarExtent), mMinHeight);
62  return s;
63 }
64 
65 /******************************************************************************
66 * Return the maximum minimum size for any instance.
67 */
68 QSize StackedScrollGroup::maxMinimumSizeHint() const
69 {
70  QSize sz;
71  for (int i = 0, count = mWidgets.count(); i < count; ++i)
72  {
73  QWidget* w = static_cast<StackedScrollWidget*>(mWidgets[i])->widget();
74  if (!w)
75  return QSize();
76  QSize s = w->minimumSizeHint();
77  if (!s.isValid())
78  return QSize();
79  sz = sz.expandedTo(s);
80  }
81  return sz;
82 }
83 
84 /******************************************************************************
85 * Return the minimum size for the dialog.
86 * If the minimum size would be too high to fit the desktop, the tab contents
87 * are made scrollable.
88 */
89 QSize StackedScrollGroup::adjustSize(bool force)
90 {
91  if (force)
92  mSized = false;
93  if (mSized)
94  return QSize();
95 
96  // Cancel any previous minimum height and set the height of the
97  // scroll widget contents widgets.
98  mMinHeight = -1;
99  mHeightReduction = 0;
100  QSize s = maxMinimumSizeHint();
101  if (s.isEmpty())
102  return QSize();
103  int maxTabHeight = s.height();
104  for (int i = 0, count = mWidgets.count(); i < count; ++i)
105  {
106  mWidgets[i]->setMinimumHeight(maxTabHeight);
107  QWidget* w = static_cast<StackedScrollWidget*>(mWidgets[i])->widget();
108  if (w)
109  w->resize(s);
110  }
111  for (QWidget* w = mWidgets[0]->parentWidget(); w && w != mDialog; w = w->parentWidget())
112  {
113  w->setMinimumHeight(0);
114  w->adjustSize();
115  }
116  mDialog->setMinimumHeight(0);
117 
118  int decoration = mDialog->frameGeometry().height() - mDialog->geometry().height();
119  if (!decoration)
120  {
121  // On X11 at least, the window decoration height may not be
122  // available, so use a guess of 25 pixels.
123  decoration = 25;
124  }
125  int desk = KAlarm::desktopWorkArea().height();
126  // There is no stored size, or the deferral group is visible.
127  // Allow the tab contents to be scrolled vertically if that is necessary
128  // to avoid the dialog exceeding the screen height.
129  QSize dlgsize = mDialog->KDialog::minimumSizeHint();
130  int y = dlgsize.height() + decoration - desk;
131  if (y > 0)
132  {
133  mHeightReduction = y;
134  mMinHeight = maxTabHeight - y;
135  kDebug() << "Scrolling: max tab height=" << maxTabHeight << ", reduction=" << mHeightReduction << "-> min tab height=" << mMinHeight;
136  if (mMinHeight > 0)
137  {
138  for (int i = 0, count = mWidgets.count(); i < count; ++i)
139  {
140  mWidgets[i]->setMinimumHeight(mMinHeight);
141  mWidgets[i]->resize(QSize(mWidgets[i]->width(), mMinHeight));
142  }
143  }
144  mSized = true;
145  QSize s = mWidgets[0]->parentWidget()->sizeHint();
146  if (s.height() < mMinHeight)
147  s.setHeight(mMinHeight);
148  mWidgets[0]->parentWidget()->resize(s);
149  for (QWidget* w = mWidgets[0]->parentWidget(); w && w != mDialog; w = w->parentWidget())
150  w->setMinimumHeight(qMin(w->minimumSizeHint().height(), w->sizeHint().height()));
151  dlgsize.setHeight(dlgsize.height() - mHeightReduction);
152  s = mDialog->KDialog::minimumSizeHint();
153  if (s.height() > dlgsize.height())
154  dlgsize.setHeight(s.height());
155  mDialog->setMinimumHeight(dlgsize.height());
156  }
157  mSized = true;
158  mDialog->resize(dlgsize);
159  return s;
160 }
161 
162 // vim: et sw=4:
StackedScrollWidget::StackedScrollWidget
StackedScrollWidget(StackedScrollGroup *group, QWidget *parent=0)
Definition: stackedwidgets.cpp:30
StackedGroupT
A group of stacked widgets whose minimum size hints are all equal to the largest widget's minimum siz...
Definition: stackedwidgets.h:28
StackedScrollGroup::adjustSize
QSize adjustSize(bool force=false)
Definition: stackedwidgets.cpp:89
QWidget
KDialog
QObject
StackedScrollGroup
A group of stacked widgets which individually become scrollable when necessary to fit the height of t...
Definition: stackedwidgets.h:116
QScrollArea
StackedScrollGroup::minimumSizeHint
virtual QSize minimumSizeHint() const
Definition: stackedwidgets.cpp:57
desktop.h
StackedScrollGroup::StackedScrollGroup
StackedScrollGroup(KDialog *, QObject *tabParent)
Definition: stackedwidgets.cpp:40
StackedScrollWidget
A stacked widget which becomes scrollable when necessary to fit the height of the screen...
Definition: stackedwidgets.h:103
StackedGroupT< QScrollArea >::mWidgets
QList< StackedWidgetT< QScrollArea > * > mWidgets
Definition: stackedwidgets.h:77
KAlarm::desktopWorkArea
QRect desktopWorkArea(int screen)
Definition: desktop.cpp:34
stackedwidgets.h
StackedWidgetT
A widget contained in a stack, whose minimum size hint is that of the largest widget in the stack...
Definition: stackedwidgets.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm/lib

Skip menu "kalarm/lib"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal