Skip to content

Commit

Permalink
Merge pull request #74 from zrax/qt6_compat
Browse files Browse the repository at this point in the history
Add Qt6 compatibility
  • Loading branch information
zrax authored Jun 12, 2023
2 parents e366729 + 2d7e9d6 commit f37a1f7
Show file tree
Hide file tree
Showing 23 changed files with 167 additions and 118 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/windows-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,22 @@ jobs:
strategy:
matrix:
cfg:
- { os: windows-2019, generator: Visual Studio 16 2019, cmake-arch: Win32, triplet: x86-windows-static-md, kf5: v5.106.0, qt: 5.15.2, qt-arch: win32_msvc2019 }
- { os: windows-2019, generator: Visual Studio 16 2019, cmake-arch: x64, triplet: x64-windows-static-md, kf5: v5.106.0, qt: 5.15.2, qt_arch: win64_msvc2019_64 }
- os: windows-2019
generator: Visual Studio 16 2019
cmake-arch: Win32
triplet: x86-windows-static-md
kf5: v5.106.0
qt: 5.15.2
kf5_cmake_args: ""
qt-arch: win32_msvc2019
- os: windows-2019
generator: Visual Studio 16 2019
cmake-arch: x64
triplet: x64-windows-static-md
kf5: v5.106.0
kf5_cmake_args: "-DBUILD_WITH_QT6=ON"
qt: 6.5.1
qt_arch: win64_msvc2019_64

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -76,7 +90,7 @@ jobs:
-G "${{ matrix.cfg.generator }}" -A ${{ matrix.cfg.cmake-arch }} `
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\install `
-DBUILD_HTML_DOCS=OFF -DBUILD_MAN_DOCS=OFF -DBUILD_QTHELP_DOCS=OFF -DBUILD_TESTING=OFF `
..
${{ matrix.cfg.kf5_cmake_args }} ..
cmake --build . --config Release -j 2
cmake --build . --config Release --target INSTALL
Expand All @@ -97,7 +111,7 @@ jobs:
-G "${{ matrix.cfg.generator }}" -A ${{ matrix.cfg.cmake-arch }} `
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}\install `
-DBUILD_HTML_DOCS=OFF -DBUILD_MAN_DOCS=OFF -DBUILD_QTHELP_DOCS=OFF -DBUILD_TESTING=OFF `
..
${{ matrix.cfg.kf5_cmake_args }} ..
cmake --build . --config Release -j 2
cmake --build . --config Release --target INSTALL
Expand Down Expand Up @@ -134,11 +148,10 @@ jobs:
- name: Deploy Qt
run: |
cd ${{ env.Qt5_Dir }}\bin
$ExeFiles = Get-ChildItem "${{ github.workspace }}\install\bin" -Filter *.exe
$DllFiles = Get-ChildItem "${{ github.workspace }}\install\bin" -Filter *.dll
ForEach-Object -InputObject ($ExeFiles + $DllFiles) {
./windeployqt.exe --release $_.FullName
windeployqt.exe --release $_.FullName
}
- name: Upload Artifacts
Expand Down
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.7)
project(PlasmaShop)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_AUTOMOC TRUE)
set(CMAKE_AUTORCC TRUE)

if(POLICY CMP0071)
# Don't run generated source files (bytes/python_*.cpp) through automoc
Expand All @@ -14,10 +15,22 @@ endif()

find_package(HSPlasma REQUIRED)
find_package(string_theory 2.0 REQUIRED)
find_package(Qt5 5.8 REQUIRED COMPONENTS Core Gui Widgets)
find_package(KF5SyntaxHighlighting REQUIRED)
find_package(PythonInterp REQUIRED)

