~ubuntu-branches/ubuntu/vivid/qpdfview/vivid

« back to all changes in this revision

Viewing changes to sources/mainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2014-10-22 21:49:15 UTC
  • mfrom: (1.2.15)
  • Revision ID: package-import@ubuntu.com-20141022214915-agqeoe318lzs2s4d
Tags: 0.4.12-1
* New upstream release.
* Fixed option to zoom to selection and implemented tiled rendering
  (Closes: #739554)
* Enable support for qt5 and poppler-qt5.
* Explicit dependence on hicolor-icon-theme.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
 
3
Copyright 2014 S. Razi Alavizadeh
3
4
Copyright 2012-2014 Adam Reichold
4
5
Copyright 2014 Dorian Scholz
5
6
Copyright 2012 Michał Trybus
26
27
 
27
28
#include <QApplication>
28
29
#include <QCheckBox>
 
30
#include <QDateTime>
29
31
#include <QDebug>
30
32
#include <QDesktopServices>
31
33
#include <QDockWidget>
56
58
#include "settings.h"
57
59
#include "shortcuthandler.h"
58
60
#include "pageitem.h"
 
61
#include "thumbnailitem.h"
59
62
#include "documentview.h"
60
63
#include "miscellaneous.h"
61
64
#include "printdialog.h"
64
67
#include "helpdialog.h"
65
68
#include "recentlyusedmenu.h"
66
69
#include "recentlyclosedmenu.h"
 
70
#include "bookmarkmodel.h"
67
71
#include "bookmarkmenu.h"
 
72
#include "bookmarkdialog.h"
68
73
#include "database.h"
69
74
 
70
75
namespace
146
151
    createDocks();
147
152
    createMenus();
148
153
 
 
154
    m_toggleToolBarsAction = createAction(tr("Toggle tool bars"), QLatin1String("toggleToolBars"), QIcon(), QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_T), SLOT(on_toggleToolBars_triggered(bool)), true, true);
 
155
    m_toggleMenuBarAction = createAction(tr("Toggle menu bar"), QLatin1String("toggleMenuBar"), QIcon(), QKeySequence(Qt::SHIFT + Qt::ALT + Qt::Key_M), SLOT(on_toggleMenuBar_triggered(bool)), true, true);
 
156
 
149
157
    restoreGeometry(s_settings->mainWindow().geometry());
150
158
    restoreState(s_settings->mainWindow().state());
151
159
 
153
161
 
154
162
    prepareDatabase();
155
163
 
 
164
    if(s_settings->mainWindow().restoreTabs())
 
165
    {
 
166
        s_database->restoreTabs();
 
167
    }
 
168
 
 
169
    if(s_settings->mainWindow().restoreBookmarks())
 
170
    {
 
171
        s_database->restoreBookmarks();
 
172
    }
 
173
 
156
174
    on_tabWidget_currentChanged(m_tabWidget->currentIndex());
157
175
}
158
176
 
172
190
    menu->addAction(m_outlineDock->toggleViewAction());
173
191
    menu->addAction(m_propertiesDock->toggleViewAction());
174
192
    menu->addAction(m_thumbnailsDock->toggleViewAction());
 
193
    menu->addAction(m_bookmarksDock->toggleViewAction());
175
194
 
176
195
    return menu;
177
196
}
191
210
            m_tabWidget->setTabToolTip(m_tabWidget->currentIndex(), currentTab()->fileInfo().absoluteFilePath());
192
211
 
193
212
            s_database->restorePerFileSettings(currentTab());
 
213
            scheduleSaveTabs();
194
214
 
195
215
            currentTab()->jumpToPage(page, false);
196
216
            currentTab()->setFocus();
244
264
        connect(newTab, SIGNAL(rightToLeftModeChanged(bool)), SLOT(on_currentTab_rightToLeftModeChanged(bool)));
245
265
        connect(newTab, SIGNAL(scaleModeChanged(ScaleMode)), SLOT(on_currentTab_scaleModeChanged(ScaleMode)));
246
266
        connect(newTab, SIGNAL(scaleFactorChanged(qreal)), SLOT(on_currentTab_scaleFactorChanged(qreal)));
 
267
        connect(newTab, SIGNAL(rotationChanged(Rotation)), SLOT(on_currentTab_rotationChanged(Rotation)));
247
268
 
248
269
        connect(newTab, SIGNAL(linkClicked(int)), SLOT(on_currentTab_linkClicked(int)));
249
270
        connect(newTab, SIGNAL(linkClicked(QString,int)), SLOT(on_currentTab_linkClicked(QString,int)));
260
281
        newTab->show();
261
282
 
262
283
        s_database->restorePerFileSettings(newTab);
 
284
        scheduleSaveTabs();
263
285
 
264
286
        newTab->jumpToPage(page, false);
265
287
        newTab->setFocus();
332
354
 
