From b8c718a6fd9810f9e91303ed50402de4ab417a49 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Tue, 6 Sep 2011 23:42:42 +0200 Subject: First step to reactivate version control plugin functionality - Add a DolphinFileItemListWidget that provides icon-overlays and colored text for the version state (implementation is missing yet) - Allow KFileItemListWidget to have custom text colors - Update interface of VersionControlObserver to work with KFileItemModel instead of the old model-interface. --- src/kitemviews/kfileitemlistwidget.cpp | 57 ++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 13 deletions(-) (limited to 'src/kitemviews/kfileitemlistwidget.cpp') diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp index 4fc3307ef..8cd124437 100644 --- a/src/kitemviews/kfileitemlistwidget.cpp +++ b/src/kitemviews/kfileitemlistwidget.cpp @@ -56,6 +56,7 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) : m_textBoundingRect(), m_sortedVisibleRoles(), m_expansionArea(), + m_customTextColor(0), m_additionalInfoTextColor() { for (int i = 0; i < TextIdCount; ++i) { @@ -66,6 +67,8 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) : KFileItemListWidget::~KFileItemListWidget() { + delete m_customTextColor; + m_customTextColor = 0; } void KFileItemListWidget::setLayout(Layout layout) @@ -114,7 +117,11 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte } painter->setFont(itemListStyleOption.font); - painter->setPen(itemListStyleOption.palette.text().color()); + if (m_customTextColor) { + painter->setPen(*m_customTextColor); + } else { + painter->setPen(itemListStyleOption.palette.text().color()); + } painter->drawStaticText(m_textPos[Name], m_text[Name]); painter->setPen(m_additionalInfoTextColor); @@ -153,6 +160,27 @@ QRectF KFileItemListWidget::expansionToggleRect() const return m_isDir ? m_expansionArea : QRectF(); } +void KFileItemListWidget::setTextColor(const QColor& color) +{ + if (color.isValid()) { + if (!m_customTextColor) { + m_customTextColor = new QColor(color); + } else { + *m_customTextColor = color; + } + } else { + delete m_customTextColor; + m_customTextColor = 0; + } + updateAdditionalInfoTextColor(); + update(); +} + +QColor KFileItemListWidget::textColor() const +{ + return m_customTextColor ? *m_customTextColor : styleOption().palette.text().color(); +} + void KFileItemListWidget::dataChanged(const QHash& current, const QSet& roles) { @@ -215,18 +243,7 @@ void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current const KItemListStyleOption& previous) { KItemListWidget::styleOptionChanged(current, previous); - - // 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 = current.palette.text().color(); - const QColor c2 = current.palette.background().color(); - const int p1 = 70; - const int p2 = 100 - p1; - m_additionalInfoTextColor = QColor((c1.red() * p1 + c2.red() * p2) / 100, - (c1.green() * p1 + c2.green() * p2) / 100, - (c1.blue() * p1 + c2.blue() * p2) / 100); - + updateAdditionalInfoTextColor(); m_dirtyLayout = true; } @@ -602,6 +619,20 @@ void KFileItemListWidget::updateDetailsLayoutTextCache() } } +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 c2 = styleOption().palette.background().color(); + const int p1 = 70; + const int p2 = 100 - p1; + m_additionalInfoTextColor = QColor((c1.red() * p1 + c2.red() * p2) / 100, + (c1.green() * p1 + c2.green() * p2) / 100, + (c1.blue() * p1 + c2.blue() * p2) / 100); +} + QString KFileItemListWidget::roleText(TextId textId, const QVariant& roleValue) const { QString text; -- cgit v1.3