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:
parent
67db5ce960
commit
d21f690651
28
delegate.cpp
28
delegate.cpp
@ -239,7 +239,15 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
QRect subTitleRect = d->subTitleRect(option, index);
|
QRect subTitleRect = d->subTitleRect(option, index);
|
||||||
subTitleRect.moveTopLeft(subTitleRect.topLeft()-option.rect.topLeft());
|
subTitleRect.moveTopLeft(subTitleRect.topLeft()-option.rect.topLeft());
|
||||||
|
|
||||||
bool uniqueTitle = !index.data(d->roles[SubTitleMandatoryRole]).value<bool>();// true;
|
// 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) {
|
if (uniqueTitle) {
|
||||||
QModelIndex sib = index.sibling(index.row() + 1, index.column());
|
QModelIndex sib = index.sibling(index.row() + 1, index.column());
|
||||||
if (sib.isValid()) {
|
if (sib.isValid()) {
|
||||||
@ -253,6 +261,7 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (subTitleText == titleText) {
|
if (subTitleText == titleText) {
|
||||||
subTitleText.clear();
|
subTitleText.clear();
|
||||||
@ -289,19 +298,20 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
}
|
}
|
||||||
p.drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
|
p.drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
|
||||||
|
|
||||||
if (hover || !uniqueTitle) {
|
|
||||||
// draw sub-title, BUT only if:
|
// draw sub-title, BUT only if:
|
||||||
// * it isn't a unique title, this allows two items to have the same title and be
|
// * SubTitleMandatoryRole is defined and model returns 'true'
|
||||||
// disambiguated by their subtitle
|
// * SubTitleMandatoryRole is not defined and the adjasent model indexes
|
||||||
// * we are directed by the model that this item should never be treated as unique
|
// have the same contents of the Qt::DisplayRole
|
||||||
// e.g. the documents list in the recently used tab
|
// * when model doesn't provide a valid data for SubTitleMandatory role
|
||||||
// * the mouse is hovered over the item, causing the additional information to be
|
// we also show title on mouse hover
|
||||||
// displayed
|
|
||||||
//
|
//
|
||||||
// the rational for this is that subtitle text should in most cases not be
|
// 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
|
// 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
|
// 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.
|
// 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) {
|
if (option.palette.color(QPalette::Base).alpha() > 0) {
|
||||||
p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1));
|
p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1));
|
||||||
} else {
|
} else {
|
||||||
|
@ -41,6 +41,10 @@ class DelegatePrivate;
|
|||||||
* SubTitleRole: the text of the subtitle
|
* SubTitleRole: the text of the subtitle
|
||||||
* SubTitleMandatoryRole: if the subtitle is to always be displayed
|
* SubTitleMandatoryRole: if the subtitle is to always be displayed
|
||||||
* (as default the subtitle is displayed only on mouse over)
|
* (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)
|
* 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
|
* or a secondary action column (only a little icon that appears on mouse
|
||||||
* over is displayed)
|
* over is displayed)
|
||||||
|
Loading…
Reference in New Issue
Block a user