Hi, I changed abstracticon class to make the size of each item uniform in Add Widgets dialog. If the new codes are ok, please commit for me. Thanks.
The codes: http://pastebin.com/KXGiduEd The old and new screenshot: http://imagebin.org/167302 diff --git a/libs/plasmagenericshell/abstracticon.cpp b/libs/plasmagenericshell/abstracticon.cpp index 0fbdb9e..adda782 100644 --- a/libs/plasmagenericshell/abstracticon.cpp +++ b/libs/plasmagenericshell/abstracticon.cpp @@ -29,6 +29,8 @@ #include <QPropertyAnimation> #include <QStyleOptionGraphicsItem> #include <QPainter> +#include <QTextLayout> +#include <QTextLine> #include <KIconLoader> #include <KIcon> @@ -89,8 +91,8 @@ QSizeF AbstractIcon::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons qreal l, t, r, b; getContentsMargins(&l, &t, &r, &b); QFontMetrics fm(font()); - const int minHeight = m_iconHeight + 2 + fm.height(); - QSizeF s(qMax(m_iconHeight, fm.width(m_name)) + l + r, minHeight + t + b); + const int minHeight = m_iconHeight + 2 + fm.height()*3; //maximum 3 lines + QSizeF s(m_iconHeight*2 + l + r, minHeight + t + b); return s; } @@ -301,7 +303,32 @@ void AbstractIcon::paintForeground(QPainter *painter, const QStyleOptionGraphics } painter->drawPixmap(iconRect, pixmap(QSize(m_iconHeight, m_iconHeight))); - painter->drawText(textRect, flags, m_name); + + QTextLayout textLayout(m_name, painter->font()); + int totalWidth = 0; + int lineCreated = 0; + textLayout.beginLayout(); + + forever { + QTextLine line = textLayout.createLine(); + + if (!line.isValid()) + break; + + line.setLineWidth(textRect.width()); + totalWidth += line.naturalTextWidth(); + + lineCreated++; + } + textLayout.endLayout(); + + totalWidth += textRect.width(); + + if (lineCreated == 1) { + totalWidth = textRect.width(); + } + QString newText = painter->fontMetrics().elidedText(m_name, Qt::ElideRight, totalWidth); + painter->drawText(textRect, Qt::AlignHCenter | Qt::AlignVCenter | Qt::TextWordWrap, newText); } qreal AbstractIcon::backgroundFadeAlpha() const _______________________________________________ Plasma-devel mailing list Plasma-devel@kde.org https://mail.kde.org/mailman/listinfo/plasma-devel