Commit ea7e3666 authored by Kurt Hindenburg's avatar Kurt Hindenburg
Browse files

Change Profile->Appearance display of the color scheme choices.

Patch by Rodrigo Fernandes rfernandes gmx com - some changes by myself.

REVIEW: 123480
parent a1957e8a
......@@ -519,6 +519,7 @@ void EditProfileDialog::updateColorSchemeList(bool selectCurrentScheme)
foreach(const ColorScheme* scheme, schemeList) {
QStandardItem* item = new QStandardItem(scheme->description());
item->setData(QVariant::fromValue(scheme) , Qt::UserRole + 1);
item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2);
item->setFlags(item->flags());
if (currentScheme == scheme)
......@@ -564,6 +565,7 @@ void EditProfileDialog::updateKeyBindingsList(bool selectCurrentTranslator)
QStandardItem* item = new QStandardItem(translator->description());
item->setEditable(false);
item->setData(QVariant::fromValue(translator), Qt::UserRole + 1);
item->setData(QVariant::fromValue(_profile->font()), Qt::UserRole + 2);
item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-keyboard")));
if (translator == currentTranslator)
......@@ -1248,93 +1250,62 @@ void ColorSchemeViewDelegate::paint(QPainter* painter, const QStyleOptionViewIte
const QModelIndex& index) const
{
const ColorScheme* scheme = index.data(Qt::UserRole + 1).value<const ColorScheme*>();
QFont profileFont = index.data(Qt::UserRole + 2).value<QFont>();
Q_ASSERT(scheme);
if (!scheme)
return;
bool transparencyAvailable = KWindowSystem::compositingActive();
painter->setRenderHint(QPainter::Antialiasing);
// draw background
painter->setPen(QPen(scheme->foregroundColor() , 1));
// Draw background
QStyle *style = option.widget ? option.widget->style() : QApplication::style();
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, option.widget);
// radial gradient for background
// from a lightened version of the scheme's background color in the center to
// a darker version at the outer edge
QColor color = scheme->backgroundColor();
QRectF backgroundRect = QRectF(option.rect).adjusted(1.5, 1.5, -1.5, -1.5);
// Draw name
QPalette::ColorRole textColor = (option.state & QStyle::State_Selected) ?
QPalette::HighlightedText: QPalette::Text;
painter->setPen(option.palette.color(textColor));
painter->setFont(option.font);
QRadialGradient backgroundGradient(backgroundRect.center() , backgroundRect.width() / 2);
backgroundGradient.setColorAt(0 , color.lighter(105));
backgroundGradient.setColorAt(1 , color.darker(115));
// Determine width of sample text using profile's font
const QString sampleText = i18n("AaZz09...");
QFontMetrics profileFontMetrics(profileFont);
const int sampleTextWidth = profileFontMetrics.width(sampleText);
const int backgroundRectXRoundness = 4;
const int backgroundRectYRoundness = 30;
painter->drawText(option.rect.adjusted(sampleTextWidth + 15,0,0,0),
Qt::AlignLeft | Qt::AlignVCenter,
index.data(Qt::DisplayRole).value<QString>());
QPainterPath backgroundRectPath(backgroundRect.topLeft());
backgroundRectPath.addRoundRect(backgroundRect , backgroundRectXRoundness , backgroundRectYRoundness);
// Draw the preview
const int x = option.rect.left();
const int y = option.rect.top();
if (transparencyAvailable) {
painter->save();
color.setAlphaF(scheme->opacity());
painter->setCompositionMode(QPainter::CompositionMode_Source);
painter->setBrush(backgroundGradient);
QRect previewRect(x + 4, y + 4, sampleTextWidth + 8, option.rect.height() - 8);
painter->drawPath(backgroundRectPath);
painter->restore();
} else {
painter->setBrush(backgroundGradient);
painter->drawPath(backgroundRectPath);
}
bool transparencyAvailable = KWindowSystem::compositingActive();
// draw stripe at the side using scheme's foreground color
painter->setPen(QPen(Qt::NoPen));
QPainterPath path(option.rect.topLeft());
path.lineTo(option.rect.width() / 10.0 , option.rect.top());
path.lineTo(option.rect.bottomLeft());
path.lineTo(option.rect.topLeft());
painter->setBrush(scheme->foregroundColor());
painter->drawPath(path.intersected(backgroundRectPath));
// draw highlight
// with a linear gradient going from translucent white to transparent
QLinearGradient gradient(option.rect.topLeft() , option.rect.bottomLeft());
gradient.setColorAt(0 , QColor(255, 255, 255, 90));
gradient.setColorAt(1 , Qt::transparent);
painter->setBrush(gradient);
painter->drawRoundRect(backgroundRect , 4 , 30);
const bool isSelected = option.state & QStyle::State_Selected;
// draw border on selected items
if (isSelected) {
static const int selectedBorderWidth = 6;
painter->setBrush(QBrush(Qt::NoBrush));
QPen pen;
QColor highlightColor = option.palette.highlight().color();
highlightColor.setAlphaF(1.0);
pen.setBrush(highlightColor);
pen.setWidth(selectedBorderWidth);
pen.setJoinStyle(Qt::MiterJoin);
painter->setPen(pen);
painter->drawRect(option.rect.adjusted(selectedBorderWidth / 2,
selectedBorderWidth / 2,
-selectedBorderWidth / 2,
-selectedBorderWidth / 2));
if (transparencyAvailable) {
painter->save();
QColor color = scheme->backgroundColor();
color.setAlphaF(scheme->opacity());
painter->setPen(Qt::NoPen);
painter->setCompositionMode(QPainter::CompositionMode_Source);
painter->setBrush(color);
painter->drawRect(previewRect);
painter->restore();
} else {
painter->setPen(Qt::NoPen);
painter->setBrush(scheme->backgroundColor());
painter->drawRect(previewRect);
}
// draw color scheme name using scheme's foreground color
QPen pen(scheme->foregroundColor());
painter->setPen(pen);
painter->drawText(option.rect , Qt::AlignCenter ,
index.data(Qt::DisplayRole).value<QString>());
// TODO: respect antialias setting
painter->setFont(profileFont);
painter->drawText(previewRect , Qt::AlignCenter, sampleText);
}
QSize ColorSchemeViewDelegate::sizeHint(const QStyleOptionViewItem& option,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment