summaryrefslogtreecommitdiff
path: root/noncore/unsupported/qpdf/QPEOutputDev.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/qpdf/QPEOutputDev.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/unsupported/qpdf/QPEOutputDev.cpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/noncore/unsupported/qpdf/QPEOutputDev.cpp b/noncore/unsupported/qpdf/QPEOutputDev.cpp
new file mode 100644
index 0000000..8d4e68e
--- a/dev/null
+++ b/noncore/unsupported/qpdf/QPEOutputDev.cpp
@@ -0,0 +1,181 @@
1#include <aconf.h>
2
3#include "QPEOutputDev.h"
4
5#include <qapplication.h>
6#include <qlabel.h>
7#include "qbusybar.h"
8
9
10QPEOutputDev::QPEOutputDev ( QWidget *parent, const char *name ) : QOutputDev ( parent, name )
11{
12 m_counter = new QLabel ( this );
13 m_counter-> setAlignment ( AlignCenter | SingleLine );
14
15 m_busybar = new QBusyBar ( this );
16 m_busybar-> setParameters ( 12, 8, 200 );
17 m_busybar-> hide ( );
18
19 setHScrollBarMode ( AlwaysOn );
20
21 m_isbusy = false;
22
23 m_selectiondrag = false;
24
25 setFocusPolicy ( WheelFocus );
26}
27
28void QPEOutputDev::startPage ( int pn, GfxState *st )
29{
30 m_selection = QRect ( );
31 m_selectiondrag = false;
32
33 QOutputDev::startPage ( pn, st );
34}
35
36
37void QPEOutputDev::setPageCount ( int actp, int maxp )
38{
39 m_counter-> setText ( QString ( "%1 / %2" ). arg ( actp ). arg ( maxp ));
40}
41
42void QPEOutputDev::setBusy ( bool b )
43{
44 if ( b != m_isbusy ) {
45 if ( b ) {
46 m_busybar-> beginBusy ( );
47 m_busybar-> show ( );
48 m_counter-> hide ( );
49 }
50 else {
51 m_counter-> show ( );
52 m_busybar-> hide ( );
53 m_busybar-> endBusy ( );
54 }
55 m_isbusy = b;
56 }
57}
58
59bool QPEOutputDev::isBusy ( ) const
60{
61 return m_isbusy;
62}
63
64void QPEOutputDev::setHBarGeometry ( QScrollBar &hbar, int x, int y, int w, int h )
65{
66 int delta = w * 3 / 10;
67
68 m_counter-> setGeometry ( x, y, delta, h );
69 m_busybar-> setGeometry ( x, y, delta, h );
70 hbar. setGeometry ( x + delta, y, w - delta, h );
71}
72
73
74void QPEOutputDev::keyPressEvent ( QKeyEvent *e )
75{
76 switch ( e-> key ( )) {
77 case Key_Left:
78 scrollBy ( -10, 0 );
79 break;
80 case Key_Right:
81 scrollBy ( 10, 0 );
82 break;
83 case Key_Up:
84 scrollBy ( 0, -10 );
85 break;
86 case Key_Down:
87 scrollBy ( 0, 10 );
88 break;
89
90 default:
91 QOutputDev::keyPressEvent ( e );
92 }
93}
94
95
96void QPEOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph )
97{
98 QOutputDev::drawContents ( p, clipx, clipy, clipw, cliph );
99
100 if ( m_selection. isValid ( )) {
101 QRect clip ( clipx, clipy, clipw, cliph );
102
103 if ( m_selection. intersects ( clip )) {
104 RasterOp rop = p-> rasterOp ( );
105
106 p-> setRasterOp ( XorROP );
107 p-> fillRect ( m_selection & clip, white );
108 p-> setRasterOp ( rop );
109 }
110 }
111}
112
113
114QRect QPEOutputDev::selection ( ) const
115{
116 return m_selection;
117}
118
119
120void QPEOutputDev::setSelection ( const QRect &r, bool scrollto )
121{
122 QRect oldsel = m_selection;
123 m_selection = r;
124
125 QArray<QRect> urects = ( QRegion ( oldsel ) ^ QRegion ( m_selection )). rects ( );
126
127 for ( uint i = 0; i < urects. count ( ); i++ )
128 repaintContents ( urects [i] );
129
130 if ( scrollto ) {
131 QPoint c = r. center ( );
132
133 ensureVisible ( c. x ( ), c. y ( ), r. width ( ) / 2 + 5, r. height ( ) / 2 + 5 );
134 }
135
136 if ( !m_selectiondrag )
137 emit selectionChanged ( m_selection );
138}
139
140
141void QPEOutputDev::viewportMousePressEvent ( QMouseEvent *e )
142{
143 if ( e-> button ( ) == LeftButton ) {
144 m_selectionstart = e-> pos ( ) + QPoint ( contentsX ( ), contentsY ( ));
145 m_selectioncursor = m_selectionstart;
146 m_selectiondrag = true;
147
148 setSelection ( QRect ( m_selectionstart, QSize ( 0, 0 )), true );
149 }
150}
151
152void QPEOutputDev::viewportMouseMoveEvent ( QMouseEvent *e )
153{
154 if ( e-> state ( ) & LeftButton ) {
155 if ( m_selectiondrag ) {
156 QPoint to ( e-> pos ( ) + QPoint ( contentsX ( ), contentsY ( )));
157
158 if ( to != m_selectioncursor ) {
159 setSelection ( QRect ( m_selectionstart, to ). normalize ( ), false );
160 m_selectioncursor = to;
161 }
162 ensureVisible ( m_selectioncursor. x ( ), m_selectioncursor. y ( ), 5, 5 );
163 }
164 }
165}
166
167
168void QPEOutputDev::viewportMouseReleaseEvent ( QMouseEvent *e )
169{
170 if ( e-> button ( ) == LeftButton ) {
171 if ( m_selectiondrag ) {
172 m_selectiondrag = false;
173
174 setSelection ( selection ( ), false ); // emit signal
175 }
176 else {
177 setSelection ( QRect ( 0, 0, 0, 0 ), false );
178 }
179 }
180}
181