diff options
| author | Peter Penz <[email protected]> | 2011-09-06 23:42:42 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2011-09-06 23:45:41 +0200 |
| commit | b8c718a6fd9810f9e91303ed50402de4ab417a49 (patch) | |
| tree | f6e22b028cb0932c44dc29ea6c494f121c6f8dc9 /src/kitemviews | |
| parent | 7a91492cff931c0c4e0d38dd0aee77d9dcb29373 (diff) | |
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.
Diffstat (limited to 'src/kitemviews')
| -rw-r--r-- | src/kitemviews/kfileitemlistview.h | 9 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.cpp | 57 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemlistwidget.h | 6 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.cpp | 9 | ||||
| -rw-r--r-- | src/kitemviews/kfileitemmodel.h | 5 |
5 files changed, 73 insertions, 13 deletions
diff --git a/src/kitemviews/kfileitemlistview.h b/src/kitemviews/kfileitemlistview.h index 4f7e84e29..1fb7bf352 100644 --- a/src/kitemviews/kfileitemlistview.h +++ b/src/kitemviews/kfileitemlistview.h @@ -27,6 +27,15 @@ class KFileItemModelRolesUpdater; class QTimer; +/** + * @brief View that allows to show the content of file-items. + * + * The corresponding model set by the controller must be an instance + * of KFileItemModel. Per default KFileItemListWidget is set as widget creator + * value and KItemListGroupHeader as group-header creator value. Use + * KItemListView::setWidgetCreator() and KItemListView::setGroupHeaderCreator() + * to apply customized generators. + */ class LIBDOLPHINPRIVATE_EXPORT KFileItemListView : public KItemListView { Q_OBJECT 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<QByteArray, QVariant>& current, const QSet<QByteArray>& 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; diff --git a/src/kitemviews/kfileitemlistwidget.h b/src/kitemviews/kfileitemlistwidget.h index 03ab17b54..0332f1159 100644 --- a/src/kitemviews/kfileitemlistwidget.h +++ b/src/kitemviews/kfileitemlistwidget.h @@ -53,6 +53,9 @@ public: virtual QRectF expansionToggleRect() const; protected: + void setTextColor(const QColor& color); + QColor textColor() 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); virtual void visibleRolesSizesChanged(const QHash<QByteArray, QSizeF>& current, const QHash<QByteArray, QSizeF>& previous); @@ -82,6 +85,8 @@ private: void updateIconsLayoutTextCache(); void updateCompactLayoutTextCache(); void updateDetailsLayoutTextCache(); + + void updateAdditionalInfoTextColor(); QString roleText(TextId textId, const QVariant& roleValue) const; @@ -111,6 +116,7 @@ private: QList<QByteArray> m_sortedVisibleRoles; QRectF m_expansionArea; + QColor* m_customTextColor; QColor m_additionalInfoTextColor; }; diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 401ba218d..2a52de986 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -213,6 +213,15 @@ int KFileItemModel::index(const KFileItem& item) const return m_items.value(item, -1); } +KUrl KFileItemModel::rootDirectory() const +{ + const KDirLister* dirLister = m_dirLister.data(); + if (dirLister) { + return dirLister->url(); + } + return KUrl(); +} + void KFileItemModel::clear() { slotClear(); diff --git a/src/kitemviews/kfileitemmodel.h b/src/kitemviews/kfileitemmodel.h index c70892dd3..189c50846 100644 --- a/src/kitemviews/kfileitemmodel.h +++ b/src/kitemviews/kfileitemmodel.h @@ -90,6 +90,11 @@ public: int index(const KFileItem& item) const; /** + * @return Root directory of all items. + */ + KUrl rootDirectory() const; + + /** * Clears all items of the model. */ void clear(); |
