~ubuntu-branches/debian/sid/qpdfview/sid

« back to all changes in this revision

Viewing changes to .pc/settings.patch/sources/mainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2013-05-26 13:52:50 UTC
  • mfrom: (1.2.8)
  • Revision ID: package-import@ubuntu.com-20130526135250-s1rhw935iqd8fcfs
Tags: 0.4.3-1
* New upstream release.
* Added menu file and fetch xpm icon file in debian folder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
Copyright 2012-2013 Adam Reichold
4
 
Copyright 2012 Michał Trybus
5
 
Copyright 2012 Alexander Volkov
6
 
 
7
 
This file is part of qpdfview.
8
 
 
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.
13
 
 
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.
18
 
 
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/>.
21
 
 
22
 
*/
23
 
 
24
 
#include "mainwindow.h"
25
 
 
26
 
#include <QApplication>
27
 
#include <QCheckBox>
28
 
#include <QCryptographicHash>
29
 
#include <QDateTime>
30
 
#include <QDebug>
31
 
#include <QDialogButtonBox>
32
 
#include <QDockWidget>
33
 
#include <QDragEnterEvent>
34
 
#include <QFileDialog>
35
 
#include <QHeaderView>
36
 
#include <QInputDialog>
37
 
#include <QMenuBar>
38
 
#include <QMessageBox>
39
 
#include <QMimeData>
40
 
#include <QPrinter>
41
 
#include <QScrollBar>
42
 
#include <QShortcut>
43
 
#include <QStandardItemModel>
44
 
#include <QTableView>
45
 
#include <QTextBrowser>
46
 
#include <QTimer>
47
 
#include <QToolBar>
48
 
#include <QToolButton>
49
 
#include <QVBoxLayout>
50
 
#include <QWidgetAction>
51
 
 
52
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
53
 
 
54
 
#include <QStandardPaths>
55
 
 
56
 
#else
57
 
 
58
 
#include <QDesktopServices>
59
 
 
60
 
#endif // QT_VERSION
61
 
 
62
 
#ifdef WITH_SQL
63
 
 
64
 
#include <QSqlError>
65
 
#include <QSqlQuery>
66
 
 
67
 
#endif // WITH_SQL
68
 
 
69
 
#include "settings.h"
70
 
#include "pageitem.h"
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"
78
 
 
79
 
Settings* MainWindow::s_settings = 0;
80
 
 
81
 
MainWindow::MainWindow(const QString& instanceName, QWidget* parent) : QMainWindow(parent)
82
 
{
83
 
    setObjectName(instanceName);
84
 
 
85
 
    if(s_settings == 0)
86
 
    {
87
 
        s_settings = Settings::instance();
88
 
    }
89
 
 
90
 
    s_settings->sync();
91
 
 
92
 
    if(s_settings->mainWindow().hasIconTheme())
93
 
    {
94
 
        QIcon::setThemeName(s_settings->mainWindow().iconTheme());
95
 
    }
96
 
 
97
 
    if(s_settings->mainWindow().hasStyleSheet())
98
 
    {
99
 
        qApp->setStyleSheet(s_settings->mainWindow().styleSheet());
100
 
    }
101
 
 
102
 
    m_shortcutHandler = new ShortcutHandler(this);
103
 
 
104
 
    setAcceptDrops(true);
105
 
 
106
 
    createWidgets();
107
 
    createActions();
108
 
    createToolBars();
109
 
    createDocks();
110
 
    createMenus();
111
 
 
112
 
    restoreGeometry(s_settings->mainWindow().geometry());
113
 
    restoreState(s_settings->mainWindow().state());
114
 
 
115
 
    m_matchCaseCheckBox->setChecked(s_settings->documentView().matchCase());
116
 
 
117
 
    createDatabase();
118
 
 
119
 
    restoreTabs();
120
 
    restoreBookmarks();
121
 
 
122
 
    on_tabWidget_currentChanged(m_tabWidget->currentIndex());
123
 
}
124
 
 
125
 
QSize MainWindow::sizeHint() const
126
 
{
127
 
    return QSize(600, 800);
128
 
}
129
 
 
130
 
QMenu* MainWindow::createPopupMenu()
131
 
{
132
 
    QMenu* menu = new QMenu();
133
 
 
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());
141
 
 
142
 
    return menu;
143
 
}
144
 
 
145
 
bool MainWindow::open(const QString& filePath, int page, const QRectF& highlight)
146
 
{
147
 
    if(m_tabWidget->currentIndex() != -1)
148
 
    {
149
 
        savePerFileSettings(currentTab());
150
 
 
151
 
        if(currentTab()->open(filePath))
152
 
        {
153
 
            QFileInfo fileInfo(filePath);
154
 
 
155
 
            s_settings->mainWindow().setOpenPath(fileInfo.absolutePath());
156
 
            m_recentlyUsedMenu->addOpenAction(filePath);
157
 
 
158
 
            m_tabWidget->setTabText(m_tabWidget->currentIndex(), fileInfo.completeBaseName());
159
 
            m_tabWidget->setTabToolTip(m_tabWidget->currentIndex(), fileInfo.absoluteFilePath());
160
 
 
161
 
            restorePerFileSettings(currentTab());
162
 
 
163
 
            currentTab()->jumpToPage(page, false);
164
 
            currentTab()->setFocus();
165
 
 
166
 
            if(!highlight.isNull())
167
 
            {
168
 
                currentTab()->highlightOnCurrentPage(highlight);
169
 
            }
170
 
 
171
 
            return true;
172
 
        }
173
 
        else
174
 
        {
175
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not open '%1'.").arg(filePath));
176
 
        }
177
 
    }
178
 
 
179
 
    return false;
180
 
}
181
 
 
182
 
bool MainWindow::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
183
 
{
184
 
    DocumentView* newTab = new DocumentView(this);
185
 
 
186
 
    if(newTab->open(filePath))
187
 
    {
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());
195
 
 
196
 
        QFileInfo fileInfo(filePath);
197
 
 
198
 
        s_settings->mainWindow().setOpenPath(fileInfo.absolutePath());
199
 
        m_recentlyUsedMenu->addOpenAction(filePath);
200
 
 
201
 
        int index;
202
 
 
203
 
        if(s_settings->mainWindow().newTabNextToCurrentTab())
204
 
        {
205
 
            index = m_tabWidget->insertTab(m_tabWidget->currentIndex() + 1, newTab, fileInfo.completeBaseName());
206
 
        }
207
 
        else
208
 
        {
209
 
            index = m_tabWidget->addTab(newTab, fileInfo.completeBaseName());
210
 
        }
211
 
 
212
 
        m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
213
 
        m_tabWidget->setCurrentIndex(index);
214
 
 
215
 
        QAction* tabAction = new QAction(m_tabWidget->tabText(index), newTab);
216
 
        connect(tabAction, SIGNAL(triggered()), SLOT(on_tabAction_triggered()));
217
 
 
218
 
        m_tabsMenu->addAction(tabAction);
219
 
 
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)));
223
 
 
224
 
        connect(newTab, SIGNAL(canJumpChanged(bool,bool)), SLOT(on_currentTab_canJumpChanged(bool,bool)));
225
 
 
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)));
231
 
 
232
 
        connect(newTab, SIGNAL(linkClicked(QString,int)), SLOT(on_currentTab_linkClicked(QString,int)));
233
 
 
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)));
237
 
 
238
 
        connect(newTab, SIGNAL(searchFinished()), SLOT(on_currentTab_searchFinished()));
239
 
        connect(newTab, SIGNAL(searchProgressChanged(int)), SLOT(on_currentTab_searchProgressChanged(int)));
240
 
 
241
 
        connect(newTab, SIGNAL(customContextMenuRequested(QPoint)), SLOT(on_currentTab_customContextMenuRequested(QPoint)));
242
 
 
243
 
        newTab->show();
244
 
 
245
 
        restorePerFileSettings(newTab);
246
 
 
247
 
        newTab->jumpToPage(page, false);
248
 
        newTab->setFocus();
249
 
 
250
 
        if(!highlight.isNull())
251
 
        {
252
 
            newTab->highlightOnCurrentPage(highlight);
253
 
        }
254
 
 
255
 
        return true;
256
 
    }
257
 
    else
258
 
    {
259
 
        delete newTab;
260
 
 
261
 
        QMessageBox::warning(this, tr("Warning"), tr("Could not open '%1'.").arg(filePath));
262
 
    }
263
 
 
264
 
    return false;
265
 
}
266
 
 
267
 
bool MainWindow::jumpToPageOrOpenInNewTab(const QString& filePath, int page, bool refreshBeforeJump, const QRectF& highlight)
268
 
{
269
 
    QFileInfo fileInfo(filePath);
270
 
 
271
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
272
 
    {
273
 
        if(QFileInfo(tab(index)->filePath()).absoluteFilePath() == fileInfo.absoluteFilePath())
274
 
        {
275
 
            m_tabWidget->setCurrentIndex(index);
276
 
 
277
 
            if(refreshBeforeJump)
278
 
            {
279
 
                if(!currentTab()->refresh())
280
 
                {
281
 
                    return false;
282
 
                }
283
 
            }
284
 
 
285
 
            currentTab()->jumpToPage(page);
286
 
            currentTab()->setFocus();
287
 
 
288
 
            if(!highlight.isNull())
289
 
            {
290
 
                currentTab()->highlightOnCurrentPage(highlight);
291
 
            }
292
 
 
293
 
            return true;
294
 
        }
295
 
    }
296
 
 
297
 
    return openInNewTab(filePath, page, highlight);
298
 
}
299
 
 
300
 
void MainWindow::startSearch(const QString& text)
301
 
{
302
 
    if(m_tabWidget->currentIndex() != -1)
303
 
    {
304
 
        m_searchToolBar->setVisible(true);
305
 
 
306
 
        m_searchProgressLineEdit->setText(text);
307
 
 
308
 
        currentTab()->setFocus();
309
 
 
310
 
        QTimer::singleShot(0, this, SLOT(on_search_timeout()));
311
 
    }
312
 
}
313
 
 
314
 
void MainWindow::on_tabWidget_currentChanged(int index)
315
 
{
316
 
    if(index != -1)
317
 
    {
318
 
        m_refreshAction->setEnabled(true);
319
 
        m_saveCopyAction->setEnabled(currentTab()->canSave());
320
 
        m_saveAsAction->setEnabled(currentTab()->canSave());
321
 
        m_printAction->setEnabled(true);
322
 
 
323
 
        m_previousPageAction->setEnabled(true);
324
 
        m_nextPageAction->setEnabled(true);
325
 
        m_firstPageAction->setEnabled(true);
326
 
        m_lastPageAction->setEnabled(true);
327
 
 
328
 
        m_jumpToPageAction->setEnabled(true);
329
 
 
330
 
        m_searchAction->setEnabled(true);
331
 
 
332
 
        m_copyToClipboardModeAction->setEnabled(true);
333
 
        m_addAnnotationModeAction->setEnabled(true);
334
 
 
335
 
        m_continuousModeAction->setEnabled(true);
336
 
        m_twoPagesModeAction->setEnabled(true);
337
 
        m_twoPagesWithCoverPageModeAction->setEnabled(true);
338
 
        m_multiplePagesModeAction->setEnabled(true);
339
 
 
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);
345
 
 
346
 
        m_rotateLeftAction->setEnabled(true);
347
 
        m_rotateRightAction->setEnabled(true);
348
 
 
349
 
        m_invertColorsAction->setEnabled(true);
350
 
 
351
 
        m_fontsAction->setEnabled(true);
352
 
 
353
 
        m_presentationAction->setEnabled(true);
354
 
 
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);
360
 
 
361
 
        m_previousBookmarkAction->setEnabled(true);
