Add download button to ImageOverlay

When opening images in the full-screen overlay, there is now
a download button next to the close button.  This button utilizes
the same functionality as the right-click->save image button.
This commit is contained in:
redsky17 2019-01-30 18:01:36 -05:00
parent f7255b7b49
commit 6d629f1c90
3 changed files with 13 additions and 0 deletions

View File

@ -76,6 +76,8 @@ ImageOverlay::paintEvent(QPaintEvent *event)
content_ = QRect(outer_margin + diff_x / 2, diff_y / 2, image_.width(), image_.height());
close_button_ =
QRect(screen_.width() - margin - buttonSize, margin, buttonSize, buttonSize);
save_button_ =
QRect(screen_.width() - (2 * margin) - (2 * buttonSize), margin, buttonSize, buttonSize);
// Draw main content_.
painter.drawPixmap(content_, image_);
@ -91,6 +93,12 @@ ImageOverlay::paintEvent(QPaintEvent *event)
painter.setPen(pen);
painter.drawLine(center - QPointF(15, 15), center + QPointF(15, 15));
painter.drawLine(center + QPointF(15, -15), center - QPointF(15, -15));
// Draw download button
center = save_button_.center();
painter.drawLine(center - QPointF(0, 15), center + QPointF(0, 15));
painter.drawLine(center - QPointF(15, 0), center + QPointF(0, 15));
painter.drawLine(center + QPointF(0, 15), center + QPointF(15, 0));
}
void
@ -101,6 +109,8 @@ ImageOverlay::mousePressEvent(QMouseEvent *event)
if (close_button_.contains(event->pos()))
emit closing();
else if (save_button_.contains(event->pos()))
emit saving();
else if (!content_.contains(event->pos()))
emit closing();
}

View File

@ -35,6 +35,7 @@ protected:
signals:
void closing();
void saving();
private:
QPixmap originalImage_;
@ -42,6 +43,7 @@ private:
QRect content_;
QRect close_button_;
QRect save_button_;
QRect screen_;
};
} // dialogs

View File

@ -158,6 +158,7 @@ ImageItem::mousePressEvent(QMouseEvent *event)
} else {
auto imgDialog = new dialogs::ImageOverlay(image_);
imgDialog->show();
connect(imgDialog, &dialogs::ImageOverlay::saving, this, &ImageItem::saveAs);
}
}