@ -19,8 +19,8 @@
|
||||
#include "InstanceDelegate.h"
|
||||
#include "InstanceList.h"
|
||||
|
||||
InstanceDelegate::InstanceDelegate(QObject* parent, int iconSize, bool isGrid)
|
||||
: QStyledItemDelegate(parent), m_iconSize(iconSize), m_isGrid(isGrid)
|
||||
InstanceDelegate::InstanceDelegate(QObject* parent, int iconSize)
|
||||
: QStyledItemDelegate(parent), m_iconSize(iconSize)
|
||||
{}
|
||||
|
||||
void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const
|
||||
@ -28,9 +28,5 @@ void InstanceDelegate::initStyleOption(QStyleOptionViewItem* option, const QMode
|
||||
QStyledItemDelegate::initStyleOption(option, index);
|
||||
if (index.column() == InstanceList::NameColumn) {
|
||||
option->decorationSize = QSize(m_iconSize, m_iconSize);
|
||||
if (m_isGrid) {
|
||||
// FIXME: kinda hacky way to add vertical padding. This assumes that the icon is square in the first place
|
||||
option->decorationSize.rheight() += 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,10 @@ class InstanceDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InstanceDelegate(QObject* parent = 0, int iconSize = 48, bool isGrid = false);
|
||||
InstanceDelegate(QObject* parent = 0, int iconSize = 48);
|
||||
|
||||
void initStyleOption(QStyleOptionViewItem* option, const QModelIndex& index) const override;
|
||||
|
||||
private:
|
||||
int m_iconSize;
|
||||
bool m_isGrid;
|
||||
};
|
||||
|
@ -24,3 +24,21 @@
|
||||
|
||||
// Placeholder model, as we might need this in the future
|
||||
InstanceGridProxyModel::InstanceGridProxyModel(QObject* parent) : InstanceTableProxyModel(parent) {}
|
||||
|
||||
QVariant InstanceGridProxyModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant data = InstanceTableProxyModel::data(index, role);
|
||||
QVariant displayData = data;
|
||||
if (role != Qt::DisplayRole)
|
||||
displayData = InstanceTableProxyModel::data(index, Qt::DisplayRole);
|
||||
|
||||
switch (role) {
|
||||
case InstanceList::IconRole: {
|
||||
QString iconKey = data.toString();
|
||||
if (iconKey.isEmpty())
|
||||
break;
|
||||
return "image://instance/" + iconKey;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -25,4 +25,7 @@ class InstanceGridProxyModel : public InstanceTableProxyModel {
|
||||
|
||||
public:
|
||||
InstanceGridProxyModel(QObject* parent = 0);
|
||||
|
||||
protected:
|
||||
QVariant data(const QModelIndex& index, int role) const override;
|
||||
};
|
||||
|
49
launcher/ui/instanceview/InstancesGrid.qml
Normal file
49
launcher/ui/instanceview/InstancesGrid.qml
Normal file
@ -0,0 +1,49 @@
|
||||
import QtQuick 2.0
|
||||
|
||||
GridView {
|
||||
id: grid
|
||||
model: instances
|
||||
anchors.fill: parent
|
||||
cellWidth: iconSize*2
|
||||
cellHeight: iconSize*2
|
||||
|
||||
highlight: Rectangle {
|
||||
width: grid.cellWidth; height: grid.cellHeight
|
||||
color: "lightsteelblue"; radius: 5
|
||||
x: grid.currentItem.x
|
||||
y: grid.currentItem.y
|
||||
Behavior on x { SmoothedAnimation { duration: 150 } }
|
||||
Behavior on y { SmoothedAnimation { duration: 150 } }
|
||||
}
|
||||
|
||||
interactive: true
|
||||
focus: true
|
||||
|
||||
delegate: Item {
|
||||
required property int index
|
||||
required property string name
|
||||
required property string icon
|
||||
width: iconSize*2
|
||||
height: iconSize*2
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: currentIndex = index;
|
||||
}
|
||||
|
||||
Image {
|
||||
id: icon
|
||||
width: iconSize
|
||||
height: iconSize
|
||||
anchors.top: parent.top
|
||||
source: parent.icon
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.top: icon.bottom
|
||||
text: parent.name
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
}
|
||||
}
|
||||
}
|
@ -27,11 +27,14 @@
|
||||
|
||||
#include "InstanceDelegate.h"
|
||||
#include "InstanceList.h"
|
||||
#include "icons/IconImageProvider.h"
|
||||
#include "ui/instanceview/InstanceGridProxyModel.h"
|
||||
#include "ui/instanceview/InstanceTableProxyModel.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QKeyEvent>
|
||||
#include <QQmlContext>
|
||||
#include <QQmlEngine>
|
||||
#include <QSize>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
@ -59,8 +62,8 @@ void InstancesView::switchDisplayMode(InstancesView::DisplayMode mode)
|
||||
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
setCurrentWidget(m_table);
|
||||
} else {
|
||||
m_grid->selectionModel()->setCurrentIndex(m_gridProxy->mapFromSource(sourceIndex),
|
||||
QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
//m_grid->selectionModel()->setCurrentIndex(m_gridProxy->mapFromSource(sourceIndex),
|
||||
// QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
setCurrentWidget(m_grid);
|
||||
}
|
||||
m_displayMode = mode;
|
||||
@ -92,7 +95,7 @@ void InstancesView::createTable()
|
||||
m_table = new QTableView(this);
|
||||
m_table->installEventFilter(this);
|
||||
m_table->setModel(m_tableProxy);
|
||||
m_table->setItemDelegate(new InstanceDelegate(this, m_iconSize, false));
|
||||
m_table->setItemDelegate(new InstanceDelegate(this, m_iconSize));
|
||||
|
||||
m_table->setTabKeyNavigation(false);
|
||||
m_table->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
@ -138,27 +141,18 @@ void InstancesView::createTable()
|
||||
|
||||
void InstancesView::createGrid()
|
||||
{
|
||||
m_grid = new QListView(this);
|
||||
m_grid = new QQuickWidget(this);
|
||||
m_grid->rootContext()->setContextProperty("instances", m_gridProxy);
|
||||
m_grid->rootContext()->setContextProperty("iconSize", m_iconSize);
|
||||
m_grid->engine()->addImageProvider("instance", new IconImageProvider(APPLICATION->icons(), m_iconSize));
|
||||
m_grid->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
m_grid->setSource(QUrl("qrc:/instanceview/InstancesGrid.qml"));
|
||||
m_grid->installEventFilter(this);
|
||||
m_grid->setModel(m_gridProxy);
|
||||
m_grid->setModelColumn(InstanceList::NameColumn);
|
||||
m_grid->setItemDelegate(new InstanceDelegate(this, m_iconSize, true));
|
||||
|
||||
m_grid->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
m_grid->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
m_grid->setEditTriggers(QAbstractItemView::EditKeyPressed);
|
||||
m_grid->setCurrentIndex(QModelIndex());
|
||||
m_grid->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
m_grid->setWordWrap(true);
|
||||
m_grid->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_grid->setViewMode(QListView::IconMode);
|
||||
m_grid->setMovement(QListView::Static);
|
||||
m_grid->setResizeMode(QListView::Adjust);
|
||||
m_grid->setFrameStyle(QFrame::NoFrame);
|
||||
m_grid->setGridSize(QSize(m_iconSize * 2, m_iconSize * 2));
|
||||
m_grid->show();
|
||||
|
||||
connect(m_grid, &QAbstractItemView::doubleClicked, this, &InstancesView::activateInstance);
|
||||
connect(m_grid->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstancesView::currentRowChanged);
|
||||
//connect(m_grid, &QAbstractItemView::doubleClicked, this, &InstancesView::activateInstance);
|
||||
//connect(m_grid->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &InstancesView::currentRowChanged);
|
||||
connect(m_grid, &QWidget::customContextMenuRequested, this, &InstancesView::contextMenuRequested);
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QListView>
|
||||
#include <QStackedWidget>
|
||||
#include <QTableView>
|
||||
#include <QQuickWidget>
|
||||
|
||||
#include "BaseInstance.h"
|
||||
#include "InstanceList.h"
|
||||
@ -41,7 +42,7 @@ class InstancesView : public QStackedWidget {
|
||||
QAbstractItemView* currentView()
|
||||
{
|
||||
if (m_displayMode == GridMode)
|
||||
return m_grid;
|
||||
return nullptr; // TODO
|
||||
return m_table;
|
||||
}
|
||||
|
||||
@ -82,7 +83,7 @@ class InstancesView : public QStackedWidget {
|
||||
DisplayMode m_displayMode = TableMode;
|
||||
|
||||
QTableView* m_table;
|
||||
QListView* m_grid;
|
||||
QQuickWidget* m_grid;
|
||||
InstanceTableProxyModel* m_tableProxy;
|
||||
InstanceGridProxyModel* m_gridProxy;
|
||||
InstanceList* m_instances;
|
||||
|
Reference in New Issue
Block a user