Rename KItemListWidget::hoverBoundingRect()

It has been split now to iconBoundingRect() and textBoundingRect().
This is required to implement the rubberband in an efficient way
and makes it more explicit what rectangle is returned.
This commit is contained in:
Peter Penz 2011-08-14 15:45:52 +02:00
parent e57bef0261
commit 5472115751
4 changed files with 38 additions and 33 deletions

View file

@ -53,7 +53,7 @@ KFileItemListWidget::KFileItemListWidget(QGraphicsItem* parent) :
m_hoverPixmap(),
m_textPos(),
m_text(),
m_textsBoundingRect(),
m_textBoundingRect(),
m_sortedVisibleRoles(),
m_expansionArea(),
m_additionalInfoTextColor()
@ -114,7 +114,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
drawPixmap(painter, m_hoverPixmap);
// Draw the hover background for the text
QRectF textsBoundingRect = m_textsBoundingRect;
QRectF textsBoundingRect = m_textBoundingRect;
const qreal marginDiff = itemListStyleOption.margin / 2;
textsBoundingRect.adjust(marginDiff, marginDiff, -marginDiff, -marginDiff);
painter->setOpacity(hoverOpacity() * opacity * 0.1);
@ -149,12 +149,7 @@ void KFileItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsIte
#endif
}
bool KFileItemListWidget::contains(const QPointF& point) const
{
return KItemListWidget::contains(point) || m_textsBoundingRect.contains(point);
}
QRectF KFileItemListWidget::hoverBoundingRect() const
QRectF KFileItemListWidget::iconBoundingRect() const
{
QRectF bounds = m_hoverPixmapRect;
const qreal margin = styleOption().margin;
@ -162,6 +157,11 @@ QRectF KFileItemListWidget::hoverBoundingRect() const
return bounds;
}
QRectF KFileItemListWidget::textBoundingRect() const
{
return m_textBoundingRect;
}
QRectF KFileItemListWidget::expansionToggleRect() const
{
return m_isDir ? m_expansionArea : QRectF();
@ -471,7 +471,7 @@ void KFileItemListWidget::updateIconsLayoutTextCache()
m_text[Name].setTextWidth(maxWidth);
m_textPos[Name] = QPointF(option.margin, widgetHeight - textLinesCount * fontHeight - option.margin);
m_textsBoundingRect = QRectF(option.margin + (maxWidth - requiredWidthForName) / 2,
m_textBoundingRect = QRectF(option.margin + (maxWidth - requiredWidthForName) / 2,
m_textPos[Name].y(),
requiredWidthForName,
m_text[Name].size().height());
@ -511,14 +511,14 @@ void KFileItemListWidget::updateIconsLayoutTextCache()
m_text[textId].setTextWidth(maxWidth);
const QRectF textBoundingRect(option.margin + (maxWidth - requiredWidth) / 2, y, requiredWidth, fontHeight);
m_textsBoundingRect |= textBoundingRect;
m_textBoundingRect |= textBoundingRect;
y += fontHeight;
}
// Add a margin to the text bounding rectangle
const qreal margin = option.margin;
m_textsBoundingRect.adjust(-margin, -margin, margin, margin);
m_textBoundingRect.adjust(-margin, -margin, margin, margin);
}
void KFileItemListWidget::updateCompactLayoutTextCache()
@ -560,7 +560,7 @@ void KFileItemListWidget::updateCompactLayoutTextCache()
y += fontHeight;
}
m_textsBoundingRect = QRectF(x - option.margin, 0, maximumRequiredTextWidth + 2 * option.margin, widgetHeight);
m_textBoundingRect = QRectF(x - option.margin, 0, maximumRequiredTextWidth + 2 * option.margin, widgetHeight);
}
void KFileItemListWidget::updateDetailsLayoutTextCache()
@ -571,7 +571,7 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
// +------+
// | Icon | Name role Additional role 1 Additional role 2
// +------+
m_textsBoundingRect = QRectF();
m_textBoundingRect = QRectF();
const KItemListStyleOption& option = styleOption();
const QHash<QByteArray, QVariant> values = data();
@ -597,7 +597,7 @@ void KFileItemListWidget::updateDetailsLayoutTextCache()
switch (textId) {
case Name: {
m_textsBoundingRect = QRectF(m_textPos[textId].x() - option.margin, 0,
m_textBoundingRect = QRectF(m_textPos[textId].x() - option.margin, 0,
requiredWidth + 2 * option.margin, size().height());
// The column after the name should always be aligned on the same x-position independent
@ -698,7 +698,7 @@ void KFileItemListWidget::drawFocusIndicator(QPainter* painter)
const KItemListStyleOption& option = styleOption();
const QPalette palette = option.palette;
const QRect rect = m_textsBoundingRect.toRect().adjusted(0, 0, 0, -1);
const QRect rect = m_textBoundingRect.toRect().adjusted(0, 0, 0, -1);
QLinearGradient gradient(rect.bottomLeft(), rect.bottomRight());
gradient.setColorAt(0.0, Qt::transparent);

View file

@ -48,8 +48,8 @@ public:
virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
virtual bool contains(const QPointF& point) const;
virtual QRectF hoverBoundingRect() const;
virtual QRectF iconBoundingRect() const;
virtual QRectF textBoundingRect() const;
virtual QRectF expansionToggleRect() const;
protected:
@ -107,7 +107,7 @@ private:
QPointF m_textPos[TextIdCount];
QStaticText m_text[TextIdCount];
QRectF m_textsBoundingRect;
QRectF m_textBoundingRect;
QList<QByteArray> m_sortedVisibleRoles;

View file

@ -95,11 +95,11 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
{
Q_UNUSED(option);
const QRect hoverBounds = hoverBoundingRect().toRect();
const QRect iconBounds = iconBoundingRect().toRect();
if (m_selected) {
QStyleOptionViewItemV4 viewItemOption;
viewItemOption.initFrom(widget);
viewItemOption.rect = hoverBounds;
viewItemOption.rect = iconBounds;
viewItemOption.state = QStyle::State_Enabled | QStyle::State_Selected | QStyle::State_Item;
viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
widget->style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &viewItemOption, painter, widget);
@ -110,14 +110,14 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
}
if (!m_hoverCache) {
m_hoverCache = new QPixmap(hoverBounds.size());
m_hoverCache = new QPixmap(iconBounds.size());
m_hoverCache->fill(Qt::transparent);
QPainter pixmapPainter(m_hoverCache);
QStyleOptionViewItemV4 viewItemOption;
viewItemOption.initFrom(widget);
viewItemOption.rect = QRect(0, 0, hoverBounds.width(), hoverBounds.height());
viewItemOption.rect = QRect(0, 0, iconBounds.width(), iconBounds.height());
viewItemOption.state = QStyle::State_Enabled | QStyle::State_MouseOver | QStyle::State_Item;
viewItemOption.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
@ -126,7 +126,7 @@ void KItemListWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* o
const qreal opacity = painter->opacity();
painter->setOpacity(m_hoverOpacity * opacity);
painter->drawPixmap(hoverBounds.topLeft(), *m_hoverCache);
painter->drawPixmap(iconBounds.topLeft(), *m_hoverCache);
painter->setOpacity(opacity);
}
@ -230,16 +230,16 @@ bool KItemListWidget::isHovered() const
bool KItemListWidget::contains(const QPointF& point) const
{
return hoverBoundingRect().contains(point) ||
if (!QGraphicsWidget::contains(point)) {
return false;
}
return iconBoundingRect().contains(point) ||
textBoundingRect().contains(point) ||
expansionToggleRect().contains(point) ||
selectionToggleRect().contains(point);
}
QRectF KItemListWidget::hoverBoundingRect() const
{
return QRectF(QPointF(0, 0), size());
}
QRectF KItemListWidget::selectionToggleRect() const
{
return QRectF();

View file

@ -83,16 +83,21 @@ public:
/**
* @return True if \a point is inside KItemListWidget::hoverBoundingRect(),
* KItemListWidget::selectionToggleRect() or KItemListWidget::expansionToggleRect().
* KItemListWidget::textBoundingRect(), KItemListWidget::selectionToggleRect()
* or KItemListWidget::expansionToggleRect().
* @reimp
*/
virtual bool contains(const QPointF& point) const;
/**
* @return Bounding rectangle for the area that acts as hovering-area. Per default
* the bounding rectangle of the KItemListWidget is returned.
* @return Bounding rectangle for the area that shows the icon.
*/
virtual QRectF hoverBoundingRect() const;
virtual QRectF iconBoundingRect() const = 0;
/**
* @return Bounding rectangle for the area that contains the text-properties.
*/
virtual QRectF textBoundingRect() const = 0;
/**
* @return Rectangle for the selection-toggle that is used to select or deselect an item.