From 51a98a583b33585a4dcf918cd8567978bf7c20ae Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 22 Mar 2010 11:30:06 +0100 Subject: 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 --- src/gui/itemviews/qheaderview.cpp | 24 ++++++++++++++++-------- 1 file 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; -- cgit v0.12 From 0d2f6432e7400dac20c71a01806cd787e5940eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Mar 2010 14:30:36 +0100 Subject: Fixed performance issues when falling back to raster for sub-pixmaps. Copy the sub-pixmap so that we don't need to convert the entire pixmap to a QImage each time. Reviewed-by: Gunnar Sletta --- src/gui/painting/qpainter.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index a1ed8f5..db4ace4 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -5414,10 +5414,15 @@ void QPainter::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr) scale(w / sw, h / sh); setBackgroundMode(Qt::TransparentMode); setRenderHint(Antialiasing, renderHints() & SmoothPixmapTransform); - QBrush brush(d->state->pen.color(), pm); + QBrush brush; + + if (sw == pm.width() && sh == pm.height()) + brush = QBrush(d->state->pen.color(), pm); + else + brush = QBrush(d->state->pen.color(), pm.copy(sx, sy, sw, sh)); + setBrush(brush); setPen(Qt::NoPen); - setBrushOrigin(QPointF(-sx, -sy)); drawRect(QRectF(0, 0, sw, sh)); restore(); -- cgit v0.12