Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 扩展主题,修改原有主题逻辑 #300

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
490 changes: 221 additions & 269 deletions 3rdparty/terminalwidget/lib/ColorScheme.cpp

Large diffs are not rendered by default.

87 changes: 43 additions & 44 deletions 3rdparty/terminalwidget/lib/ColorScheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
class QIODevice;
//class KConfig;

namespace Konsole
{
namespace Konsole {

/**
* Represents a color scheme for a terminal display.
Expand All @@ -53,30 +52,30 @@ class ColorScheme
* for Konsole.
*/
ColorScheme();
ColorScheme(const ColorScheme& other);
ColorScheme(const ColorScheme &other);
~ColorScheme();

/** Sets the descriptive name of the color scheme. */
void setDescription(const QString& description);
void setDescription(const QString &description);
/** Returns the descriptive name of the color scheme. */
QString description() const;

/** Sets the name of the color scheme */
void setName(const QString& name);
void setName(const QString &name);
/** Returns the name of the color scheme */
QString name() const;

#if 0
// Implemented upstream - in user apps
/** Reads the color scheme from the specified configuration source */
void read(KConfig& config);
void read(KConfig &config);
/** Writes the color scheme to the specified configuration source */
void write(KConfig& config) const;
void write(KConfig &config) const;
#endif
void read(const QString & filename);
void read(const QString &filename);

/** Sets a single entry within the color palette. */
void setColorTableEntry(int index , const ColorEntry& entry);
void setColorTableEntry(int index, const ColorEntry &entry);

/**
* Copies the color entries which form the palette for this color scheme
Expand All @@ -87,14 +86,14 @@ class ColorScheme
* @param randomSeed Color schemes may allow certain colors in their
* palette to be randomized. The seed is used to pick the random color.
*/
void getColorTable(ColorEntry* table, uint randomSeed = 0) const;
void getColorTable(ColorEntry *table, uint randomSeed = 0) const;

/**
* Retrieves a single color entry from the table.
*
* See getColorTable()
*/
ColorEntry colorEntry(int index , uint randomSeed = 0) const;
ColorEntry colorEntry(int index, uint randomSeed = 0) const;

/**
* Convenience method. Returns the
Expand Down Expand Up @@ -152,11 +151,11 @@ class ColorScheme
class RandomizationRange
{
public:
RandomizationRange() : hue(0) , saturation(0) , value(0) {}
RandomizationRange() : hue(0), saturation(0), value(0) {}

bool isNull() const
{
return ( hue == 0 && saturation == 0 && value == 0 );
return (hue == 0 && saturation == 0 && value == 0);
}

quint16 hue;
Expand All @@ -166,38 +165,38 @@ class ColorScheme

// returns the active color table. if none has been set specifically,
// this is the default color table.
const ColorEntry* colorTable() const;
const ColorEntry *colorTable() const;

#if 0
// implemented upstream - user apps
// reads a single colour entry from a KConfig source
// and sets the palette entry at 'index' to the entry read.
void readColorEntry(KConfig& config , int index);
void readColorEntry(KConfig &config, int index);
// writes a single colour entry to a KConfig source
void writeColorEntry(KConfig& config , const QString& colorName, const ColorEntry& entry,const RandomizationRange& range) const;
void writeColorEntry(KConfig &config, const QString &colorName, const ColorEntry &entry, const RandomizationRange &range) const;
#endif
void readColorEntry(QSettings *s, int index);

// sets the amount of randomization allowed for a particular color
// in the palette. creates the randomization table if
// it does not already exist
void setRandomizationRange( int index , quint16 hue , quint8 saturation , quint8 value );
void setRandomizationRange(int index, quint16 hue, quint8 saturation, quint8 value);

QString _description;
QString _name;
qreal _opacity;
ColorEntry* _table; // pointer to custom color table or 0 if the default
// color scheme is being used
ColorEntry *_table; // pointer to custom color table or 0 if the default
// color scheme is being used


static const quint16 MAX_HUE = 340;

RandomizationRange* _randomTable; // pointer to randomization table or 0
// if no colors in the color scheme support
// randomization
RandomizationRange *_randomTable; // pointer to randomization table or 0
// if no colors in the color scheme support
// randomization

static const char* const colorNames[TABLE_COLORS];
static const char* const translatedColorNames[TABLE_COLORS];
static const char *const colorNames[TABLE_COLORS];
static const char *const translatedColorNames[TABLE_COLORS];

static const ColorEntry defaultTable[]; // table of default color entries
};
Expand Down Expand Up @@ -232,7 +231,7 @@ class KDE3ColorSchemeReader
* Constructs a new reader which reads from the specified device.
* The device should be open in read-only mode.
*/
explicit KDE3ColorSchemeReader( QIODevice* device );
explicit KDE3ColorSchemeReader(QIODevice *device);

/**
* Reads and parses the contents of the .schema file from the input
Expand All @@ -241,15 +240,15 @@ class KDE3ColorSchemeReader
* Returns a null pointer if an error occurs whilst parsing
* the contents of the file.
*/
ColorScheme* read();
ColorScheme *read();

private:
// reads a line from the file specifying a colour palette entry
// format is: color [index] [red] [green] [blue] [transparent] [bold]
bool readColorLine(const QString& line , ColorScheme* scheme);
bool readTitleLine(const QString& line , ColorScheme* scheme);
bool readColorLine(const QString &line, ColorScheme *scheme);
bool readTitleLine(const QString &line, ColorScheme *scheme);

QIODevice* _device;
QIODevice *_device;
};

/**
Expand All @@ -276,7 +275,7 @@ class ColorSchemeManager
/**
* Returns the default color scheme for Konsole
*/
const ColorScheme* defaultColorScheme() const;
const ColorScheme *defaultColorScheme() const;

/**
* Returns the color scheme with the given name or 0 if no
Expand All @@ -286,7 +285,7 @@ class ColorSchemeManager
* The first time that a color scheme with a particular name is
* requested, the configuration information is loaded from disk.
*/
const ColorScheme* findColorScheme(const QString& name);
const ColorScheme *findColorScheme(const QString &name);

#if 0
/**
Expand All @@ -295,15 +294,15 @@ class ColorSchemeManager
*
* TODO - Ensure the old color scheme gets deleted
*/
void addColorScheme(ColorScheme* scheme);
void addColorScheme(ColorScheme *scheme);
#endif
/**
* Deletes a color scheme. Returns true on successful deletion or false otherwise.
*/
bool deleteColorScheme(const QString& name);
bool deleteColorScheme(const QString &name);

//重新加载主题
void realodColorScheme(const QString &origName);
void reloadColorScheme(const QString &origName);

/**
* Returns a list of the all the available color schemes.
Expand All @@ -312,10 +311,10 @@ class ColorSchemeManager
*
* Subsequent calls will be inexpensive.
*/
QList<const ColorScheme*> allColorSchemes();
QList<const ColorScheme *> allColorSchemes();

/** Returns the global color scheme manager instance. */
static ColorSchemeManager* instance();
static ColorSchemeManager *instance();

/** @brief Loads a custom color scheme under given \em path.
*
Expand All @@ -329,20 +328,20 @@ class ColorSchemeManager
* @param[in] path The path to KDE 4 .colorscheme or KDE 3 .schema.
* @return Whether the color scheme is loaded successfully.
*/
bool loadCustomColorScheme(const QString& path);
bool loadCustomColorScheme(const QString &path);

/**
* @brief Allows to add a custom location of color schemes.
*
* @param[in] custom_dir Custom location of color schemes (must end with /).
*/
void addCustomColorSchemeDir(const QString& custom_dir);
void addCustomColorSchemeDir(const QString &custom_dir);

private:
// loads a color scheme from a KDE 4+ .colorscheme file
bool loadColorScheme(const QString& path);
bool loadColorScheme(const QString &path);
// loads a color scheme from a KDE 3 .schema file
bool loadKDE3ColorScheme(const QString& path);
bool loadKDE3ColorScheme(const QString &path);
// returns a list of paths of color schemes in the KDE 4+ .colorscheme file format
QList<QString> listColorSchemes();
// returns a list of paths of color schemes in the .schema file format
Expand All @@ -351,10 +350,10 @@ class ColorSchemeManager
// loads all of the color schemes
void loadAllColorSchemes();
// finds the path of a color scheme
QString findColorSchemePath(const QString& name) const;
QString findColorSchemePath(const QString &name) const;

QHash<QString,const ColorScheme*> _colorSchemes;
QSet<ColorScheme*> _modifiedSchemes;
QHash<QString, const ColorScheme *> _colorSchemes;
QSet<ColorScheme *> _modifiedSchemes;

bool _haveLoadedAll;

Expand All @@ -363,6 +362,6 @@ class ColorSchemeManager

}

