Skip to content

Commit

Permalink
feat: adapt qtermwidget for Qt6.8
Browse files Browse the repository at this point in the history
log: as title
  • Loading branch information
LiHua000 committed Jan 23, 2025
1 parent 3ca7910 commit 22084c7
Show file tree
Hide file tree
Showing 20 changed files with 197 additions and 104 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ add_subdirectory(cppdap)
add_subdirectory(unioncode-qscintilla214)
if (QT_VERSION_MAJOR MATCHES 5)
add_subdirectory(unioncode-GitQlient)
add_subdirectory(unioncode-qtermwidget-0.14.1)
endif()
add_subdirectory(unioncode-qtermwidget-0.14.1)
add_subdirectory(unioncode-jsonrpccpp)
26 changes: 20 additions & 6 deletions 3rdparty/unioncode-qtermwidget-0.14.1/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QT_MINIMUM_VERSION "5.7.1")
set(LXQTBT_MINIMUM_VERSION "0.6.0")

find_package(Qt5Widgets "${QT_MINIMUM_VERSION}" REQUIRED)
find_package(Qt5LinguistTools "${QT_MINIMUM_VERSION}" REQUIRED)
#find_package(Qt5Widgets "${QT_MINIMUM_VERSION}" REQUIRED)
#find_package(Qt5LinguistTools "${QT_MINIMUM_VERSION}" REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR}LinguistTools REQUIRED)
if (${QT_VERSION_MAJOR} MATCHES 6)
find_package(Qt6Core5Compat REQUIRED)
endif()
find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED)

if(USE_UTF8PROC)
Expand Down Expand Up @@ -110,9 +115,15 @@ message(STATUS "Translations will be installed in: ${TRANSLATIONS_DIR}")

CHECK_FUNCTION_EXISTS(updwtmpx HAVE_UPDWTMPX)

qt5_wrap_cpp(MOCS ${HDRS})
qt5_wrap_ui(UI_SRCS ${UI})
set(PKG_CONFIG_REQ "Qt5Widgets")
if (${QT_VERSION_MAJOR} MATCHES 6)
qt6_wrap_cpp(MOCS ${HDRS})
qt6_wrap_ui(UI_SRCS ${UI})
else()
qt5_wrap_cpp(MOCS ${HDRS})
qt5_wrap_ui(UI_SRCS ${UI})
endif()

set(PKG_CONFIG_REQ "Qt${QT_VERSION_MAJOR}Widgets")

lxqt_translate_ts(QTERMWIDGET_QM
TRANSLATION_DIR "lib/translations"
Expand All @@ -127,7 +138,10 @@ lxqt_translate_ts(QTERMWIDGET_QM
)

add_library(${QTERMWIDGET_LIBRARY_NAME} SHARED ${SRCS} ${MOCS} ${UI_SRCS} ${QTERMWIDGET_QM})
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt5::Widgets)
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt${QT_VERSION_MAJOR}::Widgets)
if (${QT_VERSION_MAJOR} MATCHES 6)
target_link_libraries(${QTERMWIDGET_LIBRARY_NAME} Qt6::Core5Compat)
endif()

