CCIMXDesktop
 
Loading...
Searching...
No Matches
ccpdfdocument.h
1#ifndef CCPDFDOCUMENT_H
2#define CCPDFDOCUMENT_H
3
4#include "mupdf_tools/mupdf_tools.h"
5#include <QObject>
6#include <optional>
7
8/*
9 * Forward declarations related to MuPDF C API.
10 * fz_context manages the global MuPDF context.
11 * fz_document represents a loaded PDF document.
12 */
13struct fz_context;
14struct fz_document;
16
24class CCPdfDocument : public QObject {
25 Q_OBJECT
26public:
31 explicit CCPdfDocument(QObject* parent = nullptr);
32
37 explicit CCPdfDocument(const QString& document_path);
38
49
54 enum class ErrorCode {
55 NO_ERROR,
58 };
59
66 ErrorCode load_document(const QString& document_path);
67
73 bool close_document();
74
80 bool document_loaded() const;
81
87 std::optional<uint32_t> document_page() const;
88
94 fz_document* raw_handle() const;
95
101 fz_context* raw_context() const;
102
108 CCPdfMetaInfo meta_info() const;
109
117 inline int current_page() const { return current_page_index; }
118
124 inline QString current_path() const { return holding_path; }
125
131 inline int total_pages() const { return total_page; }
132
143
150 PageNavigationError jump(const int page_index);
151
152signals:
158 void document_load(const QString document_path);
159
166
167private:
168 CCPdfDocumentPrivate* privated;
169 QString holding_path;
170 int current_page_index { -1 };
171 int total_page { -1 };
172};
173
174#endif // CCPDFDOCUMENT_H
The CCPdfDocument class CCPdfDocument manages the lifetime and access to a PDF document....
Definition ccpdfdocument.h:24
PageNavigationError
PageNavigationError Enum representing errors when navigating pages.
Definition ccpdfdocument.h:137
@ PAGE_OVERFLOW
Page index beyond last page.
@ PAGE_OK
Navigation successful.
@ PAGE_UNEXSITS
Specified page does not exist.
@ PAGE_UNDERFLOW
Page index below first page.
fz_document * raw_handle() const
raw_handle Gets the raw pointer to the underlying MuPDF document.
Definition ccpdfdocument.cpp:125
fz_context * raw_context() const
raw_context Gets the raw pointer to the MuPDF context.
Definition ccpdfdocument.cpp:129
int total_pages() const
total_pages Gets the total number of pages in the loaded document.
Definition ccpdfdocument.h:131
bool document_loaded() const
document_loaded Checks if a document is currently loaded.
Definition ccpdfdocument.cpp:75
ErrorCode
ErrorCode Enum describing possible error codes during document operations.
Definition ccpdfdocument.h:54
@ FILE_NOT_EXSIT
File does not exist.
@ OTHER_MISTAKES
Other unspecified errors.
@ NO_ERROR
No error occurred.
bool close_document()
close_document Closes the currently loaded document.
Definition ccpdfdocument.cpp:103
~CCPdfDocument()
Destructor. Releases resources associated with the document.
Definition ccpdfdocument.cpp:159
CCPdfMetaInfo meta_info() const
meta_info Retrieves metadata information from the loaded document.
Definition ccpdfdocument.cpp:133
PageNavigationError jump(const int page_index)
jump Attempts to jump to a specified page index.
Definition ccpdfdocument.cpp:138
int current_page() const
current_page Gets the current page index.
Definition ccpdfdocument.h:117
void pageIndexChanged()
pageIndexChanged Signal emitted when the current page index changes. Used for lightweight UI updates ...
std::optional< uint32_t > document_page() const
document_page Gets the total number of pages in the loaded document.
Definition ccpdfdocument.cpp:116
void document_load(const QString document_path)
document_load Signal emitted when a document is successfully loaded.
QString current_path() const
current_path Gets the file path of the currently loaded document.
Definition ccpdfdocument.h:124
ErrorCode load_document(const QString &document_path)
load_document Loads a PDF document from the specified path.
Definition ccpdfdocument.cpp:80
Q_DISABLE_COPY(CCPdfDocument)
disable copy object
CCPdfDocumentPrivate holders.
Definition ccpdfdocument.cpp:23
CCPdfMetaInfo Holds metadata extracted from a PDF document.
Definition mupdf_tools.h:31