summaryrefslogtreecommitdiffstats
path: root/src/gui/itemviews
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-03-22 10:30:06 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-03-22 11:37:25 (GMT)
commit51a98a583b33585a4dcf918cd8567978bf7c20ae (patch)
treee82417dd145b5eafae3f1c78914366bdfa07e491 /src/gui/itemviews
parentb7a0a8dced26daf895fa9932e5a8c81e59fd7b84 (diff)
downloadQt-51a98a583b33585a4dcf918cd8567978bf7c20ae.zip
Qt-51a98a583b33585a4dcf918cd8567978bf7c20ae.tar.gz
Qt-51a98a583b33585a4dcf918cd8567978bf7c20ae.tar.bz2
Dragging headers in item views done right
Until now, the dropped position depended on the position of the middle of the dragged header w.r.t. the hovered header. Now, it only depends on the mouse cursor position and the middle of the hovered header, closer to what happens on Windows or Mac OS. Reviewed-by: Thierry Task-number: QTBUG-6968
Diffstat (limited to 'src/gui/itemviews')
-rw-r--r--src/gui/itemviews/qheaderview.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp
index 586e5d4..cd9ee15 100644
--- a/src/gui/itemviews/qheaderview.cpp
+++ b/src/gui/itemviews/qheaderview.cpp
@@ -2220,16 +2220,24 @@ void QHeaderView::mouseMoveEvent(QMouseEvent *e)
case QHeaderViewPrivate::MoveSection: {
if (qAbs(pos - d->firstPos) >= QApplication::startDragDistance()
|| !d->sectionIndicator->isHidden()) {
- int indicatorCenter = (d->orientation == Qt::Horizontal
- ? d->sectionIndicator->width()
- : d->sectionIndicator->height()) / 2;
- int centerOffset = indicatorCenter - d->sectionIndicatorOffset;
- // This will drop the moved section to the position under the center of the indicator.
- // If centerOffset is 0, the section will be moved to the position of the mouse cursor.
- int visual = visualIndexAt(pos + centerOffset);
+ int visual = visualIndexAt(pos);
if (visual == -1)
return;
- d->target = d->logicalIndex(visual);
+ int posThreshold = d->headerSectionPosition(visual) + d->headerSectionSize(visual) / 2;
+ int moving = visualIndex(d->section);
+ if (visual < moving) {
+ if (pos < posThreshold)
+ d->target = d->logicalIndex(visual);
+ else
+ d->target = d->logicalIndex(visual + 1);
+ } else if (visual > moving) {
+ if (pos > posThreshold)
+ d->target = d->logicalIndex(visual);
+ else
+ d->target = d->logicalIndex(visual - 1);
+ } else {
+ d->target = d->section;
+ }
d->updateSectionIndicator(d->section, pos);
}
return;