• 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
  • gotooffset
gotooffsettool.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 "gotooffsettool.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 GotoOffsetTool::GotoOffsetTool()
38  : mTargetOffset( 0 ),
39  mIsRelative( false ),
40  mIsSelectionToExtent( false ),
41  mIsBackwards( false ),
42  mByteArrayView( 0 ),
43  mByteArrayModel( 0 )
44 {
45  setObjectName( QLatin1String( "GotoOffset" ) );
46 }
47 
48 int GotoOffsetTool::currentOffset() const
49 {
50  return mByteArrayView ?
51  mByteArrayView->startOffset() + mByteArrayView->cursorPosition() :
52  -1;
53 }
54 
55 bool GotoOffsetTool::isUsable() const
56 {
57  return ( mByteArrayView && mByteArrayModel && (mByteArrayModel->size() > 0) );
58 }
59 
60 bool GotoOffsetTool::isApplyable() const
61 {
62  const int newPosition = finalTargetOffset();
63 
64  return ( mByteArrayView && mByteArrayModel
65  && (0 <= newPosition) && (newPosition <= mByteArrayModel->size()) );
66 }
67 
68 QString GotoOffsetTool::title() const { return i18nc("@title:window of the tool to set a new offset for the cursor", "Goto"); }
69 
70 void GotoOffsetTool::setTargetModel( AbstractModel* model )
71 {
72  const bool oldIsUsable = isUsable();
73  const bool oldIsApplyable = isApplyable();
74 
75  if( mByteArrayView ) mByteArrayView->disconnect( this );
76  if( mByteArrayModel ) mByteArrayModel->disconnect( this );
77 
78  mByteArrayView = model ? model->findBaseModel<ByteArrayView*>() : 0;
79 
80  ByteArrayDocument* document =
81  mByteArrayView ? qobject_cast<ByteArrayDocument*>( mByteArrayView->baseModel() ) : 0;
82  mByteArrayModel = document ? document->content() : 0;
83 
84  if( mByteArrayView && mByteArrayModel )
85  {
86  connect( mByteArrayModel, SIGNAL(contentsChanged(Okteta::ArrayChangeMetricsList)),
87  SLOT(onContentsChanged()) );
88  // TODO: update isApplyable on cursor movement and size changes
89  }
90 
91  const bool newIsUsable = isUsable();
92  const bool newIsApplyable = isApplyable();
93  if( oldIsUsable != newIsUsable )
94  emit isUsableChanged( newIsUsable );
95  if( oldIsApplyable != newIsApplyable )
96  emit isApplyableChanged( newIsApplyable );
97 }
98 
99 void GotoOffsetTool::setTargetOffset( Okteta::Address targetOffset )
100 {
101  const bool oldIsApplyable = isApplyable();
102 
103  mTargetOffset = targetOffset;
104 
105  const bool newIsApplyable = isApplyable();
106  if( oldIsApplyable != newIsApplyable )
107  emit isApplyableChanged( newIsApplyable );
108 }
109 
110 void GotoOffsetTool::setIsRelative( bool isRelative )
111 {
112  const bool oldIsApplyable = isApplyable();
113 
114  mIsRelative = isRelative;
115 
116  const bool newIsApplyable = isApplyable();
117  if( oldIsApplyable != newIsApplyable )
118  emit isApplyableChanged( newIsApplyable );
119 }
120 
121 void GotoOffsetTool::setIsSelectionToExtent( bool isSelectionToExtent )
122 {
123  const bool oldIsApplyable = isApplyable();
124 
125  mIsSelectionToExtent = isSelectionToExtent;
126 
127  const bool newIsApplyable = isApplyable();
128  if( oldIsApplyable != newIsApplyable )
129  emit isApplyableChanged( newIsApplyable );
130 }
131 
132 void GotoOffsetTool::setIsBackwards( bool isBackwards )
133 {
134  const bool oldIsApplyable = isApplyable();
135 
136  mIsBackwards = isBackwards;
137 
138  const bool newIsApplyable = isApplyable();
139  if( oldIsApplyable != newIsApplyable )
140  emit isApplyableChanged( newIsApplyable );
141 }
142 
143 
144 void GotoOffsetTool::gotoOffset()
145 {
146  const int newPosition = finalTargetOffset();
147 
148  if( mIsSelectionToExtent )
149  mByteArrayView->setSelectionCursorPosition( newPosition );
150  else
151  mByteArrayView->setCursorPosition( newPosition );
152  mByteArrayView->setFocus();
153 }
154 
155 
156 int GotoOffsetTool::finalTargetOffset() const
157 {
158  const int newPosition =
159  (! mByteArrayView) ? -1 :
160  mIsRelative ?
161  ( mIsBackwards ? mByteArrayView->cursorPosition() - mTargetOffset :
162  mByteArrayView->cursorPosition() + mTargetOffset ) :
163  ( mIsBackwards ? mByteArrayModel->size() - mTargetOffset :
164  mTargetOffset );
165 
166  return newPosition;
167 }
168 
169 void GotoOffsetTool::onContentsChanged()
170 {
171  // TODO: find status before content changed, e.g. by caching
172  emit isUsableChanged( isUsable() );
173 }
174 
175 GotoOffsetTool::~GotoOffsetTool()
176 {
177 }
178 
179 }
Kasten2::ByteArrayView::setFocus
virtual void setFocus()
Definition: bytearrayview.cpp:155
Kasten2::GotoOffsetTool::isApplyable
bool isApplyable() const
Definition: gotooffsettool.cpp:60
Okteta::Address
qint32 Address
Definition: address.h:34
abstractbytearraymodel.h
Kasten2::GotoOffsetTool::isApplyableChanged
void isApplyableChanged(bool isApplyable)
Kasten2::GotoOffsetTool::isSelectionToExtent
bool isSelectionToExtent() const
Definition: gotooffsettool.h:102
Kasten2::GotoOffsetTool::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: gotooffsettool.cpp:70
Kasten2::GotoOffsetTool::gotoOffset
void gotoOffset()
Definition: gotooffsettool.cpp:144
Kasten2::GotoOffsetTool::GotoOffsetTool
GotoOffsetTool()
Definition: gotooffsettool.cpp:37
Kasten2::GotoOffsetTool::targetOffset
int targetOffset() const
Definition: gotooffsettool.h:100
Kasten2::AbstractModel::baseModel
AbstractModel * baseModel() const
Definition: abstractmodel.cpp:40
gotooffsettool.h
Okteta::AbstractByteArrayModel::size
virtual Size size() const =0
Kasten2::ByteArrayView::cursorPosition
Okteta::Address cursorPosition() const
Definition: bytearrayview.cpp:227
Kasten2::GotoOffsetTool::title
virtual QString title() const
Definition: gotooffsettool.cpp:68
Kasten2::GotoOffsetTool::currentOffset
int currentOffset() const
Definition: gotooffsettool.cpp:48
Okteta::ArrayChangeMetricsList
Definition: arraychangemetricslist.h:36
Kasten2::GotoOffsetTool::setIsBackwards
void setIsBackwards(bool isBackwards)
Definition: gotooffsettool.cpp:132
Kasten2::ByteArrayView::setCursorPosition
void setCursorPosition(Okteta::Address cursorPosition)
Definition: bytearrayview.cpp:217
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::GotoOffsetTool::isBackwards
bool isBackwards() const
Definition: gotooffsettool.h:103
Kasten2::GotoOffsetTool::setIsSelectionToExtent
void setIsSelectionToExtent(bool isSelectionToExtent)
Definition: gotooffsettool.cpp:121
Kasten2::GotoOffsetTool::setTargetOffset
void setTargetOffset(Okteta::Address targetOffset)
Definition: gotooffsettool.cpp:99
Kasten2::GotoOffsetTool::isUsableChanged
void isUsableChanged(bool isUsable)
Kasten2::ByteArrayDocument
Definition: bytearraydocument.h:54
Kasten2::AbstractModel
Definition: abstractmodel.h:40
Kasten2::GotoOffsetTool::~GotoOffsetTool
virtual ~GotoOffsetTool()
Definition: gotooffsettool.cpp:175
bytearraydocument.h
Kasten2::ByteArrayView::startOffset
Okteta::Address startOffset() const
Definition: bytearrayview.cpp:236
Kasten2::GotoOffsetTool::setIsRelative
void setIsRelative(bool isRelative)
Definition: gotooffsettool.cpp:110
Kasten2::ByteArrayView
Definition: bytearrayview.h:51
Kasten2::GotoOffsetTool::isRelative
bool isRelative() const
Definition: gotooffsettool.h:101
Kasten2::GotoOffsetTool::isUsable
bool isUsable() const
Definition: gotooffsettool.cpp:55
Kasten2::ByteArrayView::setSelectionCursorPosition
void setSelectionCursorPosition(Okteta::Address index)
Definition: bytearrayview.cpp:222
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:08 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