31 #include <KPushButton>
33 #include <KStandardGuiItem>
34 #include <KGlobalSettings>
36 #include <KApplication>
37 #include <KIntNumInput>
39 #include <QtGui/QLabel>
40 #include <QtGui/QLayout>
41 #include <QtGui/QHeaderView>
42 #include <QtGui/QTreeView>
52 QVBoxLayout *baseLayout =
new QVBoxLayout(
this );
53 baseLayout->setMargin( 0 );
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();
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 );
74 connect( mByteTableView, SIGNAL(doubleClicked(QModelIndex)),
77 baseLayout->addWidget( mByteTableView, 10 );
79 QHBoxLayout *insertLayout =
new QHBoxLayout();
81 QLabel *label =
new QLabel( i18nc(
"@label:spinbox number of bytes to insert",
"Number:"),
this );
82 insertLayout->addWidget( label );
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 );
96 insertLayout->addStretch();
98 mInsertButton =
new KPushButton( KStandardGuiItem::insert(),
this );
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 );
107 insertLayout->addWidget( mInsertButton );
109 baseLayout->addLayout( insertLayout );
114 const QString styleName = KApplication::style()->objectName();
115 const QString fixedFontData = KGlobalSettings::fixedFont().toString();
119 resizeColumnsWidth();
125 header->resizeSection( i, columnsWidth.at( i ) );
130 void ByteTableView::resizeColumnsWidth()
133 QHeaderView* header = mByteTableView->header();
138 mByteTableView->resizeColumnToContents( i );
144 const int indexWidthHint = mByteTableView->sizeHintForIndex( index ).width();
145 const int headerWidthHint = header->sectionSizeHint( i );
146 header->resizeSection(i, qMax( indexWidthHint, headerWidthHint) );
151 void ByteTableView::setFixedFontByGlobalSettings()
153 mByteTableView->setFont( KGlobalSettings::fixedFont() );
161 const unsigned char byte = index.row();
162 mTool->
insert( byte, mInsertCountEdit->value() );
167 const unsigned char byte = mByteTableView->currentIndex().row();
168 mTool->
insert( byte, mInsertCountEdit->value() );
174 const QHeaderView* header = mByteTableView->header();
177 columnsWidth.append( header->sectionSize( i ) );
static QList< int > columnsWidth()
Get ColumnsWidth.
static QString style()
Get Style.
static void setColumnsWidth(const QList< int > &v)
Set ColumnsWidth.
ByteTableView(ByteTableTool *tool, QWidget *parent=0)
static QString fixedFont()
Get FixedFont.
static ByteTableViewSettings * self()
static void setStyle(const QString &v)
Set Style.
static void setFixedFont(const QString &v)
Set FixedFont.
void onDoubleClicked(const QModelIndex &index)
StringDataInformation * toString(const QScriptValue &value, const ParserInfo &info)