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
00022
00023
00024
00025 #include "qxtheaderview.h"
00026
00027 class QxtHeaderViewPrivate : public QxtPrivate<QxtHeaderView>
00028 {
00029 public:
00030 QXT_DECLARE_PUBLIC(QxtHeaderView);
00031
00032 QxtHeaderViewPrivate();
00033
00034 bool proportional;
00035 QMap<int, int> factors;
00036 };
00037
00038 QxtHeaderViewPrivate::QxtHeaderViewPrivate() : proportional(false)
00039 {
00040 }
00041
00052 QxtHeaderView::QxtHeaderView(Qt::Orientation orientation, QWidget* parent)
00053 : QHeaderView(orientation, parent)
00054 {
00055 QXT_INIT_PRIVATE(QxtHeaderView);
00056 }
00057
00068 bool QxtHeaderView::hasProportionalSectionSizes() const
00069 {
00070 return qxt_d().proportional;
00071 }
00072
00073 void QxtHeaderView::setProportionalSectionSizes(bool enabled)
00074 {
00075 if (qxt_d().proportional != enabled)
00076 {
00077 qxt_d().proportional = enabled;
00078 if (enabled)
00079 setResizeMode(QHeaderView::Fixed);
00080 }
00081 }
00082
00088 int QxtHeaderView::sectionStretchFactor(int logicalIndex) const
00089 {
00090 return qxt_d().factors.value(logicalIndex);
00091 }
00092
00098 void QxtHeaderView::setSectionStretchFactor(int logicalIndex, int factor)
00099 {
00100 qxt_d().factors.insert(logicalIndex, factor);
00101 }
00102
00106 void QxtHeaderView::resizeEvent(QResizeEvent* event)
00107 {
00108 QHeaderView::resizeEvent(event);
00109 if (qxt_d().proportional)
00110 {
00111 int total = 0;
00112 for (int i = 0; i < count(); ++i)
00113 total += qxt_d().factors.value(i, 1);
00114
00115 int totalSize = 0;
00116 for (int i = 0; i < count() - 1; ++i)
00117 {
00118 qreal factor = qxt_d().factors.value(i, 1) / static_cast<qreal>(total);
00119 int sectionSize = factor * (orientation() == Qt::Horizontal ? width() : height());
00120 sectionSize = qMax(minimumSectionSize(), sectionSize);
00121 resizeSection(i, sectionSize);
00122 totalSize += sectionSize;
00123 }
00124
00125 resizeSection(count() - 1, width() - totalSize);
00126 }
00127 }