1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
23 #include "kfileitemlistgroupheader.h"
25 #include <kratingpainter.h>
28 KFileItemListGroupHeader::KFileItemListGroupHeader(QGraphicsWidget
* parent
) :
29 KItemListGroupHeader(parent
),
34 m_text
.setTextFormat(Qt::PlainText
);
35 m_text
.setPerformanceHint(QStaticText::AggressiveCaching
);
38 KFileItemListGroupHeader::~KFileItemListGroupHeader()
42 void KFileItemListGroupHeader::paint(QPainter
* painter
, const QStyleOptionGraphicsItem
* option
, QWidget
* widget
)
44 KItemListGroupHeader::paint(painter
, option
, widget
);
50 if (m_pixmap
.isNull()) {
51 painter
->setPen(roleColor());
52 painter
->drawStaticText(roleBounds().topLeft(), m_text
);
54 painter
->drawPixmap(roleBounds().topLeft(), m_pixmap
);
58 void KFileItemListGroupHeader::roleChanged(const QByteArray
¤t
, const QByteArray
&previous
)
65 void KFileItemListGroupHeader::dataChanged(const QVariant
& current
, const QVariant
& previous
)
72 void KFileItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent
* event
)
74 QGraphicsWidget::resizeEvent(event
);
78 void KFileItemListGroupHeader::updateCache()
80 Q_ASSERT(m_dirtyCache
);
83 const qreal maxWidth
= size().width() - 4 * styleOption().padding
;
85 if (role() == "rating") {
88 const qreal height
= styleOption().fontMetrics
.ascent();
89 const QSizeF
pixmapSize(qMin(height
* 5, maxWidth
), height
);
91 m_pixmap
= QPixmap(pixmapSize
.toSize());
92 m_pixmap
.fill(Qt::transparent
);
94 QPainter
painter(&m_pixmap
);
95 const QRect
rect(0, 0, m_pixmap
.width(), m_pixmap
.height());
96 const int rating
= data().toInt();
97 KRatingPainter::paintRating(&painter
, rect
, Qt::AlignJustify
| Qt::AlignVCenter
, rating
);
101 QFontMetricsF
fontMetrics(font());
102 const QString text
= fontMetrics
.elidedText(data().toString(), Qt::ElideRight
, maxWidth
);
103 m_text
.setText(text
);
107 #include "kfileitemlistgroupheader.moc"