| 404 | } |
| 405 | |
| 406 | void Screenshot::grabDesktop() |
| 407 | { |
| 408 | QRect geometry; |
| 409 | QPoint cursorPosition = QCursor::pos(); |
| 410 | |
| 411 | if (mOptions.currentMonitor) { |
| 412 | int currentScreen = qApp->desktop()->screenNumber(cursorPosition); |
| 413 | |
| 414 | geometry = qApp->desktop()->screen(currentScreen)->geometry(); |
| 415 | cursorPosition = cursorPosition - geometry.topLeft(); |
| 416 | } else { |
| 417 | int top = 0; |
| 418 | |
| 419 | for (QScreen *screen : QGuiApplication::screens()) { |
| 420 | auto screenRect = screen->geometry(); |
| 421 | |
| 422 | if (screenRect.top() < 0) { |
| 423 | top += screenRect.top() * -1; |
| 424 | } |
| 425 | |
| 426 | if (screenRect.left() < 0) { |
| 427 | cursorPosition.setX(cursorPosition.x() + screenRect.width()); //= localCursorPos + screenRect.normalized().topLeft(); |
| 428 | } |
| 429 | |
| 430 | geometry = geometry.united(screenRect); |
| 431 | } |
| 432 | |
| 433 | cursorPosition.setY(cursorPosition.y() + top); |
| 434 | } |
| 435 | |
| 436 | mPixmap = QApplication::primaryScreen()->grabWindow(QApplication::desktop()->winId(), geometry.x(), geometry.y(), geometry.width(), geometry.height()); |
| 437 | mPixmap.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio()); |
| 438 | |
| 439 | if (mOptions.cursor && !mPixmap.isNull()) { |
| 440 | QPainter painter(&mPixmap); |
| 441 | auto cursorInfo = os::cursor(); |
| 442 | auto cursorPixmap = cursorInfo.first; |
| 443 | cursorPixmap.setDevicePixelRatio(QApplication::desktop()->devicePixelRatio()); |
| 444 | |
| 445 | #if 0 // Debug cursor position helper |
| 446 | painter.setBrush(QBrush(Qt::darkRed)); |
| 447 | painter.setPen(QPen(QBrush(Qt::red), 5)); |
| 448 | QRectF rect; |
| 449 | rect.setSize(QSizeF(100, 100)); |
| 450 | rect.moveCenter(cursorPosition); |
| 451 | painter.drawRoundRect(rect, rect.size().height()*2, rect.size().height()*2); |
| 452 | #endif |
| 453 | |
| 454 | painter.drawPixmap(cursorPosition-cursorInfo.second, cursorPixmap); |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | const QString Screenshot::newFileName() const |
| 459 | { |
nothing calls this directly
no test coverage detected