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);
return m_isDir ? m_expansionArea : QRectF();
}
+QRectF KFileItemListWidget::selectionToggleRect() const
+{
+ const_cast<KFileItemListWidget*>(this)->triggerCacheRefreshing();
+
+ const int iconHeight = m_pixmap.height();
+
+ int toggleSize = KIconLoader::SizeSmall;
+ if (iconHeight >= KIconLoader::SizeEnormous) {
+ toggleSize = KIconLoader::SizeMedium;
+ } else if (iconHeight >= KIconLoader::SizeLarge) {
+ toggleSize = KIconLoader::SizeSmallMedium;
+ }
+
+ 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)
{
QString text;
}
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
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 {
}
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();