00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef koRuler_h
00025 #define koRuler_h
00026
00027 #include <qframe.h>
00028 #include <qpixmap.h>
00029
00030 #include <kdemacros.h>
00031 #include <koffice_export.h>
00032 #include <KoGlobal.h>
00033 #include <KoTabChooser.h>
00034 #include <KoUnit.h>
00035
00036 class KoPageLayout;
00037 class QPainter;
00038
00039 enum KoTabulators { T_LEFT = 0, T_CENTER = 1, T_RIGHT = 2, T_DEC_PNT = 3, T_INVALID = -1 };
00040 enum KoTabulatorFilling { TF_BLANK = 0, TF_DOTS = 1, TF_LINE = 2, TF_DASH = 3, TF_DASH_DOT = 4, TF_DASH_DOT_DOT = 5};
00041
00046 struct KoTabulator {
00050 double ptPos;
00054 KoTabulators type;
00058 KoTabulatorFilling filling;
00062 double ptWidth;
00066 QChar alignChar;
00067
00068 bool operator==( const KoTabulator & t ) const {
00069 return QABS( ptPos - t.ptPos ) < 1E-4 && type == t.type &&
00070 filling == t.filling && QABS( ptWidth - t.ptWidth ) < 1E-4;
00071 }
00072 bool operator!=( const KoTabulator & t ) const {
00073 return !operator==(t);
00074 }
00075
00076 bool operator < ( const KoTabulator & t ) const {
00077 return ptPos < t.ptPos;
00078 }
00079 bool operator <= ( const KoTabulator & t ) const {
00080 return ptPos <= t.ptPos;
00081 }
00082 bool operator > ( const KoTabulator & t ) const {
00083 return ptPos > t.ptPos;
00084 }
00085 };
00086
00087 typedef QValueList<KoTabulator> KoTabulatorList;
00088
00089 class KoRulerPrivate;
00090
00101 class KOFFICEUI_EXPORT KoRuler : public QFrame
00102 {
00103 Q_OBJECT
00104 friend class KoRulerPrivate;
00105 public:
00106 static const int F_TABS;
00107 static const int F_INDENTS;
00108 static const int F_HELPLINES;
00109 static const int F_NORESIZE;
00110
00115 KoRuler( QWidget *_parent, QWidget *_canvas, Orientation _orientation,
00116 const KoPageLayout& _layout, int _flags, KoUnit::Unit _unit,
00117 KoTabChooser *_tabChooser = 0L );
00118 ~KoRuler();
00119
00125 void setUnit( const QString& unit ) KDE_DEPRECATED ;
00129 void setUnit( KoUnit::Unit unit );
00130
00134 void setZoom( const double& zoom=1.0 );
00138 const double& zoom() const { return m_zoom; }
00139
00145 void setPageLayout( const KoPageLayout& _layout );
00146
00152 void showMousePos( bool _showMPos );
00158 void setMousePos( int mx, int my );
00159
00165 void setOffset( int _diffx, int _diffy );
00166
00170 void setLeftIndent( double _left )
00171 { i_left = makeIntern( _left ); update(); }
00172
00177 void setFirstIndent( double _first )
00178 { i_first = makeIntern( _first ); update(); }
00179
00183 void setRightIndent( double _right );
00184
00190 void setDirection( bool rtl );
00191
00195 void setTabList( const KoTabulatorList & tabList );
00196
00205 void setFrameStartEnd( int _frameStart, int _frameEnd );
00206
00211 void setReadWrite( bool _readWrite );
00212
00216 void changeFlags(int _flags);
00217
00222 void setGridSize(double newGridSize) { gridSize=newGridSize; }
00223
00227 int flags() const;
00228
00238 bool doubleClickedIndent() const;
00239
00243 void setPageLayoutMenuItemEnabled(bool b);
00244
00248 virtual QSize minimumSizeHint() const;
00249
00253 virtual QSize sizeHint() const;
00254
00255 signals:
00256 void newPageLayout( const KoPageLayout & );
00257 void newLeftIndent( double );
00258 void newFirstIndent( double );
00259 void newRightIndent( double );
00261 void openPageLayoutDia();
00263 void doubleClicked();
00265 void doubleClicked( double ptPos );
00266
00267 void tabListChanged( const KoTabulatorList & );
00268 void unitChanged( KoUnit::Unit );
00269
00270 void addGuide(const QPoint &, bool, int );
00271 void moveGuide( const QPoint &, bool, int );
00272 void addHelpline(const QPoint &, bool );
00273 void moveHelpLines( const QPoint &, bool );
00274
00275 protected:
00276 enum Action {A_NONE, A_BR_LEFT, A_BR_RIGHT, A_BR_TOP, A_BR_BOTTOM,
00277 A_LEFT_INDENT, A_FIRST_INDENT, A_TAB, A_RIGHT_INDENT,
00278 A_HELPLINES };
00279
00280 void drawContents( QPainter *_painter )
00281 { orientation == Qt::Horizontal ? drawHorizontal( _painter ) : drawVertical( _painter ); }
00282
00283 void drawHorizontal( QPainter *_painter );
00284 void drawVertical( QPainter *_painter );
00285 void drawTabs( QPainter &_painter );
00286
00287 void mousePressEvent( QMouseEvent *e );
00288 void mouseReleaseEvent( QMouseEvent *e );
00289 void mouseMoveEvent( QMouseEvent *e );
00290 void mouseDoubleClickEvent( QMouseEvent* );
00291 void resizeEvent( QResizeEvent *e );
00292 void handleDoubleClick();
00293
00294 double makeIntern( double _v );
00295 double zoomIt(const double &value) const;
00296 int zoomIt(const int &value) const;
00297 unsigned int zoomIt(const unsigned int &value) const;
00298 double unZoomIt(const double &value) const;
00299 int unZoomIt(const int &value) const;
00300 unsigned int unZoomIt(const unsigned int &value) const;
00301 void setupMenu();
00302 void uncheckMenu();
00303 void searchTab(int mx);
00304 void drawLine(int oldX, int newX);
00305
00306 private:
00307 double applyRtlAndZoom( double value ) const;
00308 double unZoomItRtl( int pixValue ) const;
00309 double lineDistance() const;
00310 bool willRemoveTab( int y ) const;
00311
00312 KoRulerPrivate *d;
00313
00314 Qt::Orientation orientation;
00315 int diffx, diffy;
00316 double i_left, i_first;
00317 QPixmap buffer;
00318 double m_zoom, m_1_zoom;
00319 KoUnit::Unit m_unit;
00320 bool hasToDelete;
00321 bool showMPos;
00322 bool m_bFrameStartSet;
00323 bool m_bReadWrite;
00324 int mposX, mposY;
00325 int frameStart;
00326
00327 double gridSize;
00328
00329 protected slots:
00330 void slotMenuActivated( int i );
00331 void pageLayoutDia() { emit doubleClicked(); }
00332 void rbRemoveTab();
00333
00334 };
00335
00336 inline double KoRuler::zoomIt(const double &value) const {
00337 if (m_zoom==1.0)
00338 return value;
00339 return m_zoom*value;
00340 }
00341
00342 inline int KoRuler::zoomIt(const int &value) const {
00343 if (m_zoom==1.0)
00344 return value;
00345 return qRound(m_zoom*value);
00346 }
00347
00348 inline unsigned int KoRuler::zoomIt(const unsigned int &value) const {
00349 if (m_zoom==1.0)
00350 return value;
00351 return static_cast<unsigned int>(qRound(m_zoom*value));
00352 }
00353
00354 inline double KoRuler::unZoomIt(const double &value) const {
00355 if(m_zoom==1.0)
00356 return value;
00357 return value*m_1_zoom;
00358 }
00359
00360 inline int KoRuler::unZoomIt(const int &value) const {
00361 if(m_zoom==1.0)
00362 return value;
00363 return qRound(value*m_1_zoom);
00364 }
00365
00366 inline unsigned int KoRuler::unZoomIt(const unsigned int &value) const {
00367 if(m_zoom==1.0)
00368 return value;
00369 return static_cast<unsigned int>(qRound(value*m_1_zoom));
00370 }
00371
00372 #endif