Skip to content

Commit

Permalink
Merge pull request #4 from Soft2012/users/Soft2012
Browse files Browse the repository at this point in the history
fix 2 errors(saving & 125% scale)
  • Loading branch information
Sorok-Dva authored Sep 7, 2024
2 parents bd12532 + f2d9ee5 commit 2c21ef0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/screenshotdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void ScreenshotDisplay::mouseReleaseEvent(QMouseEvent* event) {

if (shapeDrawing) {
saveStateForUndo();
QPixmap tempPixmap = drawingPixmap.copy();
QPixmap tempPixmap = originalPixmap.copy();
QPainter painter(&tempPixmap);
painter.setPen(QPen(editor->getCurrentColor(), borderWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

Expand All @@ -236,7 +236,7 @@ void ScreenshotDisplay::mouseReleaseEvent(QMouseEvent* event) {
break;
}

drawingPixmap = tempPixmap;
originalPixmap = tempPixmap;
shapeDrawing = false;
update();
}
Expand Down Expand Up @@ -365,9 +365,12 @@ void ScreenshotDisplay::onSaveRequested() {
}

QString filePath = QFileDialog::getSaveFileName(this, "Save As", defaultFileName, fileFilter);
QScreen* screen = this->screen();
qreal dpr = screen->devicePixelRatio();
QRect scaledSelectionRect = QRect(selectionRect.topLeft() * dpr, selectionRect.size() * dpr);

if (!filePath.isEmpty()) {
QPixmap selectedPixmap = originalPixmap.copy(selectionRect);
QPixmap selectedPixmap = originalPixmap.copy(scaledSelectionRect);
selectedPixmap.save(filePath);
close();
}
Expand All @@ -383,9 +386,13 @@ void ScreenshotDisplay::onPublishRequested() {

editor->hide();

QScreen* screen = this->screen();
qreal dpr = screen->devicePixelRatio();
QRect scaledSelectionRect = QRect(selectionRect.topLeft() * dpr, selectionRect.size() * dpr);

if (selectionRect.isValid()) {
ScreenshotDisplay::hide();
QPixmap selectedPixmap = resultPixmap.copy(selectionRect);
QPixmap selectedPixmap = resultPixmap.copy(scaledSelectionRect);
QApplication::clipboard()->setPixmap(selectedPixmap);

QString tempFilePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/screenshot.png";
Expand Down Expand Up @@ -526,8 +533,12 @@ void ScreenshotDisplay::copySelectionToClipboard() {
QPainter painter(&resultPixmap);
painter.drawPixmap(0, 0, drawingPixmap);

QScreen* screen = this->screen();
qreal dpr = screen->devicePixelRatio();
QRect scaledSelectionRect = QRect(selectionRect.topLeft() * dpr, selectionRect.size() * dpr);

if (selectionRect.isValid()) {
QPixmap selectedPixmap = resultPixmap.copy(selectionRect);
QPixmap selectedPixmap = resultPixmap.copy(scaledSelectionRect);
QApplication::clipboard()->setPixmap(selectedPixmap);
}
else {
Expand Down

0 comments on commit 2c21ef0

Please sign in to comment.