From 6b5a7c9a1a00dec994cfb03b0abf369539168758 Mon Sep 17 00:00:00 2001 From: Nathaniel Graham Date: Sat, 30 Sep 2017 19:37:24 -0600 Subject: [PATCH] Custom background color Summary: BUG: 182994 Adds an option to the config dialog that enables background color (the color around the displayed page) to be changed (while by default preserving the Qt toolkit selection as not to affect existing users). Reasons for this change: Accessibility, eye strain, aesthetic reasons, color displayed on monitor can affect power consumption (how: depends on display technology). Many people want this change occording to Bugzilla and other sources. Maintenance: Nearly no additional maintenance: This is no new subsystem but a trivial feature with no complex code dependencies, and we are already showing a colour selection dialog and setting colours in other places in Okular. {F4257766} Other less important information: https://git.reviewboard.kde.org/r/130219/ https://mail.kde.org/pipermail/okular-devel/2017-September/025520.html Test Plan: Tested everything, it all works: Toggled the custom background color, changed custom background color, removed okular settings file (with: "rm ~/.config/okular*") to verify it uses the usual qt theme colour by default (where the settings file remembered the custom color). Reviewers: #okular, aacid, elvisangelaccio, rkflx, ngraham Reviewed By: ngraham Subscribers: aacid, ltoscano, ngraham Tags: #okular Differential Revision: https://phabricator.kde.org/D8051 --- CMakeLists.txt | 4 +-- conf/dlggeneral.cpp | 7 +++++ conf/dlggeneral.h | 3 +++ conf/dlggeneralbase.ui | 61 ++++++++++++++++++++++++++++++++++++++++-- conf/okular.kcfg | 5 ++++ ui/pageview.cpp | 7 ++++- 6 files changed, 82 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c5b7ac01..5b749127c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ ki18n_wrap_ui(okularcore_SRCS core/chooseenginewidget.ui ) -kconfig_add_kcfg_files(okularcore_SRCS conf/settings_core.kcfgc ) +kconfig_add_kcfg_files(okularcore_SRCS conf/settings_core.kcfgc) add_library(okularcore SHARED ${okularcore_SRCS}) generate_export_header(okularcore BASE_NAME okularcore EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/core/okularcore_export.h") @@ -323,7 +323,7 @@ ki18n_wrap_ui(okularpart_SRCS conf/dlgpresentationbase.ui ) -kconfig_add_kcfg_files(okularpart_SRCS conf/settings.kcfgc ) +kconfig_add_kcfg_files(okularpart_SRCS conf/settings.kcfgc) add_library(okularpart SHARED ${okularpart_SRCS}) generate_export_header(okularpart BASE_NAME okularpart) diff --git a/conf/dlggeneral.cpp b/conf/dlggeneral.cpp index 964a655bc..8836566a6 100644 --- a/conf/dlggeneral.cpp +++ b/conf/dlggeneral.cpp @@ -14,6 +14,7 @@ #include #include "ui_dlggeneralbase.h" +#include "settings.h" DlgGeneral::DlgGeneral( QWidget * parent, Okular::EmbedMode embedMode ) : QWidget( parent ) @@ -21,6 +22,8 @@ DlgGeneral::DlgGeneral( QWidget * parent, Okular::EmbedMode embedMode ) m_dlg = new Ui_DlgGeneralBase(); m_dlg->setupUi( this ); + setCustomBackgroundColorButton( Okular::Settings::useCustomBackgroundColor() ); + if( embedMode == Okular::ViewerWidgetMode ) { m_dlg->kcfg_SyncThumbnailsViewport->setVisible( false ); @@ -48,3 +51,7 @@ void DlgGeneral::showEvent( QShowEvent * ) #endif } +void DlgGeneral::setCustomBackgroundColorButton( bool value ) +{ + m_dlg->kcfg_BackgroundColor->setEnabled( value ); +} diff --git a/conf/dlggeneral.h b/conf/dlggeneral.h index f363d260a..6939efbce 100644 --- a/conf/dlggeneral.h +++ b/conf/dlggeneral.h @@ -24,6 +24,9 @@ class DlgGeneral : public QWidget explicit DlgGeneral( QWidget * parent, Okular::EmbedMode embedMode ); virtual ~DlgGeneral(); + public slots: + void setCustomBackgroundColorButton( bool value ); + protected: void showEvent( QShowEvent * ) override; diff --git a/conf/dlggeneralbase.ui b/conf/dlggeneralbase.ui index cf4ebca09..089ac43cf 100644 --- a/conf/dlggeneralbase.ui +++ b/conf/dlggeneralbase.ui @@ -2,12 +2,15 @@ DlgGeneralBase + + true + 0 0 558 - 575 + 632 @@ -140,6 +143,30 @@ + + + + 6 + + + 0 + + + + + false + + + + + + + Use custom background color + + + + + @@ -439,9 +466,39 @@ For files which were opened before the previous zoom is applied. + + + KColorButton + QPushButton +
kcolorbutton.h
+ + useDefaultBackgroundColor() + +
+
kiconloader.h - + + + kcfg_UseCustomBackgroundColor + toggled(bool) + DlgGeneralBase + setCustomBackgroundColorButton(bool) + + + 130 + 229 + + + 203 + -9 + + + + + + setCustomBackgroundColorButton(bool) +
diff --git a/conf/okular.kcfg b/conf/okular.kcfg index 69ea8cf62..8b2f356af 100644 --- a/conf/okular.kcfg +++ b/conf/okular.kcfg @@ -290,6 +290,11 @@ false + + false + + + diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 9766422b9..a9132ac00 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -3416,7 +3416,12 @@ QList< Okular::RegularAreaRect * > PageView::textSelections( const QPoint& start void PageView::drawDocumentOnPainter( const QRect & contentsRect, QPainter * p ) { - QColor backColor = viewport()->palette().color( QPalette::Dark ); + QColor backColor; + + if ( Okular::Settings::useCustomBackgroundColor() ) + backColor = Okular::Settings::backgroundColor(); + else + backColor = viewport()->palette().color( QPalette::Dark ); // when checking if an Item is contained in contentsRect, instead of // growing PageViewItems rects (for keeping outline into account), we -- GitLab