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 00000000..4ee12537 Binary files /dev/null and b/resources/parts_cancel.png differ