• 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
  • poddecoder
podtableview.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 2006-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 "podtableview.h"
24 
25 // controller
26 #include "podtablemodel.h"
27 #include "poddelegate.h"
28 #include "poddecodertool.h"
29 // KDE
30 #include <KComboBox>
31 #include <KLocale>
32 #include <KMessageBox>
33 // Qt
34 #include <QtGui/QLabel>
35 #include <QtGui/QLayout>
36 #include <QtGui/QCheckBox>
37 #include <QtGui/QTreeView>
38 #include <QtGui/QHeaderView>
39 #include <QtGui/QFocusEvent>
40 #include <QtGui/QFontMetrics>
41 
42 #include <KDebug>
43 namespace Kasten2
44 {
45 
46 PODTableView::PODTableView( PODDecoderTool* tool, QWidget* parent )
47  : QWidget( parent ),
48  mTool( tool ),
49  mPODTableViewFocusChild( 0 )
50 {
51  QBoxLayout* baseLayout = new QVBoxLayout( this );
52  baseLayout->setMargin( 0 );
53 
54  // table
55  mPODTableModel = new PODTableModel( mTool, this );
56  mPODTableView = new QTreeView( this );
57  mPODTableView->setObjectName( QLatin1String( "PODTable" ) );
58  mPODTableView->setRootIsDecorated( false );
59  mPODTableView->setAlternatingRowColors( true );
60  mPODTableView->setItemsExpandable( false );
61  mPODTableView->setUniformRowHeights( true );
62  mPODTableView->setAllColumnsShowFocus( true );
63  mPODTableView->setItemDelegate( new PODDelegate(mTool, this) );
64  mPODTableView->setEditTriggers( QAbstractItemView::EditKeyPressed | QAbstractItemView::DoubleClicked );
65  mPODTableView->setDragEnabled( true );
66  mPODTableView->setSortingEnabled( false );
67  mPODTableView->setModel( mPODTableModel );
68  mPODTableView->installEventFilter( this );
69  QHeaderView* header = mPODTableView->header();
70  header->setResizeMode( QHeaderView::Interactive );
71  header->setStretchLastSection( false );
72  connect( mPODTableView->selectionModel(),
73  SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
74  SLOT(onCurrentRowChanged(QModelIndex,QModelIndex)) );
75 
76  baseLayout->addWidget( mPODTableView, 10 );
77 
78  // settings
79  QBoxLayout *settingsLayout = new QHBoxLayout();
80  settingsLayout->setMargin( 0 );
81 
82  mByteOrderSelection = new KComboBox( this );
83  mByteOrderSelection->addItem( i18nc("@item:inlistbox","Little-endian") ); // add first for index
84  mByteOrderSelection->addItem( i18nc("@item:inlistbox","Big-endian") ); // add second for index
85  mByteOrderSelection->setCurrentIndex( mTool->byteOrder() );
86  connect( mByteOrderSelection, SIGNAL(activated(int)),
87  mTool, SLOT(setByteOrder(int)));
88  const QString byteOrderToolTip =
89  i18nc( "@info:tooltip",
90  "The byte order to use for decoding the bytes." );
91  mByteOrderSelection->setToolTip( byteOrderToolTip );
92  settingsLayout->addWidget( mByteOrderSelection );
93 
94  QLabel* unsignedAsHexLabel = new QLabel( i18nc("@option:check","Unsigned as hexadecimal:"), this );
95  settingsLayout->addWidget( unsignedAsHexLabel );
96 
97  mUnsignedAsHexCheck = new QCheckBox( this );
98  mUnsignedAsHexCheck->setChecked( mTool->isUnsignedAsHex() );
99  connect( mUnsignedAsHexCheck, SIGNAL(toggled(bool)),
100  mTool, SLOT(setUnsignedAsHex(bool)) );
101  unsignedAsHexLabel->setBuddy( mUnsignedAsHexCheck );
102  const QString unsignedAsHexToolTip =
103  i18nc( "@info:tooltip",
104  "Sets whether the values of the unsigned integer types are shown as hexadecimal instead of as decimal." );
105  unsignedAsHexLabel->setToolTip( unsignedAsHexToolTip );
106  mUnsignedAsHexCheck->setToolTip( unsignedAsHexToolTip );
107  settingsLayout->addWidget( mUnsignedAsHexCheck );
108  settingsLayout->addStretch();
109 
110  baseLayout->addLayout( settingsLayout );
111 
112  mTool->setDifferentSizeDialog( this );
113 
114  //resize to fit width of contents
115  //this is much (!) faster than using setResizeMode(QHeaderView::ResizeToContents)
116  QFont f;
117  QFontMetrics metrics( f );
118  //ideally we should check the width of the longest translated string, but this should be wide enough for most
119  //anyway this is just an initial setting and the width can be changed manually
120  header->resizeSection( 0, metrics.width( QLatin1String( "Hexadecimal 8-bit" ) ) + 30 );
121  header->resizeSection( 1, metrics.width( QLatin1String( "1.01234567890123456789e-111" ) ) + 15 );
122 }
123 
124 Answer PODTableView::query( int newValueSize, int oldValueSize, int sizeLeft )
125 {
126  Q_UNUSED( sizeLeft );
127 
128  Answer answer;
129 
130  int messageBoxAnswer;
131  if( newValueSize < oldValueSize )
132  {
133  const QString message =
134  i18nc( "@info",
135  "The new value needs <emphasis>fewer</emphasis> bytes (%1 instead of %2).<nl/>"
136  "Keep the unused bytes or remove them?", newValueSize, oldValueSize );
137 
138  const KGuiItem keepGuiItem =
139  KGuiItem( i18nc("@action:button keep the unused bytes",
140  "&Keep"),
141  QString(),
142  i18nc("@info:tooltip",
143  "Keep the unused bytes with their old values.") );
144 
145  messageBoxAnswer = KMessageBox::warningYesNoCancel( this, message, mTool->title(),
146  keepGuiItem,
147  KStandardGuiItem::remove() );
148  }
149  else
150  {
151  const QString message =
152  i18nc( "@info",
153  "The new value needs <emphasis>more</emphasis> bytes (%1 instead of %2).<nl/>"
154  "Overwrite the following bytes or insert new ones as needed?", newValueSize, oldValueSize );
155 
156  messageBoxAnswer = KMessageBox::warningYesNoCancel( this, message, mTool->title(),
157  KStandardGuiItem::overwrite(),
158  KStandardGuiItem::insert() );
159  }
160 
161  answer = (messageBoxAnswer == KMessageBox::Yes) ? Overwrite :
162  (messageBoxAnswer == KMessageBox::No) ? AdaptSize :
163  Cancel;
164  return answer;
165 }
166 
167 bool PODTableView::eventFilter( QObject* object, QEvent* event )
168 {
169  if( object == mPODTableView )
170  {
171  if( event->type() == QEvent::FocusIn )
172  {
173  const QModelIndex current = mPODTableView->selectionModel()->currentIndex();
174  const int podId = current.row();
175  if( current.isValid() && mTool->isApplyable() && ! mTool->value(podId).isNull() )
176  mTool->markPOD( podId );
177  }
178  else if( event->type() == QEvent::FocusOut )
179  {
180  QWidget* tableViewFocusWidget = mPODTableView->focusWidget();
181  const bool subChildHasFocus = ( tableViewFocusWidget != mPODTableView );
182  if( subChildHasFocus )
183  {
184  mPODTableViewFocusChild = tableViewFocusWidget;
185  mPODTableViewFocusChild->installEventFilter( this );
186  }
187  else if( mTool->isApplyable() )
188  mTool->unmarkPOD();
189  }
190  }
191  else if( object == mPODTableViewFocusChild )
192  {
193  // TODO: it is only assumed the edit widget will be removed if it loses the focus
194  if( event->type() == QEvent::FocusOut )
195  {
196  if( ! mPODTableView->hasFocus() && mTool->isApplyable() )
197  mTool->unmarkPOD();
198  mPODTableViewFocusChild->removeEventFilter( this );
199  mPODTableViewFocusChild = 0;
200  }
201  }
202 
203  return QWidget::eventFilter( object, event );
204 }
205 
206 void PODTableView::onCurrentRowChanged( const QModelIndex& current, const QModelIndex& previous )
207 {
208  Q_UNUSED( previous )
209 
210  if( ! mTool->isApplyable() )
211  return;
212 
213  const int podId = current.row();
214  if( current.isValid() && ! mTool->value(podId).isNull() )
215  mTool->markPOD( podId );
216  else
217  mTool->unmarkPOD();
218 }
219 
220 PODTableView::~PODTableView() {}
221 
222 }
Kasten2::PODDecoderTool::markPOD
void markPOD(int podId)
Definition: poddecodertool.cpp:317
Kasten2::PODDecoderTool::title
virtual QString title() const
Definition: poddecodertool.cpp:93
poddelegate.h
Kasten2::PODDecoderTool::unmarkPOD
void unmarkPOD()
Definition: poddecodertool.cpp:325
podtableview.h
Kasten2::PODDecoderTool
Definition: poddecodertool.h:51
QWidget
Kasten2::AdaptSize
Definition: kastencore.h:70
Kasten2::Yes
Definition: kastencore.h:62
QObject
Kasten2::PODDecoderTool::isApplyable
bool isApplyable() const
Definition: poddecodertool.cpp:95
poddecodertool.h
Kasten2::PODTableView::eventFilter
virtual bool eventFilter(QObject *object, QEvent *event)
Definition: podtableview.cpp:167
Kasten2::PODTableView::query
virtual Answer query(int newValueSize, int oldValueSize, int sizeLeft)
Definition: podtableview.cpp:124
Kasten2::PODDecoderTool::value
QVariant value(int podId) const
Definition: poddecodertool.cpp:220
Kasten2::Answer
Answer
Definition: kastencore.h:58
Kasten2::PODDelegate
Definition: poddelegate.h:36
Kasten2::Cancel
Definition: kastencore.h:60
Kasten2::PODTableView::PODTableView
PODTableView(PODDecoderTool *tool, QWidget *parent=0)
Definition: podtableview.cpp:46
podtablemodel.h
Kasten2::PODTableModel
Definition: podtablemodel.h:36
Kasten2::No
Definition: kastencore.h:63
Kasten2::PODDecoderTool::isUnsignedAsHex
bool isUnsignedAsHex() const
Definition: poddecodertool.h:132
Kasten2::PODDecoderTool::byteOrder
Okteta::ByteOrder byteOrder() const
Definition: poddecodertool.h:133
Kasten2::Overwrite
Definition: kastencore.h:68
Kasten2::PODTableView
Definition: podtableview.h:44
Kasten2::PODDecoderTool::setDifferentSizeDialog
void setDifferentSizeDialog(AbstractDifferentSizeDialog *differentSizeDialog)
Definition: poddecodertool.cpp:164
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