QSizeF KStandardItemListWidgetInformant::itemSizeHint(int index, const KItemListView* view) const
{
- const QHash<QByteArray, QVariant> values = view->model()->data(index);
const KItemListStyleOption& option = view->styleOption();
const int additionalRolesCount = qMax(view->visibleRoles().count() - 1, 0);
switch (static_cast<const KStandardItemListView*>(view)->itemLayout()) {
case KStandardItemListWidget::IconsLayout: {
- const QString text = KStringHandler::preProcessWrap(values["text"].toString());
+ const QString text = KStringHandler::preProcessWrap(itemText(index, view));
const qreal itemWidth = view->itemSize().width();
const qreal maxWidth = itemWidth - 2 * option.padding;
// to show all roles without horizontal clipping.
qreal maximumRequiredWidth = 0.0;
+ const QHash<QByteArray, QVariant> values = view->model()->data(index);
foreach (const QByteArray& role, view->visibleRoles()) {
const QString text = roleText(role, values);
const qreal requiredWidth = option.fontMetrics.width(text);
return width;
}
+QString KStandardItemListWidgetInformant::itemText(int index, const KItemListView* view) const
+{
+ return view->model()->data(index).value("text").toString();
+}
+
QString KStandardItemListWidgetInformant::roleText(const QByteArray& role,
const QHash<QByteArray, QVariant>& values) const
{
qDeleteAll(m_textInfo);
m_textInfo.clear();
- delete m_roleEditor;
- delete m_oldRoleEditor;
+ if (m_roleEditor) {
+ m_roleEditor->deleteLater();
+ }
+
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
}
void KStandardItemListWidget::setLayout(Layout layout)
painter->setPen(Qt::green);
painter->drawRect(m_iconRect);
+ painter->setPen(Qt::blue);
+ painter->drawRect(m_textRect);
+
painter->setPen(Qt::red);
painter->drawText(QPointF(0, m_customizedFontMetrics.height()), QString::number(index()));
painter->drawRect(rect());
if (m_roleEditor) {
emit roleEditingCanceled(index(), current, data().value(current));
- disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
- disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+ disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
+ disconnect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
+
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
m_oldRoleEditor = m_roleEditor;
m_roleEditor->hide();
m_roleEditor = 0;
}
return;
- } else if (m_oldRoleEditor) {
- // Delete the old editor before constructing the new one to
- // prevent a memory leak.
- m_oldRoleEditor->deleteLater();
- m_oldRoleEditor = 0;
}
Q_ASSERT(!m_roleEditor);
const TextInfo* textInfo = m_textInfo.value("text");
m_roleEditor = new KItemListRoleEditor(parent);
- m_roleEditor->setIndex(index());
m_roleEditor->setRole(current);
m_roleEditor->setFont(styleOption().font);
m_roleEditor->setTextCursor(cursor);
}
- connect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
- connect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+ connect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
+ connect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
// Adjust the geometry of the editor
QRectF rect = roleEditingRect(current);
}
}
-void KStandardItemListWidget::slotRoleEditingCanceled(int index,
- const QByteArray& role,
+void KStandardItemListWidget::slotRoleEditingCanceled(const QByteArray& role,
const QVariant& value)
{
closeRoleEditor();
- emit roleEditingCanceled(index, role, value);
+ emit roleEditingCanceled(index(), role, value);
setEditedRole(QByteArray());
}
-void KStandardItemListWidget::slotRoleEditingFinished(int index,
- const QByteArray& role,
+void KStandardItemListWidget::slotRoleEditingFinished(const QByteArray& role,
const QVariant& value)
{
closeRoleEditor();
- emit roleEditingFinished(index, role, value);
+ emit roleEditingFinished(index(), role, value);
setEditedRole(QByteArray());
}
{
if (m_supportsItemExpanding) {
const QHash<QByteArray, QVariant> values = data();
- Q_ASSERT(values.contains("expandedParentsCount"));
const int expandedParentsCount = values.value("expandedParentsCount", 0).toInt();
if (expandedParentsCount >= 0) {
const qreal widgetHeight = size().height();
// use a generic icon as fallback
iconName = QLatin1String("unknown");
}
- m_pixmap = pixmapForIcon(iconName, maxIconHeight);
+ const QStringList overlays = values["iconOverlays"].toStringList();
+ m_pixmap = pixmapForIcon(iconName, overlays, maxIconHeight);
} else if (m_pixmap.width() != maxIconWidth || m_pixmap.height() != maxIconHeight) {
// A custom pixmap has been applied. Assure that the pixmap
// is scaled to the maximum available size.
KPixmapModifier::scale(m_pixmap, QSize(maxIconWidth, maxIconHeight));
}
- const QStringList overlays = values["iconOverlays"].toStringList();
-
- // Strangely KFileItem::overlays() returns empty string-values, so
- // we need to check first whether an overlay must be drawn at all.
- // It is more efficient to do it here, as KIconLoader::drawOverlays()
- // assumes that an overlay will be drawn and has some additional
- // setup time.
- foreach (const QString& overlay, overlays) {
- if (!overlay.isEmpty()) {
- // There is at least one overlay, draw all overlays above m_pixmap
- // and cancel the check
- KIconLoader::global()->drawOverlays(overlays, m_pixmap, KIconLoader::Desktop);
- break;
- }
- }
-
if (m_isCut) {
KIconEffect* effect = KIconLoader::global()->iconEffect();
m_pixmap = effect->apply(m_pixmap, KIconLoader::Desktop, KIconLoader::DisabledState);
const int textLength = line.textStart() + line.textLength();
if (textLength < nameText.length()) {
// Elide the last line of the text
- QString lastTextLine = nameText.mid(line.textStart(), line.textLength());
+ QString lastTextLine = nameText.mid(line.textStart());
lastTextLine = m_customizedFontMetrics.elidedText(lastTextLine,
Qt::ElideRight,
- line.naturalTextWidth() - 1);
+ maxWidth);
const QString elidedText = nameText.left(line.textStart()) + lastTextLine;
nameTextInfo->staticText.setText(elidedText);
+
+ const qreal lastLineWidth = m_customizedFontMetrics.boundingRect(lastTextLine).width();
+ nameWidth = qMax(nameWidth, lastLineWidth);
}
break;
}
y += lineSpacing;
}
- m_textRect = QRectF(x - option.padding, 0, maximumRequiredTextWidth + 2 * option.padding, widgetHeight);
+ m_textRect = QRectF(x - 2 * option.padding, 0, maximumRequiredTextWidth + 3 * option.padding, widgetHeight);
}
void KStandardItemListWidget::updateDetailsLayoutTextCache()
const qreal textWidth = option.extendedSelectionRegion
? size().width() - textInfo->pos.x()
: requiredWidth + 2 * option.padding;
- m_textRect = QRectF(textInfo->pos.x() - option.padding, 0,
- textWidth, size().height());
+ m_textRect = QRectF(textInfo->pos.x() - 2 * option.padding, 0,
+ textWidth + option.padding, size().height());
// The column after the name should always be aligned on the same x-position independent
// from the expansion-level shown in the name column
void KStandardItemListWidget::closeRoleEditor()
{
- disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingCanceled(int,QByteArray,QVariant)));
- disconnect(m_roleEditor, SIGNAL(roleEditingFinished(int,QByteArray,QVariant)),
- this, SLOT(slotRoleEditingFinished(int,QByteArray,QVariant)));
+ disconnect(m_roleEditor, SIGNAL(roleEditingCanceled(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingCanceled(QByteArray,QVariant)));
+ disconnect(m_roleEditor, SIGNAL(roleEditingFinished(QByteArray,QVariant)),
+ this, SLOT(slotRoleEditingFinished(QByteArray,QVariant)));
if (m_roleEditor->hasFocus()) {
// If the editing was not ended by a FocusOut event, we have
scene()->views()[0]->parentWidget()->setFocus();
}
+ if (m_oldRoleEditor) {
+ m_oldRoleEditor->deleteLater();
+ }
m_oldRoleEditor = m_roleEditor;
m_roleEditor->hide();
m_roleEditor = 0;
}
-QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, int size)
+QPixmap KStandardItemListWidget::pixmapForIcon(const QString& name, const QStringList& overlays, int size)
{
- const QString key = "KStandardItemListWidget:" % name % ":" % QString::number(size);
+ const QString key = "KStandardItemListWidget:" % name % ":" % overlays.join(":") % ":" % QString::number(size);
QPixmap pixmap;
if (!QPixmapCache::find(key, pixmap)) {
KPixmapModifier::scale(pixmap, QSize(size, size));
}
+ // Strangely KFileItem::overlays() returns empty string-values, so
+ // we need to check first whether an overlay must be drawn at all.
+ // It is more efficient to do it here, as KIconLoader::drawOverlays()
+ // assumes that an overlay will be drawn and has some additional
+ // setup time.
+ foreach (const QString& overlay, overlays) {
+ if (!overlay.isEmpty()) {
+ // There is at least one overlay, draw all overlays above m_pixmap
+ // and cancel the check
+ KIconLoader::global()->drawOverlays(overlays, pixmap, KIconLoader::Desktop);
+ break;
+ }
+ }
+
QPixmapCache::insert(key, pixmap);
}