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

source code of poppler/qt6/demos/navigationtoolbar.cpp