diff --git a/src/colorscheme/ColorScheme.cpp b/src/colorscheme/ColorScheme.cpp index 85ab6182..32517d99 100644 --- a/src/colorscheme/ColorScheme.cpp +++ b/src/colorscheme/ColorScheme.cpp @@ -13,6 +13,7 @@ // Qt #include +#include // KDE #include @@ -466,7 +467,7 @@ void ColorScheme::read(const KConfig &config) _blur = configGroup.readEntry("Blur", false); setWallpaper( configGroup.readEntry("Wallpaper", QString()), - static_cast(configGroup.readEntry("FillStyle", 0)), + configGroup.readEntry("FillStyle", QString::fromLatin1("Tile")), configGroup.readEntry("Anchor", QPointF(0.5f, 0.5f))); _colorRandomization = configGroup.readEntry(EnableColorRandomizationKey, false); @@ -528,7 +529,9 @@ void ColorScheme::write(KConfig &config) const configGroup.writeEntry("Opacity", _opacity); configGroup.writeEntry("Blur", _blur); configGroup.writeEntry("Wallpaper", _wallpaper->path()); - configGroup.writeEntry("FillStyle", static_cast(_wallpaper->style())); + configGroup.writeEntry("FillStyle", + QMetaEnum::fromType() + .valueToKey(_wallpaper->style())); configGroup.writeEntry("Anchor", _wallpaper->anchor()); configGroup.writeEntry(EnableColorRandomizationKey, _colorRandomization); @@ -582,7 +585,19 @@ void ColorScheme::setWallpaper(const QString &path, const ColorSchemeWallpaper:: _wallpaper = new ColorSchemeWallpaper(path, style, anchor); } +void ColorScheme::setWallpaper(const QString &path, const QString style, const QPointF &anchor) +{ + ColorSchemeWallpaper::FillStyle fstyle; + fstyle = static_cast + (std::max( //keyToValue returns -1 if key was not found, but we should default to 0 + QMetaEnum::fromType() + .keyToValue(style.toStdString().c_str()) + , 0)); + + setWallpaper(path, fstyle, anchor); +} + ColorSchemeWallpaper::Ptr ColorScheme::wallpaper() const { return _wallpaper; -} +} \ No newline at end of file diff --git a/src/colorscheme/ColorScheme.h b/src/colorscheme/ColorScheme.h index 37a57842..0538eba6 100644 --- a/src/colorscheme/ColorScheme.h +++ b/src/colorscheme/ColorScheme.h @@ -134,6 +134,7 @@ 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); ColorSchemeWallpaper::Ptr wallpaper() const; diff --git a/src/colorscheme/ColorSchemeEditor.cpp b/src/colorscheme/ColorSchemeEditor.cpp index dac27a28..d11d5e5e 100644 --- a/src/colorscheme/ColorSchemeEditor.cpp +++ b/src/colorscheme/ColorSchemeEditor.cpp @@ -92,6 +92,10 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget *parent) connect(_ui->wallpaperSelectButton, &QToolButton::clicked, this, &Konsole::ColorSchemeEditor::selectWallpaper); connect(_ui->wallpaperPath, &QLineEdit::textChanged, this, &Konsole::ColorSchemeEditor::wallpaperPathChanged); + connect(_ui->wallpaperScalingType, &QComboBox::currentTextChanged, this, &Konsole::ColorSchemeEditor::scalingTypeChanged); + connect(_ui->wallpaperHorizontalAnchorSlider, &QSlider::valueChanged, this, &Konsole::ColorSchemeEditor::horizontalAnchorChanged); + connect(_ui->wallpaperVerticalAnchorSlider, &QSlider::valueChanged, this, &Konsole::ColorSchemeEditor::verticalAnchorChanged); + // color table _ui->colorTable->setColumnCount(4); _ui->colorTable->setRowCount(COLOR_TABLE_ROW_LENGTH); @@ -197,6 +201,47 @@ void ColorSchemeEditor::wallpaperPathChanged(const QString &path) } } +void ColorSchemeEditor::scalingTypeChanged(QString style) +{ + _colors->setWallpaper(_colors->wallpaper()->path(), style, _colors->wallpaper()->anchor()); +} + +void ColorSchemeEditor::horizontalAnchorChanged(int pos) +{ + QPointF anch = _colors->wallpaper()->anchor(); + _colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(pos / 2.0, anch.y())); + switch (pos) { + case 2: + _ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Right")); + break; + case 1: + _ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Center")); + break; + case 0: + default: + _ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Left")); + break; + } +} + +void ColorSchemeEditor::verticalAnchorChanged(int pos) +{ + QPointF anch = _colors->wallpaper()->anchor(); + _colors->setWallpaper(_colors->wallpaper()->path(), _colors->wallpaper()->style(), QPointF(anch.x(), pos / 2.0)); + switch (pos) { + case 2: + _ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Bottom")); + break; + case 1: + _ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Middle")); + break; + case 0: + default: + _ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Top")); + break; + } +} + void ColorSchemeEditor::setDescription(const QString &description) { if (_colors != nullptr) { @@ -257,7 +302,12 @@ void ColorSchemeEditor::setup(const std::shared_ptr &scheme, _ui->randomizedBackgroundCheck->setChecked(scheme->isColorRandomizationEnabled()); // wallpaper stuff + int ax = qRound(scheme->wallpaper()->anchor().x() * 2.0); + int ay = qRound(scheme->wallpaper()->anchor().y() * 2.0); _ui->wallpaperPath->setText(scheme->wallpaper()->path()); + _ui->wallpaperScalingType->setCurrentIndex(scheme->wallpaper()->style()); + _ui->wallpaperHorizontalAnchorSlider->setValue(ax); + _ui->wallpaperVerticalAnchorSlider->setValue(ay); } void ColorSchemeEditor::setupColorTable(const std::shared_ptr &colors) diff --git a/src/colorscheme/ColorSchemeEditor.h b/src/colorscheme/ColorSchemeEditor.h index 77504e80..fbb50e9c 100644 --- a/src/colorscheme/ColorSchemeEditor.h +++ b/src/colorscheme/ColorSchemeEditor.h @@ -69,6 +69,9 @@ private Q_SLOTS: void setRandomizedBackgroundColor(bool randomized); void editColorItem(QTableWidgetItem *item); void wallpaperPathChanged(const QString &path); + void scalingTypeChanged(QString style); + void horizontalAnchorChanged(int pos); + void verticalAnchorChanged(int pos); void selectWallpaper(); /** Triggered by apply/ok buttons */ void saveColorScheme(); diff --git a/src/colorscheme/ColorSchemeEditor.ui b/src/colorscheme/ColorSchemeEditor.ui index 6ed5e556..df2f2788 100644 --- a/src/colorscheme/ColorSchemeEditor.ui +++ b/src/colorscheme/ColorSchemeEditor.ui @@ -7,7 +7,7 @@ 0 0 364 - 376 + 460 @@ -123,6 +123,120 @@ To see any effect, set colors with saturation value greater than 0. + + + + + + Wallpaper scaling: + + + + + + + + Tile + + + + + Stretch + + + + + Crop + + + + + Adapt + + + + + NoScaling + + + + + + + + + + + + Horizontal Anchor: + + + + + + + 2 + + + 1 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 1 + + + + + + + Left + + + + + + + + + + + Vertical Anchor: + + + + + + + 2 + + + 1 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 1 + + + + + + + Top + + + + + diff --git a/src/colorscheme/ColorSchemeWallpaper.cpp b/src/colorscheme/ColorSchemeWallpaper.cpp index da9ebf63..7bd5db71 100644 --- a/src/colorscheme/ColorSchemeWallpaper.cpp +++ b/src/colorscheme/ColorSchemeWallpaper.cpp @@ -103,7 +103,7 @@ QPointF ColorSchemeWallpaper::anchor() const QRectF ColorSchemeWallpaper::ScaledRect(const QSize viewportSize, const QSize pictureSize, const QRect rect) { QRectF scaledRect = QRectF(); - QSize scaledSize = _style == NoResize ? pictureSize : pictureSize.scaled(viewportSize, RatioMode()); + QSize scaledSize = _style == NoScaling ? pictureSize : pictureSize.scaled(viewportSize, RatioMode()); double scaleX = pictureSize.width() / static_cast(scaledSize.width()); double scaleY = pictureSize.height() / static_cast(scaledSize.height()); diff --git a/src/colorscheme/ColorSchemeWallpaper.h b/src/colorscheme/ColorSchemeWallpaper.h index 770bd2bb..0564c01a 100644 --- a/src/colorscheme/ColorSchemeWallpaper.h +++ b/src/colorscheme/ColorSchemeWallpaper.h @@ -37,8 +37,9 @@ public: Stretch, Crop, Adapt, - NoResize + NoScaling }; + Q_ENUM(FillStyle) typedef QExplicitlySharedDataPointer Ptr; @@ -59,6 +60,7 @@ public: QPointF anchor() const; private: + Q_GADGET Q_DISABLE_COPY(ColorSchemeWallpaper) QString _path;