mirror of
https://github.com/leozide/leocad.git
synced 2026-10-26 22:10:32 +00:00
Use PieceData consistently for the shared part/model record, its related APIs and variables, and its source files. Keep the existing reference counting and loading behavior so ownership and readiness changes can be reviewed separately.
372 lines
8.6 KiB
C++
372 lines
8.6 KiB
C++
#pragma once
|
|
|
|
#include "lc_thumbnailmanager.h"
|
|
|
|
class lcPartSelectionListModel;
|
|
class lcPartSelectionListView;
|
|
class lcPartSelectionWidget;
|
|
|
|
enum class lcPartCategoryType
|
|
{
|
|
AllParts,
|
|
PartsInUse,
|
|
Submodels,
|
|
Palette,
|
|
Category,
|
|
Custom,
|
|
Count
|
|
};
|
|
|
|
enum class lcPartCategoryRole
|
|
{
|
|
Type = Qt::UserRole,
|
|
Index
|
|
};
|
|
|
|
enum class lcPartFilterType
|
|
{
|
|
Default,
|
|
RegularExpression,
|
|
Count
|
|
};
|
|
|
|
struct lcPartPalette
|
|
{
|
|
QString Name;
|
|
std::vector<std::string> Parts;
|
|
};
|
|
|
|
class lcPartSelectionItemDelegate : public QStyledItemDelegate
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
lcPartSelectionItemDelegate(QObject* Parent, lcPartSelectionListModel* ListModel)
|
|
: QStyledItemDelegate(Parent), mListModel(ListModel)
|
|
{
|
|
}
|
|
|
|
void paint(QPainter* Painter, const QStyleOptionViewItem& Option, const QModelIndex& Index) const override;
|
|
QSize sizeHint(const QStyleOptionViewItem& Option, const QModelIndex& Index) const override;
|
|
|
|
protected:
|
|
void initStyleOption(QStyleOptionViewItem* Option, const QModelIndex& Index) const override;
|
|
|
|
lcPartSelectionListModel* mListModel;
|
|
};
|
|
|
|
struct lcPartSelectionListModelEntry
|
|
{
|
|
lcPieceData* PieceData = nullptr;
|
|
std::string Description;
|
|
int ColorIndex = -1;
|
|
QPixmap Pixmap;
|
|
lcPartThumbnailId ThumbnailId = lcPartThumbnailId::Invalid;
|
|
};
|
|
|
|
class lcPartSelectionListModel : public QAbstractListModel
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
lcPartSelectionListModel(QObject* Parent);
|
|
~lcPartSelectionListModel();
|
|
|
|
int rowCount(const QModelIndex& Parent = QModelIndex()) const override;
|
|
QVariant data(const QModelIndex& Index, int Role = Qt::DisplayRole) const override;
|
|
QVariant headerData(int Section, Qt::Orientation Orientation, int Role = Qt::DisplayRole) const override;
|
|
Qt::ItemFlags flags(const QModelIndex& Index) const override;
|
|
|
|
QModelIndex GetPieceDataIndex(lcPieceData* PieceData) const;
|
|
|
|
lcPieceData* GetPieceData(const QModelIndex& Index) const
|
|
{
|
|
return Index.isValid() ? mParts[Index.row()].PieceData : nullptr;
|
|
}
|
|
|
|
lcPieceData* GetPieceData(int Row) const
|
|
{
|
|
return mParts[Row].PieceData;
|
|
}
|
|
|
|
bool GetShowDecoratedParts() const
|
|
{
|
|
return mShowDecoratedParts;
|
|
}
|
|
|
|
bool GetShowPartAliases() const
|
|
{
|
|
return mShowPartAliases;
|
|
}
|
|
|
|
lcPartFilterType GetPartFilterType() const
|
|
{
|
|
return mPartFilterType;
|
|
}
|
|
|
|
bool GetCaseSensitiveFilter() const
|
|
{
|
|
return mCaseSensitiveFilter;
|
|
}
|
|
|
|
bool GetFileNameFilter() const
|
|
{
|
|
return mFileNameFilter;
|
|
}
|
|
|
|
bool GetPartDescriptionFilter() const
|
|
{
|
|
return mPartDescriptionFilter;
|
|
}
|
|
|
|
int GetIconSize() const
|
|
{
|
|
return mIconSize;
|
|
}
|
|
|
|
bool GetShowPartNames() const
|
|
{
|
|
return mShowPartNames;
|
|
}
|
|
|
|
int GetColorIndex() const
|
|
{
|
|
return mColorIndex;
|
|
}
|
|
|
|
bool IsColorLocked() const
|
|
{
|
|
return mColorLocked;
|
|
}
|
|
|
|
bool IsListMode() const
|
|
{
|
|
return mListMode;
|
|
}
|
|
|
|
void UpdateThumbnails();
|
|
void SetColorIndex(int ColorIndex);
|
|
void ToggleColorLocked();
|
|
void ToggleListMode();
|
|
void SetCategory(int CategoryIndex);
|
|
void SetModelsCategory();
|
|
void SetPaletteCategory(int SetIndex);
|
|
void SetCurrentModelCategory();
|
|
void SetCustomParts(const std::vector<std::pair<lcPieceData*, std::string>>& Parts, int ColorIndex);
|
|
void SetFilter(const QString& FilterString);
|
|
void RequestThumbnail(int PartIndex);
|
|
void SetShowDecoratedParts(bool Show);
|
|
void SetShowPartAliases(bool Show);
|
|
void SetPartFilterType(lcPartFilterType Option);
|
|
void SetCaseSensitiveFilter(bool Option);
|
|
void SetFileNameFilter(bool Option);
|
|
void SetPartDescriptionFilter(bool Option);
|
|
void SetIconSize(int Size, float DeviceScale);
|
|
void SetShowPartNames(bool Show);
|
|
|
|
protected slots:
|
|
void ThumbnailReady(lcPartThumbnailId ThumbnailId, QPixmap Pixmap);
|
|
|
|
protected:
|
|
void ReleaseThumbnails();
|
|
|
|
lcPartSelectionListView* mListView;
|
|
std::vector<lcPartSelectionListModelEntry> mParts;
|
|
lcPartFilterType mPartFilterType;
|
|
int mIconSize;
|
|
float mDeviceScale = 1.0f;
|
|
bool mColorLocked;
|
|
int mColorIndex;
|
|
bool mShowPartNames;
|
|
bool mListMode;
|
|
bool mShowDecoratedParts;
|
|
bool mShowPartAliases;
|
|
bool mCaseSensitiveFilter;
|
|
bool mFileNameFilter;
|
|
bool mPartDescriptionFilter;
|
|
QString mFilterString;
|
|
};
|
|
|
|
class lcPartSelectionListView : public QListView
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
static constexpr int NoIconSize = 0;
|
|
static constexpr int SmallIconSize = 32;
|
|
static constexpr int MediumIconSize = 64;
|
|
static constexpr int LargeIconSize = 96;
|
|
static constexpr int ExtraLargeIconSize = 192;
|
|
|
|
lcPartSelectionListView(QWidget* Parent, lcPartSelectionWidget* PartSelectionWidget);
|
|
|
|
void startDrag(Qt::DropActions SupportedActions) override;
|
|
QSize sizeHint() const override;
|
|
QSize GetCellSize() const;
|
|
QSize GetPreferredSize(int MaximumWidth) const;
|
|
|
|
void SetCategory(lcPartCategoryType Type, int Index);
|
|
void SetCustomParts(const std::vector<std::pair<lcPieceData*, std::string>>& Parts, int ColorIndex);
|
|
void SetCurrentPart(lcPieceData* PieceData);
|
|
|
|
lcPieceData* GetCurrentPart() const
|
|
{
|
|
return mListModel->GetPieceData(currentIndex());
|
|
}
|
|
|
|
lcPartSelectionListModel* GetListModel() const
|
|
{
|
|
return mListModel;
|
|
}
|
|
|
|
lcPartSelectionWidget* GetPartSelectionWidget() const
|
|
{
|
|
return mPartSelectionWidget;
|
|
}
|
|
|
|
lcPieceData* GetContextInfo() const
|
|
{
|
|
return mContextPieceData;
|
|
}
|
|
|
|
void UpdateInUseCategory();
|
|
void UpdateViewMode();
|
|
|
|
signals:
|
|
void PartPicked(lcPieceData* PieceData);
|
|
void LayoutChanged();
|
|
|
|
public slots:
|
|
void CustomContextMenuRequested(QPoint Pos);
|
|
void SetNoIcons();
|
|
void SetSmallIcons();
|
|
void SetMediumIcons();
|
|
void SetLargeIcons();
|
|
void SetExtraLargeIcons();
|
|
void ToggleRegularExpressionFilter();
|
|
void TogglePartNames();
|
|
void ToggleDecoratedParts();
|
|
void TogglePartAliases();
|
|
void ToggleCaseSensitiveFilter();
|
|
void ToggleFileNameFilter();
|
|
void TogglePartDescriptionFilter();
|
|
void ToggleListMode();
|
|
void ToggleFixedColor();
|
|
|
|
protected slots:
|
|
void DoubleClicked(const QModelIndex& Index);
|
|
|
|
protected:
|
|
void SetIconSize(int Size);
|
|
void UpdateIconSize();
|
|
void UpdateItemGeometry();
|
|
void SetPartFilterType(lcPartFilterType Option);
|
|
void keyPressEvent(QKeyEvent* KeyEvent) override;
|
|
|
|
lcPartSelectionListModel* mListModel = nullptr;
|
|
lcPartSelectionWidget* mPartSelectionWidget = nullptr;
|
|
lcPieceData* mContextPieceData = nullptr;
|
|
int mRequestedIconSize = NoIconSize;
|
|
lcPartCategoryType mCategoryType = lcPartCategoryType::AllParts;
|
|
int mCategoryIndex = 0;
|
|
std::map<std::pair<lcPartCategoryType, int>, int> mLastCategoryRow;
|
|
};
|
|
|
|
class lcPartSelectionWidget : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
lcPartSelectionWidget(bool IsPopup, QWidget* Parent);
|
|
|
|
void UpdateThumbnails();
|
|
void SetDefaultPart();
|
|
void UpdateModels();
|
|
void UpdateInUseCategory();
|
|
void UpdateCategories();
|
|
void LoadState(QSettings& Settings);
|
|
void SaveState(QSettings& Settings);
|
|
void SetOrientation(Qt::Orientation Orientation);
|
|
void SetCurrentPart(lcPieceData* PieceData);
|
|
void SetCategory(lcPartCategoryType Type, int Index);
|
|
void SetCustomParts(const std::vector<std::pair<lcPieceData*, std::string>>& Parts, int ColorIndex);
|
|
|
|
bool GetIsPopup() const
|
|
{
|
|
return mIsPopup;
|
|
}
|
|
|
|
int GetColorIndex() const
|
|
{
|
|
return mPartsWidget->GetListModel()->GetColorIndex();
|
|
}
|
|
|
|
void SetColorIndex(int ColorIndex)
|
|
{
|
|
mPartsWidget->GetListModel()->SetColorIndex(ColorIndex);
|
|
}
|
|
|
|
const std::vector<lcPartPalette>& GetPartPalettes() const
|
|
{
|
|
return mPartPalettes;
|
|
}
|
|
|
|
lcPieceData* GetCurrentPart() const
|
|
{
|
|
return mPartsWidget->GetCurrentPart();
|
|
}
|
|
|
|
void SetDragEnabled(bool Enabled)
|
|
{
|
|
mPartsWidget->setDragEnabled(Enabled);
|
|
}
|
|
|
|
void FocusPartFilterWidget() const
|
|
{
|
|
mFilterWidget->setFocus();
|
|
mFilterWidget->selectAll();
|
|
}
|
|
|
|
signals:
|
|
void PartPicked(lcPieceData* PieceData);
|
|
void CurrentPartChanged(lcPieceData* PieceData);
|
|
void LayoutChanged();
|
|
|
|
public slots:
|
|
void AddToPalette();
|
|
void RemoveFromPalette();
|
|
void OpenSubmodel();
|
|
void DockLocationChanged(Qt::DockWidgetArea Area);
|
|
|
|
protected slots:
|
|
void FilterChanged(const QString& Text);
|
|
void FilterCategoriesChanged(const QString& Text);
|
|
void FilterTriggered();
|
|
void FilterCaseTriggered();
|
|
void FilterCategoriesTriggered();
|
|
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
|
|
void PartViewSelectionChanged(const QModelIndex& Current, const QModelIndex& Previous);
|
|
void PartViewPartPicked(lcPieceData* PieceData);
|
|
void OptionsMenuAboutToShow();
|
|
void EditPartPalettes();
|
|
|
|
protected:
|
|
void LoadPartPalettes();
|
|
void SavePartPalettes();
|
|
|
|
void resizeEvent(QResizeEvent* Event) override;
|
|
bool event(QEvent* Event) override;
|
|
|
|
QTreeWidget* mCategoriesWidget = nullptr;
|
|
QLineEdit* mFilterCategoriesWidget = nullptr;
|
|
QAction* mFilterCategoriesAction = nullptr;
|
|
QAction* mFilterCaseAction = nullptr;
|
|
QLineEdit* mFilterWidget = nullptr;
|
|
QAction* mFilterAction = nullptr;
|
|
lcPartSelectionListView* mPartsWidget = nullptr;
|
|
QSplitter* mSplitter = nullptr;
|
|
QTreeWidgetItem* mAllPartsCategoryItem = nullptr;
|
|
std::vector<lcPartPalette> mPartPalettes;
|
|
bool mIsPopup = false;
|
|
};
|