3
Copyright 2012 Adam Reichold
5
This file is part of qpdfview.
7
qpdfview is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 2 of the License, or
10
(at your option) any later version.
12
qpdfview is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
22
#include "mainwindow.h"
24
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
36
slotTabWidgetCurrentChanged(-1);
40
DocumentView::thumbnailWidth = m_settings.value("documentView/thumbnailWidth", 96.0).toReal();
41
DocumentView::thumbnailHeight = m_settings.value("documentView/thumbnailHeight", 144.0).toReal();
43
DocumentView::fitToEqualWidth = m_settings.value("documentView/fitToEqualWidth", false).toBool();
45
DocumentView::highlightLinks = m_settings.value("documentView/highlightLinks", true).toBool();
46
DocumentView::externalLinks = m_settings.value("documentView/externalLinks", false).toBool();
48
m_matchCaseCheckBox->setChecked(m_settings.value("mainWindow/matchCase", true).toBool());
50
restoreGeometry(m_settings.value("mainWindow/geometry").toByteArray());
51
restoreState(m_settings.value("mainWindow/state").toByteArray());
53
m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(m_settings.value("mainWindow/tabPosition", static_cast< uint >(m_tabWidget->tabPosition())).toUInt()));
57
if(m_settings.value("mainWindow/restoreTabs", false).toBool())
59
QStringList filePaths = m_settings.value("mainWindow/tabs/filePaths", QStringList()).toStringList();
60
QList< QVariant > currentPages = m_settings.value("mainWindow/tabs/currentPages", QList< QVariant >()).toList();
61
QList< QVariant > pageLayouts = m_settings.value("mainWindow/tabs/pageLayouts", QList< QVariant >()).toList();
62
QList< QVariant > scaleModes = m_settings.value("mainWindow/tabs/scaleModes", QList< QVariant >()).toList();
63
QList< QVariant > scaleFactors = m_settings.value("mainWindow/tabs/scaleFactors", QList< QVariant >()).toList();
64
QList< QVariant > rotations = m_settings.value("mainWindow/tabs/rotations", QList< QVariant >()).toList();
66
for(int index = 0; index < filePaths.count(); index++)
68
openInNewTab(filePaths.at(index));
70
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
72
documentView->setCurrentPage(currentPages.value(index, documentView->currentPage()).toInt());
73
documentView->setPageLayout(static_cast< DocumentView::PageLayout >(pageLayouts.value(index, static_cast< uint >(documentView->pageLayout())).toUInt()));
74
documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(scaleModes.value(index, static_cast< uint >(documentView->scaleMode())).toUInt()));
75
documentView->setScaleFactor(scaleFactors.value(index, documentView->scaleFactor()).toReal());
76
documentView->setRotation(static_cast< DocumentView::Rotation >(rotations.value(index, static_cast< uint >(documentView->rotation())).toUInt()));
79
m_tabWidget->setCurrentIndex(m_settings.value("mainWindow/tabs/currentIndex", -1).toInt());
83
QSize MainWindow::sizeHint() const
85
return QSize(500, 700);
88
QMenu* MainWindow::createPopupMenu()
90
QMenu* menu = new QMenu();
92
menu->addAction(m_fileToolBar->toggleViewAction());
93
menu->addAction(m_editToolBar->toggleViewAction());
94
menu->addAction(m_viewToolBar->toggleViewAction());
96
menu->addAction(m_outlineDock->toggleViewAction());
97
menu->addAction(m_metaInformationDock->toggleViewAction());
98
menu->addAction(m_thumbnailsDock->toggleViewAction());
103
bool MainWindow::open(const QString& filePath, int page, qreal top)
105
if(m_tabWidget->currentIndex() != -1)
107
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
109
if(documentView->open(filePath))
111
documentView->setCurrentPage(page, top);
117
QMessageBox::warning(this, tr("Warning"), tr("Could not open document \"%1\".").arg(QFileInfo(filePath).fileName()));
124
return openInNewTab(filePath, page, top);
128
bool MainWindow::openInNewTab(const QString& filePath, int page, qreal top)
130
DocumentView* documentView = new DocumentView();
132
if(documentView->open(filePath))
134
int index = m_tabWidget->addTab(documentView, QFileInfo(filePath).completeBaseName());
135
m_tabWidget->setTabToolTip(index, QFileInfo(filePath).completeBaseName());
136
m_tabWidget->setCurrentIndex(index);
138
m_tabMenu->addAction(documentView->tabAction());
140
connect(documentView, SIGNAL(filePathChanged(QString)), SLOT(slotFilePathChanged(QString)));
141
connect(documentView, SIGNAL(numberOfPagesChanged(int)), SLOT(slotNumberOfPagesChanged(int)));
143
connect(documentView, SIGNAL(currentPageChanged(int)), SLOT(slotCurrentPageChanged(int)));
145
connect(documentView, SIGNAL(searchProgressed(int)), SLOT(slotSearchProgressed(int)));
146
connect(documentView, SIGNAL(searchCanceled()), SLOT(slotSearchCanceled()));
147
connect(documentView, SIGNAL(searchFinished()), SLOT(slotSearchFinished()));
149
connect(documentView, SIGNAL(pageLayoutChanged(DocumentView::PageLayout)), SLOT(slotPageLayoutChanged(DocumentView::PageLayout)));
150
connect(documentView, SIGNAL(scaleModeChanged(DocumentView::ScaleMode)), SLOT(slotScaleModeChanged(DocumentView::ScaleMode)));
151
connect(documentView, SIGNAL(scaleFactorChanged(qreal)), SLOT(slotScaleFactorChanged(qreal)));
153
connect(documentView, SIGNAL(highlightAllChanged(bool)), SLOT(slotHighlightAllChanged(bool)));
155
documentView->setCurrentPage(page, top);
163
QMessageBox::warning(this, tr("Warning"), tr("Could not open document \"%1\".").arg(QFileInfo(filePath).fileName()));
169
void MainWindow::closeEvent(QCloseEvent*)
173
if(m_settings.value("mainWindow/restoreTabs", false).toBool())
175
QStringList filePaths;
176
QList< QVariant > currentPages;
177
QList< QVariant > pageLayouts;
178
QList< QVariant > scaleModes;
179
QList< QVariant > scaleFactors;
180
QList< QVariant > rotations;
182
for(int index = 0; index < m_tabWidget->count(); index++)
184
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index));
186
filePaths.append(QFileInfo(documentView->filePath()).absoluteFilePath());
187
currentPages.append(documentView->currentPage());
188
pageLayouts.append(static_cast< uint >(documentView->pageLayout()));
189
scaleModes.append(static_cast< uint >(documentView->scaleMode()));
190
scaleFactors.append(documentView->scaleFactor());
191
rotations.append(static_cast< uint >(documentView->rotation()));
194
m_settings.setValue("mainWindow/tabs/filePaths", filePaths);
195
m_settings.setValue("mainWindow/tabs/currentPages", currentPages);
196
m_settings.setValue("mainWindow/tabs/pageLayouts", pageLayouts);
197
m_settings.setValue("mainWindow/tabs/scaleModes", scaleModes);
198
m_settings.setValue("mainWindow/tabs/scaleFactors", scaleFactors);
199
m_settings.setValue("mainWindow/tabs/rotations", rotations);
201
m_settings.setValue("mainWindow/tabs/currentIndex", m_tabWidget->currentIndex());
205
m_settings.remove("mainWindow/tabs/filePaths");
206
m_settings.remove("mainWindow/tabs/currentPages");
207
m_settings.remove("mainWindow/tabs/pageLayouts");
208
m_settings.remove("mainWindow/tabs/scaleModes");
209
m_settings.remove("mainWindow/tabs/scaleFactors");
210
m_settings.remove("mainWindow/tabs/rotations");
212
m_settings.remove("mainWindow/tabs/currentIndex");
219
m_settings.setValue("mainWindow/matchCase", m_matchCaseCheckBox->isChecked());
221
if(m_fullscreenAction->isChecked())
223
m_settings.setValue("mainWindow/geometry", m_geometry);
227
m_settings.setValue("mainWindow/geometry", saveGeometry());
230
m_settings.setValue("mainWindow/state", saveState());
232
m_settings.setValue("mainWindow/tabPosition", static_cast< uint >(m_tabWidget->tabPosition()));
235
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
237
if(event->mimeData()->hasUrls())
239
event->acceptProposedAction();
243
void MainWindow::dropEvent(QDropEvent* event)
245
if(event->mimeData()->hasUrls())
247
event->acceptProposedAction();
249
foreach(QUrl url, event->mimeData()->urls())
251
if(url.scheme() == "file" && QFileInfo(url.path()).exists())
253
openInNewTab(url.path());
259
void MainWindow::keyPressEvent(QKeyEvent* event)
261
if(m_tabWidget->currentIndex() != -1)
263
QKeyEvent keyEvent(*event);
265
QApplication::sendEvent(m_tabWidget->currentWidget(), &keyEvent);
269
void MainWindow::slotOpen()
271
if(m_tabWidget->currentIndex() != -1)
273
QString filePath = QFileDialog::getOpenFileName(this, tr("Open document"),
274
m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString(),
275
"Portable Document Format (*.pdf)");
277
if(!filePath.isEmpty())
281
m_recentlyUsedAction->addEntry(filePath);
283
m_settings.setValue("mainWindow/path", QFileInfo(filePath).path());
293
void MainWindow::slotOpenInNewTab()
295
QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open documents"),
296
m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString(),
297
"Portable Document Format (*.pdf)");
299
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
301
foreach(QString filePath, filePaths)
303
if(openInNewTab(filePath))
305
m_recentlyUsedAction->addEntry(filePath);
307
m_settings.setValue("mainWindow/path", QFileInfo(filePath).path());
311
slotTabWidgetCurrentChanged(m_tabWidget->currentIndex());
313
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
316
void MainWindow::slotRecentyUsedActionEntrySelected(const QString& filePath)
321
void MainWindow::slotRefresh()
323
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
325
documentView->refresh();
328
void MainWindow::slotSaveCopy()
330
QString filePath = QFileDialog::getSaveFileName(this, tr("Save copy"),
331
m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString(),
332
"Portable Document Format (*.pdf)");
334
if(!filePath.isEmpty())
336
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
338
if(documentView->saveCopy(filePath))
340
m_settings.setValue("mainWindow/path", QFileInfo(filePath).path());
344
QMessageBox::warning(this, tr("Warning"), tr("Could not save copy at \"%1\".").arg(QFileInfo(filePath).filePath()));
349
void MainWindow::slotPrint()
351
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
353
QPrinter* printer = new QPrinter();
355
QPrintDialog printDialog(printer, this);
357
printDialog.setOptions(QAbstractPrintDialog::PrintDialogOptions());
358
printDialog.setOption(QAbstractPrintDialog::PrintCollateCopies, true);
359
printDialog.setOption(QAbstractPrintDialog::PrintPageRange, true);
361
printDialog.setMinMax(1, documentView->numberOfPages());
363
if(printDialog.exec() == QDialog::Accepted)
365
int fromPage = printDialog.fromPage() != 0 ? printDialog.fromPage() : 1;
366
int toPage = printDialog.toPage() != 0 ? printDialog.toPage() : documentView->numberOfPages();
368
QProgressDialog progressDialog;
370
progressDialog.setLabelText(tr("Printing pages %1 to %2...").arg(fromPage).arg(toPage));
371
progressDialog.setRange(0, 100);
372
progressDialog.setValue(0);
374
connect(documentView, SIGNAL(printProgressed(int)), &progressDialog, SLOT(setValue(int)));
375
connect(documentView, SIGNAL(printCanceled()), &progressDialog, SLOT(close()));
376
connect(documentView, SIGNAL(printFinished()), &progressDialog, SLOT(close()));
378
connect(&progressDialog, SIGNAL(canceled()), documentView, SLOT(cancelPrint()));
380
documentView->startPrint(printer, fromPage, toPage);
382
progressDialog.exec();
386
void MainWindow::slotPreviousPage()
388
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
390
documentView->previousPage();
393
void MainWindow::slotNextPage()
395
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
397
documentView->nextPage();
400
void MainWindow::slotFirstPage()
402
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
404
documentView->firstPage();
407
void MainWindow::slotLastPage()
409
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
411
documentView->lastPage();
414
void MainWindow::slotSearch()
416
if(m_searchToolBar->isHidden())
418
m_searchToolBar->show();
422
m_searchLineEdit->selectAll();
425
m_searchLineEdit->setFocus();
428
void MainWindow::slotStartSearch()
430
m_searchTimer->stop();
432
if(m_searchToolBar->isVisible() && !m_searchLineEdit->text().isEmpty())
434
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
436
documentView->startSearch(m_searchLineEdit->text(), m_matchCaseCheckBox->isChecked());
440
void MainWindow::slotSearchProgressed(int value)
442
QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
443
pos.rx() += 10; pos.ry() -= 50;
445
QToolTip::showText(pos, tr("Searched %1% of the the current document...").arg(value), centralWidget());
448
void MainWindow::slotSearchCanceled()
450
QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
451
pos.rx() += 10; pos.ry() -= 50;
453
QToolTip::showText(pos, tr("Search canceled."), centralWidget());
456
void MainWindow::slotSearchFinished()
458
QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
459
pos.rx() += 10; pos.ry() -= 50;
461
QToolTip::showText(pos, tr("Search finished."), centralWidget());
464
void MainWindow::slotFindPrevious()
466
if(m_tabWidget->currentIndex() != -1)
468
if(m_searchToolBar->isHidden())
470
m_searchToolBar->show();
471
m_searchLineEdit->setFocus();
475
if(!m_searchLineEdit->text().isEmpty())
477
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
479
documentView->findPrevious();
485
void MainWindow::slotFindNext()
487
if(m_tabWidget->currentIndex() != -1)
489
if(m_searchToolBar->isHidden())
491
m_searchToolBar->show();
492
m_searchLineEdit->setFocus();
496
if(!m_searchLineEdit->text().isEmpty())
498
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
500
documentView->findNext();
506
void MainWindow::slotCancelSearch()
508
m_searchLineEdit->clear();
509
m_searchTimer->stop();
510
m_searchToolBar->hide();
512
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
514
documentView->cancelSearch();
517
void MainWindow::slotSettings()
519
SettingsDialog settingsDialog;
521
if(settingsDialog.exec() == QDialog::Accepted)
523
DocumentView::fitToEqualWidth = m_settings.value("documentView/fitToEqualWidth", false).toBool();
525
DocumentView::highlightLinks = m_settings.value("documentView/highlightLinks", true).toBool();
526
DocumentView::externalLinks = m_settings.value("documentView/externalLinks", false).toBool();
528
for(int index = 0; index < m_tabWidget->count(); index++)
530
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index)); Q_ASSERT(documentView);
532
documentView->refresh();
537
void MainWindow::slotPageLayoutGroupTriggered(QAction* action)
539
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
541
documentView->setPageLayout(static_cast< DocumentView::PageLayout >(action->data().toUInt()));
544
void MainWindow::slotScaleModeGroupTriggered(QAction* action)
546
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
548
documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(action->data().toUInt()));
551
void MainWindow::slotZoomIn()
553
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
555
documentView->zoomIn();
558
void MainWindow::slotZoomOut()
560
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
562
documentView->zoomOut();
565
void MainWindow::slotRotateLeft()
567
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
569
documentView->rotateLeft();
572
void MainWindow::slotRotateRight()
574
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
576
documentView->rotateRight();
579
void MainWindow::slotFullscreen()
581
if(m_fullscreenAction->isChecked())
583
m_geometry = saveGeometry();
589
restoreGeometry(m_geometry);
593
restoreGeometry(m_geometry);
597
void MainWindow::slotPresentation()
599
if(m_tabWidget->currentIndex() != -1)
601
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
602
PresentationView* presentationView = new PresentationView();
604
if(presentationView->open(documentView->filePath()))
606
presentationView->setCurrentPage(documentView->currentPage());
608
presentationView->show();
609
presentationView->setAttribute(Qt::WA_DeleteOnClose);
613
delete presentationView;
615
QMessageBox::warning(this, tr("Warning"), tr("Could not open document \"%1\".").arg(QFileInfo(documentView->filePath()).fileName()));
620
void MainWindow::slotPreviousTab()
622
if(m_tabWidget->currentIndex() > 0)
624
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1);
628
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
632
void MainWindow::slotNextTab()
634
if(m_tabWidget->currentIndex() < m_tabWidget->count() - 1)
636
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1);
640
m_tabWidget->setCurrentIndex(0);
644
void MainWindow::slotCloseTab()
646
delete m_tabWidget->currentWidget();
649
void MainWindow::slotCloseAllTabs()
651
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
653
while(m_tabWidget->count() > 0)
655
delete m_tabWidget->widget(0);
658
slotTabWidgetCurrentChanged(-1);
660
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
663
void MainWindow::slotCloseAllTabsButCurrentTab()
665
if(m_tabWidget->currentIndex() != -1)
667
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
669
m_tabWidget->removeTab(m_tabWidget->currentIndex());
673
int index = m_tabWidget->addTab(documentView, QFileInfo(documentView->filePath()).completeBaseName());
674
m_tabWidget->setTabToolTip(index, QFileInfo(documentView->filePath()).completeBaseName());
675
m_tabWidget->setCurrentIndex(index);
679
void MainWindow::slotContents()
681
HelpDialog helpDialog;
686
void MainWindow::slotAbout()
688
QMessageBox::about(this, tr("About qpdfview"), tr("<p><b>qpdfview %1</b></p><p>qpdfview is a tabbed PDF viewer using the poppler library. See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>© 2012 Adam Reichold</p>").arg(QApplication::applicationVersion()));
691
void MainWindow::slotTabWidgetCurrentChanged(int index)
695
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
697
m_refreshAction->setEnabled(true);
698
m_saveCopyAction->setEnabled(true);
699
m_printAction->setEnabled(true);
701
m_previousPageAction->setEnabled(true);
702
m_nextPageAction->setEnabled(true);
703
m_firstPageAction->setEnabled(true);
704
m_lastPageAction->setEnabled(true);
706
m_searchAction->setEnabled(true);
707
m_findPreviousAction->setEnabled(true);
708
m_findNextAction->setEnabled(true);
709
m_cancelSearchAction->setEnabled(true);
711
m_pageLayoutGroup->setEnabled(true);
713
m_scaleModeGroup->setEnabled(true);
715
m_zoomInAction->setEnabled(true);
716
m_zoomOutAction->setEnabled(true);
718
m_rotateLeftAction->setEnabled(true);
719
m_rotateRightAction->setEnabled(true);
721
m_presentationAction->setEnabled(true);
723
m_previousTabAction->setEnabled(true);
724
m_nextTabAction->setEnabled(true);
725
m_closeTabAction->setEnabled(true);
726
m_closeAllTabsAction->setEnabled(true);
727
m_closeAllTabsButCurrentTabAction->setEnabled(true);
729
m_editToolBar->setEnabled(true);
730
m_viewToolBar->setEnabled(true);
732
m_searchToolBar->setEnabled(true);
734
if(m_searchToolBar->isVisible())
736
m_searchLineEdit->clear();
737
m_searchTimer->stop();
739
for(int index = 0; index < m_tabWidget->count(); index++)
741
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index)); Q_ASSERT(documentView);
743
documentView->cancelSearch();
747
slotCurrentPageChanged(documentView->currentPage());
748
slotNumberOfPagesChanged(documentView->numberOfPages());
749
slotPageLayoutChanged(documentView->pageLayout());
750
slotScaleModeChanged(documentView->scaleMode());
751
slotScaleFactorChanged(documentView->scaleFactor());
752
slotHighlightAllChanged(documentView->highlightAll());
754
m_outlineDock->setWidget(documentView->outlineTreeWidget());
755
m_metaInformationDock->setWidget(documentView->metaInformationTableWidget());
756
m_thumbnailsDock->setWidget(documentView->thumbnailsGraphicsView());
758
setWindowTitle(m_tabWidget->tabText(index) + " - qpdfview");
762
m_refreshAction->setEnabled(false);
763
m_saveCopyAction->setEnabled(false);
764
m_printAction->setEnabled(false);
766
m_previousPageAction->setEnabled(false);
767
m_nextPageAction->setEnabled(false);
768
m_firstPageAction->setEnabled(false);
769
m_lastPageAction->setEnabled(false);
771
m_searchAction->setEnabled(false);
772
m_findPreviousAction->setEnabled(false);
773
m_findNextAction->setEnabled(false);
774
m_cancelSearchAction->setEnabled(false);
776
m_onePageAction->setChecked(true);
777
m_pageLayoutGroup->setEnabled(false);
779
m_doNotScaleAction->setChecked(true);
780
m_scaleModeGroup->setEnabled(false);
782
m_zoomInAction->setEnabled(false);
783
m_zoomOutAction->setEnabled(false);
785
m_rotateLeftAction->setEnabled(false);
786
m_rotateRightAction->setEnabled(false);
788
m_presentationAction->setEnabled(false);
790
m_previousTabAction->setEnabled(false);
791
m_nextTabAction->setEnabled(false);
792
m_closeTabAction->setEnabled(false);
793
m_closeAllTabsAction->setEnabled(false);
794
m_closeAllTabsButCurrentTabAction->setEnabled(false);
796
m_currentPageLineEdit->setText(QString());
797
m_numberOfPagesLabel->setText(QString());
798
m_editToolBar->setEnabled(false);
800
m_scaleFactorComboBox->setCurrentIndex(2);
801
m_viewToolBar->setEnabled(false);
803
m_highlightAllCheckBox->setChecked(false);
804
m_searchToolBar->setEnabled(false);
806
if(m_searchToolBar->isVisible())
808
m_searchLineEdit->clear();
809
m_searchTimer->stop();
810
m_searchToolBar->hide();
813
m_outlineDock->setWidget(0);
814
m_metaInformationDock->setWidget(0);
815
m_thumbnailsDock->setWidget(0);
817
setWindowTitle("qpdfview");
821
void MainWindow::slotTabWidgetTabCloseRequested(int index)
823
delete m_tabWidget->widget(index);
826
void MainWindow::slotCurrentPageLineEditReturnPressed()
828
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
830
documentView->setCurrentPage(m_currentPageLineEdit->text().toInt());
833
void MainWindow::slotScaleFactorComboBoxCurrentIndexChanged(int index)
835
if(m_tabWidget->currentIndex() != -1)
837
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
839
documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(m_scaleFactorComboBox->itemData(index).toUInt()));
843
void MainWindow::slotScaleFactorComboBoxEditingFinished()
845
if(m_tabWidget->currentIndex() != -1)
847
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
849
QString text = m_scaleFactorComboBox->lineEdit()->text();
851
text = text.trimmed();
853
text = text.endsWith('%') ? text.left(text.size() - 1) : text;
855
text = text.trimmed();
858
qreal scaleFactor = QLocale::system().toInt(text, &ok) / 100.0;
860
if(ok && scaleFactor >= DocumentView::mininumScaleFactor && scaleFactor <= DocumentView::maximumScaleFactor)
862
documentView->setScaleFactor(scaleFactor);
863
documentView->setScaleMode(DocumentView::ScaleFactor);
866
slotScaleFactorChanged(documentView->scaleFactor());
867
slotScaleModeChanged(documentView->scaleMode());
871
void MainWindow::slotHighlightAllCheckBoxClicked(bool checked)
873
DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
875
documentView->setHighlightAll(checked);
878
void MainWindow::slotFilePathChanged(const QString& filePath)
880
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
882
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
884
m_tabWidget->setTabText(m_tabWidget->currentIndex(), QFileInfo(filePath).completeBaseName());
885
m_tabWidget->setTabToolTip(m_tabWidget->currentIndex(), QFileInfo(filePath).completeBaseName());
887
setWindowTitle(QFileInfo(filePath).completeBaseName() + " - qpdfview");
891
void MainWindow::slotNumberOfPagesChanged(int numberOfPages)
893
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
895
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
897
m_currentPageValidator->setRange(1, numberOfPages);
898
m_numberOfPagesLabel->setText(tr(" of %1").arg(numberOfPages));
902
void MainWindow::slotCurrentPageChanged(int currentPage)
904
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
906
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
908
m_currentPageLineEdit->setText(QLocale::system().toString(currentPage));
912
void MainWindow::slotPageLayoutChanged(DocumentView::PageLayout pageLayout)
914
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
916
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
918
foreach(QAction* action, m_pageLayoutGroup->actions())
920
action->setChecked(action->data().toUInt() == static_cast< uint >(pageLayout));
925
void MainWindow::slotScaleModeChanged(DocumentView::ScaleMode scaleMode)
927
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
929
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
931
foreach(QAction* action, m_scaleModeGroup->actions())
933
action->setChecked(action->data().toUInt() == static_cast< uint >(scaleMode));
936
for(int index = 0; index < m_scaleFactorComboBox->count(); index++)
938
if(m_scaleFactorComboBox->itemData(index).toUInt() == static_cast< uint >(scaleMode))
940
m_scaleFactorComboBox->setCurrentIndex(index);
946
void MainWindow::slotScaleFactorChanged(qreal scaleFactor)
948
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
950
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
952
m_scaleFactorComboBox->setItemText(3, tr("Scale to %1%").arg(100.0 * scaleFactor, 0, 'f', 0));
956
void MainWindow::slotHighlightAllChanged(bool highlightAll)
958
DocumentView* documentView = qobject_cast< DocumentView* >(sender());
960
if(documentView == 0 || documentView == m_tabWidget->currentWidget())
962
m_highlightAllCheckBox->setChecked(highlightAll);
966
void MainWindow::createActions()
970
m_openAction = new QAction(tr("&Open..."), this);
971
m_openAction->setShortcut(QKeySequence::Open);
972
m_openAction->setIcon(QIcon::fromTheme("document-open"));
973
m_openAction->setIconVisibleInMenu(true);
974
connect(m_openAction, SIGNAL(triggered()), SLOT(slotOpen()));
978
m_openInNewTabAction = new QAction(tr("Open in new &tab..."), this);
979
m_openInNewTabAction->setShortcut(QKeySequence::AddTab);
980
m_openInNewTabAction->setIconVisibleInMenu(true);
981
connect(m_openInNewTabAction, SIGNAL(triggered()), SLOT(slotOpenInNewTab()));
983
if(QIcon::hasThemeIcon("tab-new"))
985
m_openInNewTabAction->setIcon(QIcon::fromTheme("tab-new"));
989
#ifdef DATA_INSTALL_PATH
990
m_openInNewTabAction->setIcon(QIcon(QString("%1/tab-new.svg").arg(DATA_INSTALL_PATH)));
992
m_openInNewTabAction->setIcon(QIcon(":/icons/tab-new.svg"));
998
m_recentlyUsedAction = new RecentlyUsedAction(this);
999
m_recentlyUsedAction->setIcon(QIcon::fromTheme("document-open-recent"));
1000
m_recentlyUsedAction->setIconVisibleInMenu(true);
1001
connect(m_recentlyUsedAction, SIGNAL(entrySelected(QString)), SLOT(slotRecentyUsedActionEntrySelected(QString)));
1005
m_refreshAction = new QAction(tr("&Refresh"), this);
1006
m_refreshAction->setShortcut(QKeySequence::Refresh);
1007
m_refreshAction->setIconVisibleInMenu(true);
1008
connect(m_refreshAction, SIGNAL(triggered()), SLOT(slotRefresh()));
1010
if(QIcon::hasThemeIcon("view-refresh"))
1012
m_refreshAction->setIcon(QIcon::fromTheme("view-refresh"));
1016
#ifdef DATA_INSTALL_PATH
1017
m_refreshAction->setIcon(QIcon(QString("%1/view-refresh.svg").arg(DATA_INSTALL_PATH)));
1019
m_refreshAction->setIcon(QIcon(":/icons/view-refresh.svg"));
1025
m_saveCopyAction = new QAction(tr("&Save copy..."), this);
1026
m_saveCopyAction->setShortcut(QKeySequence::Save);
1027
m_saveCopyAction->setIcon(QIcon::fromTheme("document-save"));
1028
m_saveCopyAction->setIconVisibleInMenu(true);
1029
connect(m_saveCopyAction, SIGNAL(triggered()), SLOT(slotSaveCopy()));
1033
m_printAction = new QAction(tr("&Print..."), this);
1034
m_printAction->setShortcut(QKeySequence::Print);
1035
m_printAction->setIcon(QIcon::fromTheme("document-print"));
1036
m_printAction->setIconVisibleInMenu(true);
1037
connect(m_printAction, SIGNAL(triggered()), SLOT(slotPrint()));
1041
m_exitAction = new QAction(tr("&Exit"), this);
1042
m_exitAction->setShortcut(QKeySequence::Quit);
1043
m_exitAction->setIcon(QIcon::fromTheme("application-exit"));
1044
m_exitAction->setIconVisibleInMenu(true);
1045
connect(m_exitAction, SIGNAL(triggered()), SLOT(close()));
1049
m_previousPageAction = new QAction(tr("&Previous page"), this);
1050
m_previousPageAction->setShortcut(QKeySequence(Qt::Key_Left));
1051
m_previousPageAction->setIconVisibleInMenu(true);
1052
connect(m_previousPageAction, SIGNAL(triggered()), SLOT(slotPreviousPage()));
1054
if(QIcon::hasThemeIcon("go-previous"))
1056
m_previousPageAction->setIcon(QIcon::fromTheme("go-previous"));
1060
#ifdef DATA_INSTALL_PATH
1061
m_previousPageAction->setIcon(QIcon(QString("%1/go-previous.svg").arg(DATA_INSTALL_PATH)));
1063
m_previousPageAction->setIcon(QIcon(":/icons/go-previous.svg"));
1069
m_nextPageAction = new QAction(tr("&Next page"), this);
1070
m_nextPageAction->setShortcut(QKeySequence(Qt::Key_Right));
1071
m_nextPageAction->setIconVisibleInMenu(true);
1072
connect(m_nextPageAction, SIGNAL(triggered()), SLOT(slotNextPage()));
1074
if(QIcon::hasThemeIcon("go-next"))
1076
m_nextPageAction->setIcon(QIcon::fromTheme("go-next"));
1080
#ifdef DATA_INSTALL_PATH
1081
m_nextPageAction->setIcon(QIcon(QString("%1/go-next.svg").arg(DATA_INSTALL_PATH)));
1083
m_nextPageAction->setIcon(QIcon(":/icons/go-next.svg"));
1089
m_firstPageAction = new QAction(tr("&First page"), this);
1090
m_firstPageAction->setShortcut(QKeySequence(Qt::Key_Home));
1091
m_firstPageAction->setIcon(QIcon::fromTheme("go-first"));
1092
m_firstPageAction->setIconVisibleInMenu(true);
1093
connect(m_firstPageAction, SIGNAL(triggered()), SLOT(slotFirstPage()));
1097
m_lastPageAction = new QAction(tr("&Last page"), this);
1098
m_lastPageAction->setShortcut(QKeySequence(Qt::Key_End));
1099
m_lastPageAction->setIcon(QIcon::fromTheme("go-last"));
1100
m_lastPageAction->setIconVisibleInMenu(true);
1101
connect(m_lastPageAction, SIGNAL(triggered()), SLOT(slotLastPage()));
1105
m_searchAction = new QAction(tr("&Search..."), this);
1106
m_searchAction->setShortcut(QKeySequence::Find);
1107
m_searchAction->setIcon(QIcon::fromTheme("edit-find"));
1108
m_searchAction->setIconVisibleInMenu(true);
1109
connect(m_searchAction, SIGNAL(triggered()), SLOT(slotSearch()));
1113
m_findPreviousAction = new QAction(tr("Find previous"), this);
1114
m_findPreviousAction->setShortcut(QKeySequence::FindPrevious);
1115
m_findPreviousAction->setIconVisibleInMenu(true);
1116
connect(m_findPreviousAction, SIGNAL(triggered()), SLOT(slotFindPrevious()));
1118
if(QIcon::hasThemeIcon("go-up"))
1120
m_findPreviousAction->setIcon(QIcon::fromTheme("go-up"));
1124
#ifdef DATA_INSTALL_PATH
1125
m_findPreviousAction->setIcon(QIcon(QString("%1/go-up.svg").arg(DATA_INSTALL_PATH)));
1127
m_findPreviousAction->setIcon(QIcon(":/icons/go-up.svg"));
1133
m_findNextAction = new QAction(tr("Find next"), this);
1134
m_findNextAction->setShortcut(QKeySequence::FindNext);
1135
m_findNextAction->setIconVisibleInMenu(true);
1136
connect(m_findNextAction, SIGNAL(triggered()), SLOT(slotFindNext()));
1138
if(QIcon::hasThemeIcon("go-down"))
1140
m_findNextAction->setIcon(QIcon::fromTheme("go-down"));
1144
#ifdef DATA_INSTALL_PATH
1145
m_findNextAction->setIcon(QIcon(QString("%1/go-down.svg").arg(DATA_INSTALL_PATH)));
1147
m_findNextAction->setIcon(QIcon(":/icons/go-down.svg"));
1153
m_cancelSearchAction = new QAction(tr("Cancel search"), this);
1154
m_cancelSearchAction->setShortcut(QKeySequence(Qt::Key_Escape));
1155
m_cancelSearchAction->setIconVisibleInMenu(true);
1156
connect(m_cancelSearchAction, SIGNAL(triggered()), SLOT(slotCancelSearch()));
1158
if(QIcon::hasThemeIcon("process-stop"))
1160
m_cancelSearchAction->setIcon(QIcon::fromTheme("process-stop"));
1164
#ifdef DATA_INSTALL_PATH
1165
m_cancelSearchAction->setIcon(QIcon(QString("%1/process-stop.svg").arg(DATA_INSTALL_PATH)));
1167
m_cancelSearchAction->setIcon(QIcon(":/icons/process-stop.svg"));
1173
m_settingsAction = new QAction(tr("Settings..."), this);
1174
connect(m_settingsAction, SIGNAL(triggered()), SLOT(slotSettings()));
1178
m_onePageAction = new QAction(tr("One page"), this);
1179
m_onePageAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
1180
m_onePageAction->setCheckable(true);
1181
m_onePageAction->setData(static_cast< uint >(DocumentView::OnePage));
1182
m_twoPagesAction = new QAction(tr("Two pages"), this);
1183
m_twoPagesAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
1184
m_twoPagesAction->setCheckable(true);
1185
m_twoPagesAction->setData(static_cast< uint >(DocumentView::TwoPages));
1186
m_oneColumnAction = new QAction(tr("One column"), this);
1187
m_oneColumnAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
1188
m_oneColumnAction->setCheckable(true);
1189
m_oneColumnAction->setData(static_cast< uint >(DocumentView::OneColumn));
1190
m_twoColumnsAction = new QAction(tr("Two columns"), this);
1191
m_twoColumnsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_4));
1192
m_twoColumnsAction->setCheckable(true);
1193
m_twoColumnsAction->setData(static_cast< uint >(DocumentView::TwoColumns));
1195
m_pageLayoutGroup = new QActionGroup(this);
1196
m_pageLayoutGroup->addAction(m_onePageAction);
1197
m_pageLayoutGroup->addAction(m_twoPagesAction);
1198
m_pageLayoutGroup->addAction(m_oneColumnAction);
1199
m_pageLayoutGroup->addAction(m_twoColumnsAction);
1200
connect(m_pageLayoutGroup, SIGNAL(selected(QAction*)), SLOT(slotPageLayoutGroupTriggered(QAction*)));
1202
#ifdef DATA_INSTALL_PATH
1203
m_onePageAction->setIcon(QIcon(QString("%1/one-page.svg").arg(DATA_INSTALL_PATH)));
1204
m_twoPagesAction->setIcon(QIcon(QString("%1/two-pages.svg").arg(DATA_INSTALL_PATH)));
1205
m_oneColumnAction->setIcon(QIcon(QString("%1/one-column.svg").arg(DATA_INSTALL_PATH)));
1206
m_twoColumnsAction->setIcon(QIcon(QString("%1/two-columns.svg").arg(DATA_INSTALL_PATH)));
1208
m_onePageAction->setIcon(QIcon(":/icons/one-page.svg"));
1209
m_twoPagesAction->setIcon(QIcon(":/icons/two-pages.svg"));
1210
m_oneColumnAction->setIcon(QIcon(":/icons/one-column.svg"));
1211
m_twoColumnsAction->setIcon(QIcon(":/icons/two-columns.svg"));
1216
m_fitToPageAction = new QAction(tr("Fit to page"), this);
1217
m_fitToPageAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_8));
1218
m_fitToPageAction->setCheckable(true);
1219
m_fitToPageAction->setData(static_cast< uint >(DocumentView::FitToPage));
1220
m_fitToPageWidthAction = new QAction(tr("Fit to page width"), this);
1221
m_fitToPageWidthAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_9));
1222
m_fitToPageWidthAction->setCheckable(true);
1223
m_fitToPageWidthAction->setData(static_cast< uint >(DocumentView::FitToPageWidth));
1224
m_doNotScaleAction = new QAction(tr("Do not scale"), this);
1225
m_doNotScaleAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
1226
m_doNotScaleAction->setCheckable(true);
1227
m_doNotScaleAction->setData(static_cast< uint >(DocumentView::DoNotScale));
1229
m_scaleModeGroup = new QActionGroup(this);
1230
m_scaleModeGroup->addAction(m_fitToPageAction);
1231
m_scaleModeGroup->addAction(m_fitToPageWidthAction);
1232
m_scaleModeGroup->addAction(m_doNotScaleAction);
1233
connect(m_scaleModeGroup, SIGNAL(selected(QAction*)), SLOT(slotScaleModeGroupTriggered(QAction*)));
1235
#ifdef DATA_INSTALL_PATH
1236
m_fitToPageAction->setIcon(QIcon(QString("%1/fit-to-page.svg").arg(DATA_INSTALL_PATH)));
1237
m_fitToPageWidthAction->setIcon(QIcon(QString("%1/fit-to-page-width.svg").arg(DATA_INSTALL_PATH)));
1238
m_doNotScaleAction->setIcon(QIcon(QString("%1/do-not-scale.svg").arg(DATA_INSTALL_PATH)));
1240
m_fitToPageAction->setIcon(QIcon(":/icons/fit-to-page.svg"));
1241
m_fitToPageWidthAction->setIcon(QIcon(":/icons/fit-to-page-width.svg"));
1242
m_doNotScaleAction->setIcon(QIcon(":/icons/do-not-scale.svg"));
1247
m_zoomInAction = new QAction(tr("Zoom &in"), this);
1248
m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
1249
m_zoomInAction->setIconVisibleInMenu(true);
1250
connect(m_zoomInAction, SIGNAL(triggered()), SLOT(slotZoomIn()));
1252
if(QIcon::hasThemeIcon("zoom-in"))
1254
m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in"));
1258
#ifdef DATA_INSTALL_PATH
1259
m_zoomInAction->setIcon(QIcon(QString("%1/zoom-in.svg").arg(DATA_INSTALL_PATH)));
1261
m_zoomInAction->setIcon(QIcon(":/icons/zoom-in.svg"));
1265
m_zoomOutAction = new QAction(tr("Zoom &out"), this);
1266
m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
1267
m_zoomOutAction->setIconVisibleInMenu(true);
1268
connect(m_zoomOutAction, SIGNAL(triggered()), SLOT(slotZoomOut()));
1270
if(QIcon::hasThemeIcon("zoom-out"))
1272
m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out"));
1276
#ifdef DATA_INSTALL_PATH
1277
m_zoomOutAction->setIcon(QIcon(QString("%1/zoom-out.svg").arg(DATA_INSTALL_PATH)));
1279
m_zoomOutAction->setIcon(QIcon(":/icons/zoom-out.svg"));
1285
m_rotateLeftAction = new QAction(tr("Rotate &left"), this);
1286
m_rotateLeftAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
1287
m_rotateLeftAction->setIcon(QIcon::fromTheme("object-rotate-left"));
1288
m_rotateLeftAction->setIconVisibleInMenu(true);
1289
connect(m_rotateLeftAction, SIGNAL(triggered()), SLOT(slotRotateLeft()));
1291
m_rotateRightAction = new QAction(tr("Rotate &right"), this);
1292
m_rotateRightAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
1293
m_rotateRightAction->setIcon(QIcon::fromTheme("object-rotate-right"));
1294
m_rotateRightAction->setIconVisibleInMenu(true);
1295
connect(m_rotateRightAction, SIGNAL(triggered()), SLOT(slotRotateRight()));
1299
m_fullscreenAction = new QAction(tr("&Fullscreen"), this);
1300
m_fullscreenAction->setCheckable(true);
1301
m_fullscreenAction->setShortcut(QKeySequence(Qt::Key_F11));
1302
m_fullscreenAction->setIcon(QIcon::fromTheme("view-fullscreen"));
1303
m_fullscreenAction->setIconVisibleInMenu(true);
1304
connect(m_fullscreenAction, SIGNAL(triggered()), SLOT(slotFullscreen()));
1308
m_presentationAction = new QAction(tr("&Presentation..."), this);
1309
m_presentationAction->setShortcut(QKeySequence(Qt::Key_F12));
1310
m_presentationAction->setIcon(QIcon::fromTheme("x-office-presentation"));
1311
m_presentationAction->setIconVisibleInMenu(true);
1312
connect(m_presentationAction, SIGNAL(triggered()), SLOT(slotPresentation()));
1316
m_previousTabAction = new QAction(tr("&Previous tab"), this);
1317
m_previousTabAction->setShortcut(QKeySequence::PreviousChild);
1318
connect(m_previousTabAction, SIGNAL(triggered()), SLOT(slotPreviousTab()));
1322
m_nextTabAction = new QAction(tr("&Next tab"), this);
1323
m_nextTabAction->setShortcut(QKeySequence::NextChild);
1324
connect(m_nextTabAction, SIGNAL(triggered()), SLOT(slotNextTab()));
1328
m_closeTabAction = new QAction(tr("&Close tab"), this);
1329
m_closeTabAction->setShortcut(QKeySequence::Close);
1330
m_closeTabAction->setIcon(QIcon::fromTheme("window-close"));
1331
m_closeTabAction->setIconVisibleInMenu(true);
1332
connect(m_closeTabAction, SIGNAL(triggered()), SLOT(slotCloseTab()));
1336
m_closeAllTabsAction = new QAction(tr("Close all &tabs"), this);
1337
m_closeAllTabsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
1338
connect(m_closeAllTabsAction, SIGNAL(triggered()), SLOT(slotCloseAllTabs()));
1340
// close all tabs but current tab
1342
m_closeAllTabsButCurrentTabAction = new QAction(tr("Close all tabs &but current tab"), this);
1343
m_closeAllTabsButCurrentTabAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_W));
1344
connect(m_closeAllTabsButCurrentTabAction, SIGNAL(triggered()), SLOT(slotCloseAllTabsButCurrentTab()));
1348
m_contentsAction = new QAction(tr("&Contents"), this);
1349
m_contentsAction->setShortcut(QKeySequence::HelpContents);
1350
m_contentsAction->setIcon(QIcon::fromTheme("help-contents"));
1351
m_contentsAction->setIconVisibleInMenu(true);
1352
connect(m_contentsAction, SIGNAL(triggered()), SLOT(slotContents()));
1356
m_aboutAction = new QAction(tr("&About"), this);
1357
m_aboutAction->setIcon(QIcon::fromTheme("help-about"));
1358
m_aboutAction->setIconVisibleInMenu(true);
1359
connect(m_aboutAction, SIGNAL(triggered()), SLOT(slotAbout()));
1362
void MainWindow::createWidgets()
1366
m_tabWidget = new TabWidget(this);
1368
m_tabWidget->setTabsClosable(true);
1369
m_tabWidget->setMovable(true);
1370
m_tabWidget->setDocumentMode(true);
1371
m_tabWidget->setElideMode(Qt::ElideRight);
1373
setCentralWidget(m_tabWidget);
1375
connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(slotTabWidgetCurrentChanged(int)));
1376
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(slotTabWidgetTabCloseRequested(int)));
1380
m_currentPageLineEdit = new LineEdit(this);
1381
m_currentPageValidator = new QIntValidator(m_currentPageLineEdit);
1383
m_currentPageLineEdit->setValidator(m_currentPageValidator);
1384
m_currentPageLineEdit->setAlignment(Qt::AlignCenter);
1385
m_currentPageLineEdit->setFixedWidth(40);
1387
connect(m_currentPageLineEdit, SIGNAL(returnPressed()), SLOT(slotCurrentPageLineEditReturnPressed()));
1391
m_numberOfPagesLabel = new QLabel(this);
1393
m_numberOfPagesLabel->setAlignment(Qt::AlignCenter);
1394
m_numberOfPagesLabel->setFixedWidth(60);
1398
m_scaleFactorComboBox = new ComboBox(this);
1400
m_scaleFactorComboBox->setEditable(true);
1401
m_scaleFactorComboBox->setInsertPolicy(QComboBox::NoInsert);
1403
m_scaleFactorComboBox->addItem(tr("Fit to page"), static_cast< uint >(DocumentView::FitToPage));
1404
m_scaleFactorComboBox->addItem(tr("Fit to page width"), static_cast< uint >(DocumentView::FitToPageWidth));
1405
m_scaleFactorComboBox->addItem(tr("Do not scale"), static_cast< uint >(DocumentView::DoNotScale));
1406
m_scaleFactorComboBox->addItem(QString(), static_cast< uint >(DocumentView::ScaleFactor));
1408
connect(m_scaleFactorComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotScaleFactorComboBoxCurrentIndexChanged(int)));
1409
connect(m_scaleFactorComboBox->lineEdit(), SIGNAL(editingFinished()), SLOT(slotScaleFactorComboBoxEditingFinished()));
1413
m_searchWidget = new QWidget(this);
1414
m_searchLineEdit = new QLineEdit(m_searchWidget);
1415
m_searchTimer = new QTimer(this);
1416
m_matchCaseCheckBox = new QCheckBox(tr("Match &case"), m_searchWidget);
1417
m_highlightAllCheckBox = new QCheckBox(tr("Highlight &all"), m_searchWidget);
1418
m_searchTimer->setInterval(2000);
1419
m_searchTimer->setSingleShot(true);
1421
m_searchWidget->setLayout(new QHBoxLayout());
1422
m_searchWidget->layout()->setContentsMargins(5, 0, 5, 0);
1423
m_searchWidget->layout()->addWidget(m_searchLineEdit);
1424
m_searchWidget->layout()->addWidget(m_matchCaseCheckBox);
1425
m_searchWidget->layout()->addWidget(m_highlightAllCheckBox);
1427
connect(m_searchLineEdit, SIGNAL(textEdited(QString)), m_searchTimer, SLOT(start()));
1428
connect(m_searchLineEdit, SIGNAL(returnPressed()), this, SLOT(slotStartSearch()));
1429
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(slotStartSearch()));
1431
connect(m_highlightAllCheckBox, SIGNAL(clicked(bool)), SLOT(slotHighlightAllCheckBoxClicked(bool)));
1434
void MainWindow::createToolBars()
1438
m_fileToolBar = new QToolBar(tr("&File"));
1439
m_fileToolBar->setObjectName("fileToolBar");
1441
QStringList fileToolBar = QStringList() << "openInNewTab" << "refresh";
1442
fileToolBar = m_settings.value("mainWindow/fileToolBar", fileToolBar).toStringList();
1444
foreach(QString entry, fileToolBar)
1446
if(entry == "open") { m_fileToolBar->addAction(m_openAction); }
1447
else if(entry == "openInNewTab") { m_fileToolBar->addAction(m_openInNewTabAction); }
1448
else if(entry == "refresh") { m_fileToolBar->addAction(m_refreshAction); }
1449
else if(entry == "saveCopy") { m_fileToolBar->addAction(m_saveCopyAction); }
1450
else if(entry == "print") { m_fileToolBar->addAction(m_printAction); }
1453
addToolBar(Qt::TopToolBarArea, m_fileToolBar);
1457
m_editToolBar = new QToolBar(tr("&Edit"));
1458
m_editToolBar->setObjectName("editToolBar");
1460
QStringList editToolBar = QStringList() << "currentPage" << "numberOfPages" << "previousPage" << "nextPage";
1461
editToolBar = m_settings.value("mainWindow/editToolBar", editToolBar).toStringList();
1463
foreach(QString entry, editToolBar)
1465
if(entry == "currentPage") { m_editToolBar->addWidget(m_currentPageLineEdit); }
1466
else if(entry == "numberOfPages") { m_editToolBar->addWidget(m_numberOfPagesLabel); }
1467
else if(entry == "previousPage") { m_editToolBar->addAction(m_previousPageAction); }
1468
else if(entry == "nextPage") { m_editToolBar->addAction(m_nextPageAction); }
1469
else if(entry == "firstPage") { m_editToolBar->addAction(m_firstPageAction); }
1470
else if(entry == "lastPage") { m_editToolBar->addAction(m_lastPageAction); }
1471
else if(entry == "search") { m_editToolBar->addAction(m_searchAction); }
1474
addToolBar(Qt::TopToolBarArea, m_editToolBar);
1478
m_viewToolBar = new QToolBar(tr("&View"));
1479
m_viewToolBar->setObjectName("viewToolBar");
1481
m_viewToolBar->setHidden(true);
1483
QStringList viewToolBar = QStringList() << "scaleFactor" << "zoomIn" << "zoomOut";
1484
viewToolBar = m_settings.value("mainWindow/viewToolBar", viewToolBar).toStringList();
1486
foreach(QString entry, viewToolBar)
1488
if(entry == "scaleFactor") { m_viewToolBar->addWidget(m_scaleFactorComboBox); }
1489
else if(entry == "onePage") { m_viewToolBar->addAction(m_onePageAction); }
1490
else if(entry == "twoPages") { m_viewToolBar->addAction(m_twoPagesAction); }
1491
else if(entry == "oneColumn") { m_viewToolBar->addAction(m_oneColumnAction); }
1492
else if(entry == "twoColumns") { m_viewToolBar->addAction(m_twoColumnsAction); }
1493
else if(entry == "fitToPage") { m_viewToolBar->addAction(m_fitToPageAction); }
1494
else if(entry == "fitToPageWidth") { m_viewToolBar->addAction(m_fitToPageWidthAction); }
1495
else if(entry == "doNotScale") { m_viewToolBar->addAction(m_doNotScaleAction); }
1496
else if(entry == "zoomIn") { m_viewToolBar->addAction(m_zoomInAction); }
1497
else if(entry == "zoomOut") { m_viewToolBar->addAction(m_zoomOutAction); }
1498
else if(entry == "rotateLeft") { m_viewToolBar->addAction(m_rotateLeftAction); }
1499
else if(entry == "rotateRight") { m_viewToolBar->addAction(m_rotateRightAction); }
1500
else if(entry == "fullscreen") { m_viewToolBar->addAction(m_fullscreenAction); }
1501
else if(entry == "presentation") { m_viewToolBar->addAction(m_presentationAction); }
1504
addToolBar(Qt::TopToolBarArea, m_viewToolBar);
1508
m_searchToolBar = new QToolBar(tr("&Search"));
1509
m_searchToolBar->setObjectName("searchToolBar");
1511
m_searchToolBar->setHidden(true);
1512
m_searchToolBar->setMovable(false);
1514
m_searchToolBar->addWidget(m_searchWidget);
1515
m_searchToolBar->addAction(m_findPreviousAction);
1516
m_searchToolBar->addAction(m_findNextAction);
1517
m_searchToolBar->addAction(m_cancelSearchAction);
1519
addToolBar(Qt::BottomToolBarArea, m_searchToolBar);
1522
void MainWindow::createDocks()
1526
m_outlineDock = new QDockWidget(tr("&Outline"), this);
1527
m_outlineDock->setObjectName("outlineDock");
1528
m_outlineDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1529
m_outlineDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1531
addDockWidget(Qt::LeftDockWidgetArea, m_outlineDock);
1532
m_outlineDock->hide();
1536
m_metaInformationDock = new QDockWidget(tr("&Meta-information"), this);
1537
m_metaInformationDock->setObjectName("metaInformationDock");
1538
m_metaInformationDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1539
m_metaInformationDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1541
addDockWidget(Qt::LeftDockWidgetArea, m_metaInformationDock);
1542
m_metaInformationDock->hide();
1546
m_thumbnailsDock = new QDockWidget(tr("&Thumbnails"), this);
1547
m_thumbnailsDock->setObjectName("thumbnailsDock");
1548
m_thumbnailsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1549
m_thumbnailsDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1551
addDockWidget(Qt::RightDockWidgetArea, m_thumbnailsDock);
1552
m_thumbnailsDock->hide();
1555
void MainWindow::createMenus()
1559
m_fileMenu = menuBar()->addMenu(tr("&File"));
1560
m_fileMenu->addAction(m_openAction);
1561
m_fileMenu->addAction(m_openInNewTabAction);
1562
m_fileMenu->addAction(m_recentlyUsedAction);
1563
m_fileMenu->addAction(m_refreshAction);
1564
m_fileMenu->addAction(m_saveCopyAction);
1565
m_fileMenu->addAction(m_printAction);
1566
m_fileMenu->addSeparator();
1567
m_fileMenu->addAction(m_exitAction);
1571
m_editMenu = menuBar()->addMenu(tr("&Edit"));
1572
m_editMenu->addAction(m_previousPageAction);
1573
m_editMenu->addAction(m_nextPageAction);
1574
m_editMenu->addAction(m_firstPageAction);
1575
m_editMenu->addAction(m_lastPageAction);
1576
m_editMenu->addSeparator();
1577
m_editMenu->addAction(m_searchAction);
1578
m_editMenu->addAction(m_findPreviousAction);
1579
m_editMenu->addAction(m_findNextAction);
1580
m_editMenu->addAction(m_cancelSearchAction);
1581
m_editMenu->addSeparator();
1582
m_editMenu->addAction(m_settingsAction);
1586
m_viewMenu = menuBar()->addMenu(tr("&View"));
1587
m_viewMenu->addAction(m_onePageAction);
1588
m_viewMenu->addAction(m_twoPagesAction);
1589
m_viewMenu->addAction(m_oneColumnAction);
1590
m_viewMenu->addAction(m_twoColumnsAction);
1591
m_viewMenu->addSeparator();
1592
m_viewMenu->addAction(m_fitToPageAction);
1593
m_viewMenu->addAction(m_fitToPageWidthAction);
1594
m_viewMenu->addAction(m_doNotScaleAction);
1595
m_viewMenu->addAction(m_zoomInAction);
1596
m_viewMenu->addAction(m_zoomOutAction);
1597
m_viewMenu->addSeparator();
1598
m_viewMenu->addAction(m_rotateLeftAction);
1599
m_viewMenu->addAction(m_rotateRightAction);
1600
m_viewMenu->addSeparator();
1604
QMenu* toolbarsMenu = m_viewMenu->addMenu(tr("&Toolbars"));
1605
toolbarsMenu->addAction(m_fileToolBar->toggleViewAction());
1606
toolbarsMenu->addAction(m_editToolBar->toggleViewAction());
1607
toolbarsMenu->addAction(m_viewToolBar->toggleViewAction());
1611
QMenu* docksMenu = m_viewMenu->addMenu(tr("&Docks"));
1612
docksMenu->addAction(m_outlineDock->toggleViewAction());
1613
docksMenu->addAction(m_metaInformationDock->toggleViewAction());
1614
docksMenu->addAction(m_thumbnailsDock->toggleViewAction());
1616
m_viewMenu->addAction(m_fullscreenAction);
1617
m_viewMenu->addAction(m_presentationAction);
1621
m_tabMenu = menuBar()->addMenu(tr("&Tab"));
1622
m_tabMenu->addAction(m_previousTabAction);
1623
m_tabMenu->addAction(m_nextTabAction);
1624
m_tabMenu->addSeparator();
1625
m_tabMenu->addAction(m_closeTabAction);
1626
m_tabMenu->addAction(m_closeAllTabsAction);
1627
m_tabMenu->addAction(m_closeAllTabsButCurrentTabAction);
1628
m_tabMenu->addSeparator();
1632
m_helpMenu = menuBar()->addMenu(tr("&Help"));
1633
m_helpMenu->addAction(m_contentsAction);
1634
m_helpMenu->addAction(m_aboutAction);
1639
MainWindowAdaptor::MainWindowAdaptor(MainWindow* mainWindow) : QDBusAbstractAdaptor(mainWindow)
1643
bool MainWindowAdaptor::open(const QString& filePath, int page, qreal top)
1645
MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1647
return mainWindow->open(filePath, page, top);
1650
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, qreal top)
1652
MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1654
return mainWindow->openInNewTab(filePath, page, top);
1657
void MainWindowAdaptor::refresh(const QString& filePath, int page, qreal top)
1659
MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1661
bool openInNewTab = true;
1663
for(int index = 0; index < mainWindow->m_tabWidget->count(); index++)
1665
DocumentView* documentView = qobject_cast< DocumentView* >(mainWindow->m_tabWidget->widget(index)); Q_ASSERT(documentView);
1667
if(QFileInfo(documentView->filePath()).absoluteFilePath() == QFileInfo(filePath).absoluteFilePath())
1669
documentView->refresh();
1670
documentView->setCurrentPage(page, top);
1672
mainWindow->m_tabWidget->setCurrentIndex(index);
1674
openInNewTab = false;
1678
if(openInNewTab && QFileInfo(filePath).exists())
1680
mainWindow->openInNewTab(filePath, page, top);