362
 
        m_nextBookmarkAction->setEnabled(true);
363
 
        m_addBookmarkAction->setEnabled(true);
364
 
        m_removeBookmarkAction->setEnabled(true);
365
 
 
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);
371
 
 
372
 
        if(m_searchToolBar->isVisible())
373
 
        {
374
 
            m_searchTimer->stop();
375
 
            m_searchProgressLineEdit->setProgress(currentTab()->searchProgress());
376
 
        }
377
 
 
378
 
        m_outlineView->setModel(currentTab()->outlineModel());
379
 
 
380
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
381
 
 
382
 
        m_outlineView->header()->setSectionResizeMode(0, QHeaderView::Stretch);
383
 
        m_outlineView->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
384
 
 
385
 
#else
386
 
 
387
 
        m_outlineView->header()->setResizeMode(0, QHeaderView::Stretch);
388
 
        m_outlineView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
389
 
 
390
 
#endif // QT_VERSION
391
 
 
392
 
        m_propertiesView->setModel(currentTab()->propertiesModel());
393
 
 
394
 
        m_thumbnailsView->setScene(currentTab()->thumbnailsScene());
395
 
 
396
 
        on_currentTab_filePathChanged(currentTab()->filePath());
397
 
        on_currentTab_numberOfPagesChaned(currentTab()->numberOfPages());
398
 
        on_currentTab_currentPageChanged(currentTab()->currentPage());
399
 
 
400
 
        on_currentTab_canJumpChanged(currentTab()->canJumpBackward(), currentTab()->canJumpForward());
401
 
 
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());
407
 
 
408
 
        on_currentTab_invertColorsChanged(currentTab()->invertColors());
409
 
        on_currentTab_highlightAllChanged(currentTab()->highlightAll());
410
 
        on_currentTab_rubberBandModeChanged(currentTab()->rubberBandMode());
411
 
    }
412
 
    else
413
 
    {
414
 
        m_refreshAction->setEnabled(false);
415
 
        m_saveCopyAction->setEnabled(false);
416
 
        m_saveAsAction->setEnabled(false);
417
 
        m_printAction->setEnabled(false);
418
 
 
419
 
        m_previousPageAction->setEnabled(false);
420
 
        m_nextPageAction->setEnabled(false);
421
 
        m_firstPageAction->setEnabled(false);
422
 
        m_lastPageAction->setEnabled(false);
423
 
 
424
 
        m_jumpToPageAction->setEnabled(false);
425
 
 
426
 
        m_jumpBackwardAction->setEnabled(false);
427
 
        m_jumpForwardAction->setEnabled(false);
428
 
 
429
 
        m_searchAction->setEnabled(false);
430
 
 
431
 
        m_copyToClipboardModeAction->setEnabled(false);
432
 
        m_addAnnotationModeAction->setEnabled(false);
433
 
 
434
 
        m_continuousModeAction->setEnabled(false);
435
 
        m_twoPagesModeAction->setEnabled(false);
436
 
        m_twoPagesWithCoverPageModeAction->setEnabled(false);
437
 
        m_multiplePagesModeAction->setEnabled(false);
438
 
 
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);
444
 
 
445
 
        m_rotateLeftAction->setEnabled(false);
446
 
        m_rotateRightAction->setEnabled(false);
447
 
 
448
 
        m_invertColorsAction->setEnabled(false);
449
 
 
450
 
        m_fontsAction->setEnabled(false);
451
 
 
452
 
        m_presentationAction->setEnabled(false);
453
 
 
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);
459
 
 
460
 
        m_previousBookmarkAction->setEnabled(false);
461
 
        m_nextBookmarkAction->setEnabled(false);
462
 
        m_addBookmarkAction->setEnabled(false);
463
 
        m_removeBookmarkAction->setEnabled(false);
464
 
 
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);
470
 
 
471
 
        if(m_searchToolBar->isVisible())
472
 
        {
473
 
            m_searchTimer->stop();
474
 
            m_searchProgressLineEdit->setProgress(0);
475
 
        }
476
 
 
477
 
        m_searchToolBar->setVisible(false);
478
 
 
479
 
        m_outlineView->setModel(0);
480
 
        m_propertiesView->setModel(0);
481
 
        m_thumbnailsView->setScene(0);
482
 
 
483
 
        setWindowTitle(QLatin1String("qpdfview"));
484
 
 
485
 
        m_currentPageSpinBox->setValue(1);
486
 
        m_currentPageSpinBox->setSuffix(" / 1");
487
 
        m_scaleFactorComboBox->setCurrentIndex(4);
488
 
 
489
 
        m_copyToClipboardModeAction->setChecked(false);
490
 
        m_addAnnotationModeAction->setChecked(false);
491
 
 
492
 
        m_continuousModeAction->setChecked(false);
493
 
        m_twoPagesModeAction->setChecked(false);
494
 
        m_twoPagesWithCoverPageModeAction->setChecked(false);
495
 
        m_multiplePagesModeAction->setChecked(false);
496
 
 
497
 
        m_fitToPageSizeModeAction->setChecked(false);
498
 
        m_fitToPageWidthModeAction->setChecked(false);
499
 
 
500
 
        m_invertColorsAction->setChecked(false);
501
 
    }
502
 
}
503
 
 
504
 
void MainWindow::on_tabWidget_tabCloseRequested(int index)
505
 
{
506
 
    savePerFileSettings(tab(index));
507
 
 
508
 
    delete m_tabWidget->widget(index);
509
 
}
510
 
 
511
 
void MainWindow::on_currentTab_filePathChanged(const QString& filePath)
512
 
{
513
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
514
 
    {
515
 
        if(sender() == m_tabWidget->widget(index))
516
 
        {
517
 
            QFileInfo fileInfo(filePath);
518
 
 
519
 
            m_tabWidget->setTabText(index, fileInfo.completeBaseName());
520
 
            m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
521
 
 
522
 
            foreach(QAction* tabAction, m_tabsMenu->actions())
523
 
            {
524
 
                if(tabAction->parent() == m_tabWidget->widget(index))
525
 
                {
526
 
                    tabAction->setText(m_tabWidget->tabText(index));
527
 
 
528
 
                    break;
529
 
                }
530
 
            }
531
 
 
532
 
            break;
533
 
        }
534
 
    }
535
 
 
536
 
    if(senderIsCurrentTab())
537
 
    {
538
 
        setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
539
 
    }
540
 
}
541
 
 
542
 
void MainWindow::on_currentTab_numberOfPagesChaned(int numberOfPages)
543
 
{
544
 
    if(senderIsCurrentTab())
545
 
    {
546
 
        m_currentPageSpinBox->setRange(1, numberOfPages);
547
 
        m_currentPageSpinBox->setSuffix(QString(" / %1").arg(numberOfPages));
548
 
 
549
 
        setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
550
 
    }
551
 
}
552
 
 
553
 
void MainWindow::on_currentTab_currentPageChanged(int currentPage)
554
 
{
555
 
    if(senderIsCurrentTab())
556
 
    {
557
 
        m_currentPageSpinBox->setValue(currentPage);
558
 
 
559
 
        setWindowTitle(m_tabWidget->tabText(m_tabWidget->currentIndex()) + windowTitleSuffixForCurrentTab());
560
 
 
561
 
        m_thumbnailsView->ensureVisible(currentTab()->thumbnailItems().at(currentPage - 1));
562
 
    }
563
 
}
564
 
 
565
 
void MainWindow::on_currentTab_canJumpChanged(bool backward, bool forward)
566
 
{
567
 
    if(senderIsCurrentTab())
568
 
    {
569
 
        m_jumpBackwardAction->setEnabled(backward);
570
 
        m_jumpForwardAction->setEnabled(forward);
571
 
    }
572
 
}
573
 
 
574
 
void MainWindow::on_currentTab_continuousModeChanged(bool continuousMode)
575
 
{
576
 
    if(senderIsCurrentTab())
577
 
    {
578
 
        m_continuousModeAction->setChecked(continuousMode);
579
 
 
580
 
        s_settings->documentView().setContinuousMode(continuousMode);
581
 
    }
582
 
}
583
 
 
584
 
void MainWindow::on_currentTab_layoutModeChanged(LayoutMode layoutMode)
585
 
{
586
 
    if(senderIsCurrentTab())
587
 
    {
588
 
        m_twoPagesModeAction->setChecked(layoutMode == TwoPagesMode);
589
 
        m_twoPagesWithCoverPageModeAction->setChecked(layoutMode == TwoPagesWithCoverPageMode);
590
 
        m_multiplePagesModeAction->setChecked(layoutMode == MultiplePagesMode);
591
 
 
592
 
        s_settings->documentView().setLayoutMode(layoutMode);
593
 
    }
594
 
}
595
 
 
596
 
void MainWindow::on_currentTab_scaleModeChanged(ScaleMode scaleMode)
597
 
{
598
 
    if(senderIsCurrentTab())
599
 
    {
600
 
        switch(scaleMode)
601
 
        {
602
 
        default:
603
 
        case ScaleFactorMode:
604
 
            m_fitToPageWidthModeAction->setChecked(false);
605
 
            m_fitToPageSizeModeAction->setChecked(false);
606
 
 
607
 
            on_currentTab_scaleFactorChanged(currentTab()->scaleFactor());
608
 
            break;
609
 
        case FitToPageWidthMode:
610
 
            m_fitToPageWidthModeAction->setChecked(true);
611
 
            m_fitToPageSizeModeAction->setChecked(false);
612
 
 
613
 
            m_scaleFactorComboBox->setCurrentIndex(0);
614
 
 
615
 
            m_zoomInAction->setEnabled(true);
616
 
            m_zoomOutAction->setEnabled(true);
617
 
            break;
618
 
        case FitToPageSizeMode:
619
 
            m_fitToPageWidthModeAction->setChecked(false);
620
 
            m_fitToPageSizeModeAction->setChecked(true);
621
 
 
622
 
            m_scaleFactorComboBox->setCurrentIndex(1);
623
 
 
624
 
            m_zoomInAction->setEnabled(true);
625
 
            m_zoomOutAction->setEnabled(true);
626
 
            break;
627
 
        }
628
 
 
629
 
        s_settings->documentView().setScaleMode(scaleMode);
630
 
    }
631
 
}
632
 
 
633
 
void MainWindow::on_currentTab_scaleFactorChanged(qreal scaleFactor)
634
 
