~adamreichold/qpdfview/trunk

« back to all changes in this revision

Viewing changes to sources/mainwindow.cpp

  • Committer: Adam Reichold
  • Date: 2012-07-01 17:37:17 UTC
  • Revision ID: adamreichold@myopera.com-20120701173717-rjw063ohuse3wcri
manual merge of future branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
Copyright 2012 Adam Reichold
4
 
 
5
 
This file is part of qpdfview.
6
 
 
7
 
qpdfview is free software: you can redistribute it and/or modify
8
 
it under the terms of the GNU General Public License as published by
9
 
the Free Software Foundation, either version 2 of the License, or
10
 
(at your option) any later version.
11
 
 
12
 
qpdfview is distributed in the hope that it will be useful,
13
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
GNU General Public License for more details.
16
 
 
17
 
You should have received a copy of the GNU General Public License
18
 
along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
19
 
 
20
 
*/
21
 
 
22
 
#include "mainwindow.h"
23
 
 
24
 
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent),
25
 
    m_settings(),
26
 
    m_geometry()
27
 
{
28
 
    createActions();
29
 
    createWidgets();
30
 
    createToolBars();
31
 
    createDocks();
32
 
    createMenus();
33
 
 
34
 
    setAcceptDrops(true);
35
 
 
36
 
    slotTabWidgetCurrentChanged(-1);
37
 
 
38
 
    // settings
39
 
 
40
 
    DocumentView::thumbnailWidth = m_settings.value("documentView/thumbnailWidth", 96.0).toReal();
41
 
    DocumentView::thumbnailHeight = m_settings.value("documentView/thumbnailHeight", 144.0).toReal();
42
 
 
43
 
    DocumentView::fitToEqualWidth = m_settings.value("documentView/fitToEqualWidth", false).toBool();
44
 
 
45
 
    DocumentView::highlightLinks = m_settings.value("documentView/highlightLinks", true).toBool();
46
 
    DocumentView::externalLinks = m_settings.value("documentView/externalLinks", false).toBool();
47
 
 
48
 
    m_matchCaseCheckBox->setChecked(m_settings.value("mainWindow/matchCase", true).toBool());
49
 
 
50
 
    restoreGeometry(m_settings.value("mainWindow/geometry").toByteArray());
51
 
    restoreState(m_settings.value("mainWindow/state").toByteArray());
52
 
 
53
 
    m_tabWidget->setTabBarAsNeeded(m_settings.value("mainWindow/tabBarAsNeeded", false).toBool());
54
 
    m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(m_settings.value("mainWindow/tabPosition", static_cast< uint >(QTabWidget::North)).toUInt()));
55
 
 
56
 
    // restore tabs
57
 
 
58
 
    if(m_settings.value("mainWindow/restoreTabs", false).toBool())
59
 
    {
60
 
        QStringList filePaths = m_settings.value("mainWindow/tabs/filePaths", QStringList()).toStringList();
61
 
        QList< QVariant > currentPages = m_settings.value("mainWindow/tabs/currentPages", QList< QVariant >()).toList();
62
 
        QList< QVariant > pageLayouts = m_settings.value("mainWindow/tabs/pageLayouts", QList< QVariant >()).toList();
63
 
        QList< QVariant > scaleModes = m_settings.value("mainWindow/tabs/scaleModes", QList< QVariant >()).toList();
64
 
        QList< QVariant > scaleFactors = m_settings.value("mainWindow/tabs/scaleFactors", QList< QVariant >()).toList();
65
 
        QList< QVariant > rotations = m_settings.value("mainWindow/tabs/rotations", QList< QVariant >()).toList();
66
 
 
67
 
        for(int index = 0; index < filePaths.count(); index++)
68
 
        {
69
 
            if(openInNewTab(filePaths.at(index)))
70
 
            {
71
 
                DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
72
 
 
73
 
                documentView->setCurrentPage(currentPages.value(index, documentView->currentPage()).toInt());
74
 
                documentView->setPageLayout(static_cast< DocumentView::PageLayout >(pageLayouts.value(index, static_cast< uint >(documentView->pageLayout())).toUInt()));
75
 
                documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(scaleModes.value(index, static_cast< uint >(documentView->scaleMode())).toUInt()));
76
 
                documentView->setScaleFactor(scaleFactors.value(index, documentView->scaleFactor()).toReal());
77
 
                documentView->setRotation(static_cast< DocumentView::Rotation >(rotations.value(index, static_cast< uint >(documentView->rotation())).toUInt()));
78
 
            }
79
 
        }
80
 
 
81
 
        m_tabWidget->setCurrentIndex(m_settings.value("mainWindow/tabs/currentIndex", -1).toInt());
82
 
    }
83
 
}
84
 
 
85
 
QSize MainWindow::sizeHint() const
86
 
{
87
 
    return QSize(500, 700);
88
 
}
89
 
 
90
 
QMenu* MainWindow::createPopupMenu()
91
 
{
92
 
    QMenu* menu = new QMenu();
93
 
 
94
 
    menu->addAction(m_fileToolBar->toggleViewAction());
95
 
    menu->addAction(m_editToolBar->toggleViewAction());
96
 
    menu->addAction(m_viewToolBar->toggleViewAction());
97
 
    menu->addSeparator();
98
 
    menu->addAction(m_outlineDock->toggleViewAction());
99
 
    menu->addAction(m_metaInformationDock->toggleViewAction());
100
 
    menu->addAction(m_thumbnailsDock->toggleViewAction());
101
 
 
102
 
    return menu;
103
 
}
104
 
 
105
 
bool MainWindow::open(const QString& filePath, int page, qreal top)
106
 
{
107
 
    if(m_tabWidget->currentIndex() != -1)
108
 
    {
109
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
110
 
 
111
 
        if(documentView->open(filePath))
112
 
        {
113
 
            documentView->setCurrentPage(page, top);
114
 
            documentView->clearBookmarks();
115
 
 
116
 
            return true;
117
 
        }
118
 
        else
119
 
        {
120
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not open document at \"%1\".").arg(QFileInfo(filePath).absoluteFilePath()));
121
 
 
122
 
            return false;
123
 
        }
124
 
    }
125
 
    else
126
 
    {
127
 
        return openInNewTab(filePath, page, top);
128
 
    }
129
 
}
130
 
 
131
 
bool MainWindow::openInNewTab(const QString& filePath, int page, qreal top)
132
 
{
133
 
    DocumentView* documentView = new DocumentView();
134
 
 
135
 
    if(documentView->open(filePath))
136
 
    {
137
 
        QFileInfo fileInfo(filePath);
138
 
 
139
 
        int index = m_tabWidget->addTab(documentView, fileInfo.completeBaseName());
140
 
        m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
141
 
        m_tabWidget->setCurrentIndex(index);
142
 
 
143
 
        m_tabMenu->addAction(documentView->tabAction());
144
 
 
145
 
        connect(documentView, SIGNAL(filePathChanged(QString)), SLOT(slotFilePathChanged(QString)));
146
 
        connect(documentView, SIGNAL(numberOfPagesChanged(int)), SLOT(slotNumberOfPagesChanged(int)));
147
 
 
148
 
        connect(documentView, SIGNAL(currentPageChanged(int)), SLOT(slotCurrentPageChanged(int)));
149
 
 
150
 
        connect(documentView, SIGNAL(searchProgressed(int)), SLOT(slotSearchProgressed(int)));
151
 
        connect(documentView, SIGNAL(searchCanceled()), SLOT(slotSearchCanceled()));
152
 
        connect(documentView, SIGNAL(searchFinished()), SLOT(slotSearchFinished()));
153
 
 
154
 
        connect(documentView, SIGNAL(pageLayoutChanged(DocumentView::PageLayout)), SLOT(slotPageLayoutChanged(DocumentView::PageLayout)));
155
 
        connect(documentView, SIGNAL(scaleModeChanged(DocumentView::ScaleMode)), SLOT(slotScaleModeChanged(DocumentView::ScaleMode)));
156
 
        connect(documentView, SIGNAL(scaleFactorChanged(qreal)), SLOT(slotScaleFactorChanged(qreal)));
157
 
 
158
 
        connect(documentView, SIGNAL(highlightAllChanged(bool)), SLOT(slotHighlightAllChanged(bool)));
159
 
 
160
 
        documentView->setCurrentPage(page, top);
161
 
        documentView->clearBookmarks();
162
 
 
163
 
        documentView->setFocus();
164
 
 
165
 
        return true;
166
 
    }
167
 
    else
168
 
    {
169
 
        delete documentView;
170
 
 
171
 
        QMessageBox::warning(this, tr("Warning"), tr("Could not open document at \"%1\".").arg(QFileInfo(filePath).absoluteFilePath()));
172
 
 
173
 
        return false;
174
 
    }
175
 
}
176
 
 
177
 
void MainWindow::closeEvent(QCloseEvent*)
178
 
{
179
 
    // restore tabs
180
 
 
181
 
    if(m_settings.value("mainWindow/restoreTabs", false).toBool())
182
 
    {
183
 
        QStringList filePaths;
184
 
        QList< QVariant > currentPages;
185
 
        QList< QVariant > pageLayouts;
186
 
        QList< QVariant > scaleModes;
187
 
        QList< QVariant > scaleFactors;
188
 
        QList< QVariant > rotations;
189
 
 
190
 
        for(int index = 0; index < m_tabWidget->count(); index++)
191
 
        {
192
 
            DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index));
193
 
 
194
 
            filePaths.append(QFileInfo(documentView->filePath()).absoluteFilePath());
195
 
            currentPages.append(documentView->currentPage());
196
 
            pageLayouts.append(static_cast< uint >(documentView->pageLayout()));
197
 
            scaleModes.append(static_cast< uint >(documentView->scaleMode()));
198
 
            scaleFactors.append(documentView->scaleFactor());
199
 
            rotations.append(static_cast< uint >(documentView->rotation()));
200
 
        }
201
 
 
202
 
        m_settings.setValue("mainWindow/tabs/filePaths", filePaths);
203
 
        m_settings.setValue("mainWindow/tabs/currentPages", currentPages);
204
 
        m_settings.setValue("mainWindow/tabs/pageLayouts", pageLayouts);
205
 
        m_settings.setValue("mainWindow/tabs/scaleModes", scaleModes);
206
 
        m_settings.setValue("mainWindow/tabs/scaleFactors", scaleFactors);
207
 
        m_settings.setValue("mainWindow/tabs/rotations", rotations);
208
 
 
209
 
        m_settings.setValue("mainWindow/tabs/currentIndex", m_tabWidget->currentIndex());
210
 
    }
211
 
    else
212
 
    {
213
 
        m_settings.remove("mainWindow/tabs/filePaths");
214
 
        m_settings.remove("mainWindow/tabs/currentPages");
215
 
        m_settings.remove("mainWindow/tabs/pageLayouts");
216
 
        m_settings.remove("mainWindow/tabs/scaleModes");
217
 
        m_settings.remove("mainWindow/tabs/scaleFactors");
218
 
        m_settings.remove("mainWindow/tabs/rotations");
219
 
 
220
 
        m_settings.remove("mainWindow/tabs/currentIndex");
221
 
    }
222
 
 
223
 
    slotCloseAllTabs();
224
 
 
225
 
    // settings
226
 
 
227
 
    m_settings.setValue("mainWindow/matchCase", m_matchCaseCheckBox->isChecked());
228
 
 
229
 
    if(m_fullscreenAction->isChecked())
