Draw styled header for the details-view

This commit is contained in:
Peter Penz 2011-09-19 20:34:17 +02:00
parent f9bcd0a47c
commit 06f057d385
5 changed files with 78 additions and 13 deletions

View file

@ -329,15 +329,13 @@ void KItemListContainer::updateGeometries()
{
QRect rect = geometry();
int widthDec = frameWidth() * 2;
if (verticalScrollBar()->isVisible()) {
widthDec += style()->pixelMetric(QStyle::PM_ScrollBarExtent);
}
const int widthDec = verticalScrollBar()->isVisible()
? frameWidth() + style()->pixelMetric(QStyle::PM_ScrollBarExtent)
: frameWidth() * 2;
int heightDec = frameWidth() * 2;
if (horizontalScrollBar()->isVisible()) {
heightDec += style()->pixelMetric(QStyle::PM_ScrollBarExtent);
}
const int heightDec = horizontalScrollBar()->isVisible()
? frameWidth() + style()->pixelMetric(QStyle::PM_ScrollBarExtent)
: frameWidth() * 2;
rect.adjust(0, 0, -widthDec, -heightDec);

View file

@ -19,24 +19,75 @@
#include "kitemlistheader_p.h"
#include "kitemmodelbase.h"
#include <QFontMetricsF>
#include <QPainter>
#include <QStyleOptionHeader>
KItemListHeader::KItemListHeader(QGraphicsWidget* parent) :
QGraphicsWidget(parent)
QGraphicsWidget(parent),
m_model(0)
{
resize(0, 20); // TODO...
QStyleOptionHeader opt;
const QSize headerSize = style()->sizeFromContents(QStyle::CT_HeaderSection, &opt, QSize());
resize(0, headerSize.height());
}
KItemListHeader::~KItemListHeader()
{
}
void KItemListHeader::setModel(KItemModelBase* model)
{
if (m_model == model) {
return;
}
if (m_model) {
disconnect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
disconnect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
}
m_model = model;
if (m_model) {
connect(m_model, SIGNAL(sortRoleChanged(QByteArray,QByteArray)),
this, SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
connect(m_model, SIGNAL(sortOrderChanged(Qt::SortOrder,Qt::SortOrder)),
this, SLOT(slotSortOrderChanged(Qt::SortOrder,Qt::SortOrder)));
}
}
KItemModelBase* KItemListHeader::model() const
{
return m_model;
}
void KItemListHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->setPen(Qt::red);
painter->drawRect(rect());
QStyleOption opt;
opt.init(widget);
opt.rect = rect().toRect();
opt.state |= QStyle::State_Horizontal;
style()->drawControl(QStyle::CE_HeaderEmptyArea, &opt, painter);
}
void KItemListHeader::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous)
{
Q_UNUSED(current);
Q_UNUSED(previous);
}
void KItemListHeader::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
{
Q_UNUSED(current);
Q_UNUSED(previous);
}
#include "kitemlistheader_p.moc"

View file

@ -23,6 +23,8 @@
#include <libdolphin_export.h>
#include <QGraphicsWidget>
class KItemModelBase;
/**
* @brief Header for KItemListView that shows the currently used roles.
*/
@ -34,7 +36,17 @@ public:
KItemListHeader(QGraphicsWidget* parent = 0);
virtual ~KItemListHeader();
void setModel(KItemModelBase* model);
KItemModelBase* model() const;
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
private slots:
void slotSortRoleChanged(const QByteArray& current, const QByteArray& previous);
void slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous);
private:
KItemModelBase* m_model;
};
#endif

View file

@ -229,6 +229,9 @@ void KItemListView::setHeaderShown(bool show)
{
if (show && !m_header) {
m_header = new KItemListHeader(this);
m_header->setPos(0, 0);
m_header->setModel(m_model);
m_header->setZValue(1);
updateHeaderWidth();
m_layouter->setHeaderHeight(m_header->size().height());
} else if (!show && m_header) {

View file

@ -362,7 +362,8 @@ void KItemListViewLayouter::updateVisibleIndexes()
prevRowIndex -= m_columnCount;
}
while (prevRowIndex >= 0 && m_itemBoundingRects[prevRowIndex].bottom() >= m_offset) {
const qreal top = m_offset + m_headerHeight;
while (prevRowIndex >= 0 && m_itemBoundingRects[prevRowIndex].bottom() >= top) {
m_firstVisibleIndex = prevRowIndex;
prevRowIndex -= m_columnCount;
}