Skip to content

Commit

Permalink
Add menu item to allow erasing background image
Browse files Browse the repository at this point in the history
  • Loading branch information
huxingyi committed Dec 18, 2022
1 parent a5f8ec5 commit 2ef6895
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 23 additions & 1 deletion application/sources/document_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,14 @@ DocumentWindow::DocumentWindow()

m_fileMenu->addSeparator();

m_changeTurnaroundAction = new QAction(tr("Change Reference Sheet..."), this);
m_changeTurnaroundAction = new QAction(tr("Change Background Image..."), this);
connect(m_changeTurnaroundAction, &QAction::triggered, this, &DocumentWindow::changeTurnaround, Qt::QueuedConnection);
m_fileMenu->addAction(m_changeTurnaroundAction);

m_eraseTurnaroundAction = new QAction(tr("Erase Background Image"), this);
connect(m_eraseTurnaroundAction, &QAction::triggered, this, &DocumentWindow::eraseTurnaround, Qt::QueuedConnection);
m_fileMenu->addAction(m_eraseTurnaroundAction);

m_fileMenu->addSeparator();

for (int i = 0; i < Preferences::instance().maxRecentFiles(); ++i) {
Expand Down Expand Up @@ -867,6 +871,24 @@ void DocumentWindow::changeTurnaround()
m_document->updateTurnaround(image);
}

void DocumentWindow::eraseTurnaround()
{
if (m_document->turnaround.isNull())
return;

QMessageBox::StandardButton answer = QMessageBox::question(this,
APP_NAME,
tr("Do you really want to erase background image? This can not be undo."),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No);
if (answer != QMessageBox::Yes)
return;

QImage image(m_document->turnaround.width(), m_document->turnaround.height(), QImage::Format_RGBA8888);
image.fill(0);
m_document->updateTurnaround(image);
}

void DocumentWindow::save()
{
saveTo(m_currentFilename);
Expand Down
2 changes: 2 additions & 0 deletions application/sources/document_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DocumentWindow : public QMainWindow {
void mousePressEvent(QMouseEvent* event);
public slots:
void changeTurnaround();
void eraseTurnaround();
void save();
void saveTo(const QString& saveAsFilename);
void open();
Expand Down Expand Up @@ -136,6 +137,7 @@ public slots:
QAction* m_saveAsAction = nullptr;
QAction* m_saveAllAction = nullptr;
QAction* m_changeTurnaroundAction = nullptr;
QAction* m_eraseTurnaroundAction = nullptr;
std::vector<QAction*> m_recentFileActions;
QAction* m_recentFileSeparatorAction = nullptr;
QAction* m_quitAction = nullptr;
Expand Down

0 comments on commit 2ef6895

Please sign in to comment.