3
Copyright 2012-2013 Adam Reichold
4
Copyright 2012 Michał Trybus
5
Copyright 2012 Alexander Volkov
7
This file is part of qpdfview.
9
qpdfview is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation, either version 2 of the License, or
12
(at your option) any later version.
14
qpdfview is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
24
#include "mainwindow.h"
26
#include <QApplication>
28
#include <QCryptographicHash>
31
#include <QDialogButtonBox>
32
#include <QDockWidget>
33
#include <QDragEnterEvent>
34
#include <QFileDialog>
35
#include <QHeaderView>
36
#include <QInputDialog>
38
#include <QMessageBox>
43
#include <QStandardItemModel>
45
#include <QTextBrowser>
48
#include <QToolButton>
49
#include <QVBoxLayout>
50
#include <QWidgetAction>
52
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
54
#include <QStandardPaths>
58
#include <QDesktopServices>
71
#include "documentview.h"
72
#include "miscellaneous.h"
73
#include "shortcuthandler.h"
74
#include "printdialog.h"
75
#include "settingsdialog.h"
76
#include "recentlyusedmenu.h"
77
#include "bookmarkmenu.h"
79
Settings* MainWindow::s_settings = 0;
81
MainWindow::MainWindow(const QString& instanceName, QWidget* parent) : QMainWindow(parent)
83
setObjectName(instanceName);
87
s_settings = Settings::instance();
92
if(s_settings->mainWindow().hasIconTheme())
94
QIcon::setThemeName(s_settings->mainWindow().iconTheme());
97
if(s_settings->mainWindow().hasStyleSheet())
99
qApp->setStyleSheet(s_settings->mainWindow().styleSheet());
102
m_shortcutHandler = new ShortcutHandler(this);
104
setAcceptDrops(true);
112
restoreGeometry(s_settings->mainWindow().geometry());
113
restoreState(s_settings->mainWindow().state());
115
m_matchCaseCheckBox->setChecked(s_settings->documentView().matchCase());
122
on_tabWidget_currentChanged(m_tabWidget->currentIndex());
125
QSize MainWindow::sizeHint() const
127
return QSize(600, 800);
130
QMenu* MainWindow::createPopupMenu()
132
QMenu* menu = new QMenu();
134
menu->addAction(m_fileToolBar->toggleViewAction());
135
menu->addAction(m_editToolBar->toggleViewAction());
136
menu->addAction(m_viewToolBar->toggleViewAction());
137
menu->addSeparator();
138
menu->addAction(m_outlineDock->toggleViewAction());
139
menu->addAction(m_propertiesDock->toggleViewAction());
140
menu->addAction(m_thumbnailsDock->toggleViewAction());
145
bool MainWindow::open(const QString& filePath, int page, const QRectF& highlight)
147
if(m_tabWidget->currentIndex() != -1)
149
savePerFileSettings(currentTab());
151
if(currentTab()->open(filePath))
153
QFileInfo fileInfo(filePath);
155
s_settings->mainWindow().setOpenPath(fileInfo.absolutePath());
156
m_recentlyUsedMenu->addOpenAction(filePath);
158
m_tabWidget->setTabText(m_tabWidget->currentIndex(), fileInfo.completeBaseName());
159
m_tabWidget->setTabToolTip(m_tabWidget->currentIndex(), fileInfo.absoluteFilePath());
161
restorePerFileSettings(currentTab());
163
currentTab()->jumpToPage(page, false);
164
currentTab()->setFocus();
166
if(!highlight.isNull())
168
currentTab()->highlightOnCurrentPage(highlight);
175
QMessageBox::warning(this, tr("Warning"), tr("Could not open '%1'.").arg(filePath));
182
bool MainWindow::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
184
DocumentView* newTab = new DocumentView(this);
186
if(newTab->open(filePath))
188
newTab->setContinousMode(s_settings->documentView().continuousMode());
189
newTab->setLayoutMode(s_settings->documentView().layoutMode());
190
newTab->setScaleMode(s_settings->documentView().scaleMode());
191
newTab->setScaleFactor(s_settings->documentView().scaleFactor());
192
newTab->setRotation(s_settings->documentView().rotation());
193
newTab->setInvertColors(s_settings->documentView().invertColors());
194
newTab->setHighlightAll(s_settings->documentView().highlightAll());
196
QFileInfo fileInfo(filePath);
198
s_settings->mainWindow().setOpenPath(fileInfo.absolutePath());
199
m_recentlyUsedMenu->addOpenAction(filePath);
203
if(s_settings->mainWindow().newTabNextToCurrentTab())
205
index = m_tabWidget->insertTab(m_tabWidget->currentIndex() + 1, newTab, fileInfo.completeBaseName());
209
index = m_tabWidget->addTab(newTab, fileInfo.completeBaseName());
212
m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
213
m_tabWidget->setCurrentIndex(index);
215
QAction* tabAction = new QAction(m_tabWidget->tabText(index), newTab);
216
connect(tabAction, SIGNAL(triggered()), SLOT(on_tabAction_triggered()));
218
m_tabsMenu->addAction(tabAction);
220
connect(newTab, SIGNAL(filePathChanged(QString)), SLOT(on_currentTab_filePathChanged(QString)));
221
connect(newTab, SIGNAL(numberOfPagesChanged(int)), SLOT(on_currentTab_numberOfPagesChaned(int)));
222
connect(newTab, SIGNAL(currentPageChanged(int)), SLOT(on_currentTab_currentPageChanged(int)));
224
connect(newTab, SIGNAL(canJumpChanged(bool,bool)), SLOT(on_currentTab_canJumpChanged(bool,bool)));
226
connect(newTab, SIGNAL(continousModeChanged(bool)), SLOT(on_currentTab_continuousModeChanged(bool)));
227
connect(newTab, SIGNAL(layoutModeChanged(LayoutMode)), SLOT(on_currentTab_layoutModeChanged(LayoutMode)));
228
connect(newTab, SIGNAL(scaleModeChanged(ScaleMode)), SLOT(on_currentTab_scaleModeChanged(ScaleMode)));
229
connect(newTab, SIGNAL(scaleFactorChanged(qreal)), SLOT(on_currentTab_scaleFactorChanged(qreal)));
230
connect(newTab, SIGNAL(rotationChanged(Rotation)), SLOT(on_currentTab_rotationChanged(Rotation)));
232
connect(newTab, SIGNAL(linkClicked(QString,int)), SLOT(on_currentTab_linkClicked(QString,int)));
234
connect(newTab, SIGNAL(invertColorsChanged(bool)), SLOT(on_currentTab_invertColorsChanged(bool)));
235
connect(newTab, SIGNAL(highlightAllChanged(bool)), SLOT(on_currentTab_highlightAllChanged(bool)));
236
connect(newTab, SIGNAL(rubberBandModeChanged(RubberBandMode)), SLOT(on_currentTab_rubberBandModeChanged(RubberBandMode)));
238
connect(newTab, SIGNAL(searchFinished()), SLOT(on_currentTab_searchFinished()));
239
connect(newTab, SIGNAL(searchProgressChanged(int)), SLOT(on_currentTab_searchProgressChanged(int)));
241
connect(newTab, SIGNAL(customContextMenuRequested(QPoint)), SLOT(on_currentTab_customContextMenuRequested(QPoint)));
245
restorePerFileSettings(newTab);
247
newTab->jumpToPage(page, false);
250
if(!highlight.isNull())
252
newTab->highlightOnCurrentPage(highlight);
261
QMessageBox::warning(this, tr("Warning"), tr("Could not open '%1'.").arg(filePath));
267
bool MainWindow::jumpToPageOrOpenInNewTab(const QString& filePath, int page, bool refreshBeforeJump, const QRectF& highlight)
269
QFileInfo fileInfo(filePath);
271
for(int index = 0; index < m_tabWidget->count(); ++index)
273
if(QFileInfo(tab(index)->filePath()).absoluteFilePath() == fileInfo.absoluteFilePath())
275
m_tabWidget->setCurrentIndex(index);
277
if(refreshBeforeJump)
279
if(!currentTab()->refresh())
285
currentTab()->jumpToPage(page);
286
currentTab()->setFocus();
288
if(!highlight.isNull())
290
currentTab()->highlightOnCurrentPage(highlight);
297
return openInNewTab(filePath, page, highlight);
300
void MainWindow::startSearch(const QString& text)
302
if(m_tabWidget->currentIndex() != -1)
304
m_searchToolBar->setVisible(true);
306
m_searchProgressLineEdit->setText(text);
308
currentTab()->setFocus();
310
QTimer::singleShot(0, this, SLOT(on_search_timeout()));
314
void MainWindow::on_tabWidget_currentChanged(int index)
318
m_refreshAction->setEnabled(true);
319
m_saveCopyAction->setEnabled(currentTab()->canSave());
320
m_saveAsAction->setEnabled(currentTab()->canSave());
321
m_printAction->setEnabled(true);
323
m_previousPageAction->setEnabled(true);
324
m_nextPageAction->setEnabled(true);
325
m_firstPageAction->setEnabled(true);
326
m_lastPageAction->setEnabled(true);
328
m_jumpToPageAction->setEnabled(true);
330
m_searchAction->setEnabled(true);
332
m_copyToClipboardModeAction->setEnabled(true);
333
m_addAnnotationModeAction->setEnabled(true);
335
m_continuousModeAction->setEnabled(true);
336
m_twoPagesModeAction->setEnabled(true);
337
m_twoPagesWithCoverPageModeAction->setEnabled(true);
338
m_multiplePagesModeAction->setEnabled(true);
340
m_zoomInAction->setEnabled(true);
341
m_zoomOutAction->setEnabled(true);
342
m_originalSizeAction->setEnabled(true);
343
m_fitToPageWidthModeAction->setEnabled(true);
344
m_fitToPageSizeModeAction->setEnabled(true);
346
m_rotateLeftAction->setEnabled(true);
347
m_rotateRightAction->setEnabled(true);
349
m_invertColorsAction->setEnabled(true);
351
m_fontsAction->setEnabled(true);
353
m_presentationAction->setEnabled(true);
355
m_previousTabAction->setEnabled(true);
356
m_nextTabAction->setEnabled(true);
357
m_closeTabAction->setEnabled(true);
358
m_closeAllTabsAction->setEnabled(true);
359
m_closeAllTabsButCurrentTabAction->setEnabled(true);
361
m_previousBookmarkAction->setEnabled(true);
362
m_nextBookmarkAction->setEnabled(true);
363
m_addBookmarkAction->setEnabled(true);
364
m_removeBookmarkAction->setEnabled(true);
366
m_currentPageSpinBox->setEnabled(true);
367
m_scaleFactorComboBox->setEnabled(true);
368
m_searchProgressLineEdit->setEnabled(true);
369
m_matchCaseCheckBox->setEnabled(true);
370
m_highlightAllCheckBox->setEnabled(true);
372
if(m_searchToolBar->isVisible())
374
m_searchTimer->stop();
375
m_searchProgressLineEdit->setProgress(currentTab()->searchProgress());
378
m_outlineView->setModel(currentTab()->outlineModel());
380
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
382
m_outlineView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
383
m_outlineView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
387
m_outlineView->header()->setResizeMode(0, QHeaderView::Stretch);
388
m_outlineView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
392
m_propertiesView->setModel(currentTab()->propertiesModel());
394
m_thumbnailsView->setScene(currentTab()->thumbnailsScene());
396
on_currentTab_filePathChanged(currentTab()->filePath());
397
on_currentTab_numberOfPagesChaned(currentTab()->numberOfPages());
398
on_currentTab_currentPageChanged(currentTab()->currentPage());
400
on_currentTab_canJumpChanged(currentTab()->canJumpBackward(), currentTab()->canJumpForward());
402
on_currentTab_continuousModeChanged(currentTab()->continousMode());
403
on_currentTab_layoutModeChanged(currentTab()->layoutMode());
404
on_currentTab_scaleModeChanged(currentTab()->scaleMode());
405
on_currentTab_scaleFactorChanged(currentTab()->scaleFactor());
406
on_currentTab_rotationChanged(currentTab()->rotation());
408
on_currentTab_invertColorsChanged(currentTab()->invertColors());
409
on_currentTab_highlightAllChanged(currentTab()->highlightAll());
410
on_currentTab_rubberBandModeChanged(currentTab()->rubberBandMode());
414
m_refreshAction->setEnabled(false);
415
m_saveCopyAction->setEnabled(false);
416
m_saveAsAction->setEnabled(false);
417
m_printAction->setEnabled(false);
419
m_previousPageAction->setEnabled(false);
420
m_nextPageAction->setEnabled(false);
421
m_firstPageAction->setEnabled(false);
422
m_lastPageAction->setEnabled(false);
424
m_jumpToPageAction->setEnabled(false);
426
m_jumpBackwardAction->setEnabled(false);
427
m_jumpForwardAction->setEnabled(false);
429
m_searchAction->setEnabled(false);
431
m_copyToClipboardModeAction->setEnabled(false);
432
m_addAnnotationModeAction->setEnabled(false);
434
m_continuousModeAction->setEnabled(false);
435
m_twoPagesModeAction->setEnabled(false);
436
m_twoPagesWithCoverPageModeAction->setEnabled(false);
437
m_multiplePagesModeAction->setEnabled(false);
439
m_zoomInAction->setEnabled(false);
440
m_zoomOutAction->setEnabled(false);
441
m_originalSizeAction->setEnabled(false);
442
m_fitToPageWidthModeAction->setEnabled(false);
443
m_fitToPageSizeModeAction->setEnabled(false);
445
m_rotateLeftAction->setEnabled(false);
446
m_rotateRightAction->setEnabled(false);
448
m_invertColorsAction->setEnabled(false);
450
m_fontsAction->setEnabled(false);
452
m_presentationAction->setEnabled(false);
454
m_previousTabAction->setEnabled(false);
455
m_nextTabAction->setEnabled(false);
456
m_closeTabAction->setEnabled(false);
457
m_closeAllTabsAction->setEnabled(false);
458
m_closeAllTabsButCurrentTabAction->setEnabled(false);
460
m_previousBookmarkAction->setEnabled(false);
461
m_nextBookmarkAction->setEnabled(false);
462
m_addBookmarkAction->setEnabled(false);
463
m_removeBookmarkAction->setEnabled(false);
465
m_currentPageSpinBox->setEnabled(false);
466
m_scaleFactorComboBox->setEnabled(false);
467
m_searchProgressLineEdit->setEnabled(false);
468
m_matchCaseCheckBox->setEnabled(false);
469
m_highlightAllCheckBox->setEnabled(false);
471
if(m_searchToolBar->isVisible())
473
m_searchTimer->stop();
474
m_searchProgressLineEdit->setProgress(0);
477
m_searchToolBar->setVisible(false);
479
m_outlineView->setModel(0);
480
m_propertiesView->setModel(0);
481
m_thumbnailsView->setScene(0);
483
setWindowTitle(QLatin1String("qpdfview"));
485
m_currentPageSpinBox->setValue(1);
486
m_currentPageSpinBox->setSuffix(" / 1");
487
m_scaleFactorComboBox->setCurrentIndex(4);
489
m_copyToClipboardModeAction->setChecked(false);
490
m_addAnnotationModeAction->setChecked(false);
492
m_continuousModeAction->setChecked(false);
493
m_twoPagesModeAction->setChecked(false);
494
m_twoPagesWithCoverPageModeAction->setChecked(false);
495
m_multiplePagesModeAction->setChecked(false);
497
m_fitToPageSizeModeAction->setChecked(false);
498
m_fitToPageWidthModeAction->setChecked(false);
500
m_invertColorsAction->setChecked(false);
504
void MainWindow::on_tabWidget_tabCloseRequested(int index)
506
savePerFileSettings(tab(index));
508
delete m_tabWidget->widget(index);
511
void MainWindow::on_currentTab_filePathChanged(const QString& filePath)
513
for(int index = 0; index < m_tabWidget->count(); ++index)
515
if(sender() == m_tabWidget->widget(index))
517
QFileInfo fileInfo(filePath);
519
m_tabWidget->setTabText(index, fileInfo.completeBaseName());
520
m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
522
foreach(QAction* tabAction, m_tabsMenu->actions())
524
if(tabAction->parent() == m_tabWidget->widget(index))
526
tabAction->setText(m_tabWidget->tabText(index));
536
if(senderIsCurrentTab())
538
setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
542
void MainWindow::on_currentTab_numberOfPagesChaned(int numberOfPages)
544
if(senderIsCurrentTab())
546
m_currentPageSpinBox->setRange(1, numberOfPages);
547
m_currentPageSpinBox->setSuffix(QString(" / %1").arg(numberOfPages));
549
setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
553
void MainWindow::on_currentTab_currentPageChanged(int currentPage)
555
if(senderIsCurrentTab())
557
m_currentPageSpinBox->setValue(currentPage);
559
setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
561
m_thumbnailsView->ensureVisible(currentTab()->thumbnailItems().at(currentPage - 1));
565
void MainWindow::on_currentTab_canJumpChanged(bool backward, bool forward)
567
if(senderIsCurrentTab())
569
m_jumpBackwardAction->setEnabled(backward);
570
m_jumpForwardAction->setEnabled(forward);
574
void MainWindow::on_currentTab_continuousModeChanged(bool continuousMode)
576
if(senderIsCurrentTab())
578
m_continuousModeAction->setChecked(continuousMode);
580
s_settings->documentView().setContinuousMode(continuousMode);
584
void MainWindow::on_currentTab_layoutModeChanged(LayoutMode layoutMode)
586
if(senderIsCurrentTab())
588
m_twoPagesModeAction->setChecked(layoutMode == TwoPagesMode);
589
m_twoPagesWithCoverPageModeAction->setChecked(layoutMode == TwoPagesWithCoverPageMode);
590
m_multiplePagesModeAction->setChecked(layoutMode == MultiplePagesMode);
592
s_settings->documentView().setLayoutMode(layoutMode);
596
void MainWindow::on_currentTab_scaleModeChanged(ScaleMode scaleMode)
598
if(senderIsCurrentTab())
603
case ScaleFactorMode:
604
m_fitToPageWidthModeAction->setChecked(false);
605
m_fitToPageSizeModeAction->setChecked(false);
607
on_currentTab_scaleFactorChanged(currentTab()->scaleFactor());
609
case FitToPageWidthMode:
610
m_fitToPageWidthModeAction->setChecked(true);
611
m_fitToPageSizeModeAction->setChecked(false);
613
m_scaleFactorComboBox->setCurrentIndex(0);
615
m_zoomInAction->setEnabled(true);
616
m_zoomOutAction->setEnabled(true);
618
case FitToPageSizeMode:
619
m_fitToPageWidthModeAction->setChecked(false);
620
m_fitToPageSizeModeAction->setChecked(true);
622
m_scaleFactorComboBox->setCurrentIndex(1);
624
m_zoomInAction->setEnabled(true);
625
m_zoomOutAction->setEnabled(true);
629
s_settings->documentView().setScaleMode(scaleMode);
633
void MainWindow::on_currentTab_scaleFactorChanged(qreal scaleFactor)
635
if(senderIsCurrentTab())
637
if(currentTab()->scaleMode() == ScaleFactorMode)
639
m_scaleFactorComboBox->setCurrentIndex(m_scaleFactorComboBox->findData(scaleFactor));
640
m_scaleFactorComboBox->lineEdit()->setText(QString("%1 %").arg(qRound(scaleFactor * 100.0)));
642
m_zoomInAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::maximumScaleFactor()));
643
m_zoomOutAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::minimumScaleFactor()));
646
s_settings->documentView().setScaleFactor(scaleFactor);
650
void MainWindow::on_currentTab_rotationChanged(Rotation rotation)
652
if(senderIsCurrentTab())
654
s_settings->documentView().setRotation(rotation);
658
void MainWindow::on_currentTab_linkClicked(const QString& filePath, int page)
660
jumpToPageOrOpenInNewTab(filePath, page, true);
663
void MainWindow::on_currentTab_invertColorsChanged(bool invertColors)
665
if(senderIsCurrentTab())
667
m_invertColorsAction->setChecked(invertColors);
669
s_settings->documentView().setInvertColors(invertColors);
673
void MainWindow::on_currentTab_highlightAllChanged(bool highlightAll)
675
if(senderIsCurrentTab())
677
m_highlightAllCheckBox->setChecked(highlightAll);
679
s_settings->documentView().setHighlightAll(highlightAll);
683
void MainWindow::on_currentTab_rubberBandModeChanged(RubberBandMode rubberBandMode)
685
if(senderIsCurrentTab())
687
m_copyToClipboardModeAction->setChecked(rubberBandMode == CopyToClipboardMode);
688
m_addAnnotationModeAction->setChecked(rubberBandMode == AddAnnotationMode);
692
void MainWindow::on_currentTab_searchFinished()
694
if(senderIsCurrentTab())
696
m_searchProgressLineEdit->setProgress(0);
700
void MainWindow::on_currentTab_searchProgressChanged(int progress)
702
if(senderIsCurrentTab())
704
m_searchProgressLineEdit->setProgress(progress);
708
void MainWindow::on_currentTab_customContextMenuRequested(const QPoint& pos)
710
if(senderIsCurrentTab())
715
menu.addActions(QList< QAction* >() << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction);
718
menu.addActions(QList< QAction* >() << m_jumpBackwardAction << m_jumpForwardAction);
720
if(m_searchToolBar->isVisible())
723
menu.addActions(QList< QAction* >() << m_findPreviousAction << m_findNextAction << m_cancelSearchAction);
726
menu.exec(currentTab()->mapToGlobal(pos));
730
void MainWindow::on_currentPage_editingFinished()
732
if(m_tabWidget->currentIndex() != -1)
734
currentTab()->jumpToPage(m_currentPageSpinBox->value());
738
void MainWindow::on_currentPage_returnPressed()
740
currentTab()->setFocus();
743
void MainWindow::on_scaleFactor_activated(int index)
747
currentTab()->setScaleMode(FitToPageWidthMode);
751
currentTab()->setScaleMode(FitToPageSizeMode);
756
qreal scaleFactor = m_scaleFactorComboBox->itemData(index).toReal(&ok);
760
currentTab()->setScaleFactor(scaleFactor);
761
currentTab()->setScaleMode(ScaleFactorMode);
765
currentTab()->setFocus();
768
void MainWindow::on_scaleFactor_editingFinished()
770
if(m_tabWidget->currentIndex() != -1)
773
qreal scaleFactor = m_scaleFactorComboBox->lineEdit()->text().toInt(&ok) / 100.0;
775
scaleFactor = scaleFactor >= Defaults::DocumentView::minimumScaleFactor() ? scaleFactor : Defaults::DocumentView::minimumScaleFactor();
776
scaleFactor = scaleFactor <= Defaults::DocumentView::maximumScaleFactor() ? scaleFactor : Defaults::DocumentView::maximumScaleFactor();
780
currentTab()->setScaleFactor(scaleFactor);
781
currentTab()->setScaleMode(ScaleFactorMode);
784
on_currentTab_scaleFactorChanged(currentTab()->scaleFactor());
785
on_currentTab_scaleModeChanged(currentTab()->scaleMode());
789
void MainWindow::on_scaleFactor_returnPressed()
791
currentTab()->setFocus();
794
void MainWindow::on_open_triggered()
796
if(m_tabWidget->currentIndex() != -1)
798
QString path = s_settings->mainWindow().openPath();
799
QString filePath = QFileDialog::getOpenFileName(this, tr("Open"), path, DocumentView::openFilter().join(";;"));
801
if(!filePath.isEmpty())
808
on_openInNewTab_triggered();
812
void MainWindow::on_openInNewTab_triggered()
814
QString path = s_settings->mainWindow().openPath();
815
QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open in new tab"), path, DocumentView::openFilter().join(";;"));
817
if(!filePaths.isEmpty())
819
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
821
foreach(QString filePath, filePaths)
823
openInNewTab(filePath);
826
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
828
on_tabWidget_currentChanged(m_tabWidget->currentIndex());
832
void MainWindow::on_refresh_triggered()
834
if(!currentTab()->refresh())
836
QMessageBox::warning(this, tr("Warning"), tr("Could not refresh '%1'.").arg(currentTab()->filePath()));
840
void MainWindow::on_saveCopy_triggered()
842
QString path = s_settings->mainWindow().savePath();
843
QString filePath = QFileDialog::getSaveFileName(this, tr("Save copy"), QFileInfo(QDir(path), QFileInfo(currentTab()->filePath()).fileName()).filePath(), currentTab()->saveFilter().join(";;"));
845
if(!filePath.isEmpty())
847
if(currentTab()->save(filePath, false))
849
s_settings->mainWindow().setSavePath(QFileInfo(filePath).absolutePath());
853
QMessageBox::warning(this, tr("Warning"), tr("Could not save copy at '%1'.").arg(filePath));
858
void MainWindow::on_saveAs_triggered()
860
QString path = s_settings->mainWindow().savePath();
861
QString filePath = QFileDialog::getSaveFileName(this, tr("Save as"), QFileInfo(QDir(path), QFileInfo(currentTab()->filePath()).fileName()).filePath(), currentTab()->saveFilter().join(";;"));
863
if(!filePath.isEmpty())
865
if(currentTab()->save(filePath, true))
867
open(filePath, currentTab()->currentPage());
869
s_settings->mainWindow().setSavePath(QFileInfo(filePath).absolutePath());
873
QMessageBox::warning(this, tr("Warning"), tr("Could not save as '%1'.").arg(filePath));
878
void MainWindow::on_print_triggered()
880
QPrinter* printer = PrintDialog::createPrinter();
881
PrintDialog* printDialog = new PrintDialog(printer, this);
883
printer->setDocName(QFileInfo(currentTab()->filePath()).completeBaseName());
884
printer->setFullPage(true);
886
printDialog->setMinMax(1, currentTab()->numberOfPages());
887
printDialog->setOption(QPrintDialog::PrintToFile, false);
889
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
891
printDialog->setOption(QPrintDialog::PrintCurrentPage, true);
895
if(printDialog->exec() == QDialog::Accepted)
898
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
900
if(printDialog->printRange() == QPrintDialog::CurrentPage)
902
printer->setFromTo(currentTab()->currentPage(), currentTab()->currentPage());
907
if(!currentTab()->print(printer, printDialog->printOptions()))
909
QMessageBox::warning(this, tr("Warning"), tr("Could not print '%1'.").arg(currentTab()->filePath()));
917
void MainWindow::on_recentlyUsed_openTriggered(const QString& filePath)
919
if(!jumpToPageOrOpenInNewTab(filePath, -1, true))
921
m_recentlyUsedMenu->removeOpenAction(filePath);
925
void MainWindow::on_previousPage_triggered()
927
currentTab()->previousPage();
930
void MainWindow::on_nextPage_triggered()
932
currentTab()->nextPage();
935
void MainWindow::on_firstPage_triggered()
937
currentTab()->firstPage();
940
void MainWindow::on_lastPage_triggered()
942
currentTab()->lastPage();
945
void MainWindow::on_jumpToPage_triggered()
948
int page = QInputDialog::getInt(this, tr("Jump to page"), tr("Page:"), currentTab()->currentPage(), 1, currentTab()->numberOfPages(), 1, &ok);
952
currentTab()->jumpToPage(page);
956
void MainWindow::on_jumpBackward_triggered()
958
currentTab()->jumpBackward();
961
void MainWindow::on_jumpForward_triggered()
963
currentTab()->jumpForward();
966
void MainWindow::on_search_triggered()
968
m_searchToolBar->setVisible(true);
970
m_searchProgressLineEdit->selectAll();
971
m_searchProgressLineEdit->setFocus();
974
void MainWindow::on_search_returnPressed(const Qt::KeyboardModifiers& modifiers)
976
if(modifiers == Qt::ShiftModifier)
978
m_searchTimer->stop();
980
if(!m_searchProgressLineEdit->text().isEmpty())
982
for(int index = 0; index < m_tabWidget->count(); ++index)
984
tab(index)->startSearch(m_searchProgressLineEdit->text(), m_matchCaseCheckBox->isChecked());
994
void MainWindow::on_search_timeout()
996
m_searchTimer->stop();
998
if(!m_searchProgressLineEdit->text().isEmpty())
1000
currentTab()->startSearch(m_searchProgressLineEdit->text(), m_matchCaseCheckBox->isChecked());
1004
void MainWindow::on_findPrevious_triggered()
1006
if(!m_searchProgressLineEdit->text().isEmpty())
1008
currentTab()->findPrevious();
1012
void MainWindow::on_findNext_triggered()
1014
if(!m_searchProgressLineEdit->text().isEmpty())
1016
currentTab()->findNext();
1020
void MainWindow::on_cancelSearch_triggered()
1022
m_searchTimer->stop();
1023
m_searchProgressLineEdit->setProgress(0);
1025
m_searchToolBar->setVisible(false);
1027
for(int index = 0; index < m_tabWidget->count(); ++index)
1029
tab(index)->cancelSearch();
1033
void MainWindow::on_copyToClipboardMode_triggered(bool checked)
1035
currentTab()->setRubberBandMode(checked ? CopyToClipboardMode : ModifiersMode);
1038
void MainWindow::on_addAnnotationMode_triggered(bool checked)
1040
currentTab()->setRubberBandMode(checked ? AddAnnotationMode : ModifiersMode);
1043
void MainWindow::on_settings_triggered()
1045
SettingsDialog* settingsDialog = new SettingsDialog(m_shortcutHandler, this);
1047
if(settingsDialog->exec() == QDialog::Accepted)
1051
m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(s_settings->mainWindow().tabPosition()));
1052
m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(s_settings->mainWindow().tabVisibility()));
1054
for(int index = 0; index < m_tabWidget->count(); ++index)
1056
if(!tab(index)->refresh())
1058
QMessageBox::warning(this, tr("Warning"), tr("Could not refresh '%1'.").arg(currentTab()->filePath()));
1063
delete settingsDialog;
1066
void MainWindow::on_continuousMode_triggered(bool checked)
1068
currentTab()->setContinousMode(checked);
1071
void MainWindow::on_twoPagesMode_triggered(bool checked)
1073
currentTab()->setLayoutMode(checked ? TwoPagesMode : SinglePageMode);
1076
void MainWindow::on_twoPagesWithCoverPageMode_triggered(bool checked)
1078
currentTab()->setLayoutMode(checked ? TwoPagesWithCoverPageMode : SinglePageMode);
1081
void MainWindow::on_multiplePagesMode_triggered(bool checked)
1083
currentTab()->setLayoutMode(checked ? MultiplePagesMode : SinglePageMode);
1086
void MainWindow::on_zoomIn_triggered()
1088
currentTab()->zoomIn();
1091
void MainWindow::on_zoomOut_triggered()
1093
currentTab()->zoomOut();
1096
void MainWindow::on_originalSize_triggered()
1098
currentTab()->originalSize();
1101
void MainWindow::on_fitToPageWidthMode_triggered(bool checked)
1103
currentTab()->setScaleMode(checked ? FitToPageWidthMode : ScaleFactorMode);
1106
void MainWindow::on_fitToPageSizeMode_triggered(bool checked)
1108
currentTab()->setScaleMode(checked ? FitToPageSizeMode : ScaleFactorMode);
1111
void MainWindow::on_rotateLeft_triggered()
1113
currentTab()->rotateLeft();
1116
void MainWindow::on_rotateRight_triggered()
1118
currentTab()->rotateRight();
1121
void MainWindow::on_invertColors_triggered(bool checked)
1123
currentTab()->setInvertColors(checked);
1126
void MainWindow::on_fonts_triggered()
1128
QStandardItemModel* fontsModel = currentTab()->fontsModel();
1129
QDialog* dialog = new QDialog(this);
1131
QTableView* tableView = new QTableView(dialog);
1132
tableView->setModel(fontsModel);
1134
tableView->setAlternatingRowColors(true);
1135
tableView->setSortingEnabled(true);
1136
tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1137
tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
1139
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
1141
tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1142
tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1146
tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1147
tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1149
#endif // QT_VERSION
1151
tableView->verticalHeader()->setVisible(false);
1153
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dialog);
1154
connect(dialogButtonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
1155
connect(dialogButtonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
1157
dialog->setLayout(new QVBoxLayout(dialog));
1158
dialog->layout()->addWidget(tableView);
1159
dialog->layout()->addWidget(dialogButtonBox);
1161
dialog->resize(s_settings->mainWindow().fontsDialogSize(dialog->sizeHint()));
1163
s_settings->mainWindow().setFontsDialogSize(dialog->size());
1169
void MainWindow::on_fullscreen_triggered(bool checked)
1173
m_fullscreenAction->setData(saveGeometry());
1179
restoreGeometry(m_fullscreenAction->data().toByteArray());
1183
restoreGeometry(m_fullscreenAction->data().toByteArray());
1187
void MainWindow::on_presentation_triggered()
1189
currentTab()->startPresentation();
1192
void MainWindow::on_previousTab_triggered()
1194
if(m_tabWidget->currentIndex() > 0)
1196
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1);
1200
m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
1204
void MainWindow::on_nextTab_triggered()
1206
if(m_tabWidget->currentIndex() < m_tabWidget->count() - 1)
1208
m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1);
1212
m_tabWidget->setCurrentIndex(0);
1216
void MainWindow::on_closeTab_triggered()
1218
savePerFileSettings(currentTab());
1220
delete m_tabWidget->currentWidget();
1223
void MainWindow::on_closeAllTabs_triggered()
1225
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1227
while(m_tabWidget->count() > 0)
1229
savePerFileSettings(tab(0));
1231
delete m_tabWidget->widget(0);
1234
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1236
on_tabWidget_currentChanged(-1);
1239
void MainWindow::on_closeAllTabsButCurrentTab_triggered()
1241
DocumentView* newTab = currentTab();
1244
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1246
m_tabWidget->removeTab(m_tabWidget->currentIndex());
1248
while(m_tabWidget->count() > 0)
1250
savePerFileSettings(tab(0));
1252
delete m_tabWidget->widget(0);
1255
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1258
QFileInfo fileInfo(newTab->filePath());
1260
int index = m_tabWidget->addTab(newTab, fileInfo.completeBaseName());
1261
m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
1262
m_tabWidget->setCurrentIndex(index);
1265
void MainWindow::on_tabAction_triggered()
1267
for(int index = 0; index < m_tabWidget->count(); ++index)
1269
if(sender()->parent() == m_tabWidget->widget(index))
1271
m_tabWidget->setCurrentIndex(index);
1278
void MainWindow::on_tabShortcut_activated()
1280
for(int index = 0; index < 9; ++index)
1282
if(sender() == m_tabShortcuts[index])
1284
m_tabWidget->setCurrentIndex(index);
1291
void MainWindow::on_previousBookmark_triggered()
1293
BookmarkMenu* bookmark = bookmarkForCurrentTab();
1297
QList< int > pages = bookmark->pages();
1299
if(!pages.isEmpty())
1303
QList< int >::const_iterator lowerBound = --qLowerBound(pages, currentTab()->currentPage());
1305
if(lowerBound >= pages.constBegin())
1307
currentTab()->jumpToPage(*lowerBound);
1311
currentTab()->jumpToPage(pages.last());
1317
void MainWindow::on_nextBookmark_triggered()
1319
BookmarkMenu* bookmark = bookmarkForCurrentTab();
1323
QList< int > pages = bookmark->pages();
1325
if(!pages.isEmpty())
1329
QList< int >::const_iterator upperBound = qUpperBound(pages, currentTab()->currentPage());
1331
if(upperBound < pages.constEnd())
1333
currentTab()->jumpToPage(*upperBound);
1337
currentTab()->jumpToPage(pages.first());
1343
void MainWindow::on_addBookmark_triggered()
1345
BookmarkMenu* bookmark = bookmarkForCurrentTab();
1349
bookmark->addJumpToPageAction(currentTab()->currentPage());
1353
bookmark = new BookmarkMenu(currentTab()->filePath(), this);
1355
bookmark->addJumpToPageAction(currentTab()->currentPage());
1357
connect(bookmark, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
1358
connect(bookmark, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
1359
connect(bookmark, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
1361
m_bookmarksMenu->addMenu(bookmark);
1365
void MainWindow::on_removeBookmark_triggered()
1367
BookmarkMenu* bookmark = bookmarkForCurrentTab();
1371
bookmark->removeJumpToPageAction(currentTab()->currentPage());
1375
void MainWindow::on_removeAllBookmarks_triggered()
1377
foreach(QAction* action, m_bookmarksMenu->actions())
1379
BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1388
void MainWindow::on_bookmark_openTriggered(const QString& filePath)
1390
if(m_tabWidget->currentIndex() != -1)
1396
openInNewTab(filePath);
1400
void MainWindow::on_bookmark_openInNewTabTriggered(const QString& filePath)
1402
openInNewTab(filePath);
1405
void MainWindow::on_bookmark_jumpToPageTriggered(const QString& filePath, int page)
1407
jumpToPageOrOpenInNewTab(filePath, page);
1410
void MainWindow::on_contents_triggered()
1412
QDialog* dialog = new QDialog(this);
1414
QTextBrowser* textBrowser = new QTextBrowser(dialog);
1415
textBrowser->setSearchPaths(QStringList() << QDir(QApplication::applicationDirPath()).filePath("data") << DATA_INSTALL_PATH);
1416
textBrowser->setSource(QUrl("help.html"));
1418
QDialogButtonBox* dialogButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dialog);
1419
connect(dialogButtonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
1420
connect(dialogButtonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
1422
dialog->setLayout(new QVBoxLayout(dialog));
1423
dialog->layout()->addWidget(textBrowser);
1424
dialog->layout()->addWidget(dialogButtonBox);
1426
dialog->resize(s_settings->mainWindow().contentsDialogSize(dialog->sizeHint()));
1428
s_settings->mainWindow().setContentsDialogSize(dialog->size());
1433
void MainWindow::on_about_triggered()
1435
QMessageBox::about(this, tr("About qpdfview"), (tr("<p><b>qpdfview %1</b></p><p>qpdfview is a tabbed document viewer using Qt.</p>"
1436
"<p>This version includes:"
1439
+ tr("<li>PDF support using Poppler</li>")
1442
+ tr("<li>PS support using libspectre</li>")
1445
+ tr("<li>DjVu support using DjVuLibre</li>")
1448
+ tr("<li>Printing support using CUPS</li>")
1451
"<p>See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>© 2012-2013 The qpdfview developers</p>")).arg(QApplication::applicationVersion()));
1454
void MainWindow::on_highlightAll_clicked(bool checked)
1456
currentTab()->setHighlightAll(checked);
1459
void MainWindow::on_outline_clicked(const QModelIndex& index)
1462
int page = m_outlineView->model()->data(index, Qt::UserRole + 1).toInt(&ok);
1463
qreal left = m_outlineView->model()->data(index, Qt::UserRole + 2).toReal();
1464
qreal top = m_outlineView->model()->data(index, Qt::UserRole + 3).toReal();
1468
currentTab()->jumpToPage(page, true, left, top);
1472
void MainWindow::on_thumbnails_verticalScrollBar_valueChanged(int value)
1476
if(m_thumbnailsView->scene() != 0)
1478
QRectF visibleRect = m_thumbnailsView->mapToScene(m_thumbnailsView->viewport()->rect()).boundingRect();
1480
foreach(ThumbnailItem* page, currentTab()->thumbnailItems())
1482
if(!page->boundingRect().translated(page->pos()).intersects(visibleRect))
1484
page->cancelRender();
1490
void MainWindow::closeEvent(QCloseEvent* event)
1495
for(int index = 0; index < m_tabWidget->count(); ++index)
1497
savePerFileSettings(tab(index));
1500
removeToolBar(m_searchToolBar);
1502
s_settings->mainWindow().setRecentlyUsed(s_settings->mainWindow().trackRecentlyUsed() ? m_recentlyUsedMenu->filePaths() : QStringList());
1504
s_settings->documentView().setMatchCase(m_matchCaseCheckBox->isChecked());
1506
s_settings->mainWindow().setGeometry(m_fullscreenAction->isChecked() ? m_fullscreenAction->data().toByteArray() : saveGeometry());
1507
s_settings->mainWindow().setState(saveState());
1509
QMainWindow::closeEvent(event);
1512
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
1514
if(event->mimeData()->hasUrls())
1516
event->acceptProposedAction();
1520
void MainWindow::dropEvent(QDropEvent* event)
1522
if(event->mimeData()->hasUrls())
1524
event->acceptProposedAction();
1526
disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1528
foreach(QUrl url, event->mimeData()->urls())
1530
#if QT_VERSION >= QT_VERSION_CHECK(4,8,0)
1531
if(url.isLocalFile())
1533
if(url.scheme() == "file")
1534
#endif // QT_VERSION
1536
openInNewTab(url.toLocalFile());
1540
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1542
on_tabWidget_currentChanged(m_tabWidget->currentIndex());
1546
DocumentView* MainWindow::currentTab() const
1548
return qobject_cast< DocumentView* >(m_tabWidget->currentWidget());
1551
DocumentView* MainWindow::tab(int index) const
1553
return qobject_cast< DocumentView* >(m_tabWidget->widget(index));
1556
bool MainWindow::senderIsCurrentTab() const
1558
return sender() == m_tabWidget->currentWidget() || qobject_cast< DocumentView* >(sender()) == 0;
1561
QString MainWindow::windowTitleSuffixForCurrentTab() const
1563
if(s_settings->mainWindow().currentPageInWindowTitle())
1565
return QString(" (%1 / %2) - qpdfview").arg(currentTab()->currentPage()).arg(currentTab()->numberOfPages());
1569
return QLatin1String(" - qpdfview");
1573
BookmarkMenu* MainWindow::bookmarkForCurrentTab() const
1575
foreach(QAction* action, m_bookmarksMenu->actions())
1577
BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1581
if(QFileInfo(bookmark->filePath()).absoluteFilePath() == QFileInfo(currentTab()->filePath()).absoluteFilePath())
1591
void MainWindow::createWidgets()
1593
m_tabWidget = new TabWidget(this);
1595
m_tabWidget->setDocumentMode(true);
1596
m_tabWidget->setMovable(true);
1597
m_tabWidget->setTabsClosable(true);
1598
m_tabWidget->setElideMode(Qt::ElideRight);
1600
m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(s_settings->mainWindow().tabPosition()));
1601
m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(s_settings->mainWindow().tabVisibility()));
1603
setCentralWidget(m_tabWidget);
1605
connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(on_tabWidget_currentChanged(int)));
1606
connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(on_tabWidget_tabCloseRequested(int)));
1610
m_currentPageSpinBox = new SpinBox(this);
1612
m_currentPageSpinBox->setAlignment(Qt::AlignCenter);
1613
m_currentPageSpinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
1614
m_currentPageSpinBox->setKeyboardTracking(false);
1616
connect(m_currentPageSpinBox, SIGNAL(editingFinished()), SLOT(on_currentPage_editingFinished()));
1617
connect(m_currentPageSpinBox, SIGNAL(returnPressed()), SLOT(on_currentPage_returnPressed()));
1619
m_currentPageAction = new QWidgetAction(this);
1621
m_currentPageAction->setObjectName(QLatin1String("currentPage"));
1622
m_currentPageAction->setDefaultWidget(m_currentPageSpinBox);
1626
m_scaleFactorComboBox = new ComboBox(this);
1628
m_scaleFactorComboBox->setEditable(true);
1629
m_scaleFactorComboBox->setInsertPolicy(QComboBox::NoInsert);
1631
m_scaleFactorComboBox->addItem(tr("Page width"));
1632
m_scaleFactorComboBox->addItem(tr("Page size"));
1633
m_scaleFactorComboBox->addItem("50 %", 0.5);
1634
m_scaleFactorComboBox->addItem("75 %", 0.75);
1635
m_scaleFactorComboBox->addItem("100 %", 1.0);
1636
m_scaleFactorComboBox->addItem("125 %", 1.25);
1637
m_scaleFactorComboBox->addItem("150 %", 1.5);
1638
m_scaleFactorComboBox->addItem("200 %", 2.0);
1639
m_scaleFactorComboBox->addItem("400 %", 4.0);
1641
connect(m_scaleFactorComboBox, SIGNAL(activated(int)), SLOT(on_scaleFactor_activated(int)));
1642
connect(m_scaleFactorComboBox->lineEdit(), SIGNAL(editingFinished()), SLOT(on_scaleFactor_editingFinished()));
1643
connect(m_scaleFactorComboBox->lineEdit(), SIGNAL(returnPressed()), SLOT(on_scaleFactor_returnPressed()));
1645
m_scaleFactorAction = new QWidgetAction(this);
1647
m_scaleFactorAction->setObjectName(QLatin1String("scaleFactor"));
1648
m_scaleFactorAction->setDefaultWidget(m_scaleFactorComboBox);
1652
m_searchProgressLineEdit = new ProgressLineEdit(this);
1653
m_searchTimer = new QTimer(this);
1655
m_searchTimer->setInterval(2000);
1656
m_searchTimer->setSingleShot(true);
1658
connect(m_searchProgressLineEdit, SIGNAL(textEdited(QString)), m_searchTimer, SLOT(start()));
1659
connect(m_searchProgressLineEdit, SIGNAL(returnPressed(Qt::KeyboardModifiers)), SLOT(on_search_returnPressed(Qt::KeyboardModifiers)));
1660
connect(m_searchTimer, SIGNAL(timeout()), SLOT(on_search_timeout()));
1662
m_matchCaseCheckBox = new QCheckBox(tr("Match &case"), this);
1663
m_highlightAllCheckBox = new QCheckBox(tr("Highlight &all"), this);
1665
connect(m_highlightAllCheckBox, SIGNAL(clicked(bool)), SLOT(on_highlightAll_clicked(bool)));
1668
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QIcon& icon, const QKeySequence& shortcut, const char* member, bool checkable)
1670
QAction* action = new QAction(text, this);
1672
action->setObjectName(objectName);
1673
action->setIcon(icon);
1674
action->setShortcut(shortcut);
1676
if(!objectName.isEmpty())
1678
m_shortcutHandler->registerAction(action);
1683
action->setCheckable(true);
1685
connect(action, SIGNAL(triggered(bool)), member);
1689
action->setIconVisibleInMenu(true);
1691
connect(action, SIGNAL(triggered()), member);
1697
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QString& iconName, const QKeySequence& shortcut, const char* member, bool checkable)
1699
return createAction(text, objectName, QIcon::fromTheme(iconName, QIcon(QLatin1String(":icons/") + iconName + QLatin1String(".svg"))), shortcut, member, checkable);
1702
void MainWindow::createActions()
1706
m_openAction = createAction(tr("&Open..."), QLatin1String("open"), QLatin1String("document-open"), QKeySequence::Open, SLOT(on_open_triggered()));
1707
m_openInNewTabAction = createAction(tr("Open in new &tab..."), QLatin1String("openInNewTab"), QLatin1String("tab-new"), QKeySequence::AddTab, SLOT(on_openInNewTab_triggered()));
1708
m_refreshAction = createAction(tr("&Refresh"), QLatin1String("refresh"), QLatin1String("view-refresh"), QKeySequence::Refresh, SLOT(on_refresh_triggered()));
1709
m_saveCopyAction = createAction(tr("&Save copy..."), QLatin1String("saveCopy"), QLatin1String("document-save"), QKeySequence::Save, SLOT(on_saveCopy_triggered()));
1710
m_saveAsAction = createAction(tr("Save &as..."), QLatin1String("saveAs"), QLatin1String("document-save-as"), QKeySequence::SaveAs, SLOT(on_saveAs_triggered()));
1711
m_printAction = createAction(tr("&Print..."), QLatin1String("print"), QLatin1String("document-print"), QKeySequence::Print, SLOT(on_print_triggered()));
1712
m_exitAction = createAction(tr("E&xit"), QLatin1String("exit"), QIcon::fromTheme("application-exit"), QKeySequence::Quit, SLOT(close()));
1716
m_previousPageAction = createAction(tr("&Previous page"), QLatin1String("previousPage"), QLatin1String("go-previous"), QKeySequence(Qt::Key_Backspace), SLOT(on_previousPage_triggered()));
1717
m_nextPageAction = createAction(tr("&Next page"), QLatin1String("nextPage"), QLatin1String("go-next"), QKeySequence(Qt::Key_Space), SLOT(on_nextPage_triggered()));
1718
m_firstPageAction = createAction(tr("&First page"), QLatin1String("firstPage"), QLatin1String("go-first"), QKeySequence(Qt::Key_Home), SLOT(on_firstPage_triggered()));
1719
m_lastPageAction = createAction(tr("&Last page"), QLatin1String("lastPage"), QLatin1String("go-last"), QKeySequence(Qt::Key_End), SLOT(on_lastPage_triggered()));
1721
m_jumpToPageAction = createAction(tr("&Jump to page..."), QLatin1String("jumpToPage"), QLatin1String("go-jump"), QKeySequence(Qt::CTRL + Qt::Key_J), SLOT(on_jumpToPage_triggered()));
1723
m_jumpBackwardAction = createAction(tr("Jump &backward"), QLatin1String("jumpBackward"), QLatin1String("media-seek-backward"), QKeySequence(Qt::CTRL + Qt::Key_Return), SLOT(on_jumpBackward_triggered()));
1724
m_jumpForwardAction = createAction(tr("Jump for&ward"), QLatin1String("jumpForward"), QLatin1String("media-seek-forward"), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Return), SLOT(on_jumpForward_triggered()));
1726
m_searchAction = createAction(tr("&Search..."), QLatin1String("search"), QLatin1String("edit-find"), QKeySequence::Find, SLOT(on_search_triggered()));
1727
m_findPreviousAction = createAction(tr("Find previous"), QLatin1String("findPrevious"), QLatin1String("go-up"), QKeySequence::FindPrevious, SLOT(on_findPrevious_triggered()));
1728
m_findNextAction = createAction(tr("Find next"), QLatin1String("findNext"), QLatin1String("go-down"), QKeySequence::FindNext, SLOT(on_findNext_triggered()));
1729
m_cancelSearchAction = createAction(tr("Cancel search"), QLatin1String("cancelSearch"), QLatin1String("process-stop"), QKeySequence(Qt::Key_Escape), SLOT(on_cancelSearch_triggered()));
1731
m_copyToClipboardModeAction = createAction(tr("&Copy to clipboard"), QLatin1String("copyToClipboardMode"), QLatin1String("edit-copy"), QKeySequence(Qt::CTRL + Qt::Key_C), SLOT(on_copyToClipboardMode_triggered(bool)), true);
1732
m_addAnnotationModeAction = createAction(tr("&Add annotation"), QLatin1String("addAnnotationMode"), QLatin1String("mail-attachment"), QKeySequence(Qt::CTRL + Qt::Key_A), SLOT(on_addAnnotationMode_triggered(bool)), true);
1734
m_settingsAction = createAction(tr("Settings..."), QString(), QIcon(), QKeySequence(), SLOT(on_settings_triggered()));
1738
m_continuousModeAction = createAction(tr("&Continuous"), QLatin1String("continuousMode"), QIcon(":icons/continuous.svg"), QKeySequence(Qt::CTRL + Qt::Key_7), SLOT(on_continuousMode_triggered(bool)), true);
1739
m_twoPagesModeAction = createAction(tr("&Two pages"), QLatin1String("twoPagesMode"), QIcon(":icons/two-pages.svg"), QKeySequence(Qt::CTRL + Qt::Key_6), SLOT(on_twoPagesMode_triggered(bool)), true);
1740
m_twoPagesWithCoverPageModeAction = createAction(tr("Two pages &with cover page"), QLatin1String("twoPagesWithCoverPageMode"), QIcon(":icons/two-pages-with-cover-page.svg"), QKeySequence(Qt::CTRL + Qt::Key_5), SLOT(on_twoPagesWithCoverPageMode_triggered(bool)), true);
1741
m_multiplePagesModeAction = createAction(tr("&Multiple pages"), QLatin1String("multiplePagesMode"), QIcon(":icons/multiple-pages.svg"), QKeySequence(Qt::CTRL + Qt::Key_4), SLOT(on_multiplePagesMode_triggered(bool)), true);
1743
m_zoomInAction = createAction(tr("Zoom &in"), QLatin1String("zoomIn"), QLatin1String("zoom-in"), QKeySequence(Qt::CTRL + Qt::Key_Up), SLOT(on_zoomIn_triggered()));
1744
m_zoomOutAction = createAction(tr("Zoom &out"), QLatin1String("zoomOut"), QLatin1String("zoom-out"), QKeySequence(Qt::CTRL + Qt::Key_Down), SLOT(on_zoomOut_triggered()));
1745
m_originalSizeAction = createAction(tr("Original &size"), QLatin1String("originalSize"), QLatin1String("zoom-original"), QKeySequence(Qt::CTRL + Qt::Key_0), SLOT(on_originalSize_triggered()));
1747
m_fitToPageWidthModeAction = createAction(tr("Fit to page width"), QLatin1String("fitToPageWidthMode"), QIcon(":icons/fit-to-page-width.svg"), QKeySequence(Qt::CTRL + Qt::Key_9), SLOT(on_fitToPageWidthMode_triggered(bool)), true);
1748
m_fitToPageSizeModeAction = createAction(tr("Fit to page size"), QLatin1String("fitToPageSizeMode"), QIcon(":icons/fit-to-page-size.svg"), QKeySequence(Qt::CTRL + Qt::Key_8), SLOT(on_fitToPageSizeMode_triggered(bool)), true);
1750
m_rotateLeftAction = createAction(tr("Rotate &left"), QLatin1String("rotateLeft"), QLatin1String("object-rotate-left"), QKeySequence(Qt::CTRL + Qt::Key_Left), SLOT(on_rotateLeft_triggered()));
1751
m_rotateRightAction = createAction(tr("Rotate &right"), QLatin1String("rotateRight"), QLatin1String("object-rotate-right"), QKeySequence(Qt::CTRL + Qt::Key_Right), SLOT(on_rotateRight_triggered()));
1753
m_invertColorsAction = createAction(tr("Invert colors"), QLatin1String("invertColors"), QIcon(), QKeySequence(Qt::CTRL + Qt::Key_I), SLOT(on_invertColors_triggered(bool)), true);
1755
m_fontsAction = createAction(tr("Fonts..."), QString(), QIcon(), QKeySequence(), SLOT(on_fonts_triggered()));
1757
m_fullscreenAction = createAction(tr("&Fullscreen"), QLatin1String("fullscreen"), QLatin1String("view-fullscreen"), QKeySequence(Qt::Key_F11), SLOT(on_fullscreen_triggered(bool)), true);
1758
m_presentationAction = createAction(tr("&Presentation..."), QLatin1String("presentation"), QLatin1String("x-office-presentation"), QKeySequence(Qt::Key_F12), SLOT(on_presentation_triggered()));
1762
m_previousTabAction = createAction(tr("&Previous tab"), QLatin1String("previousTab"), QIcon(), QKeySequence::PreviousChild, SLOT(on_previousTab_triggered()));
1763
m_nextTabAction = createAction(tr("&Next tab"), QLatin1String("nextTab"), QIcon(), QKeySequence::NextChild, SLOT(on_nextTab_triggered()));
1765
m_closeTabAction = createAction(tr("&Close tab"), QLatin1String("closeTab"), QIcon::fromTheme("window-close"), QKeySequence(Qt::CTRL + Qt::Key_W), SLOT(on_closeTab_triggered()));
1766
m_closeAllTabsAction = createAction(tr("Close &all tabs"), QLatin1String("closeAllTabs"), QIcon(), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W), SLOT(on_closeAllTabs_triggered()));
1767
m_closeAllTabsButCurrentTabAction = createAction(tr("Close all tabs &but current tab"), QLatin1String("closeAllTabsButCurrent"), QIcon(), QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_W), SLOT(on_closeAllTabsButCurrentTab_triggered()));
1771
for(int index = 0; index < 9; ++index)
1773
m_tabShortcuts[index] = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_1 + index), this, SLOT(on_tabShortcut_activated()));
1778
m_previousBookmarkAction = createAction(tr("&Previous bookmark"), QLatin1String("previousBookmarkAction"), QIcon(), QKeySequence(Qt::CTRL + Qt::Key_PageUp), SLOT(on_previousBookmark_triggered()));
1779
m_nextBookmarkAction = createAction(tr("&Next bookmark"), QLatin1String("nextBookmarkAction"), QIcon(), QKeySequence(Qt::CTRL + Qt::Key_PageDown), SLOT(on_nextBookmark_triggered()));
1781
m_addBookmarkAction = createAction(tr("&Add bookmark"), QLatin1String("addBookmark"), QIcon(), QKeySequence(Qt::CTRL + Qt::Key_B), SLOT(on_addBookmark_triggered()));
1782
m_removeBookmarkAction = createAction(tr("&Remove bookmark"), QLatin1String("removeBookmark"), QIcon(), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B), SLOT(on_removeBookmark_triggered()));
1783
m_removeAllBookmarksAction = createAction(tr("Remove all bookmarks"), QLatin1String("removeAllBookmark"), QIcon(), QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_B), SLOT(on_removeAllBookmarks_triggered()));
1787
m_contentsAction = createAction(tr("&Contents"), QLatin1String("contents"), QIcon::fromTheme("help-contents"), QKeySequence::HelpContents, SLOT(on_contents_triggered()));
1788
m_aboutAction = createAction(tr("&About"), QString(), QIcon::fromTheme("help-about"), QKeySequence(), SLOT(on_about_triggered()));
1791
QToolBar* MainWindow::createToolBar(const QString& text, const QString& objectName, const QStringList& actionNames, const QList< QAction* >& actions)
1793
QToolBar* toolBar = addToolBar(text);
1795
toolBar->setObjectName(objectName);
1797
foreach(QString actionName, actionNames)
1799
if(actionName == QLatin1String("separator"))
1801
toolBar->addSeparator();
1806
foreach(QAction* action, actions)
1808
if(actionName == action->objectName())
1810
toolBar->addAction(action);
1820
void MainWindow::createToolBars()
1822
m_fileToolBar = createToolBar(tr("&File"), QLatin1String("fileToolBar"), s_settings->mainWindow().fileToolBar(),
1823
QList< QAction* >() << m_openAction << m_openInNewTabAction << m_refreshAction << m_saveCopyAction << m_saveAsAction << m_printAction);
1825
m_editToolBar = createToolBar(tr("&Edit"), QLatin1String("editToolBar"), s_settings->mainWindow().editToolBar(),
1826
QList< QAction* >() << m_currentPageAction << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction << m_searchAction << m_jumpBackwardAction << m_jumpForwardAction << m_copyToClipboardModeAction << m_addAnnotationModeAction);
1828
m_viewToolBar = createToolBar(tr("&View"), QLatin1String("viewToolBar"), s_settings->mainWindow().viewToolBar(),
1829
QList< QAction* >() << m_scaleFactorAction << m_continuousModeAction << m_twoPagesModeAction << m_twoPagesWithCoverPageModeAction << m_multiplePagesModeAction << m_zoomInAction << m_zoomOutAction << m_originalSizeAction << m_fitToPageWidthModeAction << m_fitToPageSizeModeAction << m_rotateLeftAction << m_rotateRightAction << m_fullscreenAction << m_presentationAction);
1833
m_searchToolBar = new QToolBar(tr("&Search"), this);
1834
m_searchToolBar->setObjectName(QLatin1String("searchToolBar"));
1836
connect(m_searchToolBar, SIGNAL(visibilityChanged(bool)), m_findPreviousAction, SLOT(setEnabled(bool)));
1837
connect(m_searchToolBar, SIGNAL(visibilityChanged(bool)), m_findNextAction, SLOT(setEnabled(bool)));
1838
connect(m_searchToolBar, SIGNAL(visibilityChanged(bool)), m_cancelSearchAction, SLOT(setEnabled(bool)));
1840
m_findPreviousAction->setEnabled(false);
1841
m_findNextAction->setEnabled(false);
1842
m_cancelSearchAction->setEnabled(false);
1844
m_searchToolBar->setVisible(false);
1845
m_searchToolBar->setMovable(false);
1847
addToolBar(Qt::BottomToolBarArea, m_searchToolBar);
1849
m_searchToolBar->addWidget(m_searchProgressLineEdit);
1850
m_searchToolBar->addWidget(m_matchCaseCheckBox);
1851
m_searchToolBar->addWidget(m_highlightAllCheckBox);
1852
m_searchToolBar->addAction(m_findPreviousAction);
1853
m_searchToolBar->addAction(m_findNextAction);
1854
m_searchToolBar->addAction(m_cancelSearchAction);
1857
QDockWidget* MainWindow::createDock(const QString& text, const QString& objectName, const QKeySequence& toggleViewShortcut)
1859
QDockWidget* dock = new QDockWidget(text, this);
1861
dock->setObjectName(objectName);
1862
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1863
dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1865
addDockWidget(Qt::LeftDockWidgetArea, dock);
1867
dock->toggleViewAction()->setObjectName(objectName + QLatin1String("ToggleView"));
1868
dock->toggleViewAction()->setShortcut(toggleViewShortcut);
1870
m_shortcutHandler->registerAction(dock->toggleViewAction());
1877
void MainWindow::createDocks()
1881
m_outlineDock = createDock(tr("&Outline"), QLatin1String("outlineDock"), QKeySequence(Qt::Key_F6));
1883
m_outlineView = new TreeView(this);
1884
m_outlineView->setAlternatingRowColors(true);
1885
m_outlineView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1887
m_outlineView->header()->setStretchLastSection(false);
1888
m_outlineView->header()->setVisible(false);
1890
connect(m_outlineView, SIGNAL(clicked(QModelIndex)), SLOT(on_outline_clicked(QModelIndex)));
1892
m_outlineDock->setWidget(m_outlineView);
1896
m_propertiesDock = createDock(tr("&Properties"), QLatin1String("propertiesDock"), QKeySequence(Qt::Key_F7));
1898
m_propertiesView = new QTableView(this);
1899
m_propertiesView->setAlternatingRowColors(true);
1900
m_propertiesView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1902
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
1904
m_propertiesView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
1905
m_propertiesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1909
m_propertiesView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
1910
m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1912
#endif // QT_VERSION
1914
m_propertiesView->horizontalHeader()->setVisible(false);
1915
m_propertiesView->verticalHeader()->setVisible(false);
1917
m_propertiesDock->setWidget(m_propertiesView);
1921
m_thumbnailsDock = createDock(tr("&Thumbnails"), QLatin1String("thumbnailsDock"), QKeySequence(Qt::Key_F8));
1923
m_thumbnailsView = new QGraphicsView(this);
1925
connect(m_thumbnailsView->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(on_thumbnails_verticalScrollBar_valueChanged(int)));
1927
m_thumbnailsDock->setWidget(m_thumbnailsView);
1930
void MainWindow::createMenus()
1934
m_fileMenu = menuBar()->addMenu(tr("&File"));
1935
m_fileMenu->addActions(QList< QAction* >() << m_openAction << m_openInNewTabAction);
1937
m_recentlyUsedMenu = new RecentlyUsedMenu(this);
1939
if(s_settings->mainWindow().trackRecentlyUsed())
1941
foreach(QString filePath, s_settings->mainWindow().recentlyUsed())
1943
m_recentlyUsedMenu->addOpenAction(filePath);
1946
connect(m_recentlyUsedMenu, SIGNAL(openTriggered(QString)), SLOT(on_recentlyUsed_openTriggered(QString)));
1948
m_fileMenu->addMenu(m_recentlyUsedMenu);
1950
QToolButton* openToolButton = qobject_cast< QToolButton* >(m_fileToolBar->widgetForAction(m_openAction));
1951
if(openToolButton != 0)
1953
openToolButton->setMenu(m_recentlyUsedMenu);
1956
QToolButton* openInNewTabToolButton = qobject_cast< QToolButton* >(m_fileToolBar->widgetForAction(m_openInNewTabAction));
1957
if(openInNewTabToolButton != 0)
1959
openInNewTabToolButton->setMenu(m_recentlyUsedMenu);
1963
m_fileMenu->addActions(QList< QAction* >() << m_refreshAction << m_saveCopyAction << m_saveAsAction << m_printAction);
1964
m_fileMenu->addSeparator();
1965
m_fileMenu->addAction(m_exitAction);
1969
m_editMenu = menuBar()->addMenu(tr("&Edit"));
1970
m_editMenu->addActions(QList< QAction* >() << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction);
1971
m_editMenu->addSeparator();
1972
m_editMenu->addActions(QList< QAction* >() << m_jumpBackwardAction << m_jumpForwardAction);
1973
m_editMenu->addSeparator();
1974
m_editMenu->addActions(QList< QAction* >() << m_searchAction << m_findPreviousAction << m_findNextAction << m_cancelSearchAction);
1975
m_editMenu->addSeparator();
1976
m_editMenu->addActions(QList< QAction* >() << m_copyToClipboardModeAction << m_addAnnotationModeAction);
1977
m_editMenu->addSeparator();
1978
m_editMenu->addAction(m_settingsAction);
1982
m_viewMenu = menuBar()->addMenu(tr("&View"));
1983
m_viewMenu->addActions(QList< QAction* >() << m_continuousModeAction << m_twoPagesModeAction << m_twoPagesWithCoverPageModeAction << m_multiplePagesModeAction);
1984
m_viewMenu->addSeparator();
1985
m_viewMenu->addActions(QList< QAction* >() << m_zoomInAction << m_zoomOutAction << m_originalSizeAction << m_fitToPageWidthModeAction << m_fitToPageSizeModeAction);
1986
m_viewMenu->addSeparator();
1987
m_viewMenu->addActions(QList< QAction* >() << m_rotateLeftAction << m_rotateRightAction);
1988
m_viewMenu->addSeparator();
1989
m_viewMenu->addAction(m_invertColorsAction);
1990
m_viewMenu->addSeparator();
1992
QMenu* toolBarsMenu = m_viewMenu->addMenu(tr("&Tool bars"));
1993
toolBarsMenu->addActions(QList< QAction* >() << m_fileToolBar->toggleViewAction() << m_editToolBar->toggleViewAction() << m_viewToolBar->toggleViewAction());
1995
QMenu* docksMenu = m_viewMenu->addMenu(tr("&Docks"));
1996
docksMenu->addActions(QList< QAction* >() << m_outlineDock->toggleViewAction() << m_propertiesDock->toggleViewAction() << m_thumbnailsDock->toggleViewAction());
1998
m_viewMenu->addAction(m_fontsAction);
1999
m_viewMenu->addSeparator();
2000
m_viewMenu->addActions(QList< QAction* >() << m_fullscreenAction << m_presentationAction);
2004
m_tabsMenu = menuBar()->addMenu(tr("&Tabs"));
2005
m_tabsMenu->addActions(QList< QAction* >() << m_previousTabAction << m_nextTabAction);
2006
m_tabsMenu->addSeparator();
2007
m_tabsMenu->addActions(QList< QAction* >() << m_closeTabAction << m_closeAllTabsAction << m_closeAllTabsButCurrentTabAction);
2008
m_tabsMenu->addSeparator();
2012
m_bookmarksMenu = menuBar()->addMenu(tr("&Bookmarks"));
2013
m_bookmarksMenu->addActions(QList< QAction* >() << m_previousBookmarkAction << m_nextBookmarkAction);
2014
m_bookmarksMenu->addSeparator();
2015
m_bookmarksMenu->addActions(QList< QAction* >() << m_addBookmarkAction << m_removeBookmarkAction << m_removeAllBookmarksAction);
2016
m_bookmarksMenu->addSeparator();
2020
m_helpMenu = menuBar()->addMenu(tr("&Help"));
2021
m_helpMenu->addActions(QList< QAction* >() << m_contentsAction << m_aboutAction);
2024
void MainWindow::createDatabase()
2028
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
2030
QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
2034
QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
2036
#endif // QT_VERSION
2038
QDir().mkpath(path);
2040
m_database = QSqlDatabase::addDatabase("QSQLITE");
2041
m_database.setDatabaseName(QDir(path).filePath("database"));
2044
if(m_database.isOpen())
2046
m_database.transaction();
2048
QStringList tables = m_database.tables();
2049
QSqlQuery query(m_database);
2053
if(!tables.contains("tabs_v2"))
2055
query.exec("CREATE TABLE tabs_v2 "
2057
",instanceName TEXT"
2058
",currentPage INTEGER"
2059
",continuousMode INTEGER"
2060
",layoutMode INTEGER"
2061
",scaleMode INTEGER"
2063
",rotation INTEGER)");
2065
if(!query.isActive())
2067
qDebug() << query.lastError();
2073
if(!tables.contains("bookmarks_v1"))
2075
query.exec("CREATE TABLE bookmarks_v1 "
2079
if(!query.isActive())
2081
qDebug() << query.lastError();
2085
// per-file settings
2087
if(!tables.contains("perfilesettings_v1"))
2089
query.exec("CREATE TABLE perfilesettings_v1 "
2091
",filePath TEXT PRIMARY KEY"
2092
",currentPage INTEGER"
2093
",continuousMode INTEGER"
2094
",layoutMode INTEGER"
2095
",scaleMode INTEGER"
2097
",rotation INTEGER)");
2099
if(!query.isActive())
2101
qDebug() << query.lastError();
2105
if(s_settings->mainWindow().restorePerFileSettings())
2107
query.exec("DELETE FROM perfilesettings_v1 WHERE filePath IN (SELECT filePath FROM perfilesettings_v1 ORDER BY lastUsed DESC LIMIT -1 OFFSET 1000)");
2111
query.exec("DELETE FROM perfilesettings_v1");
2114
if(!query.isActive())
2116
qDebug() << query.lastError();
2119
m_database.commit();
2123
qDebug() << m_database.lastError();
2129
void MainWindow::restoreTabs()
2133
if(m_database.isOpen())
2135
m_database.transaction();
2137
QSqlQuery query(m_database);
2138
query.prepare("SELECT filePath,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM tabs_v2 WHERE instanceName==?");
2140
query.bindValue(0, objectName());
2146
if(!query.isActive())
2148
qDebug() << query.lastError();
2152
if(openInNewTab(query.value(0).toString()))
2154
currentTab()->setContinousMode(static_cast< bool >(query.value(2).toUInt()));
2155
currentTab()->setLayoutMode(static_cast< LayoutMode >(query.value(3).toUInt()));
2157
currentTab()->setScaleMode(static_cast< ScaleMode >(query.value(4).toUInt()));
2158
currentTab()->setScaleFactor(query.value(5).toReal());
2160
currentTab()->setRotation(static_cast< Rotation >(query.value(6).toUInt()));
2162
currentTab()->jumpToPage(query.value(1).toInt());
2166
m_database.commit();
2172
void MainWindow::saveTabs()
2176
if(m_database.isOpen())
2178
m_database.transaction();
2180
QSqlQuery query(m_database);
2182
if(s_settings->mainWindow().restoreTabs())
2184
query.prepare("DELETE FROM tabs_v2 WHERE instanceName==?");
2186
query.bindValue(0, objectName());
2190
if(!query.isActive())
2192
qDebug() << query.lastError();
2195
query.prepare("INSERT INTO tabs_v2 "
2196
"(filePath,instanceName,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation)"
2197
" VALUES (?,?,?,?,?,?,?,?)");
2199
for(int index = 0; index < m_tabWidget->count(); ++index)
2201
query.bindValue(0, QFileInfo(tab(index)->filePath()).absoluteFilePath());
2202
query.bindValue(1, objectName());
2203
query.bindValue(2, tab(index)->currentPage());
2205
query.bindValue(3, static_cast< uint >(tab(index)->continousMode()));
2206
query.bindValue(4, static_cast< uint >(tab(index)->layoutMode()));
2208
query.bindValue(5, static_cast< uint >(tab(index)->scaleMode()));
2209
query.bindValue(6, tab(index)->scaleFactor());
2211
query.bindValue(7, static_cast< uint >(tab(index)->rotation()));
2215
if(!query.isActive())
2217
qDebug() << query.lastError();
2224
query.exec("DELETE FROM tabs_v2");
2226
if(!query.isActive())
2228
qDebug() << query.lastError();
2232
m_database.commit();
2238
void MainWindow::restoreBookmarks()
2242
if(m_database.isOpen())
2244
m_database.transaction();
2246
QSqlQuery query(m_database);
2247
query.exec("SELECT filePath,pages FROM bookmarks_v1");
2251
if(!query.isActive())
2253
qDebug() << query.lastError();
2257
BookmarkMenu* bookmark = new BookmarkMenu(query.value(0).toString(), this);
2259
QStringList pages = query.value(1).toString().split(",", QString::SkipEmptyParts);
2261
foreach(QString page, pages)
2263
bookmark->addJumpToPageAction(page.toInt());
2266
connect(bookmark, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
2267
connect(bookmark, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
2268
connect(bookmark, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
2270
m_bookmarksMenu->addMenu(bookmark);
2273
m_database.commit();
2279
void MainWindow::saveBookmarks()
2283
if(m_database.isOpen())
2285
m_database.transaction();
2287
QSqlQuery query(m_database);
2288
query.exec("DELETE FROM bookmarks_v1");
2290
if(!query.isActive())
2292
qDebug() << query.lastError();
2295
if(s_settings->mainWindow().restoreBookmarks())
2297
query.prepare("INSERT INTO bookmarks_v1 "
2301
foreach(QAction* action, m_bookmarksMenu->actions())
2303
BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
2309
foreach(int page, bookmark->pages())
2311
pages.append(QString::number(page));
2314
query.bindValue(0, QFileInfo(bookmark->filePath()).absoluteFilePath());
2315
query.bindValue(1, pages.join(","));
2319
if(!query.isActive())
2321
qDebug() << query.lastError();
2328
m_database.commit();
2334
void MainWindow::restorePerFileSettings(DocumentView* tab)
2338
if(s_settings->mainWindow().restorePerFileSettings() && m_database.isOpen() && tab != 0)
2340
m_database.transaction();
2342
QSqlQuery query(m_database);
2343
query.prepare("SELECT currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM perfilesettings_v1 WHERE filePath==?");
2345
query.bindValue(0, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
2351
tab->setContinousMode(query.value(1).toBool());
2352
tab->setLayoutMode(static_cast< LayoutMode >(query.value(2).toUInt()));
2354
tab->setScaleMode(static_cast< ScaleMode >(query.value(3).toUInt()));
2355
tab->setScaleFactor(query.value(4).toReal());
2357
tab->setRotation(static_cast< Rotation >(query.value(5).toUInt()));
2359
tab->jumpToPage(query.value(0).toInt(), false);
2362
if(!query.isActive())
2364
qDebug() << query.lastError();
2367
m_database.commit();
2377
void MainWindow::savePerFileSettings(const DocumentView* tab)
2381
if(s_settings->mainWindow().restorePerFileSettings() && m_database.isOpen() && tab != 0)
2383
m_database.transaction();
2385
QSqlQuery query(m_database);
2386
query.prepare("INSERT OR REPLACE INTO perfilesettings_v1 "
2387
"(lastUsed,filePath,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation)"
2388
" VALUES (?,?,?,?,?,?,?,?)");
2390
query.bindValue(0, QDateTime::currentDateTime().toTime_t());
2392
query.bindValue(1, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
2393
query.bindValue(2, tab->currentPage());
2395
query.bindValue(3, static_cast< uint >(tab->continousMode()));
2396
query.bindValue(4, static_cast< uint >(tab->layoutMode()));
2398
query.bindValue(5, static_cast< uint >(tab->scaleMode()));
2399
query.bindValue(6, tab->scaleFactor());
2401
query.bindValue(7, static_cast< uint >(tab->rotation()));
2405
if(!query.isActive())
2407
qDebug() << query.lastError();
2410
m_database.commit();
2422
MainWindowAdaptor::MainWindowAdaptor(MainWindow* mainWindow) : QDBusAbstractAdaptor(mainWindow)
2426
bool MainWindowAdaptor::open(const QString& filePath, int page, const QRectF& highlight)
2428
return mainWindow()->open(filePath, page, highlight);
2431
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
2433
return mainWindow()->openInNewTab(filePath, page, highlight);
2436
bool MainWindowAdaptor::jumpToPageOrOpenInNewTab(const QString& filePath, int page, bool refreshBeforeJump, const QRectF& highlight)
2438
return mainWindow()->jumpToPageOrOpenInNewTab(filePath, page, refreshBeforeJump, highlight);
2441
void MainWindowAdaptor::startSearch(const QString& text)
2443
mainWindow()->startSearch(text);
2446
void MainWindowAdaptor::raiseAndActivate()
2448
mainWindow()->raise();
2449
mainWindow()->activateWindow();
2452
MainWindow* MainWindowAdaptor::mainWindow() const
2454
return qobject_cast< MainWindow* >(parent());
2457
# endif // WITH_DBUS