From 58981f95808067b5a6eb86b67cf7dade1b2f4543 Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Tue, 29 Dec 2020 19:20:03 -0800 Subject: [PATCH] Added option to paint selected pieces. Fixes #561. --- common/lc_commands.cpp | 7 +++++++ common/lc_commands.h | 1 + common/lc_mainwindow.cpp | 40 +++++++++++++++++++++++++++++++++++++++- common/lc_mainwindow.h | 2 ++ common/lc_model.cpp | 5 +++++ common/lc_model.h | 1 + 6 files changed, 55 insertions(+), 1 deletion(-) diff --git a/common/lc_commands.cpp b/common/lc_commands.cpp index e5f458b7..70402760 100644 --- a/common/lc_commands.cpp +++ b/common/lc_commands.cpp @@ -1172,6 +1172,13 @@ const lcCommand gCommands[] = QT_TRANSLATE_NOOP("Status", "Create a copy of the selected pieces"), "Ctrl+D" }, + // LC_PIECE_PAINT_SELECTED + { + QT_TRANSLATE_NOOP("Action", "Piece.PaintSelected"), + QT_TRANSLATE_NOOP("Menu", "&Paint Selected"), + QT_TRANSLATE_NOOP("Status", "Change the color of the selected pieces"), + "" + }, // LC_PIECE_RESET_PIVOT_POINT { QT_TRANSLATE_NOOP("Action", "Piece.ResetPivotPoint"), diff --git a/common/lc_commands.h b/common/lc_commands.h index 13bcec6c..e10469c6 100644 --- a/common/lc_commands.h +++ b/common/lc_commands.h @@ -183,6 +183,7 @@ enum lcCommandId LC_PIECE_INSERT, LC_PIECE_DELETE, LC_PIECE_DUPLICATE, + LC_PIECE_PAINT_SELECTED, LC_PIECE_RESET_PIVOT_POINT, LC_PIECE_REMOVE_KEY_FRAMES, LC_PIECE_CONTROL_POINT_INSERT, diff --git a/common/lc_mainwindow.cpp b/common/lc_mainwindow.cpp index fb096382..4e0a9575 100644 --- a/common/lc_mainwindow.cpp +++ b/common/lc_mainwindow.cpp @@ -567,6 +567,7 @@ void lcMainWindow::CreateMenus() PieceMenu->addAction(mActions[LC_PIECE_INSERT]); PieceMenu->addAction(mActions[LC_PIECE_DELETE]); PieceMenu->addAction(mActions[LC_PIECE_DUPLICATE]); + PieceMenu->addAction(mActions[LC_PIECE_PAINT_SELECTED]); PieceMenu->addAction(mActions[LC_PIECE_ARRAY]); PieceMenu->addAction(mActions[LC_PIECE_MINIFIG_WIZARD]); PieceMenu->addAction(mActions[LC_PIECE_RESET_PIVOT_POINT]); @@ -709,7 +710,25 @@ void lcMainWindow::CreateToolBars() mColorList = new lcQColorList(); connect(mColorList, SIGNAL(colorChanged(int)), this, SLOT(ColorChanged(int))); - mColorsToolBar->setWidget(mColorList); + QWidget* ColorWidget = new QWidget(mColorsToolBar); + + QVBoxLayout* ColorLayout = new QVBoxLayout(ColorWidget); + + QHBoxLayout* ColorButtonLayout = new QHBoxLayout(); + ColorButtonLayout->setContentsMargins(0, 0, 0, 0); + ColorLayout->addLayout(ColorButtonLayout); + + mColorButton = new QToolButton(ColorWidget); + mColorButton->setAutoRaise(true); + mColorButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); + mColorButton->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum); + ColorButtonLayout->addWidget(mColorButton); + + connect(mColorButton, SIGNAL(clicked()), this, SLOT(ColorButtonClicked())); + + ColorLayout->addWidget(mColorList); + + mColorsToolBar->setWidget(ColorWidget); addDockWidget(Qt::RightDockWidgetArea, mColorsToolBar); mPropertiesToolBar = new QDockWidget(tr("Properties"), this); @@ -1110,6 +1129,14 @@ void lcMainWindow::ColorChanged(int ColorIndex) SetColorIndex(ColorIndex); } +void lcMainWindow::ColorButtonClicked() +{ + lcModel* ActiveModel = GetActiveModel(); + + if (ActiveModel) + ActiveModel->PaintSelectedPieces(); +} + void lcMainWindow::ProjectFileChanged(const QString& Path) { static bool Ignore; @@ -2038,6 +2065,7 @@ void lcMainWindow::UpdateSelectedObjects(bool SelectionChanged) mActions[LC_PIECE_DELETE]->setEnabled(Flags & LC_SEL_SELECTED); mActions[LC_PIECE_DUPLICATE]->setEnabled(Flags & LC_SEL_SELECTED); + mActions[LC_PIECE_PAINT_SELECTED]->setEnabled(Flags & LC_SEL_PIECE); mActions[LC_PIECE_RESET_PIVOT_POINT]->setEnabled(Flags & LC_SEL_SELECTED); mActions[LC_PIECE_REMOVE_KEY_FRAMES]->setEnabled(Flags & LC_SEL_SELECTED); mActions[LC_PIECE_ARRAY]->setEnabled(Flags & LC_SEL_PIECE); @@ -2152,6 +2180,11 @@ void lcMainWindow::UpdateSnap() void lcMainWindow::UpdateColor() { + QPixmap Pixmap(16, 16); + Pixmap.fill(QColor::fromRgbF(gColorList[mColorIndex].Value[0], gColorList[mColorIndex].Value[1], gColorList[mColorIndex].Value[2])); + + mColorButton->setIcon(Pixmap); + mColorButton->setText(QString(" ") + gColorList[mColorIndex].Name); mColorList->setCurrentColor(mColorIndex); } @@ -2885,6 +2918,11 @@ void lcMainWindow::HandleCommand(lcCommandId CommandId) ActiveModel->DuplicateSelectedPieces(); break; + case LC_PIECE_PAINT_SELECTED: + if (ActiveModel) + ActiveModel->PaintSelectedPieces(); + break; + case LC_PIECE_RESET_PIVOT_POINT: if (ActiveModel) ActiveModel->ResetSelectedPiecesPivotPoint(); diff --git a/common/lc_mainwindow.h b/common/lc_mainwindow.h index 57a69d47..01107d62 100644 --- a/common/lc_mainwindow.h +++ b/common/lc_mainwindow.h @@ -370,6 +370,7 @@ protected slots: void ClipboardChanged(); void ActionTriggered(); void ColorChanged(int ColorIndex); + void ColorButtonClicked(); void Print(QPrinter* Printer); void EnableWindowFlags(bool); @@ -442,6 +443,7 @@ protected: lcPartSelectionWidget* mPartSelectionWidget; lcQColorList* mColorList; + QToolButton* mColorButton; lcQPropertiesTree* mPropertiesWidget; lcTimelineWidget* mTimelineWidget; QLineEdit* mTransformXEdit; diff --git a/common/lc_model.cpp b/common/lc_model.cpp index f20064fc..5d298c36 100644 --- a/common/lc_model.cpp +++ b/common/lc_model.cpp @@ -1231,6 +1231,11 @@ void lcModel::DuplicateSelectedPieces() SaveCheckpoint(tr("Duplicating Pieces")); } +void lcModel::PaintSelectedPieces() +{ + SetSelectedPiecesColorIndex(gMainWindow->mColorIndex); +} + void lcModel::GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const { if (mPieceInfo) diff --git a/common/lc_model.h b/common/lc_model.h index 6cd16036..ea4648a9 100644 --- a/common/lc_model.h +++ b/common/lc_model.h @@ -236,6 +236,7 @@ public: void Copy(); void Paste(); void DuplicateSelectedPieces(); + void PaintSelectedPieces(); void GetScene(lcScene* Scene, lcCamera* ViewCamera, bool AllowHighlight, bool AllowFade) const; void AddSubModelRenderMeshes(lcScene* Scene, const lcMatrix44& WorldMatrix, int DefaultColorIndex, lcRenderMeshState RenderMeshState, bool ParentActive) const;