Открыть боковую панель
Aurora OS
Libraries
AmberPDF QML Plugin
Коммиты
1e31b078
Коммит
1e31b078
создал
Окт 16, 2023
по автору
OMP Education
Зафиксировано автором
k.sagalakova
Фев 15, 2024
Просмотр файлов
[View] Add option to change page aspect ratio.
Co-Authored-By:
Kira Sagalakova
<
k.sagalakova@omp.ru
>
владелец
3f704540
Изменения
6
Скрыть пробелы
Построчно
Рядом
plugin/PdfView.qml
Просмотр файла @
1e31b078
...
...
@@ -28,6 +28,7 @@ Rectangle {
property
alias
pagesWithNotesModel
:
pdfView
.
pagesWithNotesModel
property
alias
pageNumberComponent
:
pdfView
.
pageNumberComponent
property
alias
grayScaleRendering
:
pdfView
.
grayScaleRendering
property
alias
pageAspectRatio
:
pdfView
.
pageAspectRatio
signal
clicked
()
signal
clickedUrl
(
string
url
)
...
...
plugin/plugins.qmltypes
Просмотр файла @
1e31b078
...
...
@@ -95,6 +95,7 @@ Module {
Property { name: "pageRange"; type: "string" }
Property { name: "pageNumberComponent"; type: "QQmlComponent"; isPointer: true }
Property { name: "grayScaleRendering"; type: "bool" }
Property { name: "pageAspectRatio"; type: "float" }
Property { name: "status"; type: "BaseDocument::DocumentStatus"; isReadonly: true }
Property { name: "contentTopMargin"; type: "float"; isReadonly: true }
Property { name: "bookmarksModel"; type: "BookmarksModel"; isReadonly: true; isPointer: true }
...
...
@@ -188,6 +189,10 @@ Module {
name: "grayScaleRenderingChanged"
Parameter { name: "grayScaleRendering"; type: "bool" }
}
Signal {
name: "pageAspectRatioChanged"
Parameter { name: "pageAspectRatio"; type: "float" }
}
Signal {
name: "statusChanged"
Parameter { name: "status"; type: "BaseDocument::DocumentStatus" }
...
...
@@ -275,6 +280,10 @@ Module {
name: "setGrayScaleRendering"
Parameter { name: "grayScaleRendering"; type: "bool" }
}
Method {
name: "setPageAspectRatio"
Parameter { name: "pageAspectRatio"; type: "float" }
}
Method {
name: "saveDocumentAs"
Parameter { name: "path"; type: "string" }
...
...
plugin/src/documentmapper.cpp
Просмотр файла @
1e31b078
...
...
@@ -14,7 +14,8 @@ DocumentMapper::DocumentMapper(QQuickItem *parent) : QQuickItem(parent),
m_contentHeight
(
0.0
),
m_contentWidth
(
0.0
),
m_lastPageActualSize
(
0.0
),
m_pagesNumberVisible
(
false
)
m_pagesNumberVisible
(
false
),
m_pageAspectRatio
(
1.0
)
{
connect
(
this
,
&
DocumentMapper
::
widthChanged
,
this
,
&
DocumentMapper
::
_mapPages
);
connect
(
this
,
&
DocumentMapper
::
heightChanged
,
this
,
&
DocumentMapper
::
_mapPages
);
...
...
@@ -88,14 +89,18 @@ void DocumentMapper::setDocumentProvider(BaseDocument *documentProvider)
qreal
originalPageStartX
=
0.0
;
qreal
originalPageStartY
=
0.0
;
bool
isNeedeRecalcWidth
=
qFuzzyCompare
(
static_cast
<
double
>
(
m_pageAspectRatio
),
static_cast
<
double
>
(
1.0
));
for
(
int
i
=
0
;
i
<
pageCount
;
++
i
)
{
auto
pageSize
=
m_documentProvider
->
pageSize
(
i
);
auto
pageWidth
=
isNeedeRecalcWidth
?
pageSize
.
width
()
:
pageSize
.
height
()
*
m_pageAspectRatio
;
m_originalPagesMap
.
pages
.
append
({
originalPageStartX
,
originalPageStartY
,
originalPageStartX
+
page
Size
.
w
idth
()
,
originalPageStartY
+
pageSize
.
height
()});
originalPageStartX
+=
page
Size
.
w
idth
()
;
originalPageStartY
,
originalPageStartX
+
page
W
idth
,
originalPageStartY
+
pageSize
.
height
()});
originalPageStartX
+=
page
W
idth
;
originalPageStartY
+=
pageSize
.
height
();
}
...
...
@@ -132,6 +137,16 @@ void DocumentMapper::setPagesNumberVisible(bool visible)
_mapPages
();
}
void
DocumentMapper
::
setPageAspectRatio
(
qreal
pageAspectRatio
)
{
if
(
qFuzzyCompare
(
static_cast
<
double
>
(
m_pageAspectRatio
),
static_cast
<
double
>
(
pageAspectRatio
)))
return
;
m_pageAspectRatio
=
pageAspectRatio
;
if
(
!
m_originalPagesMap
.
pages
.
empty
())
_mapPages
();
}
void
DocumentMapper
::
_mapPages
()
{
if
(
width
()
<=
0
||
height
()
<=
0
)
...
...
@@ -265,6 +280,11 @@ int DocumentMapper::maxSpecialIndex() const
return
std
::
min
(
std
::
max
(
firstMax
,
it
->
second
),
m_originalPagesMap
.
pages
.
size
()
-
1
);
}
qreal
DocumentMapper
::
pageAspectRatio
()
const
{
return
m_pageAspectRatio
;
}
PagePosition
DocumentMapper
::
actualPagePosition
(
int
pageIndex
)
const
{
if
(
!
m_actualPagesCoordinates
.
contains
(
pageIndex
))
...
...
plugin/src/documentmapper.h
Просмотр файла @
1e31b078
...
...
@@ -36,6 +36,7 @@ public:
bool
isHasSpecial
()
const
;
int
minSpecialIndex
()
const
;
int
maxSpecialIndex
()
const
;
qreal
pageAspectRatio
()
const
;
public
slots
:
void
setDocumentProvider
(
BaseDocument
*
documentProvider
);
...
...
@@ -43,6 +44,7 @@ public slots:
void
setSpecialPageIndexes
(
const
std
::
map
<
int
,
int
>
&
specialRangeIndexes
,
const
std
::
set
<
int
>
&
specialIndexes
);
void
setPagesNumberVisible
(
bool
visible
);
void
setPageAspectRatio
(
qreal
pageAspectRatio
);
signals:
void
contentWidthChanged
(
qreal
);
...
...
@@ -65,6 +67,7 @@ private:
std
::
set
<
int
>
m_specialIndexes
;
std
::
map
<
int
,
int
>
m_spacialRangeIndexes
;
bool
m_pagesNumberVisible
;
qreal
m_pageAspectRatio
;
};
#endif // DOCUMENTMAPPER_H
plugin/src/pdfview.cpp
Просмотр файла @
1e31b078
...
...
@@ -32,7 +32,8 @@ PdfView::PdfView(QQuickItem *parent) : QQuickItem(parent),
m_documentEdited
(
false
),
m_pagesWithNotesModel
(
nullptr
),
m_pageNumberComponent
(
nullptr
),
m_grayScaleRendering
(
false
)
m_grayScaleRendering
(
false
),
m_pageAspectRatio
(
1.0
)
{
setFlag
(
QQuickItem
::
ItemHasContents
,
true
);
setFlag
(
QQuickItem
::
ItemAcceptsInputMethod
,
true
);
...
...
@@ -318,6 +319,11 @@ QString PdfView::pageRange() const
return
m_pageRange
;
}
qreal
PdfView
::
pageAspectRatio
()
const
{
return
m_pageAspectRatio
;
}
BaseDocument
::
DocumentStatus
PdfView
::
status
()
const
{
return
m_documentProvider
==
nullptr
?
BaseDocument
::
DocumentStatus
::
Null
:
m_documentProvider
->
status
();
...
...
@@ -513,6 +519,7 @@ void PdfView::setDocumentProvider(BaseDocument *documentProvider)
connect
(
m_documentProvider
,
&
BaseDocument
::
statusChanged
,
this
,
[
this
](
BaseDocument
::
DocumentStatus
status
)
{
if
(
status
==
BaseDocument
::
DocumentStatus
::
Ready
)
{
m_mapper
->
setPagesNumberVisible
(
m_pageNumberComponent
?
true
:
false
);
m_mapper
->
setPageAspectRatio
(
m_pageAspectRatio
);
m_mapper
->
setDocumentProvider
(
m_documentProvider
);
m_count
=
m_documentProvider
->
count
();
m_documentProvider
->
startLoadBookmarks
();
...
...
@@ -590,6 +597,15 @@ void PdfView::setGrayScaleRendering(bool grayScaleRendering)
emit
grayScaleRenderingChanged
(
m_grayScaleRendering
);
}
void
PdfView
::
setPageAspectRatio
(
qreal
pageAspectRatio
)
{
if
(
qFuzzyCompare
(
static_cast
<
double
>
(
m_pageAspectRatio
),
static_cast
<
double
>
(
pageAspectRatio
)))
return
;
m_pageAspectRatio
=
pageAspectRatio
;
emit
pageAspectRatioChanged
(
m_pageAspectRatio
);
}
void
PdfView
::
_updateContentSize
()
{
if
(
!
qFuzzyCompare
(
double
(
m_contentWidth
),
double
(
m_mapper
->
contentWidth
()))
&&
m_mapper
->
contentWidth
()
>
0.0
f
)
{
...
...
plugin/src/pdfview.h
Просмотр файла @
1e31b078
...
...
@@ -41,6 +41,7 @@ class PdfView : public QQuickItem
Q_PROPERTY
(
PagesWithNotesModel
*
pagesWithNotesModel
READ
pagesWithNotesModel
NOTIFY
pagesWithNotesModelChanged
)
Q_PROPERTY
(
QQmlComponent
*
pageNumberComponent
READ
pageNumberComponent
WRITE
setPageNumberComponent
NOTIFY
pageNumberComponentChanged
)
Q_PROPERTY
(
bool
grayScaleRendering
READ
grayScaleRendering
WRITE
setGrayScaleRendering
NOTIFY
grayScaleRenderingChanged
)
Q_PROPERTY
(
qreal
pageAspectRatio
READ
pageAspectRatio
WRITE
setPageAspectRatio
NOTIFY
pageAspectRatioChanged
)
public:
explicit
PdfView
(
QQuickItem
*
parent
=
nullptr
);
...
...
@@ -65,6 +66,7 @@ public:
QString
pdfPath
()
const
;
QString
pageRange
()
const
;
bool
grayScaleRendering
()
const
;
qreal
pageAspectRatio
()
const
;
BaseDocument
::
DocumentStatus
status
()
const
;
qreal
contentTopMargin
()
const
;
BookmarksModel
*
bookmarksModel
()
const
;
...
...
@@ -96,6 +98,7 @@ public slots:
void
setPageRange
(
const
QString
&
pageRange
);
void
setPageNumberComponent
(
QQmlComponent
*
pageNumberComponent
);
void
setGrayScaleRendering
(
bool
grayScaleRendering
);
void
setPageAspectRatio
(
qreal
pageAspectRatio
);
signals:
void
modelChanged
(
QObject
*
model
);
...
...
@@ -130,6 +133,7 @@ signals:
void
pagesWithNotesModelChanged
(
PagesWithNotesModel
*
pagesWithNotesModel
);
void
pageNumberComponentChanged
(
QQmlComponent
*
pageNumberComponent
);
void
grayScaleRenderingChanged
(
bool
grayScaleRendering
);
void
pageAspectRatioChanged
(
qreal
pageAspectRatio
);
private
slots
:
void
_updateContentSize
();
...
...
@@ -173,6 +177,7 @@ private:
QHash
<
int
,
QQuickItem
*>
m_pageNumberItems
;
QQmlComponent
*
m_pageNumberComponent
;
bool
m_grayScaleRendering
;
qreal
m_pageAspectRatio
;
};
#endif // PDFVIEW_H
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать