Skip to content

Commit

Permalink
Add basic rendering for mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Apr 2, 2024
1 parent dbce043 commit bb0707d
Show file tree
Hide file tree
Showing 14 changed files with 1,083 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/adapters/controllers/page_controller.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "page_controller.hpp"
#include <QDebug>
#include "fz_utils.hpp"
#include "mupdf/classes.h"

Expand Down Expand Up @@ -54,11 +55,13 @@ void PageController::setInvertColor(bool newInvertColor)
m_pageImageOutdated = true;
}

QImage PageController::renderPage()
QImage PageController::renderPage(int pageNr)
{
if(!m_pageImageOutdated)
return m_pageImage;

qDebug() << "Re-rendering page nr: " << pageNr;

auto zoom = m_matrix.a;
m_pageImage = utils::qImageFromPixmap(m_pageGenerator.renderPage(zoom));

Expand Down
2 changes: 1 addition & 1 deletion src/adapters/controllers/page_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PageController : public IPageController

void setInvertColor(bool newInvertColor) override;

QImage renderPage() override;
QImage renderPage(int pageNr) override;

bool pointIsAboveText(const QPointF& point) override;
bool pointIsAboveLink(const QPointF& point) override;
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/interfaces/controllers/i_page_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ADAPTERS_EXPORT IPageController : public QObject

virtual void setInvertColor(bool newInvertColor) = 0;

virtual QImage renderPage() = 0;
virtual QImage renderPage(int pageNr) = 0;

virtual bool pointIsAboveText(const QPointF& point) = 0;
virtual bool pointIsAboveLink(const QPointF& point) = 0;
Expand Down
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "i_library_service.hpp"
#include "i_user_service.hpp"
#include "library_proxy_model.hpp"
#include "page_view.hpp"
#include "setting_groups.hpp"
#include "setting_keys.hpp"
#include "shortcuts_proxy_model.hpp"
Expand All @@ -41,7 +42,6 @@
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
#include "key_sequence_recorder.hpp"
#include "message_handler.hpp"
#include "page_view.hpp"
#endif


Expand Down Expand Up @@ -90,10 +90,11 @@ int main(int argc, char* argv[])
qRegisterMetaType<adapters::dtos::DictionaryEntryDto>();
qRegisterMetaType<adapters::dtos::WordTypeDto>();
qRegisterMetaType<adapters::dtos::WordDefinitionDto>();
qmlRegisterType<cpp_elements::PageView>("Librum.elements", 1, 0, "PageView");

#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
qmlRegisterType<cpp_elements::KeySequenceRecorder>("Librum.elements", 1, 0, "KeySequenceRecorder");
qmlRegisterType<cpp_elements::PageView>("Librum.elements", 1, 0, "PageView");
#elif defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#endif


Expand Down
7 changes: 6 additions & 1 deletion src/presentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ endif()

if(ANDROID)
set(CPP_SOURCE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/mobile/modules/CppElements")
set(CPP_FILES)
set(CPP_FILES
mobile/modules/CppElements/page_view.hpp
mobile/modules/CppElements/page_view.cpp
)
else()
set(CPP_SOURCE_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/desktop/modules/CppElements")
set(CPP_FILES
Expand All @@ -27,6 +30,8 @@ add_library(presentation
${QML_SOURCE_QRC_PATH}
qmlSourcesGeneral.qrc
${CPP_FILES}
mobile/modules/CppElements/page_view.hpp mobile/modules/CppElements/page_view.cpp
mobile/modules/CppElements/presentation_export.hpp
)


Expand Down
20 changes: 16 additions & 4 deletions src/presentation/mobile/libraryPage/MBook.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import Librum.globals

Item {
id: root
property bool downloading: false
signal leftButtonClicked(int index)
signal rightButtonClicked(int index, var mouse)
signal moreOptionClicked(int index, var point)
signal clicked

implicitWidth: 120
implicitHeight: 190
Expand All @@ -29,6 +26,17 @@ Item {
Layout.fillHeight: true
color: Style.colorBookImageBackground

Image {
id: downloadBookIcon
anchors.centerIn: parent
visible: !model.downloaded
sourceSize.width: 32
fillMode: Image.PreserveAspectFit
source: Icons.downloadSelected
opacity: 1
z: 3
}

ColumnLayout {
id: upperPartLayout
anchors.centerIn: parent
Expand Down Expand Up @@ -87,6 +95,10 @@ Item {
}
}

TapHandler {
onTapped: root.clicked()
}

function giveFocus() {
root.forceActiveFocus()
}
Expand Down
20 changes: 19 additions & 1 deletion src/presentation/mobile/libraryPage/MLibraryPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import QtQuick.Layouts
import Librum.style
import Librum.fonts
import Librum.controllers
import Librum.globals
import CustomComponents

Page {
Expand Down Expand Up @@ -43,7 +44,24 @@ Page {
maximumFlickVelocity: 2500
clip: true
model: LibraryController.libraryModel
delegate: MBook {}
delegate: MBook {
id: bookDelegate

onClicked: {
if (model.downloaded) {
Globals.selectedBook = LibraryController.getBook(
model.uuid)
BookController.setUp(Globals.selectedBook.uuid)

LibraryController.refreshLastOpenedFlag(
Globals.selectedBook.uuid)

loadPage(readingPage)
} else {
LibraryController.downloadBookMedia(model.uuid)
}
}
}
}

ScrollBar {
Expand Down
16 changes: 15 additions & 1 deletion src/presentation/mobile/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "registerPage"
import "navbar"
import "libraryPage"
import "explorePage"
import "readingPage"
import "profilePage"
import "myAccountPage"

Expand All @@ -19,6 +20,15 @@ ApplicationWindow {
visibility: Window.Maximized
title: qsTr("Librum")

onClosing: {
if (stackView.depth > 2) {
close.accepted = false
let item = stackView.pop()
} else {
return
}
}

ColumnLayout {
anchors.fill: parent
spacing: 0
Expand Down Expand Up @@ -63,6 +73,10 @@ ApplicationWindow {
id: homePage
MLibraryPage {}
}
Component {
id: readingPage
MReadingPage {}
}
Component {
id: explorePage
MExplorePage {}
Expand Down Expand Up @@ -90,6 +104,6 @@ ApplicationWindow {
navbar.currentItem = navbarItem
}

stackView.replace(page)
stackView.push(page)
}
}
Loading

0 comments on commit bb0707d

Please sign in to comment.