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

« back to all changes in this revision

Viewing changes to sources/mainwindow.cpp

  • Committer: Package Import Robot
  • Author(s): Benjamin Eltzner
  • Date: 2012-06-01 19:23:41 UTC
  • Revision ID: package-import@ubuntu.com-20120601192341-0a5imt6j7i3g6z8w
Tags: upstream-0.3~beta2
ImportĀ upstreamĀ versionĀ 0.3~beta2

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