KoRuler.h
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20// Description: Ruler (header)
21
22/******************************************************************/
23
24#ifndef koRuler_h
25#define koRuler_h
26
27#include <tqframe.h>
28#include <tqpixmap.h>
29
30#include <tdemacros.h>
31#include <koffice_export.h>
32#include <KoGlobal.h>
33#include <KoTabChooser.h>
34#include <KoUnit.h>
35
36class KoPageLayout;
37class TQPainter;
38
39enum KoTabulators { T_LEFT = 0, T_CENTER = 1, T_RIGHT = 2, T_DEC_PNT = 3, T_INVALID = -1 };
40enum KoTabulatorFilling { TF_BLANK = 0, TF_DOTS = 1, TF_LINE = 2, TF_DASH = 3, TF_DASH_DOT = 4, TF_DASH_DOT_DOT = 5};
41
50 double ptPos;
54 KoTabulators type;
58 KoTabulatorFilling filling;
62 double ptWidth;
66 TQChar alignChar;
67
68 bool operator==( const KoTabulator & t ) const {
69 return TQABS( ptPos - t.ptPos ) < 1E-4 && type == t.type &&
70 filling == t.filling && TQABS( ptWidth - t.ptWidth ) < 1E-4;
71 }
72 bool operator!=( const KoTabulator & t ) const {
73 return !operator==(t);
74 }
75 // Operators used for sorting
76 bool operator < ( const KoTabulator & t ) const {
77 return ptPos < t.ptPos;
78 }
79 bool operator <= ( const KoTabulator & t ) const {
80 return ptPos <= t.ptPos;
81 }
82 bool operator > ( const KoTabulator & t ) const {
83 return ptPos > t.ptPos;
84 }
85};
86
87typedef TQValueList<KoTabulator> KoTabulatorList;
88
89class KoRulerPrivate;
90
101class KOFFICEUI_EXPORT KoRuler : public TQFrame
102{
103 TQ_OBJECT
104
105 friend class KoRulerPrivate; // for the Action enum
106public:
107 static const int F_TABS;
108 static const int F_INDENTS;
109 static const int F_HELPLINES;
110 static const int F_NORESIZE;
111
116 KoRuler( TQWidget *_parent, TQWidget *_canvas, TQt::Orientation _orientation,
117 const KoPageLayout& _layout, int _flags, KoUnit::Unit _unit,
118 KoTabChooser *_tabChooser = 0L );
119 ~KoRuler();
120
126 void setUnit( const TQString& unit ) TDE_DEPRECATED ;
130 void setUnit( KoUnit::Unit unit );
131
135 void setZoom( const double& zoom=1.0 );
139 const double& zoom() const { return m_zoom; }
140
146 void setPageLayout( const KoPageLayout& _layout );
147
153 void showMousePos( bool _showMPos );
159 void setMousePos( int mx, int my );
160
166 void setOffset( int _diffx, int _diffy );
167
171 void setLeftIndent( double _left )
172 { i_left = makeIntern( _left ); update(); }
173
178 void setFirstIndent( double _first )
179 { i_first = makeIntern( _first ); update(); }
180
184 void setRightIndent( double _right );
185
191 void setDirection( bool rtl );
192
196 void setTabList( const KoTabulatorList & tabList );
197
206 void setFrameStartEnd( int _frameStart, int _frameEnd );
207
212 void setReadWrite( bool _readWrite );
213
217 void changeFlags(int _flags);
218
223 void setGridSize(double newGridSize) { gridSize=newGridSize; }
224
228 int flags() const;
229
239 bool doubleClickedIndent() const;
240
244 void setPageLayoutMenuItemEnabled(bool b);
245
249 virtual TQSize minimumSizeHint() const;
250
254 virtual TQSize sizeHint() const;
255
256signals:
257 void newPageLayout( const KoPageLayout & );
258 void newLeftIndent( double );
259 void newFirstIndent( double );
260 void newRightIndent( double );
266 void doubleClicked( double ptPos );
267
268 void tabListChanged( const KoTabulatorList & );
269 void unitChanged( KoUnit::Unit );
270
271 void addGuide(const TQPoint &, bool, int );
272 void moveGuide( const TQPoint &, bool, int );
273 void addHelpline(const TQPoint &, bool );
274 void moveHelpLines( const TQPoint &, bool );
275
276protected:
277 enum Action {A_NONE, A_BR_LEFT, A_BR_RIGHT, A_BR_TOP, A_BR_BOTTOM,
278 A_LEFT_INDENT, A_FIRST_INDENT, A_TAB, A_RIGHT_INDENT,
279 A_HELPLINES };
280
281 void drawContents( TQPainter *_painter )
282 { orientation == TQt::Horizontal ? drawHorizontal( _painter ) : drawVertical( _painter ); }
283
284 void drawHorizontal( TQPainter *_painter );
285 void drawVertical( TQPainter *_painter );
286 void drawTabs( TQPainter &_painter );
287
288 void mousePressEvent( TQMouseEvent *e );
289 void mouseReleaseEvent( TQMouseEvent *e );
290 void mouseMoveEvent( TQMouseEvent *e );
291 void mouseDoubleClickEvent( TQMouseEvent* );
292 void resizeEvent( TQResizeEvent *e );
293 void handleDoubleClick();
294
295 double makeIntern( double _v );
296 double zoomIt(const double &value) const;
297 int zoomIt(const int &value) const;
298 unsigned int zoomIt(const unsigned int &value) const;
299 double unZoomIt(const double &value) const;
300 int unZoomIt(const int &value) const;
301 unsigned int unZoomIt(const unsigned int &value) const;
302 void setupMenu();
303 void uncheckMenu();
304 void searchTab(int mx);
305 void drawLine(int oldX, int newX);
306
307private:
308 double applyRtlAndZoom( double value ) const;
309 double unZoomItRtl( int pixValue ) const;
310 double lineDistance() const;
311 bool willRemoveTab( int y ) const;
312
313 KoRulerPrivate *d;
314
315 TQt::Orientation orientation;
316 int diffx, diffy;
317 double i_left, i_first;
318 TQPixmap buffer;
319 double m_zoom, m_1_zoom;
320 KoUnit::Unit m_unit;
321 bool hasToDelete;
322 bool showMPos;
323 bool m_bFrameStartSet;
324 bool m_bReadWrite;
325 int mposX, mposY;
326 int frameStart;
327
328 double gridSize;
329
330protected slots:
331 void slotMenuActivated( int i );
332 void pageLayoutDia() { emit doubleClicked()/*openPageLayoutDia()*/; }
333 void rbRemoveTab();
334
335};
336
337inline double KoRuler::zoomIt(const double &value) const {
338 if (m_zoom==1.0)
339 return value;
340 return m_zoom*value;
341}
342
343inline int KoRuler::zoomIt(const int &value) const {
344 if (m_zoom==1.0)
345 return value;
346 return tqRound(m_zoom*value);
347}
348
349inline unsigned int KoRuler::zoomIt(const unsigned int &value) const {
350 if (m_zoom==1.0)
351 return value;
352 return static_cast<unsigned int>(tqRound(m_zoom*value));
353}
354
355inline double KoRuler::unZoomIt(const double &value) const {
356 if(m_zoom==1.0)
357 return value;
358 return value*m_1_zoom;
359}
360
361inline int KoRuler::unZoomIt(const int &value) const {
362 if(m_zoom==1.0)
363 return value;
364 return tqRound(value*m_1_zoom);
365}
366
367inline unsigned int KoRuler::unZoomIt(const unsigned int &value) const {
368 if(m_zoom==1.0)
369 return value;
370 return static_cast<unsigned int>(tqRound(value*m_1_zoom));
371}
372
373#endif
KoRuler is the horizontal or vertical ruler, to be used around the drawing area of most KOffice progr...
Definition KoRuler.h:102
void doubleClicked()
This signal is emitted when double-clicking the ruler (or an indent)
void setLeftIndent(double _left)
Set the [paragraph] left indent to the specified position (in the current unit)
Definition KoRuler.h:171
void setGridSize(double newGridSize)
Set the size of the grid used for tabs positioning, size in pt.
Definition KoRuler.h:223
void setFirstIndent(double _first)
Set the [paragraph] first-line left indent to the specified position (in the current unit) This inden...
Definition KoRuler.h:178
void doubleClicked(double ptPos)
This signal is emitted when double-clicking a tab.
void openPageLayoutDia()
Old signal, kept for compatibility.
const double & zoom() const
Definition KoRuler.h:139
Unit
Length units supported by KOffice.
Definition KoUnit.h:63
This structure defines the page layout, including its size in pt, its format (e.g.
Struct: KoTabulator Defines the position of a tabulation (in pt), and its type.
Definition KoRuler.h:46
KoTabulators type
Type of tab (left/center/right/decimalpoint)
Definition KoRuler.h:54
KoTabulatorFilling filling
Type of tab filling.
Definition KoRuler.h:58
double ptPos
Position of the tab in pt.
Definition KoRuler.h:50
TQChar alignChar
Alignment character.
Definition KoRuler.h:66
double ptWidth
Width of the tab filling line.
Definition KoRuler.h:62