333
355
void MainWindow::on_tabWidget_currentChanged(int index)
334
356
{
335
 
    if(index != -1)
 
357
    const bool hasCurrent = index != -1;
 
358
 
 
359
    m_openContainingFolderAction->setEnabled(hasCurrent);
 
360
    m_refreshAction->setEnabled(hasCurrent);
 
361
    m_printAction->setEnabled(hasCurrent);
 
362
 
 
363
    m_previousPageAction->setEnabled(hasCurrent);
 
364
    m_nextPageAction->setEnabled(hasCurrent);
 
365
    m_firstPageAction->setEnabled(hasCurrent);
 
366
    m_lastPageAction->setEnabled(hasCurrent);
 
367
 
 
368
    m_setFirstPageAction->setEnabled(hasCurrent);
 
369
 
 
370
    m_jumpToPageAction->setEnabled(hasCurrent);
 
371
 
 
372
    m_searchAction->setEnabled(hasCurrent);
 
373
 
 
374
    m_copyToClipboardModeAction->setEnabled(hasCurrent);
 
375
    m_addAnnotationModeAction->setEnabled(hasCurrent);
 
376
 
 
377
    m_continuousModeAction->setEnabled(hasCurrent);
 
378
    m_twoPagesModeAction->setEnabled(hasCurrent);
 
379
    m_twoPagesWithCoverPageModeAction->setEnabled(hasCurrent);
 
380
    m_multiplePagesModeAction->setEnabled(hasCurrent);
 
381
    m_rightToLeftModeAction->setEnabled(hasCurrent);
 
382
 
 
383
    m_zoomInAction->setEnabled(hasCurrent);
 
384
    m_zoomOutAction->setEnabled(hasCurrent);
 
385
    m_originalSizeAction->setEnabled(hasCurrent);
 
386
    m_fitToPageWidthModeAction->setEnabled(hasCurrent);
 
387
    m_fitToPageSizeModeAction->setEnabled(hasCurrent);
 
388
 
 
389
    m_rotateLeftAction->setEnabled(hasCurrent);
 
390
    m_rotateRightAction->setEnabled(hasCurrent);
 
391
 
 
392
    m_invertColorsAction->setEnabled(hasCurrent);
 
393
 
 
394
    m_fontsAction->setEnabled(hasCurrent);
 
395
 
 
396
    m_presentationAction->setEnabled(hasCurrent);
 
397
 
 
398
    m_previousTabAction->setEnabled(hasCurrent);
 
399
    m_nextTabAction->setEnabled(hasCurrent);
 
400
    m_closeTabAction->setEnabled(hasCurrent);
 
401
    m_closeAllTabsAction->setEnabled(hasCurrent);
 
402
    m_closeAllTabsButCurrentTabAction->setEnabled(hasCurrent);
 
403
 
 
404
    m_previousBookmarkAction->setEnabled(hasCurrent);
 
405
    m_nextBookmarkAction->setEnabled(hasCurrent);
 
406
    m_addBookmarkAction->setEnabled(hasCurrent);
 
407
    m_removeBookmarkAction->setEnabled(hasCurrent);
 
408
 
 
409
    m_currentPageSpinBox->setEnabled(hasCurrent);
 
410
    m_scaleFactorComboBox->setEnabled(hasCurrent);
 
411
    m_searchLineEdit->setEnabled(hasCurrent);
 
412
    m_matchCaseCheckBox->setEnabled(hasCurrent);
 
413
    m_highlightAllCheckBox->setEnabled(hasCurrent);
 
414
 
 
415
    if(hasCurrent)
336
416
    {
337
 
        m_openContainingFolderAction->setEnabled(true);
338
 
        m_refreshAction->setEnabled(true);
339
417
        m_saveCopyAction->setEnabled(currentTab()->canSave());
340
418
        m_saveAsAction->setEnabled(currentTab()->canSave());
341
 
        m_printAction->setEnabled(true);
342
 
 
343
 
        m_previousPageAction->setEnabled(true);
344
 
        m_nextPageAction->setEnabled(true);
345
 
        m_firstPageAction->setEnabled(true);
346
 
        m_lastPageAction->setEnabled(true);
347
 
 
348
 
        m_jumpToPageAction->setEnabled(true);
349
 
 
350
 
        m_searchAction->setEnabled(true);
351
 
 
352
 
        m_copyToClipboardModeAction->setEnabled(true);
353
 
        m_addAnnotationModeAction->setEnabled(true);
354
 
 
355
 
        m_continuousModeAction->setEnabled(true);
356
 
        m_twoPagesModeAction->setEnabled(true);
357
 
        m_twoPagesWithCoverPageModeAction->setEnabled(true);
358
 
        m_multiplePagesModeAction->setEnabled(true);
359
 
        m_rightToLeftModeAction->setEnabled(true);
360
 
 
361
 
        m_zoomInAction->setEnabled(true);
362
 
        m_zoomOutAction->setEnabled(true);
363
 
        m_originalSizeAction->setEnabled(true);
364
 
        m_fitToPageWidthModeAction->setEnabled(true);
365
 
        m_fitToPageSizeModeAction->setEnabled(true);
366
 
 
367
 
        m_rotateLeftAction->setEnabled(true);
368
 
        m_rotateRightAction->setEnabled(true);
369
 
 
370
 
        m_invertColorsAction->setEnabled(true);
371
 
 
372
 
        m_fontsAction->setEnabled(true);
373
 
 
374
 
        m_presentationAction->setEnabled(true);
375
 
 
376
 
        m_previousTabAction->setEnabled(true);
377
 
        m_nextTabAction->setEnabled(true);
378
 
        m_closeTabAction->setEnabled(true);
379
 
        m_closeAllTabsAction->setEnabled(true);
380
 
        m_closeAllTabsButCurrentTabAction->setEnabled(true);
381
 
 
382
 
        m_previousBookmarkAction->setEnabled(true);
383
 
        m_nextBookmarkAction->setEnabled(true);
384
 
        m_addBookmarkAction->setEnabled(true);
385
 
        m_removeBookmarkAction->setEnabled(true);
386
 
 
387
 
        m_currentPageSpinBox->setEnabled(true);
388
 
        m_scaleFactorComboBox->setEnabled(true);
389
 
        m_searchLineEdit->setEnabled(true);
390
 
        m_matchCaseCheckBox->setEnabled(true);
391
 
        m_highlightAllCheckBox->setEnabled(true);
392
419
 
393
420
        if(m_searchDock->isVisible())
394
421
        {
398
425
 
399
426
        m_outlineView->setModel(currentTab()->outlineModel());
400
427
        m_propertiesView->setModel(currentTab()->propertiesModel());
 
428
        m_bookmarksView->setModel(bookmarkModelForCurrentTab());
401
429
        m_thumbnailsView->setScene(currentTab()->thumbnailsScene());
402
430
 
403
431
        on_currentTab_documentChanged();
421
449
    }
422
450
    else
423
451
    {
424
 
        m_openContainingFolderAction->setEnabled(false);
425
 
        m_refreshAction->setEnabled(false);
426
452
        m_saveCopyAction->setEnabled(false);
427
453
        m_saveAsAction->setEnabled(false);
428
 
        m_printAction->setEnabled(false);
429
 
 
430
 
        m_previousPageAction->setEnabled(false);
431
 
        m_nextPageAction->setEnabled(false);
432
 
        m_firstPageAction->setEnabled(false);
433
 
        m_lastPageAction->setEnabled(false);
434
 
 
435
 
        m_jumpToPageAction->setEnabled(false);
436
 
 
437
 
        m_jumpBackwardAction->setEnabled(false);
438
 
        m_jumpForwardAction->setEnabled(false);
439
 
 
440
 
        m_searchAction->setEnabled(false);
441
 
 
442
 
        m_copyToClipboardModeAction->setEnabled(false);
443
 
        m_addAnnotationModeAction->setEnabled(false);
444
 
 
445
 
        m_continuousModeAction->setEnabled(false);
446
 
        m_twoPagesModeAction->setEnabled(false);
447
 
        m_twoPagesWithCoverPageModeAction->setEnabled(false);
448
 
        m_multiplePagesModeAction->setEnabled(false);
449
 
        m_rightToLeftModeAction->setEnabled(false);
450
 
 
451
 
        m_zoomInAction->setEnabled(false);
452
 
        m_zoomOutAction->setEnabled(false);
453
 
        m_originalSizeAction->setEnabled(false);
454
 
        m_fitToPageWidthModeAction->setEnabled(false);
455
 
        m_fitToPageSizeModeAction->setEnabled(false);
456
 
 
457
 
        m_rotateLeftAction->setEnabled(false);
458
 
        m_rotateRightAction->setEnabled(false);
459
 
 
460
 
        m_invertColorsAction->setEnabled(false);
461
 
 
462
 
        m_fontsAction->setEnabled(false);
463
 
 
464
 
        m_presentationAction->setEnabled(false);
465
 
 
466
 
        m_previousTabAction->setEnabled(false);
467
 
        m_nextTabAction->setEnabled(false);
468
 
        m_closeTabAction->setEnabled(false);
469
 
        m_closeAllTabsAction->setEnabled(false);
470
 
        m_closeAllTabsButCurrentTabAction->setEnabled(false);
471
 
 
472
 
        m_previousBookmarkAction->setEnabled(false);
473
 
        m_nextBookmarkAction->setEnabled(false);
474
 
        m_addBookmarkAction->setEnabled(false);
475
 
        m_removeBookmarkAction->setEnabled(false);
476
 
 
477
 
        m_currentPageSpinBox->setEnabled(false);
478
 
        m_scaleFactorComboBox->setEnabled(false);
479
 
        m_searchLineEdit->setEnabled(false);
480
 
        m_matchCaseCheckBox->setEnabled(false);
481
 
        m_highlightAllCheckBox->setEnabled(false);
482
454
 
483
455
        if(m_searchDock->isVisible())
484
456
        {
490
462
 
491
463
        m_outlineView->setModel(0);
492
464
        m_propertiesView->setModel(0);
 
465
        m_bookmarksView->setModel(0);
493
466
        m_thumbnailsView->setScene(0);
494
467
 
495
468
        setWindowTitleForCurrentTab();
 
469
        setCurrentPageSuffixForCurrentTab();
496
470
 
497
471
        m_currentPageSpinBox->setValue(1);
498
 
        m_currentPageSpinBox->setSuffix(" / 1");
499
472
        m_scaleFactorComboBox->setCurrentIndex(4);
500
473
 
501
474
        m_copyToClipboardModeAction->setChecked(false);
582
555
 
583
556
void MainWindow::on_currentTab_documentChanged()
584
557
{
585
 
    // tab text and tool tip
586
 
 
587
558
    for(int index = 0; index < m_tabWidget->count(); ++index)
588
559
    {
589
560
        if(sender() == m_tabWidget->widget(index))
608
579
    if(senderIsCurrentTab())
609
580
    {
610
581
        setWindowTitleForCurrentTab();
611
 
 
612
 
        // outline view
613
 
 
614
 
        if(m_outlineView->header()->count() > 0)
615
 
        {
616
 
    #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
617
 
 
618
 
            m_outlineView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
619
 
 
620
 
    #else
621
 
 
622
 
            m_outlineView->header()->setResizeMode(0, QHeaderView::Stretch);
623
 
 
624
 
    #endif // QT_VERSION
625
 
        }
626
 
 
627
 
        if(m_outlineView->header()->count() > 1)
628
 
        {
629
 
    #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
630
 
 
631
 
            m_outlineView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
632
 
 
633
 
    #else
634
 
 
635
 
            m_outlineView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
636
 
 
637
 
    #endif // QT_VERSION
638
 
        }
639
 
 
640
 
        m_outlineView->header()->setMinimumSectionSize(0);
641
 
        m_outlineView->header()->setStretchLastSection(false);
642
 
        m_outlineView->header()->setVisible(false);
643
 
 
644
 
        // properties view
645
 
 
646
 
    #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
647
 
 
648
 
        m_propertiesView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
649
 
        m_propertiesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
650
 
 
651
 
    #else
652
 
 
653
 
        m_propertiesView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
654
 
        m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
655
 
 
656
 
    #endif // QT_VERSION
657
 
 
658
 
        m_propertiesView->horizontalHeader()->setVisible(false);
659
 
        m_propertiesView->verticalHeader()->setVisible(false);
660
582
    }
661
583
}
662
584
 
665
587
    if(senderIsCurrentTab())
666
588
    {
667
589
        m_currentPageSpinBox->setRange(1, numberOfPages);
668
 
        m_currentPageSpinBox->setSuffix(QString(" / %1").arg(numberOfPages));
669
590
 
670
591
        setWindowTitleForCurrentTab();
 
592
        setCurrentPageSuffixForCurrentTab();
671
593
    }
672
594
}
673
595
 
693
615
        m_thumbnailsView->ensureVisible(currentTab()->thumbnailItems().at(currentPage - 1));
694
616
 
695
617
        setWindowTitleForCurrentTab();
 
618
        setCurrentPageSuffixForCurrentTab();
 
619
 
 
620
        scheduleSaveTabs();
 
621
        scheduleSavePerFileSettings();
696
622
    }
697
623
}
698
624
 
710
636
    if(senderIsCurrentTab())
711
637
    {
712
638
        m_continuousModeAction->setChecked(continuousMode);
 
639
 
 
640
        scheduleSaveTabs();
 
641
        scheduleSavePerFileSettings();
713
642
    }
714
643
}
715
644
 
720
649
        m_twoPagesModeAction->setChecked(layoutMode == TwoPagesMode);
721
650
        m_twoPagesWithCoverPageModeAction->setChecked(layoutMode == TwoPagesWithCoverPageMode);
722
651
        m_multiplePagesModeAction->setChecked(layoutMode == MultiplePagesMode);
 
652
 
 
653
        scheduleSaveTabs();
 
654
        scheduleSavePerFileSettings();
723
655
    }
724
656
}
725
657
 
728
660
    if(senderIsCurrentTab())
729
661
    {
730
662
        m_rightToLeftModeAction->setChecked(rightToLeftMode);
 
663
 
 
664
        scheduleSaveTabs();
 
665
        scheduleSavePerFileSettings();
731
666
    }
732
667
}
733
668
 
763
698
            m_zoomOutAction->setEnabled(true);
764
699
            break;
765
700
        }
 
701
 
 
702
        scheduleSaveTabs();
 
703
        scheduleSavePerFileSettings();
766
704
    }
767
705
}
768
706
 
775
713
            m_scaleFactorComboBox->setCurrentIndex(m_scaleFactorComboBox->findData(scaleFactor));
776
714
            m_scaleFactorComboBox->lineEdit()->setText(QString("%1 %").arg(qRound(scaleFactor * 100.0)));
777
715
 
778
 
            m_zoomInAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::maximumScaleFactor()));
779
 
            m_zoomOutAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::minimumScaleFactor()));
 
716
            m_zoomInAction->setDisabled(qFuzzyCompare(scaleFactor, s_settings->documentView().maximumScaleFactor()));
 
717
            m_zoomOutAction->setDisabled(qFuzzyCompare(scaleFactor, s_settings->documentView().minimumScaleFactor()));
