-
Notifications
You must be signed in to change notification settings - Fork 363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make grid options and two others available to the embedded pdf-viewer #3942
Changes from 2 commits
7f83e03
043ec94
1a65c06
59a4ca1
b971f45
6ad8a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -896,7 +896,7 @@ void PDFWidget::setPDFDocument(PDFDocument *docu) | |
pdfdocument = docu; | ||
} | ||
|
||
void PDFWidget::setDocument(const QSharedPointer<Poppler::Document> &doc) | ||
void PDFWidget::setDocument(const QSharedPointer<Poppler::Document> &doc, bool embedded) | ||
{ | ||
pages.clear(); | ||
document = doc; | ||
|
@@ -906,7 +906,10 @@ void PDFWidget::setDocument(const QSharedPointer<Poppler::Document> &doc) | |
|
||
if (!document.isNull()) { | ||
docPages = document->numPages(); | ||
setSinglePageStep(globalConfig->singlepagestep); | ||
if (embedded) | ||
setSinglePageStep(false); | ||
else | ||
setSinglePageStep(globalConfig->singlepagestep); | ||
} else | ||
docPages = 0; | ||
#ifdef MEDIAPLAYER | ||
|
@@ -1586,9 +1589,16 @@ void PDFWidget::contextMenuEvent(QContextMenuEvent *event) | |
usingTool = kNone; | ||
} | ||
|
||
if (pdfDoc && pdfDoc->menuShow) { | ||
menu.addSeparator(); | ||
menu.addMenu(pdfDoc->menuShow); | ||
if (pdfDoc) { | ||
if (pdfDoc->menuGrid || pdfDoc->menuShow) { | ||
menu.addSeparator(); | ||
if (pdfDoc->menuGrid) { | ||
menu.addMenu(pdfDoc->menuGrid); | ||
} | ||
if (pdfDoc->menuShow) { | ||
menu.addMenu(pdfDoc->menuShow); | ||
} | ||
} | ||
} | ||
|
||
QAction *action = menu.exec(event->globalPos()); | ||
|
@@ -2098,10 +2108,14 @@ void PDFWidget::setPageOffset(int offset, bool setAsDefault, bool refresh){ | |
pageOffset = offset; | ||
else { | ||
pageOffset = gridx - 1; | ||
globalConfig->pageOffset = pageOffset; | ||
} | ||
if (!setAsDefault) | ||
globalConfig->pageOffset = pageOffset; | ||
if (!setAsDefault) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the setAsDefault was the way of distinguishing embedded/windowed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. as explained above there are cases where |
||
bool embedded = pdfdocument->embeddedMode; | ||
if (embedded) | ||
pageOffsetEmbedded = pageOffset; | ||
else | ||
globalConfig->pageOffset = pageOffset; | ||
} | ||
|
||
if (!refresh) | ||
return; | ||
|
@@ -2132,16 +2146,23 @@ int PDFWidget::getPageOffset() const | |
|
||
void PDFWidget::setGridSize(int gx, int gy, bool setAsDefault) | ||
{ | ||
bool embedded = pdfdocument->embeddedMode; | ||
if (gridx == gx && gridy == gy) | ||
return; | ||
gridx = gx; | ||
gridy = gy; | ||
if (gridx == 1) | ||
if (gridx == 1) { | ||
setPageOffset(0, true, true); | ||
else if (gridx == 2 && gridy == 1) | ||
} | ||
else if (gridx == 2 && gridy == 1) { | ||
setPageOffset(1, false, true); | ||
else | ||
} | ||
else if (!embedded) { | ||
setPageOffset(globalConfig->pageOffset, true, true); | ||
} | ||
else { | ||
setPageOffset(pageOffsetEmbedded, true, true); | ||
} | ||
|
||
if (setAsDefault) | ||
return; | ||
|
@@ -2199,7 +2220,15 @@ int PDFWidget::pageStep() | |
*/ | ||
int PDFWidget::gridCols(bool fromConfig) const | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like above |
||
{ | ||
int result= fromConfig ? globalConfig->gridx : gridx; | ||
int result; | ||
if (!fromConfig) | ||
result = gridx; | ||
else { | ||
if (pdfdocument->embeddedMode) | ||
result = gridxEmbedded; | ||
else | ||
result = globalConfig->gridx; | ||
} | ||
return result; | ||
} | ||
/*! | ||
|
@@ -2209,7 +2238,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; | ||
} | ||
|
||
|
@@ -2453,7 +2490,7 @@ void PDFWidget::fitTextWidth(bool checked) | |
if (!textRect.isValid()) return; | ||
qreal targetWidth = maxPageSizeFDpiAdjusted().width() * (gridx - 1) + textRect.width() * dpi / 72.0; | ||
//qreal targetWidth = textRect.width() * dpi / 72.0; | ||
// total with of all pages in the grid - textMargin of a single page | ||
// total width of all pages in the grid - textMargin of a single page | ||
// for a 1x grid, targetWith is the same as textRect.width() | ||
scaleFactor = portWidth / ((targetWidth ) + 2 * margin); | ||
if (scaleFactor < kMinScaleFactor) | ||
|
@@ -2478,8 +2515,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; | ||
|
@@ -2919,7 +2959,7 @@ PDFDocument::~PDFDocument() | |
/*! | ||
* \brief setup ToolBar | ||
*/ | ||
void PDFDocument::setupToolBar(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused, please remove change (here it shows the original side of code) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing argument |
||
void PDFDocument::setupToolBar(bool embedded){ | ||
toolBar = new QToolBar(this); | ||
toolBar->setWindowTitle(tr("Toolbar")); | ||
toolBar->setObjectName(QString("toolBar")); | ||
|
@@ -2949,7 +2989,7 @@ void PDFDocument::setupToolBar(){ | |
toolBar->addAction(actionFit_to_Text_Width); | ||
toolBar->addAction(actionFit_to_Window); | ||
toolBar->addSeparator(); | ||
toolBar->addAction(actionAutoHideToolbars); | ||
toolBar->addAction(actionAutoHideToolbars); | ||
toolBar->addAction(actionEnlargeViewer); | ||
toolBar->addAction(actionShrinkViewer); | ||
toolBar->addAction(actionToggleEmbedded); | ||
|
@@ -3072,6 +3112,9 @@ void PDFDocument::setupMenus(bool embedded) | |
actionGroupGrid->addAction(actionCustom); | ||
menuGrid->addSeparator(); | ||
actionSinglePageStep=configManager->newManagedAction(menuroot,menuGrid, "singlePageStep", tr("Single Page Step"), pdfWidget, SLOT(setSinglePageStep(bool)), QList<QKeySequence>()); | ||
// if (embedded) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused code, please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
menuGrid->addAction(actionContinuous); | ||
// } | ||
menuWindow->addAction(menuShow->menuAction()); | ||
#if (QT_VERSION > 0x050a00) && (defined(Q_OS_MAC)) | ||
actionCloseElement=configManager->newManagedAction(menuroot,menuWindow, "closeElement", tr("&Close something"), this, SLOT(closeElement()), QList<QKeySequence>()); // osx work around | ||
|
@@ -3144,10 +3187,9 @@ void PDFDocument::init(bool embedded) | |
pdfWidget = new PDFWidget(embedded); // needs to be initialized before setup menu | ||
pdfWidget->setPDFDocument(this); | ||
|
||
//if (!embedded) | ||
setupMenus(embedded); | ||
|
||
setupToolBar(); | ||
setupToolBar(embedded); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is done |
||
|
||
|
||
setAttribute(Qt::WA_DeleteOnClose, true); | ||
|
@@ -3369,10 +3411,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->setPageOffset(0, true); | ||
pdfWidget->setSinglePageStep(true); | ||
pdfWidget->setGridxEmbedded(1); | ||
pdfWidget->setGridyEmbedded(1); | ||
pdfWidget->setGridSize(pdfWidget->getGridxEmbedded(), pdfWidget->getGridyEmbedded(), true); | ||
pdfWidget->setPageOffsetEmbedded(0); | ||
pdfWidget->setSinglePageStep(false); | ||
scrollArea->setContinuous(true); | ||
connect(actionContinuous, SIGNAL(toggled(bool)), scrollArea, SLOT(setContinuous(bool))); | ||
} | ||
|
||
//connect(actionZoom_In, SIGNAL(triggered()), pdfWidget, SLOT(zoomIn())); | ||
|
@@ -3696,11 +3741,11 @@ void PDFDocument::loadCurrentFile(bool fillCache) | |
break; // message is handled via messageFrame | ||
} | ||
pdfWidget->hide(); | ||
pdfWidget->setDocument(document); | ||
pdfWidget->setDocument(document, embeddedMode); | ||
if (error == PDFRenderManager::FileIncomplete) | ||
reloadWhenIdle(); | ||
} else { | ||
pdfWidget->setDocument(document); | ||
pdfWidget->setDocument(document, embeddedMode); | ||
pdfWidget->show(); | ||
|
||
annotations = new PDFAnnotations(this); | ||
|
@@ -3805,11 +3850,20 @@ void PDFDocument::setGrid() | |
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){ | ||
|
@@ -3824,9 +3878,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(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,7 +182,7 @@ class PDFWidget : public QLabel | |
explicit PDFWidget(bool embedded = false); | ||
virtual ~PDFWidget(); | ||
|
||
void setDocument(const QSharedPointer<Poppler::Document> &doc); | ||
void setDocument(const QSharedPointer<Poppler::Document> &doc, bool embedded); | ||
void setPDFDocument(PDFDocument *docu); | ||
|
||
void saveState(); // used when toggling full screen mode | ||
|
@@ -232,6 +232,14 @@ class PDFWidget : public QLabel | |
Q_INVOKABLE void zoom(qreal scale); | ||
|
||
virtual void wheelEvent(QWheelEvent *event); | ||
int getGridxEmbedded() {return gridxEmbedded;}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this concepts does not comply with the general idea of object oriented programming. So the issue is that you want to overwrite the global config for the grid.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea of setting grid to 1x1 without changes to the original config turns out to be problematic. When continuous mode is switched off, the grid size is restored from the config, resulting in unexpected grid changes for the user. This is independent of whether the imbedded and windowed viewer use the same or different configurations. |
||
int getGridyEmbedded() {return gridyEmbedded;}; | ||
int getPageOffsetEmbedded() {return pageOffsetEmbedded;}; | ||
bool getSinglePageStepEmbedded() {return singlePageStepEmbedded;}; | ||
void setGridxEmbedded(int x) {gridxEmbedded=x;}; | ||
void setGridyEmbedded(int y) {gridyEmbedded=y;}; | ||
void setPageOffsetEmbedded(int o) {pageOffsetEmbedded=o;}; | ||
void setSinglePageStepEmbedded(bool s) {singlePageStepEmbedded=s;}; | ||
|
||
protected slots: //not private, so scripts have access | ||
void goFirst(); | ||
|
@@ -324,7 +332,6 @@ public slots: | |
QSharedPointer<Poppler::Document> document; | ||
QMutex textwidthCalculationMutex; | ||
|
||
//QList<int> pages; | ||
QSharedPointer<Poppler::Link> clickedLink; | ||
QSharedPointer<Poppler::Annotation> clickedAnnotation; | ||
|
||
|
@@ -363,9 +370,10 @@ public slots: | |
#endif | ||
int currentTool; // the current tool selected in the toolbar | ||
int usingTool; // the tool actually being used in an ongoing mouse drag | ||
bool singlePageStep; | ||
bool singlePageStep, singlePageStepEmbedded; | ||
|
||
int gridx, gridy, pageOffset; | ||
int gridxEmbedded, gridyEmbedded, pageOffsetEmbedded; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the need for extra variables to keep a state (grid setting) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a missunderstanding. The |
||
|
||
bool forceUpdate; | ||
|
||
|
@@ -561,8 +569,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(); | ||
|
||
|
@@ -590,7 +598,6 @@ private slots: | |
QMenu *menuFile; | ||
QMenu *menuEdit; | ||
QMenu *menuView; | ||
QMenu *menuGrid; | ||
QMenu *menuWindow; | ||
QList<QMenu *>menus; | ||
|
||
|
@@ -675,8 +682,10 @@ private slots: | |
|
||
QStatusBar *statusbar; | ||
QToolBar *toolBar; | ||
QToolBar *tbPdfView; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused, please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. indeed, and change to definition of setupToolBar must also be removed. This is done. |
||
QTimer *toolBarTimer; | ||
public: | ||
QMenu *menuGrid; | ||
QMenu *menuShow; | ||
private: | ||
QMenu *menuEdit_2; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overly complicated code
apart from the fact the the pointers are not zeroed in the first place, there is no case when only one of the two appears.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simplified and assinged nullptr in headerfile