22 #include <QApplication> 
   24 #include <QDesktopWidget> 
   25 #include <QGraphicsPixmapItem> 
   26 #include <QGraphicsRectItem> 
   27 #include <QGraphicsSceneMouseEvent> 
   28 #include <QGraphicsView> 
   29 #include <QMouseEvent> 
   45     window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
 
   46     window->setContentsMargins(0, 0, 0, 0);
 
   47     window->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
   48     window->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
 
   49     window->setFrameShape(QFrame::NoFrame);
 
   50     window->installEventFilter(
this);
 
   51     pixRatio = QApplication::primaryScreen()->devicePixelRatio();
 
   58     window->resetCachedContent();
 
   72     if (event->type() == QEvent::KeyPress)
 
   75     return QObject::eventFilter(
object, event);
 
   84     this->
window->grabKeyboard();
 
   87     QRect rec = QApplication::primaryScreen()->virtualGeometry();
 
   89     this->
window->setGeometry(rec);
 
   90     this->
scene->setSceneRect(fullGrabbedRect);
 
   91     this->
overlay->setRect(fullGrabbedRect);
 
  101     if (event->key() == Qt::Key_Escape)
 
  103     else if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)
 
  105     else if (event->key() == Qt::Key_Space) {
 
  114         QTimer::singleShot(350, 
this, SLOT(
reInit()));
 
  124     if (rect.width() < 1 || rect.height() < 1)
 
  132     qDebug() << 
"Screenshot accepted, chosen region" << rect;
 
  143     scene = 
new QGraphicsScene;
 
  171         tr(
"Click and drag to select a region. Press %1 to " 
  172            "hide/show qTox window, or %2 to cancel.",
 
  173            "Help text shown when no region has been selected yet")
 
  174             .arg(QString(
"<b>%1</b>").arg(tr(
"Space", 
"[Space] key on the keyboard")),
 
  175                  QString(
"<b>%1</b>").arg(tr(
"Escape", 
"[Escape] key on the keyboard"))));
 
  182         tr(
"Press %1 to send a screenshot of the selection, " 
  183            "%2 to hide/show qTox window, or %3 to cancel.",
 
  184            "Help text shown when a region has been selected")
 
  185             .arg(QString(
"<b>%1</b>").arg(tr(
"Enter", 
"[Enter] key on the keyboard")),
 
  186                  QString(
"<b>%1</b>").arg(tr(
"Space", 
"[Space] key on the keyboard")),
 
  187                  QString(
"<b>%1</b>").arg(tr(
"Escape", 
"[Escape] key on the keyboard"))));
 
  193     if (rect.size().isNull())
 
  205     QRect recGL = QGuiApplication::primaryScreen()->virtualGeometry();
 
  206 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) 
  207     const auto rec = QGuiApplication::screenAt(QCursor::pos())->geometry();
 
  209     const auto rec = qApp->desktop()->screenGeometry(QCursor::pos());
 
  211     const QRectF ttRect = this->
helperToolbox->childrenBoundingRect();
 
  212     int x = qAbs(recGL.x()) + rec.x() + ((rec.width() - ttRect.width()) / 2);
 
  213     int y = qAbs(recGL.y()) + rec.y();
 
  227     QScreen* screen = QGuiApplication::primaryScreen();
 
  228     QRect rec = screen->virtualGeometry();
 
  231     return screen->grabWindow(QApplication::desktop()->winId(), rec.x() * 
pixRatio,
 
  237     foreach (QWidget* w, qApp->topLevelWidgets()) {
 
  238         if (w != 
window && w->isVisible()) {
 
  240             w->setVisible(
false);
 
  260     QPointF pos = 
event->scenePos();