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 <koGlobal.h>
00031 #include <koTabChooser.h>
00032 
00033 class QPainter;
00034 
00035 enum KoTabulators { T_LEFT = 0, T_CENTER = 1, T_RIGHT = 2, T_DEC_PNT = 3, T_INVALID = -1 };
00036 enum KoTabulatorFilling { TF_BLANK = 0, TF_DOTS = 1, TF_LINE = 2, TF_DASH = 3, TF_DASH_DOT = 4, TF_DASH_DOT_DOT = 5};
00037 
00042 struct KoTabulator {
00046     double ptPos;
00050     KoTabulators type;
00054     KoTabulatorFilling filling;
00058     double ptWidth;
00062     QChar alignChar;
00063 
00064     bool operator==( const KoTabulator & t ) const {
00065         return QABS( ptPos - t.ptPos ) < 1E-4 && type == t.type &&
00066                filling == t.filling && QABS( ptWidth - t.ptWidth ) < 1E-4;
00067     }
00068     bool operator!=( const KoTabulator & t ) const {
00069         return !operator==(t);
00070     }
00071     // Operators used for sorting
00072     bool operator < ( const KoTabulator & t ) const {
00073         return ptPos < t.ptPos;
00074     }
00075     bool operator <= ( const KoTabulator & t ) const {
00076         return ptPos <= t.ptPos;
00077     }
00078     bool operator > ( const KoTabulator & t ) const {
00079         return ptPos > t.ptPos;
00080     }
00081 };
00082 
00083 typedef QValueList<KoTabulator> KoTabulatorList;
00084 
00085 class KoRulerPrivate;
00086 
00097 class KoRuler : public QFrame
00098 {
00099     Q_OBJECT
00100     friend class KoRulerPrivate; // for the Action enum
00101 public:
00102     static const int F_TABS;
00103     static const int F_INDENTS;
00104     static const int F_HELPLINES;
00105     static const int F_NORESIZE;
00106 
00111     KoRuler( QWidget *_parent,  QWidget *_canvas, Orientation _orientation,
00112              const KoPageLayout& _layout, int _flags, KoUnit::Unit _unit,
00113              KoTabChooser *_tabChooser = 0L );
00114     ~KoRuler();
00115 
00121     void setUnit( const QString& unit );
00125     void setUnit( KoUnit::Unit unit );
00126 
00130     void setZoom( const double& zoom=1.0 );
00134     const double& zoom() const { return m_zoom; }
00135 
00141     void setPageLayout( KoPageLayout _layout )
00142     { layout = _layout; update(); }
00143 
00149     void showMousePos( bool _showMPos );
00155     void setMousePos( int mx, int my );
00156 
00162     void setOffset( int _diffx, int _diffy );
00163 
00167     void setLeftIndent( double _left )
00168     { i_left = makeIntern( _left ); update(); }
00169 
00174     void setFirstIndent( double _first )
00175     { i_first = makeIntern( _first ); update(); }
00176 
00180     void setRightIndent( double _right );
00181 
00187     void setDirection( bool rtl );
00188 
00192     void setTabList( const KoTabulatorList & tabList );
00193 
00202     void setFrameStartEnd( int _frameStart, int _frameEnd );
00203 
00208     void setReadWrite( bool _readWrite );
00209 
00213     void changeFlags(int _flags);
00214 
00219     void setGridSize(double newGridSize) { gridSize=newGridSize; }
00220 
00224     int flags() const;
00225 
00235     bool doubleClickedIndent() const;
00236 
00240     void setPageLayoutMenuItemEnabled(bool b);
00241 
00242 signals:
00243     void newPageLayout( KoPageLayout ); // BIC: pass a const ref
00244     void newLeftIndent( double );
00245     void newFirstIndent( double );
00246     void newRightIndent( double );
00248     void openPageLayoutDia();
00250     void doubleClicked();
00252     void doubleClicked( double ptPos );
00253 
00254     void tabListChanged( const KoTabulatorList & );
00255     void unitChanged( QString ); // TODO KoUnit::Unit instead ?
00256 
00257     void addHelpline(const QPoint &, bool );
00258     void moveHelpLines( const QPoint &, bool );
00259 
00260 protected:
00261     enum Action {A_NONE, A_BR_LEFT, A_BR_RIGHT, A_BR_TOP, A_BR_BOTTOM,
00262                  A_LEFT_INDENT, A_FIRST_INDENT, A_TAB, A_RIGHT_INDENT,
00263                  A_HELPLINES };
00264 
00265     void drawContents( QPainter *_painter )
00266     { orientation == Qt::Horizontal ? drawHorizontal( _painter ) : drawVertical( _painter ); }
00267 
00268     void drawHorizontal( QPainter *_painter );
00269     void drawVertical( QPainter *_painter );
00270     void drawTabs( QPainter &_painter );
00271 
00272     void mousePressEvent( QMouseEvent *e );
00273     void mouseReleaseEvent( QMouseEvent *e );
00274     void mouseMoveEvent( QMouseEvent *e );
00275     void mouseDoubleClickEvent( QMouseEvent* );
00276     void resizeEvent( QResizeEvent *e );
00277     void handleDoubleClick();
00278 
00279     double makeIntern( double _v );
00280     double zoomIt(const double &value) const;
00281     int zoomIt(const int &value) const;
00282     unsigned int zoomIt(const unsigned int &value) const;
00283     double unZoomIt(const double &value) const;
00284     int unZoomIt(const int &value) const;
00285     unsigned int unZoomIt(const unsigned int &value) const;
00286     void setupMenu();
00287     void uncheckMenu();
00288     void searchTab(int mx);
00289     void drawLine(int oldX, int newX);
00290 
00291 private:
00292     double applyRtlAndZoom( double value ) const;
00293     double unZoomItRtl( int pixValue ) const;
00294     double lineDistance() const;
00295     bool willRemoveTab( int y ) const;
00296 
00297     KoRulerPrivate *d;
00298 
00299     Qt::Orientation orientation;
00300     int diffx, diffy;
00301     double i_left, i_first;
00302     KoPageLayout layout;
00303     QPixmap buffer;
00304     double m_zoom, m_1_zoom;
00305     KoUnit::Unit m_unit;
00306     bool hasToDelete;
00307     bool showMPos;
00308     int mposX, mposY;
00309     int frameStart;
00310     bool m_bFrameStartSet;
00311 
00312     bool m_bReadWrite;
00313 
00314     double gridSize;
00315 
00316 protected slots:
00317     void slotMenuActivated( int i );
00318     void pageLayoutDia() { emit doubleClicked()/*openPageLayoutDia()*/; }
00319     void rbRemoveTab();
00320 
00321 };
00322 
00323 inline double KoRuler::zoomIt(const double &value) const {
00324     if (m_zoom==1.0)
00325         return value;
00326     return m_zoom*value;
00327 }
00328 
00329 inline int KoRuler::zoomIt(const int &value) const {
00330     if (m_zoom==1.0)
00331         return value;
00332     return qRound(m_zoom*value);
00333 }
00334 
00335 inline unsigned int KoRuler::zoomIt(const unsigned int &value) const {
00336     if (m_zoom==1.0)
00337         return value;
00338     return static_cast<unsigned int>(qRound(m_zoom*value));
00339 }
00340 
00341 inline double KoRuler::unZoomIt(const double &value) const {
00342     if(m_zoom==1.0)
00343         return value;
00344     return value*m_1_zoom;
00345 }
00346 
00347 inline int KoRuler::unZoomIt(const int &value) const {
00348     if(m_zoom==1.0)
00349         return value;
00350     return qRound(value*m_1_zoom);
00351 }
00352 
00353 inline unsigned int KoRuler::unZoomIt(const unsigned int &value) const {
00354     if(m_zoom==1.0)
00355         return value;
00356     return static_cast<unsigned int>(qRound(value*m_1_zoom));
00357 }
00358 
00359 #endif
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Mar 20 14:25:26 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003