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.
371 lines
8.2 KiB
371 lines
8.2 KiB
15 years ago
|
/*
|
||
|
* khexedit - Versatile hex editor
|
||
|
* Copyright (C) 1999-2000 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.
|
||
|
*
|
||
|
*/
|
||
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include "hexmanagerwidget.h"
|
||
|
#include "searchbar.h"
|
||
|
|
||
13 years ago
|
CHexManagerWidget::CHexManagerWidget( TQWidget *parent, const char *name,
|
||
15 years ago
|
EConversionPosition conversionPosition,
|
||
|
EPosition tabBarPosition,
|
||
|
EPosition searchBarPosition )
|
||
13 years ago
|
: TQWidget( parent, name )
|
||
15 years ago
|
{
|
||
|
mValid = false;
|
||
|
|
||
|
mEditor = new CHexEditorWidget( this );
|
||
|
mTabBar = new CTabBar( this );
|
||
|
mTabBar->hide();
|
||
|
mSearchBar = 0;
|
||
|
|
||
|
mConverter = new CHexToolWidget( this );
|
||
|
|
||
15 years ago
|
connect( mEditor->view(), TQT_SIGNAL(fileName(const TQString &, bool)),
|
||
|
this, TQT_SLOT( addName(const TQString &)));
|
||
|
connect( mEditor->view(), TQT_SIGNAL( fileClosed(const TQString &)),
|
||
|
this, TQT_SLOT( removeName(const TQString &)));
|
||
|
connect( mEditor->view(),TQT_SIGNAL(fileRename(const TQString &,const TQString &)),
|
||
|
this, TQT_SLOT(changeName(const TQString &,const TQString &)));
|
||
|
connect( mEditor->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
|
||
|
mConverter, TQT_SLOT( cursorChanged( SCursorState & ) ) );
|
||
|
connect( mConverter, TQT_SIGNAL( closed(void) ),
|
||
|
this, TQT_SIGNAL( conversionClosed(void) ) );
|
||
|
connect( mTabBar, TQT_SIGNAL(selected(const TQString &)),
|
||
|
this, TQT_SLOT(open(const TQString &)));
|
||
15 years ago
|
|
||
|
mValid = true;
|
||
|
setConversionVisibility( conversionPosition );
|
||
|
setTabBarPosition( tabBarPosition );
|
||
|
setSearchBarPosition( searchBarPosition );
|
||
|
}
|
||
|
|
||
|
|
||
|
CHexManagerWidget::~CHexManagerWidget( void )
|
||
|
{
|
||
|
delete mEditor;
|
||
|
delete mTabBar;
|
||
|
delete mConverter;
|
||
|
}
|
||
|
|
||
|
|
||
|
void CHexManagerWidget::updateLayout( void )
|
||
|
{
|
||
|
if( mValid == false ) { return; }
|
||
|
|
||
13 years ago
|
delete layout();
|
||
15 years ago
|
TQVBoxLayout *vlay = new TQVBoxLayout( this, 0, 0 );
|
||
15 years ago
|
|
||
|
if( mSearchBar && mSearchBarPosition == AboveEditor )
|
||
|
{
|
||
|
vlay->addWidget( mSearchBar );
|
||
|
}
|
||
|
|
||
|
if( mTabPosition == AboveEditor )
|
||
|
{
|
||
|
vlay->addWidget( mTabBar );
|
||
|
vlay->addWidget( mEditor, 1 );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
vlay->addWidget( mEditor, 1 );
|
||
|
vlay->addWidget( mTabBar );
|
||
|
}
|
||
|
|
||
|
if( mSearchBar && mSearchBarPosition == BelowEditor )
|
||
|
{
|
||
|
vlay->addWidget( mSearchBar );
|
||
|
}
|
||
|
|
||
|
if( mConversionPosition == Embed )
|
||
|
{
|
||
|
vlay->addWidget( mConverter );
|
||
|
}
|
||
|
vlay->activate(); // Required in this case
|
||
|
}
|
||
|
|
||
|
|
||
|
void CHexManagerWidget::setConversionVisibility( EConversionPosition position )
|
||
|
{
|
||
|
if( mValid == false )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if( mConversionPosition == position )
|
||
|
{
|
||
|
if( mConversionPosition == Float )
|
||
|
{
|
||
|
mConverter->raise();
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
mConversionPosition = position;
|
||
|
if( mConversionPosition == Hide )
|
||
|
{
|
||
|
mConverter->hide();
|
||
|
}
|
||
|
else if( mConversionPosition == Float )
|
||
|
{
|
||
15 years ago
|
TQPoint point = mapToGlobal( TQPoint(0,0) );
|
||
13 years ago
|
TQRect rect = geometry();
|
||
15 years ago
|
TQPoint p;
|
||
15 years ago
|
|
||
13 years ago
|
p.setX(point.x() + rect.width()/2 - mConverter->minimumSize().width()/2);
|
||
|
p.setY(point.y() + rect.height()/2 - mConverter->minimumSize().height()/2);
|
||
|
mConverter->resize( mConverter->minimumSize() );
|
||
15 years ago
|
mConverter->reparent( 0, WStyle_Customize | WStyle_DialogBorder, p, true );
|
||
|
mConverter->setCaption(kapp->makeStdCaption(i18n("Conversion")));
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mConversionPosition = Embed;
|
||
13 years ago
|
uint utilHeight = mConverter->minimumSize().height();
|
||
15 years ago
|
TQPoint p( 0, height() - utilHeight );
|
||
15 years ago
|
mConverter->reparent( this, 0, p, true );
|
||
|
}
|
||
|
|
||
|
updateLayout();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CHexManagerWidget::setTabBarPosition( EPosition position )
|
||
|
{
|
||
|
mTabPosition = position;
|
||
|
if( mTabPosition != HideItem && mTabBar->count() > 0 )
|
||
|
{
|
||
|
if( mTabPosition == AboveEditor )
|
||
|
{
|
||
15 years ago
|
mTabBar->setShape( TQTabBar::RoundedAbove );
|
||
15 years ago
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
mTabBar->setShape( TQTabBar::RoundedBelow );
|
||
15 years ago
|
}
|
||
|
mTabBar->show();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mTabBar->hide();
|
||
|
}
|
||
|
|
||
|
updateLayout();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CHexManagerWidget::setSearchBarPosition( EPosition position )
|
||
|
{
|
||
|
mSearchBarPosition = position;
|
||
|
if( position != HideItem )
|
||
|
{
|
||
|
if( mSearchBar == 0 )
|
||
|
{
|
||
|
mSearchBar = new CSearchBar( this );
|
||
15 years ago
|
connect( mSearchBar, TQT_SIGNAL(hidden()), this, TQT_SLOT(searchBarHidden()) );
|
||
|
connect( mSearchBar, TQT_SIGNAL(findData(SSearchControl &, uint, bool)),
|
||
|
mEditor, TQT_SLOT(findData(SSearchControl &, uint, bool)) );
|
||
|
connect( editor()->view(), TQT_SIGNAL( cursorChanged( SCursorState & ) ),
|
||
|
mSearchBar, TQT_SLOT( cursorMoved() ) );
|
||
15 years ago
|
}
|
||
|
mSearchBar->show();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if( mSearchBar != 0 )
|
||
|
{
|
||
|
mSearchBar->hide();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
updateLayout();
|
||
|
}
|
||
|
|
||
|
|
||
|
void CHexManagerWidget::searchBarHidden( void )
|
||
|
{
|
||
|
updateLayout();
|
||
|
mSearchBarPosition = HideItem;
|
||
|
emit searchBarClosed();
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CHexManagerWidget::addName( const TQString &name )
|
||
15 years ago
|
{
|
||
|
if( name.isEmpty() == true )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
mTabBar->addName( name );
|
||
|
if( mTabBar->isVisible() == false && mTabPosition != HideItem )
|
||
|
{
|
||
|
setTabBarPosition( mTabPosition );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CHexManagerWidget::removeName( const TQString &name )
|
||
15 years ago
|
{
|
||
|
mTabBar->removeName( name );
|
||
|
if( mTabBar->isVisible() == true && mTabBar->count() == 0 )
|
||
|
{
|
||
|
setTabBarPosition( mTabPosition );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CHexManagerWidget::changeName( const TQString &curName,
|
||
|
const TQString &newName )
|
||
15 years ago
|
{
|
||
|
mTabBar->changeName( curName, newName );
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CHexManagerWidget::open( const TQString &name )
|
||
15 years ago
|
{
|
||
|
mEditor->open( name, false, 0 );
|
||
|
}
|
||
|
|
||
|
|
||
|
int CHexManagerWidget::preferredWidth( void )
|
||
|
{
|
||
|
int w = mEditor->defaultTextWidth();
|
||
|
if( mConversionPosition == Embed )
|
||
|
{
|
||
13 years ago
|
int converterWidth = mConverter->sizeHint().width();
|
||
14 years ago
|
w = TQMAX( w, converterWidth );
|
||
15 years ago
|
}
|
||
|
return( w );
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
13 years ago
|
CTabBar::CTabBar( TQWidget *parent, char *name )
|
||
|
:TQTabBar( parent, name )
|
||
15 years ago
|
{
|
||
15 years ago
|
connect( this, TQT_SIGNAL(selected(int)), this, TQT_SLOT(slotSelected(int)) );
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CTabBar::addName( const TQString &name )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString n( name.right(name.length()-name.findRev('/')-1) );
|
||
15 years ago
|
|
||
13 years ago
|
TQTab *t = find( n );
|
||
15 years ago
|
if( t == 0 )
|
||
|
{
|
||
15 years ago
|
t = new TQTab();
|
||
15 years ago
|
t->setText( n);
|
||
|
int id = addTab( t );
|
||
|
mFileList.append( CFileKey(name,id) );
|
||
|
}
|
||
|
setCurrentTab(t);
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CTabBar::removeName( const TQString &name )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString n( name.right(name.length()-name.findRev('/')-1) );
|
||
|
TQTab *t = find(n);
|
||
15 years ago
|
if( t == 0 )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<CFileKey>::Iterator it;
|
||
15 years ago
|
for( it = mFileList.begin(); it != mFileList.end(); ++it )
|
||
|
{
|
||
|
if( (*it).id() == t->identifier() )
|
||
|
{
|
||
|
mFileList.remove(it);
|
||
|
removeTab(t);
|
||
14 years ago
|
layoutTabs();
|
||
15 years ago
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void CTabBar::changeName( const TQString &curName, const TQString &newName )
|
||
15 years ago
|
{
|
||
13 years ago
|
TQString n( curName.right(curName.length()-curName.findRev('/')-1) );
|
||
|
TQTab *t = find(n);
|
||
15 years ago
|
if( t == 0 )
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<CFileKey>::Iterator it;
|
||
15 years ago
|
for( it = mFileList.begin(); it != mFileList.end(); ++it )
|
||
|
{
|
||
|
if( (*it).id() == t->identifier() )
|
||
|
{
|
||
13 years ago
|
TQString m( newName.right(newName.length()-newName.findRev('/')-1) );
|
||
15 years ago
|
t->setText(m);
|
||
|
|
||
|
mFileList.remove(it);
|
||
|
mFileList.append( CFileKey(newName,t->identifier()) );
|
||
14 years ago
|
layoutTabs();
|
||
15 years ago
|
update(); // Seems to be necessary
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
13 years ago
|
TQTab *CTabBar::find( const TQString &name )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPtrList<TQTab> &list = *tabList();
|
||
|
for( TQTab *t = list.first(); t != 0; t = list.next() )
|
||
15 years ago
|
{
|
||
|
if( t->text() == name )
|
||
|
{
|
||
|
return( t );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return( 0 );
|
||
|
}
|
||
|
|
||
|
|
||
|
int CTabBar::count( void )
|
||
|
{
|
||
|
return( tabList()->count() );
|
||
|
}
|
||
|
|
||
|
|
||
|
void CTabBar::slotSelected( int id )
|
||
|
{
|
||
15 years ago
|
TQValueList<CFileKey>::Iterator it;
|
||
15 years ago
|
for( it = mFileList.begin(); it != mFileList.end(); ++it )
|
||
|
{
|
||
|
if( (*it).id() == id )
|
||
|
{
|
||
|
emit selected( (*it).filename() );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#include "hexmanagerwidget.moc"
|