From c5e8a6a529732d2e87469067ad221bd89f4edb69 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 8 Nov 2016 13:39:27 +0200 Subject: [PATCH] Refactor templates SetToolButton and SetToolButtonWithApply. These templates do almost the same. Uniting them looks like a good idea. --HG-- branch : feature --- src/app/valentina/mainwindow.cpp | 54 +++++++++++--------------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 74c7fdc71..d8f4ac82c 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -541,13 +541,28 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons CancelTool(); emit EnableItemMove(false); currentTool = lastUsedTool = t; - QPixmap pixmap(cursor); + auto cursorResource = cursor; + if (qApp->devicePixelRatio() >= 2) + { + // Try to load HiDPI versions of the cursors if availible + auto cursorHidpiResource = QString(cursor).replace(".png", "@2x.png"); + if (QFileInfo(cursorResource).exists()) + { + cursorResource = cursorHidpiResource; + } + } + QPixmap pixmap(cursorResource); QCursor cur(pixmap, 2, 3); ui->view->setCursor(cur); helpLabel->setText(toolTip); ui->view->setShowToolOptions(false); dialogTool = new Dialog(pattern, 0, this); + if (t == Tool::Midpoint) + { + dialogTool->Build(t); + } + VMainGraphicsScene *scene = qobject_cast(currentScene); SCASSERT(scene != nullptr); @@ -555,6 +570,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool.data(), &DialogTool::SelectedObject); connect(dialogTool.data(), &DialogTool::DialogClosed, this, closeDialogSlot); connect(dialogTool.data(), &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); + connect(ui->view, &VMainGraphicsView::MouseRelease, [this](){EndVisualization(true);}); ui->view->itemClicked(nullptr); } else @@ -578,45 +594,13 @@ template * @param applyDialogSlot function to handle apply in dialog. */ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cursor, const QString &toolTip, - Func closeDialogSlot, Func2 applyDialogSlot) + Func closeDialogSlot, Func2 applyDialogSlot) { if (checked) { - CancelTool(); - emit EnableItemMove(false); - currentTool = lastUsedTool = t; - auto cursorResource = cursor; - if (qApp->devicePixelRatio() >= 2) - { - // Try to load HiDPI versions of the cursors if availible - auto cursorHidpiResource = QString(cursor).replace(".png", "@2x.png"); - if (QFileInfo(cursorResource).exists()) - { - cursorResource = cursorHidpiResource; - } - } - QPixmap pixmap(cursorResource); - QCursor cur(pixmap, 2, 3); - ui->view->setCursor(cur); - ui->view->setShowToolOptions(false); - helpLabel->setText(toolTip); - dialogTool = new Dialog(pattern, NULL_ID, this); + SetToolButton(checked, t, cursor, toolTip, closeDialogSlot); - if (t == Tool::Midpoint) - { - dialogTool->Build(t); - } - - VMainGraphicsScene *scene = qobject_cast(currentScene); - SCASSERT(scene != nullptr); - - connect(scene, &VMainGraphicsScene::ChoosedObject, dialogTool.data(), &DialogTool::ChosenObject); - connect(scene, &VMainGraphicsScene::SelectedObject, dialogTool.data(), &DialogTool::SelectedObject); - connect(dialogTool.data(), &DialogTool::DialogClosed, this, closeDialogSlot); connect(dialogTool.data(), &DialogTool::DialogApplied, this, applyDialogSlot); - connect(dialogTool.data(), &DialogTool::ToolTip, this, &MainWindow::ShowToolTip); - connect(ui->view, &VMainGraphicsView::MouseRelease, [this](){EndVisualization(true);}); - ui->view->itemClicked(nullptr); } else {