• 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
selection.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,2008-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 mRange 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_SELECTION_H
24 #define OKTETA_SELECTION_H
25 
26 // lib
27 #include "addressrange.h"
28 
29 
30 namespace Okteta
31 {
32 
44 class Selection
45 {
46  public:
50  explicit Selection( Address index );
52  Selection();
53 
54  ~Selection();
55 
56  public:
57  Selection& operator=( const Selection& other );
58  Selection& operator=( const AddressRange& range );
59 
60  public: // modification access
66  void setStart( Address index );
71  void setEnd( Address index );
74  void cancel();
79  void setForward( bool forward = true );
83  void reverse();
84 
85  void adaptToReplacement( Address pos, Size removedLength, Size insertedLength );
86  void adaptToSwap( Address firstOffset, Address secondOffset, Size secondLength );
87 
88  public: // value access
92  Address anchor() const;
93  Address start() const;
94  Address end() const;
95  Address nextBeforeStart() const;
96  Address nextBehindEnd() const;
100  const AddressRange& range() const;
101 
102 
103  public: // logic access
104  bool isValid() const;
108  bool started() const;
112  bool justStarted() const;
116  bool isForward() const;
117 
118  protected:
120  AddressRange mRange;
122  Address mAnchor;
123 };
124 
125 
126 inline Selection::Selection() : mAnchor( -1 ) {}
127 inline Selection::Selection( Address index ) : mAnchor( index ) {}
128 inline Selection::~Selection() {}
129 
130 inline Selection &Selection::operator=( const Selection& other )
131 {
132  mRange = other.mRange;
133  mAnchor = other.mAnchor;
134  return *this;
135 }
136 
137 inline Selection &Selection::operator=( const AddressRange& range )
138 {
139  mRange = range;
140  mAnchor = range.start();
141  return *this;
142 }
143 
144 
145 inline void Selection::setStart( Address index )
146 {
147  mAnchor = index;
148  mRange.unset();
149 }
150 
151 
152 inline void Selection::setEnd( Address index )
153 {
154  // nothing selected?
155  if( index == mAnchor )
156  mRange.unset();
157  // selecting forwards?
158  else if( index > mAnchor )
159  {
160  mRange.setStart( mAnchor );
161  mRange.setEnd( index-1 );
162  }
163  // selecting backwards
164  else
165  {
166  mRange.setStart( index );
167  mRange.setEnd( mAnchor-1 );
168  }
169 }
170 
171 inline void Selection::reverse()
172 {
173  mAnchor = isForward() ? mRange.nextBehindEnd() : mRange.start();
174 }
175 
176 inline void Selection::setForward( bool Forward )
177 {
178  mAnchor = Forward ? mRange.start() : mRange.nextBehindEnd();
179 }
180 
181 inline const AddressRange& Selection::range() const { return mRange; }
182 inline Address Selection::anchor() const { return mAnchor; }
183 inline Address Selection::start() const { return mRange.start(); }
184 inline Address Selection::end() const { return mRange.end(); }
185 inline Address Selection::nextBeforeStart() const { return mRange.nextBeforeStart(); }
186 inline Address Selection::nextBehindEnd() const { return mRange.nextBehindEnd(); }
187 
188 inline void Selection::cancel() { mAnchor = -1; mRange.unset(); }
189 
190 inline bool Selection::isValid() const { return mRange.isValid(); }
191 inline bool Selection::started() const { return mAnchor != -1; }
192 inline bool Selection::justStarted() const { return mAnchor != -1 && mRange.start() == -1; }
193 inline bool Selection::isForward() const { return mAnchor == mRange.start(); }
194 
195 inline void Selection::adaptToReplacement( Address pos, Size removedLength, Size insertedLength )
196 {
197  mRange.adaptToReplacement( pos, removedLength, insertedLength );
198  mAnchor = isForward() ? mRange.start() : mRange.nextBehindEnd();
199 }
200 
201 inline void Selection::adaptToSwap( Address firstOffset, Address secondOffset, Size secondLength )
202 {
203  // no intersection?
204  if( mRange.end() < firstOffset || mRange.start() > secondOffset+secondLength-1 )
205  return;
206 
207  const AddressRange firstSection( firstOffset, secondOffset-1 );
208  if( firstSection.includes(mRange) )
209  mRange.moveBy( secondLength );
210  else
211  {
212  const AddressRange secondRange = AddressRange::fromWidth( secondOffset, secondLength );
213  if( secondRange.includes(mRange) )
214  mRange.moveBy( -firstSection.width() );
215  else
216  mRange.unset();
217  }
218 }
219 
220 }
221 
222 #endif
Okteta::Selection::operator=
Selection & operator=(const Selection &other)
Definition: selection.h:130
Okteta::Address
qint32 Address
Definition: address.h:34
KDE::Range::moveBy
void moveBy(T D)
moves the range by D.
Definition: range.h:82
KDE::NumberRange::nextBehindEnd
N nextBehindEnd() const
Definition: numberrange.h:145
Okteta::Selection::range
const AddressRange & range() const
Definition: selection.h:181
KDE::NumberRange< Address, Size >
KDE::Range::start
T start() const
Definition: range.h:86
KDE::Range::setEnd
void setEnd(T E)
sets the last index of the range
Definition: range.h:60
Okteta::Selection::justStarted
bool justStarted() const
Definition: selection.h:192
KDE::NumberRange::width
S width() const
Definition: numberrange.h:141
Okteta::Selection::nextBehindEnd
Address nextBehindEnd() const
Definition: selection.h:186
Okteta::Selection::mRange
AddressRange mRange
mRange
Definition: selection.h:120
addressrange.h
KDE::Range::end
T end() const
Definition: range.h:88
KDE::NumberRange::adaptToReplacement
void adaptToReplacement(N offset, S removedLength, S insertedLength)
Definition: numberrange.h:226
KDE::NumberRange< Address, Size >::fromWidth
static NumberRange fromWidth(AddressstartIndex, Sizewidth)
constructs a range by width
Okteta::Selection::end
Address end() const
Definition: selection.h:184
Okteta::Selection::cancel
void cancel()
sets the selection to be invalid
Definition: selection.h:188
Okteta::Selection::Selection
Selection()
creates an invalid selection
Definition: selection.h:126
Okteta::Selection
This class describes a selected range of the buffer.
Definition: selection.h:44
Okteta::Selection::isForward
bool isForward() const
Definition: selection.h:193
Okteta::Selection::setForward
void setForward(bool forward=true)
sets the anchor to the start or the end.
Definition: selection.h:176
Okteta::Selection::adaptToReplacement
void adaptToReplacement(Address pos, Size removedLength, Size insertedLength)
Definition: selection.h:195
KDE::Range::includes
bool includes(T Value) const
returns true if Value is covered
Definition: range.h:93
Okteta::Selection::adaptToSwap
void adaptToSwap(Address firstOffset, Address secondOffset, Size secondLength)
Definition: selection.h:201
Okteta::Selection::setEnd
void setEnd(Address index)
sets the end of the current selection.
Definition: selection.h:152
Okteta::Selection::nextBeforeStart
Address nextBeforeStart() const
Definition: selection.h:185
KDE::Range::unset
void unset()
sets the range to null
Definition: range.h:62
Okteta::Selection::anchor
Address anchor() const
Definition: selection.h:182
Okteta::Selection::started
bool started() const
Definition: selection.h:191
Okteta::Selection::~Selection
~Selection()
Definition: selection.h:128
Okteta::Selection::mAnchor
Address mAnchor
cursor index where the selection starts
Definition: selection.h:122
Okteta::Selection::start
Address start() const
Definition: selection.h:183
Okteta::Selection::isValid
bool isValid() const
Definition: selection.h:190
Okteta::Size
qint32 Size
Definition: size.h:33
KDE::Range::setStart
void setStart(T S)
sets the first index of the range
Definition: range.h:58
Okteta::Selection::reverse
void reverse()
swaps anchor from start to end or vice versa.
Definition: selection.h:171
KDE::Range::isValid
bool isValid() const
returns true if the range covers at least one index
Definition: range.h:122
Okteta::Selection::setStart
void setStart(Address index)
starts the selection.
Definition: selection.h:145
KDE::NumberRange::nextBeforeStart
N nextBeforeStart() const
Definition: numberrange.h:143
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:09 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