source: terepaima/terepaima-0.4.16/sources/miscellaneous.h

desarrollostretch
Last change on this file was 1f4adec, checked in by aosorio <aosorio@…>, 8 years ago

Agregado proyecto base, esto luego del dh_make -f

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2
3Copyright 2014 S. Razi Alavizadeh
4Copyright 2012-2015 Adam Reichold
5Copyright 2014 Dorian Scholz
6
7This file is part of qpdfview.
8
9qpdfview is free software: you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation, either version 2 of the License, or
12(at your option) any later version.
13
14qpdfview is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
21
22*/
23
24#ifndef MISCELLANEOUS_H
25#define MISCELLANEOUS_H
26
27#include <QComboBox>
28#include <QGraphicsEffect>
29#include <QLineEdit>
30#include <QMenu>
31#include <QPainter>
32#include <QProxyStyle>
33#include <QSpinBox>
34#include <QTreeView>
35
36class QTextLayout;
37
38namespace qpdfview
39{
40
41// graphics composition mode effect
42
43class GraphicsCompositionModeEffect : public QGraphicsEffect
44{
45    Q_OBJECT
46
47public:
48    GraphicsCompositionModeEffect(QPainter::CompositionMode compositionMode, QObject* parent = 0);
49
50protected:
51    void draw(QPainter* painter);
52
53private:
54    QPainter::CompositionMode m_compositionMode;
55
56};
57
58// proxy style
59
60class ProxyStyle : public QProxyStyle
61{
62    Q_OBJECT
63
64public:
65    ProxyStyle();
66
67    bool scrollableMenus() const;
68    void setScrollableMenus(bool scrollableMenus);
69
70    int styleHint(StyleHint hint, const QStyleOption* option, const QWidget* widget, QStyleHintReturn* returnData) const;
71
72private:
73    Q_DISABLE_COPY(ProxyStyle)
74
75    bool m_scrollableMenus;
76
77};
78
79// searchable menu
80
81class SearchableMenu : public QMenu
82{
83    Q_OBJECT
84
85public:
86    SearchableMenu(const QString& title, QWidget* parent = 0);
87
88    bool isSearchable() const;
89    void setSearchable(bool searchable);
90
91protected:
92    void hideEvent(QHideEvent* event);
93    void keyPressEvent(QKeyEvent* event);
94
95private:
96    bool m_searchable;
97    QString m_text;
98
99};
100
101// tab bar
102
103class TabBar : public QTabBar
104{
105    Q_OBJECT
106
107public:
108    explicit TabBar(QWidget* parent = 0);
109
110protected:
111    QSize tabSizeHint(int index) const;
112
113    void mousePressEvent(QMouseEvent* event);
114
115private:
116    Q_DISABLE_COPY(TabBar)
117
118};
119
120// tab widget
121
122class TabWidget : public QTabWidget
123{
124    Q_OBJECT
125
126public:
127    explicit TabWidget(QWidget* parent = 0);
128
129    enum TabBarPolicy
130    {
131        TabBarAsNeeded = 0,
132        TabBarAlwaysOn = 1,
133        TabBarAlwaysOff = 2
134    };
135
136    TabBarPolicy tabBarPolicy() const;
137    void setTabBarPolicy(TabBarPolicy tabBarPolicy);
138
139    bool spreadTabs() const;
140    void setSpreadTabs(bool spreadTabs);
141
142signals:
143    void tabContextMenuRequested(const QPoint& globalPos, int index);
144
145protected slots:
146    void on_tabBar_customContextMenuRequested(const QPoint& pos);
147
148protected:
149    void tabInserted(int index);
150    void tabRemoved(int index);
151
152private:
153    Q_DISABLE_COPY(TabWidget)
154
155    TabBarPolicy m_tabBarPolicy;
156    bool m_spreadTabs;
157
158};
159
160// tree view
161
162class TreeView : public QTreeView
163{
164    Q_OBJECT
165
166public:
167    explicit TreeView(int expansionRole, QWidget* parent = 0);
168
169public slots:
170    void expandAbove(const QModelIndex& child);
171
172    void expandAll(const QModelIndex& index = QModelIndex());
173    void collapseAll(const QModelIndex& index = QModelIndex());
174
175    int expandedDepth(const QModelIndex& index);
176
177    void expandToDepth(const QModelIndex& index, int depth);
178    void collapseFromDepth(const QModelIndex& index, int depth);
179
180    void restoreExpansion(const QModelIndex& index = QModelIndex());
181
182protected:
183    void keyPressEvent(QKeyEvent* event);
184    void wheelEvent(QWheelEvent* event);
185
186    void contextMenuEvent(QContextMenuEvent* event);
187
188protected slots:
189    void on_expanded(const QModelIndex& index);
190    void on_collapsed(const QModelIndex& index);
191
192private:
193    Q_DISABLE_COPY(TreeView)
194
195    int m_expansionRole;
196
197};
198
199// line edit
200
201class LineEdit : public QLineEdit
202{
203    Q_OBJECT
204
205public:
206    explicit LineEdit(QWidget* parent = 0);
207
208protected:
209    void mousePressEvent(QMouseEvent* event);
210
211private:
212    Q_DISABLE_COPY(LineEdit)
213
214};
215
216// combo box
217
218class ComboBox : public QComboBox
219{
220    Q_OBJECT
221
222public:
223    explicit ComboBox(QWidget* parent = 0);
224
225private:
226    Q_DISABLE_COPY(ComboBox)
227
228};
229
230// spin box
231
232class SpinBox : public QSpinBox
233{
234    Q_OBJECT
235
236public:
237    explicit SpinBox(QWidget* parent = 0);
238
239signals:
240    void returnPressed();
241
242protected:
243    void keyPressEvent(QKeyEvent* event);
244
245private:
246    Q_DISABLE_COPY(SpinBox)
247
248};
249
250// mapping spin box
251
252class MappingSpinBox : public SpinBox
253{
254    Q_OBJECT
255
256public:
257    struct TextValueMapper
258    {
259        virtual ~TextValueMapper() {}
260
261        virtual QString textFromValue(int val, bool& ok) const = 0;
262        virtual int valueFromText(const QString& text, bool& ok) const = 0;
263    };
264
265    MappingSpinBox(TextValueMapper* mapper, QWidget* parent = 0);
266
267protected:
268    QString textFromValue(int val) const;
269    int valueFromText(const QString& text) const;
270
271    QValidator::State validate(QString& input, int& pos) const;
272
273private:
274    Q_DISABLE_COPY(MappingSpinBox)
275
276    QScopedPointer< TextValueMapper > m_mapper;
277
278};
279
280int getMappedNumber(MappingSpinBox::TextValueMapper* mapper,
281                    QWidget* parent, const QString& title, const QString& caption,
282                    int value = 0, int min = -2147483647, int max = 2147483647,
283                    bool* ok = 0, Qt::WindowFlags flags = 0);
284
285// progress line edit
286
287class ProgressLineEdit : public QLineEdit
288{
289    Q_OBJECT
290
291public:
292    explicit ProgressLineEdit(QWidget* parent = 0);
293
294    int progress() const;
295    void setProgress(int progress);
296
297signals:
298    void returnPressed(const Qt::KeyboardModifiers& modifiers);
299
300protected:
301    void paintEvent(QPaintEvent* event);
302    void keyPressEvent(QKeyEvent* event);
303
304private:
305    Q_DISABLE_COPY(ProgressLineEdit)
306
307    int m_progress;
308
309};
310
311// search line edit
312
313class SearchLineEdit : public ProgressLineEdit
314{
315    Q_OBJECT
316
317public:
318    explicit SearchLineEdit(QWidget* parent = 0);
319
320public slots:
321    void startSearch();
322
323    void startTimer();
324    void stopTimer();
325
326signals:
327    void searchInitiated(const QString& text, bool modified = false);
328
329protected slots:
330    void on_timeout();
331    void on_returnPressed(const Qt::KeyboardModifiers& modifiers);
332
333private:
334    Q_DISABLE_COPY(SearchLineEdit)
335
336    QTimer* m_timer;
337
338};
339
340// fallback icons
341
342inline QIcon loadIconWithFallback(const QString& name)
343{
344    QIcon icon = QIcon::fromTheme(name);
345
346    if(icon.isNull())
347    {
348        icon = QIcon(QLatin1String(":icons/") + name + QLatin1String(".svg"));
349    }
350
351    return icon;
352}
353
354} // qpdfview
355
356#endif // MISCELLANEOUS_H
Note: See TracBrowser for help on using the repository browser.