mirror of
https://invent.kde.org/system/dolphin
synced 2024-09-20 00:41:23 +00:00
Just change the text color for revisioned files instead of using a completely filled background. I'm unsure whether we should use emblems or not... The problem with emblems is that most people that work with revisioned files use the details view with very small icons. So having an emblem above an icon and additionally the selection indicator does not work. Any ideas?
svn path=/trunk/KDE/kdebase/apps/; revision=995378
This commit is contained in:
parent
01a158c9e0
commit
220355ca8d
|
@ -25,7 +25,9 @@
|
|||
#include <QAbstractItemModel>
|
||||
#include <QAbstractProxyModel>
|
||||
#include <QFontMetrics>
|
||||
#include <QPalette>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionViewItemV4>
|
||||
|
||||
DolphinFileItemDelegate::DolphinFileItemDelegate(QObject* parent) :
|
||||
KFileItemDelegate(parent),
|
||||
|
@ -43,45 +45,34 @@ void DolphinFileItemDelegate::paint(QPainter* painter,
|
|||
{
|
||||
const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(index.model());
|
||||
const DolphinModel* dolphinModel = static_cast<const DolphinModel*>(proxyModel->sourceModel());
|
||||
|
||||
if (m_hasMinimizedNameColumn && (index.column() == KDirModel::Name)) {
|
||||
QStyleOptionViewItemV4 opt(option);
|
||||
|
||||
const QModelIndex dirIndex = proxyModel->mapToSource(index);
|
||||
const KFileItem item = dolphinModel->itemForIndex(dirIndex);
|
||||
if (!item.isNull()) {
|
||||
// symbolic links are displayed in an italic font
|
||||
if (item.isLink()) {
|
||||
opt.font.setItalic(true);
|
||||
}
|
||||
|
||||
const int width = nameColumnWidth(item.text(), opt);
|
||||
opt.rect.setWidth(width);
|
||||
}
|
||||
KFileItemDelegate::paint(painter, opt, index);
|
||||
} else {
|
||||
KFileItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
const bool useMinimizedNameColumn = m_hasMinimizedNameColumn && (index.column() == KDirModel::Name);
|
||||
|
||||
if (dolphinModel->hasRevisionData()) {
|
||||
// The currently shown items are under revision control. Show the current revision
|
||||
// state above the decoration.
|
||||
// state by adjusting the text color.
|
||||
const QModelIndex dirIndex = proxyModel->mapToSource(index);
|
||||
const QModelIndex revisionIndex = dolphinModel->index(dirIndex.row(), DolphinModel::Revision);
|
||||
const QVariant data = dolphinModel->data(revisionIndex, Qt::DecorationRole);
|
||||
const DolphinModel::RevisionState state = static_cast<DolphinModel::RevisionState>(data.toInt());
|
||||
|
||||
if (state != DolphinModel::LocalRevision) {
|
||||
// TODO: The following code is just a proof of concept. Icons will be used later...
|
||||
QColor color(200, 0, 0, 32);
|
||||
switch (state) {
|
||||
case DolphinModel::LatestRevision: color = QColor(0, 180, 0, 32); break;
|
||||
// ...
|
||||
default: break;
|
||||
QStyleOptionViewItemV4 opt(option);
|
||||
// TODO: use different colors for different states
|
||||
opt.palette.setColor(QPalette::Text, QColor(40, 150, 40));
|
||||
if (useMinimizedNameColumn) {
|
||||
adjustOptionWidth(opt, proxyModel, dolphinModel, index);
|
||||
}
|
||||
painter->fillRect(option.rect, color);
|
||||
KFileItemDelegate::paint(painter, opt, index);
|
||||
return;
|
||||
}
|
||||
} else if (useMinimizedNameColumn) {
|
||||
QStyleOptionViewItemV4 opt(option);
|
||||
adjustOptionWidth(opt, proxyModel, dolphinModel, index);
|
||||
KFileItemDelegate::paint(painter, opt, index);
|
||||
return;
|
||||
}
|
||||
|
||||
KFileItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOptionViewItem& option)
|
||||
|
@ -96,3 +87,21 @@ int DolphinFileItemDelegate::nameColumnWidth(const QString& name, const QStyleOp
|
|||
return width;
|
||||
}
|
||||
|
||||
void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
|
||||
const QAbstractProxyModel* proxyModel,
|
||||
const DolphinModel* dolphinModel,
|
||||
const QModelIndex& index)
|
||||
{
|
||||
const QModelIndex dirIndex = proxyModel->mapToSource(index);
|
||||
const KFileItem item = dolphinModel->itemForIndex(dirIndex);
|
||||
if (!item.isNull()) {
|
||||
// symbolic links are displayed in an italic font
|
||||
if (item.isLink()) {
|
||||
option.font.setItalic(true);
|
||||
}
|
||||
|
||||
const int width = nameColumnWidth(item.text(), option);
|
||||
option.rect.setWidth(width);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
|
||||
#include <kfileitemdelegate.h>
|
||||
|
||||
class DolphinModel;
|
||||
class QAbstractProxyModel;
|
||||
|
||||
/**
|
||||
* Extends KFileItemDelegate by the ability to show the hover effect
|
||||
* and the selection in a minimized way for the name column of
|
||||
|
@ -57,6 +60,12 @@ public:
|
|||
*/
|
||||
static int nameColumnWidth(const QString& name, const QStyleOptionViewItem& option);
|
||||
|
||||
private:
|
||||
static void adjustOptionWidth(QStyleOptionViewItemV4& option,
|
||||
const QAbstractProxyModel* proxyModel,
|
||||
const DolphinModel* dolphinModel,
|
||||
const QModelIndex& index);
|
||||
|
||||
private:
|
||||
bool m_hasMinimizedNameColumn;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue