RectKey::RectKey(KeyCode keycode, const QRect &textGeometry, const QRect &keyGeometry, const QSize &labelSize, int topLeft, int topRight, int bottomLeft, int bottomRight, const QColor &keyColor, const QColor &textColor, const QColor &secondColor, const QColor &alphaColor, const QString &labelText, const QString &secondText, const QString &alphaText, const QFont &labelFont, const QFont &secondFont, const QFont &alphaFont, Qt::Alignment labelAlign, Qt::Alignment secondAlign, Qt::Alignment alphaAlign) : Key{keycode, textGeometry, keyGeometry, keyColor}, mTextColor{textColor}, mSecondColor{secondColor}, mAlphaColor{alphaColor}, mLabelAlign{labelAlign}, mSecondAlign{secondAlign}, mAlphaAlign{alphaAlign}, mLabelFont{labelFont}, mSecondFont{secondFont.resolve(labelFont)}, mAlphaFont{alphaFont.resolve(labelFont)}, mSecondText{secondText}, mAlphaText{alphaText} { QRect corner; mLabelText = labelText; mKeyShape.moveTo(keyGeometry.topLeft() + QPointF{0, topLeft * .5}); corner.setSize({bottomLeft, bottomLeft}); corner.moveBottomLeft(keyGeometry.bottomLeft()); mKeyShape.arcTo(corner, 90 * 2, 90); corner.setSize({bottomRight, bottomRight}); corner.moveBottomRight(keyGeometry.bottomRight()); mKeyShape.arcTo(corner, 90 * 3, 90); corner.setSize({topRight, topRight}); corner.moveTopRight(keyGeometry.topRight()); mKeyShape.arcTo(corner, 90 * 0, 90); corner.setSize({topLeft, topLeft}); corner.moveTopLeft(keyGeometry.topLeft()); mKeyShape.arcTo(corner, 90 * 1, 90); mLabelFont.setPixelSize(labelSize.height()); mLabelFont.setStretch(labelSize.width() * mLabelFont.stretch() / QFontMetricsF(mLabelFont).size(Qt::TextSingleLine, mLabelText).width()); }
void Popup::realign() { QRect rect; rect.setSize(sizeHint()); switch (mAnchor) { case Qt::TopLeftCorner: rect.moveTopLeft(mPos); break; case Qt::TopRightCorner: rect.moveTopRight(mPos); break; case Qt::BottomLeftCorner: rect.moveBottomLeft(mPos); break; case Qt::BottomRightCorner: rect.moveBottomRight(mPos); break; } QRect screen = QApplication::desktop()->availableGeometry(mPos); if (rect.right() > screen.right()) rect.moveRight(screen.right()); if (rect.bottom() > screen.bottom()) rect.moveBottom(screen.bottom()); move(rect.topLeft()); }
void ListWidgetButtonContainer::reLayout() { QListView *list = static_cast<QListView*>(parentWidget()); Q_ASSERT(list); Q_ASSERT(list->viewport()); QRect geometry; geometry.setHeight(list->viewport()->geometry().top()-list->contentsRect().top()); geometry.setWidth(list->contentsRect().width()); geometry.moveBottomLeft(list->viewport()->geometry().topLeft()); setGeometry(geometry); }
void KDEIntegrationTray::showNotes(bool active, const QPoint &pos) { Q_UNUSED(active) Menu menu; menu.addAction(actNew); menu.addSeparator(); QSettings s; QList<NoteListItem> notes = NoteManager::instance()->noteList( s.value("ui.menu-notes-amount", 15).toInt()); for (int i=0; i<notes.count(); i++) { menu.addAction(NoteManager::instance()->storage(notes[i].storageId)->noteIcon(), Utils::cuttedDots(notes[i].title, 48).replace('&', "&&") )->setData(i); } menu.show(); qtnote->activateWidget(&menu); QRect dr = QApplication::desktop()->availableGeometry(QCursor::pos()); QRect mr = menu.geometry(); mr.setSize(menu.sizeHint()); QPoint mp = pos - QPoint(mr.width() / 2, 0); if (pos.y() < dr.height()/2) { // icon at top-left mr.moveTopLeft(mp); } else { // icons at bottom-left mr.moveBottomLeft(mp); } // and now align to available desktop geometry if (mr.right() > dr.right()) { mr.moveRight(dr.right()); } if (mr.bottom() > dr.bottom()) { mr.moveBottom(dr.bottom()); } if (mr.left() < dr.left()) { mr.moveLeft(dr.left()); } if (mr.top() < dr.top()) { mr.moveTop(dr.top()); } QAction *act = menu.exec(mr.topLeft()); if (act && act != actNew) { NoteListItem ¬e = notes[act->data().toInt()]; emit showNoteTriggered(note.storageId, note.id); } }
void FreeRegionGrabber::paintEvent( QPaintEvent* e ) { Q_UNUSED( e ); if ( grabbing ) // grabWindow() should just get the background return; QPainter painter( this ); QPalette pal(QToolTip::palette()); QFont font = QToolTip::font(); QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight ); handleColor.setAlpha( 160 ); QColor overlayColor( 0, 0, 0, 160 ); QColor textColor = pal.color( QPalette::Active, QPalette::Text ); QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base ); painter.drawPixmap(0, 0, pixmap); painter.setFont(font); QPolygon pol = selection; if ( !selection.boundingRect().isNull() ) { // Draw outline around selection. // Important: the 1px-wide outline is *also* part of the captured free-region because // I found no way to draw the outline *around* the selection because I found no way // to create a QPolygon which is smaller than the selection by 1px (QPolygon::translated // is NOT equivalent to QRect::adjusted) QPen pen(handleColor, 1, Qt::SolidLine, Qt::SquareCap, Qt::BevelJoin); painter.setPen(pen); painter.drawPolygon( pol ); // Draw the grey area around the selection QRegion grey( rect() ); grey = grey - pol; painter.setClipRegion( grey ); painter.setPen( Qt::NoPen ); painter.setBrush( overlayColor ); painter.drawRect( rect() ); painter.setClipRect( rect() ); drawPolygon( &painter, pol, handleColor); } if ( showHelp ) { painter.setPen( textColor ); painter.setBrush( textBackgroundColor ); QString helpText = i18n( "Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit." ); helpTextRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText ); helpTextRect.adjust( -2, -2, 4, 2 ); drawPolygon( &painter, helpTextRect, textColor, textBackgroundColor ); painter.drawText( helpTextRect.adjusted( 3, 3, -3, -3 ), helpText ); } if ( selection.isEmpty() ) { return; } // The grabbed region is everything which is covered by the drawn // rectangles (border included). This means that there is no 0px // selection, since a 0px wide rectangle will always be drawn as a line. QString txt = QString( "%1x%2" ).arg( selection.boundingRect().width() ) .arg( selection.boundingRect().height() ); QRect textRect = painter.boundingRect( rect(), Qt::AlignLeft, txt ); QRect boundingRect = textRect.adjusted( -4, 0, 0, 0); if ( textRect.width() < pol.boundingRect().width() - 2*handleSize && textRect.height() < pol.boundingRect().height() - 2*handleSize && ( pol.boundingRect().width() > 100 && pol.boundingRect().height() > 100 ) ) // center, unsuitable for small selections { boundingRect.moveCenter( pol.boundingRect().center() ); textRect.moveCenter( pol.boundingRect().center() ); } else if ( pol.boundingRect().y() - 3 > textRect.height() && pol.boundingRect().x() + textRect.width() < rect().right() ) // on top, left aligned { boundingRect.moveBottomLeft( QPoint( pol.boundingRect().x(), pol.boundingRect().y() - 3 ) ); textRect.moveBottomLeft( QPoint( pol.boundingRect().x() + 2, pol.boundingRect().y() - 3 ) ); } else if ( pol.boundingRect().x() - 3 > textRect.width() ) // left, top aligned { boundingRect.moveTopRight( QPoint( pol.boundingRect().x() - 3, pol.boundingRect().y() ) ); textRect.moveTopRight( QPoint( pol.boundingRect().x() - 5, pol.boundingRect().y() ) ); } else if ( pol.boundingRect().bottom() + 3 + textRect.height() < rect().bottom() && pol.boundingRect().right() > textRect.width() ) // at bottom, right aligned { boundingRect.moveTopRight( QPoint( pol.boundingRect().right(), pol.boundingRect().bottom() + 3 ) ); textRect.moveTopRight( QPoint( pol.boundingRect().right() - 2, pol.boundingRect().bottom() + 3 ) ); } else if ( pol.boundingRect().right() + textRect.width() + 3 < rect().width() ) // right, bottom aligned { boundingRect.moveBottomLeft( QPoint( pol.boundingRect().right() + 3, pol.boundingRect().bottom() ) ); textRect.moveBottomLeft( QPoint( pol.boundingRect().right() + 5, pol.boundingRect().bottom() ) ); } // if the above didn't catch it, you are running on a very tiny screen... drawPolygon( &painter, boundingRect, textColor, textBackgroundColor ); painter.drawText( textRect, txt ); if ( ( pol.boundingRect().height() > handleSize*2 && pol.boundingRect().width() > handleSize*2 ) || !mouseDown ) { painter.setBrush(QBrush(Qt::transparent)); painter.setClipRegion( QRegion(pol)); painter.drawPolygon( rect() ); } }
void RegionGrabber::paintEvent( QPaintEvent* e ) { Q_UNUSED( e ); if ( grabbing ) // grabWindow() should just get the background return; QPainter painter( this ); QPalette pal(QToolTip::palette()); QFont font = QToolTip::font(); QColor handleColor = pal.color( QPalette::Active, QPalette::Highlight ); handleColor.setAlpha( 160 ); QColor overlayColor( 0, 0, 0, 160 ); QColor textColor = pal.color( QPalette::Active, QPalette::Text ); QColor textBackgroundColor = pal.color( QPalette::Active, QPalette::Base ); painter.drawPixmap(0, 0, pixmap); painter.setFont(font); QRect r = selection; if ( !selection.isNull() ) { QRegion grey( rect() ); grey = grey.subtracted( r ); painter.setClipRegion( grey ); painter.setPen( Qt::NoPen ); painter.setBrush( overlayColor ); painter.drawRect( rect() ); painter.setClipRect( rect() ); drawRect( &painter, r, handleColor ); } if ( showHelp ) { painter.setPen( textColor ); painter.setBrush( textBackgroundColor ); QString helpText = "Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit."; helpTextRect = painter.boundingRect( rect().adjusted( 2, 2, -2, -2 ), Qt::TextWordWrap, helpText ); helpTextRect.adjust( -2, -2, 4, 2 ); drawRect( &painter, helpTextRect, textColor, textBackgroundColor ); painter.drawText( helpTextRect.adjusted( 3, 3, -3, -3 ), helpText ); } if ( selection.isNull() ) { return; } // The grabbed region is everything which is covered by the drawn // rectangles (border included). This means that there is no 0px // selection, since a 0px wide rectangle will always be drawn as a line. QString txt = QString( "%1x%2" ).arg( selection.width() ) .arg( selection.height() ); QRect textRect = painter.boundingRect( rect(), Qt::AlignLeft, txt ); QRect boundingRect = textRect.adjusted( -4, 0, 0, 0); if ( textRect.width() < r.width() - 2*handleSize && textRect.height() < r.height() - 2*handleSize && ( r.width() > 100 && r.height() > 100 ) ) // center, unsuitable for small selections { boundingRect.moveCenter( r.center() ); textRect.moveCenter( r.center() ); } else if ( r.y() - 3 > textRect.height() && r.x() + textRect.width() < rect().right() ) // on top, left aligned { boundingRect.moveBottomLeft( QPoint( r.x(), r.y() - 3 ) ); textRect.moveBottomLeft( QPoint( r.x() + 2, r.y() - 3 ) ); } else if ( r.x() - 3 > textRect.width() ) // left, top aligned { boundingRect.moveTopRight( QPoint( r.x() - 3, r.y() ) ); textRect.moveTopRight( QPoint( r.x() - 5, r.y() ) ); } else if ( r.bottom() + 3 + textRect.height() < rect().bottom() && r.right() > textRect.width() ) // at bottom, right aligned { boundingRect.moveTopRight( QPoint( r.right(), r.bottom() + 3 ) ); textRect.moveTopRight( QPoint( r.right() - 2, r.bottom() + 3 ) ); } else if ( r.right() + textRect.width() + 3 < rect().width() ) // right, bottom aligned { boundingRect.moveBottomLeft( QPoint( r.right() + 3, r.bottom() ) ); textRect.moveBottomLeft( QPoint( r.right() + 5, r.bottom() ) ); } // if the above didn't catch it, you are running on a very tiny screen... drawRect( &painter, boundingRect, textColor, textBackgroundColor ); painter.drawText( textRect, txt ); if ( ( r.height() > handleSize*2 && r.width() > handleSize*2 ) || !mouseDown ) { updateHandles(); painter.setPen( Qt::NoPen ); painter.setBrush( handleColor ); painter.setClipRegion( handleMask( StrokeMask ) ); painter.drawRect( rect() ); handleColor.setAlpha( 60 ); painter.setBrush( handleColor ); painter.setClipRegion( handleMask( FillMask ) ); painter.drawRect( rect() ); } }
void RenderedImage::DisplayCoordinates() { QPainter painter(this); painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); QPen penWhite(Qt::white, 1, Qt::SolidLine); QBrush brushBrown(QColor(100, 50, 0)); QBrush brushDarkBlue(QColor(0, 0, 100)); QString text; enumClickMode clickMode = (enumClickMode)clickModeData.at(0).toInt(); switch (clickMode) { case clickMoveCamera: text = tr("Move camera"); break; case clickFogVisibility: text = tr("Change fog visibility"); break; case clickDOFFocus: text = tr("Change DOF focus"); break; case clickPlaceLight: text = tr("Place light #") + QString::number(clickModeData.at(1).toInt()); text += tr("\nMouse wheel - light fov / bkw"); break; case clickPlacePrimitive: text = tr("Place ") + PrimitiveNames((fractal::enumObjectType)clickModeData.at(1).toInt()) + QString(" #")+ QString::number(clickModeData.at(2).toInt()); break; case clickGetJuliaConstant: text = tr("Get Julia constant"); break; case clickFlightSpeedControl: text = tr("LMB - increase speed"); text += tr("\nRMB - decrease speed"); text += tr("\narrow keys - strafe"); text += tr("\nz, x keys - roll"); text += tr("\nspacebar - pause"); text += tr("\nhold shift key - orthogonal strafe"); break; case clickDoNothing: text = ""; break; } if(clickMode != clickDoNothing) { QRect textRect = painter.boundingRect(QRect(), Qt::AlignTop || Qt::AlignLeft, text); textRect.setHeight(textRect.height() + 2); textRect.moveBottomLeft(QPoint(lastMousePosition.x + 30, lastMousePosition.y - 3)); painter.setOpacity(0.5); painter.setPen(penWhite); painter.setBrush(brushBrown); painter.drawRoundedRect(textRect, 3, 3); painter.drawText(textRect, Qt::AlignTop || Qt::AlignLeft, text); } QString textCoordinates; if(clickMode != clickFlightSpeedControl) { textCoordinates += "x: " + QString::number(lastCoordinates.x, 'g', 15); textCoordinates += "\ny: " + QString::number(lastCoordinates.y, 'g', 15); textCoordinates += "\nz: " + QString::number(lastCoordinates.z, 'g', 15); textCoordinates += "\ndist: " + QString::number(lastDepth, 'g', 15); } else { textCoordinates += "frame: " + QString::number(flightData.frame); textCoordinates += "\nx: " + QString::number(flightData.camera.x, 'g', 15); textCoordinates += "\ny: " + QString::number(flightData.camera.y, 'g', 15); textCoordinates += "\nz: " + QString::number(flightData.camera.y, 'z', 15); textCoordinates += "\ndist: " + QString::number(flightData.distance); textCoordinates += "\nspeed act: " + QString::number(flightData.speed); textCoordinates += "\nspeed set: " + QString::number(flightData.speedSp); } QRect textRect2 = painter.boundingRect(QRect(), Qt::AlignTop || Qt::AlignLeft, textCoordinates); textRect2.setHeight(textRect2.height() + 2); textRect2.moveTopLeft(QPoint(lastMousePosition.x + 30, lastMousePosition.y + 3)); painter.setOpacity(0.5); painter.setPen(penWhite); painter.setBrush(brushDarkBlue); painter.drawRoundedRect(textRect2, 3, 3); painter.drawText(textRect2, Qt::AlignTop || Qt::AlignLeft, textCoordinates); }
void RegionGrab::paintEvent(QPaintEvent *event) { Q_UNUSED( event ); if (m_grabbing) return; QPainter painter( this ); QPalette pal(QToolTip::palette()); QFont font = QToolTip::font(); QColor handleColor = pal.color(QPalette::Active, QPalette::Highlight); handleColor.setAlpha(160); QColor overlayColor(0, 0, 0, 100); QColor textColor = pal.color(QPalette::Active, QPalette::Text); QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base); painter.drawPixmap(0, 0, m_pixmap); painter.setFont(font); const QRect& r = m_selection; if (r.isNull()) { painter.setClipRegion(QRegion(rect())); painter.setPen(Qt::NoPen); painter.setBrush(overlayColor); painter.drawRect(rect()); } else { painter.setClipRegion(QRegion(rect()).subtracted(r)); painter.setPen(Qt::NoPen); painter.setBrush(overlayColor); painter.drawRect(rect()); painter.setClipRect(rect()); drawRect(&painter, r, handleColor); } // \bug Подсказка центрируется не правильно в многомониторной конфигурации. if (m_showHelp) { painter.setPen(textColor); painter.setBrush(textBackgroundColor); QString helpText = tr("Select a region using the mouse. To take the snapshot, press the Enter key or double click. Press Esc to quit."); QRect scrRect = QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()); m_helpTextRect = painter.boundingRect(scrRect.adjusted(20, 20, -20, -20), Qt::AlignHCenter, helpText); m_helpTextRect.adjust(-4, -4, 8, 4); drawRect(&painter, m_helpTextRect, textColor, textBackgroundColor); painter.drawText(m_helpTextRect.adjusted(3, 3, -3, -3), helpText); } if (r.isNull()) return; // The grabbed region is everything which is covered by the drawn // rectangles (border included). This means that there is no 0px // selection, since a 0px wide rectangle will always be drawn as a line. QString txt = QString("%1x%2").arg(r.width()).arg(r.height()); QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt); QRect boundingRect = textRect.adjusted(-4, 0, 0, 0); // center, unsuitable for small selections if (textRect.width() < r.width() - 2 * m_handleSize && textRect.height() < r.height() - 2 * m_handleSize && (r.width() > 100 && r.height() > 100)) { boundingRect.moveCenter(r.center()); textRect.moveCenter(r.center()); } // on top, left aligned else if (r.y() - 3 > textRect.height() && r.x() + textRect.width() < rect().right()) { boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3)); textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3)); } // left, top aligned else if (r.x() - 3 > textRect.width()) { boundingRect.moveTopRight(QPoint(r.x() - 3, r.y())); textRect.moveTopRight(QPoint(r.x() - 5, r.y())); } // at bottom, right aligned else if (r.bottom() + 3 + textRect.height() < rect().bottom() && r.right() > textRect.width()) { boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3)); textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3)); } // right, bottom aligned else if (r.right() + textRect.width() + 3 < rect().width()) { boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom())); textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom())); } // if the above didn't catch it, you are running on a very tiny screen... drawRect(&painter, boundingRect, textColor, textBackgroundColor); painter.drawText(textRect, txt); if ((r.height() > m_handleSize * 2 && r.width() > m_handleSize * 2) || !m_mouseDown) { updateHandles(); painter.setPen(Qt::NoPen); painter.setBrush(handleColor); painter.setClipRegion(handleMask(StrokeMask)); painter.drawRect(rect()); handleColor.setAlpha(60); painter.setBrush(handleColor); painter.setClipRegion(handleMask(FillMask)); painter.drawRect(rect()); } }
void AreaDialog::paintEvent(QPaintEvent* e) { Q_UNUSED(e); if (mGrabbing) // grabWindow() should just get the background return; QPainter painter(this); QPalette pal = palette(); QFont font = QToolTip::font(); QColor handleColor(85, 160, 188, 220); QColor overlayColor(0, 0, 0, mOverlayAlpha); QColor textColor = pal.color(QPalette::Active, QPalette::Text); QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base); painter.drawPixmap(0, 0, mScreenshot->pixmap()); painter.setFont(font); QRect r = mSelection.normalized().adjusted(0, 0, -1, -1); QRegion grey(rect()); grey = grey.subtracted(r); painter.setPen(handleColor); painter.setBrush(overlayColor); painter.setClipRegion(grey); painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1); painter.setClipRect(rect()); painter.setBrush(Qt::NoBrush); painter.drawRect(r); if (mShowHelp) { //Drawing the explanatory text. QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen()); QString helpTxt = tr("Lightscreen area mode:\nUse your mouse to draw a rectangle to capture.\nPress any key or right click to exit."); helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered) // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have. painter.setPen(QPen(Qt::white)); painter.setBrush(QBrush(QColor(255, 255, 255, 180), Qt::SolidPattern)); QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt); // These four calls provide padding for the rect bRect.setWidth(bRect.width() + 12); bRect.setHeight(bRect.height() + 10); bRect.setX(bRect.x() - 12); bRect.setY(bRect.y() - 10); painter.drawRoundedRect(bRect, 8, 8); // Draw the text: painter.setPen(QPen(Qt::black)); painter.drawText(helpRect, Qt::AlignCenter, helpTxt); } if (!mSelection.isNull()) { // The grabbed region is everything which is covered by the drawn // rectangles (border included). This means that there is no 0px // selection, since a 0px wide rectangle will always be drawn as a line. QString txt = QString("%1x%2").arg(mSelection.width() == 0 ? 2 : mSelection.width()) .arg(mSelection.height() == 0 ? 2 : mSelection.height()); QRect textRect = painter.boundingRect(rect(), Qt::AlignLeft, txt); QRect boundingRect = textRect.adjusted(-4, 0, 0, 0); if (textRect.width() < r.width() - 2*mHandleSize && textRect.height() < r.height() - 2*mHandleSize && (r.width() > 100 && r.height() > 100)) // center, unsuitable for small selections { boundingRect.moveCenter(r.center()); textRect.moveCenter(r.center()); } else if (r.y() - 3 > textRect.height() && r.x() + textRect.width() < rect().right()) // on top, left aligned { boundingRect.moveBottomLeft(QPoint(r.x(), r.y() - 3)); textRect.moveBottomLeft(QPoint(r.x() + 2, r.y() - 3)); } else if (r.x() - 3 > textRect.width()) // left, top aligned { boundingRect.moveTopRight(QPoint(r.x() - 3, r.y())); textRect.moveTopRight(QPoint(r.x() - 5, r.y())); } else if (r.bottom() + 3 + textRect.height() < rect().bottom() && r.right() > textRect.width()) // at bottom, right aligned { boundingRect.moveTopRight(QPoint(r.right(), r.bottom() + 3)); textRect.moveTopRight(QPoint(r.right() - 2, r.bottom() + 3)); } else if (r.right() + textRect.width() + 3 < rect().width()) // right, bottom aligned { boundingRect.moveBottomLeft(QPoint(r.right() + 3, r.bottom())); textRect.moveBottomLeft(QPoint(r.right() + 5, r.bottom())); } // if the above didn't catch it, you are running on a very tiny screen... painter.setPen(textColor); painter.setBrush(textBackgroundColor); painter.drawRect(boundingRect); painter.drawText(textRect, txt); if ((r.height() > mHandleSize*2 && r.width() > mHandleSize*2) || !mMouseDown) { updateHandles(); painter.setPen(handleColor); handleColor.setAlpha(80); painter.setBrush(handleColor); painter.drawRects(handleMask().rects()); } } if (!mScreenshot->options().magnify) return; // Drawing the magnified version QPoint magStart, magEnd, drawPosition; QRect newRect; QRect pixmapRect = mScreenshot->pixmap().rect(); if (mMouseMagnifier) { drawPosition = mMousePos - QPoint(100, 100); magStart = mMousePos - QPoint(50, 50); magEnd = mMousePos + QPoint(50, 50); newRect = QRect(magStart, magEnd); } else { // So pretty.. oh so pretty. if (mMouseOverHandle == &mTLHandle) magStart = mSelection.topLeft(); else if (mMouseOverHandle == &mTRHandle) magStart = mSelection.topRight(); else if (mMouseOverHandle == &mBLHandle) magStart = mSelection.bottomLeft(); else if (mMouseOverHandle == &mBRHandle) magStart = mSelection.bottomRight(); else if (mMouseOverHandle == &mLHandle) magStart = QPoint(mSelection.left(), mSelection.center().y()); else if (mMouseOverHandle == &mTHandle) magStart = QPoint(mSelection.center().x(), mSelection.top()); else if (mMouseOverHandle == &mRHandle) magStart = QPoint(mSelection.right(), mSelection.center().y()); else if (mMouseOverHandle == &mBHandle) magStart = QPoint(mSelection.center().x(), mSelection.bottom()); else if (mMouseOverHandle == 0) magStart = mMousePos; magEnd = magStart; drawPosition = mSelection.bottomRight(); magStart -= QPoint(50, 50); magEnd += QPoint(50, 50); newRect = QRect(magStart, magEnd); if ((drawPosition.x()+newRect.width()*2) > pixmapRect.width()) drawPosition.setX(drawPosition.x()-newRect.width()*2); if ((drawPosition.y()+newRect.height()*2) > pixmapRect.height()) drawPosition.setY(drawPosition.y()-newRect.height()*2); if (drawPosition.y() == mSelection.bottomRight().y()-newRect.height()*2 && drawPosition.x() == mSelection.bottomRight().x()-newRect.width()*2) painter.setOpacity(0.7); } if (!pixmapRect.contains(newRect, true) || drawPosition.x() <= 0 || drawPosition.y() <= 0) { return; } QPixmap magnified = mScreenshot->pixmap().copy(newRect).scaled(QSize(newRect.width()*2, newRect.height()*2)); QPainter magPainter(&magnified); magPainter.setPen(QPen(QBrush(QColor(35, 35, 35)), 2)); // Same border pen magPainter.drawRect(magnified.rect()); if (!mMouseMagnifier) { magPainter.drawText(magnified.rect().center()-QPoint(4, -4), "+"); //Center minus the 4 pixels wide and across of the "+" -- TODO: Test alternative DPI settings. } painter.drawPixmap(drawPosition, magnified); }