780
718
        }
 
719
 
 
720
        scheduleSaveTabs();
 
721
        scheduleSavePerFileSettings();
 
722
    }
 
723
}
 
724
 
 
725
void MainWindow::on_currentTab_rotationChanged(Rotation rotation)
 
726
{
 
727
    Q_UNUSED(rotation);
 
728
 
 
729
    if(senderIsCurrentTab())
 
730
    {
 
731
        scheduleSaveTabs();
 
732
        scheduleSavePerFileSettings();
781
733
    }
782
734
}
783
735
 
838
790
    {
839
791
        QMenu menu;
840
792
 
841
 
        menu.addAction(m_openContainingFolderAction);
842
 
        menu.addSeparator();
843
 
        menu.addActions(QList< QAction* >() << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction);
844
 
        menu.addSeparator();
845
 
        menu.addActions(QList< QAction* >() << m_jumpBackwardAction << m_jumpForwardAction);
 
793
        menu.addActions(QList< QAction* >() << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction);
 
794
        menu.addSeparator();
 
795
        menu.addActions(QList< QAction* >() << m_jumpToPageAction << m_jumpBackwardAction << m_jumpForwardAction);
 
796
        menu.addSeparator();
 
797
        menu.addAction(m_setFirstPageAction);
846
798
 
847
799
        if(m_searchDock->isVisible())
848
800
        {
899
851
        bool ok = false;
900
852
        qreal scaleFactor = m_scaleFactorComboBox->lineEdit()->text().toInt(&ok) / 100.0;
901
853
 
902
 
        scaleFactor = scaleFactor >= Defaults::DocumentView::minimumScaleFactor() ? scaleFactor : Defaults::DocumentView::minimumScaleFactor();
903
 
        scaleFactor = scaleFactor <= Defaults::DocumentView::maximumScaleFactor() ? scaleFactor : Defaults::DocumentView::maximumScaleFactor();
 
854
        scaleFactor = qMax(scaleFactor, s_settings->documentView().minimumScaleFactor());
 
855
        scaleFactor = qMin(scaleFactor, s_settings->documentView().maximumScaleFactor());
904
856
 
905
857
        if(ok)
906
858
        {
958
910
 
959
911
void MainWindow::on_openContainingFolder_triggered()
960
912
{
961
 
    QDesktopServices::openUrl(currentTab()->fileInfo().absolutePath());
 
913
    QDesktopServices::openUrl(QUrl::fromLocalFile(currentTab()->fileInfo().absolutePath()));
962
914
}
963
915
 
964
916
void MainWindow::on_refresh_triggered()
1068
1020
    currentTab()->lastPage();
1069
1021
}
1070
1022
 
 
1023
void MainWindow::on_setFirstPage_triggered()
 
1024
{
 
1025
    bool ok = false;
 
1026
    const int pageNumber = getMappedNumber(this, SLOT(currentPage_textFromValue(int,bool*)), SLOT(currentPage_valueFromText(QString,bool*)),
 
1027
                                           this, tr("Set first page"), tr("Select the first page of the body matter:"),
 
1028
                                           currentTab()->currentPage(), 1, currentTab()->numberOfPages(), &ok);
 
1029
 
 
1030
    if(ok)
 
1031
    {
 
1032
        currentTab()->setFirstPage(pageNumber);
 
1033
    }
 
1034
}
 
1035
 
1071
1036
void MainWindow::on_jumpToPage_triggered()
1072
1037
{
1073
1038
    bool ok = false;
1074
 
    const int page = QInputDialog::getInt(this, tr("Jump to page"), tr("Page:"), currentTab()->currentPage(), 1, currentTab()->numberOfPages(), 1, &ok);
 
1039
    const int pageNumber = getMappedNumber(this, SLOT(currentPage_textFromValue(int,bool*)), SLOT(currentPage_valueFromText(QString,bool*)),
 
1040
                                           this, tr("Jump to page"), tr("Page:"),
 
1041
                                           currentTab()->currentPage(), 1, currentTab()->numberOfPages(), &ok);
1075
1042
 
1076
1043
    if(ok)
1077
1044
    {
1078
 
        currentTab()->jumpToPage(page);
 
1045
        currentTab()->jumpToPage(pageNumber);
1079
1046
    }
1080
1047
}
1081
1048
 
1142
1109
{
1143
1110
    QScopedPointer< SettingsDialog > settingsDialog(new SettingsDialog(this));
1144
1111
 
1145
 
    settingsDialog->resize(s_settings->mainWindow().settingsDialogSize(settingsDialog->sizeHint()));
1146
 
 
1147
1112
    if(settingsDialog->exec() == QDialog::Accepted)
1148
1113
    {
1149
1114
        s_settings->sync();
1152
1117
        m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(s_settings->mainWindow().tabVisibility()));
1153
1118
        m_tabWidget->setSpreadTabs(s_settings->mainWindow().spreadTabs());
1154
1119
 
 
1120
        m_saveDatabaseTimer->setInterval(s_settings->mainWindow().saveDatabaseInterval());
 
1121
 
1155
1122
        for(int index = 0; index < m_tabWidget->count(); ++index)
1156
1123
        {
1157
1124
            if(!tab(index)->refresh())
1160
1127
            }
1161
1128
        }
1162
1129
    }
1163
 
 
1164
 
    s_settings->mainWindow().setSettingsDialogSize(settingsDialog->size());
1165
1130
}
1166
1131
 
1167
1132
void MainWindow::on_continuousMode_triggered(bool checked)
1234
1199
    QScopedPointer< QStandardItemModel > fontsModel(currentTab()->fontsModel());
1235
1200
    QScopedPointer< FontsDialog > dialog(new FontsDialog(fontsModel.data(), this));
1236
1201
 
1237
 
    dialog->resize(s_settings->mainWindow().fontsDialogSize(dialog->sizeHint()));
1238
1202
    dialog->exec();
1239
 
    s_settings->mainWindow().setFontsDialogSize(dialog->size());
1240
1203
}
1241
1204
 
1242
1205
void MainWindow::on_fullscreen_triggered(bool checked)
1255
1218
 
1256
1219
        restoreGeometry(m_fullscreenAction->data().toByteArray());
1257
1220
    }
 
1221
 
 
1222
    if(s_settings->mainWindow().toggleToolAndMenuBarsWithFullscreen())
 
1223
    {
 
1224
        m_toggleToolBarsAction->trigger();
 
1225
        m_toggleMenuBarAction->trigger();
 
1226
    }
1258
1227
}
1259
1228
 
1260
1229
void MainWindow::on_presentation_triggered()
1379
1348
 
