Adjust splitter when initially loading PDF Document

Closes: #4

After consideration, we don't want to change the size of the dialog
which is the only way to make it fit the PDF.

But the geometry is saved, so the user can resize and place it.

We did set the splitter to give more space to the PDF.
This commit is contained in:
Christopher T. Johnson
2025-02-26 11:00:00 -05:00
parent e1d1946fa5
commit f952879753

View File

@@ -1,7 +1,7 @@
import math
from PySide6.QtCore import QFile, QModelIndex, QPoint, Signal, Slot
from PySide6.QtGui import QCloseEvent
from PySide6.QtCore import QFile, QModelIndex, QPoint, QSize, Signal, Slot
from PySide6.QtGui import QCloseEvent, QGuiApplication
from PySide6.QtPdf import QPdfBookmarkModel, QPdfDocument
from PySide6.QtPdfWidgets import QPdfView
from PySide6.QtWidgets import QComboBox, QDialog, QMenuBar, QSpinBox, QWidget
@@ -103,7 +103,7 @@ class PDFViewer(QDialog, Ui_pdfViewer):
self.pdfView.setZoomFactor
)
self.zoomSelector.reset()
bookmark_model = QPdfBookmarkModel(self)
bookmark_model.setDocument(self.document)
@@ -118,16 +118,13 @@ class PDFViewer(QDialog, Ui_pdfViewer):
return
def closeEvent(self, event: QCloseEvent) -> None:
print("closeEvent")
writeGeometry(self)
super().closeEvent(event)
return
@Slot(QFile) # type: ignore
def open(self, file: QFile) -> None:
# assert file.exists()
# if not file.isOpen():
# file.open(QFile.OpenModeFlag.ReadOnly)
# self.document.load(file)
self.document.load(file.fileName())
document_title = self.document.metaData(
QPdfDocument.MetaDataField.Title
@@ -135,6 +132,12 @@ class PDFViewer(QDialog, Ui_pdfViewer):
self.setWindowTitle(document_title if document_title else "PDF Viewer")
self.page_selected(0)
self.pageSelector.setMaximum(self.document.pageCount() - 1)
if self.zoomSelector.currentIndex() == 8:
pageSize = self.document.pagePointSize(0)
dpi = QGuiApplication.primaryScreen().physicalDotsPerInch()
size = QSize(int(pageSize.width()/72*dpi),self.pdfView.height())
self.pdfView.resize(size)
self.splitter.setSizes([100, size.width()])
return
@Slot(QModelIndex) # type: ignore