File indexing completed on 2024-04-21 15:41:00

0001 /*
0002    SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "colorsandmessageviewstyle.h"
0008 
0009 #include <QApplication>
0010 
0011 ColorsAndMessageViewStyle::ColorsAndMessageViewStyle()
0012     : QObject()
0013 {
0014 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0015     connect(qApp, &QApplication::paletteChanged, this, &ColorsAndMessageViewStyle::regenerateColorScheme);
0016 #endif
0017     regenerateColorScheme();
0018 }
0019 
0020 ColorsAndMessageViewStyle &ColorsAndMessageViewStyle::self()
0021 {
0022     static ColorsAndMessageViewStyle c;
0023     return c;
0024 }
0025 
0026 KColorScheme ColorsAndMessageViewStyle::schemeView() const
0027 {
0028     return mSchemeView;
0029 }
0030 
0031 KColorScheme ColorsAndMessageViewStyle::schemeWindow() const
0032 {
0033     return mSchemeWindow;
0034 }
0035 
0036 void ColorsAndMessageViewStyle::regenerateColorScheme()
0037 {
0038     mSchemeView = KColorScheme();
0039     mSchemeWindow = KColorScheme(QPalette::Active, KColorScheme::Window);
0040     Q_EMIT needToUpdateColors();
0041 }
0042 
0043 bool ColorsAndMessageViewStyle::event(QEvent *e)
0044 {
0045 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0046     if (e->type() == QEvent::ApplicationPaletteChange) {
0047         regenerateColorScheme();
0048     }
0049 #endif
0050     return QObject::event(e);
0051 }
0052 
0053 #include "moc_colorsandmessageviewstyle.cpp"