Improve subitle showing in Plasma::Delegate.

Automatically show subtitle for adjasent items with the same content
only when model doesn't provide explicit data for SubTitleMandatoryRole,
otherwise respect what model says and set visibility of subtitle accordingly

Review: http://reviewboard.kde.org/r/1357/

svn path=/trunk/KDE/kdelibs/; revision=1014442
This commit is contained in:
Dmitry Suzdalev 2009-08-22 20:47:15 +00:00
parent 67db5ce960
commit d21f690651
2 changed files with 36 additions and 22 deletions

View File

@ -239,18 +239,27 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
QRect subTitleRect = d->subTitleRect(option, index);
subTitleRect.moveTopLeft(subTitleRect.topLeft()-option.rect.topLeft());
bool uniqueTitle = !index.data(d->roles[SubTitleMandatoryRole]).value<bool>();// true;
if (uniqueTitle) {
QModelIndex sib = index.sibling(index.row() + 1, index.column());
if (sib.isValid()) {
uniqueTitle = sib.data(Qt::DisplayRole).value<QString>() != titleText;
}
// If the model wants to have exact control for subtitles showing
// it is expected to return a valid data for SubTitleMandatoryRole.
// If it doesn't return a valid data for this role
// then by default we well be showing a subtitles for
// adjasent items with the same content (see comments below too)
bool uniqueTitle = true;
QVariant mandatoryRoleData = index.data(d->roles[SubTitleMandatoryRole]);
if (!mandatoryRoleData.isValid()) {
uniqueTitle = !mandatoryRoleData.value<bool>();// true;
if (uniqueTitle) {
sib = index.sibling(index.row() + -1, index.column());
QModelIndex sib = index.sibling(index.row() + 1, index.column());
if (sib.isValid()) {
uniqueTitle = sib.data(Qt::DisplayRole).value<QString>() != titleText;
}
if (uniqueTitle) {
sib = index.sibling(index.row() + -1, index.column());
if (sib.isValid()) {
uniqueTitle = sib.data(Qt::DisplayRole).value<QString>() != titleText;
}
}
}
}
@ -289,19 +298,20 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
}
p.drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
if (hover || !uniqueTitle) {
// draw sub-title, BUT only if:
// * it isn't a unique title, this allows two items to have the same title and be
// disambiguated by their subtitle
// * we are directed by the model that this item should never be treated as unique
// e.g. the documents list in the recently used tab
// * the mouse is hovered over the item, causing the additional information to be
// displayed
//
// the rational for this is that subtitle text should in most cases not be
// required to understand the item itself and that showing all the subtexts in a
// listing makes the information density very high, impacting both the speed at
// which one can scan the list visually and the aesthetic qualities of the listing.
// draw sub-title, BUT only if:
// * SubTitleMandatoryRole is defined and model returns 'true'
// * SubTitleMandatoryRole is not defined and the adjasent model indexes
// have the same contents of the Qt::DisplayRole
// * when model doesn't provide a valid data for SubTitleMandatory role
// we also show title on mouse hover
//
// the rationale for this is that subtitle text should in most cases not be
// required to understand the item itself and that showing all the subtexts in a
// listing makes the information density very high, impacting both the speed at
// which one can scan the list visually and the aesthetic qualities of the listing.
bool drawSubTitle = mandatoryRoleData.isValid() ? mandatoryRoleData.value<bool>() : (hover || !uniqueTitle);
if (drawSubTitle) {
if (option.palette.color(QPalette::Base).alpha() > 0) {
p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1));
} else {

View File

@ -41,6 +41,10 @@ class DelegatePrivate;
* SubTitleRole: the text of the subtitle
* SubTitleMandatoryRole: if the subtitle is to always be displayed
* (as default the subtitle is displayed only on mouse over)
* NOTE: if model doesn't return a valid data for SubTitleMandatoryRole (i.e. if it returns QVaraint())
* then subtitles will be shown for adjasent items with the same content and not shown
* otherwise.
*
* ColumnTypeRole: if the column is a main column (with title and subtitle)
* or a secondary action column (only a little icon that appears on mouse
* over is displayed)