2016-12-16 18:14:19 +01:00
|
|
|
#include "lc_global.h"
|
|
|
|
#include "lc_partselectionwidget.h"
|
2016-12-20 23:46:12 +01:00
|
|
|
#include "lc_profile.h"
|
2016-12-16 18:14:19 +01:00
|
|
|
#include "lc_application.h"
|
2017-02-04 22:14:41 +01:00
|
|
|
#include "lc_mainwindow.h"
|
2016-12-16 18:14:19 +01:00
|
|
|
#include "lc_library.h"
|
2016-12-19 03:53:25 +01:00
|
|
|
#include "lc_model.h"
|
|
|
|
#include "project.h"
|
2016-12-16 18:14:19 +01:00
|
|
|
#include "pieceinf.h"
|
2017-02-06 23:20:09 +01:00
|
|
|
#include "view.h"
|
2017-06-22 06:40:26 +02:00
|
|
|
#include "lc_glextensions.h"
|
2017-02-06 23:20:09 +01:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QList<int>)
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
void lcPartSelectionItemDelegate::paint(QPainter* Painter, const QStyleOptionViewItem& Option, const QModelIndex& Index) const
|
|
|
|
{
|
2017-07-12 03:09:15 +02:00
|
|
|
mListModel->RequestPreview(Index.row());
|
2016-12-16 18:14:19 +01:00
|
|
|
QStyledItemDelegate::paint(Painter, Option, Index);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize lcPartSelectionItemDelegate::sizeHint(const QStyleOptionViewItem& Option, const QModelIndex& Index) const
|
|
|
|
{
|
2017-02-03 09:31:37 +01:00
|
|
|
QSize Size = QStyledItemDelegate::sizeHint(Option, Index);
|
|
|
|
int IconSize = mListModel->GetIconSize();
|
|
|
|
|
|
|
|
if (IconSize)
|
|
|
|
{
|
|
|
|
QWidget* Widget = (QWidget*)parent();
|
|
|
|
const int PixmapMargin = Widget->style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &Option, Widget) + 1;
|
|
|
|
int PixmapWidth = IconSize + 2 * PixmapMargin;
|
|
|
|
Size.setWidth(qMin(PixmapWidth, Size.width()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Size;
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
|
|
|
|
: QAbstractListModel(Parent)
|
|
|
|
{
|
2017-01-11 02:48:05 +01:00
|
|
|
mListView = (lcPartSelectionListView*)Parent;
|
2016-12-20 23:46:12 +01:00
|
|
|
mIconSize = 0;
|
2017-01-28 03:20:44 +01:00
|
|
|
mShowPartNames = lcGetProfileInt(LC_PROFILE_PARTS_LIST_NAMES);
|
2017-05-29 23:03:46 +02:00
|
|
|
mListMode = lcGetProfileInt(LC_PROFILE_PARTS_LIST_LISTMODE);
|
2017-07-12 03:09:15 +02:00
|
|
|
mShowDecoratedParts = lcGetProfileInt(LC_PROFILE_PARTS_LIST_DECORATED);
|
2017-01-23 04:28:05 +01:00
|
|
|
|
2017-02-04 22:14:41 +01:00
|
|
|
int ColorCode = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR);
|
|
|
|
if (ColorCode == -1)
|
2017-02-05 04:37:40 +01:00
|
|
|
{
|
|
|
|
mColorIndex = gMainWindow->mColorIndex;
|
2017-02-04 22:14:41 +01:00
|
|
|
mColorLocked = false;
|
2017-02-05 04:37:40 +01:00
|
|
|
}
|
2017-02-04 22:14:41 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mColorIndex = lcGetColorIndex(ColorCode);
|
|
|
|
mColorLocked = true;
|
|
|
|
}
|
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
connect(lcGetPiecesLibrary(), SIGNAL(PartLoaded(PieceInfo*)), this, SLOT(PartLoaded(PieceInfo*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
lcPartSelectionListModel::~lcPartSelectionListModel()
|
|
|
|
{
|
|
|
|
ClearRequests();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListModel::ClearRequests()
|
|
|
|
{
|
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
|
|
|
|
2018-02-22 01:12:18 +01:00
|
|
|
for (int RequestIdx : mRequestedPreviews)
|
2017-01-23 04:28:05 +01:00
|
|
|
{
|
|
|
|
PieceInfo* Info = mParts[RequestIdx].first;
|
|
|
|
Library->ReleasePieceInfo(Info);
|
|
|
|
}
|
|
|
|
|
|
|
|
mRequestedPreviews.clear();
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
void lcPartSelectionListModel::Redraw()
|
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
ClearRequests();
|
|
|
|
|
2016-12-29 16:28:53 +01:00
|
|
|
beginResetModel();
|
|
|
|
|
2019-05-28 20:10:21 +02:00
|
|
|
for (size_t PartIdx = 0; PartIdx < mParts.size(); PartIdx++)
|
2016-12-29 16:28:53 +01:00
|
|
|
mParts[PartIdx].second = QPixmap();
|
|
|
|
|
|
|
|
endResetModel();
|
2017-09-12 03:26:50 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
2016-12-29 16:28:53 +01:00
|
|
|
}
|
|
|
|
|
2017-02-04 22:14:41 +01:00
|
|
|
void lcPartSelectionListModel::SetColorIndex(int ColorIndex)
|
|
|
|
{
|
|
|
|
if (mColorLocked || ColorIndex == mColorIndex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mColorIndex = ColorIndex;
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListModel::ToggleColorLocked()
|
|
|
|
{
|
|
|
|
mColorLocked = !mColorLocked;
|
|
|
|
|
|
|
|
SetColorIndex(gMainWindow->mColorIndex);
|
|
|
|
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR, mColorLocked ? lcGetColorCode(mColorIndex) : -1);
|
|
|
|
}
|
|
|
|
|
2017-05-29 23:03:46 +02:00
|
|
|
void lcPartSelectionListModel::ToggleListMode()
|
|
|
|
{
|
|
|
|
mListMode = !mListMode;
|
|
|
|
|
|
|
|
mListView->UpdateViewMode();
|
|
|
|
lcSetProfileInt(LC_PROFILE_PARTS_LIST_LISTMODE, mListMode);
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
void lcPartSelectionListModel::SetCategory(int CategoryIndex)
|
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
ClearRequests();
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
beginResetModel();
|
|
|
|
|
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
|
|
|
lcArray<PieceInfo*> SingleParts, GroupedParts;
|
|
|
|
|
2017-02-01 06:12:30 +01:00
|
|
|
if (CategoryIndex != -1)
|
|
|
|
Library->GetCategoryEntries(CategoryIndex, false, SingleParts, GroupedParts);
|
|
|
|
else
|
2017-12-21 23:12:01 +01:00
|
|
|
{
|
2017-02-01 06:12:30 +01:00
|
|
|
Library->GetParts(SingleParts);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2018-04-18 01:08:29 +02:00
|
|
|
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
2017-12-21 23:12:01 +01:00
|
|
|
|
|
|
|
for (int PartIdx = 0; PartIdx < SingleParts.GetSize(); )
|
|
|
|
{
|
|
|
|
PieceInfo* Info = SingleParts[PartIdx];
|
|
|
|
|
2018-04-18 01:08:29 +02:00
|
|
|
if (!Info->IsModel() || !Info->GetModel()->IncludesModel(ActiveModel))
|
2017-12-21 23:12:01 +01:00
|
|
|
PartIdx++;
|
|
|
|
else
|
|
|
|
SingleParts.RemoveIndex(PartIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 03:09:15 +02:00
|
|
|
auto lcPartSortFunc=[](PieceInfo* const& a, PieceInfo* const& b)
|
|
|
|
{
|
|
|
|
return strcmp(a->m_strDescription, b->m_strDescription);
|
|
|
|
};
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
SingleParts.Sort(lcPartSortFunc);
|
|
|
|
mParts.resize(SingleParts.GetSize());
|
|
|
|
|
|
|
|
for (int PartIdx = 0; PartIdx < SingleParts.GetSize(); PartIdx++)
|
2016-12-19 03:53:25 +01:00
|
|
|
mParts[PartIdx] = QPair<PieceInfo*, QPixmap>(SingleParts[PartIdx], QPixmap());
|
|
|
|
|
|
|
|
endResetModel();
|
2017-07-12 03:09:15 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
2016-12-19 03:53:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListModel::SetModelsCategory()
|
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
ClearRequests();
|
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
beginResetModel();
|
|
|
|
|
|
|
|
mParts.clear();
|
|
|
|
|
|
|
|
const lcArray<lcModel*>& Models = lcGetActiveProject()->GetModels();
|
2018-04-18 01:08:29 +02:00
|
|
|
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
2016-12-19 03:53:25 +01:00
|
|
|
|
|
|
|
for (int ModelIdx = 0; ModelIdx < Models.GetSize(); ModelIdx++)
|
|
|
|
{
|
|
|
|
lcModel* Model = Models[ModelIdx];
|
|
|
|
|
2018-04-18 01:08:29 +02:00
|
|
|
if (!Model->IncludesModel(ActiveModel))
|
2019-05-28 01:22:49 +02:00
|
|
|
mParts.emplace_back(QPair<PieceInfo*, QPixmap>(Model->GetPieceInfo(), QPixmap()));
|
2016-12-19 03:53:25 +01:00
|
|
|
}
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
endResetModel();
|
2017-07-12 03:09:15 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
2017-01-27 04:02:42 +01:00
|
|
|
void lcPartSelectionListModel::SetCurrentModelCategory()
|
|
|
|
{
|
|
|
|
ClearRequests();
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
|
|
|
|
mParts.clear();
|
|
|
|
|
2018-04-18 01:08:29 +02:00
|
|
|
lcModel* ActiveModel = gMainWindow->GetActiveModel();
|
2017-01-27 04:02:42 +01:00
|
|
|
lcPartsList PartsList;
|
2018-04-18 01:08:29 +02:00
|
|
|
ActiveModel->GetPartsList(gDefaultColor, true, PartsList);
|
2017-01-27 04:02:42 +01:00
|
|
|
|
2017-04-16 00:54:17 +02:00
|
|
|
for (const auto& PartIt : PartsList)
|
2019-05-28 01:22:49 +02:00
|
|
|
mParts.emplace_back(QPair<PieceInfo*, QPixmap>((PieceInfo*)PartIt.first, QPixmap()));
|
2017-01-27 04:02:42 +01:00
|
|
|
|
|
|
|
endResetModel();
|
2017-07-12 03:09:15 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListModel::SetFilter(const QString& Filter)
|
|
|
|
{
|
|
|
|
mFilter = Filter.toLatin1();
|
|
|
|
|
2019-05-28 20:10:21 +02:00
|
|
|
for (size_t PartIdx = 0; PartIdx < mParts.size(); PartIdx++)
|
2017-07-12 03:09:15 +02:00
|
|
|
{
|
|
|
|
PieceInfo* Info = mParts[PartIdx].first;
|
|
|
|
bool Visible;
|
|
|
|
|
|
|
|
if (!mShowDecoratedParts && Info->IsPatterned())
|
|
|
|
Visible = false;
|
|
|
|
else if (mFilter.isEmpty())
|
|
|
|
Visible = true;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char Description[sizeof(Info->m_strDescription)];
|
|
|
|
char* Src = Info->m_strDescription;
|
|
|
|
char* Dst = Description;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
*Dst = *Src;
|
|
|
|
|
|
|
|
if (*Src == ' ' && *(Src + 1) == ' ')
|
|
|
|
Src++;
|
|
|
|
else if (*Src == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Src++;
|
|
|
|
Dst++;
|
|
|
|
}
|
|
|
|
|
2017-07-27 18:21:55 +02:00
|
|
|
Visible = strcasestr(Description, mFilter) || strcasestr(Info->mFileName, mFilter);
|
2017-07-12 03:09:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mListView->setRowHidden(PartIdx, !Visible);
|
|
|
|
}
|
2017-01-27 04:02:42 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
int lcPartSelectionListModel::rowCount(const QModelIndex& Parent) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(Parent);
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2019-05-28 01:22:49 +02:00
|
|
|
return (int)mParts.size();
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant lcPartSelectionListModel::data(const QModelIndex& Index, int Role) const
|
|
|
|
{
|
2019-05-28 20:10:21 +02:00
|
|
|
size_t InfoIndex = Index.row();
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
if (Index.isValid() && InfoIndex < mParts.size())
|
|
|
|
{
|
2016-12-20 23:46:12 +01:00
|
|
|
PieceInfo* Info = mParts[InfoIndex].first;
|
|
|
|
|
|
|
|
switch (Role)
|
2016-12-16 21:52:36 +01:00
|
|
|
{
|
2016-12-20 23:46:12 +01:00
|
|
|
case Qt::DisplayRole:
|
2017-05-29 23:03:46 +02:00
|
|
|
if (!mIconSize || mShowPartNames || mListMode)
|
2016-12-20 23:46:12 +01:00
|
|
|
return QVariant(QString::fromLatin1(Info->m_strDescription));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Qt::ToolTipRole:
|
2017-07-27 18:21:55 +02:00
|
|
|
return QVariant(QString("%1 (%2)").arg(QString::fromLatin1(Info->m_strDescription), QString::fromLatin1(Info->mFileName)));
|
2016-12-20 23:46:12 +01:00
|
|
|
|
|
|
|
case Qt::DecorationRole:
|
2017-01-28 03:20:44 +01:00
|
|
|
if (!mParts[InfoIndex].second.isNull() && mIconSize)
|
2016-12-16 18:14:19 +01:00
|
|
|
return QVariant(mParts[InfoIndex].second);
|
|
|
|
else
|
|
|
|
return QVariant(QColor(0, 0, 0, 0));
|
2016-12-20 23:46:12 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant lcPartSelectionListModel::headerData(int Section, Qt::Orientation Orientation, int Role) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(Section);
|
|
|
|
Q_UNUSED(Orientation);
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2016-12-19 23:23:26 +01:00
|
|
|
return Role == Qt::DisplayRole ? QVariant(QLatin1String("Image")) : QVariant();
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Qt::ItemFlags lcPartSelectionListModel::flags(const QModelIndex& Index) const
|
|
|
|
{
|
|
|
|
Qt::ItemFlags DefaultFlags = QAbstractListModel::flags(Index);
|
|
|
|
|
|
|
|
if (Index.isValid())
|
|
|
|
return Qt::ItemIsDragEnabled | DefaultFlags;
|
|
|
|
else
|
|
|
|
return DefaultFlags;
|
|
|
|
}
|
|
|
|
|
2017-01-04 15:45:01 +01:00
|
|
|
void lcPartSelectionListModel::RequestPreview(int InfoIndex)
|
2016-12-16 18:14:19 +01:00
|
|
|
{
|
2016-12-20 23:46:12 +01:00
|
|
|
if (!mIconSize || !mParts[InfoIndex].second.isNull())
|
2016-12-19 03:53:25 +01:00
|
|
|
return;
|
|
|
|
|
2019-05-28 01:22:49 +02:00
|
|
|
if (std::find(mRequestedPreviews.begin(), mRequestedPreviews.end(), InfoIndex) != mRequestedPreviews.end())
|
2017-01-23 04:28:05 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
PieceInfo* Info = mParts[InfoIndex].first;
|
|
|
|
lcGetPiecesLibrary()->LoadPieceInfo(Info, false, false);
|
|
|
|
|
|
|
|
if (Info->mState == LC_PIECEINFO_LOADED)
|
|
|
|
DrawPreview(InfoIndex);
|
|
|
|
else
|
2019-05-28 01:22:49 +02:00
|
|
|
mRequestedPreviews.push_back(InfoIndex);
|
2017-01-04 15:45:01 +01:00
|
|
|
}
|
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
void lcPartSelectionListModel::PartLoaded(PieceInfo* Info)
|
2017-01-04 15:45:01 +01:00
|
|
|
{
|
2019-05-28 20:10:21 +02:00
|
|
|
for (size_t PartIdx = 0; PartIdx < mParts.size(); PartIdx++)
|
2017-01-04 15:45:01 +01:00
|
|
|
{
|
2017-01-23 04:28:05 +01:00
|
|
|
if (mParts[PartIdx].first == Info)
|
|
|
|
{
|
2019-05-28 01:22:49 +02:00
|
|
|
auto PreviewIt = std::find(mRequestedPreviews.begin(), mRequestedPreviews.end(), PartIdx);
|
|
|
|
if (PreviewIt != mRequestedPreviews.end())
|
|
|
|
{
|
|
|
|
mRequestedPreviews.erase(PreviewIt);
|
2017-01-25 04:49:49 +01:00
|
|
|
DrawPreview(PartIdx);
|
2019-05-28 01:22:49 +02:00
|
|
|
}
|
2017-01-23 04:28:05 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-01-04 15:45:01 +01:00
|
|
|
}
|
2017-01-23 04:28:05 +01:00
|
|
|
}
|
2017-01-04 15:45:01 +01:00
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
void lcPartSelectionListModel::DrawPreview(int InfoIndex)
|
|
|
|
{
|
2018-01-16 01:36:50 +01:00
|
|
|
View* ActiveView = gMainWindow->GetActiveView();
|
|
|
|
if (!ActiveView)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ActiveView->MakeCurrent();
|
|
|
|
lcContext* Context = ActiveView->mContext;
|
2017-02-09 02:47:30 +01:00
|
|
|
int Width = mIconSize * 2;
|
|
|
|
int Height = mIconSize * 2;
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-12-29 15:50:18 +01:00
|
|
|
if (mRenderFramebuffer.first.mWidth != Width || mRenderFramebuffer.first.mHeight != Height)
|
|
|
|
{
|
|
|
|
Context->DestroyRenderFramebuffer(mRenderFramebuffer);
|
|
|
|
mRenderFramebuffer = Context->CreateRenderFramebuffer(Width, Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mRenderFramebuffer.first.IsValid())
|
2016-12-19 03:53:25 +01:00
|
|
|
return;
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
float Aspect = (float)Width / (float)Height;
|
|
|
|
Context->SetViewport(0, 0, Width, Height);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
Context->SetDefaultState();
|
2017-12-29 15:50:18 +01:00
|
|
|
Context->BindFramebuffer(mRenderFramebuffer.first);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
lcPiecesLibrary* Library = lcGetPiecesLibrary();
|
2016-12-19 03:53:25 +01:00
|
|
|
PieceInfo* Info = mParts[InfoIndex].first;
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-12-21 23:02:16 +01:00
|
|
|
lcMatrix44 ProjectionMatrix, ViewMatrix;
|
|
|
|
|
|
|
|
Info->ZoomExtents(20.0f, Aspect, ProjectionMatrix, ViewMatrix);
|
|
|
|
|
|
|
|
Context->SetProjectionMatrix(ProjectionMatrix);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
lcScene Scene;
|
2018-04-08 00:28:44 +02:00
|
|
|
Scene.SetAllowWireframe(false);
|
2016-12-19 03:53:25 +01:00
|
|
|
Scene.Begin(ViewMatrix);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2019-03-06 10:59:13 +01:00
|
|
|
Info->AddRenderMeshes(Scene, lcMatrix44Identity(), mColorIndex, lcRenderMeshState::NORMAL, false);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
Scene.End();
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-04-02 01:53:54 +02:00
|
|
|
Scene.Draw(Context);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-12-29 15:50:18 +01:00
|
|
|
mParts[InfoIndex].second = QPixmap::fromImage(Context->GetRenderFramebufferImage(mRenderFramebuffer)).scaled(mIconSize, mIconSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2017-03-25 20:29:28 +01:00
|
|
|
Library->ReleasePieceInfo(Info);
|
|
|
|
|
2017-12-29 15:50:18 +01:00
|
|
|
Context->ClearFramebuffer();
|
2017-03-25 20:29:28 +01:00
|
|
|
Context->ClearResources();
|
2016-12-16 18:14:19 +01:00
|
|
|
|
2016-12-19 23:23:26 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
2019-05-28 01:22:49 +02:00
|
|
|
QVector<int> Roles;
|
|
|
|
Roles.append(Qt::DecorationRole);
|
|
|
|
emit dataChanged(index(InfoIndex, 0), index(InfoIndex, 0), Roles);
|
2016-12-19 23:23:26 +01:00
|
|
|
#else
|
|
|
|
emit dataChanged(index(InfoIndex, 0), index(InfoIndex, 0));
|
|
|
|
#endif
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
2017-07-12 03:09:15 +02:00
|
|
|
void lcPartSelectionListModel::SetShowDecoratedParts(bool Show)
|
|
|
|
{
|
|
|
|
if (Show == mShowDecoratedParts)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mShowDecoratedParts = Show;
|
|
|
|
|
|
|
|
SetFilter(mFilter);
|
|
|
|
}
|
|
|
|
|
2016-12-20 23:46:12 +01:00
|
|
|
void lcPartSelectionListModel::SetIconSize(int Size)
|
|
|
|
{
|
|
|
|
if (Size == mIconSize)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mIconSize = Size;
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
|
2019-05-28 20:10:21 +02:00
|
|
|
for (size_t PartIdx = 0; PartIdx < mParts.size(); PartIdx++)
|
2016-12-20 23:46:12 +01:00
|
|
|
mParts[PartIdx].second = QPixmap();
|
|
|
|
|
|
|
|
endResetModel();
|
2017-09-12 03:26:50 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
2016-12-20 23:46:12 +01:00
|
|
|
}
|
|
|
|
|
2017-01-28 03:20:44 +01:00
|
|
|
void lcPartSelectionListModel::SetShowPartNames(bool Show)
|
|
|
|
{
|
|
|
|
if (Show == mShowPartNames)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mShowPartNames = Show;
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
2017-09-12 03:26:50 +02:00
|
|
|
|
|
|
|
SetFilter(mFilter);
|
2017-01-28 03:20:44 +01:00
|
|
|
}
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent)
|
|
|
|
: QListView(Parent)
|
|
|
|
{
|
|
|
|
setUniformItemSizes(true);
|
|
|
|
setResizeMode(QListView::Adjust);
|
2017-02-03 09:31:37 +01:00
|
|
|
setWordWrap(false);
|
2016-12-16 18:14:19 +01:00
|
|
|
setDragEnabled(true);
|
2016-12-20 23:46:12 +01:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
mListModel = new lcPartSelectionListModel(this);
|
2017-07-12 03:09:15 +02:00
|
|
|
setModel(mListModel);
|
|
|
|
lcPartSelectionItemDelegate* ItemDelegate = new lcPartSelectionItemDelegate(this, mListModel);
|
2016-12-16 18:14:19 +01:00
|
|
|
setItemDelegate(ItemDelegate);
|
2016-12-20 23:46:12 +01:00
|
|
|
|
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(CustomContextMenuRequested(QPoint)));
|
|
|
|
|
|
|
|
SetIconSize(lcGetProfileInt(LC_PROFILE_PARTS_LIST_ICONS));
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
|
|
|
|
{
|
|
|
|
QMenu* Menu = new QMenu(this);
|
|
|
|
|
2017-06-22 06:40:26 +02:00
|
|
|
if (gSupportsFramebufferObjectARB || gSupportsFramebufferObjectEXT)
|
|
|
|
{
|
|
|
|
QActionGroup* IconGroup = new QActionGroup(Menu);
|
|
|
|
|
|
|
|
QAction* NoIcons = Menu->addAction(tr("No Icons"), this, SLOT(SetNoIcons()));
|
|
|
|
NoIcons->setCheckable(true);
|
|
|
|
NoIcons->setChecked(mListModel->GetIconSize() == 0);
|
|
|
|
IconGroup->addAction(NoIcons);
|
|
|
|
|
|
|
|
QAction* SmallIcons = Menu->addAction(tr("Small Icons"), this, SLOT(SetSmallIcons()));
|
|
|
|
SmallIcons->setCheckable(true);
|
|
|
|
SmallIcons->setChecked(mListModel->GetIconSize() == 32);
|
|
|
|
IconGroup->addAction(SmallIcons);
|
|
|
|
|
|
|
|
QAction* MediumIcons = Menu->addAction(tr("Medium Icons"), this, SLOT(SetMediumIcons()));
|
|
|
|
MediumIcons->setCheckable(true);
|
|
|
|
MediumIcons->setChecked(mListModel->GetIconSize() == 64);
|
|
|
|
IconGroup->addAction(MediumIcons);
|
|
|
|
|
|
|
|
QAction* LargeIcons = Menu->addAction(tr("Large Icons"), this, SLOT(SetLargeIcons()));
|
|
|
|
LargeIcons->setCheckable(true);
|
|
|
|
LargeIcons->setChecked(mListModel->GetIconSize() == 96);
|
|
|
|
IconGroup->addAction(LargeIcons);
|
|
|
|
|
|
|
|
QAction* ExtraLargeIcons = Menu->addAction(tr("Extra Large Icons"), this, SLOT(SetExtraLargeIcons()));
|
|
|
|
ExtraLargeIcons->setCheckable(true);
|
|
|
|
ExtraLargeIcons->setChecked(mListModel->GetIconSize() == 192);
|
|
|
|
IconGroup->addAction(ExtraLargeIcons);
|
|
|
|
|
|
|
|
Menu->addSeparator();
|
|
|
|
}
|
2017-01-28 03:20:44 +01:00
|
|
|
|
2017-05-29 23:03:46 +02:00
|
|
|
if (mListModel->GetIconSize() != 0 && !mListModel->IsListMode())
|
2017-01-28 03:20:44 +01:00
|
|
|
{
|
2017-02-04 22:14:41 +01:00
|
|
|
QAction* PartNames = Menu->addAction(tr("Show Part Names"), this, SLOT(TogglePartNames()));
|
2017-01-28 03:20:44 +01:00
|
|
|
PartNames->setCheckable(true);
|
|
|
|
PartNames->setChecked(mListModel->GetShowPartNames());
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:14:41 +01:00
|
|
|
QAction* DecoratedParts = Menu->addAction(tr("Show Decorated Parts"), this, SLOT(ToggleDecoratedParts()));
|
|
|
|
DecoratedParts->setCheckable(true);
|
2017-07-12 03:09:15 +02:00
|
|
|
DecoratedParts->setChecked(mListModel->GetShowDecoratedParts());
|
2017-02-04 22:14:41 +01:00
|
|
|
|
2017-06-22 06:40:26 +02:00
|
|
|
if (mListModel->GetIconSize() != 0)
|
|
|
|
{
|
|
|
|
QAction* ListMode = Menu->addAction(tr("List Mode"), this, SLOT(ToggleListMode()));
|
|
|
|
ListMode->setCheckable(true);
|
|
|
|
ListMode->setChecked(mListModel->IsListMode());
|
2017-05-29 23:03:46 +02:00
|
|
|
|
2017-06-22 06:40:26 +02:00
|
|
|
QAction* FixedColor = Menu->addAction(tr("Lock Preview Color"), this, SLOT(ToggleFixedColor()));
|
|
|
|
FixedColor->setCheckable(true);
|
|
|
|
FixedColor->setChecked(mListModel->IsColorLocked());
|
|
|
|
}
|
2016-12-20 23:46:12 +01:00
|
|
|
|
|
|
|
Menu->popup(viewport()->mapToGlobal(Pos));
|
|
|
|
}
|
|
|
|
|
2017-01-28 03:20:44 +01:00
|
|
|
void lcPartSelectionListView::SetNoIcons()
|
|
|
|
{
|
|
|
|
SetIconSize(0);
|
|
|
|
}
|
|
|
|
|
2016-12-20 23:46:12 +01:00
|
|
|
void lcPartSelectionListView::SetSmallIcons()
|
|
|
|
{
|
|
|
|
SetIconSize(32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListView::SetMediumIcons()
|
|
|
|
{
|
|
|
|
SetIconSize(64);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListView::SetLargeIcons()
|
|
|
|
{
|
|
|
|
SetIconSize(96);
|
|
|
|
}
|
|
|
|
|
2017-02-09 02:47:30 +01:00
|
|
|
void lcPartSelectionListView::SetExtraLargeIcons()
|
|
|
|
{
|
|
|
|
SetIconSize(192);
|
|
|
|
}
|
|
|
|
|
2017-01-28 03:20:44 +01:00
|
|
|
void lcPartSelectionListView::TogglePartNames()
|
2016-12-20 23:46:12 +01:00
|
|
|
{
|
2017-01-28 03:20:44 +01:00
|
|
|
bool Show = !mListModel->GetShowPartNames();
|
|
|
|
mListModel->SetShowPartNames(Show);
|
|
|
|
lcSetProfileInt(LC_PROFILE_PARTS_LIST_NAMES, Show);
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:14:41 +01:00
|
|
|
void lcPartSelectionListView::ToggleDecoratedParts()
|
|
|
|
{
|
2017-07-12 03:09:15 +02:00
|
|
|
bool Show = !mListModel->GetShowDecoratedParts();
|
|
|
|
mListModel->SetShowDecoratedParts(Show);
|
2017-02-04 22:14:41 +01:00
|
|
|
lcSetProfileInt(LC_PROFILE_PARTS_LIST_DECORATED, Show);
|
|
|
|
}
|
|
|
|
|
2017-05-29 23:03:46 +02:00
|
|
|
void lcPartSelectionListView::ToggleListMode()
|
|
|
|
{
|
|
|
|
mListModel->ToggleListMode();
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:14:41 +01:00
|
|
|
void lcPartSelectionListView::ToggleFixedColor()
|
2017-01-28 03:20:44 +01:00
|
|
|
{
|
2017-02-04 22:14:41 +01:00
|
|
|
mListModel->ToggleColorLocked();
|
2016-12-20 23:46:12 +01:00
|
|
|
}
|
|
|
|
|
2017-05-29 23:03:46 +02:00
|
|
|
void lcPartSelectionListView::UpdateViewMode()
|
|
|
|
{
|
|
|
|
setViewMode(mListModel->GetIconSize() && !mListModel->IsListMode() ? QListView::IconMode : QListView::ListMode);
|
|
|
|
setWordWrap(mListModel->IsListMode());
|
2017-11-20 02:58:32 +01:00
|
|
|
setDragEnabled(true);
|
2017-05-29 23:03:46 +02:00
|
|
|
}
|
|
|
|
|
2016-12-20 23:46:12 +01:00
|
|
|
void lcPartSelectionListView::SetIconSize(int Size)
|
|
|
|
{
|
|
|
|
setIconSize(QSize(Size, Size));
|
|
|
|
lcSetProfileInt(LC_PROFILE_PARTS_LIST_ICONS, Size);
|
|
|
|
mListModel->SetIconSize(Size);
|
2017-05-29 23:03:46 +02:00
|
|
|
UpdateViewMode();
|
2019-05-12 01:07:27 +02:00
|
|
|
|
|
|
|
int Width = Size + 2 * frameWidth() + 6;
|
|
|
|
if (verticalScrollBar())
|
|
|
|
Width += verticalScrollBar()->sizeHint().width();
|
|
|
|
int Height = Size + 2 * frameWidth() + 2;
|
|
|
|
if (horizontalScrollBar())
|
|
|
|
Height += horizontalScrollBar()->sizeHint().height();
|
|
|
|
setMinimumSize(Width, Height);
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)
|
|
|
|
{
|
|
|
|
Q_UNUSED(SupportedActions);
|
|
|
|
|
|
|
|
PieceInfo* Info = GetCurrentPart();
|
|
|
|
|
|
|
|
if (!Info)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QByteArray ItemData;
|
|
|
|
QDataStream DataStream(&ItemData, QIODevice::WriteOnly);
|
2017-07-27 18:21:55 +02:00
|
|
|
DataStream << QString(Info->mFileName);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
QMimeData* MimeData = new QMimeData;
|
|
|
|
MimeData->setData("application/vnd.leocad-part", ItemData);
|
|
|
|
|
|
|
|
QDrag* Drag = new QDrag(this);
|
|
|
|
Drag->setMimeData(MimeData);
|
|
|
|
|
|
|
|
Drag->exec(Qt::CopyAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
lcPartSelectionWidget::lcPartSelectionWidget(QWidget* Parent)
|
2017-04-14 02:26:40 +02:00
|
|
|
: QWidget(Parent), mFilterAction(nullptr)
|
2016-12-16 18:14:19 +01:00
|
|
|
{
|
|
|
|
mSplitter = new QSplitter(this);
|
2017-02-06 18:06:52 +01:00
|
|
|
mSplitter->setOrientation(Qt::Vertical);
|
2016-12-16 18:14:19 +01:00
|
|
|
|
|
|
|
mCategoriesWidget = new QTreeWidget(mSplitter);
|
|
|
|
mCategoriesWidget->setHeaderHidden(true);
|
|
|
|
mCategoriesWidget->setUniformRowHeights(true);
|
|
|
|
mCategoriesWidget->setRootIsDecorated(false);
|
|
|
|
|
|
|
|
QWidget* PartsGroupWidget = new QWidget(mSplitter);
|
|
|
|
|
|
|
|
QVBoxLayout* PartsLayout = new QVBoxLayout();
|
|
|
|
PartsLayout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
PartsGroupWidget->setLayout(PartsLayout);
|
|
|
|
|
|
|
|
mFilterWidget = new QLineEdit(PartsGroupWidget);
|
|
|
|
mFilterWidget->setPlaceholderText(tr("Search Parts"));
|
2016-12-19 23:23:26 +01:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0))
|
2017-02-01 06:12:30 +01:00
|
|
|
mFilterAction = mFilterWidget->addAction(QIcon(":/resources/parts_search.png"), QLineEdit::TrailingPosition);
|
|
|
|
connect(mFilterAction, SIGNAL(triggered()), this, SLOT(FilterTriggered()));
|
2016-12-19 23:23:26 +01:00
|
|
|
#endif
|
2016-12-16 18:14:19 +01:00
|
|
|
PartsLayout->addWidget(mFilterWidget);
|
|
|
|
|
|
|
|
mPartsWidget = new lcPartSelectionListView(PartsGroupWidget);
|
|
|
|
PartsLayout->addWidget(mPartsWidget);
|
|
|
|
|
|
|
|
QHBoxLayout* Layout = new QHBoxLayout(this);
|
|
|
|
Layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
Layout->addWidget(mSplitter);
|
|
|
|
setLayout(Layout);
|
|
|
|
|
2016-12-19 23:23:26 +01:00
|
|
|
connect(mPartsWidget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(PartChanged(const QModelIndex&, const QModelIndex&)));
|
2017-02-01 06:12:30 +01:00
|
|
|
connect(mFilterWidget, SIGNAL(textChanged(const QString&)), this, SLOT(FilterChanged(const QString&)));
|
2016-12-19 23:23:26 +01:00
|
|
|
connect(mCategoriesWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(CategoryChanged(QTreeWidgetItem*, QTreeWidgetItem*)));
|
2016-12-19 03:53:25 +01:00
|
|
|
|
|
|
|
UpdateCategories();
|
2017-02-06 18:06:52 +01:00
|
|
|
|
|
|
|
mSplitter->setStretchFactor(0, 0);
|
|
|
|
mSplitter->setStretchFactor(1, 1);
|
|
|
|
|
|
|
|
connect(Parent, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)), this, SLOT(DockLocationChanged(Qt::DockWidgetArea)));
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-07 05:46:25 +01:00
|
|
|
bool lcPartSelectionWidget::event(QEvent* Event)
|
|
|
|
{
|
|
|
|
if (Event->type() == QEvent::ShortcutOverride)
|
|
|
|
{
|
|
|
|
QKeyEvent* KeyEvent = (QKeyEvent*)Event;
|
|
|
|
int Key = KeyEvent->key();
|
|
|
|
|
|
|
|
if (KeyEvent->modifiers() == Qt::NoModifier && Key >= Qt::Key_A && Key <= Qt::Key_Z)
|
|
|
|
Event->accept();
|
|
|
|
|
|
|
|
switch (Key)
|
|
|
|
{
|
|
|
|
case Qt::Key_Down:
|
|
|
|
case Qt::Key_Up:
|
|
|
|
case Qt::Key_Left:
|
|
|
|
case Qt::Key_Right:
|
|
|
|
case Qt::Key_Home:
|
|
|
|
case Qt::Key_End:
|
|
|
|
case Qt::Key_PageUp:
|
|
|
|
case Qt::Key_PageDown:
|
|
|
|
case Qt::Key_Asterisk:
|
|
|
|
case Qt::Key_Plus:
|
|
|
|
case Qt::Key_Minus:
|
|
|
|
Event->accept();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QWidget::event(Event);
|
|
|
|
}
|
|
|
|
|
2017-02-06 18:06:52 +01:00
|
|
|
void lcPartSelectionWidget::LoadState(QSettings& Settings)
|
2016-12-16 18:14:19 +01:00
|
|
|
{
|
2017-02-06 18:06:52 +01:00
|
|
|
QList<int> Sizes = Settings.value("PartSelectionSplitter").value<QList<int>>();
|
|
|
|
|
|
|
|
if (Sizes.size() != 2)
|
|
|
|
{
|
|
|
|
int Length = mSplitter->orientation() == Qt::Horizontal ? mSplitter->width() : mSplitter->height();
|
|
|
|
Sizes << Length / 3 << 2 * Length / 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSplitter->setSizes(Sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::SaveState(QSettings& Settings)
|
|
|
|
{
|
|
|
|
QList<int> Sizes = mSplitter->sizes();
|
|
|
|
Settings.setValue("PartSelectionSplitter", QVariant::fromValue(Sizes));
|
|
|
|
}
|
|
|
|
|
2017-06-22 06:40:26 +02:00
|
|
|
void lcPartSelectionWidget::DisableIconMode()
|
|
|
|
{
|
|
|
|
mPartsWidget->SetNoIcons();
|
|
|
|
}
|
|
|
|
|
2017-02-06 18:06:52 +01:00
|
|
|
void lcPartSelectionWidget::DockLocationChanged(Qt::DockWidgetArea Area)
|
|
|
|
{
|
|
|
|
if (Area == Qt::LeftDockWidgetArea || Area == Qt::RightDockWidgetArea)
|
2016-12-16 18:14:19 +01:00
|
|
|
mSplitter->setOrientation(Qt::Vertical);
|
2017-02-06 18:06:52 +01:00
|
|
|
else
|
|
|
|
mSplitter->setOrientation(Qt::Horizontal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::resizeEvent(QResizeEvent* Event)
|
|
|
|
{
|
|
|
|
if (((QDockWidget*)parent())->isFloating())
|
|
|
|
{
|
|
|
|
if (Event->size().width() > Event->size().height())
|
|
|
|
mSplitter->setOrientation(Qt::Horizontal);
|
|
|
|
else
|
|
|
|
mSplitter->setOrientation(Qt::Vertical);
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
QWidget::resizeEvent(Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::FilterChanged(const QString& Text)
|
|
|
|
{
|
2017-02-01 06:12:30 +01:00
|
|
|
if (mFilterAction)
|
|
|
|
{
|
|
|
|
if (Text.isEmpty())
|
|
|
|
mFilterAction->setIcon(QIcon(":/resources/parts_search.png"));
|
|
|
|
else
|
|
|
|
mFilterAction->setIcon(QIcon(":/resources/parts_cancel.png"));
|
|
|
|
}
|
|
|
|
|
2017-07-12 03:09:15 +02:00
|
|
|
mPartsWidget->GetListModel()->SetFilter(Text);
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
2017-02-01 06:12:30 +01:00
|
|
|
void lcPartSelectionWidget::FilterTriggered()
|
|
|
|
{
|
|
|
|
mFilterWidget->clear();
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
void lcPartSelectionWidget::CategoryChanged(QTreeWidgetItem* Current, QTreeWidgetItem* Previous)
|
|
|
|
{
|
|
|
|
Q_UNUSED(Previous);
|
2017-01-27 04:02:42 +01:00
|
|
|
lcPartSelectionListModel* ListModel = mPartsWidget->GetListModel();
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2017-01-27 04:02:42 +01:00
|
|
|
if (Current == mModelsCategoryItem)
|
|
|
|
ListModel->SetModelsCategory();
|
|
|
|
else if (Current == mCurrentModelCategoryItem)
|
|
|
|
ListModel->SetCurrentModelCategory();
|
2017-02-01 06:12:30 +01:00
|
|
|
else if (Current == mAllPartsCategoryItem)
|
|
|
|
ListModel->SetCategory(-1);
|
2016-12-19 03:53:25 +01:00
|
|
|
else
|
2017-02-01 06:12:30 +01:00
|
|
|
ListModel->SetCategory(mCategoriesWidget->indexOfTopLevelItem(Current) - 2);
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2017-07-12 03:09:15 +02:00
|
|
|
mPartsWidget->setCurrentIndex(ListModel->index(0, 0));
|
2016-12-16 18:14:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::PartChanged(const QModelIndex& Current, const QModelIndex& Previous)
|
|
|
|
{
|
2016-12-19 03:53:25 +01:00
|
|
|
Q_UNUSED(Current);
|
|
|
|
Q_UNUSED(Previous);
|
|
|
|
|
2016-12-16 18:14:19 +01:00
|
|
|
gMainWindow->SetCurrentPieceInfo(mPartsWidget->GetCurrentPart());
|
2016-12-16 21:52:36 +01:00
|
|
|
}
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2016-12-28 22:30:31 +01:00
|
|
|
void lcPartSelectionWidget::Redraw()
|
|
|
|
{
|
2016-12-29 16:28:53 +01:00
|
|
|
mPartsWidget->GetListModel()->Redraw();
|
2016-12-28 22:30:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::SetDefaultPart()
|
|
|
|
{
|
|
|
|
for (int CategoryIdx = 0; CategoryIdx < mCategoriesWidget->topLevelItemCount(); CategoryIdx++)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* CategoryItem = mCategoriesWidget->topLevelItem(CategoryIdx);
|
|
|
|
|
|
|
|
if (CategoryItem->text(0) == "Brick")
|
|
|
|
{
|
|
|
|
mCategoriesWidget->setCurrentItem(CategoryItem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
void lcPartSelectionWidget::UpdateCategories()
|
|
|
|
{
|
2017-01-27 04:02:42 +01:00
|
|
|
int CurrentIndex = mCategoriesWidget->indexOfTopLevelItem(mCategoriesWidget->currentItem());
|
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
mCategoriesWidget->clear();
|
|
|
|
|
2017-02-01 06:12:30 +01:00
|
|
|
mAllPartsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("All Parts")));
|
|
|
|
mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use")));
|
|
|
|
|
2016-12-19 03:53:25 +01:00
|
|
|
for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++)
|
2017-02-08 18:41:48 +01:00
|
|
|
new QTreeWidgetItem(mCategoriesWidget, QStringList(gCategories[CategoryIdx].Name));
|
2016-12-19 03:53:25 +01:00
|
|
|
|
2018-03-17 20:24:16 +01:00
|
|
|
mModelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Submodels")));
|
2017-01-27 04:02:42 +01:00
|
|
|
|
|
|
|
if (CurrentIndex != -1)
|
|
|
|
mCategoriesWidget->setCurrentItem(mCategoriesWidget->topLevelItem(CurrentIndex));
|
2016-12-19 03:53:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcPartSelectionWidget::UpdateModels()
|
|
|
|
{
|
|
|
|
if (mCategoriesWidget->currentItem() == mModelsCategoryItem)
|
|
|
|
mPartsWidget->GetListModel()->SetModelsCategory();
|
|
|
|
}
|