Skip to content

Commit

Permalink
Tiled Quick: Updated to require Qt 6.5
Browse files Browse the repository at this point in the history
* Migrated to new signal handling syntax.
* Removed version numbers from imports.
* Migrated to Settings from QtCore.
* Migrated to dialogs from QtQuick.Dialogs.

Some small other changes:

* Disable VSync since it makes things move erratically during resizing
  and delays response times.

* Round scaling factor since a fractional factor causes pixel movement
  during panning and window resizing.
  • Loading branch information
bjorn committed Oct 21, 2024
1 parent 312c364 commit cb35fef
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/libtiledquick/libtiledquick.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DynamicLibrary {

Depends { name: "libtiled" }
Depends { name: "cpp" }
Depends { name: "Qt"; submodules: ["quick"]; versionAtLeast: "5.12" }
Depends { name: "Qt"; submodules: ["quick"]; versionAtLeast: "6.5" }

cpp.cxxLanguageVersion: "c++17"
cpp.cxxFlags: {
Expand All @@ -21,7 +21,7 @@ DynamicLibrary {
"QT_NO_CAST_FROM_ASCII",
"QT_NO_CAST_TO_ASCII",
"QT_NO_URL_CAST_FROM_STRING",
"QT_DISABLE_DEPRECATED_BEFORE=0x050F00",
"QT_DISABLE_DEPRECATED_BEFORE=0x060500",
"QT_NO_DEPRECATED_WARNINGS",
"QT_NO_FOREACH"
]
Expand Down
19 changes: 9 additions & 10 deletions src/tiledquick/main.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QSurfaceFormat>

int main(int argc, char *argv[])
{
QCoreApplication::setOrganizationDomain("mapeditor.org");
QCoreApplication::setApplicationName("TiledQuick");

// High-DPI scaling is always enabled in Qt 6
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

// We don't need the scaling factor to be rounded
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#endif
// Not rounding causes pixel movement during panning and window resizing
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor);

QApplication app(argc, argv);

Expand All @@ -25,9 +19,14 @@ int main(int argc, char *argv[])
qmlDir += QStringLiteral("/../qml");
#endif

QSurfaceFormat format = QSurfaceFormat::defaultFormat();
// format.setSamples(8); // Increase quality of lines and edges when UI is scaled down
format.setSwapInterval(0); // Disable vsync
QSurfaceFormat::setDefaultFormat(format);

QQmlApplicationEngine engine;
engine.addImportPath(qmlDir);
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

return app.exec();
return QApplication::exec();
}
8 changes: 5 additions & 3 deletions src/tiledquick/qml/DragArea.qml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import QtQuick 2.0
import QtQuick

MouseArea {
property var lastDragPos

signal dragged(var dx, var dy)

hoverEnabled: true
onPressed: lastDragPos = mapToItem(null, mouse.x, mouse.y)
onPressed: function(mouse) {
lastDragPos = mapToItem(null, mouse.x, mouse.y)
}

onPositionChanged: {
onPositionChanged: function(mouse) {
if (!pressed)
return;

Expand Down
2 changes: 1 addition & 1 deletion src/tiledquick/qml/FontAwesome.qml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pragma Singleton
import QtQml 2.3
import QtQml

QtObject {
readonly property string open: "\uE800"
Expand Down
30 changes: 15 additions & 15 deletions src/tiledquick/qml/main.qml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Window 2.11
import org.mapeditor.Tiled 1.0 as Tiled
import Qt.labs.settings 1.0
import Qt.labs.platform 1.0 as Platform
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Dialogs
import org.mapeditor.Tiled as Tiled
import QtCore

// For access to FontAwesome Singleton
import "."
Expand All @@ -23,20 +23,20 @@ ApplicationWindow {
source: "fonts/fontawesome.ttf"
}

Platform.FileDialog {
FileDialog {
id: fileDialog
nameFilters: [ "TMX files (*.tmx)", "All files (*)" ]
onAccepted: {
mapLoader.source = fileDialog.file
settings.mapsFolder = fileDialog.folder
mapLoader.source = fileDialog.selectedFile
settings.mapsFolder = fileDialog.currentFolder
fitMapInView(false);
}
}

Platform.MessageDialog {
MessageDialog {
id: aboutBox
title: "About Tiled Quick"
text: "This is an experimental Qt Quick version of Tiled,\na generic 2D map editor"
text: "This is an experimental Qt Quick version of Tiled, a generic 2D map editor"
}

Settings {
Expand Down Expand Up @@ -71,7 +71,7 @@ ApplicationWindow {
text: qsTr("Open...")
shortcut: StandardKey.Open
onTriggered: {
fileDialog.folder = settings.mapsFolder
fileDialog.currentFolder = settings.mapsFolder
fileDialog.open()
}
}
Expand Down Expand Up @@ -167,7 +167,7 @@ ApplicationWindow {
id: singleFingerPanArea
anchors.fill: parent

onDragged: {
onDragged: function(dx, dy) {
dx *= Screen.devicePixelRatio
dy *= Screen.devicePixelRatio

Expand All @@ -184,7 +184,7 @@ ApplicationWindow {
}
}

onWheel: {
onWheel: function(wheel) {
const scaleFactor = Math.pow(1.4, wheel.angleDelta.y / 120)

let targetScale = containerAnimation.running ? containerAnimation.scale : mapContainer.scale
Expand Down
14 changes: 9 additions & 5 deletions src/tiledquick/tiledquick.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ QtGuiApplication {
Depends {
name: "Qt"
submodules: ["core", "quick", "widgets"]
versionAtLeast: "5.12"
versionAtLeast: "6.5"
}
Depends {
name: "tiledquickplugin"
Expand All @@ -23,12 +23,16 @@ QtGuiApplication {
cpp.cxxLanguageVersion: "c++17"
cpp.cxxFlags: {
var flags = base;
if (qbs.toolchain.contains("msvc")) {
if (Qt.core.versionMajor >= 6 && Qt.core.versionMinor >= 3)
flags.push("/permissive-");
}
if (qbs.toolchain.contains("msvc"))
flags.push("/permissive-");
return flags;
}
cpp.defines: [
"QT_DISABLE_DEPRECATED_BEFORE=QT_VERSION_CHECK(6,5,0)",
"QT_NO_DEPRECATED_WARNINGS",
"QT_NO_FOREACH",
"QT_NO_URL_CAST_FROM_STRING"
]

files: [
"fonts/fonts.qrc",
Expand Down
4 changes: 2 additions & 2 deletions src/tiledquickplugin/tiledquickplugin.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DynamicLibrary {
Depends { name: "libtiledquick" }
Depends {
name: "Qt"; submodules: ["qml", "quick"]
versionAtLeast: "5.12"
versionAtLeast: "6.5"
}

cpp.cxxLanguageVersion: "c++17"
Expand All @@ -19,7 +19,7 @@ DynamicLibrary {
return flags;
}
cpp.defines: [
"QT_DISABLE_DEPRECATED_BEFORE=0x050F00",
"QT_DISABLE_DEPRECATED_BEFORE=0x060500",
"QT_NO_DEPRECATED_WARNINGS",
"QT_NO_CAST_FROM_ASCII",
"QT_NO_CAST_TO_ASCII",
Expand Down

0 comments on commit cb35fef

Please sign in to comment.