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

Added settings

parent 7ecaf93b
......@@ -13,6 +13,7 @@
// Qt
#include <QPainter>
#include <QMetaEnum>
// KDE
#include <KConfig>
......@@ -466,7 +467,7 @@ void ColorScheme::read(const KConfig &config)
_blur = configGroup.readEntry("Blur", false);
setWallpaper(
configGroup.readEntry("Wallpaper", QString()),
static_cast<ColorSchemeWallpaper::FillStyle>(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<int>(_wallpaper->style()));
configGroup.writeEntry("FillStyle",
QMetaEnum::fromType<ColorSchemeWallpaper::FillStyle>()
.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<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);
}
ColorSchemeWallpaper::Ptr ColorScheme::wallpaper() const
{
return _wallpaper;
}
}
\ No newline at end of file
......@@ -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;
......
......@@ -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<const ColorScheme> &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<ColorScheme> &colors)
......
......@@ -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();
......
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>364</width>
<height>376</height>
<height>460</height>
</rect>
</property>
<layout class="QVBoxLayout">
......@@ -123,6 +123,120 @@ 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="wallpaperScalingLabel">
<property name="text">
<string>Wallpaper scaling:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="wallpaperScalingType">
<item>
<property name="text">
<string>Tile</string>
</property>
</item>
<item>
<property name="text">
<string>Stretch</string>
</property>
</item>
<item>
<property name="text">
<string>Crop</string>
</property>
</item>
<item>
<property name="text">
<string>Adapt</string>
</property>
</item>
<item>
<property name="text">
<string>NoScaling</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="wallpaperHorizontalAnchorLabel">
<property name="text">
<string>Horizontal Anchor:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="wallpaperHorizontalAnchorSlider">
<property name="maximum">
<number>2</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="wallpaperHorizontalAnchorPosition">
<property name="text">
<string>Left</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="wallpaperVerticalAnchorLabel">
<property name="text">
<string>Vertical Anchor:</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="wallpaperVerticalAnchorSlider">
<property name="maximum">
<number>2</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>1</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="wallpaperVerticalAnchorPosition">
<property name="text">
<string>Top</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer>
<property name="orientation">
......
......@@ -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<double>(scaledSize.width());
double scaleY = pictureSize.height() / static_cast<double>(scaledSize.height());
......
......@@ -37,8 +37,9 @@ public:
Stretch,
Crop,
Adapt,
NoResize
NoScaling
};
Q_ENUM(FillStyle)
typedef QExplicitlySharedDataPointer<ColorSchemeWallpaper> Ptr;
......@@ -59,6 +60,7 @@ public:
QPointF anchor() const;
private:
Q_GADGET
Q_DISABLE_COPY(ColorSchemeWallpaper)
QString _path;
......
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