Commit 209c7284 authored by Felix Ernst's avatar Felix Ernst 🇺🇦
Browse files

Remove background color chooser widget

In e6241375 actions were added to
Gwenview which allowed easy changing of the background color. As
part of this change a widget was added to the status bar which
contains these new actions.

This commit removes the widget again while keeping the actions to
quickly change the background color of the view available both from
the menu bar and from the right-click context menu.

Having these actions always visible on the status bar doesn't seem
necessary because users generally seem to not be too interested in
switching the background color frequently.

This commit is kind of a requirement for adding other actions to
the status bar instead which users are vocally more interested in
having.

Most of the added lines were just moved from the widget class to the `documentviewcontroller`.

CCBUG: 441447
parent c823464f
Pipeline #123329 passed with stage
in 11 minutes and 50 seconds
......@@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Local
#include "gwenview_app_debug.h"
#include <lib/backgroundcolorwidget/backgroundcolorwidget.h>
#include <lib/binder.h>
#include <lib/document/documentfactory.h>
#include <lib/document/documentjob.h>
......@@ -140,10 +139,11 @@ struct GvCorePrivate {
mPalettes[GvCore::NormalPalette] = KColorScheme::createApplicationPalette(config);
QPalette viewPalette = mPalettes[GvCore::NormalPalette];
BackgroundColorWidget::ColorMode colorMode = GwenviewConfig::backgroundColorMode();
bool usingLightTheme = BackgroundColorWidget::usingLightTheme();
DocumentView::BackgroundColorMode colorMode = GwenviewConfig::backgroundColorMode();
const bool usingLightTheme = qApp->palette().base().color().lightness() > qApp->palette().text().color().lightness();
if ((usingLightTheme && colorMode == BackgroundColorWidget::Dark) || (!usingLightTheme && colorMode == BackgroundColorWidget::Light)) {
if ((usingLightTheme && colorMode == DocumentView::BackgroundColorMode::Dark)
|| (!usingLightTheme && colorMode == DocumentView::BackgroundColorMode::Light)) {
viewPalette.setColor(QPalette::Base, mPalettes[GvCore::NormalPalette].color(QPalette::Text));
viewPalette.setColor(QPalette::Text, mPalettes[GvCore::NormalPalette].color(QPalette::Base));
viewPalette.setColor(QPalette::Window, mPalettes[GvCore::NormalPalette].color(QPalette::WindowText));
......@@ -152,7 +152,7 @@ struct GvCorePrivate {
viewPalette.setColor(QPalette::ButtonText, mPalettes[GvCore::NormalPalette].color(QPalette::Button));
viewPalette.setColor(QPalette::ToolTipBase, mPalettes[GvCore::NormalPalette].color(QPalette::ToolTipText));
viewPalette.setColor(QPalette::ToolTipText, mPalettes[GvCore::NormalPalette].color(QPalette::ToolTipBase));
} else if (colorMode == BackgroundColorWidget::Neutral) {
} else if (colorMode == DocumentView::BackgroundColorMode::Neutral) {
QColor base = KColorUtils::mix(mPalettes[GvCore::NormalPalette].color(QPalette::Base), mPalettes[GvCore::NormalPalette].color(QPalette::Text), 0.5);
QColor window =
KColorUtils::mix(mPalettes[GvCore::NormalPalette].color(QPalette::Window), mPalettes[GvCore::NormalPalette].color(QPalette::WindowText), 0.5);
......
......@@ -45,7 +45,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "gwenview_app_debug.h"
#include "splitter.h"
#include <gvcore.h>
#include <lib/backgroundcolorwidget/backgroundcolorwidget.h>
#include <lib/documentview/abstractdocumentviewadapter.h>
#include <lib/documentview/abstractrasterimageviewtool.h>
#include <lib/documentview/documentview.h>
......@@ -120,7 +119,6 @@ struct ViewMainPagePrivate {
DocumentViewSynchronizer *mSynchronizer;
QToolButton *mToggleSideBarButton;
QToolButton *mToggleThumbnailBarButton;
BackgroundColorWidget *mBackgroundColorWidget;
ZoomWidget *mZoomWidget;
DocumentViewContainer *mDocumentViewContainer;
SlideContainer *mToolContainer;
......@@ -151,7 +149,6 @@ struct ViewMainPagePrivate {
mStatusBarContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
mToggleSideBarButton = new StatusBarToolButton;
mToggleThumbnailBarButton = new StatusBarToolButton;
mBackgroundColorWidget = new BackgroundColorWidget;
mZoomWidget = new ZoomWidget;
mSynchronizeCheckBox = new QCheckBox(i18n("Synchronize"));
mSynchronizeCheckBox->hide();
......@@ -176,7 +173,6 @@ struct ViewMainPagePrivate {
// so its autohide feature works properly (stretch factor = 1)
statusBarContainerLayout->addWidget(mDocumentCountLabel, 1);
statusBarContainerLayout->addStretch();
statusBarContainerLayout->addWidget(mBackgroundColorWidget);
statusBarContainerLayout->addWidget(mZoomWidget);
//--
mAdapterContainer = new QWidget;
......@@ -215,7 +211,6 @@ struct ViewMainPagePrivate {
viewMainPageLayout->addWidget(mStatusBarContainer);
//--
mDocumentViewController = new DocumentViewController(mActionCollection, q);
mDocumentViewController->setBackgroundColorWidget(mBackgroundColorWidget);
mDocumentViewController->setZoomWidget(mZoomWidget);
mDocumentViewController->setToolContainer(mToolContainer);
mSynchronizer = new DocumentViewSynchronizer(&mDocumentViews, q);
......
......@@ -41,7 +41,6 @@ include_directories(
)
set(gwenviewlib_SRCS
backgroundcolorwidget/backgroundcolorwidget.cpp
cms/iccjpeg.c
cms/cmsprofile.cpp
cms/cmsprofile_png.cpp
......
/* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "backgroundcolorwidget.h"
#include <lib/gwenviewconfig.h>
#include <lib/statusbartoolbutton.h>
#include <KColorUtils>
#include <KLocalizedString>
#include <KSqueezedTextLabel>
#include <QAction>
#include <QApplication>
#include <QButtonGroup>
#include <QHBoxLayout>
#include <QPainter>
#include <QStyle>
#include <QStyleOptionToolButton>
using namespace Gwenview;
class Gwenview::BackgroundColorWidgetPrivate
{
Q_DECLARE_PUBLIC(BackgroundColorWidget)
public:
BackgroundColorWidgetPrivate(BackgroundColorWidget *q);
BackgroundColorWidget *const q_ptr;
void initChildWidgets();
void initPixmaps();
void paintPixmap(QPixmap &pixmap, const QColor &color);
void paintAutoPixmap(QPixmap &pixmap, const QColor &lightColor, const QColor &darkColor);
void setIcons(const QIcon &autoIcon, const QIcon &lightIcon, const QIcon &neutralIcon, const QIcon &darkIcon);
BackgroundColorWidget::ColorMode colorMode;
bool mirrored;
bool usingLightTheme;
QHBoxLayout *hBoxLayout = nullptr;
KSqueezedTextLabel *label = nullptr;
QButtonGroup *buttonGroup = nullptr;
StatusBarToolButton *autoButton = nullptr;
StatusBarToolButton *lightButton = nullptr;
StatusBarToolButton *neutralButton = nullptr;
StatusBarToolButton *darkButton = nullptr;
QAction *autoMode = nullptr;
QAction *lightMode = nullptr;
QAction *neutralMode = nullptr;
QAction *darkMode = nullptr;
};
BackgroundColorWidgetPrivate::BackgroundColorWidgetPrivate(BackgroundColorWidget *q)
: q_ptr(q)
, colorMode(GwenviewConfig::backgroundColorMode())
, mirrored(qApp->isRightToLeft())
, usingLightTheme(q->usingLightTheme())
, hBoxLayout(new QHBoxLayout(q))
, label(new KSqueezedTextLabel(q))
, buttonGroup(new QButtonGroup(q))
, autoButton(new StatusBarToolButton(q))
, lightButton(new StatusBarToolButton(q))
, neutralButton(new StatusBarToolButton(q))
, darkButton(new StatusBarToolButton(q))
{
initChildWidgets();
};
void BackgroundColorWidgetPrivate::initChildWidgets()
{
Q_Q(BackgroundColorWidget);
hBoxLayout->setContentsMargins(0, 0, 0, 0);
hBoxLayout->setSpacing(0);
label->setText(i18nc("@label:chooser Describes what a row of buttons control", "Background color:"));
// 4 is the same as the hardcoded spacing between icons and labels defined in
// QToolButton::sizeHint() when toolButtonStyle == ToolButtonTextBesideIcon.
label->setContentsMargins(4, 0, 4, 0);
label->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
label->setTextElideMode(Qt::ElideRight);
hBoxLayout->addWidget(label);
buttonGroup->setExclusive(true);
for (auto button : {autoButton, lightButton, neutralButton, darkButton}) {
button->setToolButtonStyle(Qt::ToolButtonIconOnly);
button->setCheckable(true);
buttonGroup->addButton(button);
hBoxLayout->addWidget(button);
}
autoButton->setGroupPosition(mirrored ? StatusBarToolButton::GroupRight : StatusBarToolButton::GroupLeft);
autoButton->setChecked(colorMode == BackgroundColorWidget::Auto);
lightButton->setGroupPosition(StatusBarToolButton::GroupCenter);
lightButton->setChecked(colorMode == BackgroundColorWidget::Light);
neutralButton->setGroupPosition(StatusBarToolButton::GroupCenter);
neutralButton->setChecked(colorMode == BackgroundColorWidget::Neutral);
darkButton->setGroupPosition(mirrored ? StatusBarToolButton::GroupLeft : StatusBarToolButton::GroupRight);
darkButton->setChecked(colorMode == BackgroundColorWidget::Dark);
initPixmaps();
}
void BackgroundColorWidgetPrivate::initPixmaps()
{
QPixmap lightPixmap(lightButton->iconSize() * qApp->devicePixelRatio());
QPixmap neutralPixmap(neutralButton->iconSize() * qApp->devicePixelRatio());
QPixmap darkPixmap(darkButton->iconSize() * qApp->devicePixelRatio());
QPixmap autoPixmap(/*autoButton*/ darkButton->iconSize() * qApp->devicePixelRatio());
// Wipe them clean. If we don't do this, the background will have all sorts of weird artifacts.
lightPixmap.fill(Qt::transparent);
neutralPixmap.fill(Qt::transparent);
darkPixmap.fill(Qt::transparent);
autoPixmap.fill(Qt::transparent);
const QColor &lightColor = usingLightTheme ? qApp->palette().base().color() : qApp->palette().text().color();
const QColor &darkColor = usingLightTheme ? qApp->palette().text().color() : qApp->palette().base().color();
QColor neutralColor = KColorUtils::mix(lightColor, darkColor, 0.5);
paintPixmap(lightPixmap, lightColor);
paintPixmap(neutralPixmap, neutralColor);
paintPixmap(darkPixmap, darkColor);
paintAutoPixmap(autoPixmap, lightColor, darkColor);
setIcons(QIcon(autoPixmap), QIcon(lightPixmap), QIcon(neutralPixmap), QIcon(darkPixmap));
}
void BackgroundColorWidgetPrivate::paintPixmap(QPixmap &pixmap, const QColor &color)
{
QPainter painter;
painter.begin(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
// QPainter isn't good at drawing lines that are exactly 1px thick.
qreal penWidth = qApp->devicePixelRatio() != 1 ? qApp->devicePixelRatio() : qApp->devicePixelRatio() + 0.001;
QColor penColor = KColorUtils::mix(color, qApp->palette().text().color(), 0.3);
QPen pen(penColor, penWidth);
qreal margin = pen.widthF() / 2.0;
QMarginsF penMargins(margin, margin, margin, margin);
QRectF rect = pixmap.rect();
painter.setBrush(color);
painter.setPen(pen);
painter.drawEllipse(rect.marginsRemoved(penMargins));
painter.end();
}
void BackgroundColorWidgetPrivate::paintAutoPixmap(QPixmap &pixmap, const QColor &lightColor, const QColor &darkColor)
{
QPainter painter;
painter.begin(&pixmap);
painter.setRenderHint(QPainter::Antialiasing);
// QPainter isn't good at drawing lines that are exactly 1px thick.
qreal penWidth = qApp->devicePixelRatio() != 1 ? qApp->devicePixelRatio() : qApp->devicePixelRatio() + 0.001;
QColor lightPenColor = KColorUtils::mix(lightColor, darkColor, 0.3);
QPen lightPen(lightPenColor, penWidth);
QColor darkPenColor = KColorUtils::mix(darkColor, lightColor, 0.3);
QPen darkPen(darkPenColor, penWidth);
qreal margin = lightPen.widthF() / 2.0;
QMarginsF penMargins(margin, margin, margin, margin);
QRectF rect = pixmap.rect();
rect = rect.marginsRemoved(penMargins);
int lightStartAngle = 45 * 16;
int lightSpanAngle = 180 * 16;
int darkStartAngle = -135 * 16;
int darkSpanAngle = 180 * 16;
painter.setBrush(lightColor);
painter.setPen(lightPen);
painter.drawChord(rect, lightStartAngle, lightSpanAngle);
painter.setBrush(darkColor);
painter.setPen(darkPen);
painter.drawChord(rect, darkStartAngle, darkSpanAngle);
painter.end();
}
// This function is written this way because existing Gwenview code tends to
// define actions in a central location and then pass them down to children.
// This code makes sure the buttons still have icons if the actions have not
// been set yet.
void BackgroundColorWidgetPrivate::setIcons(const QIcon &autoIcon, const QIcon &lightIcon, const QIcon &neutralIcon, const QIcon &darkIcon)
{
if (autoMode) {
autoMode->setIcon(autoIcon);
} else {
autoButton->setIcon(autoIcon);
}
if (lightMode) {
lightMode->setIcon(lightIcon);
} else {
lightButton->setIcon(lightIcon);
}
if (neutralMode) {
neutralMode->setIcon(neutralIcon);
} else {
neutralButton->setIcon(neutralIcon);
}
if (darkMode) {
darkMode->setIcon(darkIcon);
} else {
darkButton->setIcon(darkIcon);
}
}
BackgroundColorWidget::BackgroundColorWidget(QWidget *parent)
: QWidget(parent)
, d_ptr(new BackgroundColorWidgetPrivate(this))
{
Q_D(BackgroundColorWidget);
connect(qApp, &QApplication::paletteChanged, this, [d]() {
d->usingLightTheme = usingLightTheme();
d->initPixmaps();
});
connect(qApp, &QApplication::layoutDirectionChanged, this, [d]() {
d->mirrored = qApp->isRightToLeft();
d->autoButton->setGroupPosition(d->mirrored ? StatusBarToolButton::GroupRight : StatusBarToolButton::GroupLeft);
d->darkButton->setGroupPosition(d->mirrored ? StatusBarToolButton::GroupLeft : StatusBarToolButton::GroupRight);
});
}
BackgroundColorWidget::~BackgroundColorWidget() noexcept
{
}
BackgroundColorWidget::ColorMode BackgroundColorWidget::colorMode() const
{
Q_D(const BackgroundColorWidget);
return d->colorMode;
}
void BackgroundColorWidget::setColorMode(ColorMode colorMode)
{
Q_D(BackgroundColorWidget);
if (d->colorMode == colorMode) {
return;
}
d->colorMode = colorMode;
d->autoButton->setChecked(colorMode == BackgroundColorWidget::Auto);
d->lightButton->setChecked(colorMode == BackgroundColorWidget::Light);
d->neutralButton->setChecked(colorMode == BackgroundColorWidget::Neutral);
d->darkButton->setChecked(colorMode == BackgroundColorWidget::Dark);
Q_EMIT colorModeChanged(colorMode);
}
void BackgroundColorWidget::setActions(QAction *autoMode, QAction *lightMode, QAction *neutralMode, QAction *darkMode)
{
Q_D(BackgroundColorWidget);
autoMode->setIcon(d->autoButton->icon());
lightMode->setIcon(d->lightButton->icon());
neutralMode->setIcon(d->neutralButton->icon());
darkMode->setIcon(d->darkButton->icon());
d->autoMode = autoMode;
d->lightMode = lightMode;
d->neutralMode = neutralMode;
d->darkMode = darkMode;
d->autoButton->setDefaultAction(autoMode);
d->lightButton->setDefaultAction(lightMode);
d->neutralButton->setDefaultAction(neutralMode);
d->darkButton->setDefaultAction(darkMode);
QActionGroup *actionGroup = new QActionGroup(this);
actionGroup->addAction(autoMode);
actionGroup->addAction(lightMode);
actionGroup->addAction(neutralMode);
actionGroup->addAction(darkMode);
actionGroup->setExclusive(true);
}
bool BackgroundColorWidget::usingLightTheme()
{
return qApp->palette().base().color().lightness() > qApp->palette().text().color().lightness();
}
/* SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef BACKGROUNDCOLORWIDGET_H
#define BACKGROUNDCOLORWIDGET_H
#include <QWidget>
#include <lib/gwenviewlib_export.h>
namespace Gwenview
{
class BackgroundColorWidgetPrivate;
class GWENVIEWLIB_EXPORT BackgroundColorWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY(ColorMode colorMode READ colorMode WRITE setColorMode NOTIFY colorModeChanged)
public:
explicit BackgroundColorWidget(QWidget *parent = nullptr);
~BackgroundColorWidget() override;
enum ColorMode { Auto = 0, Light = 1, Neutral = 2, Dark = 3 };
Q_ENUM(ColorMode)
ColorMode colorMode() const;
void setColorMode(ColorMode colorMode);
void setActions(QAction *autoMode, QAction *lightMode, QAction *neutralMode, QAction *darkMode);
static bool usingLightTheme();
Q_SIGNALS:
void colorModeChanged(ColorMode colorMode);
private:
const std::unique_ptr<BackgroundColorWidgetPrivate> d_ptr;
Q_DECLARE_PRIVATE(BackgroundColorWidget)
Q_DISABLE_COPY(BackgroundColorWidget)
};
}
#endif // BACKGROUNDCOLORWIDGET_H
......@@ -666,7 +666,7 @@ void DocumentView::toggleBirdEyeView()
GwenviewConfig::setBirdEyeViewEnabled(!GwenviewConfig::birdEyeViewEnabled());
}
void DocumentView::setBackgroundColorMode(BackgroundColorWidget::ColorMode colorMode)
void DocumentView::setBackgroundColorMode(BackgroundColorMode colorMode)
{
GwenviewConfig::setBackgroundColorMode(colorMode);
Q_EMIT backgroundColorModeChanged(colorMode);
......
......@@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// KF
// Local
#include <lib/backgroundcolorwidget/backgroundcolorwidget.h>
#include <lib/document/document.h>
class QPropertyAnimation;
......@@ -79,6 +78,8 @@ public:
GLAnimation,
#endif
};
enum BackgroundColorMode { Auto = 0, Light = 1, Neutral = 2, Dark = 3 };
Q_ENUM(BackgroundColorMode)
/**
* Create a new view attached to scene. We need the scene to be able to
......@@ -157,7 +158,7 @@ public Q_SLOTS:
void toggleBirdEyeView();
void setBackgroundColorMode(BackgroundColorWidget::ColorMode colorMode);
void setBackgroundColorMode(BackgroundColorMode colorMode);
void setPosition(const QPoint &);
......@@ -183,7 +184,7 @@ Q_SIGNALS:
void videoFinished();
void backgroundColorModeChanged(BackgroundColorWidget::ColorMode);
void backgroundColorModeChanged(BackgroundColorMode);
void minimumZoomChanged(qreal);
......
// vim: set tabstop=4 shiftwidth=4 expandtab:
/*
Gwenview: an image viewer
Copyright 2011 Aurélien Gâteau <agateau@kde.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
Gwenview: an image viewer
SPDX-FileCopyrightText: 2011 Aurélien Gâteau <agateau@kde.org>
SPDX-FileCopyrightText: 2021 Noah Davis <noahadvs@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// Self
#include "documentviewcontroller.h"
......@@ -32,12 +21,15 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// KF
#include <KActionCategory>
#include <KColorUtils>
#include <KLocalizedString>
// Qt
#include <QAction>
#include <QActionGroup>
#include <QApplication>
#include <QHBoxLayout>
#include <QPainter>
namespace Gwenview
{
......@@ -45,7 +37,6 @@ struct DocumentViewControllerPrivate {
DocumentViewController *q;
KActionCollection *mActionCollection;
DocumentView *mView;
BackgroundColorWidget *mBackgroundColorWidget;
ZoomWidget *mZoomWidget;
SlideContainer *mToolContainer;
......@@ -97,44 +88,122 @@ struct DocumentViewControllerPrivate {
mBackgroundColorModeAuto = view->addAction(QStringLiteral("view_background_colormode_auto"));
mBackgroundColorModeAuto->setCheckable(true);
mBackgroundColorModeAuto->setChecked(GwenviewConfig::backgroundColorMode() == BackgroundColorWidget::Auto);
mBackgroundColorModeAuto->setChecked(GwenviewConfig::backgroundColorMode() == DocumentView::BackgroundColorMode::Auto);
mBackgroundColorModeAuto->setText(i18nc("@action", "Follow color scheme"));
mBackgroundColorModeAuto->setEnabled(mView != nullptr);
mBackgroundColorModeAuto->setToolTip(mBackgroundColorModeAuto->text());
mBackgroundColorModeLight = view->addAction(QStringLiteral("view_background_colormode_light"));
mBackgroundColorModeLight->setCheckable(true);
mBackgroundColorModeLight->setChecked(GwenviewConfig::backgroundColorMode() == BackgroundColorWidget::Light);
mBackgroundColorModeLight->setChecked(GwenviewConfig::backgroundColorMode() == DocumentView::BackgroundColorMode::Light);
mBackgroundColorModeLight->setText(i18nc("@action", "Light Mode"));
mBackgroundColorModeLight->setEnabled(mView != nullptr);
mBackgroundColorModeLight->setToolTip(mBackgroundColorModeLight->text());
mBackgroundColorModeNeutral = view->addAction(QStringLiteral("view_background_colormode_neutral"));
mBackgroundColorModeNeutral->setCheckable(true);
mBackgroundColorModeNeutral->setChecked(GwenviewConfig::backgroundColorMode() == BackgroundColorWidget::Neutral);
mBackgroundColorModeNeutral->setChecked(GwenviewConfig::backgroundColorMode() == DocumentView::BackgroundColorMode::Neutral);
mBackgroundColorModeNeutral->setText(i18nc("@action", "Neutral Mode"));
mBackgroundColorModeNeutral->setEnabled(mView != nullptr);
mBackgroundColorModeNeutral->setToolTip(mBackgroundColorModeNeutral->text());
mBackgroundColorModeDark = view->addAction(QStringLiteral("view_background_colormode_dark"));
mBackgroundColorModeDark->setCheckable(true);
mBackgroundColorModeDark->setChecked(GwenviewConfig::backgroundColorMode() == BackgroundColorWidget::Dark);
mBackgroundColorModeDark->setChecked(GwenviewConfig::backgroundColorMode() == DocumentView::BackgroundColorMode::Dark);
mBackgroundColorModeDark->setText(i18nc("@action", "Dark Mode"));
mBackgroundColorModeDark->setEnabled(mView != nullptr);
mBackgroundColorModeDark->setToolTip(mBackgroundColorModeDark->text());
setBackgroundColorModeIcons(mBackgroundColorModeAuto, mBackgroundColorModeLight, mBackgroundColorModeNeutral, mBackgroundColorModeDark);
QActionGroup *actionGroup = new QActionGroup(q);
actionGroup->addAction(mBackgroundColorModeAuto);
actionGroup->addAction(mBackgroundColorModeLight);
actionGroup->addAction(mBackgroundColorModeNeutral);
actionGroup->addAction(mBackgroundColorModeDark);
actionGroup->setExclusive(true);
mActions << mZoomToFitAction << mActualSizeAction << mZoomInAction << mZoomOutAction << mZoomToFillAction << mToggleBirdEyeViewAction
<< mBackgroundColorModeAuto << mBackgroundColorModeLight << mBackgroundColorModeNeutral << mBackgroundColorModeDark;
}
void connectBackgroundColorWidget()
void setBackgroundColorModeIcons(QAction *autoAction, QAction *lightAction, QAction *neutralAction, QAction *darkAction) const
{
if (!mBackgroundColorWidget || !mView) {
return;
}
const bool usingLightTheme = qApp->palette().base().color().lightness() > qApp->palette().text().color().lightness();
const int pixMapWidth(16 * qApp->devicePixelRatio()); // Default icon size in menus is 16 but on toolbars is 22. The icon will only show up in QMenus
// unless a user adds the action to their toolbar so we go for 16.
QPixmap lightPixmap(pixMapWidth, pixMapWidth);
QPixmap neutralPixmap(pixMapWidth, pixMapWidth);
QPixmap darkPixmap(pixMapWidth, pixMapWidth);
QPixmap autoPixmap(pixMapWidth, pixMapWidth);
// Wipe them clean. If we don't do this, the background will have all sorts of weird artifacts.
lightPixmap.fill(Qt::transparent);
neutralPixmap.fill(Qt::transparent);
darkPixmap.fill(Qt::transparent);
autoPixmap.fill(Qt::transparent);
const QColor &lightColor = usingLightTheme ? qApp->palette().base().color() : qApp->palette().text().color();
const QColor &darkColor = usingLightTheme ? qApp->palette().text().color() : qApp->palette().base().color();
QColor neutralColor = KColorUtils::mix(lightColor, darkColor, 0.5);
paintPixmap(lightPixmap, lightColor);
paintPixmap(neutralPixmap, neutralColor);
paintPixmap(darkPixmap, darkColor);
paintAutoPixmap(autoPixmap, lightColor, darkColor);
autoAction->setIcon(autoPixmap);
lightAction->setIcon(lightPixmap);
neutralAction->setIcon(neutralPixmap);
darkAction->setIcon(darkPixmap);
}
QObject::connect(mBackgroundColorWidget, &BackgroundColorWidget::colorModeChanged, mView, &DocumentView::setBackgroundColorMode);
QObject::connect(mView, &DocumentView::backgroundColorModeChanged, mBackgroundColorWidget, &BackgroundColorWidget::setColorMode);