📄 krcolorcache.cpp
字号:
/*************************************************************************** krcolorcache.cpp -------------------copyright : (C) 2000-2002 by Shie Erlich & Rafi Yanaie-mail : krusader@users.sourceforge.netweb site : http://krusader.sourceforge.net---------------------------------------------------------------------------Description***************************************************************************Adb dD d8888b. db db .d8888. .d8b. d8888b. d88888b d8888b.88 ,8P' 88 `8D 88 88 88' YP d8' `8b 88 `8D 88' 88 `8D88,8P 88oobY' 88 88 `8bo. 88ooo88 88 88 88ooooo 88oobY'88`8b 88`8b 88 88 `Y8b. 88~~~88 88 88 88~~~~~ 88`8b88 `88. 88 `88. 88b d88 db 8D 88 88 88 .8D 88. 88 `88.YP YD 88 YD ~Y8888P' `8888Y' YP YP Y8888D' Y88888P 88 YD S o u r c e F i l e**************************************************************************** ** 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. ** ****************************************************************************/#include "krcolorcache.h"#include "../krusader.h"#include "../defaults.h"#include <kglobalsettings.h> #include <qfile.h> // Macro: set target = col, if col is valid#define SETCOLOR(target, col) { if (col.isValid()) target = col; }/*Static class, which lists all allowed keywords for a quick access. Just call a method to initialize it. */class KrColorSettingNames{ static QMap<QString, bool> s_colorNames; static QMap<QString, bool> s_numNames; static QMap<QString, bool> s_boolNames; static void initialize();public: static QValueList<QString> getColorNames(); static bool isColorNameValid(const QString & settingName); static QValueList<QString> getNumNames(); static bool isNumNameValid(const QString & settingName); static QValueList<QString> getBoolNames(); static bool isBoolNameValid(const QString & settingName);} krColorSettingNames;QMap<QString, bool> KrColorSettingNames::s_colorNames;QMap<QString, bool> KrColorSettingNames::s_numNames;QMap<QString, bool> KrColorSettingNames::s_boolNames;void KrColorSettingNames::initialize(){ if (!s_colorNames.empty()) return; s_colorNames["Foreground"] = true; s_colorNames["Inactive Foreground"] = true; s_colorNames["Directory Foreground"] = true; s_colorNames["Inactive Directory Foreground"] = true; s_colorNames["Executable Foreground"] = true; s_colorNames["Inactive Executable Foreground"] = true; s_colorNames["Symlink Foreground"] = true; s_colorNames["Inactive Symlink Foreground"] = true; s_colorNames["Invalid Symlink Foreground"] = true; s_colorNames["Inactive Invalid Symlink Foreground"] = true; s_colorNames["Marked Foreground"] = true; s_colorNames["Inactive Marked Foreground"] = true; s_colorNames["Marked Background"] = true; s_colorNames["Inactive Marked Background"] = true; s_colorNames["Current Foreground"] = true; s_colorNames["Inactive Current Foreground"] = true; s_colorNames["Current Background"] = true; s_colorNames["Inactive Current Background"] = true; s_colorNames["Marked Current Foreground"] = true; s_colorNames["Inactive Marked Current Foreground"] = true; s_colorNames["Alternate Background"] = true; s_colorNames["Inactive Alternate Background"] = true; s_colorNames["Background"] = true; s_colorNames["Inactive Background"] = true; s_colorNames["Alternate Marked Background"] = true; s_colorNames["Inactive Alternate Marked Background"] = true; s_colorNames["Dim Target Color"] = true; s_numNames["Dim Factor"] = true; s_boolNames["KDE Default"] = true; s_boolNames["Enable Alternate Background"] = true; s_boolNames["Show Current Item Always"] = true; s_boolNames["Dim Inactive Colors"] = true;}QValueList<QString> KrColorSettingNames::getColorNames(){ initialize(); return s_colorNames.keys();}bool KrColorSettingNames::isColorNameValid(const QString & settingName){ initialize(); return s_colorNames.contains(settingName);}QValueList<QString> KrColorSettingNames::getNumNames(){ initialize(); return s_numNames.keys();}bool KrColorSettingNames::isNumNameValid(const QString & settingName){ initialize(); return s_numNames.contains(settingName);}QValueList<QString> KrColorSettingNames::getBoolNames(){ initialize(); return s_boolNames.keys();}bool KrColorSettingNames::isBoolNameValid(const QString & settingName){ initialize(); return s_boolNames.contains(settingName);}/*KrColorSettings implementation. Contains all properties in QMaps. loadFromConfig initializes them from krConfig.*/class KrColorSettingsImpl{ friend class KrColorSettings; QMap<QString, QString> m_colorTextValues; QMap<QString, QColor> m_colorValues; QMap<QString, int> m_numValues; QMap<QString, bool> m_boolValues; void loadFromConfig();};void KrColorSettingsImpl::loadFromConfig(){ krConfig->setGroup("Colors"); QValueList<QString> names = KrColorSettingNames::getColorNames(); for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) { m_colorTextValues[*it] = krConfig->readEntry(*it, ""); m_colorValues[*it] = krConfig->readColorEntry(*it); } names = KrColorSettingNames::getNumNames(); for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) { if (krConfig->readEntry(*it) != QString::null) m_numValues[*it] = krConfig->readNumEntry(*it); } names = KrColorSettingNames::getBoolNames(); for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) { if (krConfig->readEntry(*it) != QString::null) m_boolValues[*it] = krConfig->readBoolEntry(*it); }}KrColorSettings::KrColorSettings(){ m_impl = new KrColorSettingsImpl(); m_impl->loadFromConfig();}KrColorSettings::KrColorSettings(const KrColorSettings & src){ m_impl = new KrColorSettingsImpl(); operator =(src);}KrColorSettings::~KrColorSettings(){ delete m_impl;}const KrColorSettings & KrColorSettings::operator= (const KrColorSettings & src){ if (this == & src) return * this; QValueList<QString> names = KrColorSettingNames::getColorNames(); for ( QStringList::Iterator it = names.begin(); it != names.end(); ++it ) { m_impl->m_colorTextValues[*it] = src.m_impl->m_colorTextValues[*it]; m_impl->m_colorValues[*it] = src.m_impl->m_colorValues[*it]; } for ( QMap<QString, int>::Iterator it = src.m_impl->m_numValues.begin(); it != src.m_impl->m_numValues.end(); ++it ) { m_impl->m_numValues[it.key()] = it.data(); } for ( QMap<QString, bool>::Iterator it = src.m_impl->m_boolValues.begin(); it != src.m_impl->m_boolValues.end(); ++it ) { m_impl->m_boolValues[it.key()] = it.data(); } return * this;}QValueList<QString> KrColorSettings::getColorNames(){ return KrColorSettingNames::getColorNames();}bool KrColorSettings::isColorNameValid(const QString & settingName){ return KrColorSettingNames::isColorNameValid(settingName);}bool KrColorSettings::setColorValue(const QString & settingName, const QColor & color){ if (!isColorNameValid(settingName)) { krOut << "Invalid color setting name: " << settingName << endl; return false; } m_impl->m_colorValues[settingName] = color; return true;}QColor KrColorSettings::getColorValue(const QString & settingName) const{ if (!isColorNameValid(settingName)) { krOut << "Invalid color setting name: " << settingName << endl; return QColor(); } return m_impl->m_colorValues[settingName];}bool KrColorSettings::setColorTextValue(const QString & settingName, const QString & colorText){ if (!isColorNameValid(settingName)) { krOut << "Invalid color setting name: " << settingName << endl; return false; } m_impl->m_colorTextValues[settingName] = colorText; return true;}QString KrColorSettings::getColorTextValue(const QString & settingName) const{ if (!isColorNameValid(settingName)) { krOut << "Invalid color setting name: " << settingName << endl; return QString(); } return m_impl->m_colorTextValues[settingName];}QValueList<QString> KrColorSettings::getNumNames(){ return KrColorSettingNames::getNumNames();}bool KrColorSettings::isNumNameValid(const QString & settingName){ return KrColorSettingNames::isNumNameValid(settingName);}bool KrColorSettings::setNumValue(const QString & settingName, int value){ if (!isNumNameValid(settingName)) { krOut << "Invalid number setting name: " << settingName << endl; return false; } m_impl->m_numValues[settingName] = value; return true;}int KrColorSettings::getNumValue(const QString & settingName, int defaultValue) const{ if (!isNumNameValid(settingName)) { krOut << "Invalid number setting name: " << settingName << endl; return 0; } if (!m_impl->m_numValues.contains(settingName)) return defaultValue; return m_impl->m_numValues[settingName];}QValueList<QString> KrColorSettings::getBoolNames(){ return KrColorSettingNames::getBoolNames();}bool KrColorSettings::isBoolNameValid(const QString & settingName){ return KrColorSettingNames::isBoolNameValid(settingName);}bool KrColorSettings::setBoolValue(const QString & settingName, bool value){ if (!isBoolNameValid(settingName)) { krOut << "Invalid bool setting name: " << settingName << endl; return false; } m_impl->m_boolValues[settingName] = value; return true;}int KrColorSettings::getBoolValue(const QString & settingName, bool defaultValue) const{ if (!isBoolNameValid(settingName)) { krOut << "Invalid bool setting name: " << settingName << endl; return false; } if (!m_impl->m_boolValues.contains(settingName)) return defaultValue; return m_impl->m_boolValues[settingName];}KrColorItemType::KrColorItemType(){ m_fileType = File; m_alternateBackgroundColor = false; m_activePanel = false; m_currentItem = false; m_selectedItem = false;}KrColorItemType::KrColorItemType(FileType type, bool alternateBackgroundColor, bool activePanel, bool currentItem, bool selectedItem){ m_fileType = type; m_alternateBackgroundColor = alternateBackgroundColor; m_activePanel = activePanel; m_currentItem = currentItem; m_selectedItem = selectedItem;}KrColorItemType::KrColorItemType(const KrColorItemType & src){ operator= (src);}const KrColorItemType & KrColorItemType::operator= (const KrColorItemType & src){ if (this == & src) return * this; m_fileType = src.m_fileType; m_alternateBackgroundColor = src.m_alternateBackgroundColor; m_activePanel = src.m_activePanel; m_currentItem = src.m_currentItem; m_selectedItem = src.m_selectedItem; return * this;}/*KrColorCache implementation. Contains the KrColorSettings used for teh calculation and the cache for the results.getColors is the only method to call. All other are taken from the previous versions.*/class KrColorCacheImpl{ friend class KrColorCache; QMap<QString, QColorGroup> m_cachedColors;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -