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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*
Copyright 2014 S. Razi Alavizadeh
Copyright 2012-2018 Adam Reichold
Copyright 2018 Pavel Sanda
Copyright 2014 Dorian Scholz
This file is part of qpdfview.
qpdfview is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
qpdfview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with qpdfview. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MISCELLANEOUS_H
#define MISCELLANEOUS_H
#include <QComboBox>
#include <QGraphicsEffect>
#include <QLineEdit>
#include <QMenu>
#include <QPainter>
#include <QProxyStyle>
#include <QSpinBox>
#include <QSplitter>
#include <QTreeView>
class QTextLayout;
namespace qpdfview
{
// graphics composition mode effect
class GraphicsCompositionModeEffect : public QGraphicsEffect
{
Q_OBJECT
public:
GraphicsCompositionModeEffect(QPainter::CompositionMode compositionMode, QObject* parent = 0);
protected:
void draw(QPainter* painter);
private:
QPainter::CompositionMode m_compositionMode;
};
// proxy style
class ProxyStyle : public QProxyStyle
{
Q_OBJECT
public:
ProxyStyle();
bool scrollableMenus() const;
void setScrollableMenus(bool scrollableMenus);
int styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const;
private:
Q_DISABLE_COPY(ProxyStyle)
bool m_scrollableMenus;
};
// tool tip menu
class ToolTipMenu : public QMenu
{
Q_OBJECT
public:
explicit ToolTipMenu(QWidget* parent = 0);
ToolTipMenu(const QString& title, QWidget* parent = 0);
protected:
bool event(QEvent* event);
};
// searchable menu
class SearchableMenu : public ToolTipMenu
{
Q_OBJECT
public:
SearchableMenu(const QString& title, QWidget* parent = 0);
bool isSearchable() const;
void setSearchable(bool searchable);
protected:
void hideEvent(QHideEvent* event);
void keyPressEvent(QKeyEvent* event);
private:
bool m_searchable;
QString m_text;
};
// tab bar
class TabBar : public QTabBar
{
Q_OBJECT
public:
explicit TabBar(QWidget* parent = 0);
signals:
void tabDragRequested(int index);
protected:
QSize tabSizeHint(int index) const;
void mousePressEvent(QMouseEvent* event);
void mouseMoveEvent(QMouseEvent* event);
void mouseReleaseEvent(QMouseEvent* event);
private:
Q_DISABLE_COPY(TabBar)
int m_dragIndex;
QPoint m_dragPos;
};
// tab widget
class TabWidget : public QTabWidget
{
Q_OBJECT
public:
explicit TabWidget(QWidget* parent = 0);
bool hasCurrent() const { return currentIndex() != -1; }
QString currentTabText() const { return tabText(currentIndex()); }
void setCurrentTabText(const QString& text) { setTabText(currentIndex(), text); }
QString currentTabToolTip() const { return tabToolTip(currentIndex()); }
void setCurrentTabToolTip(const QString& toolTip) { setTabToolTip(currentIndex(), toolTip); }
int addTab(QWidget* const widget, const bool nextToCurrent,
const QString& label, const QString& toolTip);
enum TabBarPolicy
{
TabBarAsNeeded = 0,
TabBarAlwaysOn = 1,
TabBarAlwaysOff = 2
};
TabBarPolicy tabBarPolicy() const;
void setTabBarPolicy(TabBarPolicy tabBarPolicy);
bool spreadTabs() const;
void setSpreadTabs(bool spreadTabs);
public slots:
void previousTab();
void nextTab();
signals:
void tabDragRequested(int index);
void tabContextMenuRequested(QPoint globalPos, int index);
protected slots:
void on_tabBar_customContextMenuRequested(QPoint pos);
protected:
void tabInserted(int index);
void tabRemoved(int index);
private:
Q_DISABLE_COPY(TabWidget)
TabBarPolicy m_tabBarPolicy;
bool m_spreadTabs;
};
// tree view
class TreeView : public QTreeView
{
Q_OBJECT
public:
explicit TreeView(int expansionRole, QWidget* parent = 0);
public slots:
void expandAbove(const QModelIndex& child);
void expandAll(const QModelIndex& index = QModelIndex());
void collapseAll(const QModelIndex& index = QModelIndex());
int expandedDepth(const QModelIndex& index);
void expandToDepth(const QModelIndex& index, int depth);
void collapseFromDepth(const QModelIndex& index, int depth);
void restoreExpansion(const QModelIndex& index = QModelIndex());
protected:
void keyPressEvent(QKeyEvent* event);
void wheelEvent(QWheelEvent* event);
void contextMenuEvent(QContextMenuEvent* event);
protected slots:
void on_expanded(const QModelIndex& index);
void on_collapsed(const QModelIndex& index);
private:
Q_DISABLE_COPY(TreeView)
int m_expansionRole;
};
// line edit
class LineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit LineEdit(QWidget* parent = 0);
protected:
void mousePressEvent(QMouseEvent* event);
private:
Q_DISABLE_COPY(LineEdit)
};
// combo box
class ComboBox : public QComboBox
{
Q_OBJECT
public:
explicit ComboBox(QWidget* parent = 0);
private:
Q_DISABLE_COPY(ComboBox)
};
// spin box
class SpinBox : public QSpinBox
{
Q_OBJECT
public:
explicit SpinBox(QWidget* parent = 0);
signals:
void returnPressed();
protected:
void keyPressEvent(QKeyEvent* event);
private:
Q_DISABLE_COPY(SpinBox)
};
// mapping spin box
class MappingSpinBox : public SpinBox
{
Q_OBJECT
public:
struct TextValueMapper
{
virtual ~TextValueMapper() {}
virtual QString textFromValue(int val, bool& ok) const = 0;
virtual int valueFromText(const QString& text, bool& ok) const = 0;
};
MappingSpinBox(TextValueMapper* mapper, QWidget* parent = 0);
protected:
QString textFromValue(int val) const;
int valueFromText(const QString& text) const;
QValidator::State validate(QString& input, int& pos) const;
private:
Q_DISABLE_COPY(MappingSpinBox)
QScopedPointer< TextValueMapper > m_mapper;
};
int getMappedNumber(MappingSpinBox::TextValueMapper* mapper,
QWidget* parent, const QString& title, const QString& caption,
int value = 0, int min = -2147483647, int max = 2147483647,
bool* ok = 0, Qt::WindowFlags flags = Qt::WindowFlags());
// progress line edit
class ProgressLineEdit : public QLineEdit
{
Q_OBJECT
public:
explicit ProgressLineEdit(QWidget* parent = 0);
int progress() const;
void setProgress(int progress);
signals:
void returnPressed(Qt::KeyboardModifiers modifiers);
protected:
void paintEvent(QPaintEvent* event);
void keyPressEvent(QKeyEvent* event);
private:
Q_DISABLE_COPY(ProgressLineEdit)
int m_progress;
};
// search line edit
class SearchLineEdit : public ProgressLineEdit
{
Q_OBJECT
public:
explicit SearchLineEdit(QWidget* parent = 0);
public slots:
void startSearch();
void startTimer();
void stopTimer();
signals:
void searchInitiated(const QString& text, bool modified = false);
protected slots:
void on_timeout();
void on_returnPressed(Qt::KeyboardModifiers modifiers);
private:
Q_DISABLE_COPY(SearchLineEdit)
QTimer* m_timer;
};
// splitter
class Splitter : public QSplitter
{
Q_OBJECT
public:
explicit Splitter(Qt::Orientation orientation, QWidget* parent = 0);
QWidget* currentWidget() const;
void setCurrentWidget(QWidget* const currentWidget);
void setUniformSizes();
signals:
void currentWidgetChanged(QWidget* currentWidget);
protected slots:
void on_focusChanged(QWidget* old, QWidget* now);
private:
Q_DISABLE_COPY(Splitter)
int m_currentIndex;
};
// fallback icons
inline QIcon loadIconWithFallback(const QString& name)
{
QIcon icon = QIcon::fromTheme(name);
if(icon.isNull())
{
icon = QIcon(QLatin1String(":icons/") + name);
}
return icon;
}
inline void setVisibleIcon(QAction* action, const QIcon& icon, bool visible = true)
{
action->setIcon(icon);
#ifndef Q_OS_MAC
if(visible)
{
action->setIconVisibleInMenu(true);
}
#endif // Q_OS_MAC
}
// open in new window
void openInNewWindow(const QString& filePath, int page);
} // qpdfview
#endif // MISCELLANEOUS_H
|