Skip to content

Commit 6649f0e

Browse files
committed
selection clear added
1 parent 2d35c34 commit 6649f0e

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

src/DrawingWidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class DrawingWidget : public QWidget {
130130
bool isNextAvailable();
131131
void loadImage(int num);
132132
void mergeSelection();
133+
void clearSelection();
133134
void addImage(QImage img);
134135

135136
protected:

src/Selection.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ void MovableWidget::mouseReleaseEvent(QMouseEvent *event) {
4545

4646
static bool hasSelection = false;
4747

48+
static QPointF last_end = QPointF(0,0);
49+
static QPointF last_begin = QPointF(0,0);
50+
static int rad = 0;
51+
4852
void DrawingWidget::createSelection() {
4953
hasSelection = true;
5054
//printf("%f %f %f %f\n", startPoint.x(), endPoint.x(), startPoint.y(), endPoint.y());
@@ -69,7 +73,29 @@ void DrawingWidget::createSelection() {
6973
cropWidget->move(topLeft);
7074
cropWidget->raise();
7175
cropWidget->show();
72-
update();
76+
77+
rad = penSize[penType];
78+
update(QRectF(
79+
last_begin, last_end
80+
).toRect().normalized().adjusted(-rad, -rad, +rad, +rad));
81+
update(QRectF(
82+
startPoint, endPoint
83+
).toRect().normalized().adjusted(-rad, -rad, +rad, +rad));
84+
last_begin = startPoint;
85+
last_end = endPoint;
86+
}
87+
88+
void DrawingWidget::clearSelection() {
89+
if(!hasSelection){
90+
return;
91+
}
92+
hasSelection = false;
93+
cropWidget->setFixedSize(0,0);
94+
cropWidget->move(QPoint(-1,-1));
95+
cropWidget->image = QImage(QSize(0,0), QImage::Format_ARGB32);
96+
cropWidget->image.fill(QColor("transparent"));
97+
addImage(image);
98+
7399
}
74100

75101
void DrawingWidget::mergeSelection() {
@@ -80,9 +106,7 @@ void DrawingWidget::mergeSelection() {
80106
painter.begin(&image);
81107
painter.setPen(Qt::NoPen);
82108
painter.drawImage(QPoint(cropWidget->x(), cropWidget->y()), cropWidget->image.scaled(cropWidget->width(), cropWidget->height()));
83-
cropWidget->setFixedSize(0,0);
84-
cropWidget->move(QPoint(-1,-1));
85109
update();
86110
painter.end();
87-
addImage(image);
111+
clearSelection();
88112
}

src/SetupWidgets.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,10 @@ static void setupClear(){
967967
clearButtonLayout->addWidget(yesButton);
968968

969969
QPushButton *clear = create_button(":images/clear.svg", [=](){
970+
if(drawing->penMode == SELECTION) {
971+
drawing->clearSelection();
972+
return;
973+
}
970974
floatingSettings->setPage(3);
971975
floatingWidget->setFloatingOffset(7);
972976
});

0 commit comments

Comments
 (0)