Skip to content

Commit 473aa0b

Browse files
committed
fixes
1 parent c09780a commit 473aa0b

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int main(int argc, char *argv[]) {
5454
// gnome wayland fullscreen compositor is buggy.
5555
// Force prefer Xwayland for fix this issue.
5656
if(getenv("XDG_CURRENT_DESKTOP")){
57-
force_xwayland = strncmp(getenv("XDG_CURRENT_DESKTOP"), "gnome", 5) || \
58-
strncmp(getenv("XDG_CURRENT_DESKTOP"), "GNOME", 5);
57+
force_xwayland = strncmp(getenv("XDG_CURRENT_DESKTOP"), "gnome", 5) == 0 || \
58+
strncmp(getenv("XDG_CURRENT_DESKTOP"), "GNOME", 5) == 0;
5959
}
6060
// Force use X11 or Xwayland
6161
if(get_bool("xwayland") || force_xwayland){

src/tools/screenshot.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ static void setCropScreenShot(QPixmap pix){
99
board->setType(WHITE);
1010
board->setOverlayType(CUSTOM);
1111
board->rotates[drawing->getPageNum()] = 0;
12-
board->ratios[drawing->getPageNum()] = pix.width() * 100 / board->geometry().width();
12+
board->ratios[drawing->getPageNum()] = 100;
1313
board->updateTransform();
1414
setHideMainWindow(false);
15+
floatingWidget->show();
1516

16-
printf("%s\n", "crop done");
1717
}
1818
#endif
1919

@@ -36,17 +36,11 @@ void setupScreenShot(){
3636

3737
ScreenshotWidget* widget = new ScreenshotWidget();
3838
widget->crop_signal = setCropScreenShot;
39-
QTimer *sscTimer = new QTimer();
40-
QObject::connect(sscTimer, &QTimer::timeout, [=](){
41-
sscTimer->stop();
42-
widget->showFullScreen();
43-
floatingWidget->show();
4439

45-
});
4640
toolButtons[SCREENSHOT_CROP] = create_button(SCREENSHOT_CROP, [=](){
4741
floatingWidget->hide();
4842
floatingSettings->setHide();
49-
sscTimer->start(500);
43+
widget->showFullScreen();
5044
});
5145
set_shortcut(toolButtons[SCREENSHOT_CROP], Qt::Key_F2, Qt::ControlModifier);
5246
#endif

src/widgets/ScreenshotWidget.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "../tools.h"
99

1010

11+
1112
ScreenshotWidget::ScreenshotWidget(QWidget *parent)
1213
: QWidget(parent), selecting(false) {
1314
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
@@ -18,6 +19,8 @@ ScreenshotWidget::ScreenshotWidget(QWidget *parent)
1819

1920
void ScreenshotWidget::mousePressEvent(QMouseEvent *event) {
2021
startPos = event->pos();
22+
endPos = event->pos();
23+
update();
2124
}
2225

2326
void ScreenshotWidget::mouseMoveEvent(QMouseEvent *event) {
@@ -26,8 +29,15 @@ void ScreenshotWidget::mouseMoveEvent(QMouseEvent *event) {
2629
}
2730

2831
void ScreenshotWidget::mouseReleaseEvent(QMouseEvent *event) {
32+
2933
endPos = event->pos();
30-
cropScreenshot();
34+
QPoint pos1 = startPos;
35+
QPoint pos2 = endPos;
36+
hide();
37+
QTimer::singleShot(50, this, [=]() {
38+
this->cropScreenshot(pos1, pos2);
39+
});
40+
// reset surface
3141
startPos = QPoint(-1, -1);
3242
endPos = QPoint(-1, -1);
3343
update();
@@ -36,24 +46,26 @@ void ScreenshotWidget::mouseReleaseEvent(QMouseEvent *event) {
3646
void ScreenshotWidget::paintEvent(QPaintEvent *) {
3747
QPainter painter(this);
3848
painter.setPen(Qt::NoPen);
49+
3950
// background
40-
painter.setBrush(QBrush(QColor(255, 255, 255, 13)));
41-
painter.drawRect(QRect(0,0,geometry().width(), geometry().height()));
42-
// selection
4351
QColor color = drawing->penColor;
44-
color.setAlpha(127);
52+
color.setAlpha(69);
4553
painter.setBrush(QBrush(color));
54+
painter.setCompositionMode(QPainter::CompositionMode_Source);
55+
56+
57+
painter.drawRect(QRect(0,0,geometry().width(), geometry().height()));
58+
// selection
4659
QRect rect(startPos, endPos);
60+
painter.setBrush(QBrush(QColor(0,0,0,0)));
4761
painter.drawRect(rect.normalized());
4862
}
4963

50-
void ScreenshotWidget::cropScreenshot() {
64+
void ScreenshotWidget::cropScreenshot(QPoint startPos, QPoint endPos) {
5165
QScreen *screen = QGuiApplication::primaryScreen();
5266
QPixmap originalPixmap = screen->grabWindow(0);
53-
5467
QRect cropRect(startPos, endPos);
5568
QPixmap croppedPixmap = originalPixmap.copy(cropRect.normalized());
5669
crop_signal(croppedPixmap);
57-
hide();
5870
}
5971

src/widgets/ScreenshotWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ScreenshotWidget : public QWidget {
1818
void paintEvent(QPaintEvent *event) override;
1919

2020
private:
21-
void cropScreenshot();
21+
void cropScreenshot(QPoint startPos, QPoint endPos);
2222

2323
QPoint startPos;
2424
QPoint endPos;

0 commit comments

Comments
 (0)