if the background of the palette is transparent, plasmify
svn path=/trunk/KDE/kdelibs/; revision=963954
This commit is contained in:
parent
08aa5fe688
commit
3aac723ba5
57
delegate.cpp
57
delegate.cpp
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
// plasma
|
// plasma
|
||||||
#include <plasma/paintutils.h>
|
#include <plasma/paintutils.h>
|
||||||
|
#include <plasma/framesvg.h>
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -69,6 +70,7 @@ class DelegatePrivate
|
|||||||
static const int ITEM_BOTTOM_MARGIN = 5;
|
static const int ITEM_BOTTOM_MARGIN = 5;
|
||||||
|
|
||||||
bool m_showToolTip;
|
bool m_showToolTip;
|
||||||
|
FrameSvg *svg;
|
||||||
};
|
};
|
||||||
|
|
||||||
QFont DelegatePrivate::fontForSubTitle(const QFont &titleFont) const
|
QFont DelegatePrivate::fontForSubTitle(const QFont &titleFont) const
|
||||||
@ -144,6 +146,9 @@ Delegate::Delegate(QObject *parent)
|
|||||||
: QAbstractItemDelegate(parent),
|
: QAbstractItemDelegate(parent),
|
||||||
d(new DelegatePrivate)
|
d(new DelegatePrivate)
|
||||||
{
|
{
|
||||||
|
d->svg = new FrameSvg(this);
|
||||||
|
d->svg->setImagePath("widgets/viewitem");
|
||||||
|
d->svg->setElementPrefix("hover");
|
||||||
}
|
}
|
||||||
|
|
||||||
Delegate::~Delegate()
|
Delegate::~Delegate()
|
||||||
@ -230,7 +235,9 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
QString subTitleText = index.data(d->roles[SubTitleRole]).value<QString>();
|
QString subTitleText = index.data(d->roles[SubTitleRole]).value<QString>();
|
||||||
|
|
||||||
QRect titleRect = d->titleRect(option, index);
|
QRect titleRect = d->titleRect(option, index);
|
||||||
|
titleRect.moveTopLeft(titleRect.topLeft()-option.rect.topLeft());
|
||||||
QRect subTitleRect = d->subTitleRect(option, index);
|
QRect subTitleRect = d->subTitleRect(option, index);
|
||||||
|
subTitleRect.moveTopLeft(subTitleRect.topLeft()-option.rect.topLeft());
|
||||||
|
|
||||||
bool uniqueTitle = !index.data(d->roles[SubTitleMandatoryRole]).value<bool>();// true;
|
bool uniqueTitle = !index.data(d->roles[SubTitleMandatoryRole]).value<bool>();// true;
|
||||||
if (uniqueTitle) {
|
if (uniqueTitle) {
|
||||||
@ -270,11 +277,12 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
decorationIcon.paint(painter, decorationRect, option.decorationAlignment);
|
decorationIcon.paint(painter, decorationRect, option.decorationAlignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->save();
|
QPixmap buffer(option.rect.size());
|
||||||
|
buffer.fill(Qt::transparent);
|
||||||
|
QPainter p(&buffer);
|
||||||
// draw title
|
// draw title
|
||||||
painter->setFont(titleFont);
|
p.setFont(titleFont);
|
||||||
painter->drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
|
p.drawText(titleRect, Qt::AlignLeft|Qt::AlignVCenter, titleText);
|
||||||
|
|
||||||
if (hover || !uniqueTitle) {
|
if (hover || !uniqueTitle) {
|
||||||
// draw sub-title, BUT only if:
|
// draw sub-title, BUT only if:
|
||||||
@ -289,24 +297,24 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
// 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.
|
||||||
painter->setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1));
|
p.setPen(QPen(KColorScheme(QPalette::Active).foreground(KColorScheme::InactiveText), 1));
|
||||||
painter->setFont(subTitleFont);
|
p.setFont(subTitleFont);
|
||||||
painter->drawText(subTitleRect, Qt::AlignLeft|Qt::AlignVCenter, " " + subTitleText);
|
p.drawText(subTitleRect, Qt::AlignLeft|Qt::AlignVCenter, " " + subTitleText);
|
||||||
}
|
}
|
||||||
|
p.end();
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
|
|
||||||
d->m_showToolTip = false;
|
d->m_showToolTip = false;
|
||||||
|
|
||||||
painter->save();
|
const QColor gradientColor = KColorScheme(QPalette::Active).background(KColorScheme::NormalBackground).color();
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
const QColor gradientColor =
|
|
||||||
KColorScheme(QPalette::Active).background(KColorScheme::NormalBackground).color();
|
|
||||||
if (option.direction == Qt::LeftToRight) {
|
if (option.direction == Qt::LeftToRight) {
|
||||||
if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() ||
|
if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() ||
|
||||||
(subTitleRect.width() + decorationRect.width() + 15) > option.rect.width()) &&
|
(subTitleRect.width() + decorationRect.width() + 15) > option.rect.width()) &&
|
||||||
(titleRect.width() > 120 || subTitleRect.width() > 120)) {
|
(titleRect.width() > 120 || subTitleRect.width() > 120)) {
|
||||||
|
QPainter p(&buffer);
|
||||||
|
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
QLinearGradient gr;
|
QLinearGradient gr;
|
||||||
QRect gradientRect(option.rect.width() - 30, titleRect.y(),
|
QRect gradientRect(option.rect.width() - 30, titleRect.y(),
|
||||||
80, titleRect.height() + subTitleRect.height());
|
80, titleRect.height() + subTitleRect.height());
|
||||||
@ -315,15 +323,20 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
gr.setFinalStop(gradientRect.topRight());
|
gr.setFinalStop(gradientRect.topRight());
|
||||||
gr.setColorAt(0.0, Qt::transparent);
|
gr.setColorAt(0.0, Qt::transparent);
|
||||||
gr.setColorAt(0.7, gradientColor);
|
gr.setColorAt(0.7, gradientColor);
|
||||||
painter->setBrush(QBrush(gr));
|
p.setBrush(QBrush(gr));
|
||||||
painter->drawRect(gradientRect);
|
p.drawRect(gradientRect);
|
||||||
d->m_showToolTip = true;
|
d->m_showToolTip = true;
|
||||||
|
p.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() ||
|
if (((titleRect.width() + decorationRect.width() + 10) > option.rect.width() ||
|
||||||
(subTitleRect.width() + decorationRect.width() + 15 )> option.rect.width()) &&
|
(subTitleRect.width() + decorationRect.width() + 15 )> option.rect.width()) &&
|
||||||
(titleRect.width() > 120 || subTitleRect.width() > 120)) {
|
(titleRect.width() > 120 || subTitleRect.width() > 120)) {
|
||||||
|
buffer.fill(Qt::transparent);
|
||||||
|
QPainter p(&buffer);
|
||||||
|
p.setCompositionMode(QPainter::CompositionMode_DestinationOut);
|
||||||
|
p.setPen(Qt::NoPen);
|
||||||
QLinearGradient gr;
|
QLinearGradient gr;
|
||||||
QRect gradientRect(option.rect.x() - 25, titleRect.y(),
|
QRect gradientRect(option.rect.x() - 25, titleRect.y(),
|
||||||
60, titleRect.height() + subTitleRect.height());
|
60, titleRect.height() + subTitleRect.height());
|
||||||
@ -331,14 +344,16 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
gr.setFinalStop(gradientRect.topLeft());
|
gr.setFinalStop(gradientRect.topLeft());
|
||||||
gr.setColorAt(0.0, Qt::transparent);
|
gr.setColorAt(0.0, Qt::transparent);
|
||||||
gr.setColorAt(0.6, gradientColor);
|
gr.setColorAt(0.6, gradientColor);
|
||||||
painter->setBrush(QBrush(gr));
|
p.setBrush(QBrush(gr));
|
||||||
painter->drawRect(gradientRect);
|
p.drawRect(gradientRect);
|
||||||
|
|
||||||
d->m_showToolTip = true;
|
d->m_showToolTip = true;
|
||||||
|
p.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->drawPixmap(option.rect, buffer, buffer.rect());
|
||||||
|
|
||||||
|
|
||||||
if (hover) {
|
if (hover) {
|
||||||
painter->save();
|
painter->save();
|
||||||
@ -404,8 +419,14 @@ void Delegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|||||||
highlightRect.adjust(-roundedRadius, 0, +roundedRadius, 0);
|
highlightRect.adjust(-roundedRadius, 0, +roundedRadius, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if the view is transparent paint as plasma, otherwise paint with kde colors
|
||||||
|
if (option.palette.color(QPalette::Base).alpha() > 0) {
|
||||||
painter->setPen(outlinePen);
|
painter->setPen(outlinePen);
|
||||||
painter->drawPath(PaintUtils::roundedRectangle(highlightRect, roundedRadius));
|
painter->drawPath(PaintUtils::roundedRectangle(highlightRect, roundedRadius));
|
||||||
|
} else {
|
||||||
|
d->svg->resizeFrame(highlightRect.size());
|
||||||
|
d->svg->paintFrame(painter, highlightRect.topLeft());
|
||||||
|
}
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user