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

kalarm

dialogscroll.h

Go to the documentation of this file.
00001 /*
00002  *  dialogscroll.h  -  dialog scrolling when too high for screen
00003  *  Program:  kalarm
00004  *  Copyright © 2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef DIALOGSCROLL_H
00022 #define DIALOGSCROLL_H
00023 
00024 #include "kalarm.h"
00025 
00026 #include <QScrollArea>
00027 #include <QList>
00028 
00029 
00030 /*=============================================================================
00031 = Class DialogScroll
00032 = A widget to contain the tab contents, allowing the contents to scroll if
00033 = the dialog is too high to fit the screen.
00034 =============================================================================*/
00035 template <class T>
00036 class DialogScroll : public QScrollArea
00037 {
00038     public:
00039         explicit DialogScroll(QWidget* parent = 0);
00040         ~DialogScroll();
00041         virtual QSize sizeHint() const  { return minimumSizeHint(); }
00042         virtual QSize minimumSizeHint() const;
00043         static int    heightReduction() { return mHeightReduction; }
00044         static QSize  initMinimumHeight(T*);
00045         static void   setSized()        { mSized = true; }
00046         static bool   sized()           { return mSized; }
00047     private:
00048         static QList<DialogScroll<T>*> mTabs;
00049         static int    mMinHeight;
00050         static int    mHeightReduction;
00051         static bool   mSized;
00052 };
00053 
00054 
00055 #include "dialogscroll.h"
00056 #include "functions.h"
00057 #include <kdialog.h>
00058 #include <QStyle>
00059 
00060 namespace KAlarm { QRect desktopWorkArea(); }
00061 
00062 template <class T> QList<DialogScroll<T>*> DialogScroll<T>::mTabs;
00063 template <class T> int  DialogScroll<T>::mHeightReduction = 0;
00064 template <class T> int  DialogScroll<T>::mMinHeight = -1;
00065 template <class T> bool DialogScroll<T>::mSized = false;
00066 
00067 template <class T>
00068 DialogScroll<T>::DialogScroll(QWidget* parent)
00069     : QScrollArea(parent)
00070 {
00071     setFrameStyle(QFrame::NoFrame);
00072     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00073     setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
00074     setWidgetResizable(true);
00075     setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
00076     mTabs += this;
00077 }
00078 
00079 template <class T>
00080 DialogScroll<T>::~DialogScroll()
00081 {
00082     mTabs.removeAll(this);
00083 }
00084 
00085 template <class T>
00086 QSize DialogScroll<T>::minimumSizeHint() const
00087 {
00088     if (!widget())
00089         return QSize();
00090     QSize s = widget()->minimumSizeHint();
00091     if (mMinHeight > 0)
00092         return QSize(s.width() + style()->pixelMetric(QStyle::PM_ScrollBarExtent), mMinHeight);
00093     return s;
00094 }
00095 
00096 /******************************************************************************
00097 * Return the minimum size for the dialog.
00098 * If the minimum size would be too high to fit the desktop, the tab contents
00099 * are made scrollable.
00100 */
00101 template <class T>
00102 QSize DialogScroll<T>::initMinimumHeight(T* dlg)
00103 {
00104     if (mSized)
00105         return QSize();
00106     int maxHeight = 0;
00107     for (int i = 0, end = mTabs.count();  i < end;  ++i)
00108     {
00109         if (!mTabs[i]->widget())
00110             return QSize();
00111         QSize s = mTabs[i]->widget()->minimumSizeHint();
00112         if (!s.isValid())
00113             return QSize();
00114         if (s.height() > maxHeight)
00115             maxHeight = s.height();
00116     }
00117     int decoration = dlg->frameGeometry().height() - dlg->geometry().height();
00118     if (!decoration)
00119     {
00120         // On X11 at least, the window decoration height may not be
00121         // available, so use a guess of 25 pixels.
00122         decoration = 25;
00123     }
00124     int desk = KAlarm::desktopWorkArea().height();
00125     // There is no stored size, or the deferral group is visible.
00126     // Allow the tab contents to be scrolled vertically if that is necessary
00127     // to avoid the dialog exceeding the screen height.
00128     QSize s = dlg->KDialog::minimumSizeHint();
00129     int y = s.height() + decoration - desk;
00130     if (y > 0)
00131     {
00132         mHeightReduction = y;
00133         mMinHeight = maxHeight - y;
00134         if (mMinHeight > 0)
00135         {
00136             for (int i = 0, end = mTabs.count();  i < end;  ++i)
00137             {
00138                 mTabs[i]->setMinimumHeight(mMinHeight);
00139                 mTabs[i]->resize(QSize(mTabs[i]->width(), mMinHeight));
00140             }
00141         }
00142         mSized = true;
00143         mTabs[0]->parentWidget()->resize(mTabs[0]->parentWidget()->sizeHint());
00144         for (QWidget* w = mTabs[0]->parentWidget();  w && w != dlg;  w = w->parentWidget())
00145         {
00146             w->setMinimumHeight(qMin(w->minimumSizeHint().height(), w->sizeHint().height()));
00147             w->resize(w->minimumSize());
00148         }
00149         s = dlg->KDialog::minimumSizeHint();
00150         dlg->setMinimumHeight(s.height());
00151     }
00152     else
00153     {
00154         for (int i = 0, end = mTabs.count();  i < end;  ++i)
00155             mTabs[i]->setMinimumHeight(maxHeight);
00156         mSized = true;
00157     }
00158     dlg->resize(s);
00159     return s;
00160 }
00161 
00162 #endif // DIALOGSCROLL_H

kalarm

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal