You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
324 lines
6.3 KiB
324 lines
6.3 KiB
15 years ago
|
/*
|
||
|
* khexedit - Versatile hex editor
|
||
|
* Copyright (C) 1999 Espen Sand, espensa@online.no
|
||
|
*
|
||
|
* This program is free software; you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU General Public License as published by
|
||
|
* the Free Software Foundation; either version 2 of the License, or
|
||
|
* (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU General Public License
|
||
|
* along with this program; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
*
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqpainter.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdeglobalsettings.h>
|
||
15 years ago
|
|
||
|
#include "bitswapwidget.h"
|
||
|
|
||
13 years ago
|
CDigitLabel::CDigitLabel( TQWidget *parent, uint digit, const char *name )
|
||
|
:TQLabel(parent, name), mDigit( digit ), mDotPosition( 0 )
|
||
15 years ago
|
{
|
||
14 years ago
|
setFocusPolicy( TQ_StrongFocus );
|
||
15 years ago
|
initialize();
|
||
|
}
|
||
|
|
||
|
CDigitLabel::~CDigitLabel( void )
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void CDigitLabel::initialize( void )
|
||
|
{
|
||
12 years ago
|
TQFont font( TDEGlobalSettings::generalFont() );
|
||
15 years ago
|
font.setBold( true );
|
||
|
setFont( font );
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CDigitLabel::paletteChange( const TQPalette & )
|
||
15 years ago
|
{
|
||
|
update();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CDigitLabel::setValue( uint digit, bool notify )
|
||
|
{
|
||
|
if( mDigit != digit )
|
||
|
{
|
||
|
if( notify == true )
|
||
|
{
|
||
14 years ago
|
emit valueChanged( TQT_TQOBJECT(this), digit, false );
|
||
15 years ago
|
}
|
||
|
|
||
|
mDigit = digit;
|
||
|
update();
|
||
|
|
||
|
if( notify == true )
|
||
|
{
|
||
14 years ago
|
emit valueChanged( TQT_TQOBJECT(this), mDigit, true );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void CDigitLabel::setDotPosition( uint dotPosition )
|
||
|
{
|
||
|
if( mDotPosition != dotPosition )
|
||
|
{
|
||
|
mDotPosition = dotPosition;
|
||
|
update();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
13 years ago
|
TQSize CDigitLabel::sizeHint( void ) const
|
||
15 years ago
|
{
|
||
|
int h = fontMetrics().height();
|
||
15 years ago
|
TQSize s( h, h ); // Retangular
|
||
15 years ago
|
return( s );
|
||
|
}
|
||
|
|
||
|
|
||
|
#include <stdio.h>
|
||
|
|
||
|
|
||
15 years ago
|
void CDigitLabel::drawContents( TQPainter *p )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQRect cr = contentsRect();
|
||
15 years ago
|
|
||
|
if( hasFocus() == true )
|
||
|
{
|
||
13 years ago
|
p->fillRect( cr, palette().active().highlight() );
|
||
|
p->setPen( palette().active().highlightedText() );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
13 years ago
|
p->fillRect( cr, palette().active().base() );
|
||
|
p->setPen( palette().active().text() );
|
||
15 years ago
|
}
|
||
|
|
||
|
if( mDotPosition != 0 )
|
||
|
{
|
||
14 years ago
|
p->fillRect( cr.x()+2, cr.y()+2, 5, 5, TQt::red ); // UL
|
||
15 years ago
|
/*
|
||
|
if( mDotPosition == 1 )
|
||
|
{
|
||
|
p->fillRect( cr.x()+2, cr.y()+2, 5, 5, red ); // UL
|
||
|
}
|
||
|
else if( mDotPosition == 2 )
|
||
|
{
|
||
|
p->fillRect( cr.width()-7, cr.y()+2, 5, 5, red ); // UR
|
||
|
}
|
||
|
else if( mDotPosition == 3 )
|
||
|
{
|
||
|
p->fillRect( cr.x()+2, cr.height()-7, 5, 5, red ); // LL
|
||
|
}
|
||
|
else if( mDotPosition == 4 )
|
||
|
{
|
||
|
p->fillRect( cr.width()-7, cr.height()-7, 5, 5, red ); // LR
|
||
|
}
|
||
|
*/
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString text;
|
||
15 years ago
|
text.setNum( mDigit );
|
||
13 years ago
|
p->drawText( 0, 0, cr.width(), cr.height(), alignment(), text );
|
||
15 years ago
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CDigitLabel::keyPressEvent( TQKeyEvent *e )
|
||
15 years ago
|
{
|
||
|
switch ( e->key() )
|
||
|
{
|
||
|
case Key_Left:
|
||
|
case Key_Up:
|
||
14 years ago
|
emit stepCell( TQT_TQOBJECT(this), false );
|
||
15 years ago
|
break;
|
||
|
|
||
|
case Key_Right:
|
||
|
case Key_Down:
|
||
14 years ago
|
emit stepCell( TQT_TQOBJECT(this), true );
|
||
15 years ago
|
break;
|
||
|
|
||
|
case Key_Escape:
|
||
|
e->ignore(); // Allow dialog or whatever use this one
|
||
|
return;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
{
|
||
|
int val = e->text()[0].digitValue();
|
||
|
if( val >= 0 && val <= 7 )
|
||
|
{
|
||
|
setValue( val, true );
|
||
|
}
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
e->accept();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
13 years ago
|
CByteWidget::CByteWidget( TQWidget *parent, const char *name )
|
||
|
:TQWidget(parent, name)
|
||
15 years ago
|
{
|
||
15 years ago
|
mHBox = new TQHBoxLayout( this, 0 );
|
||
15 years ago
|
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
|
mDigit[i] = new CDigitLabel( this, 7-i );
|
||
|
mDigit[i]->setLineWidth( 1 );
|
||
13 years ago
|
mDigit[i]->setFixedSize( mDigit[i]->sizeHint()*2 );
|
||
15 years ago
|
mDigit[i]->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
|
||
13 years ago
|
mDigit[i]->setAlignment( AlignCenter );
|
||
15 years ago
|
connect( mDigit[i], TQT_SIGNAL(stepCell(const TQObject *, bool )),
|
||
|
this, TQT_SLOT(stepCell(const TQObject *, bool )));
|
||
|
connect( mDigit[i], TQT_SIGNAL(valueChanged(const TQObject *, uint, bool )),
|
||
|
this, TQT_SLOT(valueChanged(const TQObject *, uint, bool )));
|
||
15 years ago
|
mHBox->addWidget( mDigit[i] );
|
||
|
}
|
||
|
|
||
|
mHBox->addStretch();
|
||
|
}
|
||
|
|
||
|
CByteWidget::~CByteWidget( void )
|
||
|
{
|
||
|
for( uint i=0; i<8; i++ ) { delete mDigit[i]; }
|
||
|
delete mHBox;
|
||
|
}
|
||
|
|
||
15 years ago
|
void CByteWidget::stepCell( const TQObject *obj, bool next )
|
||
15 years ago
|
{
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
14 years ago
|
if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
|
||
15 years ago
|
{
|
||
|
if( next == true )
|
||
|
{
|
||
|
mDigit[(i+1)%8]->setFocus();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mDigit[(i+7)%8]->setFocus();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
void CByteWidget::valueChanged( const TQObject *obj, uint val, bool after )
|
||
15 years ago
|
{
|
||
|
if( after == false )
|
||
|
{
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
14 years ago
|
if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
|
||
15 years ago
|
{
|
||
|
uint tmp = 7-mDigit[i]->value();
|
||
|
mDigit[tmp]->setValue( mDigit[i]->value(), false );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
if( mDigit[7-val]->value() != val )
|
||
|
{
|
||
|
uint tmp = mDigit[7-val]->value();
|
||
|
mDigit[7-tmp]->setValue( tmp, false );
|
||
|
mDigit[7-val]->setValue( val, false );
|
||
|
}
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
setBuddy( obj );
|
||
|
|
||
|
uint pos = 1;
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
|
if( mDigit[i]->value() < (7-i) )
|
||
|
{
|
||
|
mDigit[i]->setDotPosition( pos );
|
||
|
mDigit[7-mDigit[i]->value()]->setDotPosition( pos );
|
||
|
pos++;
|
||
|
}
|
||
|
else if( mDigit[i]->value() == (7-i) )
|
||
|
{
|
||
|
mDigit[i]->setDotPosition( 0 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void CByteWidget::reset( void )
|
||
|
{
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
|
mDigit[i]->setValue( 7-i, false );
|
||
|
mDigit[i]->setDotPosition( 0 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CByteWidget::setBuddy( const TQObject *obj )
|
||
15 years ago
|
{
|
||
|
for( uint i=0; i<8; i++ )
|
||
|
{
|
||
14 years ago
|
if( TQT_BASE_OBJECT_CONST(obj) == TQT_BASE_OBJECT_CONST(mDigit[i]) )
|
||
15 years ago
|
{
|
||
|
uint val = mDigit[i]->value();
|
||
|
if( val < 8 )
|
||
|
{
|
||
|
mDigit[7-val]->setValue( 7-i, false );
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
15 years ago
|
bool CByteWidget::flag( TQByteArray &buf )
|
||
15 years ago
|
{
|
||
|
bool swapPresent = false;
|
||
|
uint i, j;
|
||
|
|
||
|
buf.resize( 8 );
|
||
|
for( i=0; i<8; buf[i++] = 0 );
|
||
|
|
||
|
for( i=j=0; i<8; i++ )
|
||
|
{
|
||
|
if( mDigit[i]->value() < (7-i) )
|
||
|
{
|
||
|
buf[j] = 7 - i; j++;
|
||
|
buf[j] = mDigit[i]->value(); j++;
|
||
|
swapPresent = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return( swapPresent );
|
||
|
}
|
||
|
|
||
|
|
||
|
#include "bitswapwidget.moc"
|