230
 
    {
231
 
        m_settings.setValue("mainWindow/geometry", m_geometry);
232
 
    }
233
 
    else
234
 
    {
235
 
        m_settings.setValue("mainWindow/geometry", saveGeometry());
236
 
    }
237
 
 
238
 
    m_settings.setValue("mainWindow/state", saveState());
239
 
 
240
 
    m_settings.setValue("mainWindow/tabBarAsNeeded", m_tabWidget->tabBarAsNeeded());
241
 
    m_settings.setValue("mainWindow/tabPosition", static_cast< uint >(m_tabWidget->tabPosition()));
242
 
}
243
 
 
244
 
void MainWindow::dragEnterEvent(QDragEnterEvent* event)
245
 
{
246
 
    if(event->mimeData()->hasUrls())
247
 
    {
248
 
        event->acceptProposedAction();
249
 
    }
250
 
}
251
 
 
252
 
void MainWindow::dropEvent(QDropEvent* event)
253
 
{
254
 
    if(event->mimeData()->hasUrls())
255
 
    {
256
 
        event->acceptProposedAction();
257
 
 
258
 
        disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
259
 
 
260
 
        foreach(QUrl url, event->mimeData()->urls())
261
 
        {
262
 
            if(url.scheme() == "file")
263
 
            {
264
 
                openInNewTab(url.path());
265
 
            }
266
 
        }
267
 
 
268
 
        slotTabWidgetCurrentChanged(m_tabWidget->currentIndex());
269
 
 
270
 
        connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
271
 
    }
272
 
}
273
 
 
274
 
void MainWindow::keyPressEvent(QKeyEvent* event)
275
 
{
276
 
    if(m_tabWidget->currentIndex() != -1)
277
 
    {
278
 
        QKeyEvent keyEvent(*event);
279
 
 
280
 
        QApplication::sendEvent(m_tabWidget->currentWidget(), &keyEvent);
281
 
    }
282
 
}
283
 
 
284
 
void MainWindow::slotOpen()
285
 
{
286
 
    if(m_tabWidget->currentIndex() != -1)
287
 
    {
288
 
        QString path = m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString();
289
 
        QString filePath = QFileDialog::getOpenFileName(this, tr("Open document"), path, "Portable Document Format (*.pdf)");
290
 
 
291
 
        if(!filePath.isEmpty())
292
 
        {
293
 
            if(open(filePath))
294
 
            {
295
 
                m_recentlyUsedAction->addEntry(filePath);
296
 
 
297
 
                m_settings.setValue("mainWindow/path", QFileInfo(filePath).absolutePath());
298
 
            }
299
 
        }
300
 
    }
301
 
    else
302
 
    {
303
 
        slotOpenInNewTab();
304
 
    }
305
 
}
306
 
 
307
 
void MainWindow::slotOpenInNewTab()
308
 
{
309
 
    QString path = m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString();
310
 
    QStringList filePaths = QFileDialog::getOpenFileNames(this, tr("Open documents"), path, "Portable Document Format (*.pdf)");
311
 
 
312
 
    disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
313
 
 
314
 
    foreach(QString filePath, filePaths)
315
 
    {
316
 
        if(openInNewTab(filePath))
317
 
        {
318
 
            m_recentlyUsedAction->addEntry(filePath);
319
 
 
320
 
            m_settings.setValue("mainWindow/path", QFileInfo(filePath).absolutePath());
321
 
        }
322
 
    }
323
 
 
324
 
    slotTabWidgetCurrentChanged(m_tabWidget->currentIndex());
325
 
 
326
 
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
327
 
}
328
 
 
329
 
void MainWindow::slotRecentyUsedActionEntrySelected(const QString& filePath)
330
 
{
331
 
    open(filePath);
332
 
}
333
 
 
334
 
void MainWindow::slotRefresh()
335
 
{
336
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
337
 
 
338
 
    documentView->refresh();
339
 
}
340
 
 
341
 
void MainWindow::slotSaveCopy()
342
 
{
343
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
344
 
 
345
 
    QString path = m_settings.value("mainWindow/path", QDesktopServices::storageLocation(QDesktopServices::DocumentsLocation)).toString() + "/" + QFileInfo(documentView->filePath()).fileName();
346
 
    QString filePath = QFileDialog::getSaveFileName(this, tr("Save copy"), path, "Portable Document Format (*.pdf)");
347
 
 
348
 
    if(!filePath.isEmpty())
349
 
    {
350
 
        if(documentView->saveCopy(filePath))
351
 
        {
352
 
            m_settings.setValue("mainWindow/path", QFileInfo(filePath).absolutePath());
353
 
        }
354
 
        else
355
 
        {
356
 
            QMessageBox::warning(this, tr("Warning"), tr("Could not save copy at \"%1\".").arg(filePath));
357
 
        }
358
 
    }
359
 
}
360
 
 
361
 
void MainWindow::slotPrint()
362
 
{
363
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
364
 
 
365
 
    QPrinter* printer = new QPrinter();
366
 
 
367
 
    QPrintDialog printDialog(printer, this);
368
 
 
369
 
    printDialog.setOptions(QAbstractPrintDialog::PrintDialogOptions());
370
 
    printDialog.setOption(QAbstractPrintDialog::PrintCollateCopies, true);
371
 
    printDialog.setOption(QAbstractPrintDialog::PrintPageRange, true);
372
 
 
373
 
    printDialog.setMinMax(1, documentView->numberOfPages());
374
 
 
375
 
    if(printDialog.exec() == QDialog::Accepted)
376
 
    {
377
 
        int fromPage = printDialog.fromPage() != 0 ? printDialog.fromPage() : 1;
378
 
        int toPage = printDialog.toPage() != 0 ? printDialog.toPage() : documentView->numberOfPages();
379
 
 
380
 
        QProgressDialog progressDialog;
381
 
 
382
 
        progressDialog.setLabelText(tr("Printing pages %1 to %2...").arg(fromPage).arg(toPage));
383
 
        progressDialog.setRange(0, 100);
384
 
        progressDialog.setValue(0);
385
 
 
386
 
        connect(documentView, SIGNAL(printProgressed(int)), &progressDialog, SLOT(setValue(int)));
387
 
        connect(documentView, SIGNAL(printCanceled()), &progressDialog, SLOT(close()));
388
 
        connect(documentView, SIGNAL(printFinished()), &progressDialog, SLOT(close()));
389
 
 
390
 
        connect(&progressDialog, SIGNAL(canceled()), documentView, SLOT(cancelPrint()));
391
 
 
392
 
        documentView->startPrint(printer, fromPage, toPage);
393
 
 
394
 
        progressDialog.exec();
395
 
    }
396
 
}
397
 
 
398
 
void MainWindow::slotPreviousPage()
399
 
{
400
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
401
 
 
402
 
    documentView->previousPage();
403
 
}
404
 
 
405
 
void MainWindow::slotNextPage()
406
 
{
407
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
408
 
 
409
 
    documentView->nextPage();
410
 
}
411
 
 
412
 
void MainWindow::slotFirstPage()
413
 
{
414
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
415
 
 
416
 
    documentView->firstPage();
417
 
}
418
 
 
419
 
void MainWindow::slotLastPage()
420
 
{
421
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
422
 
 
423
 
    documentView->lastPage();
424
 
}
425
 
 
426
 
void MainWindow::slotJumpToPage()
427
 
{
428
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
429
 
 
430
 
    bool ok = false;
431
 
    int page = QInputDialog::getInt(this, tr("Jump to page"), tr("Page:"), documentView->currentPage(), 1, documentView->numberOfPages(), 1, &ok);
432
 
 
433
 
    if(ok)
434
 
    {
435
 
        documentView->setCurrentPage(page);
436
 
    }
437
 
}
438
 
 
439
 
void MainWindow::slotSearch()
440
 
{
441
 
    if(m_searchToolBar->isHidden())
442
 
    {
443
 
        m_searchToolBar->show();
444
 
    }
445
 
    else
446
 
    {
447
 
        m_searchLineEdit->selectAll();
448
 
    }
449
 
 
450
 
    m_searchLineEdit->setFocus();
451
 
}
452
 
 
453
 
void MainWindow::slotStartSearch()
454
 
{
455
 
    m_searchTimer->stop();
456
 
 
457
 
    if(m_searchToolBar->isVisible() && !m_searchLineEdit->text().isEmpty())
458
 
    {
459
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
460
 
 
461
 
        documentView->startSearch(m_searchLineEdit->text(), m_matchCaseCheckBox->isChecked());
462
 
    }
463
 
}
464
 
 
465
 
void MainWindow::slotSearchProgressed(int value)
466
 
{
467
 
    QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
468
 
    pos.rx() += 10; pos.ry() -= 50;
469
 
 
470
 
    QToolTip::showText(pos, tr("Searched %1% of the current document...").arg(value), centralWidget());
471
 
}
472
 
 
473
 
void MainWindow::slotSearchCanceled()
474
 
{
475
 
    QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
476
 
    pos.rx() += 10; pos.ry() -= 50;
477
 
 
478
 
    QToolTip::showText(pos, tr("Search canceled."), centralWidget());
479
 
}
480
 
 
481
 
void MainWindow::slotSearchFinished()
482
 
{
483
 
    QPoint pos = centralWidget()->mapToGlobal(centralWidget()->rect().bottomLeft());
484
 
    pos.rx() += 10; pos.ry() -= 50;
485
 
 
486
 
    QToolTip::showText(pos, tr("Search finished."), centralWidget());
487
 
}
488
 
 
489
 
void MainWindow::slotFindPrevious()
490
 
{
491
 
    if(m_tabWidget->currentIndex() != -1)
492
 
    {
493
 
        if(m_searchToolBar->isHidden())
494
 
        {
495
 
            m_searchToolBar->show();
496
 
            m_searchLineEdit->setFocus();
497
 
        }
498
 
        else
499
 
        {
500
 
            if(!m_searchLineEdit->text().isEmpty())
501
 
            {
502
 
                DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
503
 
 
504
 
                documentView->findPrevious();
505
 
            }
506
 
        }
507
 
    }
508
 
}
509
 
 
510
 
void MainWindow::slotFindNext()
511
 
{
512
 
    if(m_tabWidget->currentIndex() != -1)
513
 
    {
514
 
        if(m_searchToolBar->isHidden())
515
 
        {
516
 
            m_searchToolBar->show();
517
 
            m_searchLineEdit->setFocus();
518
 
        }
519
 
        else
520
 
        {
521
 
            if(!m_searchLineEdit->text().isEmpty())
522
 
            {
523
 
                DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
524
 
 
525
 
                documentView->findNext();
526
 
            }
527
 
        }
528
 
    }
529
 
}
530
 
 
531
 
void MainWindow::slotCancelSearch()
532
 
{
533
 
    m_searchLineEdit->clear();
534
 
    m_searchTimer->stop();
535
 
    m_searchToolBar->hide();
536
 
 
537
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
538
 
 
539
 
    documentView->cancelSearch();
540
 
}
541
 
 
542
 
void MainWindow::slotSettings()
543
 
