From 97f14706ef360e7385bef734933ea19d1a2e507a Mon Sep 17 00:00:00 2001 From: 0xd34df00d <0xd34df00d@gmail.com> Date: Wed, 21 May 2014 00:08:36 +0400 Subject: [PATCH] Load arbitrary schemes by path via setColorScheme(). --- lib/qtermwidget.cpp | 25 ++++++++++++++++++++++--- lib/qtermwidget.h | 6 +++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/qtermwidget.cpp b/lib/qtermwidget.cpp index b5056ae..e22c477 100644 --- a/lib/qtermwidget.cpp +++ b/lib/qtermwidget.cpp @@ -360,12 +360,31 @@ void QTermWidget::setTextCodec(QTextCodec *codec) m_impl->m_session->setCodec(codec); } -void QTermWidget::setColorScheme(const QString & name) +void QTermWidget::setColorScheme(const QString& origName) { - const ColorScheme *cs; + const ColorScheme *cs = 0; + + const bool isFile = QFile::exists(origName); + const QString& name = isFile ? + QFileInfo(origName).baseName() : + origName; + // avoid legacy (int) solution if (!availableColorSchemes().contains(name)) - cs = ColorSchemeManager::instance()->defaultColorScheme(); + { + if (isFile) + { + if (ColorSchemeManager::instance()->loadCustomColorScheme(origName)) + cs = ColorSchemeManager::instance()->findColorScheme(name); + else + qWarning () << Q_FUNC_INFO + << "cannot load color scheme from" + << origName; + } + + if (!cs) + cs = ColorSchemeManager::instance()->defaultColorScheme(); + } else cs = ColorSchemeManager::instance()->findColorScheme(name); diff --git a/lib/qtermwidget.h b/lib/qtermwidget.h index c3970e1..fd957db 100644 --- a/lib/qtermwidget.h +++ b/lib/qtermwidget.h @@ -84,7 +84,11 @@ public: //Text codec, default is UTF-8 void setTextCodec(QTextCodec * codec); - //Color scheme, default is white on black + /** @brief Sets the color scheme, default is white on black + * + * @param[in] name The name of the color scheme, either returned from + * availableColorSchemes() or a full path to a color scheme. + */ void setColorScheme(const QString & name); static QStringList availableColorSchemes();