• 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
  • bytetable
bytetableview.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 2007,2009 Friedrich W. H. Kossebau <kossebau@kde.org>
5  Copyright 2011 Alex Richardson <alex.richardson@gmx.de>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) version 3, or any
11  later version accepted by the membership of KDE e.V. (or its
12  successor approved by the membership of KDE e.V.), which shall
13  act as a proxy defined in Section 6 of version 3 of the license.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #include "bytetableview.h"
25 
26 // tool
27 #include "bytetabletool.h"
28 #include "bytetablemodel.h"
29 #include "bytetableviewsettings.h"
30 // KDE
31 #include <KPushButton>
32 #include <KLocale>
33 #include <KStandardGuiItem>
34 #include <KGlobalSettings>
35 //#include <KDebug>
36 #include <KApplication>
37 #include <KIntNumInput>
38 // Qt
39 #include <QtGui/QLabel>
40 #include <QtGui/QLayout>
41 #include <QtGui/QHeaderView>
42 #include <QtGui/QTreeView>
43 
44 
45 namespace Kasten2
46 {
47 
48 ByteTableView::ByteTableView( ByteTableTool *tool, QWidget* parent )
49  : AbstractToolWidget( parent ),
50  mTool( tool )
51 {
52  QVBoxLayout *baseLayout = new QVBoxLayout( this );
53  baseLayout->setMargin( 0 );
54 
55  mByteTableView = new QTreeView( this );
56  connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
57  SLOT(setFixedFontByGlobalSettings()) );
58  connect( KGlobalSettings::self(), SIGNAL(kdisplayFontChanged()),
59  SLOT(resizeColumnsWidth()) );
60  connect( KGlobalSettings::self(), SIGNAL(kdisplayStyleChanged()),
61  SLOT(resizeColumnsWidth()) );
62  setFixedFontByGlobalSettings(); //do this before setting model
63  mByteTableView->setObjectName( QLatin1String( "ByteTable" ) );
64  mByteTableView->setRootIsDecorated( false );
65  mByteTableView->setItemsExpandable( false );
66  mByteTableView->setUniformRowHeights( true );
67  mByteTableView->setAllColumnsShowFocus( true );
68  mByteTableView->setSortingEnabled( false );
69  QHeaderView* header = mByteTableView->header();
70  header->setFont( font() );
71  header->setResizeMode( QHeaderView::Interactive );
72  header->setStretchLastSection( false );
73  mByteTableView->setModel( mTool->byteTableModel() );
74  connect( mByteTableView, SIGNAL(doubleClicked(QModelIndex)),
75  SLOT(onDoubleClicked(QModelIndex)) );
76 
77  baseLayout->addWidget( mByteTableView, 10 );
78 
79  QHBoxLayout *insertLayout = new QHBoxLayout();
80 
81  QLabel *label = new QLabel( i18nc("@label:spinbox number of bytes to insert","Number:"), this );
82  insertLayout->addWidget( label );
83 
84  mInsertCountEdit = new KIntNumInput( this );
85  mInsertCountEdit->setRange( 1, INT_MAX );
86  mInsertCountEdit->setValue( 1 );
87  mInsertCountEdit->setSuffix( ki18np(" byte"," bytes") );
88  label->setBuddy( mInsertCountEdit );
89  insertLayout->addWidget( mInsertCountEdit );
90  const QString insertCountToolTip =
91  i18nc( "@info:tooltip",
92  "The number with which the byte currently selected in the table will be inserted." );
93  label->setToolTip( insertCountToolTip );
94  mInsertCountEdit->setToolTip( insertCountToolTip );
95 
96  insertLayout->addStretch();
97 
98  mInsertButton = new KPushButton( KStandardGuiItem::insert(), this );
99  mInsertButton->setEnabled( mTool->hasWriteable() );
100  connect( mTool, SIGNAL(hasWriteableChanged(bool)), mInsertButton, SLOT(setEnabled(bool)) );
101  connect( mInsertButton, SIGNAL(clicked(bool)), SLOT(onInsertClicked()) );
102  const QString insertButtonToolTip =
103  i18nc( "@info:tooltip",
104  "Inserts the byte currently selected in the table with the given number." );
105  mInsertButton->setToolTip( insertButtonToolTip );
106  addButton( mInsertButton, AbstractToolWidget::Default );
107  insertLayout->addWidget( mInsertButton );
108 
109  baseLayout->addLayout( insertLayout );
110 
111  //if nothing has changed reuse the old values. This means the bytetable is fully constructed
112  //after ~3ms and not 800 as it was before. If the saved values can not be reused it takes ~100ms
113  const QList<int> columnsWidth = ByteTableViewSettings::columnsWidth();
114  const QString styleName = KApplication::style()->objectName();
115  const QString fixedFontData = KGlobalSettings::fixedFont().toString();
116  if ( columnsWidth.size() < ByteTableModel::NoOfIds || styleName != ByteTableViewSettings::style()
117  || fixedFontData != ByteTableViewSettings::fixedFont() )
118  {
119  resizeColumnsWidth();
120  }
121  else
122  {
123  for (int i = 0; i < ByteTableModel::NoOfIds; ++i)
124  {
125  header->resizeSection( i, columnsWidth.at( i ) );
126  }
127  }
128 }
129 
130 void ByteTableView::resizeColumnsWidth()
131 {
132  //kDebug() << "recalculating header width";
133  QHeaderView* header = mByteTableView->header();
134  for (int i = 0; i < ByteTableModel::NoOfIds; ++i)
135  {
136  if ( i == ByteTableModel::CharacterId )
137  {
138  mByteTableView->resizeColumnToContents( i );
139  continue;
140  }
141  //since all indexes in one row have same number of chars it is enough to calculate one row
142  //this speeds up calculating the width from 800ms to 100ms
143  const QModelIndex index = mTool->byteTableModel()->index( 0, i );
144  const int indexWidthHint = mByteTableView->sizeHintForIndex( index ).width();
145  const int headerWidthHint = header->sectionSizeHint( i );
146  header->resizeSection(i, qMax( indexWidthHint, headerWidthHint) );
147  }
148 }
149 
150 
151 void ByteTableView::setFixedFontByGlobalSettings()
152 {
153  mByteTableView->setFont( KGlobalSettings::fixedFont() );
154 }
155 
156 void ByteTableView::onDoubleClicked( const QModelIndex &index )
157 {
158  if( !mTool->hasWriteable() )
159  return;
160 
161  const unsigned char byte = index.row();
162  mTool->insert( byte, mInsertCountEdit->value() );
163 }
164 
165 void ByteTableView::onInsertClicked()
166 {
167  const unsigned char byte = mByteTableView->currentIndex().row();
168  mTool->insert( byte, mInsertCountEdit->value() );
169 }
170 
171 ByteTableView::~ByteTableView()
172 {
173  QList<int> columnsWidth;
174  const QHeaderView* header = mByteTableView->header();
175  for (int i = 0 ; i < ByteTableModel::NoOfIds; ++i)
176  {
177  columnsWidth.append( header->sectionSize( i ) );
178  }
179  ByteTableViewSettings::setColumnsWidth( columnsWidth );
180  ByteTableViewSettings::setStyle( KApplication::style()->objectName() );
181  ByteTableViewSettings::setFixedFont( KGlobalSettings::fixedFont().toString() );
182  ByteTableViewSettings::self()->writeConfig();
183 }
184 
185 }
Kasten2::ByteTableView::~ByteTableView
virtual ~ByteTableView()
Definition: bytetableview.cpp:171
Kasten2::ByteTableTool
Definition: bytetabletool.h:44
Kasten2::ByteTableViewSettings::columnsWidth
static QList< int > columnsWidth()
Get ColumnsWidth.
Definition: bytetableviewsettings.h:32
bytetableview.h
Kasten2::ByteTableViewSettings::style
static QString style()
Get Style.
Definition: bytetableviewsettings.h:51
Kasten2::ByteTableViewSettings::setColumnsWidth
static void setColumnsWidth(const QList< int > &v)
Set ColumnsWidth.
Definition: bytetableviewsettings.h:22
Kasten2::AbstractToolWidget::addButton
void addButton(QPushButton *button, DefaultType defaultType=AutoDefault)
Definition: abstracttoolwidget.cpp:37
Kasten2::ByteTableView::ByteTableView
ByteTableView(ByteTableTool *tool, QWidget *parent=0)
Definition: bytetableview.cpp:48
Kasten2::ByteTableView::onInsertClicked
void onInsertClicked()
Definition: bytetableview.cpp:165
QWidget
bytetabletool.h
Kasten2::ByteTableModel::NoOfIds
Definition: bytetablemodel.h:50
Kasten2::AbstractToolWidget
Definition: abstracttoolwidget.h:41
Kasten2::ByteTableModel::CharacterId
Definition: bytetablemodel.h:49
bytetableviewsettings.h
Kasten2::ByteTableViewSettings::fixedFont
static QString fixedFont()
Get FixedFont.
Definition: bytetableviewsettings.h:70
Kasten2::ByteTableViewSettings::self
static ByteTableViewSettings * self()
Definition: bytetableviewsettings.cpp:25
Kasten2::ByteTableTool::insert
void insert(unsigned char byte, int count)
Definition: bytetabletool.cpp:90
Kasten2::AbstractToolWidget::Default
Definition: abstracttoolwidget.h:46
bytetablemodel.h
Kasten2::ByteTableViewSettings::setStyle
static void setStyle(const QString &v)
Set Style.
Definition: bytetableviewsettings.h:41
Kasten2::ByteTableTool::byteTableModel
ByteTableModel * byteTableModel() const
Definition: bytetabletool.cpp:50
Kasten2::ByteTableViewSettings::setFixedFont
static void setFixedFont(const QString &v)
Set FixedFont.
Definition: bytetableviewsettings.h:60
Kasten2::ByteTableView::onDoubleClicked
void onDoubleClicked(const QModelIndex &index)
Definition: bytetableview.cpp:156
ScriptValueConverter::toString
StringDataInformation * toString(const QScriptValue &value, const ParserInfo &info)
Kasten2::ByteTableTool::hasWriteable
bool hasWriteable() const
Definition: bytetabletool.cpp:51
QList< int >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 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