┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-09-08 20:28:41 +0200
committerPeter Penz <[email protected]>2011-09-08 20:29:27 +0200
commitf0debd937766045c77dea5f2f5255de89f7b2697 (patch)
treefb022c37b49130b999a3b6a1f68fbf7ab1454b4c /src/kitemviews
parentbe629fe8501941138da849cf1179ad67cd5570cb (diff)
Version control: show pixmap overlays for the version state
Diffstat (limited to 'src/kitemviews')
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp50
-rw-r--r--src/kitemviews/kfileitemlistwidget.h8
2 files changed, 35 insertions, 23 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 8078d0d4d..d162ed8a2 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -56,8 +56,9 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
m_textBoundingRect(),
m_sortedVisibleRoles(),
m_expansionArea(),
- m_customTextColor(0),
- m_additionalInfoTextColor()
+ m_customTextColor(),
+ m_additionalInfoTextColor(),
+ m_overlay()
{
for (int i = 0; i < TextIdCount; ++i) {
m_text[i].setTextFormat(Qt::PlainText);
@@ -67,8 +68,6 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
KFileItemListWidget::~KFileItemListWidget()
{
- delete m_customTextColor;
- m_customTextColor = 0;
}
void KFileItemListWidget::setLayout(Layout layout)
@@ -117,11 +116,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
}
painter->setFont(itemListStyleOption.font);
- if (m_customTextColor) {
- painter->setPen(*m_customTextColor);
- } else {
- painter->setPen(itemListStyleOption.palette.text().color());
- }
+ painter->setPen(textColor());
painter->drawStaticText(m_textPos[Name], m_text[Name]);
painter->setPen(m_additionalInfoTextColor);
@@ -162,17 +157,8 @@ QRectF KFileItemListWidget::expansionToggleRect() const
void KFileItemListWidget::setTextColor(const QColor& color)
{
- if (color.isValid()) {
- if (!m_customTextColor) {
- m_customTextColor = new QColor(color);
- } else {
- *m_customTextColor = color;
- }
- updateAdditionalInfoTextColor();
- update();
- } else if (m_customTextColor){
- delete m_customTextColor;
- m_customTextColor = 0;
+ if (color != m_customTextColor) {
+ m_customTextColor = color;
updateAdditionalInfoTextColor();
update();
}
@@ -180,7 +166,23 @@ void KFileItemListWidget::setTextColor(const QColor& color)
QColor KFileItemListWidget::textColor() const
{
- return m_customTextColor ? *m_customTextColor : styleOption().palette.text().color();
+ return m_customTextColor.isValid() ? m_customTextColor : styleOption().palette.text().color();
+}
+
+void KFileItemListWidget::setOverlay(const QPixmap& overlay)
+{
+ const bool updateContent = (overlay.isNull() && !m_overlay.isNull()) ||
+ (!overlay.isNull() && m_overlay.isNull());
+ if (updateContent) {
+ m_overlay = overlay;
+ m_dirtyContent = true;
+ update();
+ }
+}
+
+QPixmap KFileItemListWidget::overlay() const
+{
+ return m_overlay;
}
void KFileItemListWidget::dataChanged(const QHash<QByteArray, QVariant>& current,
@@ -369,6 +371,10 @@ void KFileItemListWidget::updatePixmapCache()
Q_ASSERT(m_pixmap.height() == iconHeight);
}
+ if (!m_overlay.isNull()) {
+ QPainter painter(&m_pixmap);
+ painter.drawPixmap(0, m_pixmap.height() - m_overlay.height(), m_overlay);
+ }
m_scaledPixmapSize = QSize(scaledIconHeight, scaledIconHeight);
@@ -626,7 +632,7 @@ void KFileItemListWidget::updateAdditionalInfoTextColor()
// For the color of the additional info the inactive text color
// is not used as this might lead to unreadable text for some color schemes. Instead
// the text color is slightly mixed with the background color.
- const QColor c1 = m_customTextColor ? *m_customTextColor : styleOption().palette.text().color();
+ const QColor c1 = textColor();
const QColor c2 = styleOption().palette.background().color();
const int p1 = 70;
const int p2 = 100 - p1;
diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h
index 0332f1159..a16e75a8e 100644
--- a/src/kitemviews/kfileitemlistwidget.h
+++ b/src/kitemviews/kfileitemlistwidget.h
@@ -55,6 +55,9 @@ public:
protected:
void setTextColor(const QColor& color);
QColor textColor() const;
+
+ void setOverlay(const QPixmap& overlay);
+ QPixmap overlay() const;
virtual void dataChanged(const QHash<QByteArray, QVariant>& current, const QSet<QByteArray>& roles = QSet<QByteArray>());
virtual void visibleRolesChanged(const QHash<QByteArray, int>& current, const QHash<QByteArray, int>& previous);
@@ -116,8 +119,11 @@ private:
QList<QByteArray> m_sortedVisibleRoles;
QRectF m_expansionArea;
- QColor* m_customTextColor;
+
+ QColor m_customTextColor;
QColor m_additionalInfoTextColor;
+
+ QPixmap m_overlay;
};
#endif