~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/qt4/demos/navigationtoolbar.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2008-2009, Pino Toscano <pino@kde.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2, or (at your option)
 
7
 * any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "navigationtoolbar.h"
 
20
 
 
21
#include <poppler-qt4.h>
 
22
 
 
23
#include <QtGui/QAction>
 
24
#include <QtGui/QComboBox>
 
25
 
 
26
NavigationToolBar::NavigationToolBar(QWidget *parent)
 
27
    : QToolBar(parent)
 
28
{
 
29
    m_firstAct = addAction(tr("First"), this, SLOT(slotGoFirst()));
 
30
    m_prevAct = addAction(tr("Previous"), this, SLOT(slotGoPrev()));
 
31
    m_pageCombo = new QComboBox(this);
 
32
    connect(m_pageCombo, SIGNAL(activated(int)), this, SLOT(slotComboActivated(int)));
 
33
    addWidget(m_pageCombo);
 
34
    m_nextAct = addAction(tr("Next"), this, SLOT(slotGoNext()));
 
35
    m_lastAct = addAction(tr("Last"), this, SLOT(slotGoLast()));
 
36
 
 
37
    addSeparator();
 
38
 
 
39
    m_zoomCombo = new QComboBox(this);
 
40
    m_zoomCombo->setEditable(true);
 
41
    m_zoomCombo->addItem(tr("10%"));
 
42
    m_zoomCombo->addItem(tr("25%"));
 
43
    m_zoomCombo->addItem(tr("33%"));
 
44
    m_zoomCombo->addItem(tr("50%"));
 
45
    m_zoomCombo->addItem(tr("66%"));
 
46
    m_zoomCombo->addItem(tr("75%"));
 
47
    m_zoomCombo->addItem(tr("100%"));
 
48
    m_zoomCombo->addItem(tr("125%"));
 
49
    m_zoomCombo->addItem(tr("150%"));
 
50
    m_zoomCombo->addItem(tr("200%"));
 
51
    m_zoomCombo->addItem(tr("300%"));
 
52
    m_zoomCombo->addItem(tr("400%"));
 
53
    m_zoomCombo->setCurrentIndex(6); // "100%"
 
54
    connect(m_zoomCombo, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotZoomComboChanged(QString)));
 
55
    addWidget(m_zoomCombo);
 
56
 
 
57
    documentClosed();
 
58
}
 
59
 
 
60
NavigationToolBar::~NavigationToolBar()
 
61
{
 
62
}
 
63
 
 
64
void NavigationToolBar::documentLoaded()
 
65
{
 
66
    const int pageCount = document()->numPages();
 
67
    for (int i = 0; i < pageCount; ++i) {
 
68
        m_pageCombo->addItem(QString::number(i + 1));
 
69
    }
 
70
    m_pageCombo->setEnabled(true);
 
71
}
 
72
 
 
73
void NavigationToolBar::documentClosed()
 
74
{
 
75
    m_firstAct->setEnabled(false);
 
76
    m_prevAct->setEnabled(false);
 
77
    m_nextAct->setEnabled(false);
 
78
    m_lastAct->setEnabled(false);
 
79
    m_pageCombo->clear();
 
80
    m_pageCombo->setEnabled(false);
 
81
}
 
82
 
 
83
void NavigationToolBar::pageChanged(int page)
 
84
{
 
85
    const int pageCount = document()->numPages();
 
86
    m_firstAct->setEnabled(page > 0);
 
87
    m_prevAct->setEnabled(page > 0);
 
88
    m_nextAct->setEnabled(page < (pageCount - 1));
 
89
    m_lastAct->setEnabled(page < (pageCount - 1));
 
90
    m_pageCombo->setCurrentIndex(page);
 
91
}
 
92
 
 
93
void NavigationToolBar::slotGoFirst()
 
94
{
 
95
    setPage(0);
 
96
}
 
97
 
 
98
void NavigationToolBar::slotGoPrev()
 
99
{
 
100
    setPage(page() - 1);
 
101
}
 
102
 
 
103
void NavigationToolBar::slotGoNext()
 
104
{
 
105
    setPage(page() + 1);
 
106
}
 
107
 
 
108
void NavigationToolBar::slotGoLast()
 
109
{
 
110
    setPage(document()->numPages() - 1);
 
111
}
 
112
 
 
113
void NavigationToolBar::slotComboActivated(int index)
 
114
{
 
115
    setPage(index);
 
116
}
 
117
 
 
118
void NavigationToolBar::slotZoomComboChanged(const QString &_text)
 
119
{
 
120
    QString text = _text;
 
121
    text.remove(QLatin1Char('%'));
 
122
    bool ok = false;
 
123
    int value = text.toInt(&ok);
 
124
    if (ok && value >= 10) {
 
125
        emit zoomChanged(qreal(value) / 100);
 
126
    }
 
127
}
 
128
 
 
129
#include "navigationtoolbar.moc"