diff --git a/src/ColorScheme.h b/src/ColorScheme.h --- a/src/ColorScheme.h +++ b/src/ColorScheme.h @@ -27,6 +27,7 @@ #include // Konsole +#include "konsoleprivate_export.h" #include "CharacterColor.h" class KConfig; @@ -68,7 +69,7 @@ * The color scheme includes the palette of colors used to draw the text and character backgrounds * in the display and the opacity level of the display background. */ -class ColorScheme +class KONSOLEPRIVATE_EXPORT ColorScheme { public: /** diff --git a/src/ColorSchemeManager.h b/src/ColorSchemeManager.h --- a/src/ColorSchemeManager.h +++ b/src/ColorSchemeManager.h @@ -57,9 +57,8 @@ const ColorScheme *defaultColorScheme() const; /** - * Returns the color scheme with the given name or 0 if no - * scheme with that name exists. If @p name is empty, the - * default color scheme is returned. + * Returns the color scheme with the given name or the default if no + * scheme with that name exists. * * The first time that a color scheme with a particular name is * requested, the configuration information is loaded from disk. diff --git a/src/ColorSchemeManager.cpp b/src/ColorSchemeManager.cpp --- a/src/ColorSchemeManager.cpp +++ b/src/ColorSchemeManager.cpp @@ -207,17 +207,15 @@ if (_colorSchemes.contains(name)) { return _colorSchemes[name]; - } else { - // look for this color scheme - QString path = findColorSchemePath(name); - if (!path.isEmpty() && loadColorScheme(path)) { - return findColorScheme(name); - } - - qCDebug(KonsoleDebug) << "Could not find color scheme - " << name; - - return nullptr; } + // look for this color scheme + QString path = findColorSchemePath(name); + if (!path.isEmpty() && loadColorScheme(path)) { + return findColorScheme(name); + } + + qCDebug(KonsoleDebug) << "Could not find color scheme - " << name; + return defaultColorScheme(); } QString ColorSchemeManager::findColorSchemePath(const QString &name) const diff --git a/src/EditProfileDialog.cpp b/src/EditProfileDialog.cpp --- a/src/EditProfileDialog.cpp +++ b/src/EditProfileDialog.cpp @@ -283,8 +283,7 @@ const QString EditProfileDialog::currentColorSchemeName() const { - const QString ¤tColorSchemeName = lookupProfile()->colorScheme(); - return currentColorSchemeName; + return lookupProfile()->colorSchemeName(); } void EditProfileDialog::preparePage(int page) @@ -740,10 +739,10 @@ bool EditProfileDialog::eventFilter(QObject *watched, QEvent *event) { if (watched == _ui->colorSchemeList && event->type() == QEvent::Leave) { - if (_tempProfile->isPropertySet(Profile::ColorScheme)) { - preview(Profile::ColorScheme, _tempProfile->colorScheme()); + if (_tempProfile->isPropertySet(Profile::ColorSchemeName)) { + preview(Profile::ColorSchemeName, _tempProfile->colorSchemeName()); } else { - unpreview(Profile::ColorScheme); + unpreview(Profile::ColorSchemeName); } } if (watched == _ui->fontPreviewLabel && event->type() == QEvent::FontChange) { @@ -838,7 +837,7 @@ { const QString &name = index.data(Qt::UserRole + 1).value()->name(); - delayedPreview(Profile::ColorScheme, name); + delayedPreview(Profile::ColorSchemeName, name); } void EditProfileDialog::removeColorScheme() @@ -1015,7 +1014,7 @@ // select the edited or the new colorScheme after saving the changes updateColorSchemeList(selectedColorSchemeName); - preview(Profile::ColorScheme, newScheme->name()); + preview(Profile::ColorSchemeName, newScheme->name()); } void EditProfileDialog::colorSchemeSelected() @@ -1026,7 +1025,7 @@ QAbstractItemModel *model = _ui->colorSchemeList->model(); const ColorScheme *colors = model->data(selected.first(), Qt::UserRole + 1).value(); if (colors != nullptr) { - updateTempProfileProperty(Profile::ColorScheme, colors->name()); + updateTempProfileProperty(Profile::ColorSchemeName, colors->name()); previewColorScheme(selected.first()); updateTransparencyWarning(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -250,7 +250,8 @@ _pluggedController = controller; _pluggedController->view()->installEventFilter(this); - setBlur(ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(_pluggedController->session()))); + auto profile = SessionManager::instance()->sessionProfile(_pluggedController->session()); + setBlur(profile->colorScheme()->blur()); // listen for title changes from the current session connect(controller, &Konsole::SessionController::titleChanged, this, diff --git a/src/Part.cpp b/src/Part.cpp --- a/src/Part.cpp +++ b/src/Part.cpp @@ -376,7 +376,8 @@ bool Part::isBlurEnabled() { - return ViewManager::profileHasBlurEnabled(SessionManager::instance()->sessionProfile(activeSession())); + auto profile = SessionManager::instance()->sessionProfile(activeSession()); + return profile->colorScheme()->blur(); } void Part::sessionStateChanged(int state) diff --git a/src/Profile.h b/src/Profile.h --- a/src/Profile.h +++ b/src/Profile.h @@ -31,6 +31,7 @@ // Konsole #include "konsoleprivate_export.h" +#include "ColorScheme.h" namespace Konsole { class ProfileGroup; @@ -120,7 +121,7 @@ * displays using this profile. * Color schemes are managed by the ColorSchemeManager class. */ - ColorScheme, + ColorSchemeName, /** (QString) The name of the key bindings. * Key bindings are managed by the KeyboardTranslatorManager class. */ @@ -446,9 +447,9 @@ } /** Convenience method for property(Profile::ColorScheme) */ - QString colorScheme() const + QString colorSchemeName() const { - return property(Profile::ColorScheme); + return property(Profile::ColorSchemeName); } /** Convenience method for property(Profile::Environment) */ @@ -606,6 +607,8 @@ return property(Profile::MenuIndex); } + ColorScheme const* colorScheme() const; + int menuIndexAsInt() const; /** Return a list of all properties names and their type @@ -653,6 +656,7 @@ QVariant::Type type; }; static const PropertyInfo DefaultPropertyNames[]; + ColorScheme const *_colorScheme; }; inline bool Profile::canInheritProperty(Property p) diff --git a/src/Profile.cpp b/src/Profile.cpp --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -32,6 +32,7 @@ // Konsole #include "Enumeration.h" +#include "ColorSchemeManager.h" using namespace Konsole; @@ -76,8 +77,8 @@ // Appearance , { Font , "Font" , APPEARANCE_GROUP , QVariant::Font } - , { ColorScheme , "ColorScheme" , APPEARANCE_GROUP , QVariant::String } - , { ColorScheme , "colors" , nullptr , QVariant::String } + , { ColorSchemeName , "ColorScheme" , APPEARANCE_GROUP , QVariant::String } + , { ColorSchemeName , "colors" , nullptr , QVariant::String } , { AntiAliasFonts, "AntiAliasFonts" , APPEARANCE_GROUP , QVariant::Bool } , { BoldIntense, "BoldIntense", APPEARANCE_GROUP, QVariant::Bool } , { UseFontLineCharacters, "UseFontLineChararacters", APPEARANCE_GROUP, QVariant::Bool } @@ -177,7 +178,7 @@ setProperty(AlternateScrolling, true); setProperty(KeyBindings, QStringLiteral("default")); - setProperty(ColorScheme, QStringLiteral("Linux")); //use DarkPastels when is start support blue ncurses UI properly + setProperty(ColorSchemeName, QStringLiteral("Linux")); //use DarkPastels when is start support blue ncurses UI properly setProperty(Font, QFontDatabase::systemFont(QFontDatabase::FixedFont)); setProperty(HistoryMode, Enum::FixedSizeHistory); @@ -278,6 +279,11 @@ void Profile::setProperty(Property p, const QVariant& value) { _propertyValues.insert(p, value); + + // Not the best place but we have just one set method. + if (p == ColorSchemeName) { + _colorScheme = ColorSchemeManager::instance()->findColorScheme(value.toString()); + } } bool Profile::isPropertySet(Property p) const { @@ -326,6 +332,10 @@ return info; } +ColorScheme const *Profile::colorScheme() const { + return _colorScheme; +} + QHash ProfileCommandParser::parse(const QString& input) { QHash changes; @@ -379,6 +389,7 @@ properties++; } } + void ProfileGroup::setProperty(Property p, const QVariant& value) { if (_profiles.count() > 1 && !canInheritProperty(p)) { diff --git a/src/ViewManager.h b/src/ViewManager.h --- a/src/ViewManager.h +++ b/src/ViewManager.h @@ -187,11 +187,6 @@ return _sessionMap.values(); } - /** - * Returns whether the @p profile has the blur setting enabled - */ - static bool profileHasBlurEnabled(const Profile::Ptr profile); - Q_SIGNALS: /** Emitted when the last view is removed from the view manager */ void empty(); diff --git a/src/ViewManager.cpp b/src/ViewManager.cpp --- a/src/ViewManager.cpp +++ b/src/ViewManager.cpp @@ -583,7 +583,7 @@ session->addView(display); // tell the session whether it has a light or dark background - session->setDarkBackground(colorSchemeForProfile(profile)->hasDarkBackground()); + session->setDarkBackground(profile->colorScheme()->hasDarkBackground()); if (container == _viewSplitter->activeContainer()) { container->setCurrentWidget(display); @@ -761,22 +761,6 @@ return display; } -const ColorScheme *ViewManager::colorSchemeForProfile(const Profile::Ptr profile) -{ - const ColorScheme *colorScheme = ColorSchemeManager::instance()-> - findColorScheme(profile->colorScheme()); - if (colorScheme == nullptr) { - colorScheme = ColorSchemeManager::instance()->defaultColorScheme(); - } - Q_ASSERT(colorScheme); - - return colorScheme; -} - -bool ViewManager::profileHasBlurEnabled(const Profile::Ptr profile) -{ - return colorSchemeForProfile(profile)->blur(); -} void ViewManager::applyProfileToView(TerminalDisplay *view, const Profile::Ptr profile) { @@ -786,7 +770,7 @@ // load color scheme ColorEntry table[TABLE_COLORS]; - const ColorScheme *colorScheme = colorSchemeForProfile(profile); + const ColorScheme *colorScheme = profile->colorScheme(); colorScheme->getColorTable(table, view->randomSeed()); view->setColorTable(table); view->setOpacity(colorScheme->opacity()); diff --git a/src/autotests/ProfileTest.cpp b/src/autotests/ProfileTest.cpp --- a/src/autotests/ProfileTest.cpp +++ b/src/autotests/ProfileTest.cpp @@ -62,7 +62,7 @@ QVERIFY(child->isPropertySet(Profile::StartInCurrentSessionDir)); QVERIFY(!child->isPropertySet(Profile::Name)); QVERIFY(!child->isPropertySet(Profile::AntiAliasFonts)); - QVERIFY(!child->isPropertySet(Profile::ColorScheme)); + QVERIFY(!child->isPropertySet(Profile::ColorSchemeName)); // read non-inheritable properties QCOMPARE(parent->property(Profile::Name), QStringLiteral("Parent")); @@ -85,7 +85,7 @@ // create source profile and parent Profile::Ptr parent(new Profile); parent->setProperty(Profile::Command, QStringLiteral("ps")); - parent->setProperty(Profile::ColorScheme, QStringLiteral("BlackOnWhite")); + parent->setProperty(Profile::ColorSchemeName, QStringLiteral("BlackOnWhite")); Profile::Ptr source(new Profile(parent)); source->setProperty(Profile::AntiAliasFonts, false); @@ -99,7 +99,7 @@ // same value as source parent targetParent->setProperty(Profile::Command, QStringLiteral("ps")); // different value from source parent - targetParent->setProperty(Profile::ColorScheme, QStringLiteral("BlackOnGrey")); + targetParent->setProperty(Profile::ColorSchemeName, QStringLiteral("BlackOnGrey")); Profile::Ptr target(new Profile(parent)); // clone source profile, setting only properties that differ @@ -123,8 +123,8 @@ QVERIFY(!target->isPropertySet(Profile::Command)); // check that ColorScheme property is cloned because the inherited values // from the source parent and target parent differ - QCOMPARE(source->property(Profile::ColorScheme), - target->property(Profile::ColorScheme)); + QCOMPARE(source->property(Profile::ColorSchemeName), + target->property(Profile::ColorSchemeName)); } void ProfileTest::testProfileGroup()