1380
1349
void MainWindow::on_previousBookmark_triggered()
1381
1350
{
1382
 
    const BookmarkMenu* bookmark = bookmarkForCurrentTab();
 
1351
    const BookmarkModel* model = bookmarkModelForCurrentTab();
1383
1352
 
1384
 
    if(bookmark != 0)
 
1353
    if(model != 0)
1385
1354
    {
1386
1355
        QList< int > pages;
1387
1356
 
1388
 
        foreach(const Jump jump, bookmark->jumps())
 
1357
        for(int row = 0, rowCount = model->rowCount(); row < rowCount; ++row)
1389
1358
        {
1390
 
            pages.append(jump.first);
 
1359
            pages.append(model->index(row).data(BookmarkModel::PageRole).toInt());
1391
1360
        }
1392
1361
 
1393
1362
        if(!pages.isEmpty())
1410
1379
 
1411
1380
void MainWindow::on_nextBookmark_triggered()
1412
1381
{
1413
 
    const BookmarkMenu* bookmark = bookmarkForCurrentTab();
 
1382
    const BookmarkModel* model = bookmarkModelForCurrentTab();
1414
1383
 
1415
 
    if(bookmark != 0)
 
1384
    if(model != 0)
1416
1385
    {
1417
1386
        QList< int > pages;
1418
1387
 
1419
 
        foreach(const Jump jump, bookmark->jumps())
 
1388
        for(int row = 0, rowCount = model->rowCount(); row < rowCount; ++row)
1420
1389
        {
1421
 
            pages.append(jump.first);
 
1390
            pages.append(model->index(row).data(BookmarkModel::PageRole).toInt());
1422
1391
        }
1423
1392
 
1424
1393
        if(!pages.isEmpty())
1441
1410
 
1442
1411
void MainWindow::on_addBookmark_triggered()
1443
1412
{
1444
 
    bool ok = false;
1445
 
    const QString label = QInputDialog::getText(this, tr("Add bookmark"), tr("Label"), QLineEdit::Normal, tr("Jump to page %1").arg(currentTab()->currentPage()), &ok);
1446
 
 
1447
 
    if(!ok)
1448
 
    {
1449
 
        return;
1450
 
    }
1451
 
 
1452
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
1453
 
 
1454
 
    if(bookmark != 0)
1455
 
    {
1456
 
        bookmark->addJumpToPageAction(currentTab()->currentPage(), label);
1457
 
    }
1458
 
    else
1459
 
    {
1460
 
        bookmark = new BookmarkMenu(currentTab()->fileInfo(), this);
1461
 
 
1462
 
        bookmark->addJumpToPageAction(currentTab()->currentPage(), label);
1463
 
 
1464
 
        connect(bookmark, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
1465
 
        connect(bookmark, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
1466
 
        connect(bookmark, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
1467
 
 
1468
 
        m_bookmarksMenu->addMenu(bookmark);
 
1413
    const QString& currentPageLabel = s_settings->mainWindow().usePageLabel() || currentTab()->hasFrontMatter()
 
1414
            ? currentTab()->pageLabelFromNumber(currentTab()->currentPage())
 
1415
            : currentTab()->defaultPageLabelFromNumber(currentTab()->currentPage());
 
1416
 
 
1417
    BookmarkItem bookmark(currentTab()->currentPage(), tr("Jump to page %1").arg(currentPageLabel));
 
1418
 
 
1419
    BookmarkModel* model = bookmarkModelForCurrentTab(false);
 
1420
 
 
1421
    if(model != 0)
 
1422
    {
 
1423
        model->findBookmark(bookmark);
 
1424
    }
 
1425
 
 
1426
    QScopedPointer< BookmarkDialog > dialog(new BookmarkDialog(bookmark, this));
 
1427
 
 
1428
    if(dialog->exec() == QDialog::Accepted)
 
1429
    {
 
1430
        if(model == 0)
 
1431
        {
 
1432
            model = bookmarkModelForCurrentTab(true);
 
1433
 
 
1434
            m_bookmarksView->setModel(model);
 
1435
        }
 
1436
 
 
1437
        model->addBookmark(bookmark);
 
1438
 
 
1439
        m_bookmarksMenuIsDirty = true;
 
1440
        scheduleSaveBookmarks();
1469
1441
    }
1470
1442
}
1471
1443
 
1472
1444
void MainWindow::on_removeBookmark_triggered()
1473
1445
{
1474
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
 
1446
    BookmarkModel* model = bookmarkModelForCurrentTab();
1475
1447
 
1476
 
    if(bookmark != 0)
 
1448
    if(model != 0)
1477
1449
    {
1478
 
        bookmark->removeJumpToPageAction(currentTab()->currentPage());
 
1450
        model->removeBookmark(BookmarkItem(currentTab()->currentPage()));
 
1451
 
 
1452
        if(model->isEmpty())
 
1453
        {
 
1454
            m_bookmarksView->setModel(0);
 
1455
 
 
1456
            BookmarkModel::forgetPath(currentTab()->fileInfo().absoluteFilePath());
 
1457
        }
 
1458
 
 
1459
        m_bookmarksMenuIsDirty = true;
 
1460
        scheduleSaveBookmarks();
1479
1461
    }
1480
1462
}
1481
1463
 
1482
1464
void MainWindow::on_removeAllBookmarks_triggered()
1483
1465
{
1484
 
    foreach(const QAction* action, m_bookmarksMenu->actions())
1485
 
    {
1486
 
        BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1487
 
 
1488
 
        if(bookmark != 0)
 
1466
    m_bookmarksView->setModel(0);
 
1467
 
 
1468
    BookmarkModel::forgetAllPaths();
 
1469
 
 
1470
    m_bookmarksMenuIsDirty = true;
 
1471
    scheduleSaveBookmarks();
 
1472
}
 
1473
 
 
1474
void MainWindow::on_bookmarksMenu_aboutToShow()
 
1475
{
 
1476
    if(!m_bookmarksMenuIsDirty)
 
1477
    {
 
1478
        return;
 
1479
    }
 
1480
 
 
1481
    m_bookmarksMenuIsDirty = false;
 
1482
 
 
1483
 
 
1484
    m_bookmarksMenu->clear();
 
1485
 
 
1486
    m_bookmarksMenu->addActions(QList< QAction* >() << m_previousBookmarkAction << m_nextBookmarkAction);
 
1487
    m_bookmarksMenu->addSeparator();
 
1488
    m_bookmarksMenu->addActions(QList< QAction* >() << m_addBookmarkAction << m_removeBookmarkAction << m_removeAllBookmarksAction);
 
1489
    m_bookmarksMenu->addSeparator();
 
1490
 
 
1491
    foreach(const QString& absoluteFilePath, BookmarkModel::knownPaths())
 
1492
    {
 
1493
        const BookmarkModel* model = BookmarkModel::fromPath(absoluteFilePath);
 
1494
 
 
1495
        BookmarkMenu* menu = new BookmarkMenu(QFileInfo(absoluteFilePath), m_bookmarksMenu);
 
1496
 
 
1497
        for(int row = 0, rowCount = model->rowCount(); row < rowCount; ++row)
1489
1498
        {
1490
 
            delete bookmark;
 
1499
            const QModelIndex index = model->index(row);
 
1500
 
 
1501
            menu->addJumpToPageAction(index.data(BookmarkModel::PageRole).toInt(), index.data(BookmarkModel::LabelRole).toString());
1491
1502
        }
 
1503
 
 
1504
        connect(menu, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
 
1505
        connect(menu, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
 
1506
        connect(menu, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
 
1507
        connect(menu, SIGNAL(removeBookmarkTriggered(QString)), SLOT(on_bookmark_removeBookmarkTriggered(QString)));
 
1508
 
 
1509
        m_bookmarksMenu->addMenu(menu);
1492
1510
    }
1493
1511
}
1494
1512
 
1514
1532
    jumpToPageOrOpenInNewTab(absoluteFilePath, page);
1515
1533
}
1516
1534
 
 
1535
void MainWindow::on_bookmark_removeBookmarkTriggered(const QString& absoluteFilePath)
 
1536
{
 
1537
    BookmarkModel* model = BookmarkModel::fromPath(absoluteFilePath);
 
1538
 
 
1539
    if(model == m_bookmarksView->model())
 
1540
    {
 
1541
        m_bookmarksView->setModel(0);
 
1542
    }
 
1543
 
 
1544
    BookmarkModel::forgetPath(absoluteFilePath);
 
1545
 
 
1546
    m_bookmarksMenuIsDirty = true;
 
1547
    scheduleSaveBookmarks();
 
1548
}
 
1549
 
1517
1550
void MainWindow::on_contents_triggered()
1518
1551
{
1519
 
    QScopedPointer< HelpDialog > dialog(new HelpDialog(this));
1520
 
 
1521
 
    dialog->resize(s_settings->mainWindow().contentsDialogSize(dialog->sizeHint()));
1522
 
    dialog->exec();
1523
 
    s_settings->mainWindow().setContentsDialogSize(dialog->size());
 
1552
    if(m_helpDialog.isNull())
 
1553
    {
 
1554
        m_helpDialog = new HelpDialog();
 
1555
 
 
1556
        m_helpDialog->show();
 
1557
        m_helpDialog->setAttribute(Qt::WA_DeleteOnClose);
 
1558
 
 
1559
        connect(this, SIGNAL(destroyed()), m_helpDialog, SLOT(close()));
 
1560
    }
 
1561
 
 
1562
    m_helpDialog->raise();
 
1563
    m_helpDialog->activateWindow();
1524
1564
}
1525
1565
 
1526
1566
void MainWindow::on_about_triggered()
1527
1567
{
1528
1568
    QMessageBox::about(this, tr("About qpdfview"), (tr("<p><b>qpdfview %1</b></p><p>qpdfview is a tabbed document viewer using Qt.</p>"
1529
1569
                                                      "<p>This version includes:"
1530
 
                                                      "<ul>")
 
1570
                                                      "<ul>").arg(APPLICATION_VERSION)
1531
1571
#ifdef WITH_PDF
1532
 
                                                      + tr("<li>PDF support using Poppler</li>")
 
1572
                                                      + tr("<li>PDF support using Poppler %1</li>").arg(POPPLER_VERSION)
1533
1573
#endif // WITH_PDF
1534
1574
#ifdef WITH_PS
1535
 
                                                      + tr("<li>PS support using libspectre</li>")
 
1575
                                                      + tr("<li>PS support using libspectre %1</li>").arg(LIBSPECTRE_VERSION)
1536
1576
#endif // WITH_PS
1537
1577
#ifdef WITH_DJVU
1538
 
                                                      + tr("<li>DjVu support using DjVuLibre</li>")
 
1578
                                                      + tr("<li>DjVu support using DjVuLibre %1</li>").arg(DJVULIBRE_VERSION)
1539
1579
#endif // WITH_DJVU
1540
1580
#ifdef WITH_FITZ
1541
 
                                                      + tr("<li>PDF support using Fitz</li>")
 
1581
                                                      + tr("<li>PDF support using Fitz %1</li>").arg(FITZ_VERSION)
1542
1582
#endif // WITH_FITZ
1543
1583
#ifdef WITH_CUPS
1544
 
                                                      + tr("<li>Printing support using CUPS</li>")
 
1584
                                                      + tr("<li>Printing support using CUPS %1</li>").arg(CUPS_VERSION)
1545
1585
#endif // WITH_CUPS
1546
1586
                                                      + tr("</ul>"
1547
 
                                                           "<p>See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>&copy; 2012-2014 The qpdfview developers</p>")).arg(QApplication::applicationVersion()));
 
1587
                                                           "<p>See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>&copy; 2012-2014 The qpdfview developers</p>")));
 
1588
}
 
1589
 
 
1590
QString MainWindow::currentPage_textFromValue(int value, bool* ok) const
 
1591
{
 
1592
    if(currentTab() == 0 || !(s_settings->mainWindow().usePageLabel() || currentTab()->hasFrontMatter()))
 
1593
    {
 
1594
        *ok = false;
 
1595
        return QString();
 
1596
    }
 
1597
 
 
1598
    *ok = true;
 
1599
    return currentTab()->pageLabelFromNumber(value);
 
1600
}
 
1601
 
 
1602
int MainWindow::currentPage_valueFromText(QString text, bool* ok) const
 
1603
{
 
1604
    if(currentTab() == 0 || !(s_settings->mainWindow().usePageLabel() || currentTab()->hasFrontMatter()))
 
1605
    {
 
1606
        *ok = false;
 
1607
        return 0;
 
1608
    }
 
1609
 
 
1610
    const QString& prefix = m_currentPageSpinBox->prefix();
 
1611
    const QString& suffix = m_currentPageSpinBox->suffix();
 
1612
 
 
1613
    int from = 0;
 
1614
    int size = text.size();
 
1615
 
 
1616
    if(!prefix.isEmpty() && text.startsWith(prefix))
 
1617
    {
 
1618
        from += prefix.size();
 
1619
        size -= from;
 
1620
    }
 
1621
 
 
1622
    if(!suffix.isEmpty() && text.endsWith(suffix))
 
1623
    {
 
1624
        size -= suffix.size();
 
1625
    }
 
1626
 
 
1627
    text = text.mid(from, size).trimmed();
 
1628
 
 
1629
    *ok = true;
 
1630
    return currentTab()->pageNumberFromLabel(text);
1548
1631
}
1549
1632
 
1550
1633
void MainWindow::on_focusCurrentPage_activated()
1559
1642
    m_scaleFactorComboBox->lineEdit()->selectAll();
1560
1643
}
1561
1644
 
 
1645
void MainWindow::on_toggleToolBars_triggered(bool checked)
 
1646
{
 
1647
    if(checked)
 
1648
    {
 
1649
        m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(m_tabBarHadPolicy));
 
1650
 
 
1651
        m_fileToolBar->setVisible(m_fileToolBarWasVisible);
 
1652
        m_editToolBar->setVisible(m_editToolBarWasVisible);
 
1653
        m_viewToolBar->setVisible(m_viewToolBarWasVisible);
 
1654
    }
 
1655
    else
 
1656
    {
 
1657
        m_tabBarHadPolicy = static_cast< int >(m_tabWidget->tabBarPolicy());
 
1658
 
 
1659
        m_fileToolBarWasVisible = m_fileToolBar->isVisible();
 
1660
        m_editToolBarWasVisible = m_editToolBar->isVisible();
 
1661
        m_viewToolBarWasVisible = m_viewToolBar->isVisible();
 
1662
 
 
1663
        m_tabWidget->setTabBarPolicy(TabWidget::TabBarAlwaysOff);
 
1664
 
 
1665
        m_fileToolBar->setVisible(false);
 
1666
        m_editToolBar->setVisible(false);
 
1667
        m_viewToolBar->setVisible(false);
 
1668
    }
 
1669
}
 
1670
 
 
1671
void MainWindow::on_toggleMenuBar_triggered(bool checked)
 
1672
{
 
1673
    menuBar()->setVisible(checked);
 
1674
}
 
1675
 
1562
1676
void MainWindow::on_searchInitiated(const QString& text, bool allTabs)
1563
1677
{
1564
1678
    if(!text.isEmpty())
1582
1696
    currentTab()->setHighlightAll(checked);
1583
1697
}
1584
1698
 
 
1699
void MainWindow::on_outline_sectionCountChanged()
 
1700
{
 
1701
    if(m_outlineView->header()->count() > 0)
 
1702
    {
 
1703
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1704
 
 
1705
        m_outlineView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
 
1706
 
 
1707
#else
 
1708
 
 
1709
        m_outlineView->header()->setResizeMode(0, QHeaderView::Stretch);
 
1710
 
 
1711
#endif // QT_VERSION
 
1712
    }
 
1713
 
 
1714
    if(m_outlineView->header()->count() > 1)
 
1715
    {
 
1716
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1717
 
 
1718
        m_outlineView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
 
1719
 
 
1720
#else
 
1721
 
 
1722
        m_outlineView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
 
1723
 
 
1724
#endif // QT_VERSION
 
1725
    }
 
1726
 
 
1727
    m_outlineView->header()->setMinimumSectionSize(0);
 
1728
    m_outlineView->header()->setStretchLastSection(false);
 
1729
    m_outlineView->header()->setVisible(false);
 
1730
}
 
1731
 
1585
1732
void MainWindow::on_outline_clicked(const QModelIndex& index)
1586
1733
{
1587
1734
    bool ok = false;
1588
 
    const int page = m_outlineView->model()->data(index, Qt::UserRole + 1).toInt(&ok);
1589
 
    const qreal left = m_outlineView->model()->data(index, Qt::UserRole + 2).toReal();
1590
 
    const qreal top = m_outlineView->model()->data(index, Qt::UserRole + 3).toReal();
 
1735
    const int page = index.data(Qt::UserRole + 1).toInt(&ok);
 
1736
    const qreal left = index.data(Qt::UserRole + 2).toReal();
 
1737
    const qreal top = index.data(Qt::UserRole + 3).toReal();
1591
1738
 
1592
1739
    if(ok)
1593
1740
    {
1595
1742
    }
1596
1743
}
1597
1744
 
 
1745
void MainWindow::on_properties_sectionCountChanged()
 
1746
{
 
1747
    if(m_propertiesView->horizontalHeader()->count() > 0)
 
1748
    {
 
1749
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1750
 
 
1751
        m_propertiesView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
 
1752
 
 
1753
#else
 
1754
 
 
1755
        m_propertiesView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
 
1756
 
 
1757
#endif // QT_VERSION
 
1758
    }
 
1759
 
 
1760
    if(m_propertiesView->horizontalHeader()->count() > 1)
 
1761
    {
 
1762
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1763
 
 
1764
        m_propertiesView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Stretch);
 
1765
 
 
1766
#else
 
1767
 
 
1768
        m_propertiesView->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
 
1769
 
 
1770
#endif // QT_VERSION
 
1771
    }
 
1772
 
 
1773
    m_propertiesView->horizontalHeader()->setVisible(false);
 
1774
 
 
1775
 
 
1776
    if(m_propertiesView->verticalHeader()->count() > 0)
 
1777
    {
 
1778
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1779
 
 
1780
        m_propertiesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
1781
 
 
1782
#else
 
1783
 
 
1784
        m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
 
1785
 
 
1786
#endif // QT_VERSION
 
1787
    }
 
1788
 
 
1789
    m_propertiesView->verticalHeader()->setVisible(false);
 
1790
}
 
1791
 
1598
1792
void MainWindow::on_thumbnails_dockLocationChanged(Qt::DockWidgetArea area)
1599
1793
{
1600
1794
    for(int index = 0; index < m_tabWidget->count(); ++index)
1621
1815
    }
1622
1816
}
1623
1817
 
1624
 
void MainWindow::on_database_tabRestored(const QString& absoluteFilePath, bool continuousMode, LayoutMode layoutMode, ScaleMode scaleMode, qreal scaleFactor, Rotation rotation, int currentPage)
 
1818
void MainWindow::on_bookmarks_sectionCountChanged()
 
1819
{
 
1820
    if(m_bookmarksView->horizontalHeader()->count() > 0)
 
1821
    {
 
1822
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1823
 
 
1824
        m_bookmarksView->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
 
1825
 
 
1826
#else
 
1827
 
 
1828
        m_bookmarksView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
 
1829
 
 
1830
#endif // QT_VERSION
 
1831
    }
 
1832
 
 
1833
    if(m_bookmarksView->horizontalHeader()->count() > 1)
 
1834
    {
 
1835
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1836
 
 
1837
        m_bookmarksView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
 
1838
 
 
1839
#else
 
1840
 
 
1841
        m_bookmarksView->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
 
1842
 
 
1843
#endif // QT_VERSION
 
1844
    }
 
1845
 
 
1846
    m_bookmarksView->horizontalHeader()->setMinimumSectionSize(0);
 
1847
    m_bookmarksView->horizontalHeader()->setStretchLastSection(false);
 
1848
    m_bookmarksView->horizontalHeader()->setVisible(false);
 
1849
 
 
1850
    if(m_bookmarksView->verticalHeader()->count() > 0)
 
1851
    {
 
1852
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
 
1853
 
 
1854
        m_bookmarksView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
 
1855
 
 
1856
#else
 
1857
 
 
1858
        m_bookmarksView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
 
1859
 
 
1860
#endif // QT_VERSION
 
1861
    }
 
1862
 
 
1863
    m_bookmarksView->verticalHeader()->setVisible(false);
 
1864
}
 
1865
 
 
1866
void MainWindow::on_bookmarks_clicked(const QModelIndex& index)
 
1867
{
 
1868
    bool ok = false;
 
1869
    const int page = index.data(BookmarkModel::PageRole).toInt(&ok);
 
1870
 
 
1871
    if(ok)
 
1872
    {
 
1873
        currentTab()->jumpToPage(page);
 
1874
    }
 
1875
}
 
1876
 
 
1877
void MainWindow::on_bookmarks_contextMenuRequested(const QPoint& pos)
 
1878
{
 
1879
    QMenu menu;
 
1880
 
 
1881
    menu.addActions(QList< QAction* >() << m_previousBookmarkAction << m_nextBookmarkAction);
 
1882
    menu.addSeparator();
 
1883
    menu.addAction(m_addBookmarkAction);
 
1884
 
 
1885
    QAction* removeBookmarkAction = menu.addAction(tr("&Remove bookmark"));
 
1886
    QAction* editBookmarkAction = menu.addAction(tr("&Edit bookmark"));
 
1887
 
 
1888
    const QModelIndex index = m_bookmarksView->indexAt(pos);
 
1889
 
 
1890
    removeBookmarkAction->setVisible(index.isValid());
 
1891
    editBookmarkAction->setVisible(index.isValid());
 
1892
 
 
1893
    const QAction* action = menu.exec(m_bookmarksView->mapToGlobal(pos));
 
1894
 
 
1895
    if(action == removeBookmarkAction)
 
1896
    {
 
1897
        BookmarkModel* model = qobject_cast< BookmarkModel* >(m_bookmarksView->model());
 
1898
 
 
1899
        if(model != 0)
 
1900
        {
 
1901
            model->removeBookmark(BookmarkItem(index.data(BookmarkModel::PageRole).toInt()));
 
1902
 
 
1903
            if(model->isEmpty())
 
1904
            {
 
1905
                m_bookmarksView->setModel(0);
 
1906
 
 
1907
                BookmarkModel::forgetPath(currentTab()->fileInfo().absoluteFilePath());
 
1908
            }
 
1909
 
 
1910
            m_bookmarksMenuIsDirty = true;
 
1911
            scheduleSaveBookmarks();
 
1912
        }
 
1913
 
 
1914
    }
 
1915
    else if(action == editBookmarkAction)
 
1916
    {
 
1917
        BookmarkModel* model = qobject_cast< BookmarkModel* >(m_bookmarksView->model());
 
1918
 
 
1919
        if(model != 0)
 
1920
        {
 
1921
            BookmarkItem bookmark(index.data(BookmarkModel::PageRole).toInt());
 
1922
 
 
1923
            model->findBookmark(bookmark);
 
1924
 
 
1925
            QScopedPointer< BookmarkDialog > dialog(new BookmarkDialog(bookmark, this));
 
1926
 
 
1927
            if(dialog->exec() == QDialog::Accepted)
 
1928
            {
 
1929
                model->addBookmark(bookmark);
 
1930
 
 
1931
                m_bookmarksMenuIsDirty = true;
 
1932
                scheduleSaveBookmarks();
 
1933
            }
 
1934
        }
 
1935
    }
 
1936
}
 
1937
 
 
1938
void MainWindow::on_database_tabRestored(const QString& absoluteFilePath, bool continuousMode, LayoutMode layoutMode, bool rightToLeftMode, ScaleMode scaleMode, qreal scaleFactor, Rotation rotation, int currentPage)
1625
1939
{
1626
1940
    if(openInNewTab(absoluteFilePath))
1627
1941
    {
1628
1942
        currentTab()->setContinuousMode(continuousMode);
1629
1943
        currentTab()->setLayoutMode(layoutMode);
 
1944
        currentTab()->setRightToLeftMode(rightToLeftMode);
1630
1945
 
1631
1946
        currentTab()->setScaleMode(scaleMode);
1632
1947
        currentTab()->setScaleFactor(scaleFactor);
1637
1952
    }
1638
1953
}
1639
1954
 
1640
 
void MainWindow::on_database_bookmarkRestored(const QString& absoluteFilePath, const JumpList& jumps)
1641
 
{
1642
 
    BookmarkMenu* bookmark = new BookmarkMenu(QFileInfo(absoluteFilePath), this);
1643
 
 
1644
 
    foreach(const Jump jump, jumps)
1645
 
    {
1646
 
        bookmark->addJumpToPageAction(jump.first, jump.second);
1647
 
    }
1648
 
 
1649
 
    connect(bookmark, SIGNAL(openTriggered(QString)), SLOT(on_bookmark_openTriggered(QString)));
1650
 
    connect(bookmark, SIGNAL(openInNewTabTriggered(QString)), SLOT(on_bookmark_openInNewTabTriggered(QString)));
1651
 
    connect(bookmark, SIGNAL(jumpToPageTriggered(QString,int)), SLOT(on_bookmark_jumpToPageTriggered(QString,int)));
1652
 
 
1653
 
    m_bookmarksMenu->addMenu(bookmark);
1654
 
}
1655
 
 
1656
1955
void MainWindow::on_saveDatabase_timeout()
1657
1956
{
1658
1957
    if(s_settings->mainWindow().restoreTabs())
1659
1958
    {
1660
 
        saveTabs();
 
1959
        s_database->saveTabs(tabs());
1661
1960
    }
1662
1961
 
1663
1962
    if(s_settings->mainWindow().restoreBookmarks())
1664
1963
    {
1665
 
        saveBookmarks();
 
1964
        s_database->saveBookmarks();
1666
1965
    }
1667
1966
 
1668
1967
    if(s_settings->mainWindow().restorePerFileSettings())
1676
1975
 
1677
1976
void MainWindow::closeEvent(QCloseEvent* event)
1678
1977
{
1679
 
    saveTabs();
1680
 
    saveBookmarks();
 
1978
    if(s_settings->mainWindow().restoreTabs())
 
1979
    {
 
1980
        s_database->saveTabs(tabs());
 
1981
    }
 
1982
    else
 
1983
    {
 
1984
        s_database->clearTabs();
 
1985
    }
 
1986
 
 
1987
    if(s_settings->mainWindow().restoreBookmarks())
 
1988
    {
 
1989
        s_database->saveBookmarks();
 
1990
    }
 
1991
    else
 
1992
    {
 
1993
        s_database->clearBookmarks();
 
1994
    }
1681
1995
 
1682
1996
    s_settings->mainWindow().setRecentlyUsed(s_settings->mainWindow().trackRecentlyUsed() ? m_recentlyUsedMenu->filePaths() : QStringList());
1683
1997
 
1826
2140
bool MainWindow::saveModifications(DocumentView* tab)
1827
2141
{
1828
2142
    s_database->savePerFileSettings(tab);
 
2143
    scheduleSaveTabs();
1829
2144
 
1830
2145
    if(tab->wasModified())
1831
2146
    {
1882
2197
    setWindowTitle(tabText + QLatin1String("qpdfview") + instanceName);
1883
2198
}
1884
2199
 
1885
 
BookmarkMenu* MainWindow::bookmarkForCurrentTab() const
1886
 
{
1887
 
    foreach(QAction* action, m_bookmarksMenu->actions())
1888
 
    {
1889
 
        BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1890
 
 
1891
 
        if(bookmark != 0)
1892
 
        {
1893
 
            if(bookmark->absoluteFilePath() == currentTab()->fileInfo().absoluteFilePath())
1894
 
            {
1895
 
                return bookmark;
1896
 
            }
1897
 
        }
1898
 
    }
1899
 
 
1900
 
    return 0;
 
2200
void MainWindow::setCurrentPageSuffixForCurrentTab()
 
2201
{
 
2202
    QString suffix;
 
2203
 
 
2204
    if(m_tabWidget->currentIndex() != -1)
 
2205
    {
 
2206
        const int currentPage = currentTab()->currentPage();
 
2207
        const int numberOfPages = currentTab()->numberOfPages();
 
2208
 
 
2209
        const QString& defaultPageLabel = currentTab()->defaultPageLabelFromNumber(currentPage);
 
2210
        const QString& pageLabel = currentTab()->pageLabelFromNumber(currentPage);
 
2211
 
 
2212
        const QString& lastDefaultPageLabel = currentTab()->defaultPageLabelFromNumber(numberOfPages);
 
2213
 
 
2214
        if((s_settings->mainWindow().usePageLabel() || currentTab()->hasFrontMatter()) && defaultPageLabel != pageLabel)
 
2215
        {
 
2216
            suffix = QString(" (%1 / %2)").arg(defaultPageLabel).arg(lastDefaultPageLabel);
 
2217
        }
 
2218
        else
 
2219
        {
 
2220
            suffix = QString(" / %1").arg(lastDefaultPageLabel);
 
2221
        }
 
2222
    }
 
2223
    else
 
2224
    {
 
2225
        suffix = QLatin1String(" / 1");
 
2226
    }
 
2227
 
 
2228
    m_currentPageSpinBox->setSuffix(suffix);
 
2229
}
 
2230
 
 
2231
BookmarkModel* MainWindow::bookmarkModelForCurrentTab(bool create)
 
2232
{
 
2233
    return BookmarkModel::fromPath(currentTab()->fileInfo().absoluteFilePath(), create);
1901
2234
}
1902
2235
 
1903
2236
void MainWindow::prepareDatabase()
1907
2240
        s_database = Database::instance();
1908
2241
    }
1909
2242
 
1910
 
    connect(s_database, SIGNAL(tabRestored(QString,bool,LayoutMode,ScaleMode,qreal,Rotation,int)), SLOT(on_database_tabRestored(QString,bool,LayoutMode,ScaleMode,qreal,Rotation,int)));
1911
 
    connect(s_database, SIGNAL(bookmarkRestored(QString,JumpList)), SLOT(on_database_bookmarkRestored(QString,JumpList)));
1912
 
 
1913
 
 
1914
 
    s_database->restoreTabs();
1915
 
    s_database->restoreBookmarks();
1916
 
 
 
2243
    connect(s_database, SIGNAL(tabRestored(QString,bool,LayoutMode,bool,ScaleMode,qreal,Rotation,int)), SLOT(on_database_tabRestored(QString,bool,LayoutMode,bool,ScaleMode,qreal,Rotation,int)));
1917
2244
 
1918
2245
    m_saveDatabaseTimer = new QTimer(this);
 
2246
    m_saveDatabaseTimer->setSingleShot(true);
 
2247
    m_saveDatabaseTimer->setInterval(s_settings->mainWindow().saveDatabaseInterval());
1919
2248
 
1920
2249
    connect(m_saveDatabaseTimer, SIGNAL(timeout()), SLOT(on_saveDatabase_timeout()));
1921
 
 
1922
 
 
1923
 
    const int saveDatabaseInterval = s_settings->mainWindow().saveDatabaseInterval();
1924
 
 
1925
 
    if(saveDatabaseInterval > 0)
 
2250
}
 
2251
 
 
2252
void MainWindow::scheduleSaveDatabase()
 
2253
{
 
2254
    if(m_saveDatabaseTimer->interval() > 0 && !m_saveDatabaseTimer->isActive())
1926
2255
    {
1927
 
        m_saveDatabaseTimer->setInterval(saveDatabaseInterval);
1928
2256
        m_saveDatabaseTimer->start();
1929
2257
    }
1930
2258
}
1931
2259
 
1932
 
void MainWindow::saveTabs() const
1933
 
{
1934
 
    QList< const DocumentView* > tabs;
1935
 
 
1936
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
1937
 
    {
1938
 
        tabs.append(tab(index));
1939
 
    }
1940
 
 
1941
 
    s_database->saveTabs(tabs);
1942
 
}
1943
 
 
1944
 
void MainWindow::saveBookmarks() const
1945
 
{
1946
 
    QList< const BookmarkMenu* > bookmarks;
1947
 
 
1948
 
    foreach(const QAction* action, m_bookmarksMenu->actions())
1949
 
    {
1950
 
        const BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1951
 
 
1952
 
        if(bookmark != 0)
1953
 
        {
1954
 
            bookmarks.append(bookmark);
1955
 
        }
1956
 
    }
1957
 
 
1958
 
    s_database->saveBookmarks(bookmarks);
 
2260
void MainWindow::scheduleSaveTabs()
 
2261
{
 
2262
    if(s_settings->mainWindow().restoreTabs())
 
2263
    {
 
2264
        scheduleSaveDatabase();
 
2265
    }
 
2266
}
 
2267
 
 
2268
void MainWindow::scheduleSaveBookmarks()
 
2269
{
 
2270
    if(s_settings->mainWindow().restoreBookmarks())
 
2271
    {
 
2272
        scheduleSaveDatabase();
 
2273
    }
 
2274
}
 
2275
 
 
2276
void MainWindow::scheduleSavePerFileSettings()
 
2277
{
 
2278
    if(s_settings->mainWindow().restorePerFileSettings())
 
2279
    {
 
2280
        scheduleSaveDatabase();
 
2281
    }
1959
2282
}
1960
2283
 
1961
2284
void MainWindow::createWidgets()
1979
2302
 
1980
2303
    // current page
1981
2304
 
1982
 
    m_currentPageSpinBox = new SpinBox(this);
 
2305
    m_currentPageSpinBox = new MappingSpinBox(this, SLOT(currentPage_textFromValue(int,bool*)), SLOT(currentPage_valueFromText(QString,bool*)), this);
1983
2306
 
1984
2307
    m_currentPageSpinBox->setAlignment(Qt::AlignCenter);
1985
2308
    m_currentPageSpinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
2029
2352
    connect(m_highlightAllCheckBox, SIGNAL(clicked(bool)), SLOT(on_highlightAll_clicked(bool)));
2030
2353
}
2031
2354
 
2032
 
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QIcon& icon, const QKeySequence& shortcut, const char* member, bool checkable)
 
2355
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QIcon& icon, const QKeySequence& shortcut, const char* member, bool checkable, bool checked)
2033
2356
{
2034
2357
    QAction* action = new QAction(text, this);
2035
2358
 
2045
2368
    if(checkable)
2046
2369
    {
2047
2370
        action->setCheckable(true);
 
2371
        action->setChecked(checked);
2048
2372
 
2049
2373
        connect(action, SIGNAL(triggered(bool)), member);
2050
2374
    }
2055
2379
        connect(action, SIGNAL(triggered()), member);
2056
2380
    }
2057
2381
 
 
2382
    addAction(action);
 
2383
 
2058
2384
    return action;
2059
2385
}
2060
2386
 
2061
 
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QString& iconName, const QKeySequence& shortcut, const char* member, bool checkable)
 
2387
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QString& iconName, const QKeySequence& shortcut, const char* member, bool checkable, bool checked)
2062
2388
{
2063
 
    return createAction(text, objectName, QIcon::fromTheme(iconName, QIcon(QLatin1String(":icons/") + iconName + QLatin1String(".svg"))), shortcut, member, checkable);
 
2389
    return createAction(text, objectName, QIcon::fromTheme(iconName, QIcon(QLatin1String(":icons/") + iconName + QLatin1String(".svg"))), shortcut, member, checkable, checked);
2064
2390
}
2065
2391
 
