2019-01-16 20:00:10 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
|
|
|
|
|
|
|
#include "ui_shared/BootablesProcesses.h"
|
|
|
|
#include "http/HttpClientFactory.h"
|
|
|
|
|
|
|
|
#include "BootableModel.h"
|
|
|
|
#include "CoverUtils.h"
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
BootableModel::BootableModel(QObject* parent, int sortingMethod)
|
2019-01-16 20:00:10 +00:00
|
|
|
: QAbstractTableModel(parent)
|
|
|
|
{
|
|
|
|
bootables = BootablesDb::CClient::GetInstance().GetBootables(sortingMethod);
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
int BootableModel::rowCount(const QModelIndex& parent) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
2019-01-17 12:26:47 +00:00
|
|
|
return bootables.size();
|
2019-01-16 20:00:10 +00:00
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
int BootableModel::columnCount(const QModelIndex& parent) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
QVariant BootableModel::data(const QModelIndex& index, int role) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
BootableCoverQVarient::BootableCoverQVarient(std::string key)
|
|
|
|
: m_key(key)
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
void BootableCoverQVarient::paint(QPainter* painter, const QRect& rect, const QPalette& palette, int mode) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
void BootImageItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
2019-01-17 12:26:47 +00:00
|
|
|
if(index.data().canConvert<BootableCoverQVarient>())
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
BootableCoverQVarient bootablecover = qvariant_cast<BootableCoverQVarient>(index.data());
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
if(option.state & QStyle::State_Selected)
|
2019-01-16 20:00:10 +00:00
|
|
|
painter->fillRect(option.rect, option.palette.highlight());
|
|
|
|
|
|
|
|
bootablecover.paint(painter, option.rect, option.palette, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-17 12:26:47 +00:00
|
|
|
QSize BootImageItemDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
2019-01-17 12:26:47 +00:00
|
|
|
if(index.data().canConvert<BootableCoverQVarient>())
|
2019-01-16 20:00:10 +00:00
|
|
|
{
|
|
|
|
BootableCoverQVarient bootablecover = qvariant_cast<BootableCoverQVarient>(index.data());
|
|
|
|
return bootablecover.sizeHint();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
}
|
|
|
|
}
|