forked from KDE/okular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminibar.h
181 lines (143 loc) · 3.99 KB
/
minibar.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
SPDX-FileCopyrightText: 2005 Enrico Ros <[email protected]>
SPDX-FileCopyrightText: 2006 Albert Astals Cid <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef _OKULAR_MINIBAR_H_
#define _OKULAR_MINIBAR_H_
#include "core/observer.h"
#include <KLineEdit>
#include <QSet>
#include <qwidget.h>
namespace Okular
{
class Document;
}
class MiniBar;
class HoverButton;
class QIntValidator;
class QLabel;
class QToolBar;
// [private widget] lineEdit for entering/validating page numbers
class PagesEdit : public KLineEdit
{
Q_OBJECT
public:
explicit PagesEdit(MiniBar *parent);
void setText(const QString &) override;
protected:
void focusInEvent(QFocusEvent *e) override;
void focusOutEvent(QFocusEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
bool event(QEvent *e) override;
private Q_SLOTS:
void updatePalette();
private:
MiniBar *m_miniBar;
bool m_eatClick;
};
class PageNumberEdit : public PagesEdit
{
Q_OBJECT
public:
explicit PageNumberEdit(MiniBar *miniBar);
void setPagesNumber(int pages);
private:
QIntValidator *m_validator;
};
class PageLabelEdit : public PagesEdit
{
Q_OBJECT
public:
explicit PageLabelEdit(MiniBar *parent);
void setText(const QString &newText) override;
void setPageLabels(const QVector<Okular::Page *> &pageVector);
Q_SIGNALS:
void pageNumberChosen(int page);
private Q_SLOTS:
void pageChosen();
private:
QString m_lastLabel;
QMap<QString, int> m_labelPageMap;
};
/**
* @short The object that observes the document and feeds the minibars
*/
class MiniBarLogic : public QObject, public Okular::DocumentObserver
{
Q_OBJECT
public:
MiniBarLogic(QObject *parent, Okular::Document *m_document);
~MiniBarLogic() override;
void addMiniBar(MiniBar *miniBar);
void removeMiniBar(MiniBar *miniBar);
Okular::Document *document() const;
int currentPage() const;
// [INHERITED] from DocumentObserver
void notifySetup(const QVector<Okular::Page *> &pageVector, int setupFlags) override;
void notifyCurrentPageChanged(int previous, int current) override;
private:
QSet<MiniBar *> m_miniBars;
Okular::Document *m_document;
};
/**
* @short A widget to display page number and change current page.
*/
class MiniBar : public QWidget
{
Q_OBJECT
friend class MiniBarLogic;
public:
MiniBar(QWidget *parent, MiniBarLogic *miniBarLogic);
~MiniBar() override;
void changeEvent(QEvent *event) override;
Q_SIGNALS:
void gotoPage();
void prevPage();
void nextPage();
void forwardKeyPressEvent(QKeyEvent *e);
public Q_SLOTS:
void slotChangePageFromReturn();
void slotChangePage(int page);
void slotEmitNextPage();
void slotEmitPrevPage();
void slotToolBarIconSizeChanged();
private:
void resizeForPage(int pages, const QString &pagesOrLabelString);
bool eventFilter(QObject *target, QEvent *event) override;
MiniBarLogic *m_miniBarLogic;
PageNumberEdit *m_pageNumberEdit;
PageLabelEdit *m_pageLabelEdit;
QLabel *m_pageNumberLabel;
HoverButton *m_prevButton;
HoverButton *m_pagesButton;
HoverButton *m_nextButton;
QToolBar *m_oldToolbarParent;
};
/**
* @short A small progress bar.
*/
class ProgressWidget : public QWidget, public Okular::DocumentObserver
{
Q_OBJECT
public:
ProgressWidget(QWidget *parent, Okular::Document *document);
~ProgressWidget() override;
// [INHERITED] from DocumentObserver
void notifyCurrentPageChanged(int previous, int current) override;
void slotGotoNormalizedPage(float index);
Q_SIGNALS:
void prevPage();
void nextPage();
protected:
void setProgress(float percentage);
void mouseMoveEvent(QMouseEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
Okular::Document *m_document;
float m_progressPercentage;
};
#endif