Commit 5bac30ab authored by Riccardo Degli Esposti's avatar Riccardo Degli Esposti 🍌 Committed by Tomaz Canabrava
Browse files

Separate bgcolor and wallpaper opacities

parent 2dc1aa42
......@@ -188,7 +188,7 @@ ColorScheme::ColorScheme()
, _colorRandomization(false)
, _wallpaper(nullptr)
{
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5f, 0.5f));
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5f, 0.5f), 1.0);
}
ColorScheme::ColorScheme(const ColorScheme &other)
......@@ -465,10 +465,10 @@ void ColorScheme::read(const KConfig &config)
_description = i18n(schemeDescription.toUtf8().constData());
setOpacity(configGroup.readEntry("Opacity", 1.0));
_blur = configGroup.readEntry("Blur", false);
setWallpaper(
configGroup.readEntry("Wallpaper", QString()),
configGroup.readEntry("FillStyle", QString::fromLatin1("Tile")),
configGroup.readEntry("Anchor", QPointF(0.5f, 0.5f)));
setWallpaper(configGroup.readEntry("Wallpaper", QString()),
configGroup.readEntry("FillStyle", QString::fromLatin1("Tile")),
configGroup.readEntry("Anchor", QPointF(0.5f, 0.5f)),
configGroup.readEntry("WallpaperOpacity", 1.0));
_colorRandomization = configGroup.readEntry(EnableColorRandomizationKey, false);
for (int i = 0; i < TABLE_COLORS; i++) {
......@@ -533,6 +533,7 @@ void ColorScheme::write(KConfig &config) const
QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>()
.valueToKey(_wallpaper->style()));
configGroup.writeEntry("Anchor", _wallpaper->anchor());
configGroup.writeEntry("WallpaperOpacity", _wallpaper->opacity());
configGroup.writeEntry(EnableColorRandomizationKey, _colorRandomization);
for (int i = 0; i < TABLE_COLORS; i++) {
......@@ -580,12 +581,12 @@ void ColorScheme::writeColorEntry(KConfig &config, int index) const
checkAndMaybeSaveValue(RandomLightnessRangeKey, random.lightness);
}
void ColorScheme::setWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor)
void ColorScheme::setWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity)
{
_wallpaper = new ColorSchemeWallpaper(path, style, anchor);
_wallpaper = new ColorSchemeWallpaper(path, style, anchor, opacity);
}
void ColorScheme::setWallpaper(const QString &path, const QString &style, const QPointF &anchor)
void ColorScheme::setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity)
{
ColorSchemeWallpaper::FillStyle fstyle;
fstyle = static_cast<ColorSchemeWallpaper::FillStyle>
......@@ -594,7 +595,7 @@ void ColorScheme::setWallpaper(const QString &path, const QString &style, const
.keyToValue(style.toStdString().c_str())
, 0));
setWallpaper(path, fstyle, anchor);
setWallpaper(path, fstyle, anchor, opacity);
}
ColorSchemeWallpaper::Ptr ColorScheme::wallpaper() const
......
......@@ -133,8 +133,8 @@ public:
*/
bool blur() const;
void setWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor);
void setWallpaper(const QString &path, const QString &style, const QPointF &anchor);
void setWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity);
void setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity);
ColorSchemeWallpaper::Ptr wallpaper() const;
......
......@@ -89,6 +89,8 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget *parent)
_ui->wallpaperPath->setClearButtonEnabled(true);
_ui->wallpaperSelectButton->setIcon(QIcon::fromTheme(QStringLiteral("image-x-generic")));
connect(_ui->wallpaperTransparencySlider, &QSlider::valueChanged, this, &Konsole::ColorSchemeEditor::wallpaperOpacityChanged);
connect(_ui->wallpaperSelectButton, &QToolButton::clicked, this, &Konsole::ColorSchemeEditor::selectWallpaper);
connect(_ui->wallpaperPath, &QLineEdit::textChanged, this, &Konsole::ColorSchemeEditor::wallpaperPathChanged);
......@@ -188,28 +190,36 @@ void ColorSchemeEditor::selectWallpaper()
}
}
void ColorSchemeEditor::wallpaperOpacityChanged(int percent)
{
_ui->wallpaperTransparencyPercentLabel->setText(QStringLiteral("%1%").arg(percent));
const qreal opacity = (100.0 - percent) / 100.0;
_colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), _colors->wallpaper()->anchor(), opacity);
}
void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
{
if (path.isEmpty()) {
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor());
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
} else {
QFileInfo i(path);
if (i.exists() && i.isFile() && i.isReadable()) {
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor());
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
}
}
}
void ColorSchemeEditor::scalingTypeChanged(QString style)
{
_colors->setWallpaper(_colors->wallpaper()->path(), style, _colors->wallpaper()->anchor());
_colors->setWallpaper(_colors->wallpaper()->path(), style, _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
}
void ColorSchemeEditor::horizontalAnchorChanged(int pos)
{
QPointF anch = _colors->wallpaper()->anchor();
_colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(pos / 2.0, anch.y()));
_colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(pos / 2.0, anch.y()), _colors->wallpaper()->opacity());
switch (pos) {
case 2:
_ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Right"));
......@@ -227,7 +237,7 @@ void ColorSchemeEditor::horizontalAnchorChanged(int pos)
void ColorSchemeEditor::verticalAnchorChanged(int pos)
{
QPointF anch = _colors->wallpaper()->anchor();
_colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(anch.x(), pos / 2.0));
_colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(anch.x(), pos / 2.0), _colors->wallpaper()->opacity());
switch (pos) {
case 2:
_ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Bottom"));
......
......@@ -68,6 +68,7 @@ private Q_SLOTS:
void setBlur(bool blur);
void setRandomizedBackgroundColor(bool randomized);
void editColorItem(QTableWidgetItem *item);
void wallpaperOpacityChanged(int percent);
void wallpaperPathChanged(const QString &path);
void scalingTypeChanged(QString style);
void horizontalAnchorChanged(int pos);
......
......@@ -66,7 +66,7 @@ To see any effect, set colors with saturation value greater than 0.</string>
<item>
<widget class="QLabel" name="transparencyLabel">
<property name="text">
<string>Background transparency:</string>
<string>Background color transparency:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
......@@ -95,6 +95,40 @@ To see any effect, set colors with saturation value greater than 0.</string>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="wallpaperTransparencyLabel">
<property name="text">
<string>Wallpaper transparency:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="wallpaperTransparencySlider">
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="wallpaperTransparencyPercentLabel">
<property name="text">
<string>Percent</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
......
......@@ -17,11 +17,12 @@
using namespace Konsole;
ColorSchemeWallpaper::ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor)
ColorSchemeWallpaper::ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity)
: _path(path)
, _picture(nullptr)
, _style(style)
, _anchor(anchor)
, _opacity(opacity)
{
float x = _anchor.x(), y = _anchor.y();
......@@ -52,26 +53,17 @@ bool ColorSchemeWallpaper::isNull() const
return _path.isEmpty();
}
bool ColorSchemeWallpaper::draw(QPainter &painter, const QRect rect, qreal opacity)
bool ColorSchemeWallpaper::draw(QPainter &painter, const QRect rect, qreal bgColorOpacity, const QColor &backgroundColor)
{
if ((_picture == nullptr) || _picture->isNull()) {
return false;
}
if (qFuzzyCompare(qreal(1.0), opacity)) {
if (_style == Tile) {
painter.drawTiledPixmap(rect, *_picture, rect.topLeft());
} else {
QRectF srcRect = ScaledRect(painter.viewport().size(), _picture->size(), rect);
painter.drawPixmap(rect, *_picture, srcRect);
}
return true;
}
painter.save();
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(rect, QColor(0, 0, 0, 0));
painter.setOpacity(opacity);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.setOpacity(bgColorOpacity);
painter.fillRect(rect, backgroundColor);
painter.setOpacity(_opacity);
if (_style == Tile) {
painter.drawTiledPixmap(rect, *_picture, rect.topLeft());
......@@ -98,7 +90,12 @@ ColorSchemeWallpaper::FillStyle ColorSchemeWallpaper::style() const
QPointF ColorSchemeWallpaper::anchor() const
{
return _anchor;
}
}
qreal ColorSchemeWallpaper::opacity() const
{
return _opacity;
}
QRectF ColorSchemeWallpaper::ScaledRect(const QSize viewportSize, const QSize pictureSize, const QRect rect)
{
......
......@@ -43,13 +43,13 @@ public:
typedef QExplicitlySharedDataPointer<ColorSchemeWallpaper> Ptr;
explicit ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor);
explicit ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity);
~ColorSchemeWallpaper();
void load();
/** Returns true if wallpaper available and drawn */
bool draw(QPainter &painter, const QRect rect, qreal opacity = 1.0);
bool draw(QPainter &painter, const QRect rect, qreal bgColorOpacity, const QColor &backgroundColor);
bool isNull() const;
......@@ -59,6 +59,8 @@ public:
QPointF anchor() const;
qreal opacity() const;
private:
Q_GADGET
Q_DISABLE_COPY(ColorSchemeWallpaper)
......@@ -67,6 +69,7 @@ private:
std::unique_ptr<QPixmap> _picture;
FillStyle _style;
QPointF _anchor;
qreal _opacity;
QRectF ScaledRect(const QSize viewportSize, const QSize pictureSize, const QRect rect);
Qt::AspectRatioMode RatioMode();
......
......@@ -444,7 +444,8 @@ void TerminalPainter::drawBackground(QPainter &painter, const QRect &rect, const
{
const auto display = qobject_cast<TerminalDisplay *>(sender());
if (useOpacitySetting && !display->wallpaper()->isNull() && display->wallpaper()->draw(painter, rect, display->terminalColor()->opacity())) {
if (useOpacitySetting && !display->wallpaper()->isNull()
&& display->wallpaper()->draw(painter, rect, display->terminalColor()->opacity(), backgroundColor)) {
} else if (qAlpha(display->terminalColor()->blendColor()) < 0xff && useOpacitySetting) {
#if defined(Q_OS_MACOS)
// TODO: On MacOS, using CompositionMode doesn't work. Altering the
......
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