| 469 | } |
| 470 | |
| 471 | void AreaDialog::paintEvent(QPaintEvent *e) |
| 472 | { |
| 473 | Q_UNUSED(e); |
| 474 | |
| 475 | if (mGrabbing) { // grabWindow() should just get the background |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | QPainter painter(this); |
| 480 | |
| 481 | QPalette pal = palette(); |
| 482 | QFont font = QToolTip::font(); |
| 483 | |
| 484 | QColor handleColor(85, 160, 188, 220); |
| 485 | QColor overlayColor(0, 0, 0, mOverlayAlpha); |
| 486 | QColor textColor = pal.color(QPalette::Active, QPalette::Text); |
| 487 | QColor textBackgroundColor = pal.color(QPalette::Active, QPalette::Base); |
| 488 | painter.drawPixmap(0, 0, mScreenshot->pixmap()); |
| 489 | painter.setFont(font); |
| 490 | |
| 491 | QRect r = mSelection.normalized().adjusted(0, 0, -1, -1); |
| 492 | |
| 493 | QRegion grey(rect()); |
| 494 | grey = grey.subtracted(r); |
| 495 | painter.setPen(handleColor); |
| 496 | painter.setBrush(overlayColor); |
| 497 | painter.setClipRegion(grey); |
| 498 | painter.drawRect(-1, -1, rect().width() + 1, rect().height() + 1); |
| 499 | painter.setClipRect(rect()); |
| 500 | painter.setBrush(Qt::NoBrush); |
| 501 | painter.drawRect(r); |
| 502 | |
| 503 | if (mShowHelp) { |
| 504 | //Drawing the explanatory text. |
| 505 | QRect helpRect = qApp->desktop()->screenGeometry(qApp->desktop()->primaryScreen()); |
| 506 | QString helpTxt = tr("Use your mouse to draw a rectangle to capture. Press any key or right click to exit.\nType \"100x100\" or similar and press enter for precise sizing. Ctrl+M toggles magnifier."); |
| 507 | |
| 508 | helpRect.setHeight(qRound((float)(helpRect.height() / 10))); // We get a decently sized rect where the text should be drawn (centered) |
| 509 | |
| 510 | // We draw the white contrasting background for the text, using the same text and options to get the boundingRect that the text will have. |
| 511 | painter.setPen(QPen(Qt::white)); |
| 512 | painter.setBrush(QBrush(QColor(255, 255, 255, 210), Qt::SolidPattern)); |
| 513 | QRectF bRect = painter.boundingRect(helpRect, Qt::AlignCenter, helpTxt); |
| 514 | |
| 515 | // These four calls provide padding for the rect |
| 516 | bRect.setWidth(bRect.width() + 12); |
| 517 | bRect.setHeight(bRect.height() + 10); |
| 518 | bRect.setX(bRect.x() - 12); |
| 519 | bRect.setY(bRect.y() - 10); |
| 520 | |
| 521 | painter.drawRoundedRect(bRect, 8, 8); |
| 522 | |
| 523 | // Draw the text: |
| 524 | painter.setPen(QPen(Qt::black)); |
| 525 | painter.drawText(helpRect, Qt::AlignCenter, helpTxt); |
| 526 | } |
| 527 | |
| 528 | if (!mKeyboardSize.isEmpty()) { |