2066
2392
void MainWindow::createActions()
2069
2395
 
2070
2396
    m_openAction = createAction(tr("&Open..."), QLatin1String("open"), QLatin1String("document-open"), QKeySequence::Open, SLOT(on_open_triggered()));
2071
2397
    m_openInNewTabAction = createAction(tr("Open in new &tab..."), QLatin1String("openInNewTab"), QLatin1String("tab-new"), QKeySequence::AddTab, SLOT(on_openInNewTab_triggered()));
2072
 
    m_openContainingFolderAction = createAction(tr("Open containing folder"), QString(), QIcon(), QKeySequence(), SLOT(on_openContainingFolder_triggered()));
 
2398
    m_openContainingFolderAction = createAction(tr("Open containing &folder"), QLatin1String("openContainingFolder"), QLatin1String("folder"), QKeySequence(), SLOT(on_openContainingFolder_triggered()));
2073
2399
    m_refreshAction = createAction(tr("&Refresh"), QLatin1String("refresh"), QLatin1String("view-refresh"), QKeySequence::Refresh, SLOT(on_refresh_triggered()));
2074
2400
    m_saveCopyAction = createAction(tr("&Save copy..."), QLatin1String("saveCopy"), QLatin1String("document-save"), QKeySequence::Save, SLOT(on_saveCopy_triggered()));