{
544
 
    m_settings.setValue("mainWindow/tabBarAsNeeded", m_tabWidget->tabBarAsNeeded());
545
 
    m_settings.setValue("mainWindow/tabPosition", static_cast< uint >(m_tabWidget->tabPosition()));
546
 
 
547
 
    m_settings.sync();
548
 
 
549
 
    SettingsDialog settingsDialog;
550
 
 
551
 
    if(settingsDialog.exec() == QDialog::Accepted)
552
 
    {
553
 
        m_tabWidget->setTabBarAsNeeded(m_settings.value("mainWindow/tabBarAsNeeded", false).toBool());
554
 
        m_tabWidget->setTabPosition(static_cast< QTabWidget::TabPosition >(m_settings.value("mainWindow/tabPosition", static_cast< uint >(QTabWidget::North)).toUInt()));
555
 
 
556
 
        DocumentView::fitToEqualWidth = m_settings.value("documentView/fitToEqualWidth", false).toBool();
557
 
 
558
 
        DocumentView::highlightLinks = m_settings.value("documentView/highlightLinks", true).toBool();
559
 
        DocumentView::externalLinks = m_settings.value("documentView/externalLinks", false).toBool();
560
 
 
561
 
        for(int index = 0; index < m_tabWidget->count(); index++)
562
 
        {
563
 
            DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index)); Q_ASSERT(documentView);
564
 
 
565
 
            documentView->refresh();
566
 
        }
567
 
    }
568
 
}
569
 
 
570
 
void MainWindow::slotPageLayoutGroupTriggered(QAction* action)
571
 
{
572
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
573
 
 
574
 
    documentView->setPageLayout(static_cast< DocumentView::PageLayout >(action->data().toUInt()));
575
 
}
576
 
 
577
 
void MainWindow::slotScaleModeGroupTriggered(QAction* action)
578
 
{
579
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
580
 
 
581
 
    documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(action->data().toUInt()));
582
 
}
583
 
 
584
 
void MainWindow::slotZoomIn()
585
 
{
586
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
587
 
 
588
 
    documentView->zoomIn();
589
 
}
590
 
 
591
 
void MainWindow::slotZoomOut()
592
 
{
593
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
594
 
 
595
 
    documentView->zoomOut();
596
 
}
597
 
 
598
 
void MainWindow::slotRotateLeft()
599
 
{
600
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
601
 
 
602
 
    documentView->rotateLeft();
603
 
}
604
 
 
605
 
void MainWindow::slotRotateRight()
606
 
{
607
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
608
 
 
609
 
    documentView->rotateRight();
610
 
}
611
 
 
612
 
void MainWindow::slotFonts()
613
 
{
614
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
615
 
 
616
 
    FontsDialog fontsDialog(documentView->fontsTableWidget());
617
 
 
618
 
    fontsDialog.resize(m_settings.value("mainWindow/fontsDialogSize", fontsDialog.sizeHint()).toSize());
619
 
 
620
 
    fontsDialog.exec();
621
 
 
622
 
    m_settings.setValue("mainWindow/fontsDialogSize", fontsDialog.size());
623
 
}
624
 
 
625
 
void MainWindow::slotFullscreen()
626
 
{
627
 
    if(m_fullscreenAction->isChecked())
628
 
    {
629
 
        m_geometry = saveGeometry();
630
 
 
631
 
        showFullScreen();
632
 
    }
633
 
    else
634
 
    {
635
 
        restoreGeometry(m_geometry);
636
 
 
637
 
        showNormal();
638
 
 
639
 
        restoreGeometry(m_geometry);
640
 
    }
641
 
}
642
 
 
643
 
void MainWindow::slotPresentation()
644
 
{
645
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
646
 
    PresentationView* presentationView = new PresentationView();
647
 
 
648
 
    if(presentationView->open(documentView->filePath()))
649
 
    {
650
 
        presentationView->setCurrentPage(documentView->currentPage());
651
 
 
652
 
        presentationView->show();
653
 
        presentationView->setAttribute(Qt::WA_DeleteOnClose);
654
 
    }
655
 
    else
656
 
    {
657
 
        delete presentationView;
658
 
 
659
 
        QMessageBox::warning(this, tr("Warning"), tr("Could not open document \"%1\".").arg(QFileInfo(documentView->filePath()).completeBaseName()));
660
 
    }
661
 
}
662
 
 
663
 
void MainWindow::slotPreviousTab()
664
 
{
665
 
    if(m_tabWidget->currentIndex() > 0)
666
 
    {
667
 
        m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() - 1);
668
 
    }
669
 
    else
670
 
    {
671
 
        m_tabWidget->setCurrentIndex(m_tabWidget->count() - 1);
672
 
    }
673
 
}
674
 
 
675
 
void MainWindow::slotNextTab()
676
 
{
677
 
    if(m_tabWidget->currentIndex() < m_tabWidget->count() - 1)
678
 
    {
679
 
        m_tabWidget->setCurrentIndex(m_tabWidget->currentIndex() + 1);
680
 
    }
681
 
    else
682
 
    {
683
 
        m_tabWidget->setCurrentIndex(0);
684
 
    }
685
 
}
686
 
 
687
 
void MainWindow::slotCloseTab()
688
 
{
689
 
    delete m_tabWidget->currentWidget();
690
 
}
691
 
 
692
 
void MainWindow::slotCloseAllTabs()
693
 
{
694
 
    disconnect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
695
 
 
696
 
    while(m_tabWidget->count() > 0)
697
 
    {
698
 
        delete m_tabWidget->widget(0);
699
 
    }
700
 
 
701
 
    slotTabWidgetCurrentChanged(-1);
702
 
 
703
 
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotTabWidgetCurrentChanged(int)));
704
 
}
705
 
 
706
 
void MainWindow::slotCloseAllTabsButCurrentTab()
707
 
{
708
 
    if(m_tabWidget->currentIndex() != -1)
709
 
    {
710
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
711
 
 
712
 
        m_tabWidget->removeTab(m_tabWidget->currentIndex());
713
 
 
714
 
        slotCloseAllTabs();
715
 
 
716
 
        QFileInfo fileInfo(documentView->filePath());
717
 
 
718
 
        int index = m_tabWidget->addTab(documentView, fileInfo.completeBaseName());
719
 
        m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath());
720
 
        m_tabWidget->setCurrentIndex(index);
721
 
    }
722
 
}
723
 
 
724
 
void MainWindow::slotContents()
725
 
{
726
 
    HelpDialog helpDialog;
727
 
 
728
 
    helpDialog.resize(m_settings.value("mainWindow/helpDialogSize", helpDialog.sizeHint()).toSize());
729
 
 
730
 
    helpDialog.exec();
731
 
 
732
 
    m_settings.setValue("mainWindow/helpDialogSize", helpDialog.size());
733
 
}
734
 
 
735
 
void MainWindow::slotAbout()
736
 
{
737
 
    QMessageBox::about(this, tr("About qpdfview"), tr("<p><b>qpdfview %1</b></p><p>qpdfview is a tabbed PDF viewer using the poppler library. See <a href=\"https://launchpad.net/qpdfview\">launchpad.net/qpdfview</a> for more information.</p><p>&copy; 2012 Adam Reichold</p>").arg(QApplication::applicationVersion()));
738
 
}
739
 
 
740
 
void MainWindow::slotTabWidgetCurrentChanged(int index)
741
 
{
742
 
    if(index != -1)
743
 
    {
744
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
745
 
 
746
 
        m_refreshAction->setEnabled(true);
747
 
        m_saveCopyAction->setEnabled(true);
748
 
        m_printAction->setEnabled(true);
749
 
 
750
 
        m_previousPageAction->setEnabled(true);
751
 
        m_nextPageAction->setEnabled(true);
752
 
        m_firstPageAction->setEnabled(true);
753
 
        m_lastPageAction->setEnabled(true);
754
 
        m_jumpToPageAction->setEnabled(true);
755
 
 
756
 
        m_searchAction->setEnabled(true);
757
 
        m_findPreviousAction->setEnabled(true);
758
 
        m_findNextAction->setEnabled(true);
759
 
        m_cancelSearchAction->setEnabled(true);
760
 
 
761
 
        m_pageLayoutGroup->setEnabled(true);
762
 
 
763
 
        m_scaleModeGroup->setEnabled(true);
764
 
 
765
 
        m_zoomInAction->setEnabled(true);
766
 
        m_zoomOutAction->setEnabled(true);
767
 
 
768
 
        m_rotateLeftAction->setEnabled(true);
769
 
        m_rotateRightAction->setEnabled(true);
770
 
 
771
 
        m_fontsAction->setEnabled(true);
772
 
 
773
 
        m_presentationAction->setEnabled(true);
774
 
 
775
 
        m_previousTabAction->setEnabled(true);
776
 
        m_nextTabAction->setEnabled(true);
777
 
        m_closeTabAction->setEnabled(true);
778
 
        m_closeAllTabsAction->setEnabled(true);
779
 
        m_closeAllTabsButCurrentTabAction->setEnabled(true);
780
 
 
781
 
        m_editToolBar->setEnabled(true);
782
 
        m_viewToolBar->setEnabled(true);
783
 
 
784
 
        m_searchToolBar->setEnabled(true);
785
 
 
786
 
        if(m_searchToolBar->isVisible())
787
 
        {
788
 
            m_searchLineEdit->clear();
789
 
            m_searchTimer->stop();
790
 
 
791
 
            for(int index = 0; index < m_tabWidget->count(); index++)
792
 
            {
793
 
                DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->widget(index)); Q_ASSERT(documentView);
794
 
 
795
 
                documentView->cancelSearch();
796
 
            }
797
 
        }
798
 
 
799
 
        slotCurrentPageChanged(documentView->currentPage());
800
 
        slotNumberOfPagesChanged(documentView->numberOfPages());
801
 
        slotPageLayoutChanged(documentView->pageLayout());
802
 
        slotScaleModeChanged(documentView->scaleMode());
803
 
        slotScaleFactorChanged(documentView->scaleFactor());
804
 
        slotHighlightAllChanged(documentView->highlightAll());
805
 
 
806
 
        m_outlineDock->setWidget(documentView->outlineTreeWidget());
807
 
        m_metaInformationDock->setWidget(documentView->metaInformationTableWidget());
808
 
        m_thumbnailsDock->setWidget(documentView->thumbnailsGraphicsView());
809
 
 
810
 
        setWindowTitle(m_tabWidget->tabText(index) + " - qpdfview");
811
 
    }
812
 
    else
813
 
    {
814
 
        m_refreshAction->setEnabled(false);
815
 
        m_saveCopyAction->setEnabled(false);
816
 
        m_printAction->setEnabled(false);
817
 
 
818
 
        m_previousPageAction->setEnabled(false);
819
 
        m_nextPageAction->setEnabled(false);
820
 
        m_firstPageAction->setEnabled(false);
821
 
        m_lastPageAction->setEnabled(false);
822
 
        m_jumpToPageAction->setEnabled(false);
823
 
 
824
 
        m_searchAction->setEnabled(false);
825
 
        m_findPreviousAction->setEnabled(false);
826
 
        m_findNextAction->setEnabled(false);
827
 
        m_cancelSearchAction->setEnabled(false);
828
 
 
829
 
        m_onePageAction->setChecked(true);
830
 
        m_pageLayoutGroup->setEnabled(false);
831
 
 
832
 
        m_doNotScaleAction->setChecked(true);
833
 
        m_scaleModeGroup->setEnabled(false);
834
 
 
835
 
        m_zoomInAction->setEnabled(false);
836
 
        m_zoomOutAction->setEnabled(false);
837
 
 
838
 
        m_rotateLeftAction->setEnabled(false);
839
 
        m_rotateRightAction->setEnabled(false);
840
 
 
841
 
        m_fontsAction->setEnabled(false);
842
 
 
843
 
        m_presentationAction->setEnabled(false);
844
 
 
845
 
        m_previousTabAction->setEnabled(false);
846
 
        m_nextTabAction->setEnabled(false);
847
 
        m_closeTabAction->setEnabled(false);
848
 
        m_closeAllTabsAction->setEnabled(false);
849
 
        m_closeAllTabsButCurrentTabAction->setEnabled(false);
850
 
 
851
 
        m_currentPageLineEdit->setText(QString());
852
 
        m_numberOfPagesLabel->setText(QString());
853
 
        m_editToolBar->setEnabled(false);
854
 
 
855
 
        m_scaleFactorComboBox->setCurrentIndex(2);
856
 
        m_viewToolBar->setEnabled(false);
857
 
 
858
 
        m_highlightAllCheckBox->setChecked(false);
859
 
        m_searchToolBar->setEnabled(false);
860
 
 
861
 
        if(m_searchToolBar->isVisible())
862
 
        {
863
 
            m_searchLineEdit->clear();
864
 
            m_searchTimer->stop();
865
 
            m_searchToolBar->hide();
866
 
        }
867
 
 
868
 
        m_outlineDock->setWidget(0);
869
 
        m_metaInformationDock->setWidget(0);
870
 
        m_thumbnailsDock->setWidget(0);
871
 
 
872
 
        setWindowTitle("qpdfview");
873
 
    }
