• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • gui
coord.h
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Gui library, made within the KDE community.
3 
4  Copyright 2003,2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef OKTETA_COORD_H
24 #define OKTETA_COORD_H
25 
26 // lib
27 #include "lineposition.h"
28 #include "line.h"
29 // Okteta core
30 #include "address.h"
31 #include "size.h"
32 
33 
34 namespace Okteta
35 {
36 
47 class Coord
48 {
49  public:
54  static Coord fromIndex( Address index, LinePositionSize lineWidth );
55  public:
57  Coord();
58  Coord( LinePosition pos, Line line );
59  Coord( const Coord& other );
60  Coord& operator=( const Coord& other );
61 
62  ~Coord();
63 
64 
65  public: // logic
66  bool operator==( const Coord& other ) const;
67  bool operator!=( const Coord& other ) const;
68  bool operator<( const Coord& other ) const;
69  bool operator<=( const Coord& other ) const;
70  bool operator>( const Coord& other ) const;
71  bool operator>=( const Coord& other ) const;
72 
77  bool isPriorInLineThan( const Coord& other ) const;
82  bool isLaterInLineThan( const Coord& other ) const;
84  bool isBelow( Line line ) const;
86  bool isAbove( Line line ) const;
88  bool isAtStart() const;
90  bool isBehindLineStart() const;
92  bool isBeforeLineEnd( LinePosition maxPos ) const;
93 
99  Address indexByLineWidth( LinePositionSize lineWidth ) const;
100 
101  public:
106  void setByIndexNWidth( Address index, LinePositionSize lineWidth );
108  void set( LinePosition pos, Line line );
110  void setPos( LinePosition pos );
112  void setLine( Line line );
113 
115  void goLeft();
121  void goLeft( LinePositionSize positions );
126  void goCLeft( LinePosition maxPos );
128  void goRight();
132  void goRight( LinePositionSize positions );
137  void goCRight( LinePosition maxPos );
139  void gotoStart();
140  void gotoEndOfPreviousLine( LinePosition lastPos );
144  void gotoStartOfNextLine();
150  void goLineStart( const Coord& other );
157  void goLineEnd( LinePosition lastPos, const Coord& other );
159  void goUp();
161  void goDown();
165  void goUp( LineSize lines );
169  void goDown( LineSize lines );
170 
171  public: // state value access
173  LinePosition pos() const;
175  Line line() const;
177  bool isValid() const;
178 
179  private: // member variables
181  LinePosition mPos;
183  Line mLine;
184 };
185 
186 
187 inline Coord::Coord() : mPos( 0 ), mLine( 0 ) {}
188 inline Coord::Coord( LinePosition pos, Line line ) : mPos( pos ), mLine( line ) {}
189 
190 inline Coord Coord::fromIndex( Address index, LinePositionSize lineWidth )
191 {
192  const Line line = index / lineWidth;
193  const LinePosition pos = index - line*lineWidth;
194  return Coord( pos, line );
195 }
196 
197 inline Coord::Coord( const Coord& other ) : mPos( other.mPos ), mLine( other.mLine ) {}
198 inline Coord& Coord::operator=( const Coord& other ) { mPos = other.mPos; mLine = other.mLine; return *this; }
199 inline Coord::~Coord() {}
200 
201 inline bool Coord::operator==( const Coord& other ) const { return mPos == other.mPos && mLine == other.mLine; }
202 inline bool Coord::operator!=( const Coord& other ) const { return !(*this == other); }
203 
204 inline bool Coord::operator<( const Coord& other ) const
205 { return mLine < other.mLine || (mLine == other.mLine && mPos<other.mPos); }
206 inline bool Coord::operator<=( const Coord& other ) const
207 { return mLine < other.mLine || (mLine == other.mLine && mPos<=other.mPos); }
208 inline bool Coord::operator>( const Coord& other ) const
209 { return mLine > other.mLine || (mLine == other.mLine && mPos>other.mPos); }
210 inline bool Coord::operator>=( const Coord& other ) const
211 { return mLine > other.mLine || (mLine == other.mLine && mPos>=other.mPos); }
212 
213 inline LinePosition Coord::pos() const { return mPos; }
214 inline Line Coord::line() const { return mLine; }
215 inline bool Coord::isValid() const { return mLine >= 0 && mPos >= 0; }
216 
217 inline void Coord::setByIndexNWidth( Address index, LinePositionSize lineWidth )
218 {
219  mLine = index / lineWidth;
220  mPos = index - mLine*lineWidth;
221 }
222 
223 inline void Coord::set( LinePosition pos, Line line )
224 {
225  mPos = pos;
226  mLine = line;
227 }
228 inline void Coord::setPos( LinePosition pos ) { mPos = pos; }
229 inline void Coord::setLine( Line line ) { mLine = line; }
230 
231 inline void Coord::goCRight( LinePosition maxPos )
232 {
233  if( isBeforeLineEnd(maxPos) )
234  goRight();
235  else
236  gotoStartOfNextLine();
237 }
238 inline void Coord::goCLeft( LinePosition maxPos )
239 {
240  if( isBehindLineStart() )
241  goLeft();
242  else
243  gotoEndOfPreviousLine( maxPos );
244 }
245 
246 inline void Coord::goRight() { ++mPos; }
247 inline void Coord::goLeft() { --mPos; }
248 inline void Coord::goRight( LinePositionSize positions ) { mPos += positions; }
249 inline void Coord::goLeft( LinePositionSize positions ) { mPos -= positions; }
250 
251 inline void Coord::gotoStart() { mPos = mLine = 0; }
252 
253 inline void Coord::gotoEndOfPreviousLine( LinePosition lastPos )
254 {
255  --mLine;
256  mPos = lastPos;
257 }
258 
259 inline void Coord::gotoStartOfNextLine()
260 {
261  ++mLine;
262  mPos = 0;
263 }
264 
265 
266 inline void Coord::goLineStart( const Coord& other )
267 {
268  mPos = ( mLine == other.mLine ) ? other.mPos : 0;
269 }
270 
271 inline void Coord::goLineEnd( LinePosition lastPos, const Coord& other )
272 {
273  mPos = ( mLine == other.mLine ) ? other.mPos : lastPos;
274 }
275 
276 inline void Coord::goUp() { --mLine; }
277 inline void Coord::goDown() { ++mLine; }
278 inline void Coord::goUp( LineSize lines ) { mLine -= lines; }
279 inline void Coord::goDown( LineSize lines ) { mLine += lines; }
280 
281 
282 inline Address Coord::indexByLineWidth( LinePositionSize lineWidth ) const
283 {
284  return mLine * lineWidth + mPos;
285 }
286 
287 
288 inline bool Coord::isPriorInLineThan( const Coord& other ) const
289 {
290  return mLine == other.mLine && mPos < other.mPos;
291 }
292 
293 inline bool Coord::isLaterInLineThan( const Coord& other ) const
294 {
295  return mLine == other.mLine && mPos > other.mPos;
296 }
297 
298 inline bool Coord::isBelow( Line line ) const { return mLine > line; }
299 inline bool Coord::isAbove( Line line ) const { return mLine < line; }
300 
301 inline bool Coord::isBehindLineStart() const { return mPos > 0; }
302 inline bool Coord::isBeforeLineEnd( LinePosition maxPos ) const { return mPos < maxPos; }
303 
304 inline bool Coord::isAtStart() const { return mPos == 0 && mLine == 0; }
305 
306 inline Coord operator+( const Coord& other, LinePosition pos )
307 {
308  return Coord( other.pos()+pos, other.line() );
309 }
310 
311 }
312 
313 #endif
Okteta::Coord::operator>=
bool operator>=(const Coord &other) const
Definition: coord.h:210
Okteta::Address
qint32 Address
Definition: address.h:34
Okteta::Coord::isAbove
bool isAbove(Line line) const
Definition: coord.h:299
Okteta::Coord::fromIndex
static Coord fromIndex(Address index, LinePositionSize lineWidth)
constructs a section by width
Definition: coord.h:190
Okteta::Coord::isPriorInLineThan
bool isPriorInLineThan(const Coord &other) const
tests if the coord is prior in the same line than the given coord.
Definition: coord.h:288
Okteta::Coord::gotoStartOfNextLine
void gotoStartOfNextLine()
sets the coord to the start of the next line.
Definition: coord.h:259
Okteta::Coord::Coord
Coord()
creates a coord with 0,0
Definition: coord.h:187
Okteta::Coord
a class which represents a coord in a 2-dim.
Definition: coord.h:47
Okteta::Coord::operator<
bool operator<(const Coord &other) const
Definition: coord.h:204
Okteta::Coord::goLineStart
void goLineStart(const Coord &other)
sets the position to the start of the line or if the line is the same as that of the given coord to t...
Definition: coord.h:266
Okteta::Coord::gotoStart
void gotoStart()
sets coord to (0,0)
Definition: coord.h:251
Okteta::Line
qint32 Line
Definition: line.h:33
Okteta::Coord::operator!=
bool operator!=(const Coord &other) const
Definition: coord.h:202
Okteta::Coord::goUp
void goUp()
moves the coord 1 lines upwards.
Definition: coord.h:276
Okteta::Coord::set
void set(LinePosition pos, Line line)
sets both position and line
Definition: coord.h:223
Okteta::Coord::setPos
void setPos(LinePosition pos)
sets the position
Definition: coord.h:228
Okteta::Coord::goLeft
void goLeft()
moves the coord one position to the left.
Definition: coord.h:247
Okteta::Coord::isBehindLineStart
bool isBehindLineStart() const
Definition: coord.h:301
address.h
Okteta::Coord::isBeforeLineEnd
bool isBeforeLineEnd(LinePosition maxPos) const
Definition: coord.h:302
Okteta::Coord::goCRight
void goCRight(LinePosition maxPos)
moves the coord one position to the right, or if the position has already reached or passed maxPos to...
Definition: coord.h:231
Okteta::Coord::isBelow
bool isBelow(Line line) const
Definition: coord.h:298
lineposition.h
Okteta::Coord::pos
LinePosition pos() const
Definition: coord.h:213
size.h
Okteta::Coord::~Coord
~Coord()
Definition: coord.h:199
Okteta::Coord::operator<=
bool operator<=(const Coord &other) const
Definition: coord.h:206
Okteta::Coord::setByIndexNWidth
void setByIndexNWidth(Address index, LinePositionSize lineWidth)
set the coord by calculating it for an index with a given line width
Definition: coord.h:217
Okteta::Coord::gotoEndOfPreviousLine
void gotoEndOfPreviousLine(LinePosition lastPos)
Definition: coord.h:253
Okteta::LinePosition
qint32 LinePosition
Definition: lineposition.h:33
Okteta::Coord::isAtStart
bool isAtStart() const
Definition: coord.h:304
Okteta::Coord::goCLeft
void goCLeft(LinePosition maxPos)
moves the coord one position to the left, or if the position is already at the line start to the give...
Definition: coord.h:238
Okteta::Coord::operator=
Coord & operator=(const Coord &other)
Definition: coord.h:198
Okteta::Coord::line
Line line() const
Definition: coord.h:214
Okteta::LinePositionSize
qint32 LinePositionSize
Definition: lineposition.h:34
Okteta::Coord::goRight
void goRight()
moves the coord one position to the right.
Definition: coord.h:246
Okteta::Coord::isValid
bool isValid() const
Definition: coord.h:215
Okteta::operator+
Coord operator+(const Coord &other, LinePosition pos)
Definition: coord.h:306
Okteta::Coord::goDown
void goDown()
moves the coord lines lines downwards.
Definition: coord.h:277
Okteta::Coord::goLineEnd
void goLineEnd(LinePosition lastPos, const Coord &other)
sets the position to the given pos or if the line is the same as that of the given coord to the posit...
Definition: coord.h:271
Okteta::Coord::setLine
void setLine(Line line)
sets the line
Definition: coord.h:229
Okteta::Coord::indexByLineWidth
Address indexByLineWidth(LinePositionSize lineWidth) const
calculates the index the coord is at with a given line width If the coord is invalid the result is un...
Definition: coord.h:282
Okteta::LineSize
qint32 LineSize
Definition: line.h:34
Okteta::Coord::isLaterInLineThan
bool isLaterInLineThan(const Coord &other) const
tests if the coord is later in the same line than the given coord.
Definition: coord.h:293
Okteta::Coord::operator==
bool operator==(const Coord &other) const
Definition: coord.h:201
Okteta::Coord::operator>
bool operator>(const Coord &other) const
Definition: coord.h:208
line.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal