1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/***************************************************************************
khepart.cpp - description
-------------------
begin : Don Jun 19 2003
copyright : (C) 2003 by Friedrich W. H. Kossebau
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License version 2 as published by the Free Software Foundation. *
* *
***************************************************************************/
// kde specific
#include <tdelocale.h>
//#include <kinstance.h>
#include <tdeaction.h>
#include <kstdaction.h>
//#include <tdeglobalsettings.h>
// app specific
#include "khexedit.h"
#include "kcharcodec.h"
#include "khepartfactory.h"
#include "khebrowserextension.h"
#include "khepart.h"
using namespace KHE;
static const char RCFileName[] = "khexedit2partui.rc";
KHexEditPart::KHexEditPart( TQWidget *ParentWidget, const char *WidgetName,
TQObject *Parent, const char *Name,
bool BrowserViewWanted )
: KParts::ReadOnlyPart( Parent, Name )
{
setInstance( KHexEditPartFactory::instance() );
HexEdit = new KHexEdit( &Wrapping, ParentWidget, WidgetName );
HexEdit->setNoOfBytesPerLine( 16 );
HexEdit->setBufferSpacing( 3, 4, 10 );
HexEdit->setShowUnprintable( false );
// notify the part that this is our internal widget
setWidget( HexEdit );
setupActions( BrowserViewWanted );
if( CopyAction )
{
connect( HexEdit, TQ_SIGNAL(copyAvailable(bool)), CopyAction,TQ_SLOT(setEnabled(bool)) );
connect( HexEdit, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(slotSelectionChanged()) );
CopyAction->setEnabled( false );
}
// plugin to browsers
if( BrowserViewWanted )
new KHexEditBrowserExtension( this );
}
KHexEditPart::~KHexEditPart()
{
}
/*
void KHexEditPart::setupTools( bool BrowserViewWanted )
{
if( !BrowserViewWanted ) new TDEClipboardTool( this );
new KZoomToolet( this );
new TDESelectToolet( this );
new KHEValueCodingToolet( this );
new KHECharEncodingToolet( this );
new KHEResizeStyleToolet( this );
new KHEColumnToggleToolet( this );
}
*/
void KHexEditPart::setupActions( bool BrowserViewWanted )
{
TDEActionCollection *AC = actionCollection();
// create our actions
CopyAction = BrowserViewWanted ? 0 : KStdAction::copy( HexEdit, TQ_SLOT(copy()), AC );
KStdAction::selectAll( this, TQ_SLOT(slotSelectAll()), AC );
KStdAction::deselect( this, TQ_SLOT(slotUnselect()), AC );
// value encoding
CodingAction = new TDESelectAction( i18n("&Value Coding"), 0, AC, "view_valuecoding" );
TQStringList List;
List.append( i18n("&Hexadecimal") );
List.append( i18n("&Decimal") );
List.append( i18n("&Octal") );
List.append( i18n("&Binary") );
CodingAction->setItems( List );
connect( CodingAction, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotSetCoding(int)) );
// document encoding
EncodingAction = new TDESelectAction( i18n("&Char Encoding"), 0, AC, "view_charencoding" );
EncodingAction->setItems( KCharCodec::codecNames() );
connect( EncodingAction, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotSetEncoding(int)) );
ShowUnprintableAction = new TDEToggleAction( i18n("Show &Unprintable Chars (<32)"), 0, this, TQ_SLOT(slotSetShowUnprintable()), actionCollection(), "view_showunprintable" );
KStdAction::zoomIn( HexEdit, TQ_SLOT(zoomIn()), actionCollection() );
KStdAction::zoomOut( HexEdit, TQ_SLOT(zoomOut()), actionCollection() );
// resize style
ResizeStyleAction = new TDESelectAction( i18n("&Resize Style"), 0, AC, "resizestyle" );
List.clear();
List.append( i18n("&No Resize") );
List.append( i18n("&Lock Groups") );
List.append( i18n("&Full Size Usage") );
ResizeStyleAction->setItems( List );
connect( ResizeStyleAction, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotSetResizeStyle(int)) );
ShowOffsetColumnAction = new TDEToggleAction( i18n("&Line Offset"), Key_F11, this, TQ_SLOT(slotToggleOffsetColumn()), AC, "view_lineoffset" );
// show buffer columns
ToggleColumnsAction = new TDESelectAction( i18n("&Columns"), 0, AC, "togglecolumns" );
List.clear();
List.append( i18n("&Values Column") );
List.append( i18n("&Chars Column") );
List.append( i18n("&Both Columns") );
ToggleColumnsAction->setItems( List );
connect( ToggleColumnsAction, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotToggleValueCharColumns(int)) );
fitActionSettings();
// set our XML-UI resource file
setXMLFile( RCFileName );
}
void KHexEditPart::fitActionSettings()
{
ShowOffsetColumnAction->setChecked( HexEdit->offsetColumnVisible() );
ShowUnprintableAction->setChecked( HexEdit->showUnprintable() );
CodingAction->setCurrentItem( (int)HexEdit->coding() );
EncodingAction->setCurrentItem( KCharCodec::codecNames().findIndex(HexEdit->encodingName()) );
ResizeStyleAction->setCurrentItem( (int)HexEdit->resizeStyle() );
ToggleColumnsAction->setCurrentItem( (int)HexEdit->visibleBufferColumns()-1 );
}
bool KHexEditPart::openFile()
{
Wrapping.open( m_file );
HexEdit->setDataBuffer( &Wrapping );
HexEdit->setCursorPosition( 0 );
HexEdit->selectAll( false );
return true;
}
void KHexEditPart::slotSelectionChanged()
{
bool State = HexEdit->hasSelectedData();
CopyAction->setEnabled( State );
}
void KHexEditPart::slotSelectAll()
{
HexEdit->selectAll( true );
}
void KHexEditPart::slotUnselect()
{
HexEdit->selectAll( false );
}
void KHexEditPart::slotSetCoding( int Coding )
{
HexEdit->setCoding( (KHexEdit::KCoding)Coding );
}
void KHexEditPart::slotSetShowUnprintable()
{
HexEdit->setShowUnprintable( ShowUnprintableAction->isChecked() );
}
void KHexEditPart::slotToggleOffsetColumn()
{
HexEdit->toggleOffsetColumn( ShowOffsetColumnAction->isChecked() );
}
void KHexEditPart::slotSetResizeStyle( int ResizeStyle )
{
HexEdit->setResizeStyle( (KHexEdit::KResizeStyle)ResizeStyle );
}
void KHexEditPart::slotSetEncoding( int Encoding )
{
HexEdit->setEncoding( KCharCodec::codecNames()[Encoding] );
}
void KHexEditPart::slotToggleValueCharColumns( int VisibleColumns)
{
HexEdit->showBufferColumns( VisibleColumns+1 );
}
#include "khepart.moc"
|