Skip to content

Commit

Permalink
Port to Qt 6
Browse files Browse the repository at this point in the history
Complete Qt 6 port.

Closes: #35
  • Loading branch information
plfiorini committed Apr 6, 2024
1 parent 8701e80 commit 846aa29
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ on:
- develop

jobs:
linux-qt5:
uses: lirios/.github/.github/workflows/build-linux-qt5.yml@master
linux-qt6:
uses: lirios/.github/.github/workflows/build-linux-qt6.yml@master
with:
build_dependencies: "cmake-shared fluid"
windows:
Expand Down
39 changes: 9 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
cmake_minimum_required(VERSION 3.10.0)
cmake_minimum_required(VERSION 3.19)

project("Calculator"
VERSION "1.3.0"
DESCRIPTION "Calculator application"
LANGUAGES CXX C
)

## Shared macros and functions:
if(CALCULATOR_WITH_FLUID AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fluid/CMakeLists.txt")
set(LIRI_LOCAL_ECM TRUE)
set(FLUID_WITH_DOCUMENTATION FALSE)
set(FLUID_WITH_DEMO FALSE)
endif()
if(LIRI_LOCAL_ECM)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/fluid/cmake/shared/modules")
else()
find_package(LiriCMakeShared "2.0.0" REQUIRED NO_MODULE)
list(APPEND CMAKE_MODULE_PATH "${LCS_MODULE_PATH}")
endif()
## Enable C++17:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

## Set minimum versions required.
set(QT_MIN_VERSION "5.10.0")

## Liri specific setup common for all modules:
include(LiriSetup)

## Features:
option(CALCULATOR_WITH_FLUID "Build together with Fluid" OFF)
add_feature_info("Calculator::WithFluid" CALCULATOR_WITH_FLUID "Build together with Fluid")

## Find Qt 5.
find_package(Qt5 "${QT_MIN_VERSION}"
CONFIG REQUIRED
COMPONENTS
## Find Qt:
find_package(Qt6
REQUIRED COMPONENTS
Core
Core5Compat
Gui
Widgets
Svg
Expand All @@ -42,10 +23,8 @@ find_package(Qt5 "${QT_MIN_VERSION}"
QuickControls2
LinguistTools
)
qt_standard_project_setup(REQUIRES 6.6)

## Add subdirectories:
if(CALCULATOR_WITH_FLUID)
add_subdirectory(fluid)
endif()
add_subdirectory(data)
add_subdirectory(src)
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ A cross-platform material design calculator.

## Dependencies

Qt >= 5.10.0 with at least the following modules is required:
Qt >= 6.6 with at least the following modules is required:

* [qtbase](http://code.qt.io/cgit/qt/qtbase.git)
* [qtdeclarative](http://code.qt.io/cgit/qt/qtdeclarative.git)
* [qtquickcontrols2](http://code.qt.io/cgit/qt/qtquickcontrols2.git)

The following modules and their dependencies are required:

* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.10.0
* [cmake-shared](https://github.com/lirios/cmake-shared.git) >= 1.0.0
* [fluid](https://github.com/lirios/fluid.git) >= 1.0.0
* [cmake](https://gitlab.kitware.com/cmake/cmake) >= 3.19.0
* [fluid](https://github.com/lirios/fluid.git) >= 2.0.0

## Installation

Expand All @@ -38,10 +36,6 @@ make install # use sudo if necessary
Replace `/path/to/prefix` to your installation prefix.
Default is `/usr/local`.

You can also append the following options to the `cmake` command:

* `-DCALCULATOR_WITH_FLUID:BOOL=ON`: Build with a local copy of the Fluid sources.

## Licensing

Licensed under the terms of the GNU General Public License version 3 or, at your option, any later version.
5 changes: 4 additions & 1 deletion data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ if(UNIX AND NOT APPLE AND NOT ANDROID)
get_filename_component(icon_directory "${icon_basename}" DIRECTORY)
string(REPLACE "${icon_directory}/" "" icon_filename "${icon_basename}")
string(REGEX REPLACE "\.(png|svg)" "" icon_filename "${icon_filename}")
set(dest_path "${INSTALL_DATADIR}/icons/hicolor/${icon_directory}/")
set(dest_path "${CMAKE_INSTALL_DATADIR}/icons/hicolor/${icon_directory}/")
install(FILES "${source_path}" DESTINATION "${dest_path}")
endforeach()
endif()

install(FILES io.liri.Calculator.appdata.xml DESTINATION "${CMAKE_INSTALL_DATADIR}/appdata")
install(FILES io.liri.Calculator.desktop DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
107 changes: 60 additions & 47 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
# Translations
file(GLOB LiriCalculator_TRANSLATIONS "${CMAKE_SOURCE_DIR}/translations/*_*.ts")
qt5_add_translation(LiriCalculator_QM_FILES ${LiriCalculator_TRANSLATIONS})
if(WIN32)
set(_translations_destdir "${CMAKE_CURRENT_BINARY_DIR}/translations")
elseif(APPLE)
set(_translations_destdir "${CMAKE_CURRENT_BINARY_DIR}/Contents/Resources/data/translations")
elseif(LINUX OR BSD)
set(_translations_destdir "${INSTALL_DATADIR}/liri-calculator/translations")
endif()
if(DEFINED _translations_destdir)
install(FILES ${LiriCalculator_QM_FILES} DESTINATION "${_translations_destdir}")
endif()
qt_add_executable(LiriCalculator
WIN32 MACOSX_BUNDLE
main/main.cpp
filehandler/filehandler.cpp filehandler/filehandler.h
)

qt_add_qml_module(LiriCalculator
URI Application
VERSION 2.0
QML_FILES
engine/qmldir
engine/math.js
engine/MathJs.qml
ui/qmldir
ui/ButtonsPanel.qml
ui/ButtonsView.qml
ui/CalculationLine.qml
ui/CalculationZone.qml
ui/HistoryPanel.qml
ui/Main.qml
ui/NavButton.qml
ui/Shortcuts.qml
ui/Styles.qml
RESOURCES
icons/icon.png
)

target_compile_definitions(LiriCalculator PRIVATE
QT_NO_CAST_FROM_ASCII
QT_NO_FOREACH
)

file(GLOB ts_files "../translations/*.ts")
qt_add_translations(LiriCalculator
TS_FILES ${ts_files}
RESOURCE_PREFIX /qt/qml/Application/i18n
)

target_link_libraries(LiriCalculator
PRIVATE
Qt6::Core
Qt6::Core5Compat
Qt6::Gui
Qt6::Widgets
Qt6::Qml
Qt6::Quick
Qt6::QuickControls2
)

if(APPLE OR WIN32)
set(LiriCalculator_OUTPUT_NAME "LiriCalculator")
set_target_properties(LiriCalculator PROPERTIES OUTPUT_NAME "LiriCalculator")
else()
set(LiriCalculator_OUTPUT_NAME "liri-calculator")
set_target_properties(LiriCalculator PROPERTIES OUTPUT_NAME "liri-calculator")
endif()
if(APPLE)
set_target_properties(LiriCalculator PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.liri.Calculator"
MACOSX_BUNDLE_ICON_FILE "io.liri.Calculator"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
)
endif()

liri_add_executable(LiriCalculator
OUTPUT_NAME
"${LiriCalculator_OUTPUT_NAME}"
SOURCES
main/main.cpp
filehandler/filehandler.cpp
filehandler/filehandler.h
${LiriCalculator_QM_FILES}
RESOURCES
calculator.qrc
DEFINES
QT_NO_CAST_FROM_ASCII
QT_NO_FOREACH
APPDATA
"${CMAKE_CURRENT_SOURCE_DIR}/../data/io.liri.Calculator.appdata.xml"
DESKTOP
"${CMAKE_CURRENT_SOURCE_DIR}/../data/io.liri.Calculator.desktop"
LIBRARIES
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Qml
Qt5::Quick
Qt5::QuickControls2
GUI
install(TARGETS LiriCalculator
BUNDLE DESTINATION .
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set_target_properties(LiriCalculator PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER "io.liri.Calculator"
MACOSX_BUNDLE_ICON_FILE "io.liri.Calculator"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}"
)

liri_finalize_executable(LiriCalculator)
18 changes: 0 additions & 18 deletions src/calculator.qrc

This file was deleted.

5 changes: 4 additions & 1 deletion src/filehandler/filehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ void FileHandler::load(const QUrl &fileUrl) {
return;
}

const QUrl path = QQmlFileSelector::get(engine)->selector()->select(fileUrl);
QQmlFileSelector* selector = new QQmlFileSelector(engine);
const QUrl path = selector->selector()->select(fileUrl);
const QString fileName = QQmlFile::urlToLocalFileOrQrc(path);
if (QFile::exists(fileName)) {
QFile file(fileName);
Expand Down Expand Up @@ -102,3 +103,5 @@ QTextDocument *FileHandler::textDocument() const {

return m_document->textDocument();
}

#include "moc_filehandler.cpp"
42 changes: 17 additions & 25 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,30 @@

#include "../filehandler/filehandler.h"

using namespace Qt::StringLiterals;

int main(int argc, char *argv[])
{
// Set Material Design QtQuick Controls 2 style
QQuickStyle::setStyle(QStringLiteral("Material"));

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QApplication app(argc, argv);
app.setOrganizationName(QStringLiteral("Liri"));
app.setOrganizationDomain(QStringLiteral("liri.io"));
app.setApplicationName(QStringLiteral("Calculator"));
app.setDesktopFileName(QStringLiteral("io.liri.Calculator.desktop"));
app.setWindowIcon(QIcon(QStringLiteral("qrc:/icons/icon.png")));
app.setDesktopFileName(QStringLiteral("io.liri.Calculator"));
app.setWindowIcon(QIcon(QStringLiteral(":/qt/icons/icon.png")));

// Load Translations
// Load Qt translations
QTranslator qtTranslator;
qtTranslator.load(QStringLiteral("qt_") + QLocale::system().name(),
QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
if (qtTranslator.load(QLocale(), "qt"_L1, "_"_L1,
QLibraryInfo::path(QLibraryInfo::TranslationsPath)))
app.installTranslator(&qtTranslator);

// Load translations from resources
QTranslator translator;
#if (defined Q_OS_LINUX)
const QString translationsPath = QStandardPaths::locate(
QStandardPaths::GenericDataLocation, QStringLiteral("liri-calculator/translations/"),
QStandardPaths::LocateDirectory);
#elif (defined Q_OS_MACOS)
const QString translationsPath =
QDir(QCoreApplication::applicationDirPath())
.absoluteFilePath(QStringLiteral("../Resources/data/translations/"));
#elif (defined Q_OS_WIN)
const QString translationsPath = QDir(QCoreApplication::applicationDirPath())
.absoluteFilePath(QStringLiteral("translations/"));
#else
#error "Platform not supported"
#endif
if (translator.load(translationsPath + QStringLiteral("liri-calculator_") + QLocale::system().name()))
app.installTranslator(&translator);
if (translator.load(QLocale(), "liri-calculator"_L1, "_"_L1, ":/qt/qml/Application/i18n"_L1))
QCoreApplication::installTranslator(&translator);

// Set the X11 WM_CLASS so X11 desktops can find the desktop file
qputenv("RESOURCE_NAME", "io.liri.Calculator");
Expand All @@ -87,11 +74,16 @@ int main(int argc, char *argv[])

qmlRegisterType<FileHandler>("filehandler", 1, 0, "FileHandler");

// Quit on error
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
QCoreApplication::instance(), QCoreApplication::quit,
Qt::QueuedConnection);

// setup qml imports
engine.addImportPath(QStringLiteral("qrc:/"));

// load main ui
engine.load(QUrl(QStringLiteral("qrc:/ui/Main.qml")));
engine.loadFromModule("Application", "Main");

return app.exec();
}
16 changes: 8 additions & 8 deletions src/ui/ButtonsPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* $END_LICENSE$
*/

import QtQuick 2.7
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import Fluid.Controls 1.0
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import Fluid.Controls
import ".."
import "../engine"

Expand All @@ -44,14 +44,14 @@ Rectangle {
color: styles.accentColor
labels: ['sqrt','exp','log','cos','sin','tan','acos','asin','atan','π','','x10^']
targets: ['sqrt(','exp(','log','cos(','sin(','tan(','acos(','asin(','atan(','pi','Infinity','e']
onButtonClicked: calculationZone.appendToFormula(strToAppend)
onButtonClicked: (strToAppend) => calculationZone.appendToFormula(strToAppend)
}

ButtonsView {
color: Material.color(Material.Grey, Material.Shade900)
labels: ['7', '8', '9', '', '4', '5', '6', '^', '1', '2', '3', '!', '.', '0', '(', ')']
targets: ['7', '8', '9', 'DEL', '4', '5', '6', '^', '1', '2', '3', '!', '.', '0', '(', ')']
onButtonClicked: calculationZone.appendToFormula(strToAppend)
onButtonClicked: (strToAppend) => calculationZone.appendToFormula(strToAppend)
onButtonLongPressed: {
if (strToAppend === "DEL") {
calculationZone.clearFormula();
Expand All @@ -63,7 +63,7 @@ Rectangle {
color: Material.color(Material.Grey, Material.Shade800)
labels: ['+', '-', '×', '÷']
targets: ['+', '-', '*', '/']
onButtonClicked: calculationZone.appendToFormula(strToAppend)
onButtonClicked: (strToAppend) => calculationZone.appendToFormula(strToAppend)
}
}
}
10 changes: 5 additions & 5 deletions src/ui/ButtonsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
* $END_LICENSE$
*/

import QtQuick 2.7
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import Fluid.Controls 1.0
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import QtQuick.Controls.Material
import Fluid.Controls
import ".."


Expand Down
Loading

0 comments on commit 846aa29

Please sign in to comment.