874
 
}
875
 
 
876
 
void MainWindow::slotTabWidgetTabCloseRequested(int index)
877
 
{
878
 
    delete m_tabWidget->widget(index);
879
 
}
880
 
 
881
 
void MainWindow::slotCurrentPageLineEditEditingFinished()
882
 
{
883
 
    if(m_tabWidget->currentIndex() != -1)
884
 
    {
885
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
886
 
 
887
 
        documentView->setCurrentPage(m_currentPageLineEdit->text().toInt());
888
 
    }
889
 
}
890
 
 
891
 
void MainWindow::slotCurrentPageLineEditReturnPressed()
892
 
{
893
 
    m_tabWidget->currentWidget()->setFocus();
894
 
}
895
 
 
896
 
void MainWindow::slotScaleFactorComboBoxCurrentIndexChanged(int index)
897
 
{
898
 
    if(m_tabWidget->currentIndex() != -1)
899
 
    {
900
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
901
 
 
902
 
        documentView->setScaleMode(static_cast< DocumentView::ScaleMode >(m_scaleFactorComboBox->itemData(index).toUInt()));
903
 
    }
904
 
}
905
 
 
906
 
void MainWindow::slotScaleFactorComboBoxEditingFinished()
907
 
{
908
 
    if(m_tabWidget->currentIndex() != -1)
909
 
    {
910
 
        DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
911
 
 
912
 
        QString text = m_scaleFactorComboBox->lineEdit()->text();
913
 
 
914
 
        text = text.trimmed();
915
 
 
916
 
        text = text.endsWith('%') ? text.left(text.size() - 1) : text;
917
 
 
918
 
        text = text.trimmed();
919
 
 
920
 
        bool ok = false;
921
 
        qreal scaleFactor = QLocale::system().toInt(text, &ok) / 100.0;
922
 
 
923
 
        if(ok && scaleFactor >= DocumentView::mininumScaleFactor && scaleFactor <= DocumentView::maximumScaleFactor)
924
 
        {
925
 
            documentView->setScaleFactor(scaleFactor);
926
 
            documentView->setScaleMode(DocumentView::ScaleFactor);
927
 
        }
928
 
 
929
 
        slotScaleFactorChanged(documentView->scaleFactor());
930
 
        slotScaleModeChanged(documentView->scaleMode());
931
 
    }
932
 
}
933
 
 
934
 
void MainWindow::slotScaleFactorComboBoxReturnPressed()
935
 
{
936
 
    m_tabWidget->currentWidget()->setFocus();
937
 
}
938
 
 
939
 
void MainWindow::slotHighlightAllCheckBoxClicked(bool checked)
940
 
{
941
 
    DocumentView* documentView = qobject_cast< DocumentView* >(m_tabWidget->currentWidget()); Q_ASSERT(documentView);
942
 
 
943
 
    documentView->setHighlightAll(checked);
944
 
}
945
 
 
946
 
void MainWindow::slotFilePathChanged(const QString& filePath)
947
 
{
948
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
949
 
 
950
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
951
 
    {
952
 
        QFileInfo fileInfo(filePath);
953
 
 
954
 
        m_tabWidget->setTabText(m_tabWidget->currentIndex(), fileInfo.completeBaseName());
955
 
        m_tabWidget->setTabToolTip(m_tabWidget->currentIndex(), fileInfo.absoluteFilePath());
956
 
 
957
 
        setWindowTitle(fileInfo.completeBaseName() + " - qpdfview");
958
 
    }
959
 
}
960
 
 
961
 
void MainWindow::slotNumberOfPagesChanged(int numberOfPages)
962
 
{
963
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
964
 
 
965
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
966
 
    {
967
 
        m_currentPageValidator->setRange(1, numberOfPages);
968
 
        m_numberOfPagesLabel->setText(tr(" of %1").arg(numberOfPages));
969
 
    }
970
 
}
971
 
 
972
 
void MainWindow::slotCurrentPageChanged(int currentPage)
973
 
{
974
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
975
 
 
976
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
977
 
    {
978
 
        m_currentPageLineEdit->setText(QLocale::system().toString(currentPage));
979
 
    }
980
 
}
981
 
 
982
 
void MainWindow::slotPageLayoutChanged(DocumentView::PageLayout pageLayout)
983
 
{
984
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
985
 
 
986
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
987
 
    {
988
 
        foreach(QAction* action, m_pageLayoutGroup->actions())
989
 
        {
990
 
            action->setChecked(action->data().toUInt() == static_cast< uint >(pageLayout));
991
 
        }
992
 
    }
993
 
}
994
 
 
995
 
void MainWindow::slotScaleModeChanged(DocumentView::ScaleMode scaleMode)
996
 
{
997
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
998
 
 
999
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
1000
 
    {
1001
 
        foreach(QAction* action, m_scaleModeGroup->actions())
1002
 
        {
1003
 
            action->setChecked(action->data().toUInt() == static_cast< uint >(scaleMode));
1004
 
        }
1005
 
 
1006
 
        for(int index = 0; index < m_scaleFactorComboBox->count(); index++)
1007
 
        {
1008
 
            if(m_scaleFactorComboBox->itemData(index).toUInt() == static_cast< uint >(scaleMode))
1009
 
            {
1010
 
                m_scaleFactorComboBox->setCurrentIndex(index);
1011
 
            }
1012
 
        }
1013
 
    }
1014
 
}
1015
 
 
1016
 
void MainWindow::slotScaleFactorChanged(qreal scaleFactor)
1017
 
{
1018
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
1019
 
 
1020
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
1021
 
    {
1022
 
        m_scaleFactorComboBox->setItemText(3, tr("Scale to %1%").arg(100.0 * scaleFactor, 0, 'f', 0));
1023
 
    }
1024
 
}
1025
 
 
1026
 
void MainWindow::slotHighlightAllChanged(bool highlightAll)
1027
 
{
1028
 
    DocumentView* documentView = qobject_cast< DocumentView* >(sender());
1029
 
 
1030
 
    if(documentView == 0 || documentView == m_tabWidget->currentWidget())
1031
 
    {
1032
 
        m_highlightAllCheckBox->setChecked(highlightAll);
1033
 
    }
1034
 
}
1035
 
 
1036
 
void MainWindow::createActions()
1037
 