{
635
 
    if(senderIsCurrentTab())
636
 
    {
637
 
        if(currentTab()->scaleMode() == ScaleFactorMode)
638
 
        {
639
 
            m_scaleFactorComboBox->setCurrentIndex(m_scaleFactorComboBox->findData(scaleFactor));
640
 
            m_scaleFactorComboBox->lineEdit()->setText(QString("%1 %").arg(qRound(scaleFactor * 100.0)));
641
 
 
642
 
            m_zoomInAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::maximumScaleFactor()));
643
 
            m_zoomOutAction->setDisabled(qFuzzyCompare(scaleFactor, Defaults::DocumentView::minimumScaleFactor()));
644
 
        }
645
 
 
646
 
        s_settings->documentView().setScaleFactor(scaleFactor);
647
 
    }
648
 
}
649
 
 
650
 
void MainWindow::on_currentTab_rotationChanged(Rotation rotation)
651
 
{
652
 
    if(senderIsCurrentTab())
653
 
    {
654
 
        s_settings->documentView().setRotation(rotation);
655
 
    }
656
 
}
657
 
 
658
 
void MainWindow::on_currentTab_linkClicked(const QString& filePath, int page)
659
 
{
660
 
    jumpToPageOrOpenInNewTab(filePath, page, true);
661
 
}
662
 
 
663
 
void MainWindow::on_currentTab_invertColorsChanged(bool invertColors)
664
 
{
665
 
    if(senderIsCurrentTab())
666
 
    {
667
 
        m_invertColorsAction->setChecked(invertColors);
668
 
 
669
 
        s_settings->documentView().setInvertColors(invertColors);
670
 
    }
671
 
}
672
 
 
673
 
void MainWindow::on_currentTab_highlightAllChanged(bool highlightAll)
674
 
{
675
 
    if(senderIsCurrentTab())
676
 
    {
677
 
        m_highlightAllCheckBox->setChecked(highlightAll);
678
 
 
679
 
        s_settings->documentView().setHighlightAll(highlightAll);
680
 
    }
681
 
}
682
 
 
683
 
void MainWindow::on_currentTab_rubberBandModeChanged(RubberBandMode rubberBandMode)
684
 
{
685
 
    if(senderIsCurrentTab())
686
 
    {
687
 
        m_copyToClipboardModeAction->setChecked(rubberBandMode == CopyToClipboardMode);
688
 
        m_addAnnotationModeAction->setChecked(rubberBandMode == AddAnnotationMode);
689
 
    }
690
 
}
691
 
 
692
 
void MainWindow::on_currentTab_searchFinished()
693
 
{
694
 
    if(senderIsCurrentTab())
695
 
    {
696
 
        m_searchProgressLineEdit->setProgress(0);
697
 
    }
698
 
}
699
 
 
700
 
void MainWindow::on_currentTab_searchProgressChanged(int progress)
701
 
{
702
 
    if(senderIsCurrentTab())
703
 
    {
704
 
        m_searchProgressLineEdit->setProgress(progress);
705
 
    }
706
 
}
707
 
 
708
 
void MainWindow::on_currentTab_customContextMenuRequested(const QPoint& pos)
709
 
{
710
 
    if(senderIsCurrentTab())
711
 
    {
712
 
        QMenu menu;
713
 
 
714
 
        menu.addSeparator();
715
 
        menu.addActions(QList< QAction* >() << m_previousPageAction << m_nextPageAction << m_firstPageAction << m_lastPageAction << m_jumpToPageAction);
716
 
 
717
 
        menu.addSeparator();
718
 
        menu.addActions(QList< QAction* >() << m_jumpBackwardAction << m_jumpForwardAction);
719
 
 
720
 
        if(m_searchToolBar->isVisible())
721
 
        {
722
 
            menu.addSeparator();
723
 
            menu.addActions(QList< QAction* >() << m_findPreviousAction << m_findNextAction << m_cancelSearchAction);
724
 
        }
725
 
 
726
 
        menu.exec(currentTab()->mapToGlobal(pos));
727
 
    }
728
 
}
729
 
 
730
 
void MainWindow::on_currentPage_editingFinished()
731
 
{
732
 
    if(m_tabWidget->currentIndex() != -1)
733
 
    {
734
 
        currentTab()->jumpToPage(m_currentPageSpinBox->value());
735
 
    }
736
 
}
737
 
 
738
 
void MainWindow::on_currentPage_returnPressed()
739
 
{
740
 
    currentTab()->setFocus();
741
 
}
742
 
 
743
 
void MainWindow::on_scaleFactor_activated(int index)
744
 
{
745
 
    if(index == 0)
746
 
    {
747
 
        currentTab()->setScaleMode(FitToPageWidthMode);
748
 
    }
749
 
    else if(index == 1)
750
 
    {
751
 
        currentTab()->setScaleMode(FitToPageSizeMode);
752
 
    }
753
 
    else
754
 
    {
755
 
        bool ok = false;
756
 
        qreal scaleFactor = m_scaleFactorComboBox->itemData(index).toReal(&ok);
757
 
 
758
 
        if(ok)
759
 
        {
760
 
            currentTab()->setScaleFactor(scaleFactor);
761
 
            currentTab()->setScaleMode(ScaleFactorMode);
762
 
        }
763
 
    }
764
 
 
765
 
    currentTab()->setFocus();
766
 
}
767
 
 
768
 
void MainWindow::on_scaleFactor_editingFinished()
769
 
{
770
 
    if(m_tabWidget->currentIndex() != -1)
771
 
    {
772
 
        bool ok = false;
773
 
        qreal scaleFactor = m_scaleFactorComboBox->lineEdit()->text().toInt(&ok) / 100.0;
774
 
 
775
 
        scaleFactor = scaleFactor >= Defaults::DocumentView::minimumScaleFactor() ? scaleFactor : Defaults::DocumentView::minimumScaleFactor();
776
 
        scaleFactor = scaleFactor <= Defaults::DocumentView::maximumScaleFactor() ? scaleFactor : Defaults::DocumentView::maximumScaleFactor();
777
 
 
778
 
        if(ok)
779
 
        {
780
 
            currentTab()->setScaleFactor(scaleFactor);
781
 
            currentTab()->setScaleMode(ScaleFactorMode);
782
 
        }
783
 
 
784
 
        on_currentTab_scaleFactorChanged(currentTab()->scaleFactor());
785
 
        on_currentTab_scaleModeChanged(currentTab()->scaleMode());
786
 
    }
787
 
}
788
 
 
789
 
void MainWindow::on_scaleFactor_returnPressed()
790
 
{
791
 
    currentTab()->setFocus();
792
 
}
793
 
 
794
 
void MainWindow::on_open_triggered()
795
 
{
796
 
    if(m_tabWidget->currentIndex() != -1)
797
 
    {
798
 
        QString path = s_settings->mainWindow().openPath();
799
 
        QString filePath = QFileDialog::getOpenFileName(this, tr("Open"), path, DocumentView::openFilter().join(";;"));
800
 
 
801
 
        if(!filePath.isEmpty())
802
 
        {
803
 
            open(filePath);
804
 
        }
805
 
    }
806
 
    else
807
 
    {
808
 
        on_openInNewTab_triggered();
809
 
    }
810
 
}
811
 
 
812
 
void MainWindow::on_openInNewTab_triggered()
813
 
{
814
 
    QString path = s_settings->mainWindow().openPath();
815
 
    QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open in new tab"), path, DocumentView::openFilter().join(";;"));
816
 
 
817
 
    if(!filePaths.isEmpty())
818
 
    {
819
 
        disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
820
 
 
821
 
        foreach(QString filePath, filePaths)
822
 
        {
823
 
            openInNewTab(filePath);
824
 
        }
825
 
 
826
 
        connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
827
 
 
828
 
        on_tabWidget_currentChanged(m_tabWidget->currentIndex());
829
 
    }
830
 
}
831
 
 
832
 
void MainWindow::on_refresh_triggered()
833
 
{
834
 
    if(!currentTab()->refresh())
835
 
    {
836
 
        QMessageBox::warning(this, tr("Warning"), tr("Could not refresh '%1'.").arg(currentTab()->filePath()));
837
 
    }
838
 
}
839
 
 
840
 
void MainWindow::on_saveCopy_triggered()
841
 
{
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(";;"));
844
 
 
845
 
    if(!filePath.isEmpty())
846
 
    {
847
 
        if(currentTab()->save(filePath, false))
848
 
        {
849
 
            s_settings->mainWindow().setSavePath(QFileInfo(filePath).absolutePath());
850
 
        }
851
 
        else
852
 
        {
853
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not save copy at '%1'.").arg(filePath));
854
 
        }
855
 
    }
856
 
}
857
 
 
858
 
void MainWindow::on_saveAs_triggered()
859
 
{
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(";;"));
862
 
 
863
 
    if(!filePath.isEmpty())
864
 
    {
865
 
        if(currentTab()->save(filePath, true))
866
 
        {
867
 
            open(filePath, currentTab()->currentPage());
868
 
 
869
 
            s_settings->mainWindow().setSavePath(QFileInfo(filePath).absolutePath());
870
 
        }
871
 
        else
872
 
        {
873
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not save as '%1'.").arg(filePath));
874
 
        }
875
 
    }
876
 
}
877
 
 
878
 
void MainWindow::on_print_triggered()
879
 
{
880
 
    QPrinter* printer = PrintDialog::createPrinter();
881
 
    PrintDialog* printDialog = new PrintDialog(printer, this);
882
 
 
883
 
    printer->setDocName(QFileInfo(currentTab()->filePath()).completeBaseName());
884
 
    printer->setFullPage(true);
885
 
 
886
 
    printDialog->setMinMax(1, currentTab()->numberOfPages());
887
 
    printDialog->setOption(QPrintDialog::PrintToFile, false);
888
 
 
889
 
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
890
 
 
891
 
    printDialog->setOption(QPrintDialog::PrintCurrentPage, true);
892
 
 
893
 
#endif // QT_VERSION
894
 
 
895
 
    if(printDialog->exec() == QDialog::Accepted)
896
 
    {
897
 
 
898
 
#if QT_VERSION >= QT_VERSION_CHECK(4,7,0)
899
 
 
900
 
        if(printDialog->printRange() == QPrintDialog::CurrentPage)
901
 
        {
902
 
            printer->setFromTo(currentTab()->currentPage(), currentTab()->currentPage());
903
 
        }
904
 
 
905
 
#endif // QT_VERSION
906
 
 
907
 
        if(!currentTab()->print(printer, printDialog->printOptions()))
908
 
        {
909
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not print '%1'.").arg(currentTab()->filePath()));
910
 
        }
911
 
    }
912
 
 
913
 
    delete printer;
914
 
    delete printDialog;
915
 
}
916
 
 
917
 
void MainWindow::on_recentlyUsed_openTriggered(const QString& filePath)
918
 
{
919
 
    if(!jumpToPageOrOpenInNewTab(filePath, -1, true))
920
 
    {
921
 
        m_recentlyUsedMenu->removeOpenAction(filePath);
922
 
    }
923
 
}
924
 
 
925
 
void MainWindow::on_previousPage_triggered()
926
 
{
927
 
    currentTab()->previousPage();
928
 
}
929
 
 
930
 
