lib Library API Documentation

koRuler.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
00018 */
00019 
00020 // Description: Ruler (header)
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     // Operators used for sorting
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; // for the Action enum
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 addHelpline(const QPoint &, bool );
00271     void moveHelpLines( const QPoint &, bool );
00272 
00273 protected:
00274     enum Action {A_NONE, A_BR_LEFT, A_BR_RIGHT, A_BR_TOP, A_BR_BOTTOM,
00275                  A_LEFT_INDENT, A_FIRST_INDENT, A_TAB, A_RIGHT_INDENT,
00276                  A_HELPLINES };
00277 
00278     void drawContents( QPainter *_painter )
00279     { orientation == Qt::Horizontal ? drawHorizontal( _painter ) : drawVertical( _painter ); }
00280 
00281     void drawHorizontal( QPainter *_painter );
00282     void drawVertical( QPainter *_painter );
00283     void drawTabs( QPainter &_painter );
00284 
00285     void mousePressEvent( QMouseEvent *e );
00286     void mouseReleaseEvent( QMouseEvent *e );
00287     void mouseMoveEvent( QMouseEvent *e );
00288     void mouseDoubleClickEvent( QMouseEvent* );
00289     void resizeEvent( QResizeEvent *e );
00290     void handleDoubleClick();
00291 
00292     double makeIntern( double _v );
00293     double zoomIt(const double &value) const;
00294     int zoomIt(const int &value) const;
00295     unsigned int zoomIt(const unsigned int &value) const;
00296     double unZoomIt(const double &value) const;
00297     int unZoomIt(const int &value) const;
00298     unsigned int unZoomIt(const unsigned int &value) const;
00299     void setupMenu();
00300     void uncheckMenu();
00301     void searchTab(int mx);
00302     void drawLine(int oldX, int newX);
00303 
00304 private:
00305     double applyRtlAndZoom( double value ) const;
00306     double unZoomItRtl( int pixValue ) const;
00307     double lineDistance() const;
00308     bool willRemoveTab( int y ) const;
00309 
00310     KoRulerPrivate *d;
00311 
00312     Qt::Orientation orientation;
00313     int diffx, diffy;
00314     double i_left, i_first;
00315     QPixmap buffer;
00316     double m_zoom, m_1_zoom;
00317     KoUnit::Unit m_unit;
00318     bool hasToDelete;
00319     bool showMPos;
00320     bool m_bFrameStartSet;
00321     bool m_bReadWrite;
00322     int mposX, mposY;
00323     int frameStart;
00324 
00325     double gridSize;
00326 
00327 protected slots:
00328     void slotMenuActivated( int i );
00329     void pageLayoutDia() { emit doubleClicked()/*openPageLayoutDia()*/; }
00330     void rbRemoveTab();
00331 
00332 };
00333 
00334 inline double KoRuler::zoomIt(const double &value) const {
00335     if (m_zoom==1.0)
00336         return value;
00337     return m_zoom*value;
00338 }
00339 
00340 inline int KoRuler::zoomIt(const int &value) const {
00341     if (m_zoom==1.0)
00342         return value;
00343     return qRound(m_zoom*value);
00344 }
00345 
00346 inline unsigned int KoRuler::zoomIt(const unsigned int &value) const {
00347     if (m_zoom==1.0)
00348         return value;
00349     return static_cast<unsigned int>(qRound(m_zoom*value));
00350 }
00351 
00352 inline double KoRuler::unZoomIt(const double &value) const {
00353     if(m_zoom==1.0)
00354         return value;
00355     return value*m_1_zoom;
00356 }
00357 
00358 inline int KoRuler::unZoomIt(const int &value) const {
00359     if(m_zoom==1.0)
00360         return value;
00361     return qRound(value*m_1_zoom);
00362 }
00363 
00364 inline unsigned int KoRuler::unZoomIt(const unsigned int &value) const {
00365     if(m_zoom==1.0)
00366         return value;
00367     return static_cast<unsigned int>(qRound(value*m_1_zoom));
00368 }
00369 
00370 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:40:05 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003