if(NOT DEFINED QT_VERSION_MAJOR)
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
endif()
find_package(Qt${QT_VERSION_MAJOR} 5.10 REQUIRED COMPONENTS Core Widgets)
if(Qt5_FOUND AND NOT TARGET Qt::Core)
# The version-generic targets were only added in Qt 5.15
foreach(_qt_lib Core Widgets)
add_library(Qt::${_qt_lib} INTERFACE IMPORTED)
set_target_properties(Qt::${_qt_lib} PROPERTIES
INTERFACE_LINK_LIBRARIES "Qt5::${_qt_lib}")
endforeach()
endif()

find_package(KF5SyntaxHighlighting REQUIRED)
if(KF5SyntaxHighlighting_VERSION VERSION_LESS "5.39.0")
message(WARNING "KF5SyntaxHighlighting version 5.39.0 or later is required \
in order to use custom highlighting rules. KF5SyntaxHighlighting version \
Expand Down Expand Up @@ -61,7 +74,6 @@ endif()
add_definitions(-DPLASMASHOP_VERSION="${PlasmaShop_VERSION}")

set(QTEXTPAD_WIDGET_ONLY ON)
set(QT_VERSION_MAJOR 5)
add_subdirectory(qtextpad)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/qtextpad/lib")

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(PSCommon_Sources
)

add_library(PSCommon STATIC ${PSCommon_Headers} ${PSCommon_Sources})
target_link_libraries(PSCommon PUBLIC HSPlasma Qt5::Widgets syntaxtextedit)
target_link_libraries(PSCommon PUBLIC HSPlasma Qt::Widgets syntaxtextedit)

add_subdirectory(PlasmaShop)
add_subdirectory(PrpShop)
Expand Down
6 changes: 3 additions & 3 deletions src/PlasmaShop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ if(WIN32)
endif()

# generate rules for building source files from the resources
qt5_add_resources(PlasmaShop_RCC images.qrc PlasmaSyntax.qrc)
set(PlasmaShop_QRC images.qrc PlasmaSyntax.qrc)

include_directories("${pycdc_SOURCE_DIR}")

add_executable(PlasmaShop WIN32 MACOSX_BUNDLE
${PlasmaShop_Headers} ${PlasmaShop_Sources}
${pycdc_Headers} ${pycdc_Sources} ${pycdc_GeneratedSources}
${PlasmaShop_RCC})
target_link_libraries(PlasmaShop PSCommon Qt5::Core Qt5::Widgets)
${PlasmaShop_QRC})
target_link_libraries(PlasmaShop PSCommon Qt::Core Qt::Widgets)
target_link_libraries(PlasmaShop HSPlasma)

if(WIN32)
Expand Down
61 changes: 22 additions & 39 deletions src/PlasmaShop/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ PlasmaShopMain::PlasmaShopMain()
fActions[kTreeRename] = new QAction(tr("&Rename"), this);
fActions[kTreeDelete] = new QAction(tr("&Delete"), this);