void MainWindow::on_nextPage_triggered()
931
 
{
932
 
    currentTab()->nextPage();
933
 
}
934
 
 
935
 
void MainWindow::on_firstPage_triggered()
936
 
{
937
 
    currentTab()->firstPage();
938
 
}
939
 
 
940
 
void MainWindow::on_lastPage_triggered()
941
 
{
942
 
    currentTab()->lastPage();
943
 
}
944
 
 
945
 
void MainWindow::on_jumpToPage_triggered()
946
 
{
947
 
    bool ok = false;
948
 
    int page = QInputDialog::getInt(this, tr("Jump to page"), tr("Page:"), currentTab()->currentPage(), 1, currentTab()->numberOfPages(), 1, &ok);
949
 
 
950
 
    if(ok)
951
 
    {
952
 
        currentTab()->jumpToPage(page);
953
 
    }
954
 
}
955
 
 
956
 
void MainWindow::on_jumpBackward_triggered()
957
 
{
958
 
    currentTab()->jumpBackward();
959
 
}
960
 
 
961
 
void MainWindow::on_jumpForward_triggered()
962
 
{
963
 
    currentTab()->jumpForward();
964
 
}
965
 
 
966
 
void MainWindow::on_search_triggered()
967
 
{
968
 
    m_searchToolBar->setVisible(true);
969
 
 
970
 
    m_searchProgressLineEdit->selectAll();
971
 
    m_searchProgressLineEdit->setFocus();
972
 
}
973
 
 
974
 
void MainWindow::on_search_returnPressed(const Qt::KeyboardModifiers& modifiers)
975
 
{
976
 
    if(modifiers == Qt::ShiftModifier)
977
 
    {
978
 
        m_searchTimer->stop();
979
 
 
980
 
        if(!m_searchProgressLineEdit->text().isEmpty())
981
 
        {
982
 
            for(int index = 0; index < m_tabWidget->count(); ++index)
983
 
            {
984
 
                tab(index)->startSearch(m_searchProgressLineEdit->text(), m_matchCaseCheckBox->isChecked());
985
 
            }
986
 
        }
987
 
    }
988
 
    else
989
 
    {
990
 
        on_search_timeout();
991
 
    }
992
 
}
993
 
 
994
 
void MainWindow::on_search_timeout()
995
 
{
996
 
    m_searchTimer->stop();
997
 
 
998
 
    if(!m_searchProgressLineEdit->text().isEmpty())
999
 
    {
1000
 
        currentTab()->startSearch(m_searchProgressLineEdit->text(), m_matchCaseCheckBox->isChecked());
1001
 
    }
1002
 
}
1003
 
 
1004
 
void MainWindow::on_findPrevious_triggered()
1005
 
{
1006
 
    if(!m_searchProgressLineEdit->text().isEmpty())
1007
 
    {
1008
 
        currentTab()->findPrevious();
1009
 
    }
1010
 
}
1011
 
 
1012
 
void MainWindow::on_findNext_triggered()
1013
 
{
1014
 
    if(!m_searchProgressLineEdit->text().isEmpty())
1015
 
    {
1016
 
        currentTab()->findNext();
1017
 
    }
1018
 
}
1019
 
 
1020
 
void MainWindow::on_cancelSearch_triggered()
1021
 
{
1022
 
    m_searchTimer->stop();
1023
 
    m_searchProgressLineEdit->setProgress(0);
1024
 
 
1025
 
    m_searchToolBar->setVisible(false);
1026
 
 
1027
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
1028
 
    {
1029
 
        tab(index)->cancelSearch();
1030
 
    }
1031
 
}
1032
 
 
1033
 
void MainWindow::on_copyToClipboardMode_triggered(bool checked)
1034
 
{
1035
 
    currentTab()->setRubberBandMode(checked ? CopyToClipboardMode : ModifiersMode);
1036
 
}
1037
 
 
1038
 
void MainWindow::on_addAnnotationMode_triggered(bool checked)
1039
 
{
1040
 
    currentTab()->setRubberBandMode(checked ? AddAnnotationMode : ModifiersMode);
1041
 
}
1042
 
 
1043
 
void MainWindow::on_settings_triggered()
1044
 
{
1045
 
    SettingsDialog* settingsDialog = new SettingsDialog(m_shortcutHandler, this);
1046
 
 
1047
 
    if(settingsDialog->exec() == QDialog::Accepted)
1048
 
    {
1049
 
        s_settings->sync();
1050
 
 
1051
 
        m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(s_settings->mainWindow().tabPosition()));
1052
 
        m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(s_settings->mainWindow().tabVisibility()));
1053
 
 
1054
 
        for(int index = 0; index < m_tabWidget->count(); ++index)
1055
 
        {
1056
 
            if(!tab(index)->refresh())
1057
 
            {
1058
 
                QMessageBox::warning(this, tr("Warning"), tr("Could not refresh '%1'.").arg(currentTab()->filePath()));
1059
 
            }
1060
 
        }
1061
 
    }
1062
 
 
1063
 
    delete settingsDialog;
1064
 
}
1065
 
 
1066
 
void MainWindow::on_continuousMode_triggered(bool checked)
1067
 
{
1068
 
    currentTab()->setContinousMode(checked);
1069
 
}
1070
 
 
1071
 
void MainWindow::on_twoPagesMode_triggered(bool checked)
1072
 
{
1073
 
    currentTab()->setLayoutMode(checked ? TwoPagesMode : SinglePageMode);
1074
 
}
1075
 
 
1076
 
void MainWindow::on_twoPagesWithCoverPageMode_triggered(bool checked)
1077
 
{
1078
 
    currentTab()->setLayoutMode(checked ? TwoPagesWithCoverPageMode : SinglePageMode);
1079
 
}
1080
 
 
1081
 
void MainWindow::on_multiplePagesMode_triggered(bool checked)
1082
 
{
1083
 
    currentTab()->setLayoutMode(checked ? MultiplePagesMode : SinglePageMode);
1084
 
}
1085
 
 
1086
 
void MainWindow::on_zoomIn_triggered()
1087
 
{
1088
 
    currentTab()->zoomIn();
1089
 
}
1090
 
 
1091
 
void MainWindow::on_zoomOut_triggered()
1092
 
{
1093
 
    currentTab()->zoomOut();
1094
 
}
1095
 
 
1096
 
void MainWindow::on_originalSize_triggered()
1097
 
{
1098
 
    currentTab()->originalSize();
1099
 
}
1100
 
 
1101
 
void MainWindow::on_fitToPageWidthMode_triggered(bool checked)
1102
 
{
1103
 
    currentTab()->setScaleMode(checked ? FitToPageWidthMode : ScaleFactorMode);
1104
 
}
1105
 
 
1106
 
void MainWindow::on_fitToPageSizeMode_triggered(bool checked)
1107
 
{
1108
 
    currentTab()->setScaleMode(checked ? FitToPageSizeMode : ScaleFactorMode);
1109
 
}
1110
 
 
1111
 
void MainWindow::on_rotateLeft_triggered()
1112
 
{
1113
 
    currentTab()->rotateLeft();
1114
 
}
1115
 
 
1116
 
void MainWindow::on_rotateRight_triggered()
1117
 
{
1118
 
    currentTab()->rotateRight();
1119
 
}
1120
 
 
1121
 
void MainWindow::on_invertColors_triggered(bool checked)
1122
 
{
1123
 
    currentTab()->setInvertColors(checked);
1124
 
}
1125
 
 
1126
 
void MainWindow::on_fonts_triggered()
1127
 
{
1128
 
    QStandardItemModel* fontsModel = currentTab()->fontsModel();
1129
 
    QDialog* dialog = new QDialog(this);
1130
 
 
1131
 
    QTableView* tableView = new QTableView(dialog);
1132
 
    tableView->setModel(fontsModel);
1133
 
 
1134
 
    tableView->setAlternatingRowColors(true);
1135
 
    tableView->setSortingEnabled(true);
1136
 
    tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1137
 
    tableView->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
1138
 
 
1139
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
1140
 
 
1141
 
    tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1142
 
    tableView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1143
 
 
1144
 
#else
1145
 
 
1146
 
    tableView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1147
 
    tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1148
 
 
1149
 
#endif // QT_VERSION
1150
 
 
1151
 
    tableView->verticalHeader()->setVisible(false);
1152
 
 
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()));
1156
 
 
1157
 
    dialog->setLayout(new QVBoxLayout(dialog));
1158
 
    dialog->layout()->addWidget(tableView);
1159
 
    dialog->layout()->addWidget(dialogButtonBox);
1160
 
 
1161
 
    dialog->resize(s_settings->mainWindow().fontsDialogSize(dialog->sizeHint()));
1162
 
    dialog->exec();
1163
 
    s_settings->mainWindow().setFontsDialogSize(dialog->size());
1164
 
 
1165
 
    delete fontsModel;
1166
 
    delete dialog;
1167
 
}
1168
 
 
1169
 
void MainWindow::on_fullscreen_triggered(bool checked)
1170
 
{
1171
 
    if(checked)
1172
 
    {
1173
 
        m_fullscreenAction->setData(saveGeometry());
1174
 
 
1175
 
        showFullScreen();
1176
 
    }
1177
 
    else
1178
 
    {
1179
 
        restoreGeometry(m_fullscreenAction->data().toByteArray());
1180
 
 
1181
 
        showNormal();
1182
 
 
1183
 
        restoreGeometry(m_fullscreenAction->data().toByteArray());
1184
 
    }
1185
 
}
1186
 
 
1187
 
void MainWindow::on_presentation_triggered()
1188
 
{
1189
 
    currentTab()->startPresentation();
1190
 
}
1191
 
 
1192
 
void MainWindow::on_previousTab_triggered()
1193
 
{
1194
 
    if(m_tabWidget->currentIndex() > 0)
1195
 
    {
1196
 
        m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1);
1197
 
    }
1198
 
    else
1199
 
    {
1200
 
        m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
1201
 
    }
1202
 
}
1203
 
 
1204
 
void MainWindow::on_nextTab_triggered()
1205
 
{
1206
 
    if(m_tabWidget->currentIndex() < m_tabWidget->count() - 1)
1207
 
    {
1208
 
        m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1);
1209
 
    }
1210
 
    else
1211
 
    {
1212
 
        m_tabWidget->setCurrentIndex(0);
1213
 
    }
1214
 
}
1215
 
 
1216
 
void MainWindow::on_closeTab_triggered()
1217
 
{
1218
 
    savePerFileSettings(currentTab());
1219
 
 
1220
 
    delete m_tabWidget->currentWidget();
1221
 
}
1222
 
 
1223
 
void MainWindow::on_closeAllTabs_triggered()
1224
 
{
1225
 
    disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1226
 
 
1227
 
    while(m_tabWidget->count() > 0)
1228
 
    {
1229
 
        savePerFileSettings(tab(0));
1230
 
 
1231
 
        delete m_tabWidget->widget(0);
1232
 
    }
1233
 
 
1234
 
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1235
 
 
1236
 
    on_tabWidget_currentChanged(-1);
1237
 
}
1238
 
 
1239
 
