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);
KFileItemListWidget::~KFileItemListWidget()
{
- delete m_customTextColor;
- m_customTextColor = 0;
}
void KFileItemListWidget::setLayout(Layout layout)
}
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);
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();
}
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,
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);
// 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;
#include "dolphinfileitemlistwidget.h"
-#include <kversioncontrolplugin.h>
+#include <KIcon>
+#include <KIconLoader>
#include <QColor>
#include <KDebug>
KFileItemListWidget::dataChanged(current, roles);
QColor color;
+ QPixmap overlay;
if (roles.contains("version")) {
// The item is under version control. Apply the text color corresponding
// to its version state.
const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(current.value("version").toInt());
- if (version != KVersionControlPlugin::UnversionedVersion) {
- const QColor textColor = styleOption().palette.text().color();
- QColor tintColor = textColor;
-
- // Using hardcoded colors is generally a bad idea. In this case the colors just act
- // as tint colors and are mixed with the current set text color. The tint colors
- // have been optimized for the base colors of the corresponding Oxygen emblems.
- switch (version) {
- case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break;
- case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::darkGreen; break;
- case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break;
- case KVersionControlPlugin::AddedVersion: tintColor = Qt::green; break;
- case KVersionControlPlugin::RemovedVersion: tintColor = Qt::darkRed; break;
- case KVersionControlPlugin::ConflictingVersion: tintColor = Qt::red; break;
- case KVersionControlPlugin::UnversionedVersion:
- case KVersionControlPlugin::NormalVersion:
- default:
- // use the default text color
- return;
- }
-
- color = QColor((tintColor.red() + textColor.red()) / 2,
- (tintColor.green() + textColor.green()) / 2,
- (tintColor.blue() + textColor.blue()) / 2,
- (tintColor.alpha() + textColor.alpha()) / 2);
+ const QColor textColor = styleOption().palette.text().color();
+ QColor tintColor = textColor;
+
+ // Using hardcoded colors is generally a bad idea. In this case the colors just act
+ // as tint colors and are mixed with the current set text color. The tint colors
+ // have been optimized for the base colors of the corresponding Oxygen emblems.
+ switch (version) {
+ case KVersionControlPlugin::UpdateRequiredVersion: tintColor = Qt::yellow; break;
+ case KVersionControlPlugin::LocallyModifiedUnstagedVersion: tintColor = Qt::green; break;
+ case KVersionControlPlugin::LocallyModifiedVersion: tintColor = Qt::green; break;
+ case KVersionControlPlugin::AddedVersion: tintColor = Qt::green; break;
+ case KVersionControlPlugin::RemovedVersion: tintColor = Qt::darkRed; break;
+ case KVersionControlPlugin::ConflictingVersion: tintColor = Qt::red; break;
+ case KVersionControlPlugin::UnversionedVersion: tintColor = Qt::white; break;
+ case KVersionControlPlugin::NormalVersion:
+ default:
+ break;
}
+
+ color = QColor((tintColor.red() + textColor.red()) / 2,
+ (tintColor.green() + textColor.green()) / 2,
+ (tintColor.blue() + textColor.blue()) / 2,
+ (tintColor.alpha() + textColor.alpha()) / 2);
+
+ overlay = overlayForState(version, styleOption().iconSize);
}
setTextColor(color);
+ setOverlay(overlay);
+}
+
+void DolphinFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current, const KItemListStyleOption& previous)
+{
+ KFileItemListWidget::styleOptionChanged(current, previous);
+
+ if (!overlay().isNull() && current.iconSize != previous.iconSize) {
+ const KVersionControlPlugin::VersionState version = static_cast<KVersionControlPlugin::VersionState>(data().value("version").toInt());
+ const QPixmap newOverlay = overlayForState(version, current.iconSize);
+ setOverlay(newOverlay);
+ }
+}
+
+QPixmap DolphinFileItemListWidget::overlayForState(KVersionControlPlugin::VersionState version, int size)
+{
+ int overlayHeight = KIconLoader::SizeSmall;
+ if (size >= KIconLoader::SizeEnormous) {
+ overlayHeight = KIconLoader::SizeMedium;
+ } else if (size >= KIconLoader::SizeLarge) {
+ overlayHeight = KIconLoader::SizeSmallMedium;
+ } else if (size >= KIconLoader::SizeMedium) {
+ overlayHeight = KIconLoader::SizeSmall;
+ } else {
+ overlayHeight = KIconLoader::SizeSmall / 2;
+ }
+
+ QString iconName;
+ switch (version) {
+ case KVersionControlPlugin::NormalVersion:
+ iconName = "vcs-normal";
+ break;
+ case KVersionControlPlugin::UpdateRequiredVersion:
+ iconName = "vcs-update-required";
+ break;
+ case KVersionControlPlugin::LocallyModifiedVersion:
+ iconName = "vcs-locally-modified";
+ break;
+ case KVersionControlPlugin::LocallyModifiedUnstagedVersion:
+ iconName = "vcs-locally-modified-unstaged";
+ break;
+ case KVersionControlPlugin::AddedVersion:
+ iconName = "vcs-added";
+ break;
+ case KVersionControlPlugin::RemovedVersion:
+ iconName = "vcs-removed";
+ break;
+ case KVersionControlPlugin::ConflictingVersion:
+ iconName = "vcs-conflicting";
+ break;
+ case KVersionControlPlugin::UnversionedVersion:
+ break;
+ default:
+ Q_ASSERT(false);
+ break;
+ }
+
+ return KIcon(iconName).pixmap(QSize(overlayHeight, overlayHeight));
}
#include "dolphinfileitemlistwidget.moc"