File indexing completed on 2024-05-12 15:59:14

0001 /* This file is part of the KDE project
0002  * SPDX-FileCopyrightText: 2012 Arjen Hiemstra <ahiemstra@heimr.nl>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "Settings.h"
0008 #include <QApplication>
0009 
0010 
0011 #include <ksharedconfig.h>
0012 #include <kconfiggroup.h>
0013 #include <kis_paintop_preset.h>
0014 #include "KisResourceServerProvider.h"
0015 
0016 #include "Theme.h"
0017 #include "PropertyContainer.h"
0018 #include <kis_config.h>
0019 
0020 class Settings::Private
0021 {
0022 public:
0023     Private() : temporaryFile(false), focusItem(0), theme(0){ }
0024 
0025     QString currentFile;
0026     bool temporaryFile;
0027     QQuickItem *focusItem;
0028     Theme* theme {0};
0029 };
0030 
0031 Settings::Settings( QObject* parent )
0032     : QObject( parent )
0033     , d( new Private )
0034 {
0035 }
0036 
0037 Settings::~Settings()
0038 {
0039     delete d;
0040 }
0041 
0042 void Settings::setTheme(Theme *theme)
0043 {
0044     d->theme = theme;
0045     d->theme->setParent(this);
0046     connect(d->theme, SIGNAL(fontCacheRebuilt()), SIGNAL(themeChanged()));
0047 
0048 }
0049 
0050 
0051 QString Settings::currentFile() const
0052 {
0053     return d->currentFile;
0054 }
0055 
0056 void Settings::setCurrentFile(const QString& fileName)
0057 {
0058     qApp->processEvents();
0059     if (fileName != d->currentFile) {
0060         d->currentFile = fileName;
0061         emit currentFileChanged();
0062     }
0063 }
0064 
0065 bool Settings::isTemporaryFile() const
0066 {
0067     return d->temporaryFile;
0068 }
0069 
0070 void Settings::setTemporaryFile(bool temp)
0071 {
0072     if (temp != d->temporaryFile) {
0073         d->temporaryFile = temp;
0074         emit temporaryFileChanged();
0075     }
0076 }
0077 
0078 QQuickItem* Settings::focusItem()
0079 {
0080     return d->focusItem;
0081 }
0082 
0083 void Settings::setFocusItem(QQuickItem* item)
0084 {
0085     if (item != d->focusItem) {
0086         d->focusItem = item;
0087         emit focusItemChanged();
0088     }
0089 }
0090 
0091 QObject* Settings::theme() const
0092 {
0093     return d->theme;
0094 }
0095 
0096 QString Settings::themeID() const
0097 {
0098     if(d->theme)
0099         return d->theme->id();
0100 
0101     return QString();
0102 }
0103 
0104 void Settings::setThemeID(const QString& /*id*/)
0105 {
0106 //    if(!d->theme || id != d->theme->id()) {
0107 //        if(d->theme) {
0108 //            delete d->theme;
0109 //            d->theme = 0;
0110 //        }
0111 
0112 //        d->theme = Theme::load(id, this);
0113 //        KSharedConfig::openConfig()->group("General").writeEntry<QString>("theme", id);
0114 
0115 //        emit themeChanged();
0116 //    }
0117 }
0118 
0119 QObject* Settings::customImageSettings() const
0120 {
0121     QObject* settings = new PropertyContainer("customImageSettings", qApp);
0122     KisConfig cfg(false);
0123     settings->setProperty("Width", cfg.defImageWidth());
0124     settings->setProperty("Height", cfg.defImageHeight());
0125     settings->setProperty("Resolution", qRound(cfg.defImageResolution() * 72)); // otherwise we end up with silly floating point numbers
0126     settings->setProperty("ColorModel", cfg.defColorModel());
0127     settings->setProperty("ColorDepth", cfg.defaultColorDepth());
0128     settings->setProperty("ColorProfile", cfg.defColorProfile());
0129     return settings;
0130 }
0131