diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index fa2c5f29..4648e164 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -185,7 +185,7 @@ void lcPartSelectionListModel::SetModelsCategory() SetFilter(mFilter); } -void lcPartSelectionListModel::SetCustomSetCategory(int SetIndex) +void lcPartSelectionListModel::SetPaletteCategory(int SetIndex) { ClearRequests(); @@ -194,8 +194,8 @@ void lcPartSelectionListModel::SetCustomSetCategory(int SetIndex) mParts.clear(); lcPartSelectionWidget* PartSelectionWidget = mListView->GetPartSelectionWidget(); - const std::vector& CustomSets = PartSelectionWidget->GetCustomSets(); - std::vector PartsList = lcGetPiecesLibrary()->GetPartsFromSet(CustomSets[SetIndex].Parts); + const std::vector& Palettes = PartSelectionWidget->GetPartPalettes(); + std::vector PartsList = lcGetPiecesLibrary()->GetPartsFromSet(Palettes[SetIndex].Parts); auto lcPartSortFunc = [](const PieceInfo* a, const PieceInfo* b) { @@ -513,14 +513,14 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos) QModelIndex Index = indexAt(Pos); mContextInfo = Index.isValid() ? mListModel->GetPieceInfo(Index.row()) : nullptr; - QMenu* SetMenu = Menu->addMenu(tr("Add to Set")); + QMenu* SetMenu = Menu->addMenu(tr("Add to Palette")); - const std::vector& CustomSets = mPartSelectionWidget->GetCustomSets(); + const std::vector& Palettes = mPartSelectionWidget->GetPartPalettes(); - if (!CustomSets.empty()) + if (!Palettes.empty()) { - for (const lcPartCategoryCustomSet& Set : CustomSets) - SetMenu->addAction(Set.Name, mPartSelectionWidget, SLOT(AddToSet())); + for (const lcPartPalette& Palette : Palettes) + SetMenu->addAction(Palette.Name, mPartSelectionWidget, SLOT(AddToPalette())); } else { @@ -528,8 +528,8 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos) Action->setEnabled(false); } - QAction* RemoveAction = Menu->addAction(tr("Remove from Set"), mPartSelectionWidget, SLOT(RemoveFromSet())); - RemoveAction->setEnabled(mCategoryType == lcPartCategoryType::CustomSet); + QAction* RemoveAction = Menu->addAction(tr("Remove from Palette"), mPartSelectionWidget, SLOT(RemoveFromPalette())); + RemoveAction->setEnabled(mCategoryType == lcPartCategoryType::Palette); Menu->exec(viewport()->mapToGlobal(Pos)); delete Menu; @@ -551,8 +551,8 @@ void lcPartSelectionListView::SetCategory(lcPartCategoryType Type, int Index) case lcPartCategoryType::Submodels: mListModel->SetModelsCategory(); break; - case lcPartCategoryType::CustomSet: - mListModel->SetCustomSetCategory(Index); + case lcPartCategoryType::Palette: + mListModel->SetPaletteCategory(Index); break; case lcPartCategoryType::Category: mListModel->SetCategory(Index); @@ -714,7 +714,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&))); connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*))); - LoadCustomSets(); + LoadPartPalettes(); UpdateCategories(); mSplitter->setStretchFactor(0, 0); @@ -843,6 +843,9 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow() QMenu* Menu = (QMenu*)sender(); Menu->clear(); + Menu->addAction("Configure Palettes...", this, SLOT(ConfigurePartPalettes())); + Menu->addSeparator(); + lcPartSelectionListModel* ListModel = mPartsWidget->GetListModel(); if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT) @@ -904,6 +907,11 @@ void lcPartSelectionWidget::OptionsMenuAboutToShow() } } +void lcPartSelectionWidget::ConfigurePartPalettes() +{ + +} + void lcPartSelectionWidget::Redraw() { mPartsWidget->GetListModel()->Redraw(); @@ -923,68 +931,68 @@ void lcPartSelectionWidget::SetDefaultPart() } } -void lcPartSelectionWidget::LoadCustomSets() +void lcPartSelectionWidget::LoadPartPalettes() { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) - QByteArray Buffer = lcGetProfileBuffer(LC_PROFILE_PART_SETS); + QByteArray Buffer = lcGetProfileBuffer(LC_PROFILE_PART_PALETTES); QJsonDocument Document = QJsonDocument::fromJson(Buffer); if (Document.isNull()) - Document = QJsonDocument::fromJson((QString("{ \"Version\":1, \"Sets\": { \"%1\": [] } }").arg(tr("Favorites"))).toUtf8()); + Document = QJsonDocument::fromJson((QString("{ \"Version\":1, \"Palettes\": { \"%1\": [] } }").arg(tr("Favorites"))).toUtf8()); QJsonObject RootObject = Document.object(); - mCustomSets.clear(); + mPartPalettes.clear(); int Version = RootObject["Version"].toInt(0); if (Version != 1) return; - QJsonObject SetsObject = RootObject["Sets"].toObject(); + QJsonObject PalettesObject = RootObject["Palettes"].toObject(); - for (QJsonObject::const_iterator ElementIt = SetsObject.constBegin(); ElementIt != SetsObject.constEnd(); ElementIt++) + for (QJsonObject::const_iterator ElementIt = PalettesObject.constBegin(); ElementIt != PalettesObject.constEnd(); ElementIt++) { if (!ElementIt.value().isArray()) continue; - lcPartCategoryCustomSet Set; - Set.Name = ElementIt.key(); + lcPartPalette Palette; + Palette.Name = ElementIt.key(); QJsonArray Parts = ElementIt.value().toArray(); for (const QJsonValue& Part : Parts) - Set.Parts.emplace_back(Part.toString().toStdString()); + Palette.Parts.emplace_back(Part.toString().toStdString()); - mCustomSets.emplace_back(std::move(Set)); + mPartPalettes.emplace_back(std::move(Palette)); } #endif } -void lcPartSelectionWidget::SaveCustomSets() +void lcPartSelectionWidget::SavePartPalettes() { #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) QJsonObject RootObject; RootObject["Version"] = 1; - QJsonObject SetsObject; + QJsonObject PalettesObject; - for (const lcPartCategoryCustomSet& Set: mCustomSets) + for (const lcPartPalette& Palette : mPartPalettes) { QJsonArray Parts; - for (const std::string& PartId : Set.Parts) + for (const std::string& PartId : Palette.Parts) Parts.append(QString::fromStdString(PartId)); - SetsObject[Set.Name] = Parts; + PalettesObject[Palette.Name] = Parts; } - RootObject["Sets"] = SetsObject; + RootObject["Palettes"] = PalettesObject; QByteArray Buffer = QJsonDocument(RootObject).toJson(); - lcSetProfileBuffer(LC_PROFILE_PART_SETS, Buffer); + lcSetProfileBuffer(LC_PROFILE_PART_PALETTES, Buffer); #endif } -void lcPartSelectionWidget::AddToSet() +void lcPartSelectionWidget::AddToPalette() { PieceInfo* Info = mPartsWidget->GetContextInfo(); if (!Info) @@ -992,45 +1000,45 @@ void lcPartSelectionWidget::AddToSet() QString SetName = ((QAction*)sender())->text(); - std::vector::iterator SetIt = std::find_if(mCustomSets.begin(), mCustomSets.end(), [&SetName](const lcPartCategoryCustomSet& Set) + std::vector::iterator SetIt = std::find_if(mPartPalettes.begin(), mPartPalettes.end(), [&SetName](const lcPartPalette& Set) { return Set.Name == SetName; }); - if (SetIt == mCustomSets.end()) + if (SetIt == mPartPalettes.end()) return; std::string PartId = lcGetPiecesLibrary()->GetPartId(Info); - std::vector& SetParts = SetIt->Parts; + std::vector& Parts = SetIt->Parts; - if (std::find(SetParts.begin(), SetParts.end(), PartId) == SetParts.end()) + if (std::find(Parts.begin(), Parts.end(), PartId) == Parts.end()) { - SetParts.emplace_back(PartId); - SaveCustomSets(); + Parts.emplace_back(PartId); + SavePartPalettes(); } } -void lcPartSelectionWidget::RemoveFromSet() +void lcPartSelectionWidget::RemoveFromPalette() { PieceInfo* Info = mPartsWidget->GetContextInfo(); if (!Info) return; QTreeWidgetItem* CurrentItem = mCategoriesWidget->currentItem(); - if (!CurrentItem || CurrentItem->data(0, static_cast(lcPartCategoryRole::Type)) != static_cast(lcPartCategoryType::CustomSet)) + if (!CurrentItem || CurrentItem->data(0, static_cast(lcPartCategoryRole::Type)) != static_cast(lcPartCategoryType::Palette)) return; int SetIndex = CurrentItem->data(0, static_cast(lcPartCategoryRole::Index)).toInt(); - lcPartCategoryCustomSet& Set = mCustomSets[SetIndex]; + lcPartPalette& Palette = mPartPalettes[SetIndex]; std::string PartId = lcGetPiecesLibrary()->GetPartId(Info); - std::vector::iterator PartIt = std::find(Set.Parts.begin(), Set.Parts.end(), PartId); + std::vector::iterator PartIt = std::find(Palette.Parts.begin(), Palette.Parts.end(), PartId); - if (PartIt != Set.Parts.end()) + if (PartIt != Palette.Parts.end()) { - Set.Parts.erase(PartIt); - mPartsWidget->SetCategory(lcPartCategoryType::CustomSet, SetIndex); - SaveCustomSets(); + Palette.Parts.erase(PartIt); + mPartsWidget->SetCategory(lcPartCategoryType::Palette, SetIndex); + SavePartPalettes(); } } @@ -1049,11 +1057,11 @@ void lcPartSelectionWidget::UpdateCategories() QTreeWidgetItem* SubmodelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Submodels"))); SubmodelsCategoryItem->setData(0, static_cast(lcPartCategoryRole::Type), static_cast(lcPartCategoryType::Submodels)); - for (int SetIdx = 0; SetIdx < static_cast(mCustomSets.size()); SetIdx++) + for (int SetIdx = 0; SetIdx < static_cast(mPartPalettes.size()); SetIdx++) { - const lcPartCategoryCustomSet& Set = mCustomSets[SetIdx]; + const lcPartPalette& Set = mPartPalettes[SetIdx]; QTreeWidgetItem* SetCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(Set.Name)); - SetCategoryItem->setData(0, static_cast(lcPartCategoryRole::Type), static_cast(lcPartCategoryType::CustomSet)); + SetCategoryItem->setData(0, static_cast(lcPartCategoryRole::Type), static_cast(lcPartCategoryType::Palette)); SetCategoryItem->setData(0, static_cast(lcPartCategoryRole::Index), SetIdx); } diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 073b03b0..9728972e 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -11,7 +11,7 @@ enum class lcPartCategoryType AllParts, PartsInUse, Submodels, - CustomSet, + Palette, Category }; @@ -21,7 +21,7 @@ enum class lcPartCategoryRole Index }; -struct lcPartCategoryCustomSet +struct lcPartPalette { QString Name; std::vector Parts; @@ -103,7 +103,7 @@ public: void ToggleListMode(); void SetCategory(int CategoryIndex); void SetModelsCategory(); - void SetCustomSetCategory(int SetIndex); + void SetPaletteCategory(int SetIndex); void SetCurrentModelCategory(); void SetFilter(const QString& Filter); void RequestPreview(int InfoIndex); @@ -209,14 +209,14 @@ public: mPartsWidget->GetListModel()->SetColorIndex(ColorIndex); } - const std::vector& GetCustomSets() const + const std::vector& GetPartPalettes() const { - return mCustomSets; + return mPartPalettes; } public slots: - void AddToSet(); - void RemoveFromSet(); + void AddToPalette(); + void RemoveFromPalette(); protected slots: void DockLocationChanged(Qt::DockWidgetArea Area); @@ -225,10 +225,11 @@ protected slots: void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); void PartChanged(const QModelIndex& Current, const QModelIndex& Previous); void OptionsMenuAboutToShow(); + void ConfigurePartPalettes(); protected: - void LoadCustomSets(); - void SaveCustomSets(); + void LoadPartPalettes(); + void SavePartPalettes(); virtual void resizeEvent(QResizeEvent* Event); virtual bool event(QEvent* Event); @@ -238,5 +239,5 @@ protected: QAction* mFilterAction; lcPartSelectionListView* mPartsWidget; QSplitter* mSplitter; - std::vector mCustomSets; + std::vector mPartPalettes; }; diff --git a/common/lc_profile.cpp b/common/lc_profile.cpp index 7a84d1fc..d502acc3 100644 --- a/common/lc_profile.cpp +++ b/common/lc_profile.cpp @@ -77,7 +77,7 @@ static lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] = lcProfileEntry("Settings", "CheckUpdates", 1), // LC_PROFILE_CHECK_UPDATES lcProfileEntry("Settings", "ProjectsPath", ""), // LC_PROFILE_PROJECTS_PATH lcProfileEntry("Settings", "PartsLibrary", ""), // LC_PROFILE_PARTS_LIBRARY - lcProfileEntry("Settings", "PartSets"), // LC_PROFILE_PART_SETS + lcProfileEntry("Settings", "PartPalettes"), // LC_PROFILE_PART_PALETTES lcProfileEntry("Settings", "MinifigSettings", ""), // LC_PROFILE_MINIFIG_SETTINGS lcProfileEntry("Settings", "ColorConfig", ""), // LC_PROFILE_COLOR_CONFIG lcProfileEntry("Settings", "Shortcuts"), // LC_PROFILE_KEYBOARD_SHORTCUTS diff --git a/common/lc_profile.h b/common/lc_profile.h index ce75a773..ee5e64b2 100644 --- a/common/lc_profile.h +++ b/common/lc_profile.h @@ -25,7 +25,7 @@ enum LC_PROFILE_KEY LC_PROFILE_CHECK_UPDATES, LC_PROFILE_PROJECTS_PATH, LC_PROFILE_PARTS_LIBRARY, - LC_PROFILE_PART_SETS, + LC_PROFILE_PART_PALETTES, LC_PROFILE_MINIFIG_SETTINGS, LC_PROFILE_COLOR_CONFIG, LC_PROFILE_KEYBOARD_SHORTCUTS,