Last active
June 27, 2023 06:29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.16) | |
project(ZoomingTest VERSION 0.1 LANGUAGES CXX) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
find_package(Qt6 6.4 REQUIRED COMPONENTS Quick) | |
qt_standard_project_setup() | |
qt_add_executable(appZoomingTest | |
main.cpp | |
) | |
qt_add_qml_module(appZoomingTest | |
URI ZoomingTest | |
VERSION 1.0 | |
QML_FILES Main.qml DocumentNavigation.js | |
) | |
set_target_properties(appZoomingTest PROPERTIES | |
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com | |
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} | |
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} | |
MACOSX_BUNDLE TRUE | |
WIN32_EXECUTABLE TRUE | |
) | |
target_link_libraries(appZoomingTest | |
PRIVATE Qt6::Quick | |
) | |
install(TARGETS appZoomingTest | |
BUNDLE DESTINATION . | |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
int main(int argc, char *argv[]) | |
{ | |
QGuiApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
const QUrl url(u"qrc:/ZoomingTest/Main.qml"_qs); | |
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, | |
&app, []() { QCoreApplication::exit(-1); }, | |
Qt::QueuedConnection); | |
engine.load(url); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import QtQuick 2.15 | |
import QtQuick.Controls 2.15 | |
import QtQuick.Window 2.15 | |
import "DocumentNavigation.js" as NavigationLogic | |
/* | |
A view on the document's pages in a certain layout (e.g. vertical) | |
*/ | |
ApplicationWindow | |
{ | |
id: root | |
visible: true | |
visibility: Window.Maximized | |
property int currentPage: 4 | |
MouseArea | |
{ | |
id: mouseArea | |
anchors.fill: parent | |
// Handle scrolling customly | |
onWheel: (wheel) => NavigationLogic.handleWheel(wheel) | |
ListView | |
{ | |
id: pageView | |
readonly property real defaultPageHeight: 1334 | |
property real zoomFactor: 1 | |
readonly property int defaultPageSpacing: 12 | |
readonly property int scrollSpeed: 1600 | |
height: parent.height | |
width: currentItem.width <= root.width ? currentItem.width : root.width | |
contentWidth: currentItem.width | |
anchors.centerIn: parent | |
flickableDirection: Flickable.AutoFlickDirection | |
interactive: true | |
clip: true | |
cacheBuffer: 2000 | |
boundsMovement: Flickable.StopAtBounds | |
flickDeceleration: 10000 | |
model: 500 | |
delegate: Rectangle | |
{ | |
height: Math.round(pageView.defaultPageHeight * pageView.zoomFactor) | |
width: height * 0.7 | |
color: modelData % 2 == 0 ? "gray" : "green" | |
Label | |
{ | |
anchors.centerIn: parent | |
font.bold: true | |
font.pointSize: 20 | |
text: modelData | |
} | |
} | |
onContentYChanged: NavigationLogic.updateCurrentPageCounter(); | |
MouseArea | |
{ | |
id: wheelInterceptor | |
anchors.fill: parent | |
onWheel: (wheel) => | |
{ | |
NavigationLogic.handleWheel(wheel); | |
wheel.accepted = true; | |
} | |
} | |
} | |
} | |
function zoom(factor) | |
{ | |
NavigationLogic.zoom(factor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment