From e766f7892e80f6058f0d6e1d40c25e2724ea3edb Mon Sep 17 00:00:00 2001 From: Leonardo Zide Date: Tue, 31 Jan 2017 21:12:30 -0800 Subject: [PATCH] Added 'All Parts' category. --- common/lc_library.cpp | 5 +++++ common/lc_library.h | 1 + common/lc_partselectionwidget.cpp | 33 ++++++++++++++++++++++++------ common/lc_partselectionwidget.h | 3 +++ leocad.qrc | 1 + resources/parts_cancel.png | Bin 0 -> 1049 bytes 6 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 resources/parts_cancel.png diff --git a/common/lc_library.cpp b/common/lc_library.cpp index a681db0b..71fe9c0d 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -2598,6 +2598,11 @@ void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray& } } +void lcPiecesLibrary::GetParts(lcArray& Parts) +{ + Parts = mPieces; +} + bool lcPiecesLibrary::LoadBuiltinPieces() { QResource Resource(":/resources/library.zip"); diff --git a/common/lc_library.h b/common/lc_library.h index 7e580c82..b5e79d3d 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -152,6 +152,7 @@ public: void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); void GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); void GetPatternedPieces(PieceInfo* Parent, lcArray& Pieces) const; + void GetParts(lcArray& Parts); bool IsPrimitive(const char* Name) const { diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index 9a8021cd..6d1295ab 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -127,7 +127,10 @@ void lcPartSelectionListModel::SetCategory(int CategoryIndex) lcPiecesLibrary* Library = lcGetPiecesLibrary(); lcArray SingleParts, GroupedParts; - Library->GetCategoryEntries(CategoryIndex, false, SingleParts, GroupedParts); + if (CategoryIndex != -1) + Library->GetCategoryEntries(CategoryIndex, false, SingleParts, GroupedParts); + else + Library->GetParts(SingleParts); SingleParts.Sort(lcPartSortFunc); mParts.resize(SingleParts.GetSize()); @@ -481,7 +484,7 @@ void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions) } lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) - : QWidget(Parent) + : QWidget(Parent), mFilterAction(NULL) { mSplitter = new QSplitter(this); @@ -504,7 +507,8 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) mFilterWidget = new QLineEdit(PartsGroupWidget); mFilterWidget->setPlaceholderText(tr("Search Parts")); #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) - mFilterWidget->addAction(QIcon(":/resources/parts_search.png"), QLineEdit::LeadingPosition); + mFilterAction = mFilterWidget->addAction(QIcon(":/resources/parts_search.png"), QLineEdit::TrailingPosition); + connect(mFilterAction, SIGNAL(triggered()), this, SLOT(FilterTriggered())); #endif PartsLayout->addWidget(mFilterWidget); @@ -519,7 +523,7 @@ lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent) setLayout(Layout); connect(mPartsWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(PartChanged(const QModelIndex&, const QModelIndex&))); - connect(mFilterWidget, SIGNAL(textEdited(const QString&)), this, SLOT(FilterChanged(const QString&))); + connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&))); connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*))); UpdateCategories(); @@ -537,9 +541,22 @@ void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event) void lcPartSelectionWidget::FilterChanged(const QString& Text) { + if (mFilterAction) + { + if (Text.isEmpty()) + mFilterAction->setIcon(QIcon(":/resources/parts_search.png")); + else + mFilterAction->setIcon(QIcon(":/resources/parts_cancel.png")); + } + mPartsWidget->GetFilterModel()->SetFilter(Text); } +void lcPartSelectionWidget::FilterTriggered() +{ + mFilterWidget->clear(); +} + void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous) { Q_UNUSED(Previous); @@ -549,8 +566,10 @@ void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidge ListModel->SetModelsCategory(); else if (Current == mCurrentModelCategoryItem) ListModel->SetCurrentModelCategory(); + else if (Current == mAllPartsCategoryItem) + ListModel->SetCategory(-1); else - ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current)); + ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current) - 2); mPartsWidget->setCurrentIndex(mPartsWidget->GetFilterModel()->index(0, 0)); } @@ -588,10 +607,12 @@ void lcPartSelectionWidget::UpdateCategories() mCategoriesWidget->clear(); + mAllPartsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("All Parts"))); + mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use"))); + for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++) new QTreeWidgetItem(mCategoriesWidget, QStringList((const char*)gCategories[CategoryIdx].Name)); - mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Current Model"))); mModelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Models"))); if (CurrentIndex != -1) diff --git a/common/lc_partselectionwidget.h b/common/lc_partselectionwidget.h index 9b5ae6ef..301091ab 100644 --- a/common/lc_partselectionwidget.h +++ b/common/lc_partselectionwidget.h @@ -155,6 +155,7 @@ public: protected slots: void FilterChanged(const QString& Text); + void FilterTriggered(); void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous); void PartChanged(const QModelIndex& Current, const QModelIndex& Previous); @@ -162,9 +163,11 @@ protected: virtual void resizeEvent(QResizeEvent* Event); QTreeWidget* mCategoriesWidget; + QTreeWidgetItem* mAllPartsCategoryItem; QTreeWidgetItem* mCurrentModelCategoryItem; QTreeWidgetItem* mModelsCategoryItem; QLineEdit* mFilterWidget; + QAction* mFilterAction; lcPartSelectionListView* mPartsWidget; QSplitter* mSplitter; }; diff --git a/leocad.qrc b/leocad.qrc index 623d53ab..6d0db189 100644 --- a/leocad.qrc +++ b/leocad.qrc @@ -89,6 +89,7 @@ resources/piece_show_later.png resources/time_add_keys.png resources/parts_search.png + resources/parts_cancel.png resources/library.zip resources/minifig.ini resources/leocad_fr.qm diff --git a/resources/parts_cancel.png b/resources/parts_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..4ee1253736b73693b282fff8b698b445756c0548 GIT binary patch literal 1049 zcmV+!1m^pRP)>Iyb|4W2iTaM&PCXA5iV z5aAKdYEbL@m7lo@tl?`9L_eEVJf!rVjN5lmsUAYdr+MC3oNy~4*P))Tf5gy?%sPBhw zu9!?9V!Vj9^xzgGR$K*4^xrz=EkQ~K#kGD{`>ndR9~-xb1?d(&W@bhgupAJxCAWk8ek(DlV1d*^^cv%*Iq+c zB6gf9255e@KK9&`F!rpTmz+<4vxveXU_Li_#BDj42V*Z9T#~yI;3Ojc#3>MWeG){z zoN)vcuU`_$NdlZj94`Rx-gdXhO?$IJ@wSmlj+>Z(W3&dYCLFVwO(JeJY!WD1nu#Jr#F6J50_hLs zy52%vbQ~z#T3w0|@zn+C!LpgStSs=Gn%s~?v>34slpP(sBJ2ckb%8u%Kgj+~QGwMO zE&CtrFQfWuw?u%d>x+{J#)&*V9sK8J(2i$_rVR{*$>~|v@HNdJV`6N_qg-r9o|XoI zi}UE@Air+&5*es^df-CuSfOHJX|WTaiH+53iE$Vk`yqdWQ$-|CO@$z{o;sCtj4!AL z2B54@kw2`_jp14bStL$Y@{|+^vKZ(XUJ_9C_p{3(<|-mEFH;kZ+9I+gA4IoitOATU z>!Fdg%XcM1Ftb8QRLg4>5xWO)b)xz@2x^nr