Skip to content

Commit

Permalink
add toolbutton grid actions to embedded pdf-viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
octaeder committed Jan 1, 2025
1 parent 3a16a7d commit 4f34a39
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 17 deletions.
79 changes: 64 additions & 15 deletions src/pdfviewer/PDFDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2199,7 +2199,15 @@ int PDFWidget::pageStep()
*/
int PDFWidget::gridCols(bool fromConfig) const
{
int result= fromConfig ? globalConfig->gridx : gridx;
int result;
if (!fromConfig)
result = gridx;
else {
if (pdfdocument->embeddedMode)
result = gridxEmbedded;
else
result = globalConfig->gridx;
}
return result;
}
/*!
Expand All @@ -2209,7 +2217,15 @@ int PDFWidget::gridCols(bool fromConfig) const
*/
int PDFWidget::gridRows(bool fromConfig) const
{
int result= fromConfig ? globalConfig->gridy : gridy;
int result;
if (!fromConfig)
result = gridy;
else {
if (pdfdocument->embeddedMode)
result = gridyEmbedded;
else
result = globalConfig->gridy;
}
return result;
}

Expand Down Expand Up @@ -2478,8 +2494,11 @@ void PDFWidget::fitWindow(bool checked)
PDFScrollArea *scrollArea = getScrollArea();
if (scrollArea && !pages.isEmpty()) {
qreal portWidth = scrollArea->viewport()->width() - GridBorder * (gridx - 1);
int gy=globalConfig->gridy;
if(pdfdocument->embeddedMode) gy=1;
int gy;
if(pdfdocument->embeddedMode)
gy=gridyEmbedded;
else
gy=globalConfig->gridy;
qreal portHeight = scrollArea->viewport()->height() - GridBorder * (gy - 1); // use globalConfig->gridy as gridy is automatically increased in continous mode to force rendering of surrounding pages
QSizeF pageSize = maxPageSizeFDpiAdjusted();
qreal sfh = portWidth / pageSize.width() / gridx;
Expand Down Expand Up @@ -2920,7 +2939,7 @@ PDFDocument::~PDFDocument()
/*!
* \brief setup ToolBar
*/
void PDFDocument::setupToolBar(){
void PDFDocument::setupToolBar(bool embedded){
toolBar = new QToolBar(this);
toolBar->setWindowTitle(tr("Toolbar"));
toolBar->setObjectName(QString("toolBar"));
Expand Down Expand Up @@ -2950,6 +2969,17 @@ void PDFDocument::setupToolBar(){
toolBar->addAction(actionFit_to_Text_Width);
toolBar->addAction(actionFit_to_Window);
toolBar->addSeparator();
if (embedded) {
QToolButton *tbPdfView = new QToolButton(toolBar);
actionContinuous->setCheckable(true);
actionContinuous->setChecked(true);
menuGrid->addAction(actionContinuous);
tbPdfView->setMenu(menuGrid);
tbPdfView->setPopupMode(QToolButton::MenuButtonPopup);
tbPdfView->setText(tr("View"));
toolBar->addWidget(tbPdfView);
toolBar->addSeparator();
}
toolBar->addAction(actionAutoHideToolbars);
toolBar->addAction(actionEnlargeViewer);
toolBar->addAction(actionShrinkViewer);
Expand Down Expand Up @@ -3148,7 +3178,7 @@ void PDFDocument::init(bool embedded)
//if (!embedded)
setupMenus(embedded);

setupToolBar();
setupToolBar(embedded);


setAttribute(Qt::WA_DeleteOnClose, true);
Expand Down Expand Up @@ -3370,10 +3400,13 @@ void PDFDocument::init(bool embedded)
conf->registerOption("Preview/Continuous", &globalConfig->continuous, true);
conf->linkOptionToObject(&globalConfig->continuous, actionContinuous, LO_NONE);
} else {
pdfWidget->setGridSize(1, 1, true);
pdfWidget->setGridxEmbedded(1);
pdfWidget->setGridyEmbedded(1);
pdfWidget->setGridSize(pdfWidget->getGridxEmbedded(), pdfWidget->getGridyEmbedded(), true);
pdfWidget->setPageOffset(0, true);
pdfWidget->setSinglePageStep(true);
scrollArea->setContinuous(true);
connect(actionContinuous, SIGNAL(toggled(bool)), scrollArea, SLOT(setContinuous(bool)));
}

//connect(actionZoom_In, SIGNAL(triggered()), pdfWidget, SLOT(zoomIn()));
Expand Down Expand Up @@ -3800,17 +3833,26 @@ void PDFDocument::setGrid()
QString gs = sender()->property("grid").toString();
if (gs == "xx") {
UniversalInputDialog d;
int x = pdfWidget->gridCols();
int y = pdfWidget->gridRows();
int x = pdfWidget->gridCols(true);
int y = pdfWidget->gridRows(true);
d.addVariable(&x , "X-Grid:");
d.addVariable(&y , "Y-Grid:");
if (d.exec()) {
pdfWidget->setGridSize(x, y);
globalConfig->gridx = x;
globalConfig->gridy = y;
if (embeddedMode) {
pdfWidget->setGridxEmbedded(x);
pdfWidget->setGridyEmbedded(y);
} else{
globalConfig->gridx = x;
globalConfig->gridy = y;
}
}
// set grid menu entry checked
QString gs=QString("%1x%2").arg(globalConfig->gridx).arg(globalConfig->gridy);
QString gs;
if (embeddedMode)
gs=QString("%1x%2").arg(pdfWidget->getGridxEmbedded()).arg(pdfWidget->getGridyEmbedded());
else
gs=QString("%1x%2").arg(globalConfig->gridx).arg(globalConfig->gridy);
bool found=false;
for(QAction *a:actionGroupGrid->actions()){
if(a->property("grid").toString()==gs){
Expand All @@ -3825,9 +3867,16 @@ void PDFDocument::setGrid()
}
} else {
int p = gs.indexOf("x");
globalConfig->gridx = gs.left(p).toInt();
globalConfig->gridy = gs.mid(p + 1).toInt();
pdfWidget->setGridSize(globalConfig->gridx, globalConfig->gridy);
int x = gs.left(p).toInt();
int y = gs.mid(p + 1).toInt();
pdfWidget->setGridSize(x, y);
if (embeddedMode) {
pdfWidget->setGridxEmbedded(x);
pdfWidget->setGridyEmbedded(y);
} else{
globalConfig->gridx = x;
globalConfig->gridy = y;
}
}
pdfWidget->windowResized();
}
Expand Down
10 changes: 8 additions & 2 deletions src/pdfviewer/PDFDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ class PDFWidget : public QLabel
Q_INVOKABLE void zoom(qreal scale);

virtual void wheelEvent(QWheelEvent *event);
int getGridxEmbedded() {return gridxEmbedded;};
int getGridyEmbedded() {return gridyEmbedded;};
void setGridxEmbedded(int x) {gridxEmbedded=x;};
void setGridyEmbedded(int y) {gridyEmbedded=y;};

protected slots: //not private, so scripts have access
void goFirst();
Expand Down Expand Up @@ -366,6 +370,7 @@ public slots:
bool singlePageStep;

int gridx, gridy, pageOffset;
int gridxEmbedded, gridyEmbedded;

bool forceUpdate;

Expand Down Expand Up @@ -561,8 +566,8 @@ private slots:

private:
void init(bool embedded = false);
void setupMenus(bool embedded);
void setupToolBar();
void setupMenus(bool embedded);
void setupToolBar(bool embedded);
void setCurrentFile(const QString &fileName);
void loadSyncData();

Expand Down Expand Up @@ -675,6 +680,7 @@ private slots:

QStatusBar *statusbar;
QToolBar *toolBar;
QToolBar *tbPdfView;
QTimer *toolBarTimer;
public:
QMenu *menuShow;
Expand Down

0 comments on commit 4f34a39

Please sign in to comment.