2075
2401
    m_saveAsAction = createAction(tr("Save &as..."), QLatin1String("saveAs"), QLatin1String("document-save-as"), QKeySequence::SaveAs, SLOT(on_saveAs_triggered()));
2083
2409
    m_firstPageAction = createAction(tr("&First page"), QLatin1String("firstPage"), QLatin1String("go-first"), QKeySequence(Qt::Key_Home), SLOT(on_firstPage_triggered()));
2084
2410
    m_lastPageAction = createAction(tr("&Last page"), QLatin1String("lastPage"), QLatin1String("go-last"), QKeySequence(Qt::Key_End), SLOT(on_lastPage_triggered()));
2085
2411
 
 
2412
    m_setFirstPageAction = createAction(tr("&Set first page..."), QString(), QIcon(), QKeySequence(), SLOT(on_setFirstPage_triggered()));
 
2413
 
2086
2414
    m_jumpToPageAction = createAction(tr("&Jump to page..."), QLatin1String("jumpToPage"), QLatin1String("go-jump"), QKeySequence(Qt::CTRL + Qt::Key_J), SLOT(on_jumpToPage_triggered()));
2087
2415
 
2088
2416
    m_jumpBackwardAction = createAction(tr("Jump &backward"), QLatin1String("jumpBackward"), QLatin1String("media-seek-backward"), QKeySequence(Qt::CTRL + Qt::Key_Return), SLOT(on_jumpBackward_triggered()));
