kalarm
dialogscroll.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00032
00033
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
00098
00099
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
00121
00122 decoration = 25;
00123 }
00124 int desk = KAlarm::desktopWorkArea().height();
00125
00126
00127
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