void MainWindow::on_closeAllTabsButCurrentTab_triggered()
1240
 
{
1241
 
    DocumentView* newTab = currentTab();
1242
 
 
1243
 
    {
1244
 
        disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1245
 
 
1246
 
        m_tabWidget->removeTab(m_tabWidget->currentIndex());
1247
 
 
1248
 
        while(m_tabWidget->count() > 0)
1249
 
        {
1250
 
            savePerFileSettings(tab(0));
1251
 
 
1252
 
            delete m_tabWidget->widget(0);
1253
 
        }
1254
 
 
1255
 
        connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1256
 
    }
1257
 
 
1258
 
    QFileInfo fileInfo(newTab->filePath());
1259
 
 
1260
 
    int index = m_tabWidget->addTab(newTab, fileInfo.completeBaseName());
1261
 
    m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
1262
 
    m_tabWidget->setCurrentIndex(index);
1263
 
}
1264
 
 
1265
 
void MainWindow::on_tabAction_triggered()
1266
 
{
1267
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
1268
 
    {
1269
 
        if(sender()->parent() == m_tabWidget->widget(index))
1270
 
        {
1271
 
            m_tabWidget->setCurrentIndex(index);
1272
 
 
1273
 
            break;
1274
 
        }
1275
 
    }
1276
 
}
1277
 
 
1278
 
void MainWindow::on_tabShortcut_activated()
1279
 
{
1280
 
    for(int index = 0; index < 9; ++index)
1281
 
    {
1282
 
        if(sender() == m_tabShortcuts[index])
1283
 
        {
1284
 
            m_tabWidget->setCurrentIndex(index);
1285
 
 
1286
 
            break;
1287
 
        }
1288
 
    }
1289
 
}
1290
 
 
1291
 
void MainWindow::on_previousBookmark_triggered()
1292
 
{
1293
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
1294
 
 
1295
 
    if(bookmark != 0)
1296
 
    {
1297
 
        QList< int > pages = bookmark->pages();
1298
 
 
1299
 
        if(!pages.isEmpty())
1300
 
        {
1301
 
            qSort(pages);
1302
 
 
1303
 
            QList< int >::const_iterator lowerBound = --qLowerBound(pages, currentTab()->currentPage());
1304
 
 
1305
 
            if(lowerBound >= pages.constBegin())
1306
 
            {
1307
 
                currentTab()->jumpToPage(*lowerBound);
1308
 
            }
1309
 
            else
1310
 
            {
1311
 
                currentTab()->jumpToPage(pages.last());
1312
 
            }
1313
 
        }
1314
 
    }
1315
 
}
1316
 
 
1317
 
void MainWindow::on_nextBookmark_triggered()
1318
 
{
1319
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
1320
 
 
1321
 
    if(bookmark != 0)
1322
 
    {
1323
 
        QList< int > pages = bookmark->pages();
1324
 
 
1325
 
        if(!pages.isEmpty())
1326
 
        {
1327
 
            qSort(pages);
1328
 
 
1329
 
            QList< int >::const_iterator upperBound = qUpperBound(pages, currentTab()->currentPage());
1330
 
 
1331
 
            if(upperBound < pages.constEnd())
1332
 
            {
1333
 
                currentTab()->jumpToPage(*upperBound);
1334
 
            }
1335
 
            else
1336
 
            {
1337
 
                currentTab()->jumpToPage(pages.first());
1338
 
            }
1339
 
        }
1340
 
    }
1341
 
}
1342
 
 
1343
 
void MainWindow::on_addBookmark_triggered()
1344
 
{
1345
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
1346
 
 
1347
 
    if(bookmark != 0)
1348
 
    {
1349
 
        bookmark->addJumpToPageAction(currentTab()->currentPage());
1350
 
    }
1351
 
    else
1352
 
    {
1353
 
        bookmark = new BookmarkMenu(currentTab()->filePath(), this);
1354
 
 
1355
 
        bookmark->addJumpToPageAction(currentTab()->currentPage());
1356
 
 
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)));
1360
 
 
1361
 
        m_bookmarksMenu->addMenu(bookmark);
1362
 
    }
1363
 
}
1364
 
 
1365
 
void MainWindow::on_removeBookmark_triggered()
1366
 
{
1367
 
    BookmarkMenu* bookmark = bookmarkForCurrentTab();
1368
 
 
1369
 
    if(bookmark != 0)
1370
 
    {
1371
 
        bookmark->removeJumpToPageAction(currentTab()->currentPage());
1372
 
    }
1373
 
}
1374
 
 
1375
 
void MainWindow::on_removeAllBookmarks_triggered()
1376
 
{
1377
 
    foreach(QAction* action, m_bookmarksMenu->actions())
1378
 
    {
1379
 
        BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1380
 
 
1381
 
        if(bookmark != 0)
1382
 
        {
1383
 
            delete bookmark;
1384
 
        }
1385
 
    }
1386
 
}
1387
 
 
1388
 
void MainWindow::on_bookmark_openTriggered(const QString& filePath)
1389
 
{
1390
 
    if(m_tabWidget->currentIndex() != -1)
1391
 
    {
1392
 
        open(filePath);
1393
 
    }
1394
 
    else
1395
 
    {
1396
 
        openInNewTab(filePath);
1397
 
    }
1398
 
}
1399
 
 
1400
 
void MainWindow::on_bookmark_openInNewTabTriggered(const QString& filePath)
1401
 
{
1402
 
    openInNewTab(filePath);
1403
 
}
1404
 
 
1405
 
void MainWindow::on_bookmark_jumpToPageTriggered(const QString& filePath, int page)
1406
 
{
1407
 
    jumpToPageOrOpenInNewTab(filePath, page);
1408
 
}
1409
 
 
1410
 
void MainWindow::on_contents_triggered()
1411
 
{
1412
 
    QDialog* dialog = new QDialog(this);
1413
 
 
1414
 
    QTextBrowser* textBrowser = new QTextBrowser(dialog);
1415
 
    textBrowser->setSearchPaths(QStringList() << QDir(QApplication::applicationDirPath()).filePath("data") << DATA_INSTALL_PATH);
1416
 
    textBrowser->setSource(QUrl("help.html"));
1417
 
 
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()));
1421
 
 
1422
 
    dialog->setLayout(new QVBoxLayout(dialog));
1423
 
    dialog->layout()->addWidget(textBrowser);
1424
 
    dialog->layout()->addWidget(dialogButtonBox);
1425
 
 
1426
 
    dialog->resize(s_settings->mainWindow().contentsDialogSize(dialog->sizeHint()));
1427
 
    dialog->exec();
1428
 
    s_settings->mainWindow().setContentsDialogSize(dialog->size());
1429
 
 
1430
 
    delete dialog;
1431
 
}
1432
 
 
1433
 
void MainWindow::on_about_triggered()
1434
 
{
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:"
1437
 
                                                      "<ul>")
1438
 
#ifdef WITH_PDF
1439
 
                                                      + tr("<li>PDF support using Poppler</li>")
1440
 
#endif // WITH_PDF
1441
 
#ifdef WITH_PS
1442
 
                                                      + tr("<li>PS support using libspectre</li>")
1443
 
#endif // WITH_PS
1444
 
#ifdef WITH_DJVU
1445
 
                                                      + tr("<li>DjVu support using DjVuLibre</li>")
1446
 
#endif // WITH_DJVU
1447
 
#ifdef WITH_CUPS
1448
 
                                                      + tr("<li>Printing support using CUPS</li>")
1449
 
#endif // WITH_CUPS
1450
 
                                                      + tr("</ul>"
1451
 
                                                      "<p>See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>&copy; 2012-2013 The qpdfview developers</p>")).arg(QApplication::applicationVersion()));
1452
 
}
1453
 
 
1454
 
void MainWindow::on_highlightAll_clicked(bool checked)
1455
 
{
1456
 
    currentTab()->setHighlightAll(checked);
1457
 
}
1458
 
 
1459
 
void MainWindow::on_outline_clicked(const QModelIndex& index)
1460
 
{
1461
 
    bool ok = false;
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();
1465
 
 
1466
 
    if(ok)
1467
 
    {
1468
 
        currentTab()->jumpToPage(page, true, left, top);
1469
 
    }
1470
 
}
1471
 
 
1472
 
void MainWindow::on_thumbnails_verticalScrollBar_valueChanged(int value)
1473
 
{
1474
 
    Q_UNUSED(value);
1475
 
 
1476
 
    if(m_thumbnailsView->scene() != 0)
1477
 
    {
1478
 
        QRectF visibleRect = m_thumbnailsView->mapToScene(m_thumbnailsView->viewport()->rect()).boundingRect();
1479
 
 
1480
 
        foreach(ThumbnailItem* page, currentTab()->thumbnailItems())
1481
 
        {
1482
 
            if(!page->boundingRect().translated(page->pos()).intersects(visibleRect))
1483
 
            {
1484
 
                page->cancelRender();
1485
 
            }
1486
 
        }
1487
 
    }
1488
 
}
1489
 
 
1490
 
void MainWindow::closeEvent(QCloseEvent* event)
1491
 
{
1492
 
    saveTabs();
1493
 
    saveBookmarks();
1494
 
 
1495
 
    for(int index = 0; index < m_tabWidget->count(); ++index)
1496
 
    {
1497
 
        savePerFileSettings(tab(index));
1498
 
    }
1499
 
 
1500
 
    removeToolBar(m_searchToolBar);
1501
 
 
1502
 
    s_settings->mainWindow().setRecentlyUsed(s_settings->mainWindow().trackRecentlyUsed() ? m_recentlyUsedMenu->filePaths() : QStringList());
1503
 
 
1504
 
    s_settings->documentView().setMatchCase(m_matchCaseCheckBox->isChecked());
1505
 
 
1506
 
    s_settings->mainWindow().setGeometry(m_fullscreenAction->isChecked() ? m_fullscreenAction->data().toByteArray() : saveGeometry());
1507
 
    s_settings->mainWindow().setState(saveState());
1508
 
 
1509
 
    QMainWindow::closeEvent(event);
1510
 
}
1511
 
 
1512
 
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
1513
 
{
1514
 
    if(event->mimeData()->hasUrls())
1515
 
    {
1516
 
        event->acceptProposedAction();
1517
 
    }
1518
 
}
1519
 
 
1520
 
void MainWindow::dropEvent(QDropEvent* event)
1521
 
{
1522
 
    if(event->mimeData()->hasUrls())
1523
 
    {
1524
 
        event->acceptProposedAction();
1525
 
 
1526
 
        disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1527
 
 
1528
 
        foreach(QUrl url, event->mimeData()->urls())
1529
 
        {
1530
 
#if QT_VERSION >= QT_VERSION_CHECK(4,8,0)
1531
 
            if(url.isLocalFile())
1532
 
#else
1533
 
            if(url.scheme() == "file")
1534
 
#endif // QT_VERSION
1535
 
            {
1536
 
                openInNewTab(url.toLocalFile());
1537
 
            }
1538
 
        }
1539
 
 
1540
 
        connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(on_tabWidget_currentChanged(int)));
1541
 
 
1542
 
        on_tabWidget_currentChanged(m_tabWidget->currentIndex());
1543
 
    }