{
1038
 
    if(m_settings.contains("mainWindow/iconTheme"))
1039
 
    {
1040
 
        QIcon::setThemeName(m_settings.value("mainWindow/iconTheme").toString());
1041
 
    }
1042
 
 
1043
 
    // open
1044
 
 
1045
 
    m_openAction = new QAction(tr("&Open..."), this);
1046
 
    m_openAction->setShortcut(QKeySequence::Open);
1047
 
    m_openAction->setIconVisibleInMenu(true);
1048
 
    connect(m_openAction, SIGNAL(triggered()), SLOT(slotOpen()));
1049
 
 
1050
 
    if(QIcon::hasThemeIcon("document-open"))
1051
 
    {
1052
 
        m_openAction->setIcon(QIcon::fromTheme("document-open"));
1053
 
    }
1054
 
    else
1055
 
    {
1056
 
#ifdef DATA_INSTALL_PATH
1057
 
        m_openAction->setIcon(QIcon(QString("%1/document-open.svg").arg(DATA_INSTALL_PATH)));
1058
 
#else
1059
 
        m_openAction->setIcon(QIcon(":/icons/document-open.svg"));
1060
 
#endif
1061
 
    }
1062
 
 
1063
 
    // open in new tab
1064
 
 
1065
 
    m_openInNewTabAction = new QAction(tr("Open in new &tab..."), this);
1066
 
    m_openInNewTabAction->setShortcut(QKeySequence::AddTab);
1067
 
    m_openInNewTabAction->setIconVisibleInMenu(true);
1068
 
    connect(m_openInNewTabAction, SIGNAL(triggered()), SLOT(slotOpenInNewTab()));
1069
 
 
1070
 
    if(QIcon::hasThemeIcon("tab-new"))
1071
 
    {
1072
 
        m_openInNewTabAction->setIcon(QIcon::fromTheme("tab-new"));
1073
 
    }
1074
 
    else
1075
 
    {
1076
 
#ifdef DATA_INSTALL_PATH
1077
 
        m_openInNewTabAction->setIcon(QIcon(QString("%1/tab-new.svg").arg(DATA_INSTALL_PATH)));
1078
 
#else
1079
 
        m_openInNewTabAction->setIcon(QIcon(":/icons/tab-new.svg"));
1080
 
#endif
1081
 
    }
1082
 
 
1083
 
    // recently used
1084
 
 
1085
 
    m_recentlyUsedAction = new RecentlyUsedAction(this);
1086
 
    m_recentlyUsedAction->setIcon(QIcon::fromTheme("document-open-recent"));
1087
 
    m_recentlyUsedAction->setIconVisibleInMenu(true);
1088
 
    connect(m_recentlyUsedAction, SIGNAL(entrySelected(QString)), SLOT(slotRecentyUsedActionEntrySelected(QString)));
1089
 
 
1090
 
    // refresh
1091
 
 
1092
 
    m_refreshAction = new QAction(tr("&Refresh"), this);
1093
 
    m_refreshAction->setShortcut(QKeySequence::Refresh);
1094
 
    m_refreshAction->setIconVisibleInMenu(true);
1095
 
    connect(m_refreshAction, SIGNAL(triggered()), SLOT(slotRefresh()));
1096
 
 
1097
 
    if(QIcon::hasThemeIcon("view-refresh"))
1098
 
    {
1099
 
        m_refreshAction->setIcon(QIcon::fromTheme("view-refresh"));
1100
 
    }
1101
 
    else
1102
 
    {
1103
 
#ifdef DATA_INSTALL_PATH
1104
 
        m_refreshAction->setIcon(QIcon(QString("%1/view-refresh.svg").arg(DATA_INSTALL_PATH)));
1105
 
#else
1106
 
        m_refreshAction->setIcon(QIcon(":/icons/view-refresh.svg"));
1107
 
#endif
1108
 
    }
1109
 
 
1110
 
    // save copy
1111
 
 
1112
 
    m_saveCopyAction = new QAction(tr("&Save copy..."), this);
1113
 
    m_saveCopyAction->setShortcut(QKeySequence::Save);
1114
 
    m_saveCopyAction->setIconVisibleInMenu(true);
1115
 
    connect(m_saveCopyAction, SIGNAL(triggered()), SLOT(slotSaveCopy()));
1116
 
 
1117
 
    if(QIcon::hasThemeIcon("document-save"))
1118
 
    {
1119
 
        m_saveCopyAction->setIcon(QIcon::fromTheme("document-save"));
1120
 
    }
1121
 
    else
1122
 
    {
1123
 
#ifdef DATA_INSTALL_PATH
1124
 
        m_saveCopyAction->setIcon(QIcon(QString("%1/document-save.svg").arg(DATA_INSTALL_PATH)));
1125
 
#else
1126
 
        m_saveCopyAction->setIcon(QIcon(":/icons/document-save.svg"));
1127
 
#endif
1128
 
    }
1129
 
 
1130
 
    // print
1131
 
 
1132
 
    m_printAction = new QAction(tr("&Print..."), this);
1133
 
    m_printAction->setShortcut(QKeySequence::Print);
1134
 
    m_printAction->setIconVisibleInMenu(true);
1135
 
    connect(m_printAction, SIGNAL(triggered()), SLOT(slotPrint()));
1136
 
 
1137
 
    if(QIcon::hasThemeIcon("document-print"))
1138
 
    {
1139
 
        m_printAction->setIcon(QIcon::fromTheme("document-print"));
1140
 
    }
1141
 
    else
1142
 
    {
1143
 
#ifdef DATA_INSTALL_PATH
1144
 
        m_printAction->setIcon(QIcon(QString("%1/document-print.svg").arg(DATA_INSTALL_PATH)));
1145
 
#else
1146
 
        m_printAction->setIcon(QIcon(":/icons/document-print.svg"));
1147
 
#endif
1148
 
    }
1149
 
 
1150
 
    // exit
1151
 
 
1152
 
    m_exitAction = new QAction(tr("&Exit"), this);
1153
 
    m_exitAction->setShortcut(QKeySequence::Quit);
1154
 
    m_exitAction->setIcon(QIcon::fromTheme("application-exit"));
1155
 
    m_exitAction->setIconVisibleInMenu(true);
1156
 
    connect(m_exitAction, SIGNAL(triggered()), SLOT(close()));
1157
 
 
1158
 
    // previous page
1159
 
 
1160
 
    m_previousPageAction = new QAction(tr("&Previous page"), this);
1161
 
    m_previousPageAction->setShortcut(QKeySequence(Qt::Key_Left));
1162
 
    m_previousPageAction->setIconVisibleInMenu(true);
1163
 
    connect(m_previousPageAction, SIGNAL(triggered()), SLOT(slotPreviousPage()));
1164
 
 
1165
 
    if(QIcon::hasThemeIcon("go-previous"))
1166
 
    {
1167
 
        m_previousPageAction->setIcon(QIcon::fromTheme("go-previous"));
1168
 
    }
1169
 
    else
1170
 
    {
1171
 
#ifdef DATA_INSTALL_PATH
1172
 
        m_previousPageAction->setIcon(QIcon(QString("%1/go-previous.svg").arg(DATA_INSTALL_PATH)));
1173
 
#else
1174
 
        m_previousPageAction->setIcon(QIcon(":/icons/go-previous.svg"));
1175
 
#endif
1176
 
    }
1177
 
 
1178
 
    // next page
1179
 
 
1180
 
    m_nextPageAction = new QAction(tr("&Next page"), this);
1181
 
    m_nextPageAction->setShortcut(QKeySequence(Qt::Key_Right));
1182
 
    m_nextPageAction->setIconVisibleInMenu(true);
1183
 
    connect(m_nextPageAction, SIGNAL(triggered()), SLOT(slotNextPage()));
1184
 
 
1185
 
    if(QIcon::hasThemeIcon("go-next"))
1186
 
    {
1187
 
        m_nextPageAction->setIcon(QIcon::fromTheme("go-next"));
1188
 
    }
1189
 
    else
1190
 
    {
1191
 
#ifdef DATA_INSTALL_PATH
1192
 
        m_nextPageAction->setIcon(QIcon(QString("%1/go-next.svg").arg(DATA_INSTALL_PATH)));
1193
 
#else
1194
 
        m_nextPageAction->setIcon(QIcon(":/icons/go-next.svg"));
1195
 
#endif
1196
 
    }
1197
 
 
1198
 
    // first page
1199
 
 
1200
 
    m_firstPageAction = new QAction(tr("&First page"), this);
1201
 
    m_firstPageAction->setShortcut(QKeySequence(Qt::Key_Home));
1202
 
    m_firstPageAction->setIconVisibleInMenu(true);
1203
 
    connect(m_firstPageAction, SIGNAL(triggered()), SLOT(slotFirstPage()));
1204
 
 
1205
 
    if(QIcon::hasThemeIcon("go-first"))
1206
 
    {
1207
 
        m_firstPageAction->setIcon(QIcon::fromTheme("go-first"));
1208
 
    }
1209
 
    else
1210
 
    {
1211
 
#ifdef DATA_INSTALL_PATH
1212
 
        m_firstPageAction->setIcon(QIcon(QString("%1/go-first.svg").arg(DATA_INSTALL_PATH)));
1213
 
#else
1214
 
        m_firstPageAction->setIcon(QIcon(":/icons/go-first.svg"));
1215
 
#endif
1216
 
    }
1217
 
 
1218
 
    // last page
1219
 
 
1220
 
    m_lastPageAction = new QAction(tr("&Last page"), this);
1221
 
    m_lastPageAction->setShortcut(QKeySequence(Qt::Key_End));
1222
 
    m_lastPageAction->setIconVisibleInMenu(true);
1223
 
    connect(m_lastPageAction, SIGNAL(triggered()), SLOT(slotLastPage()));
1224
 
 
1225
 
    if(QIcon::hasThemeIcon("go-last"))
1226
 
    {
1227
 
        m_lastPageAction->setIcon(QIcon::fromTheme("go-last"));
1228
 
    }
1229
 
    else
1230
 
    {
1231
 
#ifdef DATA_INSTALL_PATH
1232
 
        m_lastPageAction->setIcon(QIcon(QString("%1/go-last.svg").arg(DATA_INSTALL_PATH)));
1233
 
#else
1234
 
        m_lastPageAction->setIcon(QIcon(":/icons/go-last.svg"));
1235
 
#endif
1236
 
    }
1237
 
 
1238
 
    // jump to page
1239
 
 
1240
 
    m_jumpToPageAction = new QAction(tr("&Jump to page..."), this);
1241
 
    m_jumpToPageAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_J));
1242
 
    m_jumpToPageAction->setIconVisibleInMenu(true);
1243
 
    connect(m_jumpToPageAction, SIGNAL(triggered()), SLOT(slotJumpToPage()));
1244
 
 
1245
 
    if(QIcon::hasThemeIcon("go-jump"))
1246
 
    {
1247
 
        m_jumpToPageAction->setIcon(QIcon::fromTheme("go-jump"));
1248
 
    }
1249
 
    else
1250
 
    {
1251
 
#ifdef DATA_INSTALL_PATH
1252
 
        m_jumpToPageAction->setIcon(QIcon(QString("%1/go-jump.svg").arg(DATA_INSTALL_PATH)));
1253
 
#else
1254
 
        m_jumpToPageAction->setIcon(QIcon(":/icons/go-jump.svg"));
1255
 
#endif
1256
 
    }
1257
 
 
1258
 
    // search
1259
 
 
1260
 
    m_searchAction = new QAction(tr("&Search..."), this);
1261
 
    m_searchAction->setShortcut(QKeySequence::Find);
1262
 
    m_searchAction->setIconVisibleInMenu(true);
1263
 
    connect(m_searchAction, SIGNAL(triggered()), SLOT(slotSearch()));
1264
 
 
1265
 
    if(QIcon::hasThemeIcon("edit-find"))
1266
 
    {
1267
 
        m_searchAction->setIcon(QIcon::fromTheme("edit-find"));
1268
 
    }
1269
 
    else
1270
 
    {
1271
 
#ifdef DATA_INSTALL_PATH
1272
 
        m_searchAction->setIcon(QIcon(QString("%1/edit-find.svg").arg(DATA_INSTALL_PATH)));
1273
 
#else
1274
 
        m_searchAction->setIcon(QIcon(":/icons/edit-find.svg"));
1275
 
#endif
1276
 
    }
1277
 
 
1278
 
    // find previous
1279
 
 
1280
 
    m_findPreviousAction = new QAction(tr("Find previous"), this);
1281
 
    m_findPreviousAction->setShortcut(QKeySequence::FindPrevious);
1282
 
    m_findPreviousAction->setIconVisibleInMenu(true);
1283
 
    connect(m_findPreviousAction, SIGNAL(triggered()), SLOT(slotFindPrevious()));
1284
 
 
1285
 
    if(QIcon::hasThemeIcon("go-up"))
1286
 
    {
1287
 
        m_findPreviousAction->setIcon(QIcon::fromTheme("go-up"));
1288
 
    }
1289
 
    else
1290
 
    {
1291
 
#ifdef DATA_INSTALL_PATH
1292
 
        m_findPreviousAction->setIcon(QIcon(QString("%1/go-up.svg").arg(DATA_INSTALL_PATH)));
1293
 
#else
1294
 
        m_findPreviousAction->setIcon(QIcon(":/icons/go-up.svg"));
1295
 
#endif
1296
 
    }
1297
 
 
1298
 
    // find next
1299
 
 
1300
 
    m_findNextAction = new QAction(tr("Find next"), this);
1301
 
    m_findNextAction->setShortcut(QKeySequence::FindNext);
1302
 
    m_findNextAction->setIconVisibleInMenu(true);
1303
 
    connect(m_findNextAction, SIGNAL(triggered()), SLOT(slotFindNext()));
1304
 
 
1305
 
    if(QIcon::hasThemeIcon("go-down"))
1306
 
    {
1307
 
        m_findNextAction->setIcon(QIcon::fromTheme("go-down"));
1308
 
    }
1309
 
    else
1310
 
    {
1311
 
#ifdef DATA_INSTALL_PATH
1312
 
        m_findNextAction->setIcon(QIcon(QString("%1/go-down.svg").arg(DATA_INSTALL_PATH)));
1313
 
#else
1314
 
        m_findNextAction->setIcon(QIcon(":/icons/go-down.svg"));
1315
 
#endif
1316
 
    }
1317
 
 
1318
 
    // cancel search
1319
 
 
1320
 
    m_cancelSearchAction = new QAction(tr("Cancel search"), this);
1321
 
    m_cancelSearchAction->setShortcut(QKeySequence(Qt::Key_Escape));
1322
 
    m_cancelSearchAction->setIconVisibleInMenu(true);
1323
 
    connect(m_cancelSearchAction, SIGNAL(triggered()), SLOT(slotCancelSearch()));
1324
 
 
1325
 
    if(QIcon::hasThemeIcon("process-stop"))
1326
 
    {
1327
 
        m_cancelSearchAction->setIcon(QIcon::fromTheme("process-stop"));
1328
 
    }
1329
 
    else
1330
 
    {
1331
 
#ifdef DATA_INSTALL_PATH
1332
 
        m_cancelSearchAction->setIcon(QIcon(QString("%1/process-stop.svg").arg(DATA_INSTALL_PATH)));
1333
 
#else
1334
 
        m_cancelSearchAction->setIcon(QIcon(":/icons/process-stop.svg"));
1335
 
#endif
1336
 
    }