fActions[kFileNew]->setShortcut(Qt::CTRL + Qt::Key_N);
fActions[kFileOpen]->setShortcut(Qt::CTRL + Qt::Key_O);
fActions[kFileSave]->setShortcut(Qt::CTRL + Qt::Key_S);
fActions[kFileSaveAs]->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_S);
fActions[kFileNew]->setShortcut(Qt::CTRL | Qt::Key_N);
fActions[kFileOpen]->setShortcut(Qt::CTRL | Qt::Key_O);
fActions[kFileSave]->setShortcut(Qt::CTRL | Qt::Key_S);
fActions[kFileSaveAs]->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::Key_S);
fActions[kFileRevert]->setShortcut(Qt::Key_F5);
fActions[kFileExit]->setShortcut(Qt::ALT + Qt::Key_F4);
fActions[kEditUndo]->setShortcut(Qt::CTRL + Qt::Key_Z);
fActions[kEditRedo]->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_Z);
fActions[kEditCut]->setShortcut(Qt::CTRL + Qt::Key_X);
fActions[kEditCopy]->setShortcut(Qt::CTRL + Qt::Key_C);
fActions[kEditPaste]->setShortcut(Qt::CTRL + Qt::Key_V);
fActions[kFileExit]->setShortcut(Qt::ALT | Qt::Key_F4);
fActions[kEditUndo]->setShortcut(Qt::CTRL | Qt::Key_Z);
fActions[kEditRedo]->setShortcut(Qt::SHIFT | Qt::CTRL | Qt::Key_Z);
fActions[kEditCut]->setShortcut(Qt::CTRL | Qt::Key_X);
fActions[kEditCopy]->setShortcut(Qt::CTRL | Qt::Key_C);
fActions[kEditPaste]->setShortcut(Qt::CTRL | Qt::Key_V);
fActions[kEditDelete]->setShortcut(Qt::Key_Delete);
fActions[kEditSelectAll]->setShortcut(Qt::CTRL + Qt::Key_A);
fActions[kTextFind]->setShortcut(Qt::CTRL + Qt::Key_F);
fActions[kEditSelectAll]->setShortcut(Qt::CTRL | Qt::Key_A);
fActions[kTextFind]->setShortcut(Qt::CTRL | Qt::Key_F);
fActions[kTextFindNext]->setShortcut(Qt::Key_F3);
fActions[kTextReplace]->setShortcut(Qt::CTRL + Qt::Key_R);
fActions[kTextReplace]->setShortcut(Qt::CTRL | Qt::Key_R);

fActions[kFileShowBrowser]->setCheckable(true);
fActions[kTextStxNone]->setCheckable(true);
Expand Down Expand Up @@ -312,16 +312,10 @@ void PlasmaShopMain::loadFile(QString filename)
}

// Guess the filetype based on its extension
QString ext, fnameNoPath, fnameDisplay = filename;
QRegExp re;
re.setPattern(".*\\.([^\\.]*)");
if (re.indexIn(filename) >= 0)
ext = re.cap(1).toLower();
re.setPattern("(.*[\\\\\\/])?([^\\\\\\/]*)");
if (re.indexIn(filename) >= 0) {
fnameNoPath = re.cap(2).toLower();
fnameDisplay = re.cap(2);
}
QFileInfo fileInfo(filename);
QString ext = fileInfo.suffix().toLower();
QString fnameDisplay = fileInfo.fileName();
QString fnameNoPath = fnameDisplay.toLower();

DocumentType dtype = kDocUnknown;
if (ext == "age" || ext == "cfg" || ext == "csv" || ext == "elf" ||
Expand Down Expand Up @@ -371,7 +365,7 @@ void PlasmaShopMain::loadFile(QString filename)
} else {
QMessageBox::critical(this, tr("Unsupported File Type"),
tr("Error: File %1 has an unsupported file type (%2)")
.arg(fnameNoPath).arg(ext),
.arg(fnameDisplay).arg(ext),
QMessageBox::Ok);
return;
}
Expand Down Expand Up @@ -424,7 +418,7 @@ void PlasmaShopMain::loadFile(QString filename)
} else {
QMessageBox::critical(this, tr("Oops"),
tr("No editor is currently available for %1")
.arg(fnameNoPath), QMessageBox::Ok);
.arg(fnameDisplay), QMessageBox::Ok);
}
}

Expand Down Expand Up @@ -676,14 +670,7 @@ void PlasmaShopMain::onSaveAs()
return;
QPlasmaDocument* doc = (QPlasmaDocument*)fEditorPane->currentWidget();

QString ext, fnameNoPath;
QRegExp re;
re.setPattern(".*\\.([^.]*)");
if (re.indexIn(doc->filename()) >= 0)
ext = re.cap(1).toLower();
re.setPattern(".*[\\/]([^\\/]*)");
if (re.indexIn(doc->filename()) >= 0)
fnameNoPath = re.cap(1).toLower();
QString ext = QFileInfo(doc->filename()).suffix().toLower();

QString typeList;
QString curFilter;
Expand Down Expand Up @@ -775,11 +762,7 @@ void PlasmaShopMain::onSaveAs()
fDialogDir = dir.absolutePath();