1544
 
}
1545
 
 
1546
 
DocumentView* MainWindow::currentTab() const
1547
 
{
1548
 
    return qobject_cast< DocumentView* >(m_tabWidget->currentWidget());
1549
 
}
1550
 
 
1551
 
DocumentView* MainWindow::tab(int index) const
1552
 
{
1553
 
    return qobject_cast< DocumentView* >(m_tabWidget->widget(index));
1554
 
}
1555
 
 
1556
 
bool MainWindow::senderIsCurrentTab() const
1557
 
{
1558
 
    return sender() == m_tabWidget->currentWidget() || qobject_cast< DocumentView* >(sender()) == 0;
1559
 
}
1560
 
 
1561
 
QString MainWindow::windowTitleSuffixForCurrentTab() const
1562
 
{
1563
 
    if(s_settings->mainWindow().currentPageInWindowTitle())
1564
 
    {
1565
 
        return QString(" (%1 / %2) - qpdfview").arg(currentTab()->currentPage()).arg(currentTab()->numberOfPages());
1566
 
    }
1567
 
    else
1568
 
    {
1569
 
        return QLatin1String(" - qpdfview");
1570
 
    }
1571
 
}
1572
 
 
1573
 
BookmarkMenu* MainWindow::bookmarkForCurrentTab() const
1574
 
{
1575
 
    foreach(QAction* action, m_bookmarksMenu->actions())
1576
 
    {
1577
 
        BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
1578
 
 
1579
 
        if(bookmark != 0)
1580
 
        {
1581
 
            if(QFileInfo(bookmark->filePath()).absoluteFilePath() == QFileInfo(currentTab()->filePath()).absoluteFilePath())
1582
 
            {
1583
 
                return bookmark;
1584
 
            }
1585
 
        }
1586
 
    }
1587
 
 
1588
 
    return 0;
1589
 
}
1590
 
 
1591
 
void MainWindow::createWidgets()
1592
 
{
1593
 
    m_tabWidget = new TabWidget(this);
1594
 
 
1595
 
    m_tabWidget->setDocumentMode(true);
1596
 
    m_tabWidget->setMovable(true);
1597
 
    m_tabWidget->setTabsClosable(true);
1598
 
    m_tabWidget->setElideMode(Qt::ElideRight);
1599
 
 
1600
 
    m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(s_settings->mainWindow().tabPosition()));
1601
 
    m_tabWidget->setTabBarPolicy(static_cast< TabWidget::TabBarPolicy >(s_settings->mainWindow().tabVisibility()));
1602
 
 
1603
 
    setCentralWidget(m_tabWidget);
1604
 
 
1605
 
    connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(on_tabWidget_currentChanged(int)));
1606
 
    connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(on_tabWidget_tabCloseRequested(int)));
1607
 
 
1608
 
    // current page
1609
 
 
1610
 
    m_currentPageSpinBox = new SpinBox(this);
1611
 
 
1612
 
    m_currentPageSpinBox->setAlignment(Qt::AlignCenter);
1613
 
    m_currentPageSpinBox->setButtonSymbols(QAbstractSpinBox::NoButtons);
1614
 
    m_currentPageSpinBox->setKeyboardTracking(false);
1615
 
 
1616
 
    connect(m_currentPageSpinBox, SIGNAL(editingFinished()), SLOT(on_currentPage_editingFinished()));
1617
 
    connect(m_currentPageSpinBox, SIGNAL(returnPressed()), SLOT(on_currentPage_returnPressed()));
1618
 
 
1619
 
    m_currentPageAction = new QWidgetAction(this);
1620
 
 
1621
 
    m_currentPageAction->setObjectName(QLatin1String("currentPage"));
1622
 
    m_currentPageAction->setDefaultWidget(m_currentPageSpinBox);
1623
 
 
1624
 
    // scale factor
1625
 
 
1626
 
    m_scaleFactorComboBox = new ComboBox(this);
1627
 
 
1628
 
    m_scaleFactorComboBox->setEditable(true);
1629
 
    m_scaleFactorComboBox->setInsertPolicy(QComboBox::NoInsert);
1630
 
 
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);
1640
 
 
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()));
1644
 
 
1645
 
    m_scaleFactorAction = new QWidgetAction(this);
1646
 
 
1647
 
    m_scaleFactorAction->setObjectName(QLatin1String("scaleFactor"));
1648
 
    m_scaleFactorAction->setDefaultWidget(m_scaleFactorComboBox);
1649
 
 
1650
 
    // search
1651
 
 
1652
 
    m_searchProgressLineEdit = new ProgressLineEdit(this);
1653
 
    m_searchTimer = new QTimer(this);
1654
 
 
1655
 
    m_searchTimer->setInterval(2000);
1656
 
    m_searchTimer->setSingleShot(true);
1657
 
 
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()));
1661
 
 
1662
 
    m_matchCaseCheckBox = new QCheckBox(tr("Match &case"), this);
1663
 
    m_highlightAllCheckBox = new QCheckBox(tr("Highlight &all"), this);
1664
 
 
1665
 
    connect(m_highlightAllCheckBox, SIGNAL(clicked(bool)), SLOT(on_highlightAll_clicked(bool)));
1666
 
}
1667
 
 
1668
 
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QIcon& icon, const QKeySequence& shortcut, const char* member, bool checkable)
1669
 
{
1670
 
    QAction* action = new QAction(text, this);
1671
 
 
1672
 
    action->setObjectName(objectName);
1673
 
    action->setIcon(icon);
1674
 
    action->setShortcut(shortcut);
1675
 
 
1676
 
    if(!objectName.isEmpty())
1677
 
    {
1678
 
        m_shortcutHandler->registerAction(action);
1679
 
    }
1680
 
 
1681
 
    if(checkable)
1682
 
    {
1683
 
        action->setCheckable(true);
1684
 
 
1685
 
        connect(action, SIGNAL(triggered(bool)), member);
1686
 
    }
1687
 
    else
1688
 
    {
1689
 
        action->setIconVisibleInMenu(true);
1690
 
 
1691
 
        connect(action, SIGNAL(triggered()), member);
1692
 
    }
1693
 
 
1694
 
    return action;
1695
 
}
1696
 
 
1697
 
QAction* MainWindow::createAction(const QString& text, const QString& objectName, const QString& iconName, const QKeySequence& shortcut, const char* member, bool checkable)
1698
 
{
1699
 
    return createAction(text, objectName, QIcon::fromTheme(iconName, QIcon(QLatin1String(":icons/") + iconName + QLatin1String(".svg"))), shortcut, member, checkable);
1700
 
}
1701
 
 
1702
 
void MainWindow::createActions()
1703
 
{
1704
 
    // file
1705
 
 
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()));
1713
 
 
1714
 
    // edit
1715
 
 
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()));
1720
 
 
1721
 
    m_jumpToPageAction = createAction(tr("&Jump to page..."), QLatin1String("jumpToPage"), QLatin1String("go-jump"), QKeySequence(Qt::CTRL + Qt::Key_J), SLOT(on_jumpToPage_triggered()));
1722
 
 
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()));
1725
 
 
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()));
1730
 
 
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);
1733
 
 
1734
 
    m_settingsAction = createAction(tr("Settings..."), QString(), QIcon(), QKeySequence(), SLOT(on_settings_triggered()));
1735
 
 
1736
 
    // view
1737
 
 
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);
1742
 
 
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()));
1746
 
 
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);
1749
 
 
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()));
1752
 
 
1753
 
    m_invertColorsAction = createAction(tr("Invert colors"), QLatin1String("invertColors"), QIcon(), QKeySequence(Qt::CTRL + Qt::Key_I), SLOT(on_invertColors_triggered(bool)), true);
1754
 
 
1755
 
    m_fontsAction = createAction(tr("Fonts..."), QString(), QIcon(), QKeySequence(), SLOT(on_fonts_triggered()));
1756
 
 
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()));
1759
 
 
1760
 
    // tabs
1761
 
 
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()));
1764
 
 
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()));
1768
 
 
1769
 
    // tab shortcuts
1770
 
 
1771
 
    for(int index = 0; index < 9; ++index)
1772
 
    {
1773
 
        m_tabShortcuts[index] = new QShortcut(QKeySequence(Qt::ALT + Qt::Key_1 + index), this, SLOT(on_tabShortcut_activated()));
1774
 
    }
1775
 
 
1776
 
    // bookmarks
1777
 
 
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()));
1780
 
 
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()));
1784
 
 
1785
 
    // help
1786
 
 
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()));
1789
 
}
1790
 
 
1791
 
QToolBar* MainWindow::createToolBar(const QString& text, const QString& objectName, const QStringList& actionNames, const QList< QAction* >& actions)
1792
 
{
1793
 
    QToolBar* toolBar = addToolBar(text);
1794
 
 
1795
 
    toolBar->setObjectName(objectName);
1796
 
 
1797
 
    foreach(QString actionName, actionNames)
1798
 
    {
1799
 
        if(actionName == QLatin1String("separator"))
1800
 
        {
1801
 
            toolBar->addSeparator();
1802
 
 
1803
 
            continue;
1804
 
        }
1805
 
 
1806
 
        foreach(QAction* action, actions)
1807
 
        {
1808
 
            if(actionName == action->objectName())
1809
 
            {
1810
 
                toolBar->addAction(action);
1811
 
 
1812
 
                break;
1813
 
            }
1814
 
        }
1815
 
    }
1816
 
 
1817
 
    return toolBar;
1818
 
}
1819
 
 
1820
 
void MainWindow::createToolBars()
1821
 
{
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);
1824
 
 
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);
1827
 
 
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);
1830
 
 
1831
 
    // search
1832
 
 
1833
 
    m_searchToolBar = new QToolBar(tr("&Search"), this);
1834
 
    m_searchToolBar->setObjectName(QLatin1String("searchToolBar"));
1835
 
 
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)));
1839
 
 
1840
 
    m_findPreviousAction->setEnabled(false);
1841
 
    m_findNextAction->setEnabled(false);
1842
 
    m_cancelSearchAction->setEnabled(false);
1843
 
 
1844
 
    m_searchToolBar->setVisible(false);
1845
 
    m_searchToolBar->setMovable(false);
1846
 
 
1847
 
    addToolBar(Qt::BottomToolBarArea, m_searchToolBar);
1848
 
 
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);
1855
 
}
1856
 
 
1857
 
QDockWidget* MainWindow::createDock(const QString& text, const QString& objectName, const QKeySequence& toggleViewShortcut)
1858
 
{
1859
 
    QDockWidget* dock = new QDockWidget(text, this);
1860
 
 
1861
 
    dock->setObjectName(objectName);
1862
 
    dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1863
 
    dock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1864
 
 
1865
 
    addDockWidget(Qt::LeftDockWidgetArea, dock);
1866
 
 
1867
 
    dock->toggleViewAction()->setObjectName(objectName + QLatin1String("ToggleView"));
1868
 
    dock->toggleViewAction()->setShortcut(toggleViewShortcut);
1869
 
 
1870
 
    m_shortcutHandler->registerAction(dock->toggleViewAction());
1871
 
 
1872
 
    dock->hide();
1873
 
 
1874
 
    return dock;
1875
 
}
1876
 
 
1877
 
