parent
149b0c9369
commit
1b9dcf0182
|
@ -16,12 +16,19 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
# You can also select to disable deprecated APIs only up to a certain version of Qt.
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
|
msvc {
|
||||||
|
QMAKE_CFLAGS += /utf-8
|
||||||
|
QMAKE_CXXFLAGS += /utf-8
|
||||||
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
corehost.cpp \
|
||||||
dbunit.cpp \
|
dbunit.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
mainwindow.cpp
|
mainwindow.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
corehost.h \
|
||||||
dbunit.h \
|
dbunit.h \
|
||||||
mainwindow.h
|
mainwindow.h
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include "corehost.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QHash>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
|
CoreHost::CoreHost()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CoreHost::~CoreHost()
|
||||||
|
{
|
||||||
|
for (auto item : pics_resources)
|
||||||
|
delete item;
|
||||||
|
pics_resources.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon*
|
||||||
|
CoreHost::queryCoverIcon(const QString& path)
|
||||||
|
{
|
||||||
|
if (!pics_resources.contains(path))
|
||||||
|
pics_resources.insert(path, new QIcon(path));
|
||||||
|
|
||||||
|
return pics_resources.value(path);
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
#ifndef COREHOST_H
|
||||||
|
#define COREHOST_H
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class CoreHost
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CoreHost();
|
||||||
|
virtual ~CoreHost();
|
||||||
|
|
||||||
|
QIcon* queryCoverIcon(const QString& path);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHash<QString, QIcon*> pics_resources;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COREHOST_H
|
BIN
cover.jpg
BIN
cover.jpg
Binary file not shown.
Before Width: | Height: | Size: 282 KiB After Width: | Height: | Size: 288 KiB |
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
|
@ -1,24 +1,30 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "corehost.h"
|
||||||
|
#include <QDebug>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
#include <QSplitter>
|
#include <QSplitter>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
#define GROUP_COVER0 Qt::DecorationRole
|
#define GROUP_COVER0_PATH Qt::UserRole + 1
|
||||||
#define GROUP_COVER1 Qt::UserRole + 3
|
#define GROUP_COVER1_PATH Qt::UserRole + 2
|
||||||
#define GROUP_COVER2 Qt::UserRole + 4
|
#define GROUP_COVER2_PATH Qt::UserRole + 3
|
||||||
#define GROUP_TITLE Qt::DisplayRole
|
#define GROUP_TITLE Qt::DisplayRole
|
||||||
#define GROUP_ITEMSCOUNT Qt::UserRole + 1
|
#define GROUP_ITEMSCOUNT Qt::UserRole + 4
|
||||||
|
|
||||||
#define ITEM_ICON Qt::DecorationRole
|
#define ITEM_ICON_PATH Qt::UserRole + 1
|
||||||
#define ITEM_TITLE Qt::DisplayRole
|
#define ITEM_TITLE Qt::DisplayRole
|
||||||
|
|
||||||
|
CoreHost host;
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget* parent)
|
MainWindow::MainWindow(QWidget* parent)
|
||||||
: QMainWindow(parent), groups_view(new QListView(this)),
|
: QMainWindow(parent), groups_view(new QListView(this)),
|
||||||
groups_list(new QStandardItemModel(this)), items_view(new QListView(this)),
|
groups_list(new QStandardItemModel(this)), items_view(new QListView(this)),
|
||||||
items_list(new QStandardItemModel(this))
|
items_list(new QStandardItemModel(this))
|
||||||
{
|
{
|
||||||
|
setMinimumSize(800, 600);
|
||||||
|
|
||||||
groups_view->setModel(groups_list);
|
groups_view->setModel(groups_list);
|
||||||
items_view->setModel(items_list);
|
items_view->setModel(items_list);
|
||||||
|
|
||||||
|
@ -37,6 +43,11 @@ MainWindow::MainWindow(QWidget* parent)
|
||||||
|
|
||||||
init_groups_list(items_list);
|
init_groups_list(items_list);
|
||||||
items_view->setItemDelegate(new ListIconDelegate());
|
items_view->setItemDelegate(new ListIconDelegate());
|
||||||
|
items_view->setViewMode(QListView::IconMode);
|
||||||
|
items_view->setResizeMode(QListView::Adjust);
|
||||||
|
items_view->setSelectionRectVisible(true);
|
||||||
|
items_view->setGridSize(QSize(135, 195));
|
||||||
|
items_view->setIconSize(QSize(120, 180));
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -53,19 +64,18 @@ MainWindow::init_groups_list(QStandardItemModel* model)
|
||||||
QList<QStandardItem*> row;
|
QList<QStandardItem*> row;
|
||||||
row << new QStandardItem("无名集合0");
|
row << new QStandardItem("无名集合0");
|
||||||
row.last()->setData(gen.generate() % 100, GROUP_ITEMSCOUNT);
|
row.last()->setData(gen.generate() % 100, GROUP_ITEMSCOUNT);
|
||||||
|
row.last()->setData(":/imgs/default/cover_item.jpg", GROUP_COVER0_PATH);
|
||||||
|
|
||||||
model->appendRow(row);
|
model->appendRow(row);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupDisplayDelegate::GroupDisplayDelegate()
|
GroupDisplayDelegate::GroupDisplayDelegate()
|
||||||
: default_cover(new QIcon(":/imgs/default/cover.jpg"))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupDisplayDelegate::~GroupDisplayDelegate()
|
GroupDisplayDelegate::~GroupDisplayDelegate()
|
||||||
{
|
{
|
||||||
delete default_cover;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget*
|
QWidget*
|
||||||
|
@ -107,37 +117,38 @@ GroupDisplayDelegate::paint(QPainter* painter, const QStyleOptionViewItem& optio
|
||||||
{
|
{
|
||||||
drawBackground(painter, option, index);
|
drawBackground(painter, option, index);
|
||||||
|
|
||||||
auto cover0 = index.data(GROUP_COVER0);
|
QIcon *icon0 = nullptr, *icon1 = nullptr, *icon2 = nullptr;
|
||||||
|
auto cover0 = index.data(GROUP_COVER0_PATH);
|
||||||
if (cover0.isNull())
|
if (cover0.isNull())
|
||||||
cover0 = default_cover->pixmap(QSize(100, 150));
|
icon0 = host.queryCoverIcon(":/imgs/default/cover.jpg");
|
||||||
else
|
else
|
||||||
cover0 = cover0.value<QIcon>().pixmap(QSize(100, 150));
|
icon0 = host.queryCoverIcon(cover0.toString());
|
||||||
|
|
||||||
auto cover1 = index.data(GROUP_COVER1);
|
auto cover1 = index.data(GROUP_COVER1_PATH);
|
||||||
if (cover1.isNull())
|
if (cover1.isNull())
|
||||||
cover1 = default_cover->pixmap(QSize(100, 150));
|
icon1 = host.queryCoverIcon(":/imgs/default/cover.jpg");
|
||||||
else
|
else
|
||||||
cover0 = cover0.value<QIcon>().pixmap(QSize(100, 150));
|
icon1 = host.queryCoverIcon(cover1.toString());
|
||||||
|
|
||||||
auto cover2 = index.data(GROUP_COVER2);
|
auto cover2 = index.data(GROUP_COVER2_PATH);
|
||||||
if (cover2.isNull())
|
if (cover2.isNull())
|
||||||
cover2 = default_cover->pixmap(QSize(100, 150));
|
icon2 = host.queryCoverIcon(":/imgs/default/cover.jpg");
|
||||||
else
|
else
|
||||||
cover0 = cover0.value<QIcon>().pixmap(QSize(100, 150));
|
icon2 = host.queryCoverIcon(cover2.toString());
|
||||||
|
|
||||||
auto valid_rect = option.rect - QMargins(15, 15, 15, 15);
|
auto valid_rect = option.rect - QMargins(15, 15, 15, 15);
|
||||||
|
|
||||||
auto pixmap1 = cover1.value<QPixmap>();
|
auto pixmap1 = icon1->pixmap(100, 150);
|
||||||
QRectF rect1(valid_rect.left() + 60, valid_rect.top() + 20, 54, 80);
|
QRect rect1(valid_rect.left() + 60, valid_rect.top() + 20, 54, 80);
|
||||||
painter->drawPixmap(rect1, pixmap1, QRectF(0, 0, 100, 150));
|
painter->drawPixmap(rect1, pixmap1);
|
||||||
|
|
||||||
auto pixmap2 = cover2.value<QPixmap>();
|
auto pixmap2 = icon2->pixmap(100, 150);
|
||||||
QRectF rect2(valid_rect.left() + 34, valid_rect.top() + 10, 66, 100);
|
QRect rect2(valid_rect.left() + 34, valid_rect.top() + 10, 66, 100);
|
||||||
painter->drawPixmap(rect2, pixmap2, QRectF(0, 0, 100, 150));
|
painter->drawPixmap(rect2, pixmap2);
|
||||||
|
|
||||||
auto pixmap0 = cover0.value<QPixmap>();
|
auto pixmap0 = icon0->pixmap(100, 150);
|
||||||
QRectF rect0(valid_rect.left(), valid_rect.top(), 80, 120);
|
QRect rect0(valid_rect.left(), valid_rect.top(), 80, 120);
|
||||||
painter->drawPixmap(rect0, pixmap0, QRectF(0, 0, 100, 150));
|
painter->drawPixmap(rect0, pixmap0);
|
||||||
|
|
||||||
QStyleOptionViewItem new_copy = option;
|
QStyleOptionViewItem new_copy = option;
|
||||||
new_copy.font.setPointSize(26);
|
new_copy.font.setPointSize(26);
|
||||||
|
@ -156,34 +167,44 @@ GroupDisplayDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelI
|
||||||
}
|
}
|
||||||
|
|
||||||
ListIconDelegate::ListIconDelegate()
|
ListIconDelegate::ListIconDelegate()
|
||||||
: default_cover(new QIcon(":/imgs/default/cover.jpg"))
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ListIconDelegate::~ListIconDelegate()
|
ListIconDelegate::~ListIconDelegate()
|
||||||
{
|
{
|
||||||
delete default_cover;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ListIconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
ListIconDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
drawBackground(painter, option, index);
|
painter->save();
|
||||||
|
|
||||||
|
QPen pen(QColor(0, 0, 200, 150), 3, Qt::SolidLine);
|
||||||
|
painter->setPen(pen);
|
||||||
|
QBrush brush(QColor(20, 20, 150, 100));
|
||||||
|
painter->setBrush(brush);
|
||||||
|
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
if (option.state & QStyle::State_Selected)
|
||||||
|
painter->drawRoundedRect(option.rect - QMargins(2, 2, 2, 2), 5, 5);
|
||||||
|
|
||||||
|
QIcon* icon = nullptr;
|
||||||
|
auto cover = index.data(ITEM_ICON_PATH);
|
||||||
|
if (!cover.isValid())
|
||||||
|
icon = host.queryCoverIcon(":/imgs/default/cover.jpg");
|
||||||
|
else
|
||||||
|
icon = host.queryCoverIcon(cover.toString());
|
||||||
|
|
||||||
auto valid_rect = option.rect - QMargins(15, 15, 15, 15);
|
auto valid_rect = option.rect - QMargins(15, 15, 15, 15);
|
||||||
auto cover = index.data(ITEM_ICON);
|
drawDecoration(painter, option, valid_rect, icon->pixmap(120, 180));
|
||||||
if (!cover.isValid())
|
|
||||||
cover = default_cover->pixmap(100, 150);
|
|
||||||
else
|
|
||||||
cover = cover.value<QIcon>().pixmap(QSize(100, 150));
|
|
||||||
|
|
||||||
painter->drawPixmap(valid_rect, cover.value<QPixmap>());
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize
|
QSize
|
||||||
ListIconDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
ListIconDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
return QSize(100, 160);
|
return QSize(135, 195);
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget*
|
QWidget*
|
||||||
|
|
|
@ -20,9 +20,6 @@ public:
|
||||||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
|
||||||
private:
|
|
||||||
QIcon* const default_cover;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ListIconDelegate : public QItemDelegate {
|
class ListIconDelegate : public QItemDelegate {
|
||||||
|
@ -38,9 +35,6 @@ public:
|
||||||
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const override;
|
||||||
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
|
||||||
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
|
||||||
|
|
||||||
private:
|
|
||||||
QIcon* const default_cover;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MainWindow : public QMainWindow {
|
class MainWindow : public QMainWindow {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/imgs/default">
|
<qresource prefix="/imgs/default">
|
||||||
<file>cover.jpg</file>
|
<file>cover.jpg</file>
|
||||||
|
<file>cover_item.jpg</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
Loading…
Reference in New Issue