summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qheaderview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qheaderview.cpp')
-rw-r--r--src/widgets/itemviews/qheaderview.cpp61
1 files changed, 51 insertions, 10 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp
index fe99f7a5e0..66ff472724 100644
--- a/src/widgets/itemviews/qheaderview.cpp
+++ b/src/widgets/itemviews/qheaderview.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtWidgets module of the Qt Toolkit.
**
@@ -10,9 +10,9 @@
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -23,8 +23,8 @@
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
+** As a special exception, The Qt Company gives you certain additional
+** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
@@ -1515,6 +1515,11 @@ void QHeaderView::setCascadingSectionResizes(bool enable)
This property only affects sections that have \l Interactive or \l Fixed
as their resize mode.
+ By default, the value of this property is style dependent.
+ Thus, when the style changes, this property updates from it.
+ Calling setDefaultSectionSize() stops the updates, calling
+ resetDefaultSectionSize() will restore default behavior.
+
\sa setSectionResizeMode(), minimumSectionSize
*/
int QHeaderView::defaultSectionSize() const
@@ -1531,6 +1536,15 @@ void QHeaderView::setDefaultSectionSize(int size)
d->setDefaultSectionSize(size);
}
+void QHeaderView::resetDefaultSectionSize()
+{
+ Q_D(QHeaderView);
+ if (d->customDefaultSectionSize) {
+ d->updateDefaultSectionSizeFromStyle();
+ d->customDefaultSectionSize = false;
+ }
+}
+
/*!
\since 4.2
\property QHeaderView::minimumSectionSize
@@ -2209,6 +2223,10 @@ bool QHeaderView::event(QEvent *e)
resizeSections();
}
break; }
+ case QEvent::StyleChange:
+ if (!d->customDefaultSectionSize)
+ d->updateDefaultSectionSizeFromStyle();
+ break;
default:
break;
}
@@ -2371,10 +2389,10 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
{
Q_D(QHeaderView);
int pos = d->orientation == Qt::Horizontal ? e->x() : e->y();
- if (pos < 0)
+ if (pos < 0 && d->state != QHeaderViewPrivate::SelectSections)
return;
if (e->buttons() == Qt::NoButton) {
-#if !defined(Q_WS_MAC)
+#if !defined(Q_DEAD_CODE_FROM_QT4_MAC)
// Under Cocoa, when the mouse button is released, may include an extra
// simulated mouse moved event. The state of the buttons when this event
// is generated is already "no button" and the code below gets executed
@@ -2430,7 +2448,9 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
return;
}
case QHeaderViewPrivate::SelectSections: {
- int logical = logicalIndexAt(pos);
+ int logical = logicalIndexAt(qMax(-d->offset, pos));
+ if (logical == -1 && pos > 0)
+ logical = d->lastVisibleVisualIndex();
if (logical == d->pressed)
return; // nothing to do
else if (d->pressed != -1)
@@ -3463,6 +3483,7 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
executePostedLayout();
invalidateCachedSizeHint();
defaultSectionSize = size;
+ customDefaultSectionSize = true;
if (state == QHeaderViewPrivate::ResizeSection)
preventCursorChangeInSetOffset = true;
for (int i = 0; i < sectionItems.count(); ++i) {
@@ -3483,6 +3504,17 @@ void QHeaderViewPrivate::setDefaultSectionSize(int size)
viewport->update();
}
+void QHeaderViewPrivate::updateDefaultSectionSizeFromStyle()
+{
+ Q_Q(QHeaderView);
+ if (orientation == Qt::Horizontal) {
+ defaultSectionSize = q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeHorizontal, 0, q);
+ } else {
+ defaultSectionSize = qMax(q->minimumSectionSize(),
+ q->style()->pixelMetric(QStyle::PM_HeaderDefaultSectionSizeVertical, 0, q));
+ }
+}
+
void QHeaderViewPrivate::recalcSectionStartPos() const // linear (but fast)
{
int pixelpos = 0;
@@ -3630,6 +3662,7 @@ void QHeaderViewPrivate::write(QDataStream &out) const
out << sectionItems;
out << resizeContentsPrecision;
+ out << customDefaultSectionSize;
}
bool QHeaderViewPrivate::read(QDataStream &in)
@@ -3737,6 +3770,14 @@ bool QHeaderViewPrivate::read(QDataStream &in)
if (in.status() == QDataStream::Ok) // we haven't read past end
resizeContentsPrecision = tmpint;
+ bool tmpbool;
+ in >> tmpbool;
+ if (in.status() == QDataStream::Ok) { // we haven't read past end
+ customDefaultSectionSize = tmpbool;
+ if (!customDefaultSectionSize)
+ updateDefaultSectionSizeFromStyle();
+ }
+
return true;
}