Q_DECLARE_METATYPE(const Konsole::ColorScheme*)
Q_DECLARE_METATYPE(const Konsole::ColorScheme *)

#endif //COLORSCHEME_H
19 changes: 7 additions & 12 deletions 3rdparty/terminalwidget/lib/qtermwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ void QTermWidget::setIsAllowScroll(bool isAllowScroll)
*******************************************************************************/
void QTermWidget::setNoHasSelect()
{
if(m_bHasSelect) {
if (m_bHasSelect) {
//清除搜索状态
m_lastBackwardsPosition = -1;
m_isLastForwards = false;
Expand Down Expand Up @@ -455,13 +455,6 @@ void QTermWidget::init(int startnow)
m_impl->m_terminalDisplay->filterChain()->addFilter(urlFilter);
m_impl->m_terminalDisplay->filterChain()->setSessionId(m_impl->m_session->sessionId());

// m_searchBar = new SearchBar(this);
// m_searchBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Maximum);
// connect(m_searchBar, SIGNAL(searchCriteriaChanged()), this, SLOT(find()));
// connect(m_searchBar, SIGNAL(findNext()), this, SLOT(findNext()));
// connect(m_searchBar, SIGNAL(findPrevious()), this, SLOT(findPrevious()));
// m_layout->addWidget(m_searchBar);
// m_searchBar->hide();

if (startnow && m_impl->m_session) {
m_impl->m_session->run();
Expand Down Expand Up @@ -626,7 +619,7 @@ void QTermWidget::setTerminalWordCharacters(const QString &wc)
3. @日期: 2020-12-01
4. @说明: 设置主题的配色方案,根据参数 needReloadTheme 判断是否需要重新加载
*******************************************************************************/
void QTermWidget::setColorScheme(const QString &origName, bool needReloadTheme)
int QTermWidget::setColorScheme(const QString &origName)
{
const ColorScheme *cs = nullptr;

Expand All @@ -646,19 +639,21 @@ void QTermWidget::setColorScheme(const QString &origName, bool needReloadTheme)
cs = ColorSchemeManager::instance()->defaultColorScheme();
}
} else {
if (name == "customTheme" && needReloadTheme) {
ColorSchemeManager::instance()->realodColorScheme(origName);
if (name == "customTheme") {
ColorSchemeManager::instance()->reloadColorScheme(origName);
}
cs = ColorSchemeManager::instance()->findColorScheme(name);
}

if (!cs) {
QMessageBox::information(this, tr("Color Scheme Error"), tr("Cannot load color scheme: %1").arg(name));
return;
return -1;
}
ColorEntry table[TABLE_COLORS];
cs->getColorTable(table);
m_impl->m_terminalDisplay->setColorTable(table);
const QColor &background_color = table[DEFAULT_BACK_COLOR].color;
return background_color.lightness();
}

QStringList QTermWidget::availableColorSchemes()
Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/terminalwidget/lib/qtermwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
* availableColorSchemes() or a full path to a color scheme.
*/
//设置主题的配色方案
void setColorScheme(const QString &name, bool needReloadTheme = false);
int setColorScheme(const QString &name);
static QStringList availableColorSchemes();
static void addCustomColorSchemeDir(const QString &custom_dir);

Expand Down Expand Up @@ -198,7 +198,7 @@ class TERMINALWIDGET_EXPORT QTermWidget : public QWidget
* @param preserveLineBreaks Specifies whether new line characters should
* be inserted into the returned text at the end of each terminal line.
*/
QString selectedText(const Screen::DecodingOptions options=Screen::PreserveLineBreaks);
QString selectedText(const Screen::DecodingOptions options = Screen::PreserveLineBreaks);

void setMonitorActivity(bool);
void setMonitorSilence(bool);
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ pkg_search_module(GOBJECT REQUIRED gobject-2.0)
pkg_check_modules(LIBSECRET REQUIRED libsecret-1)
pkg_check_modules(XCB_EWMH REQUIRED xcb-ewmh x11)


# Compile definitions for TerminalWidget
# So we can use QT_VERSION_CHECK
set(TERMINALWIDGET_VERSION_MAJOR "0")
Expand Down Expand Up @@ -167,6 +166,7 @@ set (DTNG_CPP_FILES
src/views/listview.cpp
src/views/customthemesettingdialog.cpp
src/views/themepreviewarea.cpp
src/views/switchthememenu.cpp
)

set (DTNG_HEADER_FILES
Expand Down Expand Up @@ -217,6 +217,7 @@ set (DTNG_HEADER_FILES
src/views/listview.h
src/views/customthemesettingdialog.h
src/views/themepreviewarea.h
src/views/switchthememenu.h
)

set (DTNG_QRC_FILES
Expand Down
2 changes: 1 addition & 1 deletion src/assets/other/default-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"key": "theme",
"hide": true,
"reset": false,
"default": "Linux"
"default": ""
},
{
"key": "expand_theme",
Expand Down
Loading
Loading