2158
2486
QToolBar* MainWindow::createToolBar(const QString& text, const QString& objectName, const QStringList& actionNames, const QList< QAction* >& actions)
2159
2487
{
2160
2488
    QToolBar* toolBar = addToolBar(text);
2161
 
 
2162
2489
    toolBar->setObjectName(objectName);
2163
2490
 
2164
2491
    foreach(const QString& actionName, actionNames)
2181
2508
        }
2182
2509
    }
2183
2510
 
 
2511
    toolBar->toggleViewAction()->setObjectName(objectName + QLatin1String("ToggleView"));
 
2512
    ShortcutHandler::instance()->registerAction(toolBar->toggleViewAction());
 
2513
 
2184
2514
    return toolBar;
2185
2515
}
2186
2516
 
2187
2517
void MainWindow::createToolBars()
2188
2518
{
2189
2519
    m_fileToolBar = createToolBar(tr("&File"), QLatin1String("fileToolBar"), s_settings->mainWindow().fileToolBar(),
2190
 
                                  QList< QAction* >() << m_openAction << m_openInNewTabAction << m_refreshAction << m_saveCopyAction << m_saveAsAction << m_printAction);
 
2520
                                  QList< QAction* >() << m_openAction << m_openInNewTabAction << m_openContainingFolderAction << m_refreshAction << m_saveCopyAction << m_saveAsAction << m_printAction);
2191
2521
 
2192
2522
    m_editToolBar = createToolBar(tr("&Edit"), QLatin1String("editToolBar"), s_settings->mainWindow().editToolBar(),
2193
2523
                                  QList< QAction* >() << m_currentPageAction << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction << m_searchAction << m_jumpBackwardAction << m_jumpForwardAction << m_copyToClipboardModeAction << m_addAnnotationModeAction);
2223
2553
 
2224
2554
    m_outlineDock = createDock(tr("&Outline"), QLatin1String("outlineDock"), QKeySequence(Qt::Key_F6));
2225
2555
 
2226
 
    m_outlineView = new TreeView(Qt::UserRole, this);
 
2556
    m_outlineView = new TreeView(Qt::UserRole + 4, this);
2227
2557
    m_outlineView->setAlternatingRowColors(true);
2228
2558
    m_outlineView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2229
2559
    m_outlineView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
2230
2560
    m_outlineView->setSelectionBehavior(QAbstractItemView::SelectRows);
2231
2561
 
 
2562
    connect(m_outlineView->header(), SIGNAL(sectionCountChanged(int,int)), SLOT(on_outline_sectionCountChanged()));
2232
2563
    connect(m_outlineView, SIGNAL(clicked(QModelIndex)), SLOT(on_outline_clicked(QModelIndex)));
2233
2564
 
2234
2565
    m_outlineDock->setWidget(m_outlineView);
2242
2573
    m_propertiesView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2243
2574
    m_propertiesView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
2244
2575
 
 
2576
    connect(m_propertiesView->horizontalHeader(), SIGNAL(sectionCountChanged(int,int)), SLOT(on_properties_sectionCountChanged()));
 
2577
 
2245
2578
    m_propertiesDock->setWidget(m_propertiesView);
2246
2579
 
2247
2580
    // thumbnails
2256
2589
 
2257
2590
    m_thumbnailsDock->setWidget(m_thumbnailsView);
2258
2591
 
 
2592
    // bookmarks
 
2593
 
 
2594
    m_bookmarksDock = createDock(tr("&Bookmarks"), QLatin1String("bookmarksDock"), QKeySequence(Qt::Key_F9));
 
2595
 
 
2596
    m_bookmarksView = new QTableView(this);
 
2597
    m_bookmarksView->setShowGrid(false);
 
2598
    m_bookmarksView->setAlternatingRowColors(true);
 
2599
    m_bookmarksView->setEditTriggers(QAbstractItemView::NoEditTriggers);
 
2600
    m_bookmarksView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
 
2601
    m_bookmarksView->setSelectionMode(QAbstractItemView::SingleSelection);
 
2602
    m_bookmarksView->setSelectionBehavior(QAbstractItemView::SelectRows);
 
2603
    m_bookmarksView->setContextMenuPolicy(Qt::CustomContextMenu);
 
2604
 
 
2605
    connect(m_bookmarksView->horizontalHeader(), SIGNAL(sectionCountChanged(int,int)), SLOT(on_bookmarks_sectionCountChanged()));
 
2606
    connect(m_bookmarksView, SIGNAL(clicked(QModelIndex)), SLOT(on_bookmarks_clicked(QModelIndex)));
 
2607
    connect(m_bookmarksView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(on_bookmarks_contextMenuRequested(QPoint)));
 
2608
 
 
2609
    m_bookmarksDock->setWidget(m_bookmarksView);
 
2610
 
2259
2611
    // search
2260
2612
 
2261
2613
    m_searchDock = new QDockWidget(tr("&Search"), this);