1337
 
 
1338
 
    // settings
1339
 
 
1340
 
    m_settingsAction = new QAction(tr("Settings..."), this);
1341
 
    m_settingsAction->setIcon(QIcon::fromTheme("preferences-other"));
1342
 
    m_settingsAction->setIconVisibleInMenu(true);
1343
 
    connect(m_settingsAction, SIGNAL(triggered()), SLOT(slotSettings()));
1344
 
 
1345
 
    // page layout
1346
 
 
1347
 
    m_onePageAction = new QAction(tr("One page"), this);
1348
 
    m_onePageAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_1));
1349
 
    m_onePageAction->setCheckable(true);
1350
 
    m_onePageAction->setData(static_cast< uint >(DocumentView::OnePage));
1351
 
    m_twoPagesAction = new QAction(tr("Two pages"), this);
1352
 
    m_twoPagesAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_2));
1353
 
    m_twoPagesAction->setCheckable(true);
1354
 
    m_twoPagesAction->setData(static_cast< uint >(DocumentView::TwoPages));
1355
 
    m_oneColumnAction = new QAction(tr("One column"), this);
1356
 
    m_oneColumnAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_3));
1357
 
    m_oneColumnAction->setCheckable(true);
1358
 
    m_oneColumnAction->setData(static_cast< uint >(DocumentView::OneColumn));
1359
 
    m_twoColumnsAction = new QAction(tr("Two columns"), this);
1360
 
    m_twoColumnsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_4));
1361
 
    m_twoColumnsAction->setCheckable(true);
1362
 
    m_twoColumnsAction->setData(static_cast< uint >(DocumentView::TwoColumns));
1363
 
 
1364
 
    m_pageLayoutGroup = new QActionGroup(this);
1365
 
    m_pageLayoutGroup->addAction(m_onePageAction);
1366
 
    m_pageLayoutGroup->addAction(m_twoPagesAction);
1367
 
    m_pageLayoutGroup->addAction(m_oneColumnAction);
1368
 
    m_pageLayoutGroup->addAction(m_twoColumnsAction);
1369
 
    connect(m_pageLayoutGroup, SIGNAL(selected(QAction*)), SLOT(slotPageLayoutGroupTriggered(QAction*)));
1370
 
 
1371
 
#ifdef DATA_INSTALL_PATH
1372
 
    m_onePageAction->setIcon(QIcon(QString("%1/one-page.svg").arg(DATA_INSTALL_PATH)));
1373
 
    m_twoPagesAction->setIcon(QIcon(QString("%1/two-pages.svg").arg(DATA_INSTALL_PATH)));
1374
 
    m_oneColumnAction->setIcon(QIcon(QString("%1/one-column.svg").arg(DATA_INSTALL_PATH)));
1375
 
    m_twoColumnsAction->setIcon(QIcon(QString("%1/two-columns.svg").arg(DATA_INSTALL_PATH)));
1376
 
#else
1377
 
    m_onePageAction->setIcon(QIcon(":/icons/one-page.svg"));
1378
 
    m_twoPagesAction->setIcon(QIcon(":/icons/two-pages.svg"));
1379
 
    m_oneColumnAction->setIcon(QIcon(":/icons/one-column.svg"));
1380
 
    m_twoColumnsAction->setIcon(QIcon(":/icons/two-columns.svg"));
1381
 
#endif
1382
 
 
1383
 
    // scale mode
1384
 
 
1385
 
    m_fitToPageAction = new QAction(tr("Fit to page"), this);
1386
 
    m_fitToPageAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_8));
1387
 
    m_fitToPageAction->setCheckable(true);
1388
 
    m_fitToPageAction->setData(static_cast< uint >(DocumentView::FitToPage));
1389
 
    m_fitToPageWidthAction = new QAction(tr("Fit to page width"), this);
1390
 
    m_fitToPageWidthAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_9));
1391
 
    m_fitToPageWidthAction->setCheckable(true);
1392
 
    m_fitToPageWidthAction->setData(static_cast< uint >(DocumentView::FitToPageWidth));
1393
 
    m_doNotScaleAction = new QAction(tr("Do not scale"), this);
1394
 
    m_doNotScaleAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0));
1395
 
    m_doNotScaleAction->setCheckable(true);
1396
 
    m_doNotScaleAction->setData(static_cast< uint >(DocumentView::DoNotScale));
1397
 
 
1398
 
    m_scaleModeGroup = new QActionGroup(this);
1399
 
    m_scaleModeGroup->addAction(m_fitToPageAction);
1400
 
    m_scaleModeGroup->addAction(m_fitToPageWidthAction);
1401
 
    m_scaleModeGroup->addAction(m_doNotScaleAction);
1402
 
    connect(m_scaleModeGroup, SIGNAL(selected(QAction*)), SLOT(slotScaleModeGroupTriggered(QAction*)));
1403
 
 
1404
 
#ifdef DATA_INSTALL_PATH
1405
 
    m_fitToPageAction->setIcon(QIcon(QString("%1/fit-to-page.svg").arg(DATA_INSTALL_PATH)));
1406
 
    m_fitToPageWidthAction->setIcon(QIcon(QString("%1/fit-to-page-width.svg").arg(DATA_INSTALL_PATH)));
1407
 
    m_doNotScaleAction->setIcon(QIcon(QString("%1/do-not-scale.svg").arg(DATA_INSTALL_PATH)));
1408
 
#else
1409
 
    m_fitToPageAction->setIcon(QIcon(":/icons/fit-to-page.svg"));
1410
 
    m_fitToPageWidthAction->setIcon(QIcon(":/icons/fit-to-page-width.svg"));
1411
 
    m_doNotScaleAction->setIcon(QIcon(":/icons/do-not-scale.svg"));
1412
 
#endif
1413
 
 
1414
 
    // zoom
1415
 
 
1416
 
    m_zoomInAction = new QAction(tr("Zoom &in"), this);
1417
 
    m_zoomInAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Up));
1418
 
    m_zoomInAction->setIconVisibleInMenu(true);
1419
 
    connect(m_zoomInAction, SIGNAL(triggered()), SLOT(slotZoomIn()));
1420
 
 
1421
 
    if(QIcon::hasThemeIcon("zoom-in"))
1422
 
    {
1423
 
        m_zoomInAction->setIcon(QIcon::fromTheme("zoom-in"));
1424
 
    }
1425
 
    else
1426
 
    {
1427
 
#ifdef DATA_INSTALL_PATH
1428
 
        m_zoomInAction->setIcon(QIcon(QString("%1/zoom-in.svg").arg(DATA_INSTALL_PATH)));
1429
 
#else
1430
 
        m_zoomInAction->setIcon(QIcon(":/icons/zoom-in.svg"));
1431
 
#endif
1432
 
    }
1433
 
 
1434
 
    m_zoomOutAction = new QAction(tr("Zoom &out"), this);
1435
 
    m_zoomOutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Down));
1436
 
    m_zoomOutAction->setIconVisibleInMenu(true);
1437
 
    connect(m_zoomOutAction, SIGNAL(triggered()), SLOT(slotZoomOut()));
1438
 
 
1439
 
    if(QIcon::hasThemeIcon("zoom-out"))
1440
 
    {
1441
 
        m_zoomOutAction->setIcon(QIcon::fromTheme("zoom-out"));
1442
 
    }
1443
 
    else
1444
 
    {
1445
 
#ifdef DATA_INSTALL_PATH
1446
 
        m_zoomOutAction->setIcon(QIcon(QString("%1/zoom-out.svg").arg(DATA_INSTALL_PATH)));
1447
 
#else
1448
 
        m_zoomOutAction->setIcon(QIcon(":/icons/zoom-out.svg"));
1449
 
#endif
1450
 
    }
1451
 
 
1452
 
    // rotate
1453
 
 
1454
 
    m_rotateLeftAction = new QAction(tr("Rotate &left"), this);
1455
 
    m_rotateLeftAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left));
1456
 
    m_rotateLeftAction->setIconVisibleInMenu(true);
1457
 
    connect(m_rotateLeftAction, SIGNAL(triggered()), SLOT(slotRotateLeft()));
1458
 
 
1459
 
    if(QIcon::hasThemeIcon("object-rotate-left"))
1460
 
    {
1461
 
        m_rotateLeftAction->setIcon(QIcon::fromTheme("object-rotate-left"));
1462
 
    }
1463
 
    else
1464
 
    {
1465
 
#ifdef DATA_INSTALL_PATH
1466
 
        m_rotateLeftAction->setIcon(QIcon(QString("%1/object-rotate-left.svg").arg(DATA_INSTALL_PATH)));
1467
 
#else
1468
 
        m_rotateLeftAction->setIcon(QIcon(":/icons/object-rotate-left.svg"));
1469
 
#endif
1470
 
    }
1471
 
 
1472
 
    m_rotateRightAction = new QAction(tr("Rotate &right"), this);
1473
 
    m_rotateRightAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right));
1474
 
    m_rotateRightAction->setIconVisibleInMenu(true);
1475
 
    connect(m_rotateRightAction, SIGNAL(triggered()), SLOT(slotRotateRight()));
1476
 
 
1477
 
    if(QIcon::hasThemeIcon("object-rotate-right"))
1478
 
    {
1479
 
        m_rotateRightAction->setIcon(QIcon::fromTheme("object-rotate-right"));
1480
 
    }
1481
 
    else
1482
 
    {
1483
 
#ifdef DATA_INSTALL_PATH
1484
 
        m_rotateRightAction->setIcon(QIcon(QString("%1/object-rotate-right.svg").arg(DATA_INSTALL_PATH)));
1485
 
#else
1486
 
        m_rotateRightAction->setIcon(QIcon(":/icons/object-rotate-right.svg"));
1487
 
#endif
1488
 
    }
1489
 
 
1490
 
    // fonts
1491
 
 
1492
 
    m_fontsAction = new QAction(tr("Fonts..."), this);
1493
 
    connect(m_fontsAction, SIGNAL(triggered()), SLOT(slotFonts()));
1494
 
 
1495
 
    // fullscreen
1496
 
 
1497
 
    m_fullscreenAction = new QAction(tr("&Fullscreen"), this);
1498
 
    m_fullscreenAction->setCheckable(true);
1499
 
    m_fullscreenAction->setShortcut(QKeySequence(Qt::Key_F11));
1500
 
    m_fullscreenAction->setIconVisibleInMenu(true);
1501
 
    connect(m_fullscreenAction, SIGNAL(triggered()), SLOT(slotFullscreen()));
1502
 
 
1503
 
    if(QIcon::hasThemeIcon("view-fullscreen"))
1504
 
    {
1505
 
        m_fullscreenAction->setIcon(QIcon::fromTheme("view-fullscreen"));
1506
 
    }
1507
 
    else
1508
 
    {
1509
 
#ifdef DATA_INSTALL_PATH
1510
 
        m_fullscreenAction->setIcon(QIcon(QString("%1/view-fullscreen.svg").arg(DATA_INSTALL_PATH)));
1511
 
#else
1512
 
        m_fullscreenAction->setIcon(QIcon(":/icons/view-fullscreen.svg"));
1513
 
#endif
1514
 
    }
1515
 
 
1516
 
    // presentation
1517
 
 
1518
 
    m_presentationAction = new QAction(tr("&Presentation..."), this);
1519
 
    m_presentationAction->setShortcut(QKeySequence(Qt::Key_F12));
1520
 
    m_presentationAction->setIconVisibleInMenu(true);
1521
 
    connect(m_presentationAction, SIGNAL(triggered()), SLOT(slotPresentation()));