// Update the displayed filename for the file
QString fnameDisplay = filename;
QRegExp re;
re.setPattern("(.*[\\\\\\/])?([^\\\\\\/]*)");
if (re.indexIn(filename) >= 0)
fnameDisplay = re.cap(2);
QString fnameDisplay = QFileInfo(filename).fileName();
fEditorPane->setTabText(fEditorPane->currentIndex(), fnameDisplay);
}
}
Expand Down Expand Up @@ -1426,7 +1409,7 @@ void PlasmaShopMain::onDocClean()
int main(int argc, char* argv[])
{
// Redirect libPlasma's debug stuff to PlasmaShop.log
QString logpath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QString logpath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
QDir dir;
dir.mkpath(logpath);
logpath += "/PlasmaShop.log";
Expand Down
11 changes: 11 additions & 0 deletions src/PlasmaShop/OptionsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,13 @@ OptionsDialog::OptionsDialog(QWidget* parent)
QFont fnt;
fnt.setFamily(settings.value("SciFont", PLAT_FONT).toString());
fnt.setPointSize(settings.value("SciFontSize", 10).toInt());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Qt6 changed the values for this enum...
fnt.setWeight(static_cast<QFont::Weight>(
settings.value("SciFontWeight-qt6", QFont::Normal).toInt()));
#else
fnt.setWeight(settings.value("SciFontWeight", QFont::Normal).toInt());
#endif
fnt.setItalic(settings.value("SciFontItalic", false).toBool());
fSciFont->setFont(fnt);

Expand Down Expand Up @@ -211,7 +217,12 @@ void OptionsDialog::onSave()
settings.setValue("SciTabWidth", fSciTabWidth->text().toInt());
settings.setValue("SciFont", fSciFont->font().family());
settings.setValue("SciFontSize", fSciFont->font().pointSize());
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Qt6 changed the values for this enum...
settings.setValue("SciFontWeight-qt6", static_cast<int>(fSciFont->font().weight()));
#else
settings.setValue("SciFontWeight", fSciFont->font().weight());
#endif
settings.setValue("SciFontItalic", fSciFont->font().italic());

accept();
Expand Down
12 changes: 4 additions & 8 deletions src/PlasmaShop/QPlasmaDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QInputDialog>
#include <QSettings>
#include <QMessageBox>
#include <QFileInfo>

QIcon QPlasmaDocument::GetDocIcon(const QString& filename)
{
Expand All @@ -46,14 +47,9 @@ QIcon QPlasmaDocument::GetDocIcon(const QString& filename)
return QIcon(":/img/db.png");
}

QString ext, fnameNoPath;
QRegExp re;
re.setPattern(".*\\.([^\\.]*)");
if (re.indexIn(filename) >= 0)
ext = re.cap(1).toLower();
re.setPattern("(.*[\\\\\\/])?([^\\\\\\/]*)");
if (re.indexIn(filename) >= 0)
fnameNoPath = re.cap(2).toLower();
QFileInfo fileInfo(filename);
QString ext = fileInfo.suffix().toLower();
QString fnameNoPath = fileInfo.fileName().toLower();

if (ext == "age")
return QIcon(":/img/age.png");
Expand Down
4 changes: 2 additions & 2 deletions src/PlasmaShop/QPlasmaSumFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void QPlasmaSumFile::addToSumFile(const QString& filename)
QFileInfo finfo(filename);

ST::string sumPath;
uint32_t timestamp = finfo.lastModified().toTime_t();
uint32_t timestamp = finfo.lastModified().toSecsSinceEpoch();

// Construct a default path based on the file extension
if (finfo.suffix() == "prp" || finfo.suffix() == "fni" || finfo.suffix() == "age" ||
Expand Down Expand Up @@ -259,7 +259,7 @@ void QPlasmaSumFile::onItemChanged(QTreeWidgetItem* item, int column)
item->setText(1, locale.toString(dateTime, QLocale::ShortFormat));
break;
}
file.fTimestamp = ts.toTime_t();
file.fTimestamp = ts.toSecsSinceEpoch();
makeDirty();
}
break;
Expand Down
15 changes: 12 additions & 3 deletions src/PlasmaShop/QPlasmaTextDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <QSettings>
#include <QMessageBox>
#include <QTextBlock>
#include <QRegularExpression>
#include <Stream/plEncryptedStream.h>
#include <Stream/hsElfStream.h>
#include "QPlasma.h"
Expand Down Expand Up @@ -332,9 +333,14 @@ QPlasmaTextDoc::QPlasmaTextDoc(QWidget* parent)
void QPlasmaTextDoc::updateSettings()
{
QSettings settings("PlasmaShop", "PlasmaShop");
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Qt6 changed the values for this enum...
QFont::Weight weight = static_cast<QFont::Weight>(settings.value("SciFontWeight-qt6", QFont::Normal).toInt());
#else
int weight = static_cast<QFont::Weight>(settings.value("SciFontWeight", QFont::Normal).toInt());
#endif
QFont textFont(settings.value("SciFont", PLAT_FONT).toString(),
settings.value("SciFontSize", 10).toInt(),
settings.value("SciFontWeight", QFont::Normal).toInt(),
settings.value("SciFontSize", 10).toInt(), weight,
settings.value("SciFontItalic", false).toBool());

fEditor->setFont(textFont);
Expand Down Expand Up @@ -392,15 +398,18 @@ bool QPlasmaTextDoc::onFind(const QString& text, bool regex, bool cs,
bool wo, bool reverse)
{
QTextDocument::FindFlags options;
QRegularExpression::PatternOptions regex_options;
if (cs)
options |= QTextDocument::FindCaseSensitively;
else
regex_options |= QRegularExpression::CaseInsensitiveOption;
if (wo)
options |= QTextDocument::FindWholeWords;
if (reverse)
options |= QTextDocument::FindBackward;

if (regex)
return fEditor->find(QRegExp(text, cs ? Qt::CaseSensitive : Qt::CaseInsensitive), options);
return fEditor->find(QRegularExpression(text, regex_options), options);
else
return fEditor->find(text, options);
}
Expand Down
13 changes: 9 additions & 4 deletions src/PrpShop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ if(WIN32)
set(PrpShop_Sources ${PrpShop_Sources} res/PrpShop.rc)
endif()

find_package(Qt5OpenGL REQUIRED)
if(QT_VERSION_MAJOR VERSION_GREATER_EQUAL 6)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS OpenGLWidgets)
endif()

