Commit 2a360ba3 authored by Liu Bodong's avatar Liu Bodong 😘 Committed by Tomaz Canabrava
Browse files

Feature: Allow wallpaper flip(both horizontal and vertical)

parent 5547abc7
......@@ -188,7 +188,7 @@ ColorScheme::ColorScheme()
, _colorRandomization(false)
, _wallpaper(nullptr)
{
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5, 0.5), 1.0);
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5, 0.5), 1.0, false, false);
}
ColorScheme::ColorScheme(const ColorScheme &other)
......@@ -469,7 +469,9 @@ void ColorScheme::read(const KConfig &config)
setWallpaper(configGroup.readEntry("Wallpaper", QString()),
configGroup.readEntry("FillStyle", QString::fromLatin1("Tile")),
configGroup.readEntry("Anchor", QPointF(0.5, 0.5)),
configGroup.readEntry("WallpaperOpacity", 1.0));
configGroup.readEntry("WallpaperOpacity", 1.0),
configGroup.readEntry("wallpaperFlipHorizontal", false),
configGroup.readEntry("wallpaperFlipVertical", false));
_colorRandomization = configGroup.readEntry(EnableColorRandomizationKey, false);
for (int i = 0; i < TABLE_COLORS; i++) {
......@@ -531,6 +533,8 @@ void ColorScheme::write(KConfig &config) const
configGroup.writeEntry("Blur", _blur);
configGroup.writeEntry("Wallpaper", _wallpaper->path());
configGroup.writeEntry("FillStyle", QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>().valueToKey(_wallpaper->style()));
configGroup.writeEntry("wallpaperFlipHorizontal", _wallpaper->flipHorizontal());
configGroup.writeEntry("wallpaperFlipVertical", _wallpaper->flipVertical());
configGroup.writeEntry("Anchor", _wallpaper->anchor());
configGroup.writeEntry("WallpaperOpacity", _wallpaper->opacity());
configGroup.writeEntry(EnableColorRandomizationKey, _colorRandomization);
......@@ -580,19 +584,29 @@ 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, const qreal &opacity)
void ColorScheme::setWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
{
_wallpaper = new ColorSchemeWallpaper(path, style, anchor, opacity);
_wallpaper = new ColorSchemeWallpaper(path, style, anchor, opacity, flipHorizontal, flipVertical);
}
void ColorScheme::setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity)
void ColorScheme::setWallpaper(const QString &path,
const QString &style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
{
ColorSchemeWallpaper::FillStyle fstyle;
fstyle = static_cast<ColorSchemeWallpaper::FillStyle>(std::max( // keyToValue returns -1 if key was not found, but we should default to 0
QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>().keyToValue(style.toStdString().c_str()),
0));
setWallpaper(path, fstyle, anchor, opacity);
setWallpaper(path, fstyle, anchor, opacity, flipHorizontal, flipVertical);
}
ColorSchemeWallpaper::Ptr ColorScheme::wallpaper() const
......
......@@ -133,8 +133,14 @@ public:
*/
bool blur() const;
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);
void setWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical);
void
setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity, const bool &flipHorizontal, const bool &flipVertical);
ColorSchemeWallpaper::Ptr wallpaper() const;
......
......@@ -99,6 +99,9 @@ ColorSchemeEditor::ColorSchemeEditor(QWidget *parent)
connect(_ui->wallpaperHorizontalAnchorSlider, &QSlider::valueChanged, this, &Konsole::ColorSchemeEditor::horizontalAnchorChanged);
connect(_ui->wallpaperVerticalAnchorSlider, &QSlider::valueChanged, this, &Konsole::ColorSchemeEditor::verticalAnchorChanged);
connect(_ui->wallpaperFlipHorizontalCheckBox, &QCheckBox::toggled, this, &Konsole::ColorSchemeEditor::wallpaperFlipHorizontalChanged);
connect(_ui->wallpaperFlipVerticalCheckBox, &QCheckBox::toggled, this, &Konsole::ColorSchemeEditor::wallpaperFlipVerticalChanged);
// color table
_ui->colorTable->setColumnCount(4);
_ui->colorTable->setRowCount(COLOR_TABLE_ROW_LENGTH);
......@@ -196,19 +199,34 @@ void ColorSchemeEditor::setWallpaperOpacity(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);
_colors->setWallpaper(_colors->wallpaper()->path(),
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
opacity,
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
}
void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
{
if (path.isEmpty()) {
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
_colors->setWallpaper(path,
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
enableWallpaperSettings(false);
} else {
QFileInfo i(path);
if (i.exists() && i.isFile() && i.isReadable()) {
_colors->setWallpaper(path, _colors->wallpaper()->style(), _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
_colors->setWallpaper(path,
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
enableWallpaperSettings(true);
}
}
......@@ -217,13 +235,43 @@ void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
void ColorSchemeEditor::scalingTypeChanged(int styleIndex)
{
const char *style = QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>().valueToKey(styleIndex);
_colors->setWallpaper(_colors->wallpaper()->path(), QString::fromLatin1(style), _colors->wallpaper()->anchor(), _colors->wallpaper()->opacity());
_colors->setWallpaper(_colors->wallpaper()->path(),
QString::fromLatin1(style),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
}
void ColorSchemeEditor::wallpaperFlipHorizontalChanged(bool horizontal)
{
_colors->setWallpaper(_colors->wallpaper()->path(),
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
horizontal,
_colors->wallpaper()->flipVertical());
}
void ColorSchemeEditor::wallpaperFlipVerticalChanged(bool vertical)
{
_colors->setWallpaper(_colors->wallpaper()->path(),
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
vertical);
}
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->wallpaper()->opacity());
_colors->setWallpaper(_colors->wallpaper()->path(),
_colors->wallpaper()->style(),
QPointF(pos / 2.0, anch.y()),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
switch (pos) {
case 2:
_ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Right"));
......@@ -241,7 +289,12 @@ 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->wallpaper()->opacity());
_colors->setWallpaper(_colors->wallpaper()->path(),
_colors->wallpaper()->style(),
QPointF(anch.x(), pos / 2.0),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
switch (pos) {
case 2:
_ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Bottom"));
......@@ -323,6 +376,8 @@ void ColorSchemeEditor::setup(const std::shared_ptr<const ColorScheme> &scheme,
int ay = qRound(scheme->wallpaper()->anchor().y() * 2.0);
_ui->wallpaperPath->setText(scheme->wallpaper()->path());
_ui->wallpaperScalingType->setCurrentIndex(scheme->wallpaper()->style());
_ui->wallpaperFlipHorizontalCheckBox->setChecked(scheme->wallpaper()->flipHorizontal());
_ui->wallpaperFlipVerticalCheckBox->setChecked(scheme->wallpaper()->flipVertical());
_ui->wallpaperHorizontalAnchorSlider->setValue(ax);
_ui->wallpaperVerticalAnchorSlider->setValue(ay);
enableWallpaperSettings(!scheme->wallpaper()->isNull());
......@@ -382,4 +437,6 @@ void ColorSchemeEditor::enableWallpaperSettings(bool enable)
_ui->wallpaperVerticalAnchorSlider->setEnabled(enable);
_ui->wallpaperTransparencySlider->setEnabled(enable);
_ui->wallpaperScalingType->setEnabled(enable);
_ui->wallpaperFlipHorizontalCheckBox->setEnabled(enable);
_ui->wallpaperFlipVerticalCheckBox->setEnabled(enable);
}
......@@ -71,6 +71,8 @@ private Q_SLOTS:
void setWallpaperOpacity(int percent);
void wallpaperPathChanged(const QString &path);
void scalingTypeChanged(int styleIndex);
void wallpaperFlipHorizontalChanged(bool horizontal);
void wallpaperFlipVerticalChanged(bool vertical);
void horizontalAnchorChanged(int pos);
void verticalAnchorChanged(int pos);
void selectWallpaper();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>364</width>
<height>460</height>
<height>474</height>
</rect>
</property>
<layout class="QVBoxLayout">
......@@ -197,6 +197,31 @@ 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="wallpaperFlipLabel">
<property name="text">
<string>Wallpaper flip:</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wallpaperFlipHorizontalCheckBox">
<property name="text">
<string>Horizontal</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wallpaperFlipVerticalCheckBox">
<property name="text">
<string>Vertical</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
......
......@@ -17,12 +17,19 @@
using namespace Konsole;
ColorSchemeWallpaper::ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity)
ColorSchemeWallpaper::ColorSchemeWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
: _path(path)
, _picture(nullptr)
, _style(style)
, _anchor(anchor)
, _opacity(opacity)
, _flipHorizontal(flipHorizontal)
, _flipVertical(flipVertical)
{
float x = _anchor.x(), y = _anchor.y();
......@@ -44,7 +51,9 @@ void ColorSchemeWallpaper::load()
}
if (_picture->isNull()) {
_picture->load(_path);
QImage image(_path);
QImage transformed = image.mirrored(flipHorizontal(), flipVertical());
_picture->convertFromImage(transformed);
}
}
......@@ -87,6 +96,16 @@ ColorSchemeWallpaper::FillStyle ColorSchemeWallpaper::style() const
return _style;
}
bool ColorSchemeWallpaper::flipHorizontal() const
{
return _flipHorizontal;
}
bool ColorSchemeWallpaper::flipVertical() const
{
return _flipVertical;
}
QPointF ColorSchemeWallpaper::anchor() const
{
return _anchor;
......
......@@ -42,7 +42,12 @@ public:
typedef QExplicitlySharedDataPointer<ColorSchemeWallpaper> Ptr;
explicit ColorSchemeWallpaper(const QString &path, const ColorSchemeWallpaper::FillStyle style, const QPointF &anchor, const qreal &opacity);
explicit ColorSchemeWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical);
~ColorSchemeWallpaper();
void load();
......@@ -60,6 +65,10 @@ public:
qreal opacity() const;
bool flipHorizontal() const;
bool flipVertical() const;
private:
Q_GADGET
Q_DISABLE_COPY(ColorSchemeWallpaper)
......@@ -69,6 +78,8 @@ private:
FillStyle _style;
QPointF _anchor;
qreal _opacity;
bool _flipHorizontal;
bool _flipVertical;
QRectF ScaledRect(const QSize viewportSize, const QSize pictureSize, const QRect rect);
Qt::AspectRatioMode RatioMode();
......
Supports Markdown
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