1522
 
 
1523
 
    if(QIcon::hasThemeIcon("x-office-presentation"))
1524
 
    {
1525
 
        m_presentationAction->setIcon(QIcon::fromTheme("x-office-presentation"));
1526
 
    }
1527
 
    else
1528
 
    {
1529
 
#ifdef DATA_INSTALL_PATH
1530
 
        m_fullscreenAction->setIcon(QIcon(QString("%1/x-office-presentation.svg").arg(DATA_INSTALL_PATH)));
1531
 
#else
1532
 
        m_fullscreenAction->setIcon(QIcon(":/icons/x-office-presentation.svg"));
1533
 
#endif
1534
 
    }
1535
 
 
1536
 
    // previous tab
1537
 
 
1538
 
    m_previousTabAction = new QAction(tr("&Previous tab"), this);
1539
 
    m_previousTabAction->setShortcut(QKeySequence::PreviousChild);
1540
 
    connect(m_previousTabAction, SIGNAL(triggered()), SLOT(slotPreviousTab()));
1541
 
 
1542
 
    // next tab
1543
 
 
1544
 
    m_nextTabAction = new QAction(tr("&Next tab"), this);
1545
 
    m_nextTabAction->setShortcut(QKeySequence::NextChild);
1546
 
    connect(m_nextTabAction, SIGNAL(triggered()), SLOT(slotNextTab()));
1547
 
 
1548
 
    // close tab
1549
 
 
1550
 
    m_closeTabAction = new QAction(tr("&Close tab"), this);
1551
 
    m_closeTabAction->setShortcut(QKeySequence::Close);
1552
 
    m_closeTabAction->setIcon(QIcon::fromTheme("window-close"));
1553
 
    m_closeTabAction->setIconVisibleInMenu(true);
1554
 
    connect(m_closeTabAction, SIGNAL(triggered()), SLOT(slotCloseTab()));
1555
 
 
1556
 
    // close all tabs
1557
 
 
1558
 
    m_closeAllTabsAction = new QAction(tr("Close all &tabs"), this);
1559
 
    m_closeAllTabsAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_W));
1560
 
    connect(m_closeAllTabsAction, SIGNAL(triggered()), SLOT(slotCloseAllTabs()));
1561
 
 
1562
 
    // close all tabs but current tab
1563
 
 
1564
 
    m_closeAllTabsButCurrentTabAction = new QAction(tr("Close all tabs &but current tab"), this);
1565
 
    m_closeAllTabsButCurrentTabAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_W));
1566
 
    connect(m_closeAllTabsButCurrentTabAction, SIGNAL(triggered()), SLOT(slotCloseAllTabsButCurrentTab()));
1567
 
 
1568
 
    // contents
1569
 
 
1570
 
    m_contentsAction = new QAction(tr("&Contents"), this);
1571
 
    m_contentsAction->setShortcut(QKeySequence::HelpContents);
1572
 
    m_contentsAction->setIcon(QIcon::fromTheme("help-contents"));
1573
 
    m_contentsAction->setIconVisibleInMenu(true);
1574
 
    connect(m_contentsAction, SIGNAL(triggered()), SLOT(slotContents()));
1575
 
 
1576
 
    // about
1577
 
 
1578
 
    m_aboutAction = new QAction(tr("&About"), this);
1579
 
    m_aboutAction->setIcon(QIcon::fromTheme("help-about"));
1580
 
    m_aboutAction->setIconVisibleInMenu(true);
1581
 
    connect(m_aboutAction, SIGNAL(triggered()), SLOT(slotAbout()));
1582
 
}
1583
 
 
1584
 
void MainWindow::createWidgets()
1585
 
{
1586
 
    // tab
1587
 
 
1588
 
    m_tabWidget = new TabWidget(this);
1589
 
 
1590
 
    m_tabWidget->setTabsClosable(true);
1591
 
    m_tabWidget->setMovable(true);
1592
 
    m_tabWidget->setDocumentMode(true);
1593
 
    m_tabWidget->setElideMode(Qt::ElideRight);
1594
 
 
1595
 
    setCentralWidget(m_tabWidget);
1596
 
 
1597
 
    connect(m_tabWidget, SIGNAL(currentChanged(int)), SLOT(slotTabWidgetCurrentChanged(int)));
1598
 
    connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), SLOT(slotTabWidgetTabCloseRequested(int)));
1599
 
 
1600
 
    // current page
1601
 
 
1602
 
    m_currentPageLineEdit = new LineEdit(this);
1603
 
    m_currentPageValidator = new QIntValidator(m_currentPageLineEdit);
1604
 
 
1605
 
    m_currentPageLineEdit->setValidator(m_currentPageValidator);
1606
 
    m_currentPageLineEdit->setAlignment(Qt::AlignCenter);
1607
 
    m_currentPageLineEdit->setFixedWidth(40);
1608
 
 
1609
 
    connect(m_currentPageLineEdit, SIGNAL(editingFinished()), SLOT(slotCurrentPageLineEditEditingFinished()));
1610
 
    connect(m_currentPageLineEdit, SIGNAL(returnPressed()), SLOT(slotCurrentPageLineEditReturnPressed()));
1611
 
 
1612
 
    // number of pages
1613
 
 
1614
 
    m_numberOfPagesLabel = new QLabel(this);
1615
 
 
1616
 
    m_numberOfPagesLabel->setAlignment(Qt::AlignCenter);
1617
 
    m_numberOfPagesLabel->setFixedWidth(60);
1618
 
 
1619
 
    // scale factor
1620
 
 
1621
 
    m_scaleFactorComboBox = new ComboBox(this);
1622
 
 
1623
 
    m_scaleFactorComboBox->setEditable(true);
1624
 
    m_scaleFactorComboBox->setInsertPolicy(QComboBox::NoInsert);
1625
 
 
1626
 
    m_scaleFactorComboBox->addItem(tr("Fit to page"), static_cast< uint >(DocumentView::FitToPage));
1627
 
    m_scaleFactorComboBox->addItem(tr("Fit to page width"), static_cast< uint >(DocumentView::FitToPageWidth));
1628
 
    m_scaleFactorComboBox->addItem(tr("Do not scale"), static_cast< uint >(DocumentView::DoNotScale));
1629
 
    m_scaleFactorComboBox->addItem(QString(), static_cast< uint >(DocumentView::ScaleFactor));
1630
 
 
1631
 
    connect(m_scaleFactorComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotScaleFactorComboBoxCurrentIndexChanged(int)));
1632
 
    connect(m_scaleFactorComboBox->lineEdit(), SIGNAL(editingFinished()), SLOT(slotScaleFactorComboBoxEditingFinished()));
1633
 
    connect(m_scaleFactorComboBox->lineEdit(), SIGNAL(returnPressed()), SLOT(slotScaleFactorComboBoxReturnPressed()));
1634
 
 
1635
 
    // search
1636
 
 
1637
 
    m_searchWidget = new QWidget(this);
1638
 
    m_searchLineEdit = new QLineEdit(m_searchWidget);
1639
 
    m_searchTimer = new QTimer(this);
1640
 
    m_matchCaseCheckBox = new QCheckBox(tr("Match &case"), m_searchWidget);
1641
 
    m_highlightAllCheckBox = new QCheckBox(tr("Highlight &all"), m_searchWidget);
1642
 
    m_searchTimer->setInterval(2000);
1643
 
    m_searchTimer->setSingleShot(true);
1644
 
 
1645
 
    m_searchWidget->setLayout(new QHBoxLayout());
1646
 
    m_searchWidget->layout()->setContentsMargins(5, 0, 5, 0);
1647
 
    m_searchWidget->layout()->addWidget(m_searchLineEdit);
1648
 
    m_searchWidget->layout()->addWidget(m_matchCaseCheckBox);
1649
 
    m_searchWidget->layout()->addWidget(m_highlightAllCheckBox);
1650
 
 
1651
 
    connect(m_searchLineEdit, SIGNAL(textEdited(QString)), m_searchTimer, SLOT(start()));
1652
 
    connect(m_searchLineEdit, SIGNAL(returnPressed()), this, SLOT(slotStartSearch()));
1653
 
    connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(slotStartSearch()));
1654
 
 
1655
 
    connect(m_highlightAllCheckBox, SIGNAL(clicked(bool)), SLOT(slotHighlightAllCheckBoxClicked(bool)));
1656
 
}
1657
 
 
1658
 
void MainWindow::createToolBars()
1659
 
{
1660
 
    // file
1661
 
 
1662
 
    m_fileToolBar = new QToolBar(tr("&File"));
1663
 
    m_fileToolBar->setObjectName("fileToolBar");
1664
 
 
1665
 
    QStringList fileToolBar = QStringList() << "openInNewTab" << "refresh";
1666
 
    fileToolBar = m_settings.value("mainWindow/fileToolBar", fileToolBar).toStringList();
1667
 
 
1668
 
    foreach(QString entry, fileToolBar)
1669
 
    {
1670
 
        if(entry == "open") { m_fileToolBar->addAction(m_openAction); }
1671
 
        else if(entry == "openInNewTab") { m_fileToolBar->addAction(m_openInNewTabAction); }
1672
 
        else if(entry == "refresh") { m_fileToolBar->addAction(m_refreshAction); }
1673
 
        else if(entry == "saveCopy") { m_fileToolBar->addAction(m_saveCopyAction); }
1674
 
        else if(entry == "print") { m_fileToolBar->addAction(m_printAction); }
1675
 
    }
1676
 
 
1677
 
    addToolBar(Qt::TopToolBarArea, m_fileToolBar);
1678
 
 
1679
 
    // edit
1680
 
 
1681
 
    m_editToolBar = new QToolBar(tr("&Edit"));
1682
 
    m_editToolBar->setObjectName("editToolBar");
1683
 
 
1684
 
    QStringList editToolBar = QStringList() << "currentPage" << "numberOfPages" << "previousPage" << "nextPage";
1685
 
    editToolBar = m_settings.value("mainWindow/editToolBar", editToolBar).toStringList();
1686
 
 
1687
 
    foreach(QString entry, editToolBar)
1688
 
    {
1689
 
        if(entry == "currentPage") { m_editToolBar->addWidget(m_currentPageLineEdit); }
1690
 
        else if(entry == "numberOfPages") { m_editToolBar->addWidget(m_numberOfPagesLabel); }
1691
 
        else if(entry == "previousPage") { m_editToolBar->addAction(m_previousPageAction); }
1692
 
        else if(entry == "nextPage") { m_editToolBar->addAction(m_nextPageAction); }
1693
 
        else if(entry == "firstPage") { m_editToolBar->addAction(m_firstPageAction); }
1694
 
        else if(entry == "lastPage") { m_editToolBar->addAction(m_lastPageAction); }
1695
 
        else if(entry == "jumpToPage") { m_editToolBar->addAction(m_jumpToPageAction); }
1696
 
        else if(entry == "search") { m_editToolBar->addAction(m_searchAction); }
1697
 
    }
1698
 
 
1699
 
    addToolBar(Qt::TopToolBarArea, m_editToolBar);
1700
 
 
1701
 
    // view
1702
 
 
1703
 
    m_viewToolBar = new QToolBar(tr("&View"));
1704
 
    m_viewToolBar->setObjectName("viewToolBar");
1705
 
 
1706
 
    m_viewToolBar->setHidden(true);
1707
 
 
1708
 
    QStringList viewToolBar = QStringList() << "scaleFactor" << "zoomIn" << "zoomOut";
1709
 
    viewToolBar = m_settings.value("mainWindow/viewToolBar", viewToolBar).toStringList();
1710
 
 
1711
 
    foreach(QString entry, viewToolBar)
1712
 
    {
1713
 
        if(entry == "scaleFactor") { m_viewToolBar->addWidget(m_scaleFactorComboBox); }
1714
 
        else if(entry == "onePage") { m_viewToolBar->addAction(m_onePageAction); }
1715
 
        else if(entry == "twoPages") { m_viewToolBar->addAction(m_twoPagesAction); }
1716
 
        else if(entry == "oneColumn") { m_viewToolBar->addAction(m_oneColumnAction); }
1717
 
        else if(entry == "twoColumns") { m_viewToolBar->addAction(m_twoColumnsAction); }
1718
 
        else if(entry == "fitToPage") { m_viewToolBar->addAction(m_fitToPageAction); }
1719
 
        else if(entry == "fitToPageWidth") { m_viewToolBar->addAction(m_fitToPageWidthAction); }
1720
 
        else if(entry == "doNotScale") { m_viewToolBar->addAction(m_doNotScaleAction); }
1721
 
        else if(entry == "zoomIn") { m_viewToolBar->addAction(m_zoomInAction); }
1722
 
        else if(entry == "zoomOut") { m_viewToolBar->addAction(m_zoomOutAction); }
1723
 
        else if(entry == "rotateLeft") { m_viewToolBar->addAction(m_rotateLeftAction); }
1724
 
        else if(entry == "rotateRight") { m_viewToolBar->addAction(m_rotateRightAction); }
1725
 
        else if(entry == "fullscreen") { m_viewToolBar->addAction(m_fullscreenAction); }
1726
 
        else if(entry == "presentation") { m_viewToolBar->addAction(m_presentationAction); }
1727
 
    }
1728
 
 
1729
 
    addToolBar(Qt::TopToolBarArea, m_viewToolBar);
1730
 
 
1731
 
    // search
1732
 
 
1733
 
    m_searchToolBar = new QToolBar(tr("&Search"));
1734
 
    m_searchToolBar->setObjectName("searchToolBar");
1735
 
 
1736
 
    m_searchToolBar->setHidden(true);
1737
 
    m_searchToolBar->setMovable(false);
1738
 
 
1739
 
    m_searchToolBar->addWidget(m_searchWidget);
1740
 
    m_searchToolBar->addAction(m_findPreviousAction);
1741
 
    m_searchToolBar->addAction(m_findNextAction);
1742
 
    m_searchToolBar->addAction(m_cancelSearchAction);
1743
 
 
1744
 
    addToolBar(Qt::BottomToolBarArea, m_searchToolBar);
1745
 
}
1746
 
 
1747
 
