• 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
gotooffsetview.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 "gotooffsetview.h"
24 
25 // tool
26 #include "gotooffsettool.h"
27 // lib
28 #include <addresscombobox.h>
29 #include <addressvalidator.h>
30 // KDE
31 #include <KPushButton>
32 #include <KGuiItem>
33 #include <KLocale>
34 // Qt
35 #include <QtGui/QCheckBox>
36 #include <QtGui/QLabel>
37 #include <QtGui/QLayout>
38 
39 
40 namespace Kasten2
41 {
42 
43 GotoOffsetView::GotoOffsetView( GotoOffsetTool* tool, QWidget* parent )
44  : AbstractToolWidget( parent ),
45  mTool( tool )
46 {
47  QHBoxLayout* baseLayout = new QHBoxLayout( this );
48  baseLayout->setMargin( 0 );
49 
50  // offset
51  QHBoxLayout* offsetLayout = new QHBoxLayout();
52  offsetLayout->setMargin( 0 );
53 
54  QLabel* label = new QLabel( i18nc("@label:listbox","O&ffset:"), this );
55  mAddressEdit = new Okteta::AddressComboBox( this );
56  connect( mAddressEdit, SIGNAL(addressChanged(Okteta::Address)),
57  mTool, SLOT(setTargetOffset(Okteta::Address)) );
58  connect( mAddressEdit, SIGNAL(formatChanged(int)),
59  SLOT(onFormatChanged(int)) );
60  connect( mAddressEdit, SIGNAL(addressTypeChanged(int)),
61  SLOT(onAddressTypeChanged(int)) );
62  label->setBuddy( mAddressEdit );
63  const QString inputWhatsThis =
64  i18nc( "@info:whatsthis","Enter an offset to go to, or select a previous offset from the list." );
65  label->setWhatsThis( inputWhatsThis );
66  mAddressEdit->setWhatsThis( inputWhatsThis );
67 
68  offsetLayout->addWidget( label );
69  offsetLayout->addWidget( mAddressEdit, 1 );
70 
71  baseLayout->addLayout( offsetLayout, 1 );
72  baseLayout->setAlignment( offsetLayout, Qt::AlignTop );
73 
74  setFocusProxy( mAddressEdit ); // TODO: see how KDialog does it, e.g. see if there is already a focuswidget as child
75 
76  // options
77  QVBoxLayout* optionsLayout = new QVBoxLayout();
78  optionsLayout->setMargin( 0 );
79 
80  mAtCursorCheckBox = new QCheckBox( i18nc("@option:check","From c&ursor"), this );
81  mAtCursorCheckBox->setWhatsThis(
82  i18nc("@info:whatsthis","Go relative from the current cursor location and not absolute.") );
83  connect( mAtCursorCheckBox, SIGNAL(toggled(bool)),
84  mTool, SLOT(setIsRelative(bool)) );
85  mExtendSelectionCheckBox = new QCheckBox( i18nc("@option:check","&Extend selection"), this );
86  mExtendSelectionCheckBox->setWhatsThis(
87  i18nc("@info:whatsthis","Extend the selection by the cursor move.") );
88  connect( mExtendSelectionCheckBox, SIGNAL(toggled(bool)),
89  mTool, SLOT(setIsSelectionToExtent(bool)) );
90  mBackwardsCheckBox = new QCheckBox( i18nc("@option:check","&Backwards"), this );
91  mBackwardsCheckBox->setWhatsThis(
92  i18nc("@info:whatsthis","Go backwards from the end or the current cursor location.") );
93  connect( mBackwardsCheckBox, SIGNAL(toggled(bool)), mTool, SLOT(setIsBackwards(bool)) );
94 
95  QHBoxLayout* upperOptionsLayout = new QHBoxLayout();
96  upperOptionsLayout->setMargin( 0 );
97  upperOptionsLayout->addWidget( mAtCursorCheckBox );
98  upperOptionsLayout->addWidget( mBackwardsCheckBox );
99 
100  optionsLayout->addLayout( upperOptionsLayout );
101  optionsLayout->addWidget( mExtendSelectionCheckBox );
102 
103  baseLayout->addLayout( optionsLayout );
104 
105  // Goto button
106  const KGuiItem gotoGuiItem =
107  KGuiItem( i18nc("@action:button","&Go"),
108  QLatin1String("go-jump"),
109  i18nc("@info:tooltip",
110  "Go to the Offset"),
111  i18nc("@info:whatsthis",
112  "If you press the <interface>Go</interface> "
113  "button, the cursor will be moved in the document to or, "
114  "on your option, by the offset you entered above.") );
115  mGotoButton = new KPushButton( gotoGuiItem, this );
116  connect( mGotoButton, SIGNAL(clicked(bool)), SLOT(onGotoButtonClicked()) );
117  addButton( mGotoButton, AbstractToolWidget::Default );
118  baseLayout->addWidget( mGotoButton );
119  baseLayout->setAlignment( mGotoButton, Qt::AlignTop );
120 
121  setTabOrder( mAddressEdit, mAtCursorCheckBox );
122  setTabOrder( mAtCursorCheckBox, mBackwardsCheckBox );
123  setTabOrder( mBackwardsCheckBox, mExtendSelectionCheckBox );
124  setTabOrder( mExtendSelectionCheckBox, mGotoButton );
125 
126  connect( mTool, SIGNAL(isApplyableChanged(bool)),
127  SLOT(onApplyableChanged(bool)) );
128 
129  onApplyableChanged( mTool->isApplyable() );
130 }
131 
132 
133 void GotoOffsetView::onApplyableChanged( bool isApplyable )
134 {
135  // TODO: set error tooltip, like offset out of range or no document
136  // TODO: set color flag to offset input
137  mGotoButton->setEnabled( isApplyable );
138 }
139 
140 
141 void GotoOffsetView::onGotoButtonClicked()
142 {
143  // TODO: collect recently used offset in tool instead?
144  mAddressEdit->rememberCurrentAddress();
145 
146  mTool->gotoOffset();
147 // emit toolUsed();
148 }
149 
150 void GotoOffsetView::onAddressTypeChanged( int addressType )
151 {
152  const bool isNotExpression = (mAddressEdit->format() != 2);
153  if( isNotExpression
154  || addressType == Okteta::AddressValidator::InvalidAddressType )
155  return;
156 
157  bool fromCursor = false;
158  bool backwards = false;
159 
160  if( addressType == Okteta::AddressValidator::AbsoluteAddress )
161  {
162  fromCursor = false;
163  backwards = false; // TODO: there is no way yet for: absolute from end
164  }
165  else if( addressType == Okteta::AddressValidator::RelativeForwards )
166  {
167  fromCursor = true;
168  backwards = false;
169  }
170  else if( addressType == Okteta::AddressValidator::RelativeBackwards )
171  {
172  fromCursor = true;
173  backwards = true;
174  }
175 
176  mAtCursorCheckBox->setChecked( fromCursor );
177  mTool->setIsRelative( fromCursor );
178  mBackwardsCheckBox->setChecked( backwards );
179  mTool->setIsBackwards( backwards );
180 }
181 
182 void GotoOffsetView::onFormatChanged( int formatIndex )
183 {
184  //TODO: make sure Expr is always at index 2
185  const bool isNotExpression = (formatIndex != 2);
186 
187  mAtCursorCheckBox->setEnabled( isNotExpression );
188  mBackwardsCheckBox->setEnabled( isNotExpression );
189 }
190 
191 GotoOffsetView::~GotoOffsetView() {}
192 
193 }
Kasten2::GotoOffsetTool::isApplyable
bool isApplyable() const
Definition: gotooffsettool.cpp:60
Okteta::Address
qint32 Address
Definition: address.h:34
Kasten2::GotoOffsetView::~GotoOffsetView
virtual ~GotoOffsetView()
Definition: gotooffsetview.cpp:191
Okteta::AddressValidator::AbsoluteAddress
Definition: addressvalidator.h:47
Okteta::AddressValidator::RelativeBackwards
Definition: addressvalidator.h:47
Kasten2::AbstractToolWidget::addButton
void addButton(QPushButton *button, DefaultType defaultType=AutoDefault)
Definition: abstracttoolwidget.cpp:37
Kasten2::GotoOffsetTool::gotoOffset
void gotoOffset()
Definition: gotooffsettool.cpp:144
QWidget
Kasten2::AbstractToolWidget
Definition: abstracttoolwidget.h:41
gotooffsettool.h
Kasten2::GotoOffsetView::GotoOffsetView
GotoOffsetView(GotoOffsetTool *tool, QWidget *parent=0)
Definition: gotooffsetview.cpp:43
Kasten2::AbstractToolWidget::Default
Definition: abstracttoolwidget.h:46
Okteta::AddressComboBox::format
int format() const
Definition: addresscombobox.cpp:55
Kasten2::GotoOffsetTool::setIsBackwards
void setIsBackwards(bool isBackwards)
Definition: gotooffsettool.cpp:132
Okteta::AddressValidator::RelativeForwards
Definition: addressvalidator.h:47
Okteta::AddressComboBox
Definition: addresscombobox.h:42
addressvalidator.h
addresscombobox.h
Okteta::AddressComboBox::rememberCurrentAddress
void rememberCurrentAddress()
Definition: addresscombobox.cpp:63
Kasten2::GotoOffsetTool
Definition: gotooffsettool.h:44
Kasten2::GotoOffsetTool::setIsRelative
void setIsRelative(bool isRelative)
Definition: gotooffsettool.cpp:110
Okteta::AddressValidator::InvalidAddressType
Definition: addressvalidator.h:47
gotooffsetview.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