Added List Mode option to the parts list. Closes #43.

This commit is contained in:
Leonardo Zide 2017-05-29 14:03:46 -07:00
parent 05e3d7846c
commit e872ec4a63
4 changed files with 39 additions and 5 deletions

View file

@ -99,6 +99,7 @@ lcPartSelectionListModel::lcPartSelectionListModel(QObject* Parent)
mListView = (lcPartSelectionListView*)Parent;
mIconSize = 0;
mShowPartNames = lcGetProfileInt(LC_PROFILE_PARTS_LIST_NAMES);
mListMode = lcGetProfileInt(LC_PROFILE_PARTS_LIST_LISTMODE);
int ColorCode = lcGetProfileInt(LC_PROFILE_PARTS_LIST_COLOR);
if (ColorCode == -1)
@ -162,6 +163,14 @@ void lcPartSelectionListModel::ToggleColorLocked()
lcSetProfileInt(LC_PROFILE_PARTS_LIST_COLOR, mColorLocked ? lcGetColorCode(mColorIndex) : -1);
}
void lcPartSelectionListModel::ToggleListMode()
{
mListMode = !mListMode;
mListView->UpdateViewMode();
lcSetProfileInt(LC_PROFILE_PARTS_LIST_LISTMODE, mListMode);
}
void lcPartSelectionListModel::SetCategory(int CategoryIndex)
{
ClearRequests();
@ -243,7 +252,7 @@ QVariant lcPartSelectionListModel::data(const QModelIndex& Index, int Role) cons
switch (Role)
{
case Qt::DisplayRole:
if (!mIconSize || mShowPartNames)
if (!mIconSize || mShowPartNames || mListMode)
return QVariant(QString::fromLatin1(Info->m_strDescription));
break;
@ -444,7 +453,7 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
Menu->addSeparator();
if (mListModel->GetIconSize() != 0)
if (mListModel->GetIconSize() != 0 && !mListModel->IsListMode())
{
QAction* PartNames = Menu->addAction(tr("Show Part Names"), this, SLOT(TogglePartNames()));
PartNames->setCheckable(true);
@ -455,6 +464,10 @@ void lcPartSelectionListView::CustomContextMenuRequested(QPoint Pos)
DecoratedParts->setCheckable(true);
DecoratedParts->setChecked(mFilterModel->GetShowDecoratedParts());
QAction* ListMode = Menu->addAction(tr("List Mode"), this, SLOT(ToggleListMode()));
ListMode->setCheckable(true);
ListMode->setChecked(mListModel->IsListMode());
QAction* FixedColor = Menu->addAction(tr("Lock Preview Color"), this, SLOT(ToggleFixedColor()));
FixedColor->setCheckable(true);
FixedColor->setChecked(mListModel->IsColorLocked());
@ -501,17 +514,28 @@ void lcPartSelectionListView::ToggleDecoratedParts()
lcSetProfileInt(LC_PROFILE_PARTS_LIST_DECORATED, Show);
}
void lcPartSelectionListView::ToggleListMode()
{
mListModel->ToggleListMode();
}
void lcPartSelectionListView::ToggleFixedColor()
{
mListModel->ToggleColorLocked();
}
void lcPartSelectionListView::UpdateViewMode()
{
setViewMode(mListModel->GetIconSize() && !mListModel->IsListMode() ? QListView::IconMode : QListView::ListMode);
setWordWrap(mListModel->IsListMode());
}
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);
UpdateViewMode();
}
void lcPartSelectionListView::startDrag(Qt::DropActions SupportedActions)

View file

@ -82,9 +82,15 @@ public:
return mColorLocked;
}
bool IsListMode() const
{
return mListMode;
}
void Redraw();
void SetColorIndex(int ColorIndex);
void ToggleColorLocked();
void ToggleListMode();
void SetCategory(int CategoryIndex);
void SetModelsCategory();
void SetCurrentModelCategory();
@ -106,6 +112,7 @@ protected:
bool mColorLocked;
int mColorIndex;
bool mShowPartNames;
bool mListMode;
};
class lcPartSelectionListView : public QListView
@ -132,6 +139,8 @@ public:
return mFilterModel;
}
void UpdateViewMode();
protected slots:
void CustomContextMenuRequested(QPoint Pos);
void SetNoIcons();
@ -141,6 +150,7 @@ protected slots:
void SetExtraLargeIcons();
void TogglePartNames();
void ToggleDecoratedParts();
void ToggleListMode();
void ToggleFixedColor();
protected:
@ -148,8 +158,6 @@ protected:
lcPartSelectionListModel* mListModel;
lcPartSelectionFilterModel* mFilterModel;
// QSize sizeHint() const;
};
class lcPartSelectionWidget : public QWidget

View file

@ -88,6 +88,7 @@ lcProfileEntry gProfileEntries[LC_NUM_PROFILE_KEYS] =
lcProfileEntry("Settings", "PartsListNames", 0), // LC_PROFILE_PARTS_LIST_NAMES
lcProfileEntry("Settings", "PartsListFixedColor", -1), // LC_PROFILE_PARTS_LIST_FIXED_COLOR
lcProfileEntry("Settings", "PartsListDecorated", 1), // LC_PROFILE_PARTS_LIST_DECORATED
lcProfileEntry("Settings", "PartsListListMode", 0), // LC_PROFILE_PARTS_LIST_LISTMODE
lcProfileEntry("Defaults", "Author", ""), // LC_PROFILE_DEFAULT_AUTHOR_NAME
lcProfileEntry("Defaults", "FloorColor", LC_RGB(0, 191, 0)), // LC_PROFILE_DEFAULT_FLOOR_COLOR

View file

@ -37,6 +37,7 @@ enum LC_PROFILE_KEY
LC_PROFILE_PARTS_LIST_NAMES,
LC_PROFILE_PARTS_LIST_COLOR,
LC_PROFILE_PARTS_LIST_DECORATED,
LC_PROFILE_PARTS_LIST_LISTMODE,
// Defaults for new projects.
LC_PROFILE_DEFAULT_AUTHOR_NAME,