Added option to choose the size of the parts icons.

This commit is contained in:
leozide 2016-12-20 14:46:12 -08:00
parent 8ed7e0d6c8
commit b5e61f2c26
4 changed files with 95 additions and 12 deletions

View file

@ -1,13 +1,12 @@
#include "lc_global.h" #include "lc_global.h"
#include "lc_partselectionwidget.h" #include "lc_partselectionwidget.h"
#include "lc_profile.h"
#include "lc_application.h" #include "lc_application.h"
#include "lc_library.h" #include "lc_library.h"
#include "lc_model.h" #include "lc_model.h"
#include "project.h" #include "project.h"
#include "pieceinf.h" #include "pieceinf.h"
static const int gIconSize = 64;
static int lcPartSortFunc(PieceInfo* const& a, PieceInfo* const& b) static int lcPartSortFunc(PieceInfo* const& a, PieceInfo* const& b)
{ {
return strcmp(a->m_strDescription, b->m_strDescription); return strcmp(a->m_strDescription, b->m_strDescription);
@ -68,6 +67,7 @@ QSize lcPartSelectionItemDelegate::sizeHint(const QStyleOptionViewItem& Option,
lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent) lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
: QAbstractListModel(Parent) : QAbstractListModel(Parent)
{ {
mIconSize = 0;
} }
void lcPartSelectionListModel::SetCategory(int CategoryIndex) void lcPartSelectionListModel::SetCategory(int CategoryIndex)
@ -121,17 +121,29 @@ QVariant lcPartSelectionListModel::data(const QModelIndex& Index, int Role) cons
if (Index.isValid() && InfoIndex < mParts.size()) if (Index.isValid() && InfoIndex < mParts.size())
{ {
if (Role == Qt::ToolTipRole) PieceInfo* Info = mParts[InfoIndex].first;
switch (Role)
{ {
PieceInfo* Info = mParts[InfoIndex].first; case Qt::DisplayRole:
if (!mIconSize)
{
PieceInfo* Info = mParts[InfoIndex].first;
return QVariant(QString::fromLatin1(Info->m_strDescription));
}
break;
case Qt::ToolTipRole:
return QVariant(QString("%1 (%2)").arg(QString::fromLatin1(Info->m_strDescription), QString::fromLatin1(Info->m_strName))); return QVariant(QString("%1 (%2)").arg(QString::fromLatin1(Info->m_strDescription), QString::fromLatin1(Info->m_strName)));
}
else if (Role == Qt::DecorationRole) case Qt::DecorationRole:
{
if (!mParts[InfoIndex].second.isNull()) if (!mParts[InfoIndex].second.isNull())
return QVariant(mParts[InfoIndex].second); return QVariant(mParts[InfoIndex].second);
else else
return QVariant(QColor(0, 0, 0, 0)); return QVariant(QColor(0, 0, 0, 0));
default:
break;
} }
} }
@ -161,13 +173,13 @@ Qt::ItemFlags lcPartSelectionListModel::flags(const QModelIndex& Index) const
void lcPartSelectionListModel::DrawPreview(int InfoIndex) void lcPartSelectionListModel::DrawPreview(int InfoIndex)
{ {
if (!mParts[InfoIndex].second.isNull()) if (!mIconSize || !mParts[InfoIndex].second.isNull())
return; return;
gMainWindow->mPreviewWidget->MakeCurrent(); gMainWindow->mPreviewWidget->MakeCurrent();
lcContext* Context = gMainWindow->mPreviewWidget->mContext; lcContext* Context = gMainWindow->mPreviewWidget->mContext;
int Width = gIconSize; int Width = mIconSize;
int Height = gIconSize; int Height = mIconSize;
if (!Context->BeginRenderToTexture(Width, Height)) if (!Context->BeginRenderToTexture(Width, Height))
return; return;
@ -217,14 +229,28 @@ void lcPartSelectionListModel::DrawPreview(int InfoIndex)
#endif #endif
} }
void lcPartSelectionListModel::SetIconSize(int Size)
{
if (Size == mIconSize)
return;
mIconSize = Size;
beginResetModel();
for (int PartIdx = 0; PartIdx < mParts.size(); PartIdx++)
mParts[PartIdx].second = QPixmap();
endResetModel();
}
lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent) lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent)
: QListView(Parent) : QListView(Parent)
{ {
setUniformItemSizes(true); setUniformItemSizes(true);
setViewMode(QListView::IconMode);
setIconSize(QSize(gIconSize, gIconSize));
setResizeMode(QListView::Adjust); setResizeMode(QListView::Adjust);
setDragEnabled(true); setDragEnabled(true);
setContextMenuPolicy(Qt::CustomContextMenu);
mListModel = new lcPartSelectionListModel(this); mListModel = new lcPartSelectionListModel(this);
mFilterModel = new lcPartSelectionFilterModel(this); mFilterModel = new lcPartSelectionFilterModel(this);
@ -232,6 +258,50 @@ lcPartSelectionListView::lcPartSelectionListView(QWidget* Parent)
setModel(mFilterModel); setModel(mFilterModel);
lcPartSelectionItemDelegate* ItemDelegate = new lcPartSelectionItemDelegate(this, mListModel, mFilterModel); lcPartSelectionItemDelegate* ItemDelegate = new lcPartSelectionItemDelegate(this, mListModel, mFilterModel);
setItemDelegate(ItemDelegate); setItemDelegate(ItemDelegate);
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);
Menu->addAction("Small Icons", this, SLOT(SetSmallIcons()));
Menu->addAction("Medium Icons", this, SLOT(SetMediumIcons()));
Menu->addAction("Large Icons", this, SLOT(SetLargeIcons()));
Menu->addAction("Text", this, SLOT(SetText()));
Menu->popup(viewport()->mapToGlobal(Pos));
}
void lcPartSelectionListView::SetSmallIcons()
{
SetIconSize(32);
}
void lcPartSelectionListView::SetMediumIcons()
{
SetIconSize(64);
}
void lcPartSelectionListView::SetLargeIcons()
{
SetIconSize(96);
}
void lcPartSelectionListView::SetText()
{
SetIconSize(0);
}
void lcPartSelectionListView::SetIconSize(int Size)
{
setViewMode(Size ? QListView::IconMode : QListView::ListMode);
setIconSize(QSize(Size, Size));
lcSetProfileInt(LC_PROFILE_PARTS_LIST_ICONS, Size);
mListModel->SetIconSize(Size);
} }
void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions) void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)

