Changeset View
Changeset View
Standalone View
Standalone View
src/QuickEditor/QuickEditor.cpp
Show First 20 Lines • Show All 266 Lines • ▼ Show 20 Line(s) | 263 | { | |||
---|---|---|---|---|---|
267 | if (xOffset > 0) { | 267 | if (xOffset > 0) { | ||
268 | if (mouse) { | 268 | if (mouse) { | ||
269 | mStartPos.setX(mStartPos.x() + xOffset * dprI); | 269 | mStartPos.setX(mStartPos.x() + xOffset * dprI); | ||
270 | } | 270 | } | ||
271 | newTopLeftX = realMaxX; | 271 | newTopLeftX = realMaxX; | ||
272 | } | 272 | } | ||
273 | 273 | | |||
274 | return newTopLeftX; | 274 | return newTopLeftX; | ||
275 | | ||||
276 | | ||||
277 | | ||||
278 | } | 275 | } | ||
279 | 276 | | |||
280 | int QuickEditor::boundsUp(int newTopLeftY, const bool mouse) | 277 | int QuickEditor::boundsUp(int newTopLeftY, const bool mouse) | ||
281 | { | 278 | { | ||
282 | if (newTopLeftY < 0) { | 279 | if (newTopLeftY < 0) { | ||
283 | if (mouse) { | 280 | if (mouse) { | ||
284 | mStartPos.setY(mStartPos.y() + newTopLeftY * dprI); | 281 | mStartPos.setY(mStartPos.y() + newTopLeftY * dprI); | ||
285 | } | 282 | } | ||
▲ Show 20 Lines • Show All 194 Lines • ▼ Show 20 Line(s) | 476 | { | |||
480 | event->accept(); | 477 | event->accept(); | ||
481 | if (event->button() == Qt::LeftButton && mSelection.contains(event->pos())) { | 478 | if (event->button() == Qt::LeftButton && mSelection.contains(event->pos())) { | ||
482 | acceptSelection(); | 479 | acceptSelection(); | ||
483 | } | 480 | } | ||
484 | } | 481 | } | ||
485 | 482 | | |||
486 | void QuickEditor::paintEvent(QPaintEvent*) | 483 | void QuickEditor::paintEvent(QPaintEvent*) | ||
487 | { | 484 | { | ||
485 | // Fix dual screen offset issue in X11 | ||||
486 | int newX = x(); | ||||
ngraham: Coding style:
```
int newX = x();
int newY = y();
``` | |||||
487 | int newY = y(); | ||||
488 | if (newX < 0 || newY < 0) { | ||||
489 | if (newX < 0) { | ||||
490 | newX = 0; | ||||
491 | } | ||||
492 | if (newY < 0) { | ||||
493 | newY = 0; | ||||
494 | } | ||||
495 | move(newX, newY); | ||||
496 | } | ||||
497 | | ||||
488 | QPainter painter(this); | 498 | QPainter painter(this); | ||
489 | painter.setRenderHints(QPainter::Antialiasing); | 499 | painter.setRenderHints(QPainter::Antialiasing); | ||
490 | QBrush brush(mPixmap); | 500 | QBrush brush(mPixmap); | ||
491 | brush.setTransform(QTransform().scale(dprI, dprI)); | 501 | brush.setTransform(QTransform().scale(dprI, dprI)); | ||
492 | painter.setBackground(brush); | 502 | painter.setBackground(brush); | ||
493 | painter.eraseRect(geometry()); | 503 | // DON'T use geometry() because the widget position is not always (0, 0) | ||
504 | painter.eraseRect(QRect(0, 0, width(), height())); | ||||
494 | if (!mSelection.size().isEmpty() || mMouseDragState != MouseState::None) { | 505 | if (!mSelection.size().isEmpty() || mMouseDragState != MouseState::None) { | ||
495 | painter.fillRect(mSelection, mStrokeColor); | 506 | painter.fillRect(mSelection, mStrokeColor); | ||
496 | const QRectF innerRect = mSelection.adjusted(1, 1, -1, -1); | 507 | const QRectF innerRect = mSelection.adjusted(1, 1, -1, -1); | ||
497 | if (innerRect.width() > 0 && innerRect.height() > 0) { | 508 | if (innerRect.width() > 0 && innerRect.height() > 0) { | ||
498 | painter.eraseRect(mSelection.adjusted(1, 1, -1, -1)); | 509 | painter.eraseRect(mSelection.adjusted(1, 1, -1, -1)); | ||
499 | } | 510 | } | ||
500 | 511 | | |||
501 | QRectF top(0, 0, width(), mSelection.top()); | 512 | QRectF top(0, 0, width(), mSelection.top()); | ||
▲ Show 20 Lines • Show All 247 Lines • ▼ Show 20 Line(s) | 714 | { | |||
749 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | 760 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver); | ||
750 | for (auto& rect : { crossHairTop, crossHairRight, crossHairBottom, crossHairLeft }) { | 761 | for (auto& rect : { crossHairTop, crossHairRight, crossHairBottom, crossHairLeft }) { | ||
751 | painter.fillRect(rect, mCrossColor); | 762 | painter.fillRect(rect, mCrossColor); | ||
752 | } | 763 | } | ||
753 | } | 764 | } | ||
754 | 765 | | |||
755 | void QuickEditor::drawMidHelpText(QPainter &painter) | 766 | void QuickEditor::drawMidHelpText(QPainter &painter) | ||
756 | { | 767 | { | ||
757 | painter.fillRect(geometry(), mMaskColor); | 768 | // DON'T use geometry() because the widget position is not always (0, 0) | ||
769 | painter.fillRect(QRect(0, 0, width(), height()), mMaskColor); | ||||
758 | painter.setFont(mMidHelpTextFont); | 770 | painter.setFont(mMidHelpTextFont); | ||
759 | QRect textSize = painter.boundingRect(QRect(), Qt::AlignCenter, mMidHelpText); | 771 | QRect textSize = painter.boundingRect(QRect(), Qt::AlignCenter, mMidHelpText); | ||
760 | QPoint pos((mPrimaryScreenGeo.width() - textSize.width()) / 2 + mPrimaryScreenGeo.x(), (height() - textSize.height()) / 2); | 772 | QPoint pos((mPrimaryScreenGeo.width() - textSize.width()) / 2 + mPrimaryScreenGeo.x(), (height() - textSize.height()) / 2); | ||
761 | 773 | | |||
762 | painter.setBrush(mLabelBackgroundColor); | 774 | painter.setBrush(mLabelBackgroundColor); | ||
763 | QPen pen(mLabelForegroundColor); | 775 | QPen pen(mLabelForegroundColor); | ||
764 | pen.setWidth(2); | 776 | pen.setWidth(2); | ||
765 | painter.setPen(pen); | 777 | painter.setPen(pen); | ||
▲ Show 20 Lines • Show All 131 Lines • Show Last 20 Lines |
Coding style: