Qt: spread/center covers horizontally, show scrollbar

This commit is contained in:
Mahmood - Zer0xFF 2019-05-19 16:16:24 +01:00
parent 6e62ac0283
commit 716543c9eb
5 changed files with 34 additions and 5 deletions

View File

@ -7,6 +7,8 @@
#include "BootableModel.h"
#include "CoverUtils.h"
int g_viewwidth;
BootableModel::BootableModel(QObject* parent, std::vector<BootablesDb::Bootable>& bootables)
: QAbstractTableModel(parent)
, m_bootables(bootables)
@ -61,6 +63,11 @@ void BootableModel::removeItem(const QModelIndex& index)
emit QAbstractTableModel::endRemoveRows();
}
void BootableModel::SetWidth(int width)
{
g_viewwidth = width;
}
/* start of BootImageItemDelegate */
BootableCoverQVarient::BootableCoverQVarient(std::string key, std::string title)
: m_key(key)
@ -93,20 +100,35 @@ void BootableCoverQVarient::paint(QPainter* painter, const QRect& rect, const QP
text += m_title;
painter.drawText(pix_rect, text.c_str(), opts);
}
painter->drawPixmap(rect.x() + 5, rect.y() + 5, pixmap);
painter->drawPixmap(rect.x() + 5 + (GetPadding() / 2), rect.y() + 5, pixmap);
painter->restore();
}
int BootableCoverQVarient::GetPadding() const
{
QPixmap pixmap = CoverUtils::find("PH");
int cover_width = pixmap.size().width() + 10;
int cover_count = (g_viewwidth / cover_width);
int reminder = (g_viewwidth % cover_width);
if(reminder > 0 && cover_count > 0)
return reminder / cover_count;
return 0;
}
QSize BootableCoverQVarient::sizeHint() const
{
static QSize size;
QSize size;
if(size.isEmpty())
{
QPixmap pixmap = CoverUtils::find("PH");
size = pixmap.size();
size.setHeight(size.height() + 10);
size.setWidth(size.width() + 10);
size.rwidth() += GetPadding();
}
return size;
}

View File

@ -19,6 +19,7 @@ public:
QSize SizeHint();
BootablesDb::Bootable GetBootable(const QModelIndex&);
void removeItem(const QModelIndex&);
void SetWidth(int);
private:
std::vector<BootablesDb::Bootable>& m_bootables;
@ -35,6 +36,7 @@ public:
QSize sizeHint() const;
private:
int GetPadding() const;
std::string m_key;
std::string m_title;
};

View File

@ -84,9 +84,6 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="movement">
<enum>QListView::Free</enum>
</property>

View File

@ -161,3 +161,9 @@ void BootableListDialog::UpdateCoverDisplay()
ui->listView->scroll(1, 0);
ui->listView->scroll(-1, 0);
}
void BootableListDialog::resizeEvent(QResizeEvent* ev)
{
model->SetWidth(ui->listView->size().width() - ui->listView->style()->pixelMetric(QStyle::PM_ScrollBarExtent) - 5);
QDialog::resizeEvent(ev);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <QResizeEvent>
#include <QDialog>
#include <QDir>
#include <boost/filesystem.hpp>
@ -48,4 +49,5 @@ Q_SIGNALS:
protected:
void showEvent(QShowEvent*) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent*) Q_DECL_OVERRIDE;
};