View file

@ -61,9 +61,11 @@ public:
void SetCategory(int CategoryIndex); void SetCategory(int CategoryIndex);
void SetModelsCategory(); void SetModelsCategory();
void DrawPreview(int InfoIndex); void DrawPreview(int InfoIndex);
void SetIconSize(int Size);
protected: protected:
QVector<QPair<PieceInfo*, QPixmap>> mParts; QVector<QPair<PieceInfo*, QPixmap>> mParts;
int mIconSize;
}; };
class lcPartSelectionListView : public QListView class lcPartSelectionListView : public QListView
@ -90,7 +92,16 @@ public:
return mFilterModel; return mFilterModel;
} }
protected slots:
void CustomContextMenuRequested(QPoint Pos);
void SetSmallIcons();
void SetMediumIcons();
void SetLargeIcons();
void SetText();
protected: protected:
void SetIconSize(int Size);
lcPartSelectionListModel* mListModel; lcPartSelectionListModel* mListModel;
lcPartSelectionFilterModel* mFilterModel; lcPartSelectionFilterModel* mFilterModel;

View file

@ -85,6 +85,7 @@ lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "ImageExtension", ".png"), // LC_PROFILE_IMAGE_EXTENSION lcProfileEntry("Settings", "ImageExtension", ".png"), // LC_PROFILE_IMAGE_EXTENSION
lcProfileEntry("Settings", "PrintRows", 1), // LC_PROFILE_PRINT_ROWS lcProfileEntry("Settings", "PrintRows", 1), // LC_PROFILE_PRINT_ROWS
lcProfileEntry("Settings", "PrintColumns", 1), // LC_PROFILE_PRINT_COLUMNS lcProfileEntry("Settings", "PrintColumns", 1), // LC_PROFILE_PRINT_COLUMNS
lcProfileEntry("Settings", "PartsListIcons", 64), // LC_PROFILE_PARTS_LIST_ICONS
lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME
lcProfileEntry("Defaults", "FloorColor", LC_RGB(0, 191, 0)), // LC_PROFILE_DEFAULT_FLOOR_COLOR lcProfileEntry("Defaults", "FloorColor", LC_RGB(0, 191, 0)), // LC_PROFILE_DEFAULT_FLOOR_COLOR

View file

@ -33,6 +33,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_IMAGE_EXTENSION, LC_PROFILE_IMAGE_EXTENSION,
LC_PROFILE_PRINT_ROWS, LC_PROFILE_PRINT_ROWS,
LC_PROFILE_PRINT_COLUMNS, LC_PROFILE_PRINT_COLUMNS,
LC_PROFILE_PARTS_LIST_ICONS,
// Defaults for new projects. // Defaults for new projects.
LC_PROFILE_DEFAULT_AUTHOR_NAME, LC_PROFILE_DEFAULT_AUTHOR_NAME,