mirror of
https://github.com/jpd002/Play-.git
synced 2025-04-28 21:57:57 +03:00
126 lines
3 KiB
C++
126 lines
3 KiB
C++
![]() |
#include <QPainter>
|
||
|
#include <QPixmap>
|
||
|
|
||
|
#include "ui_shared/BootablesProcesses.h"
|
||
|
#include "http/HttpClientFactory.h"
|
||
|
|
||
|
#include "BootableModel.h"
|
||
|
#include "CoverUtils.h"
|
||
|
|
||
|
|
||
|
BootableModel::BootableModel(QObject *parent, int sortingMethod)
|
||
|
: QAbstractTableModel(parent)
|
||
|
{
|
||
|
bootables = BootablesDb::CClient::GetInstance().GetBootables(sortingMethod);
|
||
|
}
|
||
|
|
||
|
int BootableModel::rowCount(const QModelIndex &parent) const
|
||
|
{
|
||
|
return bootables.size();
|
||
|
}
|
||
|
|
||
|
int BootableModel::columnCount(const QModelIndex &parent) const
|
||
|
{
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
QVariant BootableModel::data(const QModelIndex &index, int role) const
|
||
|
{
|
||
|
if(role == Qt::DisplayRole)
|
||
|
{
|
||
|
int pos = index.row() + index.column();
|
||
|
auto bootable = bootables.at(pos);
|
||
|
return QVariant::fromValue(BootableCoverQVarient(bootable.discId));
|
||
|
}
|
||
|
return QVariant();
|
||
|
}
|
||
|
|
||
|
QSize BootableModel::SizeHint()
|
||
|
{
|
||
|
static QSize size;
|
||
|
if(size.isEmpty())
|
||
|
{
|
||
|
QPixmap pixmap = CoverUtils::find("PH");
|
||
|
size = pixmap.size();
|
||
|
size.setHeight(size.height() + 10);
|
||
|
size.setWidth(size.width() + 10);
|
||
|
}
|
||
|
return size;
|
||
|
}
|
||
|
|
||
|
BootablesDb::Bootable BootableModel::GetBootable(const QModelIndex& index)
|
||
|
{
|
||
|
unsigned int pos = index.row() + index.column();
|
||
|
return bootables.at(pos);
|
||
|
}
|
||
|
|
||
|
void BootableModel::removeItem(const QModelIndex& index)
|
||
|
{
|
||
|
unsigned int pos = index.row() + index.column();
|
||
|
emit QAbstractTableModel::beginRemoveRows(QModelIndex(), pos, pos);
|
||
|
bootables.erase(bootables.begin() + pos);
|
||
|
emit QAbstractTableModel::endRemoveRows();
|
||
|
}
|
||
|
|
||
|
BootableCoverQVarient::BootableCoverQVarient(std::string key) : m_key(key)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void BootableCoverQVarient::paint(QPainter *painter, const QRect &rect, const QPalette &palette, int mode) const
|
||
|
{
|
||
|
painter->save();
|
||
|
|
||
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||
|
painter->setPen(Qt::NoPen);
|
||
|
|
||
|
QPixmap pixmap = CoverUtils::find(m_key.c_str());
|
||
|
painter->drawPixmap(rect.x() + 5, rect.y() + 5, pixmap);
|
||
|
|
||
|
painter->restore();
|
||
|
}
|
||
|
|
||
|
QSize BootableCoverQVarient::sizeHint() const
|
||
|
{
|
||
|
static QSize size;
|
||
|
if(size.isEmpty())
|
||
|
{
|
||
|
QPixmap pixmap = CoverUtils::find("PH");
|
||
|
size = pixmap.size();
|
||
|
size.setHeight(size.height() + 10);
|
||
|
size.setWidth(size.width() + 10);
|
||
|
}
|
||
|
return size;
|
||
|
}
|
||
|
|
||
|
|
||
|
void BootImageItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||
|
{
|
||
|
if (index.data().canConvert<BootableCoverQVarient>())
|
||
|
{
|
||
|
BootableCoverQVarient bootablecover = qvariant_cast<BootableCoverQVarient>(index.data());
|
||
|
|
||
|
if (option.state & QStyle::State_Selected)
|
||
|
painter->fillRect(option.rect, option.palette.highlight());
|
||
|
|
||
|
bootablecover.paint(painter, option.rect, option.palette, 0);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
QStyledItemDelegate::paint(painter, option, index);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
QSize BootImageItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||
|
{
|
||
|
if (index.data().canConvert<BootableCoverQVarient>())
|
||
|
{
|
||
|
BootableCoverQVarient bootablecover = qvariant_cast<BootableCoverQVarient>(index.data());
|
||
|
return bootablecover.sizeHint();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return QStyledItemDelegate::sizeHint(option, index);
|
||
|
}
|
||
|
}
|