Commit 2e1e8266 authored by Aurélien Gâteau's avatar Aurélien Gâteau
Browse files

Simplify: let the use choose the background color darkness only

not selecting the whole color will make it easier to generate valid
foreground colors in some cases.
parent 2b0b0764
......@@ -68,6 +68,7 @@ ConfigDialog::ConfigDialog(QWidget* parent)
widget = setupPage(d->mGeneralConfigPage);
pageItem = addPage(widget, i18n("General"));
pageItem->setIcon(KIcon("gwenview"));
connect(d->mGeneralConfigPage.kcfg_ViewBackgroundValue, SIGNAL(valueChanged(int)), SLOT(updateViewBackgroundFrame()));
// Image View
widget = setupPage(d->mImageViewConfigPage);
......@@ -95,6 +96,8 @@ ConfigDialog::ConfigDialog(QWidget* parent)
pageItem = addPage(widget, i18n("Advanced"));
pageItem->setIcon(KIcon("preferences-other"));
d->mAdvancedConfigPage.cacheHelpLabel->setFont(KGlobalSettings::smallestReadableFont());
updateViewBackgroundFrame();
}
......@@ -103,4 +106,19 @@ ConfigDialog::~ConfigDialog() {
}
void ConfigDialog::updateViewBackgroundFrame() {
QColor color = QColor::fromHsv(0, 0, d->mGeneralConfigPage.kcfg_ViewBackgroundValue->value());
QString css =
QString(
"background-color: %1;"
"border-radius: 5px;"
"border: 1px solid %1;")
.arg(color.name());
// When using Oxygen, setting the background color via palette causes the
// pixels outside the frame to be painted with the new background color as
// well. Using CSS works more like expected.
d->mGeneralConfigPage.backgroundValueFrame->setStyleSheet(css);
}
} // namespace
......@@ -33,10 +33,14 @@ namespace Gwenview {
struct ConfigDialogPrivate;
class ConfigDialog : public KConfigDialog {
Q_OBJECT
public:
ConfigDialog(QWidget* parent);
~ConfigDialog();
private Q_SLOTS:
void updateViewBackgroundFrame();
private:
ConfigDialogPrivate* const d;
};
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>378</width>
<width>470</width>
<height>338</height>
</rect>
</property>
......@@ -16,17 +16,48 @@
<property name="text">
<string>Background color:</string>
</property>
<property name="buddy">
<cstring>kcfg_ViewBackgroundColor</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout">
<item>
<widget class="KColorButton" name="kcfg_ViewBackgroundColor">
<property name="text">
<string/>
<widget class="QSlider" name="kcfg_ViewBackgroundValue">
<property name="minimumSize">
<size>
<width>256</width>
<height>0</height>
</size>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="backgroundValueFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
</widget>
</item>
......@@ -77,13 +108,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
<header>kcolorbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
......@@ -1409,8 +1409,9 @@ void MainWindow::loadConfig() {
d->mThumbnailViewPanel->loadConfig();
// Colors
QColor bgColor = GwenviewConfig::viewBackgroundColor();
QColor fgColor = bgColor.value() > 128 ? Qt::black : Qt::white;
int value = GwenviewConfig::viewBackgroundValue();
QColor bgColor = QColor::fromHsv(0, 0, value);
QColor fgColor = value > 128 ? Qt::black : Qt::white;
QPalette pal = palette();
pal.setColor(QPalette::Base, bgColor);
......
......@@ -114,8 +114,9 @@ struct ThumbnailPagePrivate : public Ui_ThumbnailPage {
mThumbnailView->setItemDelegate(delegate);
// Colors
QColor bgColor = GwenviewConfig::viewBackgroundColor();
QColor fgColor = bgColor.value() > 128 ? Qt::black : Qt::white;
int value = GwenviewConfig::viewBackgroundValue();
QColor bgColor = QColor::fromHsv(0, 0, value);
QColor fgColor = value > 128 ? Qt::black : Qt::white;
QPalette pal = mThumbnailView->palette();
pal.setColor(QPalette::Base, bgColor);
......
......@@ -16,8 +16,8 @@
</group>
<group name="General">
<entry name="ViewBackgroundColor" type="Color">
<default>#666666</default>
<entry name="ViewBackgroundValue" type="Int">
<default>100</default>
</entry>
<entry name="HistoryEnabled" type="Bool">
......
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