1
1
/****************************************************************************
3
3
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
4
5
** Contact: Nokia Corporation (qt-info@nokia.com)
6
7
** This file is part of the QtGui module of the Qt Toolkit.
8
9
** $QT_BEGIN_LICENSE:LGPL$
10
** Licensees holding valid Qt Commercial licenses may use this file in
11
** accordance with the Qt Commercial License Agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and Nokia.
10
** No Commercial Usage
11
** This file contains pre-release code and may not be distributed.
12
** You may use this file in accordance with the terms and conditions
13
** contained in the Technology Preview License Agreement accompanying
15
16
** GNU Lesser General Public License Usage
16
17
** Alternatively, this file may be used under the terms of the GNU Lesser
20
21
** ensure the GNU Lesser General Public License version 2.1 requirements
21
22
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23
** In addition, as a special exception, Nokia gives you certain
24
** additional rights. These rights are described in the Nokia Qt LGPL
25
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** If you are unsure which license is appropriate for your use, please
37
** contact the sales department at http://www.qtsoftware.com/contact.
24
** In addition, as a special exception, Nokia gives you certain additional
25
** rights. These rights are described in the Nokia Qt LGPL Exception
26
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28
** If you have questions regarding the use of this file, please contact
29
** Nokia at qt-info@nokia.com.
38
38
** $QT_END_LICENSE$
40
40
****************************************************************************/
520
522
QSize QHeaderView::sizeHint() const
522
524
Q_D(const QHeaderView);
525
525
if (d->cachedSizeHint.isValid())
526
526
return d->cachedSizeHint;
527
d->cachedSizeHint = QSize(0, 0); //reinitialize the cached size hint
528
const int sectionCount = count();
529
530
// get size hint for the first n sections
530
int c = qMin(count(), 100);
531
for (int i = 0; i < c; ++i) {
532
for (int checked = 0; checked < 100 && i < sectionCount; ++i) {
532
533
if (isSectionHidden(i))
534
536
QSize hint = sectionSizeFromContents(i);
535
width = qMax(hint.width(), width);
536
height = qMax(hint.height(), height);
537
d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
538
539
// get size hint for the last n sections
539
c = qMax(count() - 100, c);
540
for (int j = count() - 1; j >= c; --j) {
540
i = qMax(i, sectionCount - 100 );
541
for (int j = sectionCount - 1, checked = 0; j >= i && checked < 100; --j) {
541
542
if (isSectionHidden(j))
543
545
QSize hint = sectionSizeFromContents(j);
544
width = qMax(hint.width(), width);
545
height = qMax(hint.height(), height);
546
d->cachedSizeHint = d->cachedSizeHint.expandedTo(hint);
547
d->cachedSizeHint = QSize(width, height);
548
548
return d->cachedSizeHint;
1049
1049
Returns the logicalIndex for the section at the given \a visualIndex
1050
position, or -1 otherwise.
1050
position, or -1 if visualIndex < 0 or visualIndex >= QHeaderView::count().
1052
Note that the visualIndex is not affected by hidden sections.
1052
1054
\sa visualIndex(), sectionPosition()
1153
1155
Sets the constraints on how the section specified by \a logicalIndex in
1154
the header can be resized to those described by the given \a mode.
1156
the header can be resized to those described by the given \a mode. The logical
1157
index should exist at the time this function is called.
1156
1159
\note This setting will be ignored for the last section if the stretchLastSection
1157
1160
property is set to true. This is the default for the horizontal headers provided
1970
1974
if (d->orientation == Qt::Horizontal && current.column() != old.column()) {
1971
1975
if (old.isValid() && old.parent() == d->root)
1972
d->setDirtyRegion(QRect(sectionViewportPosition(old.column()), 0,
1976
d->viewport->update(QRect(sectionViewportPosition(old.column()), 0,
1973
1977
sectionSize(old.column()), d->viewport->height()));
1974
1978
if (current.isValid() && current.parent() == d->root)
1975
d->setDirtyRegion(QRect(sectionViewportPosition(current.column()), 0,
1979
d->viewport->update(QRect(sectionViewportPosition(current.column()), 0,
1976
1980
sectionSize(current.column()), d->viewport->height()));
1977
1981
} else if (d->orientation == Qt::Vertical && current.row() != old.row()) {
1978
1982
if (old.isValid() && old.parent() == d->root)
1979
d->setDirtyRegion(QRect(0, sectionViewportPosition(old.row()),
1983
d->viewport->update(QRect(0, sectionViewportPosition(old.row()),
1980
1984
d->viewport->width(), sectionSize(old.row())));
1981
1985
if (current.isValid() && current.parent() == d->root)
1982
d->setDirtyRegion(QRect(0, sectionViewportPosition(current.row()),
1986
d->viewport->update(QRect(0, sectionViewportPosition(current.row()),
1983
1987
d->viewport->width(), sectionSize(current.row())));
1985
d->updateDirtyRegion();
2538
2541
if (opt.icon.isNull())
2539
2542
opt.icon = qvariant_cast<QPixmap>(variant);
2540
2543
QSize size = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize(), this);
2541
if (isSortIndicatorShown() && sortIndicatorSection() == logicalIndex) {
2544
if (isSortIndicatorShown()) {
2542
2545
int margin = style()->pixelMetric(QStyle::PM_HeaderMargin, &opt, this);
2543
2546
if (d->orientation == Qt::Horizontal)
2544
2547
size.rwidth() += size.height() + margin;
2615
2618
int first = orientation() == Qt::Horizontal ? topLeft.column() : topLeft.row();
2616
2619
int last = orientation() == Qt::Horizontal ? bottomRight.column() : bottomRight.row();
2617
2620
for (int i = first; i <= last && !resizeRequired; ++i)
2618
resizeRequired = (resizeRequired && resizeMode(i));
2621
resizeRequired = (resizeMode(i) == ResizeToContents);
2619
2622
if (resizeRequired)
2620
2623
d->doDelayedResizeSections();
2821
2824
sectionIndicator = new QLabel(viewport);
2825
2828
int p = q->sectionViewportPosition(section);
2826
2829
if (orientation == Qt::Horizontal) {
2829
2830
w = q->sectionSize(section);
2830
2831
h = viewport->height();
2834
2833
w = viewport->width();
2835
2834
h = q->sectionSize(section);
2936
2935
void QHeaderViewPrivate::resizeSections(QHeaderView::ResizeMode globalMode, bool useGlobalMode)
2938
2937
Q_Q(QHeaderView);
2938
//stop the timer in case it is delayed
2939
delayedResize.stop();
2940
2941
executePostedLayout();
2941
2942
if (sectionCount == 0)
2945
if (resizeRecursionBlock)
2947
resizeRecursionBlock = true;
2943
2949
invalidateCachedSizeHint();
2951
const int lastVisibleSection = lastVisibleVisualIndex();
2945
2953
// find stretchLastSection if we have it
2946
2954
int stretchSection = -1;
2947
if (stretchLastSection && !useGlobalMode) {
2948
for (int i = sectionCount - 1; i >= 0; --i) {
2949
if (!isVisualIndexHidden(i)) {
2955
if (stretchLastSection && !useGlobalMode)
2956
stretchSection = lastVisibleVisualIndex();
2956
2958
// count up the number of strected sections and how much space left for them
2957
2959
int lengthToStrech = (orientation == Qt::Horizontal ? viewport->width() : viewport->height());
2965
2967
if (useGlobalMode && (i != stretchSection))
2966
2968
resizeMode = globalMode;
2968
resizeMode = (i == stretchSection ? QHeaderView::Stretch : visualIndexResizeMode(i));
2970
resizeMode = (i == stretchSection ? QHeaderView::Stretch : headerSectionResizeMode(i));
2970
2972
if (resizeMode == QHeaderView::Stretch) {
2971
2973
++numberOfStretchedSections;
3017
3018
resizeMode = (i == stretchSection
3018
3019
? QHeaderView::Stretch
3019
: visualIndexResizeMode(i));
3020
: newSectionResizeMode);
3020
3021
if (resizeMode == QHeaderView::Stretch && stretchSectionLength != -1) {
3021
3022
if (i == lastVisibleSection)
3022
3023
newSectionLength = qMax(stretchSectionLength, lastSectionSize);
3053
3054
(sectionCount - spanStartSection) * previousSectionLength,
3054
3055
previousSectionResizeMode);
3055
3056
//Q_ASSERT(headerLength() == length);
3057
resizeRecursionBlock = false;
3057
3058
viewport->update();
3471
3472
int QHeaderViewPrivate::viewSectionSizeHint(int logical) const
3473
Q_Q(const QHeaderView);
3474
if (QAbstractItemView *parent = qobject_cast<QAbstractItemView*>(q->parent())) {
3474
if (QAbstractItemView *view = qobject_cast<QAbstractItemView*>(parent)) {
3475
3475
return (orientation == Qt::Horizontal
3476
? parent->sizeHintForColumn(logical)
3477
: parent->sizeHintForRow(logical));
3476
? view->sizeHintForColumn(logical)
3477
: view->sizeHintForRow(logical));