void MainWindow::createDocks()
1748
 
{
1749
 
    // outline
1750
 
 
1751
 
    m_outlineDock = new QDockWidget(tr("&Outline"), this);
1752
 
    m_outlineDock->setObjectName("outlineDock");
1753
 
    m_outlineDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1754
 
    m_outlineDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1755
 
 
1756
 
    addDockWidget(Qt::LeftDockWidgetArea, m_outlineDock);
1757
 
    m_outlineDock->hide();
1758
 
 
1759
 
    m_outlineDock->toggleViewAction()->setShortcut(QKeySequence(Qt::Key_F6));
1760
 
 
1761
 
    // meta-information
1762
 
 
1763
 
    m_metaInformationDock = new QDockWidget(tr("&Meta-information"), this);
1764
 
    m_metaInformationDock->setObjectName("metaInformationDock");
1765
 
    m_metaInformationDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1766
 
    m_metaInformationDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1767
 
 
1768
 
    addDockWidget(Qt::LeftDockWidgetArea, m_metaInformationDock);
1769
 
    m_metaInformationDock->hide();
1770
 
 
1771
 
    m_metaInformationDock->toggleViewAction()->setShortcut(QKeySequence(Qt::Key_F7));
1772
 
 
1773
 
    // thumbnails
1774
 
 
1775
 
    m_thumbnailsDock = new QDockWidget(tr("&Thumbnails"), this);
1776
 
    m_thumbnailsDock->setObjectName("thumbnailsDock");
1777
 
    m_thumbnailsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1778
 
    m_thumbnailsDock->setFeatures(QDockWidget::AllDockWidgetFeatures);
1779
 
 
1780
 
    addDockWidget(Qt::RightDockWidgetArea, m_thumbnailsDock);
1781
 
    m_thumbnailsDock->hide();
1782
 
 
1783
 
    m_thumbnailsDock->toggleViewAction()->setShortcut(QKeySequence(Qt::Key_F8));
1784
 
}
1785
 
 
1786
 
void MainWindow::createMenus()
1787
 
{
1788
 
    // file
1789
 
 
1790
 
    m_fileMenu = menuBar()->addMenu(tr("&File"));
1791
 
    m_fileMenu->addAction(m_openAction);
1792
 
    m_fileMenu->addAction(m_openInNewTabAction);
1793
 
    m_fileMenu->addAction(m_recentlyUsedAction);
1794
 
    m_fileMenu->addAction(m_refreshAction);
1795
 
    m_fileMenu->addAction(m_saveCopyAction);
1796
 
    m_fileMenu->addAction(m_printAction);
1797
 
    m_fileMenu->addSeparator();
1798
 
    m_fileMenu->addAction(m_exitAction);
1799
 
 
1800
 
    // edit
1801
 
 
1802
 
    m_editMenu = menuBar()->addMenu(tr("&Edit"));
1803
 
    m_editMenu->addAction(m_previousPageAction);
1804
 
    m_editMenu->addAction(m_nextPageAction);
1805
 
    m_editMenu->addAction(m_firstPageAction);
1806
 
    m_editMenu->addAction(m_lastPageAction);
1807
 
    m_editMenu->addAction(m_jumpToPageAction);
1808
 
    m_editMenu->addSeparator();
1809
 
    m_editMenu->addAction(m_searchAction);
1810
 
    m_editMenu->addAction(m_findPreviousAction);
1811
 
    m_editMenu->addAction(m_findNextAction);
1812
 
    m_editMenu->addAction(m_cancelSearchAction);
1813
 
    m_editMenu->addSeparator();
1814
 
    m_editMenu->addAction(m_settingsAction);
1815
 
 
1816
 
    // view
1817
 
 
1818
 
    m_viewMenu = menuBar()->addMenu(tr("&View"));
1819
 
    m_viewMenu->addAction(m_onePageAction);
1820
 
    m_viewMenu->addAction(m_twoPagesAction);
1821
 
    m_viewMenu->addAction(m_oneColumnAction);
1822
 
    m_viewMenu->addAction(m_twoColumnsAction);
1823
 
    m_viewMenu->addSeparator();
1824
 
    m_viewMenu->addAction(m_fitToPageAction);
1825
 
    m_viewMenu->addAction(m_fitToPageWidthAction);
1826
 
    m_viewMenu->addAction(m_doNotScaleAction);
1827
 
    m_viewMenu->addAction(m_zoomInAction);
1828
 
    m_viewMenu->addAction(m_zoomOutAction);
1829
 
    m_viewMenu->addSeparator();
1830
 
    m_viewMenu->addAction(m_rotateLeftAction);
1831
 
    m_viewMenu->addAction(m_rotateRightAction);
1832
 
    m_viewMenu->addSeparator();
1833
 
 
1834
 
    // toolbars
1835
 
 
1836
 
    QMenu* toolbarsMenu = m_viewMenu->addMenu(tr("&Toolbars"));
1837
 
    toolbarsMenu->addAction(m_fileToolBar->toggleViewAction());
1838
 
    toolbarsMenu->addAction(m_editToolBar->toggleViewAction());
1839
 
    toolbarsMenu->addAction(m_viewToolBar->toggleViewAction());
1840
 
 
1841
 
    // docks
1842
 
 
1843
 
    QMenu* docksMenu = m_viewMenu->addMenu(tr("&Docks"));
1844
 
    docksMenu->addAction(m_outlineDock->toggleViewAction());
1845
 
    docksMenu->addAction(m_metaInformationDock->toggleViewAction());
1846
 
    docksMenu->addAction(m_thumbnailsDock->toggleViewAction());
1847
 
 
1848
 
    m_viewMenu->addAction(m_fontsAction);
1849
 
 
1850
 
    m_viewMenu->addAction(m_fullscreenAction);
1851
 
    m_viewMenu->addAction(m_presentationAction);
1852
 
 
1853
 
    // tab
1854
 
 
1855
 
    m_tabMenu = menuBar()->addMenu(tr("&Tab"));
1856
 
    m_tabMenu->addAction(m_previousTabAction);
1857
 
    m_tabMenu->addAction(m_nextTabAction);
1858
 
    m_tabMenu->addSeparator();
1859
 
    m_tabMenu->addAction(m_closeTabAction);
1860
 
    m_tabMenu->addAction(m_closeAllTabsAction);
1861
 
    m_tabMenu->addAction(m_closeAllTabsButCurrentTabAction);
1862
 
    m_tabMenu->addSeparator();
1863
 
 
1864
 
    // help
1865
 
 
1866
 
    m_helpMenu = menuBar()->addMenu(tr("&Help"));
1867
 
    m_helpMenu->addAction(m_contentsAction);
1868
 
    m_helpMenu->addAction(m_aboutAction);
1869
 
}
1870
 
 
1871
 
#ifdef WITH_DBUS
1872
 
 
1873
 
MainWindowAdaptor::MainWindowAdaptor(MainWindow* mainWindow) : QDBusAbstractAdaptor(mainWindow)
1874
 
{
1875
 
}
1876
 
 
1877
 
bool MainWindowAdaptor::open(const QString& filePath, int page, qreal top)
1878
 
{
1879
 
    MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1880
 
 
1881
 
    return mainWindow->open(filePath, page, top);
1882
 
}
1883
 
 
1884
 
bool MainWindowAdaptor::openInNewTab(const QString& filePath, int page, qreal top)
1885
 
{
1886
 
    MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1887
 
 
1888
 
    return mainWindow->openInNewTab(filePath, page, top);
1889
 
}
1890
 
 
1891
 
void MainWindowAdaptor::refresh(const QString& filePath, int page, qreal top)
1892
 
{
1893
 
    MainWindow* mainWindow = qobject_cast< MainWindow* >(parent()); Q_ASSERT(mainWindow);
1894
 
 
1895
 
    bool openInNewTab = true;
1896
 
    QFileInfo fileInfo(filePath);
1897
 
 
1898
 
    for(int index = 0; index < mainWindow->m_tabWidget->count(); index++)
1899
 
    {
1900
 
        DocumentView* documentView = qobject_cast< DocumentView* >(mainWindow->m_tabWidget->widget(index)); Q_ASSERT(documentView);
1901
 
 
1902
 
        if(QFileInfo(documentView->filePath()).absoluteFilePath() == fileInfo.absoluteFilePath())
1903
 
        {
1904
 
            documentView->refresh();
1905
 
            documentView->setCurrentPage(page, top);
1906
 
 
1907
 
            mainWindow->m_tabWidget->setCurrentIndex(index);
1908
 
 
1909
 
            openInNewTab = false;
1910
 
        }
1911
 
    }
1912
 
 
1913
 
    if(openInNewTab)
1914
 
    {
1915
 
        mainWindow->openInNewTab(filePath, page, top);
1916
 
    }
1917
 
}
1918
 
 
1919
 
#endif // WITH_DBUS