From 0399fe3d621f7bacb2b29204f68860986ca78381 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 24 Mar 2019 13:56:59 +0100 Subject: [PATCH 1/8] Merge layers works as expected --- app/app.pro | 9 ++- app/src/actioncommands.cpp | 20 +++++++ app/src/actioncommands.h | 1 + app/src/mainwindow2.cpp | 1 + app/src/mergelayers.cpp | 88 +++++++++++++++++++++++++++ app/src/mergelayers.h | 36 +++++++++++ app/ui/mainwindow2.ui | 9 ++- app/ui/mergelayers.ui | 118 +++++++++++++++++++++++++++++++++++++ 8 files changed, 278 insertions(+), 4 deletions(-) create mode 100644 app/src/mergelayers.cpp create mode 100644 app/src/mergelayers.h create mode 100644 app/ui/mergelayers.ui diff --git a/app/app.pro b/app/app.pro index e92f201f66..c859aa3740 100644 --- a/app/app.pro +++ b/app/app.pro @@ -60,7 +60,8 @@ HEADERS += \ src/spinslider.h \ src/doubleprogressdialog.h \ src/colorslider.h \ - src/checkupdatesdialog.h + src/checkupdatesdialog.h \ + src/mergelayers.h SOURCES += \ src/main.cpp \ @@ -89,7 +90,8 @@ SOURCES += \ src/spinslider.cpp \ src/doubleprogressdialog.cpp \ src/colorslider.cpp \ - src/checkupdatesdialog.cpp + src/checkupdatesdialog.cpp \ + src/mergelayers.cpp FORMS += \ ui/mainwindow2.ui \ @@ -111,7 +113,8 @@ FORMS += \ ui/timelinepage.ui \ ui/filespage.ui \ ui/toolspage.ui \ - ui/toolboxwidget.ui + ui/toolboxwidget.ui \ + ui/mergelayers.ui diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index ebd55f05b9..ead30b159b 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -49,6 +49,7 @@ GNU General Public License for more details. #include "aboutdialog.h" #include "doubleprogressdialog.h" #include "checkupdatesdialog.h" +#include "mergelayers.h" ActionCommands::ActionCommands(QWidget* parent) : QObject(parent) @@ -649,6 +650,25 @@ Status ActionCommands::addNewSoundLayer() return Status::OK; } +Status ActionCommands::mergeLayers() +{ + if (!(mEditor->layers()->currentLayer()->type() == Layer::BITMAP || + mEditor->layers()->currentLayer()->type() == Layer::VECTOR)) + { + QMessageBox::information(nullptr, nullptr, + tr("Only Bitmap and Vector Layers\n" + "can be merged.")); + return Status::NOT_SUPPORTED; + } + + MergeLayers* merge = new MergeLayers(); + if (merge == nullptr) + return Status::FAIL; + merge->initDialog(mEditor); + merge->exec(); + return Status::OK; +} + Status ActionCommands::deleteCurrentLayer() { LayerManager* layerMgr = mEditor->layers(); diff --git a/app/src/actioncommands.h b/app/src/actioncommands.h index 3911ea8975..56cc4a106d 100644 --- a/app/src/actioncommands.h +++ b/app/src/actioncommands.h @@ -72,6 +72,7 @@ class ActionCommands : public QObject Status addNewVectorLayer(); Status addNewCameraLayer(); Status addNewSoundLayer(); + Status mergeLayers(); Status deleteCurrentLayer(); QString nameSuggest(QString s); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 10375dae2c..ef8a2de707 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -268,6 +268,7 @@ void MainWindow2::createMenus() connect(ui->actionNew_Vector_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewVectorLayer); connect(ui->actionNew_Sound_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewSoundLayer); connect(ui->actionNew_Camera_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewCameraLayer); + connect(ui->actionMerge_Layer, &QAction::triggered, mCommands, &ActionCommands::mergeLayers); connect(ui->actionDelete_Current_Layer, &QAction::triggered, mCommands, &ActionCommands::deleteCurrentLayer); //--- View Menu --- diff --git a/app/src/mergelayers.cpp b/app/src/mergelayers.cpp new file mode 100644 index 0000000000..253ad94da9 --- /dev/null +++ b/app/src/mergelayers.cpp @@ -0,0 +1,88 @@ +#include "mergelayers.h" +#include "ui_mergelayers.h" + +#include "layerbitmap.h" +#include "layervector.h" + +MergeLayers::MergeLayers(QWidget *parent) : + QDialog(parent), + ui(new Ui::MergeLayers) +{ + ui->setupUi(this); + connect(ui->cbFromLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); + connect(ui->cbToLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); + connect(ui->btnMerge, &QPushButton::clicked, this, &MergeLayers::mergeLayers); + connect(ui->btnClose, &QPushButton::clicked, this, &MergeLayers::close); +} + +MergeLayers::~MergeLayers() +{ + delete ui; +} + +void MergeLayers::initDialog(Editor *editor) +{ + mEditor = editor; + mLayerType = mEditor->layers()->currentLayer()->type(); + ui->cbFromLayer->clear(); + ui->cbToLayer->clear(); + for (int i = 0; i < mEditor->layers()->count(); i++) + { + if (mEditor->layers()->getLayer(i)->type() == mLayerType) + { + ui->cbFromLayer->addItem(mEditor->layers()->getLayer(i)->name()); + ui->cbToLayer->addItem(mEditor->layers()->getLayer(i)->name()); + } + } + if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) + { + ui->btnMerge->setEnabled(false); + } +} + +void MergeLayers::layerSelectionChanged() +{ + if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) + { + ui->btnMerge->setEnabled(false); + } + else { + ui->btnMerge->setEnabled(true); + } +} + +void MergeLayers::mergeLayers() +{ + if (mLayerType == Layer::BITMAP) + { + mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); + mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); + } + else + { + mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); + mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); + } + + for (int i = mFromLayer->firstKeyFramePosition(); i <= mFromLayer->getMaxKeyFramePosition(); i++) + { + mEditor->scrubTo(i); + if (mFromLayer->keyExists(i)) + { + mEditor->layers()->setCurrentLayer(mFromLayer); + mEditor->copy(); + mEditor->layers()->setCurrentLayer(mToLayer); + if (!mToLayer->keyExists(i)) + mToLayer->addNewKeyFrameAt(i); + mEditor->paste(); + } + } + mEditor->layers()->setCurrentLayer(mFromLayer); + if (ui->cbDeleteLayer->isChecked()) + mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); +} + +void MergeLayers::closeUi() +{ + close(); +} diff --git a/app/src/mergelayers.h b/app/src/mergelayers.h new file mode 100644 index 0000000000..6bee6f5d7c --- /dev/null +++ b/app/src/mergelayers.h @@ -0,0 +1,36 @@ +#ifndef MERGELAYERS_H +#define MERGELAYERS_H + +#include +#include "editor.h" +#include "layermanager.h" + +namespace Ui { +class MergeLayers; +} + +class MergeLayers : public QDialog +{ + Q_OBJECT + +public: + explicit MergeLayers(QWidget *parent = nullptr); + ~MergeLayers(); + + void initDialog(Editor* editor); + +private slots: + void layerSelectionChanged(); + void mergeLayers(); + void closeUi(); + +private: + Ui::MergeLayers *ui; + + Editor* mEditor = nullptr; + Layer* mFromLayer = nullptr; + Layer* mToLayer = nullptr; + int mLayerType; +}; + +#endif // MERGELAYERS_H diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 3eeac3369a..2c33f88238 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 800 - 21 + 20 @@ -211,6 +211,8 @@ + + @@ -974,6 +976,11 @@ Flip Rolling + + + Merge Layers + + diff --git a/app/ui/mergelayers.ui b/app/ui/mergelayers.ui new file mode 100644 index 0000000000..ec52043991 --- /dev/null +++ b/app/ui/mergelayers.ui @@ -0,0 +1,118 @@ + + + MergeLayers + + + + 0 + 0 + 364 + 157 + + + + Merge Layers + + + + + + Merge layers + + + + 2 + + + 4 + + + 4 + + + 4 + + + 4 + + + + + + + Merge Layer... + + + + + + + + + + + + + + ...to Layer + + + + + + + + + + + + Delete layer after merge + + + + + + + Qt::Horizontal + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Merge Layers + + + + + + + Close + + + + + + + + + + + + + From f5c68dd0b8cd8d75e62de29ac7d08eda0971a73c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 30 Mar 2019 17:39:29 +0100 Subject: [PATCH 2/8] Prevent mergerequest when impossible --- app/src/actioncommands.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index ead30b159b..0656231eee 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -661,6 +661,20 @@ Status ActionCommands::mergeLayers() return Status::NOT_SUPPORTED; } + int type = mEditor->layers()->currentLayer()->type(); + int layers = 0; + for (int i = 0; i < mEditor->layers()->count(); i++) + { + if (mEditor->layers()->getLayer(i)->type() == type) + layers++; + } + if (layers < 2) + { + QMessageBox::information(nullptr, tr("Merge not possible"), + tr("Only one layer of that type!")); + return Status::NOT_SUPPORTED; + } + MergeLayers* merge = new MergeLayers(); if (merge == nullptr) return Status::FAIL; From a0ef9865ce5f307475d9a4a9b0ace20978b0e48e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 30 Mar 2019 20:24:13 +0100 Subject: [PATCH 3/8] Moved mergeLayers function to layermanager --- app/src/mergelayers.cpp | 15 +-------------- core_lib/src/managers/layermanager.cpp | 17 +++++++++++++++++ core_lib/src/managers/layermanager.h | 1 + 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/mergelayers.cpp b/app/src/mergelayers.cpp index 253ad94da9..cd5426a2d3 100644 --- a/app/src/mergelayers.cpp +++ b/app/src/mergelayers.cpp @@ -63,20 +63,7 @@ void MergeLayers::mergeLayers() mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); } - - for (int i = mFromLayer->firstKeyFramePosition(); i <= mFromLayer->getMaxKeyFramePosition(); i++) - { - mEditor->scrubTo(i); - if (mFromLayer->keyExists(i)) - { - mEditor->layers()->setCurrentLayer(mFromLayer); - mEditor->copy(); - mEditor->layers()->setCurrentLayer(mToLayer); - if (!mToLayer->keyExists(i)) - mToLayer->addNewKeyFrameAt(i); - mEditor->paste(); - } - } + mEditor->layers()->mergeLayers(mFromLayer, mToLayer); mEditor->layers()->setCurrentLayer(mFromLayer); if (ui->cbDeleteLayer->isChecked()) mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index ac3ea2782d..6cb808c9f8 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -271,6 +271,23 @@ Status LayerManager::deleteLayer(int index) return Status::OK; } +void LayerManager::mergeLayers(Layer *fromLayer, Layer *toLayer) +{ + for (int i = fromLayer->firstKeyFramePosition(); i <= fromLayer->getMaxKeyFramePosition(); i++) + { + editor()->scrubTo(i); + if (fromLayer->keyExists(i)) + { + editor()->layers()->setCurrentLayer(fromLayer); + editor()->copy(); + editor()->layers()->setCurrentLayer(toLayer); + if (!toLayer->keyExists(i)) + toLayer->addNewKeyFrameAt(i); + editor()->paste(); + } + } +} + Status LayerManager::renameLayer(Layer* layer, const QString& newName) { if (newName.isEmpty()) return Status::FAIL; diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index 886818536a..fa3aaac535 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -50,6 +50,7 @@ class LayerManager : public BaseManager int count(); Status deleteLayer(int index); + void mergeLayers(Layer* fromLayer, Layer* toLayer); Status renameLayer(Layer*, const QString& newName); void notifyLayerChanged(Layer*); From e8ca7658863f110cbd1d990a2610c70d6eb5275d Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 4 Apr 2019 21:26:40 +0200 Subject: [PATCH 4/8] WIP delete dialog --- app/app.pro | 9 +- app/src/actioncommands.cpp | 34 ------- app/src/actioncommands.h | 1 - app/src/mainwindow2.cpp | 1 - app/src/mergelayers.cpp | 75 -------------- app/src/mergelayers.h | 36 ------- app/ui/mainwindow2.ui | 2 - app/ui/mergelayers.ui | 118 ----------------------- core_lib/src/interface/timelinecells.cpp | 17 +++- core_lib/src/managers/layermanager.cpp | 2 + 10 files changed, 21 insertions(+), 274 deletions(-) delete mode 100644 app/src/mergelayers.cpp delete mode 100644 app/src/mergelayers.h delete mode 100644 app/ui/mergelayers.ui diff --git a/app/app.pro b/app/app.pro index c859aa3740..e92f201f66 100644 --- a/app/app.pro +++ b/app/app.pro @@ -60,8 +60,7 @@ HEADERS += \ src/spinslider.h \ src/doubleprogressdialog.h \ src/colorslider.h \ - src/checkupdatesdialog.h \ - src/mergelayers.h + src/checkupdatesdialog.h SOURCES += \ src/main.cpp \ @@ -90,8 +89,7 @@ SOURCES += \ src/spinslider.cpp \ src/doubleprogressdialog.cpp \ src/colorslider.cpp \ - src/checkupdatesdialog.cpp \ - src/mergelayers.cpp + src/checkupdatesdialog.cpp FORMS += \ ui/mainwindow2.ui \ @@ -113,8 +111,7 @@ FORMS += \ ui/timelinepage.ui \ ui/filespage.ui \ ui/toolspage.ui \ - ui/toolboxwidget.ui \ - ui/mergelayers.ui + ui/toolboxwidget.ui diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 0656231eee..ebd55f05b9 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -49,7 +49,6 @@ GNU General Public License for more details. #include "aboutdialog.h" #include "doubleprogressdialog.h" #include "checkupdatesdialog.h" -#include "mergelayers.h" ActionCommands::ActionCommands(QWidget* parent) : QObject(parent) @@ -650,39 +649,6 @@ Status ActionCommands::addNewSoundLayer() return Status::OK; } -Status ActionCommands::mergeLayers() -{ - if (!(mEditor->layers()->currentLayer()->type() == Layer::BITMAP || - mEditor->layers()->currentLayer()->type() == Layer::VECTOR)) - { - QMessageBox::information(nullptr, nullptr, - tr("Only Bitmap and Vector Layers\n" - "can be merged.")); - return Status::NOT_SUPPORTED; - } - - int type = mEditor->layers()->currentLayer()->type(); - int layers = 0; - for (int i = 0; i < mEditor->layers()->count(); i++) - { - if (mEditor->layers()->getLayer(i)->type() == type) - layers++; - } - if (layers < 2) - { - QMessageBox::information(nullptr, tr("Merge not possible"), - tr("Only one layer of that type!")); - return Status::NOT_SUPPORTED; - } - - MergeLayers* merge = new MergeLayers(); - if (merge == nullptr) - return Status::FAIL; - merge->initDialog(mEditor); - merge->exec(); - return Status::OK; -} - Status ActionCommands::deleteCurrentLayer() { LayerManager* layerMgr = mEditor->layers(); diff --git a/app/src/actioncommands.h b/app/src/actioncommands.h index 56cc4a106d..3911ea8975 100644 --- a/app/src/actioncommands.h +++ b/app/src/actioncommands.h @@ -72,7 +72,6 @@ class ActionCommands : public QObject Status addNewVectorLayer(); Status addNewCameraLayer(); Status addNewSoundLayer(); - Status mergeLayers(); Status deleteCurrentLayer(); QString nameSuggest(QString s); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index ef8a2de707..10375dae2c 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -268,7 +268,6 @@ void MainWindow2::createMenus() connect(ui->actionNew_Vector_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewVectorLayer); connect(ui->actionNew_Sound_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewSoundLayer); connect(ui->actionNew_Camera_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewCameraLayer); - connect(ui->actionMerge_Layer, &QAction::triggered, mCommands, &ActionCommands::mergeLayers); connect(ui->actionDelete_Current_Layer, &QAction::triggered, mCommands, &ActionCommands::deleteCurrentLayer); //--- View Menu --- diff --git a/app/src/mergelayers.cpp b/app/src/mergelayers.cpp deleted file mode 100644 index cd5426a2d3..0000000000 --- a/app/src/mergelayers.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "mergelayers.h" -#include "ui_mergelayers.h" - -#include "layerbitmap.h" -#include "layervector.h" - -MergeLayers::MergeLayers(QWidget *parent) : - QDialog(parent), - ui(new Ui::MergeLayers) -{ - ui->setupUi(this); - connect(ui->cbFromLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); - connect(ui->cbToLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); - connect(ui->btnMerge, &QPushButton::clicked, this, &MergeLayers::mergeLayers); - connect(ui->btnClose, &QPushButton::clicked, this, &MergeLayers::close); -} - -MergeLayers::~MergeLayers() -{ - delete ui; -} - -void MergeLayers::initDialog(Editor *editor) -{ - mEditor = editor; - mLayerType = mEditor->layers()->currentLayer()->type(); - ui->cbFromLayer->clear(); - ui->cbToLayer->clear(); - for (int i = 0; i < mEditor->layers()->count(); i++) - { - if (mEditor->layers()->getLayer(i)->type() == mLayerType) - { - ui->cbFromLayer->addItem(mEditor->layers()->getLayer(i)->name()); - ui->cbToLayer->addItem(mEditor->layers()->getLayer(i)->name()); - } - } - if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) - { - ui->btnMerge->setEnabled(false); - } -} - -void MergeLayers::layerSelectionChanged() -{ - if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) - { - ui->btnMerge->setEnabled(false); - } - else { - ui->btnMerge->setEnabled(true); - } -} - -void MergeLayers::mergeLayers() -{ - if (mLayerType == Layer::BITMAP) - { - mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); - mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); - } - else - { - mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); - mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); - } - mEditor->layers()->mergeLayers(mFromLayer, mToLayer); - mEditor->layers()->setCurrentLayer(mFromLayer); - if (ui->cbDeleteLayer->isChecked()) - mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); -} - -void MergeLayers::closeUi() -{ - close(); -} diff --git a/app/src/mergelayers.h b/app/src/mergelayers.h deleted file mode 100644 index 6bee6f5d7c..0000000000 --- a/app/src/mergelayers.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MERGELAYERS_H -#define MERGELAYERS_H - -#include -#include "editor.h" -#include "layermanager.h" - -namespace Ui { -class MergeLayers; -} - -class MergeLayers : public QDialog -{ - Q_OBJECT - -public: - explicit MergeLayers(QWidget *parent = nullptr); - ~MergeLayers(); - - void initDialog(Editor* editor); - -private slots: - void layerSelectionChanged(); - void mergeLayers(); - void closeUi(); - -private: - Ui::MergeLayers *ui; - - Editor* mEditor = nullptr; - Layer* mFromLayer = nullptr; - Layer* mToLayer = nullptr; - int mLayerType; -}; - -#endif // MERGELAYERS_H diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 2c33f88238..e82f28ddec 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -211,8 +211,6 @@ - - diff --git a/app/ui/mergelayers.ui b/app/ui/mergelayers.ui deleted file mode 100644 index ec52043991..0000000000 --- a/app/ui/mergelayers.ui +++ /dev/null @@ -1,118 +0,0 @@ - - - MergeLayers - - - - 0 - 0 - 364 - 157 - - - - Merge Layers - - - - - - Merge layers - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - Merge Layer... - - - - - - - - - - - - - - ...to Layer - - - - - - - - - - - - Delete layer after merge - - - - - - - Qt::Horizontal - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Merge Layers - - - - - - - Close - - - - - - - - - - - - - diff --git a/core_lib/src/interface/timelinecells.cpp b/core_lib/src/interface/timelinecells.cpp index dcc9debc5f..fcf666ab3d 100644 --- a/core_lib/src/interface/timelinecells.cpp +++ b/core_lib/src/interface/timelinecells.cpp @@ -20,6 +20,7 @@ GNU General Public License for more details. #include #include #include +#include #include "object.h" #include "editor.h" @@ -491,7 +492,21 @@ void TimeLineCells::mousePressEvent(QMouseEvent* event) } else { - mEditor->layers()->setCurrentLayer(layerNumber); + if (event->button() == Qt::RightButton) + { + // if types dont match... + if (mEditor->layers()->currentLayer()->type() != mEditor->layers()->getLayer(layerNumber)->type()) + { + QMessageBox::information(this, tr("Merge impossible"), + tr("The two layers must be of same type!"), + QMessageBox::Ok); + return; + } + } + else + { + mEditor->layers()->setCurrentLayer(layerNumber); + } } } if (layerNumber == -1) diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 6cb808c9f8..b307ab26be 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -273,6 +273,8 @@ Status LayerManager::deleteLayer(int index) void LayerManager::mergeLayers(Layer *fromLayer, Layer *toLayer) { + if (fromLayer == nullptr || toLayer == nullptr) { return; } + for (int i = fromLayer->firstKeyFramePosition(); i <= fromLayer->getMaxKeyFramePosition(); i++) { editor()->scrubTo(i); From 425b2c27a8d8a93e888c344f3a4bcd8533457e32 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 7 Apr 2019 18:24:25 +0100 Subject: [PATCH 5/8] Context menu works. Delete and merge layer. --- core_lib/src/interface/timelinecells.cpp | 48 +++++++++++++++++------- core_lib/src/interface/timelinecells.h | 4 ++ core_lib/src/managers/layermanager.cpp | 1 + 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/core_lib/src/interface/timelinecells.cpp b/core_lib/src/interface/timelinecells.cpp index fcf666ab3d..3f67534d81 100644 --- a/core_lib/src/interface/timelinecells.cpp +++ b/core_lib/src/interface/timelinecells.cpp @@ -21,6 +21,7 @@ GNU General Public License for more details. #include #include #include +#include #include "object.h" #include "editor.h" @@ -165,11 +166,42 @@ void TimeLineCells::updateContent() update(); } - bool TimeLineCells::didDetatchLayer() { return abs(getMouseMoveY()) > mLayerDetatchThreshold; } +void TimeLineCells::showContextMenu(QPoint pos) +{ + pos = this->mapToGlobal(pos); + int index = mEditor->layers()->currentLayerIndex(); + + QMenu* menu = new QMenu(); + if (mEditor->layers()->currentLayerIndex() > 0 && + mEditor->layers()->currentLayer()->type() == Layer::BITMAP && + mEditor->layers()->getLayer(index)->type() == mEditor->layers()->getLayer(index-1)->type()) + { + menu->addAction(tr("Merge onto Layer: %1").arg(mEditor->layers()->getLayer(index-1)->name()), this, &TimeLineCells::mergeLayers); + menu->addSeparator(); + } + menu->addAction(tr("Delete Layer: %1").arg(mEditor->layers()->currentLayer()->name()), this, &TimeLineCells::deleteLayer); + + menu->exec(pos); +} + +void TimeLineCells::deleteLayer() +{ + mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); +} + +void TimeLineCells::mergeLayers() +{ + int index = mEditor->layers()->currentLayerIndex(); + if (mEditor->layers()->getLayer(index)->type() == mEditor->layers()->getLayer(index-1)->type()) + { + mEditor->layers()->mergeLayers(mEditor->layers()->currentLayer(), mEditor->layers()->getLayer(index-1)); + } +} + void TimeLineCells::drawContent() { if (mCache == nullptr) @@ -492,20 +524,10 @@ void TimeLineCells::mousePressEvent(QMouseEvent* event) } else { + mEditor->layers()->setCurrentLayer(layerNumber); if (event->button() == Qt::RightButton) { - // if types dont match... - if (mEditor->layers()->currentLayer()->type() != mEditor->layers()->getLayer(layerNumber)->type()) - { - QMessageBox::information(this, tr("Merge impossible"), - tr("The two layers must be of same type!"), - QMessageBox::Ok); - return; - } - } - else - { - mEditor->layers()->setCurrentLayer(layerNumber); + showContextMenu(event->pos()); } } } diff --git a/core_lib/src/interface/timelinecells.h b/core_lib/src/interface/timelinecells.h index 163adb006d..40307f8030 100644 --- a/core_lib/src/interface/timelinecells.h +++ b/core_lib/src/interface/timelinecells.h @@ -63,6 +63,10 @@ class TimeLineCells : public QWidget void paintLayerGutter(QPainter& painter); bool didDetatchLayer(); + void showContextMenu(QPoint pos); + void deleteLayer(); + void mergeLayers(); + Q_SIGNALS: void mouseMovedY(int); void lengthChanged(int); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index b307ab26be..0e77dc0022 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -288,6 +288,7 @@ void LayerManager::mergeLayers(Layer *fromLayer, Layer *toLayer) editor()->paste(); } } + deleteLayer(getIndex(fromLayer)); } Status LayerManager::renameLayer(Layer* layer, const QString& newName) From 5313498b73a9d6f3e4a0cfc3988535bb89b64dc1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 8 Apr 2019 07:41:53 +0100 Subject: [PATCH 6/8] Removed merge dialog --- app/app.pro | 9 +-- app/src/actioncommands.cpp | 34 ----------- app/src/actioncommands.h | 1 - app/src/mainwindow2.cpp | 1 - app/src/mergelayers.cpp | 75 ----------------------- app/src/mergelayers.h | 36 ----------- app/ui/mainwindow2.ui | 4 +- app/ui/mergelayers.ui | 118 ------------------------------------- 8 files changed, 4 insertions(+), 274 deletions(-) delete mode 100644 app/src/mergelayers.cpp delete mode 100644 app/src/mergelayers.h delete mode 100644 app/ui/mergelayers.ui diff --git a/app/app.pro b/app/app.pro index c859aa3740..e92f201f66 100644 --- a/app/app.pro +++ b/app/app.pro @@ -60,8 +60,7 @@ HEADERS += \ src/spinslider.h \ src/doubleprogressdialog.h \ src/colorslider.h \ - src/checkupdatesdialog.h \ - src/mergelayers.h + src/checkupdatesdialog.h SOURCES += \ src/main.cpp \ @@ -90,8 +89,7 @@ SOURCES += \ src/spinslider.cpp \ src/doubleprogressdialog.cpp \ src/colorslider.cpp \ - src/checkupdatesdialog.cpp \ - src/mergelayers.cpp + src/checkupdatesdialog.cpp FORMS += \ ui/mainwindow2.ui \ @@ -113,8 +111,7 @@ FORMS += \ ui/timelinepage.ui \ ui/filespage.ui \ ui/toolspage.ui \ - ui/toolboxwidget.ui \ - ui/mergelayers.ui + ui/toolboxwidget.ui diff --git a/app/src/actioncommands.cpp b/app/src/actioncommands.cpp index 0656231eee..ebd55f05b9 100644 --- a/app/src/actioncommands.cpp +++ b/app/src/actioncommands.cpp @@ -49,7 +49,6 @@ GNU General Public License for more details. #include "aboutdialog.h" #include "doubleprogressdialog.h" #include "checkupdatesdialog.h" -#include "mergelayers.h" ActionCommands::ActionCommands(QWidget* parent) : QObject(parent) @@ -650,39 +649,6 @@ Status ActionCommands::addNewSoundLayer() return Status::OK; } -Status ActionCommands::mergeLayers() -{ - if (!(mEditor->layers()->currentLayer()->type() == Layer::BITMAP || - mEditor->layers()->currentLayer()->type() == Layer::VECTOR)) - { - QMessageBox::information(nullptr, nullptr, - tr("Only Bitmap and Vector Layers\n" - "can be merged.")); - return Status::NOT_SUPPORTED; - } - - int type = mEditor->layers()->currentLayer()->type(); - int layers = 0; - for (int i = 0; i < mEditor->layers()->count(); i++) - { - if (mEditor->layers()->getLayer(i)->type() == type) - layers++; - } - if (layers < 2) - { - QMessageBox::information(nullptr, tr("Merge not possible"), - tr("Only one layer of that type!")); - return Status::NOT_SUPPORTED; - } - - MergeLayers* merge = new MergeLayers(); - if (merge == nullptr) - return Status::FAIL; - merge->initDialog(mEditor); - merge->exec(); - return Status::OK; -} - Status ActionCommands::deleteCurrentLayer() { LayerManager* layerMgr = mEditor->layers(); diff --git a/app/src/actioncommands.h b/app/src/actioncommands.h index 56cc4a106d..3911ea8975 100644 --- a/app/src/actioncommands.h +++ b/app/src/actioncommands.h @@ -72,7 +72,6 @@ class ActionCommands : public QObject Status addNewVectorLayer(); Status addNewCameraLayer(); Status addNewSoundLayer(); - Status mergeLayers(); Status deleteCurrentLayer(); QString nameSuggest(QString s); diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index ef8a2de707..10375dae2c 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -268,7 +268,6 @@ void MainWindow2::createMenus() connect(ui->actionNew_Vector_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewVectorLayer); connect(ui->actionNew_Sound_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewSoundLayer); connect(ui->actionNew_Camera_Layer, &QAction::triggered, mCommands, &ActionCommands::addNewCameraLayer); - connect(ui->actionMerge_Layer, &QAction::triggered, mCommands, &ActionCommands::mergeLayers); connect(ui->actionDelete_Current_Layer, &QAction::triggered, mCommands, &ActionCommands::deleteCurrentLayer); //--- View Menu --- diff --git a/app/src/mergelayers.cpp b/app/src/mergelayers.cpp deleted file mode 100644 index cd5426a2d3..0000000000 --- a/app/src/mergelayers.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "mergelayers.h" -#include "ui_mergelayers.h" - -#include "layerbitmap.h" -#include "layervector.h" - -MergeLayers::MergeLayers(QWidget *parent) : - QDialog(parent), - ui(new Ui::MergeLayers) -{ - ui->setupUi(this); - connect(ui->cbFromLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); - connect(ui->cbToLayer, QOverload::of(&QComboBox::currentIndexChanged), this, &MergeLayers::layerSelectionChanged); - connect(ui->btnMerge, &QPushButton::clicked, this, &MergeLayers::mergeLayers); - connect(ui->btnClose, &QPushButton::clicked, this, &MergeLayers::close); -} - -MergeLayers::~MergeLayers() -{ - delete ui; -} - -void MergeLayers::initDialog(Editor *editor) -{ - mEditor = editor; - mLayerType = mEditor->layers()->currentLayer()->type(); - ui->cbFromLayer->clear(); - ui->cbToLayer->clear(); - for (int i = 0; i < mEditor->layers()->count(); i++) - { - if (mEditor->layers()->getLayer(i)->type() == mLayerType) - { - ui->cbFromLayer->addItem(mEditor->layers()->getLayer(i)->name()); - ui->cbToLayer->addItem(mEditor->layers()->getLayer(i)->name()); - } - } - if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) - { - ui->btnMerge->setEnabled(false); - } -} - -void MergeLayers::layerSelectionChanged() -{ - if (ui->cbFromLayer->currentText() == ui->cbToLayer->currentText()) - { - ui->btnMerge->setEnabled(false); - } - else { - ui->btnMerge->setEnabled(true); - } -} - -void MergeLayers::mergeLayers() -{ - if (mLayerType == Layer::BITMAP) - { - mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); - mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); - } - else - { - mFromLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbFromLayer->currentText())); - mToLayer = static_cast(mEditor->layers()->findLayerByName(ui->cbToLayer->currentText())); - } - mEditor->layers()->mergeLayers(mFromLayer, mToLayer); - mEditor->layers()->setCurrentLayer(mFromLayer); - if (ui->cbDeleteLayer->isChecked()) - mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); -} - -void MergeLayers::closeUi() -{ - close(); -} diff --git a/app/src/mergelayers.h b/app/src/mergelayers.h deleted file mode 100644 index 6bee6f5d7c..0000000000 --- a/app/src/mergelayers.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MERGELAYERS_H -#define MERGELAYERS_H - -#include -#include "editor.h" -#include "layermanager.h" - -namespace Ui { -class MergeLayers; -} - -class MergeLayers : public QDialog -{ - Q_OBJECT - -public: - explicit MergeLayers(QWidget *parent = nullptr); - ~MergeLayers(); - - void initDialog(Editor* editor); - -private slots: - void layerSelectionChanged(); - void mergeLayers(); - void closeUi(); - -private: - Ui::MergeLayers *ui; - - Editor* mEditor = nullptr; - Layer* mFromLayer = nullptr; - Layer* mToLayer = nullptr; - int mLayerType; -}; - -#endif // MERGELAYERS_H diff --git a/app/ui/mainwindow2.ui b/app/ui/mainwindow2.ui index 2c33f88238..3354d8400a 100644 --- a/app/ui/mainwindow2.ui +++ b/app/ui/mainwindow2.ui @@ -49,7 +49,7 @@ 0 0 800 - 20 + 22 @@ -211,8 +211,6 @@ - - diff --git a/app/ui/mergelayers.ui b/app/ui/mergelayers.ui deleted file mode 100644 index ec52043991..0000000000 --- a/app/ui/mergelayers.ui +++ /dev/null @@ -1,118 +0,0 @@ - - - MergeLayers - - - - 0 - 0 - 364 - 157 - - - - Merge Layers - - - - - - Merge layers - - - - 2 - - - 4 - - - 4 - - - 4 - - - 4 - - - - - - - Merge Layer... - - - - - - - - - - - - - - ...to Layer - - - - - - - - - - - - Delete layer after merge - - - - - - - Qt::Horizontal - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Merge Layers - - - - - - - Close - - - - - - - - - - - - - From 2e8b8e2853fbe901f58373facc75bc3834a2d96e Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 20 Jul 2019 08:45:48 +0200 Subject: [PATCH 7/8] Duplicate layer added to cotext menu --- core_lib/src/interface/timelinecells.cpp | 12 ++++++++++++ core_lib/src/interface/timelinecells.h | 1 + core_lib/src/managers/layermanager.cpp | 19 +++++++++++++++++++ core_lib/src/managers/layermanager.h | 1 + 4 files changed, 33 insertions(+) diff --git a/core_lib/src/interface/timelinecells.cpp b/core_lib/src/interface/timelinecells.cpp index 3f67534d81..337797ba36 100644 --- a/core_lib/src/interface/timelinecells.cpp +++ b/core_lib/src/interface/timelinecells.cpp @@ -183,6 +183,11 @@ void TimeLineCells::showContextMenu(QPoint pos) menu->addAction(tr("Merge onto Layer: %1").arg(mEditor->layers()->getLayer(index-1)->name()), this, &TimeLineCells::mergeLayers); menu->addSeparator(); } + + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + { + menu->addAction(tr("Duplicate Layer: %1").arg(mEditor->layers()->currentLayer()->name()), this, &TimeLineCells::duplicateLayer); + } menu->addAction(tr("Delete Layer: %1").arg(mEditor->layers()->currentLayer()->name()), this, &TimeLineCells::deleteLayer); menu->exec(pos); @@ -193,6 +198,13 @@ void TimeLineCells::deleteLayer() mEditor->layers()->deleteLayer(mEditor->layers()->currentLayerIndex()); } +void TimeLineCells::duplicateLayer() +{ + QString newLayerName = mEditor->layers()->currentLayer()->name() + "_copy"; + mEditor->layers()->createBitmapLayer(newLayerName); + mEditor->layers()->duplicateLayer(mEditor->layers()->currentLayer(), mEditor->layers()->findLayerByName(newLayerName)); +} + void TimeLineCells::mergeLayers() { int index = mEditor->layers()->currentLayerIndex(); diff --git a/core_lib/src/interface/timelinecells.h b/core_lib/src/interface/timelinecells.h index 40307f8030..466a5ac9f0 100644 --- a/core_lib/src/interface/timelinecells.h +++ b/core_lib/src/interface/timelinecells.h @@ -65,6 +65,7 @@ class TimeLineCells : public QWidget void showContextMenu(QPoint pos); void deleteLayer(); + void duplicateLayer(); void mergeLayers(); Q_SIGNALS: diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 0e77dc0022..c39ab77b0f 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -271,6 +271,25 @@ Status LayerManager::deleteLayer(int index) return Status::OK; } +void LayerManager::duplicateLayer(Layer *fromLayer, Layer *toLayer) +{ + if (fromLayer == nullptr || toLayer == nullptr) { return; } + + for (int i = fromLayer->firstKeyFramePosition(); i <= fromLayer->getMaxKeyFramePosition(); i++) + { + editor()->scrubTo(i); + if (fromLayer->keyExists(i)) + { + editor()->layers()->setCurrentLayer(fromLayer); + editor()->copy(); + editor()->layers()->setCurrentLayer(toLayer); + if (!toLayer->keyExists(i)) + toLayer->addNewKeyFrameAt(i); + editor()->paste(); + } + } +} + void LayerManager::mergeLayers(Layer *fromLayer, Layer *toLayer) { if (fromLayer == nullptr || toLayer == nullptr) { return; } diff --git a/core_lib/src/managers/layermanager.h b/core_lib/src/managers/layermanager.h index fa3aaac535..501b5557f2 100644 --- a/core_lib/src/managers/layermanager.h +++ b/core_lib/src/managers/layermanager.h @@ -50,6 +50,7 @@ class LayerManager : public BaseManager int count(); Status deleteLayer(int index); + void duplicateLayer(Layer* fromLayer, Layer* toLayer); void mergeLayers(Layer* fromLayer, Layer* toLayer); Status renameLayer(Layer*, const QString& newName); void notifyLayerChanged(Layer*); From 80b067804ef7256c2b134df9241cd33ceebe2bf3 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 19 Dec 2019 19:18:35 +0100 Subject: [PATCH 8/8] Added support for merging visble bitmap layers --- core_lib/src/interface/timelinecells.cpp | 47 ++++++++++++++++++++++-- core_lib/src/interface/timelinecells.h | 3 +- core_lib/src/managers/layermanager.cpp | 1 - 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/core_lib/src/interface/timelinecells.cpp b/core_lib/src/interface/timelinecells.cpp index 150d8169be..d2b7e7fd34 100644 --- a/core_lib/src/interface/timelinecells.cpp +++ b/core_lib/src/interface/timelinecells.cpp @@ -174,13 +174,24 @@ void TimeLineCells::showContextMenu(QPoint pos) { pos = this->mapToGlobal(pos); int index = mEditor->layers()->currentLayerIndex(); - + bool mergeInMenu = false; QMenu* menu = new QMenu(); if (mEditor->layers()->currentLayerIndex() > 0 && mEditor->layers()->currentLayer()->type() == Layer::BITMAP && mEditor->layers()->getLayer(index)->type() == mEditor->layers()->getLayer(index-1)->type()) { - menu->addAction(tr("Merge onto Layer: %1").arg(mEditor->layers()->getLayer(index-1)->name()), this, &TimeLineCells::mergeLayers); + menu->addAction(tr("Merge onto Layer: %1").arg(mEditor->layers()->getLayer(index-1)->name()), this, &TimeLineCells::mergeLayerDown); + mergeInMenu = true; + } + + if (mEditor->layers()->currentLayer()->type() == Layer::BITMAP) + { + menu->addAction(tr("Merge visible bitmap layers"), this, &TimeLineCells::mergeVisibleLayers); + mergeInMenu = true; + } + + if (mergeInMenu) + { menu->addSeparator(); } @@ -205,13 +216,43 @@ void TimeLineCells::duplicateLayer() mEditor->layers()->duplicateLayer(mEditor->layers()->currentLayer(), mEditor->layers()->findLayerByName(newLayerName)); } -void TimeLineCells::mergeLayers() +void TimeLineCells::mergeLayerDown() { int index = mEditor->layers()->currentLayerIndex(); if (mEditor->layers()->getLayer(index)->type() == mEditor->layers()->getLayer(index-1)->type()) { mEditor->layers()->mergeLayers(mEditor->layers()->currentLayer(), mEditor->layers()->getLayer(index-1)); } + mEditor->layers()->deleteLayer(index); +} + +void TimeLineCells::mergeVisibleLayers() +{ + QList indexes; + for (int i = 0; i < mEditor->layers()->count(); i++) + { + if (mEditor->layers()->getLayer(i)->type() == Layer::BITMAP && + mEditor->layers()->getLayer(i)->visible()) + indexes.append(i); + } + + if (indexes.size() < 2) { return; } + + int count = indexes.size(); + while (count > 1) + { + mEditor->layers()->mergeLayers(mEditor->layers()->getLayer(indexes.at(count - 1)), + mEditor->layers()->getLayer(indexes.at(count - 2))); + count--; + } + + indexes.removeFirst(); + + while (!indexes.empty()) + { + mEditor->layers()->deleteLayer(indexes.last()); + indexes.removeLast(); + } } void TimeLineCells::drawContent() diff --git a/core_lib/src/interface/timelinecells.h b/core_lib/src/interface/timelinecells.h index dcaed980e2..3b1f6bef26 100644 --- a/core_lib/src/interface/timelinecells.h +++ b/core_lib/src/interface/timelinecells.h @@ -66,7 +66,8 @@ class TimeLineCells : public QWidget void showContextMenu(QPoint pos); void deleteLayer(); void duplicateLayer(); - void mergeLayers(); + void mergeLayerDown(); + void mergeVisibleLayers(); Q_SIGNALS: void mouseMovedY(int); diff --git a/core_lib/src/managers/layermanager.cpp b/core_lib/src/managers/layermanager.cpp index 391f4431ae..fccf943f32 100644 --- a/core_lib/src/managers/layermanager.cpp +++ b/core_lib/src/managers/layermanager.cpp @@ -341,7 +341,6 @@ void LayerManager::mergeLayers(Layer *fromLayer, Layer *toLayer) editor()->paste(); } } - deleteLayer(getIndex(fromLayer)); } Status LayerManager::renameLayer(Layer* layer, const QString& newName)