From b3b60054ddc37d40b79cc59db5b3942003e58152 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Mon, 23 Sep 2019 22:17:01 +0200 Subject: [PATCH 1/8] Items are now draggable within listview --- app/src/colorpalettewidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/colorpalettewidget.cpp b/app/src/colorpalettewidget.cpp index 0c54fe349..6c2d93bcd 100644 --- a/app/src/colorpalettewidget.cpp +++ b/app/src/colorpalettewidget.cpp @@ -222,7 +222,7 @@ void ColorPaletteWidget::refreshColorList() colourItem->setIcon(swatchIcon); swatchPainter.end(); - colourItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); + colourItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDragEnabled); ui->colorListWidget->addItem(colourItem); } @@ -320,7 +320,7 @@ void ColorPaletteWidget::palettePreferences() void ColorPaletteWidget::setListMode() { ui->colorListWidget->setViewMode(QListView::ListMode); - ui->colorListWidget->setMovement(QListView::Static); + ui->colorListWidget->setDragDropMode(QAbstractItemView::InternalMove); ui->colorListWidget->setGridSize(QSize(-1, -1)); updateUI(); From c69ac354cb9559fcd8fd3490d7b510b6b673ff82 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sat, 28 Sep 2019 11:38:33 +0200 Subject: [PATCH 2/8] Colors update when dragged. Only one swatch at a time. --- app/src/colorpalettewidget.cpp | 67 ++++++++++++++++++++ app/src/colorpalettewidget.h | 3 +- core_lib/src/graphics/vector/vectorimage.cpp | 12 ++++ core_lib/src/graphics/vector/vectorimage.h | 1 + core_lib/src/interface/scribblearea.cpp | 2 +- core_lib/src/structure/layervector.cpp | 8 +++ core_lib/src/structure/layervector.h | 1 + core_lib/src/structure/object.cpp | 19 ++++++ core_lib/src/structure/object.h | 2 + 9 files changed, 113 insertions(+), 2 deletions(-) diff --git a/app/src/colorpalettewidget.cpp b/app/src/colorpalettewidget.cpp index 6c2d93bcd..4aed933b8 100644 --- a/app/src/colorpalettewidget.cpp +++ b/app/src/colorpalettewidget.cpp @@ -31,6 +31,7 @@ GNU General Public License for more details. #include #include #include +#include // Project #include "colourref.h" @@ -80,6 +81,8 @@ void ColorPaletteWidget::initUI() palettePreferences(); connect(ui->colorListWidget, &QListWidget::itemClicked, this, &ColorPaletteWidget::clickColorListItem); + connect(ui->colorListWidget, &QListWidget::itemSelectionChanged, this, &ColorPaletteWidget::onItemSelectionChanged); + connect(ui->colorListWidget->model(), &QAbstractItemModel::rowsMoved, this, &ColorPaletteWidget::onRowsMoved); connect(ui->colorListWidget, &QListWidget::itemDoubleClicked, this, &ColorPaletteWidget::changeColourName); connect(ui->colorListWidget, &QListWidget::itemChanged, this, &ColorPaletteWidget::onItemChanged); @@ -262,6 +265,70 @@ void ColorPaletteWidget::onItemChanged(QListWidgetItem* item) editor()->object()->renameColour(index, newColorName); } +void ColorPaletteWidget::onItemSelectionChanged() +{ + if (ui->colorListWidget->viewMode() == QListWidget::IconMode) { return; } + // you can only drag one swatch at a time... + if (ui->colorListWidget->selectedItems().size() == 1) + ui->colorListWidget->setDragDropMode(QAbstractItemView::InternalMove); + else + ui->colorListWidget->setDragDropMode(QAbstractItemView::NoDragDrop); +} + +void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) +{ + Q_UNUSED(parent) + Q_UNUSED(destination) + Q_UNUSED(end) + + /* + * An error in the signal rowsMoved gives a row-value that is + * 1 higher than it should be, when dragged downwards. Dragging + * upwards yields no erronous values. + */ + + int startIndex, endIndex; + if (start < row) + { + row -= 1; // TODO: follow this bug, and remove if fixed later... + if (start == row) { return; } + + startIndex = start; + endIndex = row; + + editor()->object()->movePaletteColor(startIndex, endIndex); + + editor()->object()->addColour(editor()->object()->getColour(startIndex)); + editor()->object()->moveVectorColor(startIndex, editor()->object()->getColourCount() - 1); + for (int i = startIndex; i < endIndex; i++) + { + editor()->object()->moveVectorColor(i + 1, i); + } + editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); + editor()->object()->removeColour(editor()->object()->getColourCount() - 1); + } + else + { + if (start == row) { return; } + + startIndex = start; + endIndex = row; + + editor()->object()->movePaletteColor(startIndex, endIndex); + + editor()->object()->addColour(editor()->object()->getColour(startIndex)); + editor()->object()->moveVectorColor(startIndex, editor()->object()->getColourCount() - 1); + for (int i = startIndex; i > endIndex; i--) + { + editor()->object()->moveVectorColor(i - 1, i); + } + editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); + editor()->object()->removeColour(editor()->object()->getColourCount() - 1); + } + + refreshColorList(); +} + void ColorPaletteWidget::clickColorListItem(QListWidgetItem* currentItem) { auto modifiers = qApp->keyboardModifiers(); diff --git a/app/src/colorpalettewidget.h b/app/src/colorpalettewidget.h index 8d074d052..1961b5d86 100644 --- a/app/src/colorpalettewidget.h +++ b/app/src/colorpalettewidget.h @@ -35,7 +35,6 @@ namespace Ui class ColorPalette; } - class ColorPaletteWidget : public BaseDockWidget { Q_OBJECT @@ -67,6 +66,8 @@ private slots: void clickColorListItem(QListWidgetItem*); void changeColourName(QListWidgetItem*); void onItemChanged(QListWidgetItem* item); + void onItemSelectionChanged(); + void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); void clickAddColorButton(); void clickColorDialogButton(); void clickRemoveColorButton(); diff --git a/core_lib/src/graphics/vector/vectorimage.cpp b/core_lib/src/graphics/vector/vectorimage.cpp index a66648d5c..5ab3fc677 100644 --- a/core_lib/src/graphics/vector/vectorimage.cpp +++ b/core_lib/src/graphics/vector/vectorimage.cpp @@ -1111,6 +1111,18 @@ void VectorImage::removeColour(int index) } } +void VectorImage::moveColor(int start, int end) +{ + for(int i=0; i< mArea.size(); i++) + { + if (mArea[i].getColourNumber() == start) mArea[i].setColourNumber(end); + } + for(int i=0; i< mCurves.size(); i++) + { + if (mCurves[i].getColourNumber() == start) mCurves[i].setColourNumber(end); + } +} + /** * @brief VectorImage::paintImage * @param painter: QPainter& diff --git a/core_lib/src/graphics/vector/vectorimage.h b/core_lib/src/graphics/vector/vectorimage.h index 7ec14be6e..c9a244c7f 100644 --- a/core_lib/src/graphics/vector/vectorimage.h +++ b/core_lib/src/graphics/vector/vectorimage.h @@ -86,6 +86,7 @@ class VectorImage : public KeyFrame int getColourNumber(QPointF point); bool usesColour(int index); void removeColour(int index); + void moveColor(int start, int end); void paintImage(QPainter& painter, bool simplified, bool showThinCurves, bool antialiasing); void outputImage(QImage* image, QTransform myView, bool simplified, bool showThinCurves, bool antialiasing); // uses paintImage diff --git a/core_lib/src/interface/scribblearea.cpp b/core_lib/src/interface/scribblearea.cpp index daa4dd758..e0b140a7f 100644 --- a/core_lib/src/interface/scribblearea.cpp +++ b/core_lib/src/interface/scribblearea.cpp @@ -1557,7 +1557,7 @@ void ScribbleArea::setPrevTool() void ScribbleArea::paletteColorChanged(QColor color) { - Q_UNUSED(color); + Q_UNUSED(color) updateAllVectorLayersAtCurrentFrame(); } diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index 7df584e9e..0c5d2b12f 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -50,6 +50,14 @@ void LayerVector::removeColour(int colorIndex) }); } +void LayerVector::moveColor(int start, int end) +{ + foreachKeyFrame( [=]( KeyFrame* pKeyFrame ) + { + auto pVecImage = static_cast< VectorImage* >( pKeyFrame ); + pVecImage->moveColor(start, end ); + } );} + void LayerVector::loadImageAtFrame(QString path, int frameNumber) { if (keyExists(frameNumber)) diff --git a/core_lib/src/structure/layervector.h b/core_lib/src/structure/layervector.h index 0779fcf55..a7300426e 100644 --- a/core_lib/src/structure/layervector.h +++ b/core_lib/src/structure/layervector.h @@ -41,6 +41,7 @@ class LayerVector : public Layer bool usesColour(int index); void removeColour(int index); + void moveColor(int start, int end); protected: Status saveKeyFrameFile(KeyFrame*, QString path) override; diff --git a/core_lib/src/structure/object.cpp b/core_lib/src/structure/object.cpp index 74733583c..87acc4472 100644 --- a/core_lib/src/structure/object.cpp +++ b/core_lib/src/structure/object.cpp @@ -308,6 +308,25 @@ void Object::addColour(QColor colour) addColour(ColourRef(colour, "Colour " + QString::number(mPalette.size()))); } +void Object::movePaletteColor(int start, int end) +{ + mPalette.move(start, end); +} + +void Object::moveVectorColor(int start, int end) +{ + // movePaletteColor _must_ be made before calling this function! + + for (int i = 0; i < getLayerCount(); i++) + { + Layer* layer = getLayer(i); + if (layer->type() == Layer::VECTOR) + { + static_cast(layer)->moveColor(start, end); + } + } +} + void Object::addColourAtIndex(int index, ColourRef newColour) { mPalette.insert(index, newColour); diff --git a/core_lib/src/structure/object.h b/core_lib/src/structure/object.h index 22070968a..706ccf030 100644 --- a/core_lib/src/structure/object.h +++ b/core_lib/src/structure/object.h @@ -87,6 +87,8 @@ class Object : public QObject void setColour(int index, QColor newColour); void setColourRef(int index, ColourRef newColourRef); void addColour(QColor); + void movePaletteColor(int start, int end); + void moveVectorColor(int start, int end); void addColour(ColourRef newColour) { mPalette.append(newColour); } void addColourAtIndex(int index, ColourRef newColour); From 8614e0fc01cc1a38b2e6ff42067bf97b048afc6c Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Wed, 2 Oct 2019 22:36:40 +0200 Subject: [PATCH 3/8] Removed restriction of one layer only. --- app/src/colorpalettewidget.cpp | 23 +++-------------------- app/src/colorpalettewidget.h | 1 - 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/app/src/colorpalettewidget.cpp b/app/src/colorpalettewidget.cpp index 4aed933b8..d28d8e27e 100644 --- a/app/src/colorpalettewidget.cpp +++ b/app/src/colorpalettewidget.cpp @@ -81,7 +81,6 @@ void ColorPaletteWidget::initUI() palettePreferences(); connect(ui->colorListWidget, &QListWidget::itemClicked, this, &ColorPaletteWidget::clickColorListItem); - connect(ui->colorListWidget, &QListWidget::itemSelectionChanged, this, &ColorPaletteWidget::onItemSelectionChanged); connect(ui->colorListWidget->model(), &QAbstractItemModel::rowsMoved, this, &ColorPaletteWidget::onRowsMoved); connect(ui->colorListWidget, &QListWidget::itemDoubleClicked, this, &ColorPaletteWidget::changeColourName); @@ -265,32 +264,16 @@ void ColorPaletteWidget::onItemChanged(QListWidgetItem* item) editor()->object()->renameColour(index, newColorName); } -void ColorPaletteWidget::onItemSelectionChanged() -{ - if (ui->colorListWidget->viewMode() == QListWidget::IconMode) { return; } - // you can only drag one swatch at a time... - if (ui->colorListWidget->selectedItems().size() == 1) - ui->colorListWidget->setDragDropMode(QAbstractItemView::InternalMove); - else - ui->colorListWidget->setDragDropMode(QAbstractItemView::NoDragDrop); -} - void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) { Q_UNUSED(parent) Q_UNUSED(destination) Q_UNUSED(end) - /* - * An error in the signal rowsMoved gives a row-value that is - * 1 higher than it should be, when dragged downwards. Dragging - * upwards yields no erronous values. - */ - int startIndex, endIndex; if (start < row) { - row -= 1; // TODO: follow this bug, and remove if fixed later... + row -= 1; // TODO: Is this a bug? if (start == row) { return; } startIndex = start; @@ -305,7 +288,6 @@ void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int e editor()->object()->moveVectorColor(i + 1, i); } editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); - editor()->object()->removeColour(editor()->object()->getColourCount() - 1); } else { @@ -323,9 +305,10 @@ void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int e editor()->object()->moveVectorColor(i - 1, i); } editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); - editor()->object()->removeColour(editor()->object()->getColourCount() - 1); } + editor()->object()->removeColour(editor()->object()->getColourCount() - 1); + refreshColorList(); } diff --git a/app/src/colorpalettewidget.h b/app/src/colorpalettewidget.h index 1961b5d86..a6300e9b7 100644 --- a/app/src/colorpalettewidget.h +++ b/app/src/colorpalettewidget.h @@ -66,7 +66,6 @@ private slots: void clickColorListItem(QListWidgetItem*); void changeColourName(QListWidgetItem*); void onItemChanged(QListWidgetItem* item); - void onItemSelectionChanged(); void onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row); void clickAddColorButton(); void clickColorDialogButton(); From 4dcce609d4e821fc4832d038b9175694803fa53d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Oct 2019 19:42:15 +0200 Subject: [PATCH 4/8] Update core_lib/src/structure/layervector.cpp Moving close bracket Co-Authored-By: Oliver Stevns --- core_lib/src/structure/layervector.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index 0c5d2b12f..f1f340080 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -56,7 +56,8 @@ void LayerVector::moveColor(int start, int end) { auto pVecImage = static_cast< VectorImage* >( pKeyFrame ); pVecImage->moveColor(start, end ); - } );} + }); +} void LayerVector::loadImageAtFrame(QString path, int frameNumber) { From 8bdc3183325c48b58f212aad45f92e11d56a0f3a Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Oct 2019 19:43:07 +0200 Subject: [PATCH 5/8] Update core_lib/src/structure/layervector.cpp Keeping code guidelines Co-Authored-By: Oliver Stevns --- core_lib/src/structure/layervector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index f1f340080..d99489208 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -52,7 +52,7 @@ void LayerVector::removeColour(int colorIndex) void LayerVector::moveColor(int start, int end) { - foreachKeyFrame( [=]( KeyFrame* pKeyFrame ) + foreachKeyFrame( [=] (KeyFrame* pKeyFrame) { auto pVecImage = static_cast< VectorImage* >( pKeyFrame ); pVecImage->moveColor(start, end ); From 1f88cce67e72fdf9679d12cc0192619a7d126f27 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 3 Oct 2019 19:43:37 +0200 Subject: [PATCH 6/8] Update core_lib/src/structure/layervector.cpp Keeping coding guidelines Co-Authored-By: Oliver Stevns --- core_lib/src/structure/layervector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index d99489208..b1e2cfb07 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -54,7 +54,7 @@ void LayerVector::moveColor(int start, int end) { foreachKeyFrame( [=] (KeyFrame* pKeyFrame) { - auto pVecImage = static_cast< VectorImage* >( pKeyFrame ); + auto pVecImage = static_cast(pKeyFrame); pVecImage->moveColor(start, end ); }); } From 9a261887b5bd8775599814363d624b2f683318d1 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Thu, 3 Oct 2019 19:46:57 +0200 Subject: [PATCH 7/8] removed comment, and fixed code style error --- core_lib/src/structure/layervector.cpp | 5 +++-- core_lib/src/structure/object.cpp | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core_lib/src/structure/layervector.cpp b/core_lib/src/structure/layervector.cpp index 0c5d2b12f..edc7505e8 100644 --- a/core_lib/src/structure/layervector.cpp +++ b/core_lib/src/structure/layervector.cpp @@ -55,8 +55,9 @@ void LayerVector::moveColor(int start, int end) foreachKeyFrame( [=]( KeyFrame* pKeyFrame ) { auto pVecImage = static_cast< VectorImage* >( pKeyFrame ); - pVecImage->moveColor(start, end ); - } );} + pVecImage->moveColor(start, end); + }); +} void LayerVector::loadImageAtFrame(QString path, int frameNumber) { diff --git a/core_lib/src/structure/object.cpp b/core_lib/src/structure/object.cpp index 87acc4472..40164cb9b 100644 --- a/core_lib/src/structure/object.cpp +++ b/core_lib/src/structure/object.cpp @@ -315,8 +315,6 @@ void Object::movePaletteColor(int start, int end) void Object::moveVectorColor(int start, int end) { - // movePaletteColor _must_ be made before calling this function! - for (int i = 0; i < getLayerCount(); i++) { Layer* layer = getLayer(i); From 137c455b93fbf9e7d2ab3bce2ade810e5777d3a4 Mon Sep 17 00:00:00 2001 From: David Lamhauge Date: Sun, 10 Nov 2019 20:41:23 +0100 Subject: [PATCH 8/8] Made Editor and Object local variables --- app/src/colorpalettewidget.cpp | 68 ++++++++++++++++++---------------- app/src/colorpalettewidget.h | 4 ++ app/src/mainwindow2.cpp | 1 + 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/app/src/colorpalettewidget.cpp b/app/src/colorpalettewidget.cpp index d28d8e27e..8fb1e0569 100644 --- a/app/src/colorpalettewidget.cpp +++ b/app/src/colorpalettewidget.cpp @@ -98,6 +98,12 @@ void ColorPaletteWidget::updateUI() updateGridUI(); } +void ColorPaletteWidget::setCore(Editor *editor) +{ + mEditor = editor; + mObject = mEditor->object(); +} + void ColorPaletteWidget::showContextMenu(const QPoint &pos) { QPoint globalPos = ui->colorListWidget->mapToGlobal(pos); @@ -113,14 +119,14 @@ void ColorPaletteWidget::showContextMenu(const QPoint &pos) void ColorPaletteWidget::addItem() { QSignalBlocker b(ui->colorListWidget); - QColor newColour = editor()->color()->frontColor(); + QColor newColour = mEditor->color()->frontColor(); // add in front of selected color int colorIndex = ui->colorListWidget->currentRow()+1; ColourRef ref(newColour); - editor()->object()->addColourAtIndex(colorIndex, ref); + mObject->addColourAtIndex(colorIndex, ref); refreshColorList(); } @@ -129,7 +135,7 @@ void ColorPaletteWidget::replaceItem() QSignalBlocker b(ui->colorListWidget); int index = ui->colorListWidget->currentRow(); - QColor newColour = editor()->color()->frontColor(); + QColor newColour = mEditor->color()->frontColor(); if (index >= 0) { @@ -191,11 +197,11 @@ void ColorPaletteWidget::refreshColorList() borderHighlight.setColor(QColor(255, 255, 255, 200)); borderHighlight.setDashOffset(4); - int colourCount = editor()->object()->getColourCount(); + int colourCount = mObject->getColourCount(); for (int i = 0; i < colourCount; i++) { - const ColourRef colourRef = editor()->object()->getColour(i); + const ColourRef colourRef = mObject->getColour(i); QListWidgetItem* colourItem = new QListWidgetItem(ui->colorListWidget); if (ui->colorListWidget->viewMode() != QListView::IconMode) @@ -246,11 +252,11 @@ void ColorPaletteWidget::changeColourName(QListWidgetItem* item) tr("Colour name"), tr("Colour name"), QLineEdit::Normal, - editor()->object()->getColour(colorNumber).name, + mObject->getColour(colorNumber).name, &ok); if (ok && !text.isEmpty()) { - editor()->object()->renameColour(colorNumber, text); + mObject->renameColour(colorNumber, text); refreshColorList(); } } @@ -261,7 +267,7 @@ void ColorPaletteWidget::onItemChanged(QListWidgetItem* item) { int index = ui->colorListWidget->row(item); QString newColorName = item->text(); - editor()->object()->renameColour(index, newColorName); + mObject->renameColour(index, newColorName); } void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) @@ -279,15 +285,15 @@ void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int e startIndex = start; endIndex = row; - editor()->object()->movePaletteColor(startIndex, endIndex); + mObject->movePaletteColor(startIndex, endIndex); - editor()->object()->addColour(editor()->object()->getColour(startIndex)); - editor()->object()->moveVectorColor(startIndex, editor()->object()->getColourCount() - 1); + mObject->addColour(mObject->getColour(startIndex)); + mObject->moveVectorColor(startIndex, mObject->getColourCount() - 1); for (int i = startIndex; i < endIndex; i++) { - editor()->object()->moveVectorColor(i + 1, i); + mObject->moveVectorColor(i + 1, i); } - editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); + mObject->moveVectorColor(mObject->getColourCount() - 1, endIndex); } else { @@ -296,18 +302,18 @@ void ColorPaletteWidget::onRowsMoved(const QModelIndex &parent, int start, int e startIndex = start; endIndex = row; - editor()->object()->movePaletteColor(startIndex, endIndex); + mObject->movePaletteColor(startIndex, endIndex); - editor()->object()->addColour(editor()->object()->getColour(startIndex)); - editor()->object()->moveVectorColor(startIndex, editor()->object()->getColourCount() - 1); + mObject->addColour(mObject->getColour(startIndex)); + mObject->moveVectorColor(startIndex, mObject->getColourCount() - 1); for (int i = startIndex; i > endIndex; i--) { - editor()->object()->moveVectorColor(i - 1, i); + mObject->moveVectorColor(i - 1, i); } - editor()->object()->moveVectorColor(editor()->object()->getColourCount() - 1, endIndex); + mObject->moveVectorColor(mObject->getColourCount() - 1, endIndex); } - editor()->object()->removeColour(editor()->object()->getColourCount() - 1); + mObject->removeColour(mObject->getColourCount() - 1); refreshColorList(); } @@ -474,21 +480,21 @@ void ColorPaletteWidget::clickAddColorButton() if (mIsColorDialog) newColour = QColorDialog::getColor(prevColor.rgba(), this, QString(), QColorDialog::ShowAlphaChannel); else - newColour = editor()->color()->frontColor(); + newColour = mEditor->color()->frontColor(); if (!newColour.isValid()) { return; // User canceled operation } - int colorIndex = editor()->object()->getColourCount(); + int colorIndex = mObject->getColourCount(); ColourRef ref(newColour); - editor()->object()->addColour(ref); + mObject->addColour(ref); refreshColorList(); - editor()->color()->setColorNumber(colorIndex); - editor()->color()->setColor(ref.colour); + mEditor->color()->setColorNumber(colorIndex); + mEditor->color()->setColor(ref.colour); } void ColorPaletteWidget::clickRemoveColorButton() @@ -500,28 +506,28 @@ void ColorPaletteWidget::clickRemoveColorButton() // items are not deleted by qt, it has to be done manually // delete should happen before removing the color from from palette // as the palette will be one ahead and crash otherwise - if (editor()->object()->isColourInUse(index)) + if (mObject->isColourInUse(index)) { bool accepted = false; if (!mMultipleSelected) accepted = showPaletteWarning(); - if ((accepted || mMultipleSelected) && editor()->object()->getColourCount() > 1) + if ((accepted || mMultipleSelected) && mObject->getColourCount() > 1) { delete item; - editor()->object()->removeColour(index); + mObject->removeColour(index); } } - else if (editor()->object()->getColourCount() > 1) + else if (mObject->getColourCount() > 1) { delete item; - editor()->object()->removeColour(index); + mObject->removeColour(index); } - else if (editor()->object()->getColourCount() == 1) + else if (mObject->getColourCount() == 1) { showPaletteReminder(); } - editor()->updateCurrentFrame(); + mEditor->updateCurrentFrame(); } mMultipleSelected = false; } diff --git a/app/src/colorpalettewidget.h b/app/src/colorpalettewidget.h index a6300e9b7..0c38a5aa8 100644 --- a/app/src/colorpalettewidget.h +++ b/app/src/colorpalettewidget.h @@ -46,6 +46,7 @@ class ColorPaletteWidget : public BaseDockWidget void initUI() override; void updateUI() override; + void setCore(Editor* editor); int currentColourNumber(); @@ -106,6 +107,9 @@ private slots: bool mIsColorDialog = false; bool mMultipleSelected = false; + Editor* mEditor = nullptr; + Object* mObject = nullptr; + }; #endif diff --git a/app/src/mainwindow2.cpp b/app/src/mainwindow2.cpp index 54aa10dbf..4fd60dd72 100644 --- a/app/src/mainwindow2.cpp +++ b/app/src/mainwindow2.cpp @@ -148,6 +148,7 @@ void MainWindow2::createDockWidgets() mColorInspector->setObjectName("Color Inspector"); mColorPalette = new ColorPaletteWidget(this); + mColorPalette->setCore(mEditor); mColorPalette->setObjectName("ColorPalette"); mDisplayOptionWidget = new DisplayOptionWidget(this);