if(APPLE)
target_compile_definitions(${QTERMWIDGET_LIBRARY_NAME}
Expand Down
8 changes: 6 additions & 2 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/Character.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,12 @@ class Character
union
{
/** The unicode character value for this character. */
wchar_t character;
/**
#if QT_VERSION >= 0x060000
char16_t character;
#else
wchar_t character;
#endif
/**
* Experimental addition which allows a single Character instance to contain more than
* one unicode character.
*
Expand Down
20 changes: 9 additions & 11 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/ColorScheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <QSettings>
#include <QDir>
#include <QRegularExpression>

#include <QRandomGenerator>

// KDE
//#include <KColorScheme>
Expand Down Expand Up @@ -177,11 +177,9 @@ void ColorScheme::setColorTableEntry(int index , const ColorEntry& entry)
}
ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const
{
Q_UNUSED(randomSeed);
Q_ASSERT( index >= 0 && index < TABLE_COLORS );

if ( randomSeed != 0 )
qsrand(randomSeed);

ColorEntry entry = colorTable()[index];

if ( randomSeed != 0 &&
Expand All @@ -191,9 +189,9 @@ ColorEntry ColorScheme::colorEntry(int index , uint randomSeed) const
const RandomizationRange& range = _randomTable[index];


int hueDifference = range.hue ? (qrand() % range.hue) - range.hue/2 : 0;
int saturationDifference = range.saturation ? (qrand() % range.saturation) - range.saturation/2 : 0;
int valueDifference = range.value ? (qrand() % range.value) - range.value/2 : 0;
int hueDifference = range.hue ? (QRandomGenerator::global()->bounded(range.hue)) - range.hue/2 : 0;
int saturationDifference = range.saturation ? (QRandomGenerator::global()->bounded(range.saturation)) - range.saturation/2 : 0;
int valueDifference = range.value ? (QRandomGenerator::global()->bounded(range.value)) - range.value/2 : 0;

QColor& color = entry.color;

Expand Down Expand Up @@ -367,9 +365,9 @@ void ColorScheme::readColorEntry(QSettings * s , int index)
if (hexColorPattern.match(colorStr).hasMatch())
{
// Parsing is always ok as already matched by the regexp
r = colorStr.midRef(1, 2).toInt(nullptr, 16);
g = colorStr.midRef(3, 2).toInt(nullptr, 16);
b = colorStr.midRef(5, 2).toInt(nullptr, 16);
r = colorStr.mid(1, 2).toInt(nullptr, 16);
g = colorStr.mid(3, 2).toInt(nullptr, 16);
b = colorStr.mid(5, 2).toInt(nullptr, 16);
ok = true;
}
}
Expand Down Expand Up @@ -502,7 +500,7 @@ ColorScheme* KDE3ColorSchemeReader::read()

ColorScheme* scheme = new ColorScheme();

QRegExp comment(QLatin1String("#.*$"));
QRegularExpression comment(QLatin1String("#.*$"));
while ( !_device->atEnd() )
{
QString line(QString::fromUtf8(_device->readLine()));
Expand Down
7 changes: 4 additions & 3 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/HistorySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "Emulation.h"
#include "HistorySearch.h"

HistorySearch::HistorySearch(EmulationPtr emulation, QRegExp regExp,
HistorySearch::HistorySearch(EmulationPtr emulation, QRegularExpression regExp,
bool forwards, int startColumn, int startLine,
QObject* parent) :
QObject(parent),
Expand All @@ -41,7 +41,7 @@ HistorySearch::~HistorySearch() {
void HistorySearch::search() {
bool found = false;

if (! m_regExp.isEmpty())
if( ! m_regExp.isValid())
{
if (m_forwards) {
found = search(m_startColumn, m_startLine, -1, m_emulation->lineCount()) || search(0, 0, m_startColumn, m_startLine);
Expand Down Expand Up @@ -119,7 +119,8 @@ bool HistorySearch::search(int startColumn, int startLine, int endColumn, int en

if (matchStart > -1)
{
int matchEnd = matchStart + m_regExp.matchedLength() - 1;
auto match = m_regExp.match(string);
int matchEnd = matchStart + match.capturedLength() - 1;
qDebug() << "Found in string from" << matchStart << "to" << matchEnd;

// Translate startPos and endPos to startColum, startLine, endColumn and endLine in history.
Expand Down
5 changes: 3 additions & 2 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/HistorySearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <QObject>
#include <QPointer>
#include <QMap>
#include <QRegularExpression>

#include <Session.h>
#include <ScreenWindow.h>
Expand All @@ -38,7 +39,7 @@ class HistorySearch : public QObject
Q_OBJECT

public:
explicit HistorySearch(EmulationPtr emulation, QRegExp regExp, bool forwards,
explicit HistorySearch(EmulationPtr emulation, QRegularExpression regExp, bool forwards,
int startColumn, int startLine, QObject* parent);

~HistorySearch();
Expand All @@ -55,7 +56,7 @@ class HistorySearch : public QObject


EmulationPtr m_emulation;
QRegExp m_regExp;
QRegularExpression m_regExp;
bool m_forwards;
int m_startColumn;
int m_startLine;
Expand Down
27 changes: 15 additions & 12 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/KeyboardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QKeySequence>
#include <QDir>
#include <QtDebug>
#include <QRegularExpression>

#include "tools.h"

Expand Down Expand Up @@ -532,41 +533,42 @@ QList<KeyboardTranslatorReader::Token> KeyboardTranslatorReader::tokenize(const
text = text.simplified();

// title line: keyboard "title"
static QRegExp title(QLatin1String("keyboard\\s+\"(.*)\""));
QRegularExpression title(QLatin1String("keyboard\\s+\"(.*)\""));
// key line: key KeySequence : "output"
// key line: key KeySequence : command
static QRegExp key(QLatin1String("key\\s+([\\w\\+\\s\\-\\*\\.]+)\\s*:\\s*(\"(.*)\"|\\w+)"));
QRegularExpression key(QLatin1String("key\\s+([\\w\\+\\s\\-\\*\\.]+)\\s*:\\s*(\"(.*)\"|\\w+)"));

QList<Token> list;
if ( text.isEmpty() )
{
return list;
}

if ( title.exactMatch(text) )
if ( title.match(text).hasMatch() )
{
auto match = title.match(text);
Token titleToken = { Token::TitleKeyword , QString() };
Token textToken = { Token::TitleText , title.capturedTexts().at(1) };

Token textToken = { Token::TitleText , match.capturedTexts().at(1) };
list << titleToken << textToken;
}
else if ( key.exactMatch(text) )
else if ( key.match(text).hasMatch() )
{
auto match = key.match(text);
Token keyToken = { Token::KeyKeyword , QString() };
Token sequenceToken = { Token::KeySequence , key.capturedTexts().value(1).remove(QLatin1Char(' ')) };
Token sequenceToken = { Token::KeySequence , match.capturedTexts().value(1).remove(QLatin1Char(' ')) };

list << keyToken << sequenceToken;

if ( key.capturedTexts().at(3).isEmpty() )
if ( match.capturedTexts().size() < 4 || match.capturedTexts().at(3).isEmpty() )
{
// capturedTexts()[2] is a command
Token commandToken = { Token::Command , key.capturedTexts().at(2) };
Token commandToken = { Token::Command , match.capturedTexts().at(2) };
list << commandToken;
}
else
{
// capturedTexts()[3] is the output string
Token outputToken = { Token::OutputText , key.capturedTexts().at(3) };
Token outputToken = { Token::OutputText , match.capturedTexts().at(3) };
list << outputToken;
}
}
Expand Down Expand Up @@ -664,7 +666,8 @@ QByteArray KeyboardTranslator::Entry::escapedText(bool expandWildCards,Qt::Keybo

if ( replacement == 'x' )
{
result.replace(i,1,"\\x"+QByteArray(1,ch).toHex());
QByteArray data = "\\x"+QByteArray(1,ch).toHex();
result.replace(i,1,data);
} else if ( replacement != 0 )
{
result.remove(i,1);
Expand All @@ -682,7 +685,7 @@ QByteArray KeyboardTranslator::Entry::unescape(const QByteArray& input) const
for ( int i = 0 ; i < result.count()-1 ; i++ )
{

QByteRef ch = result[i];
auto ch = result[i];
if ( ch == '\\' )
{
char replacement[2] = {0,0};
Expand Down
9 changes: 6 additions & 3 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/Pty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,22 +317,25 @@ int Pty::foregroundProcessGroup() const
return 0;
}

// TODO: we need to handle this
#if QT_VERSION < 0x060000
void Pty::setupChildProcess()
{
KPtyProcess::setupChildProcess();

// reset all signal handlers
// this ensures that terminal applications respond to
// signals generated via key sequences such as Ctrl+C
// (which sends SIGINT)
struct sigaction action;
sigset_t sigset;
sigemptyset(&action.sa_mask);
sigemptyset(&sigset);
action.sa_handler = SIG_DFL;
action.sa_flags = 0;
for (int signal=1;signal < NSIG; signal++) {
sigaction(signal,&action,0L);
sigaction(signal,&action,nullptr);
sigaddset(&sigset, signal);
}
sigprocmask(SIG_UNBLOCK, &sigset, NULL);
sigprocmask(SIG_UNBLOCK, &sigset, nullptr);
}
#endif
6 changes: 4 additions & 2 deletions 3rdparty/unioncode-qtermwidget-0.14.1/lib/Pty.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ Q_OBJECT
*/
void receivedData(const char* buffer, int length);

protected:
void setupChildProcess();
#if QT_VERSION < 0x060000
protected:
void setupChildProcess() override;
#endif

private slots:
// called when data is received from the terminal process
Expand Down
6 changes: 5 additions & 1 deletion 3rdparty/unioncode-qtermwidget-0.14.1/lib/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@

// Qt
#include <QApplication>
#include <QByteRef>
#include <QDir>
#include <QFile>
#include <QRegExp>
#include <QStringList>
#include <QFile>
#include <QtDebug>
#include <QRegularExpression>

#include "Pty.h"
//#include "kptyprocess.h"
Expand Down Expand Up @@ -381,7 +381,11 @@ void Session::setUserTitle( int what, const QString & caption )

if (what == 31) {
QString cwd=caption;
#if QT_VERSION >= 0x060000
cwd=cwd.replace( QRegularExpression(QLatin1String("^~")), QDir::homePath() );
#else
cwd=cwd.replace( QRegExp(QLatin1String("^~")), QDir::homePath() );
#endif
emit openUrlRequest(cwd);
}

Expand Down
Loading

0 comments on commit 22084c7

Please sign in to comment.