# generate rules for building source files from the resources
qt5_add_resources(PrpShop_RCC images.qrc)
set(PrpShop_QRC images.qrc)

include_directories("${PROJECT_SOURCE_DIR}/src/PrpShop")

Expand All @@ -152,8 +154,11 @@ find_package(OpenGL)
set(QT_QTOPENGL_LIB_DEPENDENCIES ${OPENGL_glu_LIBRARY} ${OPENGL_gl_LIBRARY})

add_executable(PrpShop WIN32 MACOSX_BUNDLE
${PrpShop_Sources} ${PrpShop_Headers} ${PrpShop_RCC})
target_link_libraries(PrpShop PSCommon Qt5::Core Qt5::Widgets Qt5::OpenGL)
${PrpShop_Sources} ${PrpShop_Headers} ${PrpShop_QRC})
target_link_libraries(PrpShop PSCommon Qt::Core Qt::Widgets)
if(QT_VERSION_MAJOR VERSION_GREATER_EQUAL 6)
target_link_libraries(PrpShop Qt::OpenGLWidgets)
endif()
target_link_libraries(PrpShop HSPlasma)
target_link_libraries(PrpShop ${QT_QTOPENGL_LIB_DEPENDENCIES})

Expand Down
Loading

0 comments on commit f37a1f7

Please sign in to comment.