┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemlistwidget.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-08-08 23:41:18 +0200
committerPeter Penz <[email protected]>2011-08-09 16:22:36 +0200
commit3957884bf2e44619a4ed35ba0ffead519988885b (patch)
treed8a5bf1a015cc6001adb4afc5f0f1da721908a22 /src/kitemviews/kfileitemlistwidget.cpp
parent4692eb7c96f57328479862c0d17d7945b4e87188 (diff)
Improvements for selections, smooth scrolling, tooltips and info-panel
Diffstat (limited to 'src/kitemviews/kfileitemlistwidget.cpp')
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp47
1 files changed, 39 insertions, 8 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 91c0cb597..a5251439f 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -33,6 +33,7 @@
#include <QFontMetricsF>
#include <QGraphicsSceneResizeEvent>
#include <QPainter>
+#include <QStyleOption>
#include <QTextLayout>
#include <QTextLine>
@@ -91,6 +92,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
const_cast<KFileItemListWidget*>(this)->updateCache();
}
+ // Draw expansion toggle '>' or 'V'
if (m_isDir && !m_expansionArea.isEmpty()) {
QStyleOption arrowOption;
arrowOption.rect = m_expansionArea.toRect();
@@ -99,10 +101,8 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
style()->drawPrimitive(arrow, &arrowOption, painter);
}
- const bool isHovered = (hoverOpacity() > 0.0);
-
const KItemListStyleOption& itemListStyleOption = styleOption();
- if (isHovered) {
+ if (isHovered()) {
// Blend the unhovered and hovered pixmap if the hovering
// animation is ongoing
if (hoverOpacity() < 1.0) {
@@ -127,11 +127,11 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
drawPixmap(painter, m_pixmap);
}
- QFont font(itemListStyleOption.font);
- if (itemListStyleOption.state & QStyle::State_HasFocus) {
- font.setUnderline(true);
+ if (isCurrent()) {
+ drawFocusIndicator(painter);
}
- painter->setFont(font);
+
+ painter->setFont(itemListStyleOption.font);
painter->setPen(itemListStyleOption.palette.text().color());
painter->drawStaticText(m_textPos[Name], m_text[Name]);
@@ -244,6 +244,12 @@ void KFileItemListWidget::styleOptionChanged(const KItemListStyleOption& current
m_dirtyLayout = true;
}
+void KFileItemListWidget::hoveredChanged(bool hovered)
+{
+ Q_UNUSED(hovered);
+ m_dirtyLayout = true;
+}
+
void KFileItemListWidget::resizeEvent(QGraphicsSceneResizeEvent* event)
{
KItemListWidget::resizeEvent(event);
@@ -374,7 +380,7 @@ void KFileItemListWidget::updatePixmapCache()
m_hoverPixmapRect.moveTopLeft(QPointF(x, y));
// Prepare the pixmap that is used when the item gets hovered
- if (option.state & QStyle::State_MouseOver) {
+ if (isHovered()) {
m_hoverPixmap = m_pixmap;
KIconEffect* effect = KIconLoader::global()->iconEffect();
// In the KIconLoader terminology, active = hover.
@@ -681,6 +687,31 @@ void KFileItemListWidget::drawPixmap(QPainter* painter, const QPixmap& pixmap)
}
}
+void KFileItemListWidget::drawFocusIndicator(QPainter* painter)
+{
+ // Ideally style()->drawPrimitive(QStyle::PE_FrameFocusRect...)
+ // should be used, but Oxygen only draws indicators within classes
+ // derived from QAbstractItemView or Q3ListView. As a workaround
+ // the indicator is drawn manually. Code copied from oxygenstyle.cpp
+ // Copyright ( C ) 2009-2010 Hugo Pereira Da Costa <[email protected]>
+ // TODO: Clarify with Oxygen maintainers how to proceed with this.
+
+ const KItemListStyleOption& option = styleOption();
+ const QPalette palette = option.palette;
+ const QRect rect = m_textsBoundingRect.toRect().adjusted(0, 0, 0, -1);
+
+ QLinearGradient gradient(rect.bottomLeft(), rect.bottomRight());
+ gradient.setColorAt(0.0, Qt::transparent);
+ gradient.setColorAt(1.0, Qt::transparent);
+ gradient.setColorAt(0.2, palette.color(QPalette::Text));
+ gradient.setColorAt(0.8, palette.color(QPalette::Text));
+
+ painter->setRenderHint(QPainter::Antialiasing, false);
+ painter->setPen(QPen(gradient, 1));
+ painter->drawLine(rect.bottomLeft(), rect.bottomRight());
+ painter->setRenderHint(QPainter::Antialiasing, true);
+}
+
QPixmap KFileItemListWidget::pixmapForIcon(const QString& name, int size)
{
const KIcon icon(name);