┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/kitemviews/kfileitemlistwidget.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-11-13 20:55:51 +0100
committerPeter Penz <[email protected]>2011-11-13 20:58:43 +0100
commite560a2f6462044c4cf3c66366b6995cf74dd8e2d (patch)
tree40f953f9f848509e2b2a00ee120df3bb17776ef1 /src/kitemviews/kfileitemlistwidget.cpp
parent2438b61d8e76f8ea016217150be711a1467c32d0 (diff)
Fix selection style issues
Don't use a custom drawing code for showing the hover-indication or selection of the text. - The default style for items is used. - Merge icon-rectangle and text-rectangle if possible. - Fix background and minor focus-issues
Diffstat (limited to 'src/kitemviews/kfileitemlistwidget.cpp')
-rw-r--r--src/kitemviews/kfileitemlistwidget.cpp42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/kitemviews/kfileitemlistwidget.cpp b/src/kitemviews/kfileitemlistwidget.cpp
index 8fd00fa02..710253ae8 100644
--- a/src/kitemviews/kfileitemlistwidget.cpp
+++ b/src/kitemviews/kfileitemlistwidget.cpp
@@ -58,7 +58,8 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
m_expansionArea(),
m_customTextColor(),
m_additionalInfoTextColor(),
- m_overlay()
+ m_overlay(),
+ m_selectionTogglePos()
{
for (int i = 0; i < TextIdCount; ++i) {
m_text[i].setTextFormat(Qt::PlainText);
@@ -185,7 +186,26 @@ QRectF KFileItemListWidget::selectionToggleRect() const
toggleSize = KIconLoader::SizeSmallMedium;
}
- return QRectF(m_pixmapPos, QSizeF(toggleSize, toggleSize));
+ QPointF pos = m_selectionTogglePos;
+
+ // If the selection toggle has a very small distance to the
+ // widget borders, the size of the selection toggle will get
+ // increased to prevent an accidental clicking of the item
+ // when trying to hit the toggle.
+ const int widgetHeight = size().height();
+ const int widgetWidth = size().width();
+ const int minMargin = 2;
+
+ if (toggleSize + minMargin * 2 >= widgetHeight) {
+ toggleSize = widgetHeight;
+ pos.setY(0);
+ }
+ if (toggleSize + minMargin * 2 >= widgetWidth) {
+ toggleSize = widgetWidth;
+ pos.setX(0);
+ }
+
+ return QRectF(pos, QSizeF(toggleSize, toggleSize));
}
QString KFileItemListWidget::roleText(const QByteArray& role, const QHash<QByteArray, QVariant>& values)
@@ -397,6 +417,10 @@ void KFileItemListWidget::updatePixmapCache()
}
if (updatePixmap) {
+ // The selection toggle should always be applied to the top/left
+ // of the pixmap
+ m_selectionTogglePos = QPointF(-option.margin, -option.margin);
+
m_pixmap = values["iconPixmap"].value<QPixmap>();
if (m_pixmap.isNull()) {
// Use the icon that fits to the MIME-type
@@ -424,15 +448,17 @@ void KFileItemListWidget::updatePixmapCache()
squarePixmap.fill(Qt::transparent);
QPainter painter(&squarePixmap);
+ int x, y;
if (iconOnTop) {
- const int x = (iconHeight - m_pixmap.width()) / 2; // Center horizontally
- const int y = iconHeight - m_pixmap.height(); // Align on bottom
+ x = (iconHeight - m_pixmap.width()) / 2; // Center horizontally
+ y = iconHeight - m_pixmap.height(); // Align on bottom
painter.drawPixmap(x, y, m_pixmap);
} else {
- const int x = iconHeight - m_pixmap.width(); // Align right
- const int y = (iconHeight - m_pixmap.height()) / 2; // Center vertically
+ x = iconHeight - m_pixmap.width(); // Align right
+ y = (iconHeight - m_pixmap.height()) / 2; // Center vertically
painter.drawPixmap(x, y, m_pixmap);
}
+ m_selectionTogglePos += QPointF(x, y);
m_pixmap = squarePixmap;
} else {
@@ -455,6 +481,10 @@ void KFileItemListWidget::updatePixmapCache()
}
m_pixmapPos.setY(option.margin);
+ if (updatePixmap) {
+ m_selectionTogglePos += m_pixmapPos;
+ }
+
// Center the hover rectangle horizontally and align it on bottom
const qreal x = m_pixmapPos.x() + (m_scaledPixmapSize.width() - m_hoverPixmapRect.width()) / 2.0;
const qreal y = m_pixmapPos.y() + m_scaledPixmapSize.height() - m_hoverPixmapRect.height();