leocad/common/lc_partselectionwidget.h

281 lines
6.1 KiB
C
Raw Normal View History

#pragma once
2024-07-11 15:04:07 -07:00
#include "lc_thumbnailmanager.h"
class lcPartSelectionListModel;
2017-01-10 17:48:05 -08:00
class lcPartSelectionListView;
2019-12-08 16:54:12 -08:00
class lcPartSelectionWidget;
enum class lcPartCategoryType
{
AllParts,
PartsInUse,
Submodels,
2019-12-08 19:19:02 -08:00
Palette,
2019-12-15 19:01:55 -08:00
Category,
Count
2019-12-08 16:54:12 -08:00
};
enum class lcPartCategoryRole
{
Type = Qt::UserRole,
Index
};
2019-12-08 19:19:02 -08:00
struct lcPartPalette
2019-12-08 16:54:12 -08:00
{
QString Name;
std::vector<std::string> Parts;
};
class lcPartSelectionItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
2017-07-11 18:09:15 -07:00
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:
lcPartSelectionListModel* mListModel;
};
2024-07-11 15:04:07 -07:00
struct lcPartSelectionListModelEntry
{
PieceInfo* Info = nullptr;
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 GetPieceInfoIndex(PieceInfo* Info) const;
2017-04-20 18:56:35 -07:00
PieceInfo* GetPieceInfo(const QModelIndex& Index) const
{
2024-07-11 15:04:07 -07:00
return Index.isValid() ? mParts[Index.row()].Info : nullptr;
}
PieceInfo* GetPieceInfo(int Row) const
{
2024-07-11 15:04:07 -07:00
return mParts[Row].Info;
}
2017-07-11 18:09:15 -07:00
bool GetShowDecoratedParts() const
{
return mShowDecoratedParts;
}
bool GetShowPartAliases() const
{
return mShowPartAliases;
}
2017-01-27 18:20:44 -08:00
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;
}
2024-07-11 15:04:07 -07:00
void UpdateThumbnails();
void SetColorIndex(int ColorIndex);
void ToggleColorLocked();
void ToggleListMode();
void SetCategory(int CategoryIndex);
2016-12-18 18:53:25 -08:00
void SetModelsCategory();
2019-12-08 19:19:02 -08:00
void SetPaletteCategory(int SetIndex);
void SetCurrentModelCategory();
2017-07-11 18:09:15 -07:00
void SetFilter(const QString& Filter);
2024-07-11 15:04:07 -07:00
void RequestThumbnail(int PartIndex);
2017-07-11 18:09:15 -07:00
void SetShowDecoratedParts(bool Show);
void SetShowPartAliases(bool Show);
void SetIconSize(int Size);
2017-01-27 18:20:44 -08:00
void SetShowPartNames(bool Show);
2017-01-10 17:48:05 -08:00
protected slots:
2024-07-11 15:04:07 -07:00
void ThumbnailReady(lcPartThumbnailId ThumbnailId, QPixmap Pixmap);
2017-01-10 17:48:05 -08:00
protected:
2024-07-11 15:04:07 -07:00
void ReleaseThumbnails();
2017-01-22 19:28:05 -08:00
2017-01-10 17:48:05 -08:00
lcPartSelectionListView* mListView;
2024-07-11 15:04:07 -07:00
std::vector<lcPartSelectionListModelEntry> mParts;
int mIconSize;
bool mColorLocked;
int mColorIndex;
2017-01-27 18:20:44 -08:00
bool mShowPartNames;
bool mListMode;
2017-07-11 18:09:15 -07:00
bool mShowDecoratedParts;
bool mShowPartAliases;
2017-07-11 18:09:15 -07:00
QByteArray mFilter;
};
class lcPartSelectionListView : public QListView
{
Q_OBJECT
public:
2019-12-08 16:54:12 -08:00
lcPartSelectionListView(QWidget* Parent, lcPartSelectionWidget* PartSelectionWidget);
void startDrag(Qt::DropActions SupportedActions) override;
2019-12-08 16:54:12 -08:00
void SetCategory(lcPartCategoryType Type, int Index);
void SetCurrentPart(PieceInfo* Info);
2019-12-08 16:54:12 -08:00
PieceInfo* GetCurrentPart() const
{
2017-07-11 18:09:15 -07:00
return mListModel->GetPieceInfo(currentIndex());
}
lcPartSelectionListModel* GetListModel() const
{
return mListModel;
}
2019-12-08 16:54:12 -08:00
lcPartSelectionWidget* GetPartSelectionWidget() const
{
return mPartSelectionWidget;
}
PieceInfo* GetContextInfo() const
{
return mContextInfo;
}
2019-12-08 16:54:12 -08:00
void UpdateViewMode();
2019-12-07 09:52:46 -08:00
public slots:
void CustomContextMenuRequested(QPoint Pos);
2017-01-27 18:20:44 -08:00
void SetNoIcons();
void SetSmallIcons();
void SetMediumIcons();
void SetLargeIcons();
void SetExtraLargeIcons();
2017-01-27 18:20:44 -08:00
void TogglePartNames();
void ToggleDecoratedParts();
void TogglePartAliases();
void ToggleListMode();
void ToggleFixedColor();
protected:
void SetIconSize(int Size);
lcPartSelectionListModel* mListModel;
2019-12-08 16:54:12 -08:00
lcPartSelectionWidget* mPartSelectionWidget;
2019-12-07 11:23:50 -08:00
PieceInfo* mContextInfo;
2019-12-08 16:54:12 -08:00
lcPartCategoryType mCategoryType;
int mCategoryIndex;
};
class lcPartSelectionWidget : public QWidget
{
Q_OBJECT
public:
lcPartSelectionWidget(QWidget* Parent);
2024-07-11 15:04:07 -07:00
void UpdateThumbnails();
2016-12-28 13:30:31 -08:00
void SetDefaultPart();
2016-12-18 18:53:25 -08:00
void UpdateModels();
2016-12-20 14:11:19 -08:00
void UpdateCategories();
2017-02-06 09:06:52 -08:00
void LoadState(QSettings& Settings);
void SaveState(QSettings& Settings);
void DisableIconMode();
void SetOrientation(Qt::Orientation Orientation);
void SetCurrentPart(PieceInfo* Info);
int GetColorIndex() const
{
return mPartsWidget->GetListModel()->GetColorIndex();
}
2016-12-18 18:53:25 -08:00
void SetColorIndex(int ColorIndex)
{
mPartsWidget->GetListModel()->SetColorIndex(ColorIndex);
}
2019-12-08 19:19:02 -08:00
const std::vector<lcPartPalette>& GetPartPalettes() const
2019-12-08 16:54:12 -08:00
{
2019-12-08 19:19:02 -08:00
return mPartPalettes;
2019-12-08 16:54:12 -08:00
}
PieceInfo* GetCurrentPart() const
{
return mPartsWidget->GetCurrentPart();
}
signals:
2024-07-25 17:56:29 -07:00
void PartPicked(PieceInfo* Info);
void CurrentPartChanged(PieceInfo* Info);
2019-12-08 16:54:12 -08:00
public slots:
2019-12-08 19:19:02 -08:00
void AddToPalette();
void RemoveFromPalette();
void DockLocationChanged(Qt::DockWidgetArea Area);
2019-12-08 16:54:12 -08:00
protected slots:
void FilterChanged(const QString& Text);
2023-04-18 00:59:12 +02:00
void FilterCategoriesChanged(const QString& Text);
2017-01-31 21:12:30 -08:00
void FilterTriggered();
2023-04-19 13:07:46 +02:00
void FilterCaseTriggered();
2023-04-18 00:59:12 +02:00
void FilterCategoriesTriggered();
void CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous);
void PartViewSelectionChanged(const QModelIndex& Current, const QModelIndex& Previous);
void PartViewDoubleClicked(const QModelIndex& Index);
2019-12-08 16:54:12 -08:00
void OptionsMenuAboutToShow();
2019-12-15 19:01:55 -08:00
void EditPartPalettes();
protected:
2019-12-08 19:19:02 -08:00
void LoadPartPalettes();
void SavePartPalettes();
2019-12-08 16:54:12 -08:00
void resizeEvent(QResizeEvent* Event) override;
bool event(QEvent* Event) override;
2024-07-25 17:56:29 -07:00
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;
2019-12-08 19:19:02 -08:00
std::vector<lcPartPalette> mPartPalettes;
};