• 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
  • kasten
  • controllers
  • view
  • selectrange
selectrangetool.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 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 #include "selectrangetool.h"
24 
25 // lib
26 #include <bytearrayview.h>
27 #include <bytearraydocument.h>
28 // Okteta core
29 #include <abstractbytearraymodel.h>
30 // KDE
31 #include <KLocale>
32 
33 
34 namespace Kasten2
35 {
36 
37 SelectRangeTool::SelectRangeTool()
38  : mTargetStart( 0 ),
39  mTargetEnd( -1 ),
40  mIsEndRelative( false ),
41  mIsEndBackwards( false ),
42  mByteArrayView( 0 ),
43  mByteArrayModel( 0 )
44 {
45  setObjectName( QLatin1String( "SelectRange" ) );
46 }
47 
48 int SelectRangeTool::currentSelectionStart() const
49 {
50  return mByteArrayView ?
51  mByteArrayView->startOffset() + mByteArrayView->selection().start() :
52  -1;
53 }
54 int SelectRangeTool::currentSelectionEnd() const
55 {
56  return mByteArrayView ?
57  mByteArrayView->startOffset() + mByteArrayView->selection().end() :
58  -1;
59 }
60 
61 bool SelectRangeTool::isUsable() const
62 {
63  return ( mByteArrayView && mByteArrayModel && (mByteArrayModel->size() > 0) );
64 }
65 
66 bool SelectRangeTool::isApplyable() const
67 {
68  const int start = finalTargetSelectionStart();
69  const int end = finalTargetSelectionEnd();
70 
71  return ( mByteArrayView && mByteArrayModel
72  && (start <= end)
73  && (0 <= start) && (start < mByteArrayModel->size())
74  && (0 <= end) && (end < mByteArrayModel->size()) );
75 }
76 
77 QString SelectRangeTool::title() const { return i18nc("@title:window of the tool to select a range", "Select"); }
78 
79 void SelectRangeTool::setTargetModel( AbstractModel* model )
80 {
81  const bool oldIsUsable = isUsable();
82  const bool oldIsApplyable = isApplyable();
83 
84  if( mByteArrayView ) mByteArrayView->disconnect( this );
85  if( mByteArrayModel ) mByteArrayModel->disconnect( this );
86 
87  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
88 
89  ByteArrayDocument* document =
90  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
91  mByteArrayModel = document ? document->content() : 0;
92 
93  if( mByteArrayView && mByteArrayModel )
94  {
95  connect( mByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)),
96  SLOT(onContentsChanged()) );
97  // TODO: update isApplyable on cursor movement and size changes
98  }
99 
100  const bool newIsUsable = isUsable();
101  const bool newIsApplyable = isApplyable();
102  if( oldIsUsable != newIsUsable )
103  emit isUsableChanged( newIsUsable );
104  if( oldIsApplyable != newIsApplyable )
105  emit isApplyableChanged( newIsApplyable );
106 }
107 
108 void SelectRangeTool::setTargetStart( Okteta::Address start )
109 {
110  const bool oldIsApplyable = isApplyable();
111 
112  mTargetStart = start;
113 
114  const bool newIsApplyable = isApplyable();
115  if( oldIsApplyable != newIsApplyable )
116  emit isApplyableChanged( newIsApplyable );
117 }
118 
119 void SelectRangeTool::setTargetEnd( Okteta::Address end )
120 {
121  const bool oldIsApplyable = isApplyable();
122 
123  mTargetEnd = end;
124 
125  const bool newIsApplyable = isApplyable();
126  if( oldIsApplyable != newIsApplyable )
127  emit isApplyableChanged( newIsApplyable );
128 }
129 
130 void SelectRangeTool::setIsEndRelative( bool isEndRelative )
131 {
132  const bool oldIsApplyable = isApplyable();
133 
134  mIsEndRelative = isEndRelative;
135 
136  const bool newIsApplyable = isApplyable();
137  if( oldIsApplyable != newIsApplyable )
138  emit isApplyableChanged( newIsApplyable );
139 }
140 
141 void SelectRangeTool::setIsEndBackwards( bool isEndBackwards )
142 {
143  const bool oldIsApplyable = isApplyable();
144 
145  mIsEndBackwards = isEndBackwards;
146 
147  const bool newIsApplyable = isApplyable();
148  if( oldIsApplyable != newIsApplyable )
149  emit isApplyableChanged( newIsApplyable );
150 }
151 
152 
153 void SelectRangeTool::select()
154 {
155  const int start = finalTargetSelectionStart();
156  const int end = finalTargetSelectionEnd();
157 
158  mByteArrayView->setSelection( start, end );
159  mByteArrayView->setFocus();
160 }
161 
162 
163 int SelectRangeTool::finalTargetSelectionStart() const
164 {
165  const int end =
166  (! mByteArrayView) ? -1 :
167  mIsEndRelative && mIsEndBackwards ? mTargetStart - mTargetEnd + 1 :
168  mTargetStart;
169 
170  return end;
171 }
172 
173 int SelectRangeTool::finalTargetSelectionEnd() const
174 {
175  const int end =
176  (! mByteArrayView) ? -1 :
177  mIsEndRelative ?
178  ( mIsEndBackwards ? mTargetStart :
179  mTargetStart + mTargetEnd - 1 ) :
180  mTargetEnd;
181 
182  return end;
183 }
184 
185 void SelectRangeTool::onContentsChanged()
186 {
187  // TODO: find status before content changed, e.g. by caching
188  emit isUsableChanged( isUsable() );
189 }
190 
191 SelectRangeTool::~SelectRangeTool()
192 {
193 }
194 
195 }
Kasten2::ByteArrayView::setFocus
virtual void setFocus()
Definition: bytearrayview.cpp:155
Kasten2::SelectRangeTool::currentSelectionStart
int currentSelectionStart() const
Definition: selectrangetool.cpp:48
Okteta::Address
qint32 Address
Definition: address.h:34
abstractbytearraymodel.h
Kasten2::ByteArrayView::setSelection
void setSelection(Okteta::Address start, Okteta::Address end)
Definition: bytearrayview.cpp:276
Kasten2::SelectRangeTool::setIsEndRelative
void setIsEndRelative(bool isEndRelative)
Definition: selectrangetool.cpp:130
Kasten2::SelectRangeTool::title
virtual QString title() const
Definition: selectrangetool.cpp:77
Kasten2::SelectRangeTool::SelectRangeTool
SelectRangeTool()
Definition: selectrangetool.cpp:37
selectrangetool.h
Kasten2::SelectRangeTool::isEndRelative
bool isEndRelative() const
Definition: selectrangetool.h:104
KDE::Range::start
T start() const
Definition: range.h:86
Kasten2::SelectRangeTool::isApplyable
bool isApplyable() const
Definition: selectrangetool.cpp:66
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
Kasten2::ByteArrayView::selection
Okteta::AddressRange selection() const
Definition: bytearrayview.cpp:271
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
KDE::Range::end
T end() const
Definition: range.h:88
Okteta::ArrayChangeMetricsList
Definition: arraychangemetricslist.h:36
Kasten2::SelectRangeTool::isUsableChanged
void isUsableChanged(bool isUsable)
Kasten2::AbstractModel::findBaseModel
T findBaseModel() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:93
Kasten2::SelectRangeTool::currentSelectionEnd
int currentSelectionEnd() const
Definition: selectrangetool.cpp:54
Kasten2::SelectRangeTool::isUsable
bool isUsable() const
Definition: selectrangetool.cpp:61
Kasten2::SelectRangeTool::setTargetStart
void setTargetStart(Okteta::Address start)
Definition: selectrangetool.cpp:108
Kasten2::SelectRangeTool::~SelectRangeTool
virtual ~SelectRangeTool()
Definition: selectrangetool.cpp:191
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::SelectRangeTool::setTargetEnd
void setTargetEnd(Okteta::Address end)
Definition: selectrangetool.cpp:119
Kasten2::SelectRangeTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: selectrangetool.cpp:79
Kasten2::SelectRangeTool::setIsEndBackwards
void setIsEndBackwards(bool isEndBackwards)
Definition: selectrangetool.cpp:141
bytearraydocument.h
Kasten2::ByteArrayView::startOffset
Okteta::Address startOffset() const
Definition: bytearrayview.cpp:236
Kasten2::SelectRangeTool::select
void select()
Definition: selectrangetool.cpp:153
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::SelectRangeTool::isApplyableChanged
void isApplyableChanged(bool isApplyable)
Kasten2::SelectRangeTool::isEndBackwards
bool isEndBackwards() const
Definition: selectrangetool.h:105
bytearrayview.h
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