mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
[SiteInfo] Use uniform item sizes in list widget.
Also fixed showing the whole item on Windows.
This commit is contained in:
parent
9ea89aacc1
commit
134f8f5263
@ -24,7 +24,9 @@ ListItemDelegate::ListItemDelegate(int iconSize, QWidget* parent)
|
||||
: QStyledItemDelegate(parent)
|
||||
, m_iconSize(iconSize)
|
||||
, m_updateParentHeight(false)
|
||||
, m_uniformItemSizes(false)
|
||||
, m_itemHeight(0)
|
||||
, m_itemWidth(0)
|
||||
, m_padding(0)
|
||||
{
|
||||
}
|
||||
@ -34,6 +36,11 @@ void ListItemDelegate::setUpdateParentHeight(bool update)
|
||||
m_updateParentHeight = update;
|
||||
}
|
||||
|
||||
void ListItemDelegate::setUniformItemSizes(bool uniform)
|
||||
{
|
||||
m_uniformItemSizes = uniform;
|
||||
}
|
||||
|
||||
int ListItemDelegate::itemHeight() const
|
||||
{
|
||||
return m_itemHeight;
|
||||
@ -91,10 +98,25 @@ QSize ListItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QMode
|
||||
// Update height of parent widget
|
||||
QWidget* p = qobject_cast<QWidget*>(parent());
|
||||
if (p && m_updateParentHeight) {
|
||||
p->setFixedHeight(m_itemHeight);
|
||||
p->setFixedHeight(m_itemHeight
|
||||
#ifdef Q_OS_WIN
|
||||
+ 4 // Vertical padding 2px on Windows
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
int width = 2 * m_padding + option.fontMetrics.width(index.data(Qt::DisplayRole).toString());
|
||||
return QSize(width > (m_iconSize + 2 * m_padding) ? width : m_iconSize + 2 * m_padding, m_itemHeight);
|
||||
width = width > (m_iconSize + 2 * m_padding) ? width : m_iconSize + 2 * m_padding;
|
||||
|
||||
if (m_uniformItemSizes) {
|
||||
if (width > m_itemWidth) {
|
||||
m_itemWidth = width;
|
||||
}
|
||||
else {
|
||||
width = m_itemWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return QSize(width, m_itemHeight);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ public:
|
||||
explicit ListItemDelegate(int iconSize, QWidget* parent);
|
||||
|
||||
void setUpdateParentHeight(bool update);
|
||||
void setUniformItemSizes(bool uniform);
|
||||
|
||||
int itemHeight() const;
|
||||
|
||||
void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
@ -36,8 +38,10 @@ public:
|
||||
private:
|
||||
int m_iconSize;
|
||||
bool m_updateParentHeight;
|
||||
bool m_uniformItemSizes;
|
||||
|
||||
mutable int m_itemHeight;
|
||||
mutable int m_itemWidth;
|
||||
mutable int m_padding;
|
||||
};
|
||||
|
||||
|
@ -57,6 +57,7 @@ SiteInfo::SiteInfo(WebView* view, QWidget* parent)
|
||||
|
||||
ListItemDelegate* delegate = new ListItemDelegate(24, ui->listWidget);
|
||||
delegate->setUpdateParentHeight(true);
|
||||
delegate->setUniformItemSizes(true);
|
||||
ui->listWidget->setItemDelegate(delegate);
|
||||
|
||||
ui->listWidget->item(0)->setIcon(QIcon::fromTheme("document-properties", QIcon(":/icons/preferences/document-properties.png")));
|
||||
|
Loading…
Reference in New Issue
Block a user