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

Update for Qt6 #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions fingerterm.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
QT = core gui qml quick

greaterThan(QT_MAJOR_VERSION,5) QT += core5compat

CONFIG += link_pkgconfig

enable-feedback {
Expand Down Expand Up @@ -92,7 +94,10 @@ desktopfile.files = $${TARGET}.desktop
TS_FILE = $$OUT_PWD/fingerterm.ts
EE_QM = $$OUT_PWD/fingerterm_eng_en.qm

ts.commands += lupdate $$PWD -ts $$TS_FILE
LUPDATE = $$[QT_INSTALL_BINS]/lupdate
LRELEASE = $$[QT_INSTALL_BINS]/lrelease

ts.commands += $${LUPDATE} $$PWD -ts $$TS_FILE
ts.CONFIG += no_check_exist
ts.output = $$TS_FILE
ts.input = .
Expand All @@ -102,7 +107,7 @@ ts_install.path = /usr/share/translations/source
ts_install.CONFIG += no_check_exist

# should add -markuntranslated "-" when proper translations are in place (or for testing)
engineering_english.commands += lrelease -idbased $$TS_FILE -qm $$EE_QM
engineering_english.commands += $${LRELEASE} -idbased $$TS_FILE -qm $$EE_QM
engineering_english.CONFIG += no_check_exist
engineering_english.depends = ts
engineering_english.input = $$TS_FILE
Expand Down
4 changes: 4 additions & 0 deletions keyloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ bool KeyLoader::loadLayoutInternal(QIODevice &from)
line.replace("\\x5D", "]");
line.replace("\\x5C", "\\");

#if QT_VERSION < 0x051500
QStringList parts = line.split(",", QString::KeepEmptyParts);
#else
QStringList parts = line.split(",", Qt::KeepEmptyParts);
#endif
if(parts.count()>=2) {
bool ok = true;
key.label = parts.at(0);
Expand Down
2 changes: 2 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int main(int argc, char *argv[])
app.installTranslator(engineeringEnglish.data());
app.installTranslator(translator.data());

#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QScreen* sc = app.primaryScreen();
if(sc){
QFlags<Qt::ScreenOrientation> mask = Qt::PrimaryOrientation
Expand All @@ -109,6 +110,7 @@ int main(int argc, char *argv[])
}
sc->setOrientationUpdateMask(mask);
}
#endif

qmlRegisterType<TextRender>("FingerTerm", 1, 0, "TextRender");
qmlRegisterUncreatableType<Util>("FingerTerm", 1, 0, "Util", "Util is created by app");
Expand Down
10 changes: 5 additions & 5 deletions qml/MenuFingerterm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import QtQuick 2.0
import QtQuick.XmlListModel 2.0
import QtQml.XmlListModel
Copy link
Member

@rainemak rainemak Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work with Qt5.x as version number is mandatory with it. One simple approach could go as follows

  • Rename / copy qml/MenuFingerterm.qml to qml/MenuFingerterm5.qml and qml/MenuFingerterm6.qml
  • Have Qt6 changes in qml/MenuFingerterm6.qml and Qt5 in qml/MenuFingerterm5.qml
  • Expose Qt major version to the root context or have it as a singleton
  • On qml/Main.qml use Loader to load correct menu

Something like this to Main.qml to replace MenuFingerterm

Loader {
    id: menu

    readonly property showing: item && item.showing

    anchors.fill: parent
    source: QtMajorVersion === 5 ? Qt.resolvedUrl("MenuFingerterm5.qml") : Qt.resolvedUrl("MenuFingerterm6.qml")
}

Point is that neither of these menu component won't get compiled when Main.qml is compiled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't maybe even copy the whole MenuFingerterm.qml. It should be enough putting the ~10 line XmlListModel snippet into qml version specific model files and load such on MenuFingerTerm based on qt version.

import FingerTerm 1.0

Item {
Expand Down Expand Up @@ -62,12 +62,12 @@ Item {

XmlListModel {
id: xmlModel
xml: term.getUserMenuXml()
source: term.getUserMenuXmlPath()
query: "/userMenu/item"

XmlRole { name: "title"; query: "title/string()" }
XmlRole { name: "command"; query: "command/string()" }
XmlRole { name: "disableOn"; query: "disableOn/string()" }
XmlListModelRole { name: "title"; elementName: "title" }
XmlListModelRole { name: "command"; elementName: "command" }
XmlListModelRole { name: "disableOn"; elementName: "disableOn" }
}

Component {
Expand Down
13 changes: 9 additions & 4 deletions terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void Terminal::keyPress(int key, int modifiers, const QString& text)

if (asciiVal >= 0x41 && asciiVal <= 0x5f) {
// Turn uppercase characters into their control code equivalent
toWrite.append(asciiVal - 0x40);
toWrite.append((char)(asciiVal - 0x40));
} else {
qWarning() << "Ctrl+" << c << " does not translate into a control code";
}
Expand Down Expand Up @@ -1312,7 +1312,7 @@ const QStringList Terminal::grabURLsFromBuffer()
for (int i=0; i<iBackBuffer.size(); i++) {
for (int j=0; j<iBackBuffer[i].size(); j++) {
if (iBackBuffer[i][j].c.isPrint())
buf.append(iBackBuffer[i][j].c);
buf.append(iBackBuffer[i][j].c.toLatin1());
else if (iBackBuffer[i][j].c == 0)
buf.append(' ');
}
Expand All @@ -1325,7 +1325,7 @@ const QStringList Terminal::grabURLsFromBuffer()
for (int i=0; i<buffer().size(); i++) {
for (int j=0; j<buffer()[i].size(); j++) {
if (buffer()[i][j].c.isPrint())
buf.append(buffer()[i][j].c);
buf.append(buffer()[i][j].c.toLatin1());
else if (buffer()[i][j].c == 0)
buf.append(' ');
}
Expand All @@ -1340,7 +1340,7 @@ const QStringList Terminal::grabURLsFromBuffer()
foreach(QString prot, lookFor) {
int ind=0;
while( ind != -1 ) {
ind = buf.indexOf(prot, ind);
ind = buf.indexOf(prot.toUtf8(), ind);
if(ind!=-1) {
int ind2 = buf.indexOf(" ",ind);
int l=-1;
Expand All @@ -1355,6 +1355,11 @@ const QStringList Terminal::grabURLsFromBuffer()
return ret;
}

QString Terminal::getUserMenuXmlPath()
{
return iUtil->configPath()+"/menu.xml";
}

QString Terminal::getUserMenuXml()
{
if(!iUtil)
Expand Down
1 change: 1 addition & 0 deletions terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Terminal : public QObject
Q_INVOKABLE const QStringList grabURLsFromBuffer();

Q_INVOKABLE QString getUserMenuXml();
Q_INVOKABLE QString getUserMenuXmlPath();

void scrollBackBufferFwd(int lines);
void scrollBackBufferBack(int lines);
Expand Down
4 changes: 4 additions & 0 deletions textrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ TextRender::TextRender(QQuickItem *parent) :
iShowBufferScrollIndicator = false;

iFont = QFont(sUtil->fontFamily(), sUtil->fontSize());
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
iFont.setStyleHint(QFont::Monospace, QFont::StyleStrategy(QFont::PreferDefault | QFont::ForceIntegerMetrics));
#else
iFont.setStyleHint(QFont::Monospace, QFont::StyleStrategy(QFont::PreferDefault));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer default would be the default so does this do anything? For second thing is even the earlier ForceIntegerMetrics doing anything since there is QFontMetrics used for sizes as suggested by the deprecation notice?

#endif
iFont.setBold(false);
QFontMetrics fontMetrics(iFont);
iFontHeight = fontMetrics.height();
Expand Down