void MainWindow::createDocks()
1878
 
{
1879
 
    // outline
1880
 
 
1881
 
    m_outlineDock = createDock(tr("&Outline"), QLatin1String("outlineDock"), QKeySequence(Qt::Key_F6));
1882
 
 
1883
 
    m_outlineView = new TreeView(this);
1884
 
    m_outlineView->setAlternatingRowColors(true);
1885
 
    m_outlineView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1886
 
 
1887
 
    m_outlineView->header()->setStretchLastSection(false);
1888
 
    m_outlineView->header()->setVisible(false);
1889
 
 
1890
 
    connect(m_outlineView, SIGNAL(clicked(QModelIndex)), SLOT(on_outline_clicked(QModelIndex)));
1891
 
 
1892
 
    m_outlineDock->setWidget(m_outlineView);
1893
 
 
1894
 
    // properties
1895
 
 
1896
 
    m_propertiesDock = createDock(tr("&Properties"), QLatin1String("propertiesDock"), QKeySequence(Qt::Key_F7));
1897
 
 
1898
 
    m_propertiesView = new QTableView(this);
1899
 
    m_propertiesView->setAlternatingRowColors(true);
1900
 
    m_propertiesView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1901
 
 
1902
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
1903
 
 
1904
 
    m_propertiesView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
1905
 
    m_propertiesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
1906
 
 
1907
 
#else
1908
 
 
1909
 
    m_propertiesView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
1910
 
    m_propertiesView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
1911
 
 
1912
 
#endif // QT_VERSION
1913
 
 
1914
 
    m_propertiesView->horizontalHeader()->setVisible(false);
1915
 
    m_propertiesView->verticalHeader()->setVisible(false);
1916
 
 
1917
 
    m_propertiesDock->setWidget(m_propertiesView);
1918
 
 
1919
 
    // thumbnails
1920
 
 
1921
 
    m_thumbnailsDock = createDock(tr("&Thumbnails"), QLatin1String("thumbnailsDock"), QKeySequence(Qt::Key_F8));
1922
 
 
1923
 
    m_thumbnailsView = new QGraphicsView(this);
1924
 
 
1925
 
    connect(m_thumbnailsView->verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(on_thumbnails_verticalScrollBar_valueChanged(int)));
1926
 
 
1927
 
    m_thumbnailsDock->setWidget(m_thumbnailsView);
1928
 
}
1929
 
 
1930
 
void MainWindow::createMenus()
1931
 
{
1932
 
    // file
1933
 
 
1934
 
    m_fileMenu = menuBar()->addMenu(tr("&File"));
1935
 
    m_fileMenu->addActions(QList< QAction* >() << m_openAction << m_openInNewTabAction);
1936
 
 
1937
 
    m_recentlyUsedMenu = new RecentlyUsedMenu(this);
1938
 
 
1939
 
    if(s_settings->mainWindow().trackRecentlyUsed())
1940
 
    {
1941
 
        foreach(QString filePath, s_settings->mainWindow().recentlyUsed())
1942
 
        {
1943
 
            m_recentlyUsedMenu->addOpenAction(filePath);
1944
 
        }
1945
 
 
1946
 
        connect(m_recentlyUsedMenu, SIGNAL(openTriggered(QString)), SLOT(on_recentlyUsed_openTriggered(QString)));
1947
 
 
1948
 
        m_fileMenu->addMenu(m_recentlyUsedMenu);
1949
 
 
1950
 
        QToolButton* openToolButton = qobject_cast< QToolButton* >(m_fileToolBar->widgetForAction(m_openAction));
1951
 
        if(openToolButton != 0)
1952
 
        {
1953
 
            openToolButton->setMenu(m_recentlyUsedMenu);
1954
 
        }
1955
 
 
1956
 
        QToolButton* openInNewTabToolButton = qobject_cast< QToolButton* >(m_fileToolBar->widgetForAction(m_openInNewTabAction));
1957
 
        if(openInNewTabToolButton != 0)
1958
 
        {
1959
 
            openInNewTabToolButton->setMenu(m_recentlyUsedMenu);
1960
 
        }
1961
 
    }
1962
 
 
1963
 
    m_fileMenu->addActions(QList< QAction* >() << m_refreshAction << m_saveCopyAction << m_saveAsAction << m_printAction);
1964
 
    m_fileMenu->addSeparator();
1965
 
    m_fileMenu->addAction(m_exitAction);
1966
 
 
1967
 
    // edit
1968
 
 
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);
1979
 
 
1980
 
    // view
1981
 
 
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();
1991
 
 
1992
 
    QMenu* toolBarsMenu = m_viewMenu->addMenu(tr("&Tool bars"));
1993
 
    toolBarsMenu->addActions(QList< QAction* >() << m_fileToolBar->toggleViewAction() << m_editToolBar->toggleViewAction() << m_viewToolBar->toggleViewAction());
1994
 
 
1995
 
    QMenu* docksMenu = m_viewMenu->addMenu(tr("&Docks"));
1996
 
    docksMenu->addActions(QList< QAction* >() << m_outlineDock->toggleViewAction() << m_propertiesDock->toggleViewAction() << m_thumbnailsDock->toggleViewAction());
1997
 
 
1998
 
    m_viewMenu->addAction(m_fontsAction);
1999
 
    m_viewMenu->addSeparator();
2000
 
    m_viewMenu->addActions(QList< QAction* >() << m_fullscreenAction << m_presentationAction);
2001
 
 
2002
 
    // tabs
2003
 
 
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();
2009
 
 
2010
 
    // bookmarks
2011
 
 
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();
2017
 
 
2018
 
    // help
2019
 
 
2020
 
    m_helpMenu = menuBar()->addMenu(tr("&Help"));
2021
 
    m_helpMenu->addActions(QList< QAction* >() << m_contentsAction << m_aboutAction);
2022
 
}
2023
 
 
2024
 
void MainWindow::createDatabase()
2025
 
{
2026
 
#ifdef WITH_SQL
2027
 
 
2028
 
#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
2029
 
 
2030
 
    QString path = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
2031
 
 
2032
 
#else
2033
 
 
2034
 
    QString path = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
2035
 
 
2036
 
#endif // QT_VERSION
2037
 
 
2038
 
    QDir().mkpath(path);
2039
 
 
2040
 
    m_database = QSqlDatabase::addDatabase("QSQLITE");
2041
 
    m_database.setDatabaseName(QDir(path).filePath("database"));
2042
 
    m_database.open();
2043
 
 
2044
 
    if(m_database.isOpen())
2045
 
    {
2046
 
        m_database.transaction();
2047
 
 
2048
 
        QStringList tables = m_database.tables();
2049
 
        QSqlQuery query(m_database);
2050
 
 
2051
 
        // tabs
2052
 
 
2053
 
        if(!tables.contains("tabs_v2"))
2054
 
        {
2055
 
            query.exec("CREATE TABLE tabs_v2 "
2056
 
                       "(filePath TEXT"
2057
 
                       ",instanceName TEXT"
2058
 
                       ",currentPage INTEGER"
2059
 
                       ",continuousMode INTEGER"
2060
 
                       ",layoutMode INTEGER"
2061
 
                       ",scaleMode INTEGER"
2062
 
                       ",scaleFactor REAL"
2063
 
                       ",rotation INTEGER)");
2064
 
 
2065
 
            if(!query.isActive())
2066
 
            {
2067
 
                qDebug() << query.lastError();
2068
 
            }
2069
 
        }
2070
 
 
2071
 
        // bookmarks
2072
 
 
2073
 
        if(!tables.contains("bookmarks_v1"))
2074
 
        {
2075
 
            query.exec("CREATE TABLE bookmarks_v1 "
2076
 
                       "(filePath TEXT"
2077
 
                       ",pages TEXT)");
2078
 
 
2079
 
            if(!query.isActive())
2080
 
            {
2081
 
                qDebug() << query.lastError();
2082
 
            }
2083
 
        }
2084
 
 
2085
 
        // per-file settings
2086
 
 
2087
 
        if(!tables.contains("perfilesettings_v1"))
2088
 
        {
2089
 
            query.exec("CREATE TABLE perfilesettings_v1 "
2090
 
                       "(lastUsed INTEGER"
2091
 
                       ",filePath TEXT PRIMARY KEY"
2092
 
                       ",currentPage INTEGER"
2093
 
                       ",continuousMode INTEGER"
2094
 
                       ",layoutMode INTEGER"
2095
 
                       ",scaleMode INTEGER"
2096
 
                       ",scaleFactor REAL"
2097
 
                       ",rotation INTEGER)");
2098
 
 
2099
 
            if(!query.isActive())
2100
 
            {
2101
 
                qDebug() << query.lastError();
2102
 
            }
2103
 
        }
2104
 
 
2105
 
        if(s_settings->mainWindow().restorePerFileSettings())
2106
 
        {
2107
 
            query.exec("DELETE FROM perfilesettings_v1 WHERE filePath IN (SELECT filePath FROM perfilesettings_v1 ORDER BY lastUsed DESC LIMIT -1 OFFSET 1000)");
2108
 
        }
2109
 
        else
2110
 
        {
2111
 
            query.exec("DELETE FROM perfilesettings_v1");
2112
 
        }
2113
 
 
2114
 
        if(!query.isActive())
2115
 
        {
2116
 
            qDebug() << query.lastError();
2117
 
        }
2118
 
 
2119
 
        m_database.commit();
2120
 
    }
2121
 
    else
2122
 
    {
2123
 
        qDebug() << m_database.lastError();
2124
 
    }
2125
 
 
2126
 
#endif // WITH_SQL
2127
 
}
2128
 
 
2129
 
void MainWindow::restoreTabs()
2130
 
{
2131
 
#ifdef WITH_SQL
2132
 
 
2133
 
    if(m_database.isOpen())
2134
 
    {
2135
 
        m_database.transaction();
2136
 
 
2137
 
        QSqlQuery query(m_database);
2138
 
        query.prepare("SELECT filePath,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM tabs_v2 WHERE instanceName==?");
2139
 
 
2140
 
        query.bindValue(0, objectName());
2141
 
 
2142
 
        query.exec();
2143
 
 
2144
 
        while(query.next())
2145
 
        {
2146
 
            if(!query.isActive())
2147
 
            {
2148
 
                qDebug() << query.lastError();
2149
 
                break;
2150
 
            }
2151
 
 
2152
 
            if(openInNewTab(query.value(0).toString()))
2153
 
            {
2154
 
                currentTab()->setContinousMode(static_cast< bool >(query.value(2).toUInt()));
2155
 
                currentTab()->setLayoutMode(static_cast< LayoutMode >(query.value(3).toUInt()));
2156
 
 
2157
 
                currentTab()->setScaleMode(static_cast< ScaleMode >(query.value(4).toUInt()));
2158
 
                currentTab()->setScaleFactor(query.value(5).toReal());
2159
 
 
2160
 
                currentTab()->setRotation(static_cast< Rotation >(query.value(6).toUInt()));
2161
 
 
2162
 
                currentTab()->jumpToPage(query.value(1).toInt());
2163
 
            }
2164
 
        }
2165
 
 
2166
 
        m_database.commit();
2167
 
    }
2168
 
 
2169
 
#endif // WITH_SQL
2170
 
}
2171
 
 
2172
 
