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

1. Use enum instead of bool to control flip direction

2. In ColorSchemeEditor, Use combobox instead of checkbox to hold wallpaper flip type change.
parent 7bbfe661
Pipeline #229032 passed with stage
in 3 minutes and 21 seconds
......@@ -188,7 +188,7 @@ ColorScheme::ColorScheme()
, _colorRandomization(false)
, _wallpaper(nullptr)
{
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5, 0.5), 1.0, false, false);
setWallpaper(QString(), ColorSchemeWallpaper::Tile, QPointF(0.5, 0.5), 1.0, ColorSchemeWallpaper::NoFlip);
}
ColorScheme::ColorScheme(const ColorScheme &other)
......@@ -470,8 +470,7 @@ void ColorScheme::read(const KConfig &config)
configGroup.readEntry("FillStyle", QString::fromLatin1("Tile")),
configGroup.readEntry("Anchor", QPointF(0.5, 0.5)),
configGroup.readEntry("WallpaperOpacity", 1.0),
configGroup.readEntry("WallpaperFlipHorizontal", false),
configGroup.readEntry("WallpaperFlipVertical", false));
configGroup.readEntry("WallpaperFlipType", QString::fromLatin1("NoFlip")));
_colorRandomization = configGroup.readEntry(EnableColorRandomizationKey, false);
for (int i = 0; i < TABLE_COLORS; i++) {
......@@ -533,8 +532,7 @@ 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("WallpaperFlipType", QMetaEnum::fromType<ColorSchemeWallpaper::FlipType>().valueToKey(_wallpaper->flipType()));
configGroup.writeEntry("Anchor", _wallpaper->anchor());
configGroup.writeEntry("WallpaperOpacity", _wallpaper->opacity());
configGroup.writeEntry(EnableColorRandomizationKey, _colorRandomization);
......@@ -588,25 +586,24 @@ void ColorScheme::setWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
const ColorSchemeWallpaper::FlipType flipType)
{
_wallpaper = new ColorSchemeWallpaper(path, style, anchor, opacity, flipHorizontal, flipVertical);
_wallpaper = new ColorSchemeWallpaper(path, style, anchor, opacity, flipType);
}
void ColorScheme::setWallpaper(const QString &path,
const QString &style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
void ColorScheme::setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity, const QString &flipType)
{
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, flipHorizontal, flipVertical);
ColorSchemeWallpaper::FlipType ftype;
ftype = static_cast<ColorSchemeWallpaper::FlipType>(std::max( // keyToValue returns -1 if key was not found, but we should default to 0
QMetaEnum::fromType<ColorSchemeWallpaper::FlipType>().keyToValue(flipType.toStdString().c_str()),
0));
setWallpaper(path, fstyle, anchor, opacity, ftype);
}
ColorSchemeWallpaper::Ptr ColorScheme::wallpaper() const
......
......@@ -137,10 +137,9 @@ public:
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);
const ColorSchemeWallpaper::FlipType flipType);
void setWallpaper(const QString &path, const QString &style, const QPointF &anchor, const qreal &opacity, const QString &flipType);
ColorSchemeWallpaper::Ptr wallpaper() const;
......
......@@ -99,8 +99,7 @@ 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);
connect(_ui->wallpaperFlipType, (void(QComboBox::*)(int)) & QComboBox::currentIndexChanged, this, &Konsole::ColorSchemeEditor::flipTypeChanged);
// color table
_ui->colorTable->setColumnCount(4);
......@@ -203,8 +202,7 @@ void ColorSchemeEditor::setWallpaperOpacity(int percent)
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
opacity,
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
_colors->wallpaper()->flipType());
}
void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
......@@ -214,8 +212,7 @@ void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
_colors->wallpaper()->flipType());
enableWallpaperSettings(false);
} else {
QFileInfo i(path);
......@@ -225,8 +222,7 @@ void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
_colors->wallpaper()->style(),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
_colors->wallpaper()->flipType());
enableWallpaperSettings(true);
}
}
......@@ -234,33 +230,24 @@ void ColorSchemeEditor::wallpaperPathChanged(const QString &path)
void ColorSchemeEditor::scalingTypeChanged(int styleIndex)
{
const char *flipType = QMetaEnum::fromType<ColorSchemeWallpaper::FlipType>().valueToKey(_colors->wallpaper()->flipType());
const char *style = QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>().valueToKey(styleIndex);
_colors->setWallpaper(_colors->wallpaper()->path(),
QString::fromLatin1(style),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
QString::fromLatin1(flipType));
}
void ColorSchemeEditor::wallpaperFlipHorizontalChanged(bool horizontal)
void ColorSchemeEditor::flipTypeChanged(int flipTypeIndex)
{
const char *fillStyle = QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>().valueToKey(_colors->wallpaper()->style());
const char *flipType = QMetaEnum::fromType<ColorSchemeWallpaper::FlipType>().valueToKey(flipTypeIndex);
_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(),
QString::fromLatin1(fillStyle),
_colors->wallpaper()->anchor(),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
vertical);
QString::fromLatin1(flipType));
}
void ColorSchemeEditor::horizontalAnchorChanged(int pos)
......@@ -270,8 +257,7 @@ void ColorSchemeEditor::horizontalAnchorChanged(int pos)
_colors->wallpaper()->style(),
QPointF(pos / 2.0, anch.y()),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
_colors->wallpaper()->flipType());
switch (pos) {
case 2:
_ui->wallpaperHorizontalAnchorPosition->setText(QString::fromLatin1("Right"));
......@@ -293,8 +279,7 @@ void ColorSchemeEditor::verticalAnchorChanged(int pos)
_colors->wallpaper()->style(),
QPointF(anch.x(), pos / 2.0),
_colors->wallpaper()->opacity(),
_colors->wallpaper()->flipHorizontal(),
_colors->wallpaper()->flipVertical());
_colors->wallpaper()->flipType());
switch (pos) {
case 2:
_ui->wallpaperVerticalAnchorPosition->setText(QString::fromLatin1("Bottom"));
......@@ -376,8 +361,7 @@ 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->wallpaperFlipType->setCurrentIndex(scheme->wallpaper()->flipType());
_ui->wallpaperHorizontalAnchorSlider->setValue(ax);
_ui->wallpaperVerticalAnchorSlider->setValue(ay);
enableWallpaperSettings(!scheme->wallpaper()->isNull());
......@@ -437,6 +421,5 @@ 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);
_ui->wallpaperFlipType->setEnabled(enable);
}
......@@ -71,8 +71,7 @@ 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 flipTypeChanged(int flipTypeIndex);
void horizontalAnchorChanged(int pos);
void verticalAnchorChanged(int pos);
void selectWallpaper();
......
......@@ -207,17 +207,27 @@ To see any effect, set colors with saturation value greater than 0.</string>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wallpaperFlipHorizontalCheckBox">
<widget class="QComboBox" name="wallpaperFlipType">
<item>
<property name="text">
<string>Horizontal</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="wallpaperFlipVerticalCheckBox">
<string>NoFlip</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical</string>
</property>
<string>Horizontal</string>
</property>
</item>
<item>
<property name="text">
<string>Vertical</string>
</property>
</item>
<item>
<property name="text">
<string>Both</string>
</property>
</item>
</widget>
</item>
</layout>
......
......@@ -21,15 +21,13 @@ ColorSchemeWallpaper::ColorSchemeWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical)
const ColorSchemeWallpaper::FlipType flipType)
: _path(path)
, _picture(nullptr)
, _style(style)
, _anchor(anchor)
, _opacity(opacity)
, _flipHorizontal(flipHorizontal)
, _flipVertical(flipVertical)
, _flipType(flipType)
{
float x = _anchor.x(), y = _anchor.y();
......@@ -51,8 +49,8 @@ void ColorSchemeWallpaper::load()
}
if (_picture->isNull()) {
QImage image(_path);
QImage transformed = image.mirrored(flipHorizontal(), flipVertical());
const QImage image(_path);
const QImage transformed = FlipImage(image, _flipType);
_picture->convertFromImage(transformed);
}
}
......@@ -96,14 +94,9 @@ ColorSchemeWallpaper::FillStyle ColorSchemeWallpaper::style() const
return _style;
}
bool ColorSchemeWallpaper::flipHorizontal() const
ColorSchemeWallpaper::FlipType ColorSchemeWallpaper::flipType() const
{
return _flipHorizontal;
}
bool ColorSchemeWallpaper::flipVertical() const
{
return _flipVertical;
return _flipType;
}
QPointF ColorSchemeWallpaper::anchor() const
......@@ -149,3 +142,17 @@ Qt::AspectRatioMode ColorSchemeWallpaper::RatioMode()
return Qt::IgnoreAspectRatio;
}
}
QImage ColorSchemeWallpaper::FlipImage(const QImage image, const ColorSchemeWallpaper::FlipType flipType)
{
switch (flipType) {
case Horizontal:
return image.mirrored(true, false);
case Vertical:
return image.mirrored(false, true);
case Both:
return image.mirrored(true, true);
default:
return image;
}
}
......@@ -40,14 +40,21 @@ public:
};
Q_ENUM(FillStyle)
enum FlipType {
NoFlip = 0,
Horizontal,
Vertical,
Both,
};
Q_ENUM(FlipType)
typedef QExplicitlySharedDataPointer<ColorSchemeWallpaper> Ptr;
explicit ColorSchemeWallpaper(const QString &path,
const ColorSchemeWallpaper::FillStyle style,
const QPointF &anchor,
const qreal &opacity,
const bool &flipHorizontal,
const bool &flipVertical);
const ColorSchemeWallpaper::FlipType flipType);
~ColorSchemeWallpaper();
void load();
......@@ -65,9 +72,7 @@ public:
qreal opacity() const;
bool flipHorizontal() const;
bool flipVertical() const;
FlipType flipType() const;
private:
Q_GADGET
......@@ -78,11 +83,11 @@ private:
FillStyle _style;
QPointF _anchor;
qreal _opacity;
bool _flipHorizontal;
bool _flipVertical;
FlipType _flipType;
QRectF ScaledRect(const QSize viewportSize, const QSize pictureSize, const QRect rect);
Qt::AspectRatioMode RatioMode();
QImage FlipImage(const QImage image, const ColorSchemeWallpaper::FlipType flipType);
};
}
......
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