diff options
-rw-r--r-- | Swift/QtUI/Trellis/QtGridSelectionDialog.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp b/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp index f67a4b8..1ca1953 100644 --- a/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp +++ b/Swift/QtUI/Trellis/QtGridSelectionDialog.cpp @@ -108,61 +108,65 @@ void QtGridSelectionDialog::mousePressEvent(QMouseEvent*) { void QtGridSelectionDialog::paintEvent(QPaintEvent*) { QPainter painter(this); // draw grid QRect gridCell = QRect(QPoint(0,0), frameSize); painter.setBrush(palette().highlight()); painter.setPen(Qt::NoPen); for (int x = 0; x < currentGridSize.width(); x++) { for (int y = 0; y < currentGridSize.height(); y++) { int xPos = horizontalMargin + (x * (frameSize.width() + padding)); int yPos = verticalMargin + (y * (frameSize.height() + padding)); gridCell.moveTo(QPoint(xPos, yPos)); painter.drawRect(gridCell); } } // draw description text auto fontMetrics = QFontMetrics(QApplication::font()); auto descriptionBB = fontMetrics.boundingRect(QRect(0,0, width() - 2 * horizontalMargin,0), Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, descriptionText, 0, 0); QStyleOption opt; opt.initFrom(this); int textY = verticalMargin + (currentGridSize.height() * (frameSize.height() + padding)); int textX = (size().width() - descriptionBB.width()) / 2; style()->drawItemText(&painter, QRect(textX, textY, descriptionBB.width(), descriptionBB.height()), Qt::AlignHCenter | Qt::AlignTop | Qt::TextWordWrap, opt.palette, true, descriptionText, foregroundRole()); } void QtGridSelectionDialog::showEvent(QShowEvent*) { int xPos = horizontalMargin + frameSize.width() + (padding + frameSize.width()) * (currentGridSize.width() - 1) - frameSize.width()/2; int yPos = verticalMargin + frameSize.height() + (padding + frameSize.height()) * (currentGridSize.height() - 1) - frameSize.height()/2; - QCursor::setPos(mapToGlobal(QPoint(xPos, yPos))); + // Apply the above offset to the global cursor position (which was positioned at a known position before showing the widget): + QPoint pos = QCursor::pos(); + pos.rx() += xPos; + pos.ry() += yPos; + QCursor::setPos(pos); setMouseTracking(true); } void QtGridSelectionDialog::hideEvent(QHideEvent*) { setMouseTracking(false); } void QtGridSelectionDialog::mouseMoveEvent(QMouseEvent*) { QPoint diff = (frameGeometry().bottomRight() - QCursor::pos()); QSize newDimensions = currentGridSize; if (diff.x() > frameSize.width() * 1.5) { newDimensions -= QSize(diff.x() / (frameSize.width() * 1.5), 0); } if (diff.y() > frameSize.height() * 1.5) { newDimensions -= QSize(0, diff.y() / (frameSize.height() * 1.5)); } if (minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize) != currentGridSize) { currentGridSize = minGridSize.expandedTo(newDimensions).boundedTo(maxGridSize); resize(sizeHint()); } } void QtGridSelectionDialog::leaveEvent(QEvent *) { QPoint diff = (frameGeometry().bottomRight() - QCursor::pos()); QSize newGridSize = currentGridSize; if (diff.x() < 0) { newGridSize += QSize(1,0); } if (diff.y() < 0) { newGridSize += QSize(0,1); |