2306
2658
    // file
2307
2659
 
2308
2660
    m_fileMenu = menuBar()->addMenu(tr("&File"));
2309
 
    m_fileMenu->addActions(QList< QAction* >() << m_openAction << m_openInNewTabAction);
 
2661
    m_fileMenu->addActions(QList< QAction* >() << m_openAction << m_openInNewTabAction << m_openContainingFolderAction);
2310
2662
 
2311
2663
    m_recentlyUsedMenu = new RecentlyUsedMenu(s_settings->mainWindow().recentlyUsed(), s_settings->mainWindow().recentlyUsedCount(), this);
2312
2664
 
2355
2707
    toolBarsMenu->addActions(QList< QAction* >() << m_fileToolBar->toggleViewAction() << m_editToolBar->toggleViewAction() << m_viewToolBar->toggleViewAction());
2356
2708
 
2357
2709
    QMenu* docksMenu = m_viewMenu->addMenu(tr("&Docks"));
2358
 
    docksMenu->addActions(QList< QAction* >() << m_outlineDock->toggleViewAction() << m_propertiesDock->toggleViewAction() << m_thumbnailsDock->toggleViewAction());
 
2710
    docksMenu->addActions(QList< QAction* >() << m_outlineDock->toggleViewAction() << m_propertiesDock->toggleViewAction() << m_thumbnailsDock->toggleViewAction() << m_bookmarksDock->toggleViewAction());
2359
2711
 
2360
2712
    m_viewMenu->addAction(m_fontsAction);
2361
2713
    m_viewMenu->addSeparator();
2382
2734
    // bookmarks
2383
2735
 
2384
2736
    m_bookmarksMenu = menuBar()->addMenu(tr("&Bookmarks"));
2385
 
    m_bookmarksMenu->addActions(QList< QAction* >() << m_previousBookmarkAction << m_nextBookmarkAction);
2386
 
    m_bookmarksMenu->addSeparator();
2387
 
    m_bookmarksMenu->addActions(QList< QAction* >() << m_addBookmarkAction << m_removeBookmarkAction << m_removeAllBookmarksAction);
2388
 
    m_bookmarksMenu->addSeparator();
 
2737
 
 
2738
    connect(m_bookmarksMenu, SIGNAL(aboutToShow()), this, SLOT(on_bookmarksMenu_aboutToShow()));
 
2739
 
 
2740
    m_bookmarksMenuIsDirty = true;
2389
2741
 
2390
2742
    // help
2391
2743
 
2399
2751
{
2400
2752
}
2401
2753
 
 
2754
void MainWindowAdaptor::raiseAndActivate()
 
2755
{
 
2756
    mainWindow()->raise();
 
2757
    mainWindow()->activateWindow();
 
2758
}
 
2759
 
2402
2760
bool MainWindowAdaptor::open(const QString& absoluteFilePath, int page, const QRectF& highlight, bool quiet)
2403
2761
{
2404
2762
    return mainWindow()->open(absoluteFilePath, page, highlight, quiet);
2419
2777
    mainWindow()->startSearch(text);
2420
2778
}
2421
2779
 
2422
 
void MainWindowAdaptor::raiseAndActivate()
2423
 
{
2424
 
    mainWindow()->raise();
2425
 
    mainWindow()->activateWindow();
 
2780
#define ONLY_IF_CURRENT_TAB if(mainWindow()->m_tabWidget->currentIndex() == -1) { return; }
 
2781
 
 
2782
void MainWindowAdaptor::previousPage()
 
2783
{
 
2784
    ONLY_IF_CURRENT_TAB
 
2785
 
 
2786
    mainWindow()->on_previousPage_triggered();
 
2787
}
 
2788
 
 
2789
void MainWindowAdaptor::nextPage()
 
2790
{
 
2791
    ONLY_IF_CURRENT_TAB
 
2792
 
 
2793
    mainWindow()->on_nextPage_triggered();
 
2794
}
 
2795
 
 
2796
void MainWindowAdaptor::firstPage()
 
2797
{
 
2798
    ONLY_IF_CURRENT_TAB
 
2799
 
 
2800
    mainWindow()->on_firstPage_triggered();
 
2801
}
 
2802
 
 
2803
void MainWindowAdaptor::lastPage()
 
2804
{
 
2805
    ONLY_IF_CURRENT_TAB
 
2806
 
 
2807
    mainWindow()->on_lastPage_triggered();
 
2808
}
 
2809
 
 
2810
void MainWindowAdaptor::previousBookmark()
 
2811
{
 
2812
    ONLY_IF_CURRENT_TAB
 
2813
 
 
2814
    mainWindow()->on_previousBookmark_triggered();
 
2815
}
 
2816
 
 
2817
void MainWindowAdaptor::nextBookmark()
 
2818
{
 
2819
    ONLY_IF_CURRENT_TAB
 
2820
 
 
2821
    mainWindow()->on_nextBookmark_triggered();
 
2822
}
 
2823
 
 
2824
bool MainWindowAdaptor::jumpToBookmark(const QString& label)
 
2825
{
 
2826
    if(mainWindow()->m_tabWidget->currentIndex() == -1) { return false; }
 
2827
 
 
2828
    const BookmarkModel* model = mainWindow()->bookmarkModelForCurrentTab();
 
2829
 
 
2830
    if(model != 0)
 
2831
    {
 
2832
        for(int row = 0, rowCount = model->rowCount(); row < rowCount; ++row)
 
2833
        {
 
2834
            const QModelIndex index = model->index(row);
 
2835
 
 
2836
            if(label == index.data(BookmarkModel::LabelRole).toString())
 
2837
            {
 
2838
                mainWindow()->currentTab()->jumpToPage(index.data(BookmarkModel::PageRole).toInt());
 
2839
 
 
2840
                return true;
 
2841
            }
 
2842
        }
 
2843
    }
 
2844
 
 
2845
    return false;
 
2846
}
 
2847
 
 
2848
void MainWindowAdaptor::continuousModeAction(bool checked)
 
2849
{
 
2850
    ONLY_IF_CURRENT_TAB
 
2851
 
 
2852
    mainWindow()->on_continuousMode_triggered(checked);
 
2853
}
 
2854
 
 
2855
void MainWindowAdaptor::twoPagesModeAction(bool checked)
 
2856
{
 
2857
    ONLY_IF_CURRENT_TAB
 
2858
 
 
2859
    mainWindow()->on_twoPagesMode_triggered(checked);
 
2860
}
 
2861
 
 
2862
void MainWindowAdaptor::twoPagesWithCoverPageModeAction(bool checked)
 
2863
{
 
2864
    ONLY_IF_CURRENT_TAB
 
2865
 
 
2866
    mainWindow()->on_twoPagesWithCoverPageMode_triggered(checked);
 
2867
}
 
2868
 
 
2869
void MainWindowAdaptor::multiplePagesModeAction(bool checked)
 
2870
{
 
2871
    ONLY_IF_CURRENT_TAB
 
2872
 
 
2873
    mainWindow()->on_multiplePagesMode_triggered(checked);
 
2874
}
 
2875
 
 
2876
void MainWindowAdaptor::fitToPageWidthModeAction(bool checked)
 
2877
{
 
2878
    ONLY_IF_CURRENT_TAB
 
2879
 
 
2880
    mainWindow()->on_fitToPageWidthMode_triggered(checked);
 
2881
}
 
2882
 
 
2883
void MainWindowAdaptor::fitToPageSizeModeAction(bool checked)
 
2884
{
 
2885
    ONLY_IF_CURRENT_TAB
 
2886
 
 
2887
    mainWindow()->on_fitToPageSizeMode_triggered(checked);
 
2888
}
 
2889
 
 
2890
void MainWindowAdaptor::invertColorsAction(bool checked)
 
2891
{
 
2892
    ONLY_IF_CURRENT_TAB
 
2893
 
 
2894
    mainWindow()->on_invertColors_triggered(checked);
 
2895
}
 
2896
 
 
2897
void MainWindowAdaptor::fullscreenAction(bool checked)
 
2898
{
 
2899
    if(mainWindow()->m_fullscreenAction->isChecked() != checked)
 
2900
    {
 
2901
        mainWindow()->m_fullscreenAction->trigger();
 
2902
    }
 
2903
}
 
2904
 
 
2905
void MainWindowAdaptor::presentationAction()
 
2906
{
 
2907
    ONLY_IF_CURRENT_TAB
 
2908
 
 
2909
    mainWindow()->on_presentation_triggered();
 
2910
}
 
2911
 
 
2912
void MainWindowAdaptor::closeTab()
 
2913
{
 
2914
    ONLY_IF_CURRENT_TAB
 
2915
 
 
2916
    mainWindow()->on_closeTab_triggered();
 
2917
}
 
2918
 
 
2919
void MainWindowAdaptor::closeAllTabs()
 
2920
{
 
2921
    mainWindow()->on_closeAllTabs_triggered();
 
2922
}
 
2923
 
 
2924
void MainWindowAdaptor::closeAllTabsButCurrentTab()
 
2925
{
 
2926
    mainWindow()->on_closeAllTabsButCurrentTab_triggered();
 
2927
}
 
2928
 
 
2929
bool MainWindowAdaptor::closeTab(const QString& absoluteFilePath)
 
2930
{
 
2931
    if(mainWindow()->m_tabWidget->currentIndex() == -1) { return false; }
 
2932
 
 
2933
    const QFileInfo fileInfo(absoluteFilePath);
 
2934
 
 
2935
    foreach(DocumentView* tab, mainWindow()->tabs())
 
2936
    {
 
2937
        if(tab->fileInfo() == fileInfo)
 
2938
        {
 
2939
            if(mainWindow()->saveModifications(tab))
 
2940
            {
 
2941
                mainWindow()->closeTab(tab);
 
2942
            }
 
2943
 
 
2944
            return true;
 
2945
        }
 
2946
    }
 
2947
 
 
2948
    return false;
2426
2949
}
2427
2950
 
2428
2951
MainWindow* MainWindowAdaptor::mainWindow() const