00001 #include <aconf.h>
00002
00003 #include "QPEOutputDev.h"
00004
00005 #include <qapplication.h>
00006 #include <qlabel.h>
00007 #include "qbusybar.h"
00008
00009
00010 QPEOutputDev::QPEOutputDev ( QWidget *parent, const char *name ) : QOutputDev ( parent, name )
00011 {
00012 m_counter = new QLabel ( this );
00013 m_counter-> setAlignment ( AlignCenter | SingleLine );
00014
00015 m_busybar = new QBusyBar ( this );
00016 m_busybar-> setParameters ( 12, 8, 200 );
00017 m_busybar-> hide ( );
00018
00019 setHScrollBarMode ( AlwaysOn );
00020
00021 m_isbusy = false;
00022
00023 m_selectiondrag = false;
00024
00025 setFocusPolicy ( WheelFocus );
00026 }
00027
00028 void QPEOutputDev::startPage ( int pn, GfxState *st )
00029 {
00030 m_selection = QRect ( );
00031 m_selectiondrag = false;
00032
00033 QOutputDev::startPage ( pn, st );
00034 }
00035
00036
00037 void QPEOutputDev::setPageCount ( int actp, int maxp )
00038 {
00039 m_counter-> setText ( QString ( "%1 / %2" ). arg ( actp ). arg ( maxp ));
00040 }
00041
00042 void QPEOutputDev::setBusy ( bool b )
00043 {
00044 if ( b != m_isbusy ) {
00045 if ( b ) {
00046 m_busybar-> beginBusy ( );
00047 m_busybar-> show ( );
00048 m_counter-> hide ( );
00049 }
00050 else {
00051 m_counter-> show ( );
00052 m_busybar-> hide ( );
00053 m_busybar-> endBusy ( );
00054 }
00055 m_isbusy = b;
00056 }
00057 }
00058
00059 bool QPEOutputDev::isBusy ( ) const
00060 {
00061 return m_isbusy;
00062 }
00063
00064 void QPEOutputDev::setHBarGeometry ( QScrollBar &hbar, int x, int y, int w, int h )
00065 {
00066 int delta = w * 3 / 10;
00067
00068 m_counter-> setGeometry ( x, y, delta, h );
00069 m_busybar-> setGeometry ( x, y, delta, h );
00070 hbar. setGeometry ( x + delta, y, w - delta, h );
00071 }
00072
00073
00074 void QPEOutputDev::keyPressEvent ( QKeyEvent *e )
00075 {
00076 switch ( e-> key ( )) {
00077 case Key_Left:
00078 scrollBy ( -10, 0 );
00079 break;
00080 case Key_Right:
00081 scrollBy ( 10, 0 );
00082 break;
00083 case Key_Up:
00084 scrollBy ( 0, -10 );
00085 break;
00086 case Key_Down:
00087 scrollBy ( 0, 10 );
00088 break;
00089
00090 default:
00091 QOutputDev::keyPressEvent ( e );
00092 }
00093 }
00094
00095
00096 void QPEOutputDev::drawContents ( QPainter *p, int clipx, int clipy, int clipw, int cliph )
00097 {
00098 QOutputDev::drawContents ( p, clipx, clipy, clipw, cliph );
00099
00100 if ( m_selection. isValid ( )) {
00101 QRect clip ( clipx, clipy, clipw, cliph );
00102
00103 if ( m_selection. intersects ( clip )) {
00104 RasterOp rop = p-> rasterOp ( );
00105
00106 p-> setRasterOp ( XorROP );
00107 p-> fillRect ( m_selection & clip, white );
00108 p-> setRasterOp ( rop );
00109 }
00110 }
00111 }
00112
00113
00114 QRect QPEOutputDev::selection ( ) const
00115 {
00116 return m_selection;
00117 }
00118
00119
00120 void QPEOutputDev::setSelection ( const QRect &r, bool scrollto )
00121 {
00122 QRect oldsel = m_selection;
00123 m_selection = r;
00124
00125 QArray<QRect> urects = ( QRegion ( oldsel ) ^ QRegion ( m_selection )). rects ( );
00126
00127 for ( uint i = 0; i < urects. count ( ); i++ )
00128 repaintContents ( urects [i] );
00129
00130 if ( scrollto ) {
00131 QPoint c = r. center ( );
00132
00133 ensureVisible ( c. x ( ), c. y ( ), r. width ( ) / 2 + 5, r. height ( ) / 2 + 5 );
00134 }
00135
00136 if ( !m_selectiondrag )
00137 emit selectionChanged ( m_selection );
00138 }
00139
00140
00141 void QPEOutputDev::viewportMousePressEvent ( QMouseEvent *e )
00142 {
00143 if ( e-> button ( ) == LeftButton ) {
00144 m_selectionstart = e-> pos ( ) + QPoint ( contentsX ( ), contentsY ( ));
00145 m_selectioncursor = m_selectionstart;
00146 m_selectiondrag = true;
00147
00148 setSelection ( QRect ( m_selectionstart, QSize ( 0, 0 )), true );
00149 }
00150 }
00151
00152 void QPEOutputDev::viewportMouseMoveEvent ( QMouseEvent *e )
00153 {
00154 if ( e-> state ( ) & LeftButton ) {
00155 if ( m_selectiondrag ) {
00156 QPoint to ( e-> pos ( ) + QPoint ( contentsX ( ), contentsY ( )));
00157
00158 if ( to != m_selectioncursor ) {
00159 setSelection ( QRect ( m_selectionstart, to ). normalize ( ), false );
00160 m_selectioncursor = to;
00161 }
00162 ensureVisible ( m_selectioncursor. x ( ), m_selectioncursor. y ( ), 5, 5 );
00163 }
00164 }
00165 }
00166
00167
00168 void QPEOutputDev::viewportMouseReleaseEvent ( QMouseEvent *e )
00169 {
00170 if ( e-> button ( ) == LeftButton ) {
00171 if ( m_selectiondrag ) {
00172 m_selectiondrag = false;
00173
00174 setSelection ( selection ( ), false );
00175 }
00176 else {
00177 setSelection ( QRect ( 0, 0, 0, 0 ), false );
00178 }
00179 }
00180 }
00181