2
This file is part of the Okteta Kasten module, part of the KDE project.
4
Copyright 2010 Friedrich W. H. Kossebau <kossebau@kde.org>
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.
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.
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/>.
23
#include "viewprofileedit.h"
26
#include <bytearrayviewprofile.h>
28
#include <charcodec.h>
31
#include <KIntNumInput>
34
#include <QtGui/QVBoxLayout>
35
#include <QtGui/QGroupBox>
36
#include <QtGui/QFormLayout>
37
#include <QtGui/QCheckBox>
44
listIndexFromByteArrayCodingsFlags( int byteArrayCodingsFlags )
46
return byteArrayCodingsFlags - 1;
50
byteArrayCodingsFlagsFromListIndex( int listIndex )
56
ViewProfileEdit::ViewProfileEdit( QWidget* parent )
59
QVBoxLayout* layout = new QVBoxLayout( this );
62
QFormLayout* titleFormLayout = new QFormLayout;
63
// char for non-printable bytes
64
mTitleEdit = new KLineEdit( this );
65
titleFormLayout->addRow( i18n("Title:"), mTitleEdit );
68
QGroupBox* displayBox = new QGroupBox( this );
69
displayBox->setTitle( i18n("Display") );
70
QFormLayout* displayBoxFormLayout = new QFormLayout( displayBox );
72
mLineOffsetShownCheckBox = new QCheckBox( displayBox );
73
displayBoxFormLayout->addRow( i18n("Show Line Offset:"), mLineOffsetShownCheckBox );
74
// values or char shown
75
mValuesCharsShownComboBox = new KComboBox( displayBox );
76
QStringList valuesCharsList;
77
valuesCharsList.append( i18nc("@item:","Values") );
78
valuesCharsList.append( i18nc("@item:","Chars") );
79
valuesCharsList.append( i18nc("@item:","Values & Chars") );
80
mValuesCharsShownComboBox->addItems( valuesCharsList );
81
displayBoxFormLayout->addRow( i18n("Show Values or Chars:"), mValuesCharsShownComboBox );
83
const QString displayModeLabel =
84
i18nc( "@label:listbox ",
85
"Show with Rows or Columns::" );
86
mDisplayModeComboBox = new KComboBox( displayBox );
87
QStringList displayModeList;
88
displayModeList.append( i18nc("@item:","Columns") );
89
displayModeList.append( i18nc("@item:","Rows") );
90
mDisplayModeComboBox->addItems( displayModeList );
91
displayBoxFormLayout->addRow( displayModeLabel, mDisplayModeComboBox );
94
QGroupBox* layoutBox = new QGroupBox( this );
95
layoutBox->setTitle( i18n("Layout") );
96
QFormLayout* layoutBoxFormLayout = new QFormLayout( layoutBox );
98
mLineBreakComboBox = new KComboBox( layoutBox );
99
QStringList lineBreakList;
100
lineBreakList.append( i18nc("@item:inmenu The layout will not change on size changes.",
102
lineBreakList.append( i18nc("@item:inmenu The layout will adapt to the size, but only with complete groups of bytes.",
103
"Wrap Only Complete Byte Groups") );
104
lineBreakList.append( i18nc("@item:inmenu The layout will adapt to the size and fit in as much bytes per line as possible.",
106
mLineBreakComboBox->addItems( lineBreakList );
107
connect( mLineBreakComboBox, SIGNAL(currentIndexChanged(int)),
108
SLOT(onLineBreakIndexChanged(int)) );
109
layoutBoxFormLayout->addRow( i18n("Break lines:"), mLineBreakComboBox );
111
mGroupedBytesCountEdit = new KIntNumInput( this );
112
mGroupedBytesCountEdit->setRange( 0, INT_MAX );
113
mGroupedBytesCountEdit->setSuffix( ki18np(" byte"," bytes") );
114
const QString noGroupingText = i18nc( "@label",
116
mGroupedBytesCountEdit->setSpecialValueText( noGroupingText );
117
const QString groupedBytesCountLabel =
118
i18nc( "@label:spinbox number of bytes which are grouped",
119
"Bytes per Group:" );
120
layoutBoxFormLayout->addRow( groupedBytesCountLabel, mGroupedBytesCountEdit );
122
mBytesPerLineEdit = new KIntNumInput( this );
123
mBytesPerLineEdit->setRange( 1, INT_MAX );
124
mBytesPerLineEdit->setSuffix( ki18np(" byte"," bytes") );
125
const QString bytesPerLineLabel =
126
i18nc( "@label:spinbox number of bytes which are shown per line",
128
layoutBoxFormLayout->addRow( bytesPerLineLabel, mBytesPerLineEdit );
131
QGroupBox* valuesBox = new QGroupBox( this );
132
valuesBox->setTitle( i18n("Values") );
133
QFormLayout* valuesBoxFormLayout = new QFormLayout( valuesBox );
135
mValueCodingComboBox = new KComboBox( valuesBox );
136
QStringList valueCodingList;
137
valueCodingList.append( i18nc("@item:inmenu encoding of the bytes as values in the hexadecimal format","Hexadecimal") );
138
valueCodingList.append( i18nc("@item:inmenu encoding of the bytes as values in the decimal format", "Decimal") );
139
valueCodingList.append( i18nc("@item:inmenu encoding of the bytes as values in the octal format", "Octal") );
140
valueCodingList.append( i18nc("@item:inmenu encoding of the bytes as values in the binary format", "Binary") );
141
mValueCodingComboBox->addItems( valueCodingList );
142
valuesBoxFormLayout->addRow( i18n("Coding:"), mValueCodingComboBox );
145
QGroupBox* charsBox = new QGroupBox( this );
146
charsBox->setTitle( i18n("Chars") );
147
QFormLayout* charsBoxFormLayout = new QFormLayout( charsBox );
149
mCharCodingComboBox = new KComboBox( charsBox );
150
mCharCodingComboBox->addItems( Okteta::CharCodec::codecNames() );
151
charsBoxFormLayout->addRow( i18n("Coding:"), mCharCodingComboBox );
153
mNonPrintableShownCheckBox = new QCheckBox( charsBox );
154
charsBoxFormLayout->addRow( i18n("Show Non-printable:"), mNonPrintableShownCheckBox );
155
// char for non-printable bytes
156
mNonPrintableCharEdit = new KLineEdit( charsBox ); // TODO: use a validator to ensure always one char
157
mNonPrintableCharEdit->setMaxLength( 1 );
158
charsBoxFormLayout->addRow( i18n("Char for non-printable bytes:"), mNonPrintableCharEdit );
159
// char for undefined bytes
160
mUndefinedCharEdit = new KLineEdit( charsBox ); // TODO: use a validator to ensure always one char
161
mUndefinedCharEdit->setMaxLength( 1 );
162
charsBoxFormLayout->addRow( i18n("Char for undefined bytes:"), mUndefinedCharEdit );
164
layout->addLayout( titleFormLayout );
165
layout->addWidget( displayBox );
166
layout->addWidget( layoutBox );
167
layout->addWidget( valuesBox );
168
layout->addWidget( charsBox );
171
ByteArrayViewProfile ViewProfileEdit::viewProfile() const
173
ByteArrayViewProfile viewProfile;
174
viewProfile.setViewProfileTitle( mTitleEdit->text() );
176
viewProfile.toggleOffsetColumn( mLineOffsetShownCheckBox->isChecked() );
177
const int visibleByteArrayCodings =
178
byteArrayCodingsFlagsFromListIndex( mValuesCharsShownComboBox->currentIndex() );
179
viewProfile.setVisibleByteArrayCodings( visibleByteArrayCodings );
180
viewProfile.setViewModus( mDisplayModeComboBox->currentIndex() );
182
viewProfile.setLayoutStyle( mLineBreakComboBox->currentIndex() );
183
viewProfile.setNoOfGroupedBytes( mGroupedBytesCountEdit->value() );
184
viewProfile.setNoOfBytesPerLine( mBytesPerLineEdit->value() );
186
viewProfile.setValueCoding( mValueCodingComboBox->currentIndex() );
188
viewProfile.setCharCoding( mCharCodingComboBox->currentText() );
189
viewProfile.setShowsNonprinting( mNonPrintableShownCheckBox->isChecked() );
190
viewProfile.setSubstituteChar( mNonPrintableCharEdit->text()[0] ); // TODO: need make sure is one char
191
viewProfile.setUndefinedChar( mUndefinedCharEdit->text()[0] ); // TODO: need make sure is one char
196
void ViewProfileEdit::setViewProfile( const ByteArrayViewProfile& viewProfile )
198
mTitleEdit->setText( viewProfile.viewProfileTitle() );
200
mLineOffsetShownCheckBox->setChecked( viewProfile.offsetColumnVisible() );
201
const int valuesCharsShownListIndex =
202
listIndexFromByteArrayCodingsFlags( viewProfile.visibleByteArrayCodings() );
203
mValuesCharsShownComboBox->setCurrentIndex( valuesCharsShownListIndex );
204
mDisplayModeComboBox->setCurrentIndex( viewProfile.viewModus() );
206
mLineBreakComboBox->setCurrentIndex( viewProfile.layoutStyle() );
207
mGroupedBytesCountEdit->setValue( viewProfile.noOfGroupedBytes() );
208
mBytesPerLineEdit->setValue( viewProfile.noOfBytesPerLine() );
210
mValueCodingComboBox->setCurrentIndex( viewProfile.valueCoding() );
212
mCharCodingComboBox->setCurrentItem( viewProfile.charCodingName() );
213
mNonPrintableShownCheckBox->setChecked( viewProfile.showsNonprinting() );
214
mNonPrintableCharEdit->setText( viewProfile.substituteChar() );
215
mUndefinedCharEdit->setText( viewProfile.undefinedChar() );
218
void ViewProfileEdit::onLineBreakIndexChanged( int lineBreakIndex )
220
const bool isLineBreakByByte = ( lineBreakIndex == 0 );
222
mBytesPerLineEdit->setEnabled( isLineBreakByByte );
225
ViewProfileEdit::~ViewProfileEdit()