void MainWindow::saveTabs()
2173
 
{
2174
 
#ifdef WITH_SQL
2175
 
 
2176
 
    if(m_database.isOpen())
2177
 
    {
2178
 
        m_database.transaction();
2179
 
 
2180
 
        QSqlQuery query(m_database);
2181
 
 
2182
 
        if(s_settings->mainWindow().restoreTabs())
2183
 
        {
2184
 
            query.prepare("DELETE FROM tabs_v2 WHERE instanceName==?");
2185
 
 
2186
 
            query.bindValue(0, objectName());
2187
 
 
2188
 
            query.exec();
2189
 
 
2190
 
            if(!query.isActive())
2191
 
            {
2192
 
                qDebug() << query.lastError();
2193
 
            }
2194
 
 
2195
 
            query.prepare("INSERT INTO tabs_v2 "
2196
 
                          "(filePath,instanceName,currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation)"
2197
 
                          " VALUES (?,?,?,?,?,?,?,?)");
2198
 
 
2199
 
            for(int index = 0; index < m_tabWidget->count(); ++index)
2200
 
            {
2201
 
                query.bindValue(0, QFileInfo(tab(index)->filePath()).absoluteFilePath());
2202
 
                query.bindValue(1, objectName());
2203
 
                query.bindValue(2, tab(index)->currentPage());
2204
 
 
2205
 
                query.bindValue(3, static_cast< uint >(tab(index)->continousMode()));
2206
 
                query.bindValue(4, static_cast< uint >(tab(index)->layoutMode()));
2207
 
 
2208
 
                query.bindValue(5, static_cast< uint >(tab(index)->scaleMode()));
2209
 
                query.bindValue(6, tab(index)->scaleFactor());
2210
 
 
2211
 
                query.bindValue(7, static_cast< uint >(tab(index)->rotation()));
2212
 
 
2213
 
                query.exec();
2214
 
 
2215
 
                if(!query.isActive())
2216
 
                {
2217
 
                    qDebug() << query.lastError();
2218
 
                    break;
2219
 
                }
2220
 
            }
2221
 
        }
2222
 
        else
2223
 
        {
2224
 
            query.exec("DELETE FROM tabs_v2");
2225
 
 
2226
 
            if(!query.isActive())
2227
 
            {
2228
 
                qDebug() << query.lastError();
2229
 
            }
2230
 
        }
2231
 
 
2232
 
        m_database.commit();
2233
 
    }
2234
 
 
2235
 
#endif // WITH_SQL
2236
 
}
2237
 
 
2238
 
void MainWindow::restoreBookmarks()
2239
 
{
2240
 
#ifdef WITH_SQL
2241
 
 
2242
 
    if(m_database.isOpen())
2243
 
    {
2244
 
        m_database.transaction();
2245
 
 
2246
 
        QSqlQuery query(m_database);
2247
 
        query.exec("SELECT filePath,pages FROM bookmarks_v1");
2248
 
 
2249
 
        while(query.next())
2250
 
        {
2251
 
            if(!query.isActive())
2252
 
            {
2253
 
                qDebug() << query.lastError();
2254
 
                break;
2255
 
            }
2256
 
 
2257
 
            BookmarkMenu* bookmark = new BookmarkMenu(query.value(0).toString(), this);
2258
 
 
2259
 
            QStringList pages = query.value(1).toString().split(",", QString::SkipEmptyParts);
2260
 
 
2261
 
            foreach(QString page, pages)
2262
 
            {
2263
 
                bookmark->addJumpToPageAction(page.toInt());
2264
 
            }
2265
 
 
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)));
2269
 
 
2270
 
            m_bookmarksMenu->addMenu(bookmark);
2271
 
        }
2272
 
 
2273
 
        m_database.commit();
2274
 
    }
2275
 
 
2276
 
#endif // WITH_SQL
2277
 
}
2278
 
 
2279
 
void MainWindow::saveBookmarks()
2280
 
{
2281
 
#ifdef WITH_SQL
2282
 
 
2283
 
    if(m_database.isOpen())
2284
 
    {
2285
 
        m_database.transaction();
2286
 
 
2287
 
        QSqlQuery query(m_database);
2288
 
        query.exec("DELETE FROM bookmarks_v1");
2289
 
 
2290
 
        if(!query.isActive())
2291
 
        {
2292
 
            qDebug() << query.lastError();
2293
 
        }
2294
 
 
2295
 
        if(s_settings->mainWindow().restoreBookmarks())
2296
 
        {
2297
 
            query.prepare("INSERT INTO bookmarks_v1 "
2298
 
                          "(filePath,pages)"
2299
 
                          " VALUES (?,?)");
2300
 
 
2301
 
            foreach(QAction* action, m_bookmarksMenu->actions())
2302
 
            {
2303
 
                BookmarkMenu* bookmark = qobject_cast< BookmarkMenu* >(action->menu());
2304
 
 
2305
 
                if(bookmark != 0)
2306
 
                {
2307
 
                    QStringList pages;
2308
 
 
2309
 
                    foreach(int page, bookmark->pages())
2310
 
                    {
2311
 
                        pages.append(QString::number(page));
2312
 
                    }
2313
 
 
2314
 
                    query.bindValue(0, QFileInfo(bookmark->filePath()).absoluteFilePath());
2315
 
                    query.bindValue(1, pages.join(","));
2316
 
 
2317
 
                    query.exec();
2318
 
 
2319
 
                    if(!query.isActive())
2320
 
                    {
2321
 
                        qDebug() << query.lastError();
2322
 
                        break;
2323
 
                    }
2324
 
                }
2325
 
            }
2326
 
        }
2327
 
 
2328
 
        m_database.commit();
2329
 
    }
2330
 
 
2331
 
#endif // WITH_SQL
2332
 
}
2333
 
 
2334
 
void MainWindow::restorePerFileSettings(DocumentView* tab)
2335
 
{
2336
 
#ifdef WITH_SQL
2337
 
 
2338
 
    if(s_settings->mainWindow().restorePerFileSettings() && m_database.isOpen() && tab != 0)
2339
 
    {
2340
 
        m_database.transaction();
2341
 
 
2342
 
        QSqlQuery query(m_database);
2343
 
        query.prepare("SELECT currentPage,continuousMode,layoutMode,scaleMode,scaleFactor,rotation FROM perfilesettings_v1 WHERE filePath==?");
2344
 
 
2345
 
        query.bindValue(0, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
2346
 
 
2347
 
        query.exec();
2348
 
 
2349
 
        if(query.next())
2350
 
        {
2351
 
            tab->setContinousMode(query.value(1).toBool());
2352
 
            tab->setLayoutMode(static_cast< LayoutMode >(query.value(2).toUInt()));
2353
 
 
2354
 
            tab->setScaleMode(static_cast< ScaleMode >(query.value(3).toUInt()));
2355
 
            tab->setScaleFactor(query.value(4).toReal());
2356
 
 
2357
 
            tab->setRotation(static_cast< Rotation >(query.value(5).toUInt()));
2358
 
 
2359
 
            tab->jumpToPage(query.value(0).toInt(), false);
2360
 
        }
2361
 
 
2362
 
        if(!query.isActive())
2363
 
        {
2364
 
            qDebug() << query.lastError();
2365
 
        }
2366
 
 
2367
 
        m_database.commit();
2368
 
    }
2369
 
 
2370
 
#else
2371
 
 
2372
 
    Q_UNUSED(tab);
2373
 
 
2374
 
#endif // WITH_SQL
2375
 
}
2376
 
 
2377
 
void MainWindow::savePerFileSettings(const DocumentView* tab)
2378
 
{
2379
 
#ifdef WITH_SQL
2380
 
 
2381
 
    if(s_settings->mainWindow().restorePerFileSettings() && m_database.isOpen() && tab != 0)
2382
 
    {
2383
 
        m_database.transaction();
2384
 
 
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 (?,?,?,?,?,?,?,?)");
2389
 
 
2390
 
        query.bindValue(0, QDateTime::currentDateTime().toTime_t());
2391
 
 
2392
 
        query.bindValue(1, QCryptographicHash::hash(QFileInfo(tab->filePath()).absoluteFilePath().toUtf8(), QCryptographicHash::Sha1).toBase64());
2393
 
        query.bindValue(2, tab->currentPage());
2394
 
 
2395
 
        query.bindValue(3, static_cast< uint >(tab->continousMode()));
2396
 
        query.bindValue(4, static_cast< uint >(tab->layoutMode()));
2397
 
 
2398
 
        query.bindValue(5, static_cast< uint >(tab->scaleMode()));
2399
 
        query.bindValue(6, tab->scaleFactor());
2400
 
 
2401
 
        query.bindValue(7, static_cast< uint >(tab->rotation()));
2402
 
 
2403
 
        query.exec();
2404
 
 
2405
 
        if(!query.isActive())
2406
 
        {
2407
 
            qDebug() << query.lastError();
2408
 
        }
2409
 
 
2410
 
        m_database.commit();
2411
 
    }
2412
 
 
2413
 
#else
2414
 
 
2415
 
    Q_UNUSED(tab);
2416
 
 
2417
 
#endif // WITH_SQL
2418
 
}
2419
 
 
2420
 
#ifdef WITH_DBUS
2421
 
 
2422
 
MainWindowAdaptor::MainWindowAdaptor(MainWindow* mainWindow) : QDBusAbstractAdaptor(mainWindow)
2423
 
{
2424
 
}
2425
 
 
2426
 
bool MainWindowAdaptor::open(const QString& filePath, int page, const QRectF& highlight)
2427
 
{
2428
 
    return mainWindow()->open(filePath, page, highlight);
2429
 
}
2430
 
 
2431
 
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, const QRectF& highlight)
2432
 
{
2433
 
    return mainWindow()->openInNewTab(filePath, page, highlight);
2434
 
}
2435
 
 
2436
 
bool MainWindowAdaptor::jumpToPageOrOpenInNewTab(const QString& filePath, int page, bool refreshBeforeJump, const QRectF& highlight)
2437
 
{
2438
 
    return mainWindow()->jumpToPageOrOpenInNewTab(filePath, page, refreshBeforeJump, highlight);
2439
 
}
2440
 
 
2441
 
void MainWindowAdaptor::startSearch(const QString& text)
2442
 
{
2443
 
    mainWindow()->startSearch(text);
2444
 
}
2445
 
 
2446
 
void MainWindowAdaptor::raiseAndActivate()
2447
 
{
2448
 
    mainWindow()->raise();
2449
 
    mainWindow()->activateWindow();
2450
 
}
2451
 
 
2452
 
MainWindow* MainWindowAdaptor::mainWindow() const
2453
 
{
2454
 
    return qobject_cast< MainWindow* >(parent());
2455
 
}
2456
 
 
2457
 
# endif // WITH_DBUS