Source Code (Use browser search to find items of interest.)
Class Index
khexedit'CHexViewWidget (./kdeutils/khexedit/hexviewwidget.h:102)
class CHexViewWidget : public QFrame
{
Q_OBJECT
public:
CHexViewWidget( QWidget *parent, const char *name, CHexBuffer *hexBuffer );
~CHexViewWidget( void );
inline bool widgetValid( void );
int readFile( QFile &file, const QString &url, CProgress &p );
int insertFile( QFile &file, CProgress &p );
int writeFile( QFile &file, CProgress &p );
int newFile( const QString &url );
void closeFile( void );
void initFile( void );
void setBuffer( CHexBuffer *hexBuffer );
void updateView( bool redraw, bool fixCursor );
void selectAll( void );
void unselect( void );
void unmark( void );
uint numPage( CHexPrinter &printer );
int print( CHexPrinter &printer, CProgress &p );
int exportText( const SExportText &ex, CProgress &p );
int exportHtml( const SExportHtml &ex, CProgress &p );
int exportCArray( const SExportCArray &ex, CProgress &p );
void copy( void );
void copyText( int columnSegment=CHexBuffer::VisibleColumn );
void paste( void );
void cut( void );
void undo( void );
void redo( void );
void addBookmark( int position );
void removeBookmark( bool all );
void replaceBookmark( void );
void gotoBookmark( uint position );
void gotoNextBookmark( bool next );
void benchmark( void );
virtual void setPalette( const QPalette & );
void setInputMode( SDisplayInputMode &mode );
void setLayout( SDisplayLayout &layout );
void setCursor( const SDisplayCursor &cursor, bool updateDisplay );
void setColor( const SDisplayColor &color, bool updateDisplay );
void setFont( const SDisplayFontInfo &fontInfo, bool updateDisplay );
void setMisc( SDisplayMisc &misc );
void setInsertMode( bool insertMode );
int setEncoding( CConversion::EMode mode, CProgress &p );
void reportEncoding( void );
int findFirst( SSearchControl &sc );
int findNext( SSearchControl &sc );
int findWrap( SSearchControl &sc );
int replaceAll( SSearchControl &sc, bool init );
int replaceMarked( SSearchControl &sc );
int collectStrings( CStringCollectControl &sc );
int collectStatistic( SStatisticControl &sc, CProgress &p );
inline void setPopupMenu( QPopupMenu *popupMenu );
inline void setDocumentMenu( QPopupMenu *popupMenu );
inline int scrollBarWidth( void );
inline int dataWidth( void );
inline int defaultWidth( void );
inline uint offset( void );
inline uint bookmarkCount( void );
inline bool modified( void );
inline const QDateTime &diskModifyTime( void );
inline bool losslessEncoding( CConversion::EMode mode );
inline const SEncodeState &encoding( void );
inline bool documentPresent( void );
inline bool urlValid( void );
inline QString &url( void );
inline void setUrl( QString &url );
inline const CHexBuffer *hexBuffer( void );
public slots:
void filter( SFilterControl &fc );
void insert( SInsertData &id );
void insert( const QByteArray &buf );
void append( const QByteArray &buf );
void valueOnCursor( QByteArray &buf, uint size );
void paletteChanged( void );
void fontChanged( void );
void gotoOffset( uint offset, uint bit, bool fromCursor, bool forward );
void gotoOffset( uint offset );
void setMark( uint offset, uint size, bool moveCursor );
void setDropHighlight( bool mode );
protected:
virtual void drawFrame( QPainter *p );
virtual void paintEvent( QPaintEvent *e );
virtual void resizeEvent( QResizeEvent *e );
virtual void keyPressEvent( QKeyEvent *e );
virtual void keyReleaseEvent( QKeyEvent *e );
virtual void mousePressEvent( QMouseEvent *e );
virtual void mouseMoveEvent( QMouseEvent *e );
virtual void wheelEvent( QWheelEvent * );
virtual void mouseReleaseEvent( QMouseEvent *e );
virtual void dragEnterEvent( QDragEnterEvent *e );
virtual void dragLeaveEvent( QDragLeaveEvent *e );
virtual void dragMoveEvent( QDragMoveEvent *e );
virtual void dropEvent( QDropEvent *e );
virtual void showEvent( QShowEvent * );
virtual void timerEvent( QTimerEvent *e );
virtual void focusInEvent( QFocusEvent *e );
virtual void focusOutEvent( QFocusEvent *e );
protected slots:
void changeXPos( int pos );
void changeYPos( int pos );
void clipboardChanged( void );
signals:
void cursorChanged( SCursorState &state );
void fileState( SFileState &state );
void dataChanged( void );
void layoutChanged( const SDisplayLayout &layout );
void inputModeChanged( const SDisplayInputMode &mode );
void bookmarkChanged( QList<SCursorOffset> &list );
void editMode( CHexBuffer::EEditMode editMode );
void encodingChanged( const SEncodeState &state );
void textWidth( uint width );
void fileName( const QString &url, bool onDisk );
void fileRename( const QString &curName, const QString &newName );
void fileClosed( const QString &url );
void pleaseOpenNewFile( void );
void pleaseStepFile( bool next );
void pleaseOpenFile(const QString &url,bool reloadWhenChanged,uint offset);
private:
void setSelection( uint offset, bool init );
void setCursorPosition( int x, int y, bool init, bool cellLevel );
void updateCursor( SCursorConfig &cc, bool always = false,
bool touchSelection = true );
void setEditMode( CHexBuffer::EEditMode mode );
void paintFrame( void );
void updateFrameSize( void );
void redrawInterval( uint start, uint stop );
void redrawLines( uint docLine, int numLine );
void redrawFromOffset( uint offset, bool finishWindow );
void paintText( const QRect &r, bool expand );
void paintCursor( int cursorMode );
void toggleEditor( void );
void cursorStep( SCursorConfig &cc, uint stepSize );
void cursorLeft( SCursorConfig &cc );
void cursorRight( SCursorConfig &cc );
void cursorHome( SCursorConfig &cc );
void cursorEnd( SCursorConfig &cc );
void cursorUp( SCursorConfig &cc );
void cursorDown( SCursorConfig &cc );
void cursorPageUp( SCursorConfig &cc );
void cursorPageDown( SCursorConfig &cc );
void cursorInsert( SCursorConfig &cc );
void cursorDelete( SCursorConfig &cc );
void cursorBackspace( SCursorConfig &cc );
void cursorInput( QChar c );
int bookmarkMenu( const QString &title );
inline bool shiftButtonState( void );
inline void setupCursorTimer( void );
inline int startX( void );
inline int startY( void );
inline void setStartX( int val );
inline void setStartY( int val );
inline void updateWindow( bool completeRedraw, bool touchSelection );
inline void updateWindow( uint line );
inline void updateWindow( uint fromOffset, bool finishWindow );
inline void updateWindow( void );
inline void setTextBufferSize( void );
inline void autoCopy( void );
private slots:
void startDrag( bool asText );
private:
CScrollBar *mVertScroll;
CScrollBar *mHorzScroll;
QWidget *mCorner;
CHexBuffer *mHexBuffer;
QPixmap mTextBuffer;
SDisplayLayout mLayout;
SDisplayCursor mCursor;
SDisplayColor mColor;
SDisplayFontInfo mFontInfo;
SDisplayMisc mMisc;
QPopupMenu *mDocumentMenu;
int mScrollBarSize;
CHexBuffer::EEditMode mEditMode;
bool mShowCursor;
bool mDropHighlight;
int mCursorTimerId;
CDragManager *mDragManager;
CHexClipboard mClipConvert;
};
inline bool CHexViewWidget::shiftButtonState( void )
{
Window root = RootWindow( x11Display(), x11Screen() );
uint mask;
Window w;
int i;
XQueryPointer( x11Display(), root, &w, &w, &i, &i, &i, &i, &mask );
return( mask & ShiftMask ? true : false );
}
inline bool CHexViewWidget::widgetValid( void )
{
if( mVertScroll == 0 || mHorzScroll == 0 || mHexBuffer == 0 )
{
return( false );
}
else
{
return( true );
}
}
inline void CHexViewWidget::setupCursorTimer( void )
{
if( mCursorTimerId != 0 )
{
killTimer( mCursorTimerId );
mCursorTimerId = 0;
}
if( hasFocus() == true )
{
if( mCursor.alwaysVisible == false )
{
mCursorTimerId = startTimer( mCursor.interval );
}
mShowCursor = true;
mHexBuffer->setDisableCursor( false );
}
else
{
if( mCursor.alwaysVisible == false )
{
if( mCursor.focusMode == SDisplayCursor::ignore )
{
mCursorTimerId = startTimer( mCursor.interval );
}
}
if( mCursor.focusMode != SDisplayCursor::hide )
{
mShowCursor = true;
}
else
{
mShowCursor = false;
mHexBuffer->setDisableCursor( true );
}
}
mHexBuffer->setShowCursor( mShowCursor );
}
inline void CHexViewWidget::setPopupMenu( QPopupMenu *popupMenu )
{
KContextMenuManager::insert( this, popupMenu );
}
inline void CHexViewWidget::setDocumentMenu( QPopupMenu *popupMenu )
{
mDocumentMenu = popupMenu;
}
inline int CHexViewWidget::startX( void )
{
return( mHexBuffer->startX() );
}
inline int CHexViewWidget::startY( void )
{
return( mHexBuffer->startY() );
}
inline void CHexViewWidget::setStartX( int val )
{
mHexBuffer->setStartX( val );
}
inline void CHexViewWidget::setStartY( int val )
{
mHexBuffer->setStartY( val );
}
inline void CHexViewWidget::updateWindow( bool completeRedraw,
bool touchSelection )
{
if( completeRedraw == true )
{
SCursorConfig cc;
updateCursor( cc, true, touchSelection );
updateView( true, false );
}
else
{
SCursorConfig cc;
updateCursor( cc, false, touchSelection );
redrawFromOffset( mHexBuffer->cursorOffset(), true );
updateView( false, false );
}
emit fileState( mHexBuffer->fileState() );
}
inline void CHexViewWidget::updateWindow( uint line )
{
SCursorConfig cc;
updateCursor( cc, false, true );
if( line == mHexBuffer->cursorLine() )
{
redrawLines( line, 1 );
}
else if( line < mHexBuffer->cursorLine() )
{
redrawLines( line, mHexBuffer->cursorLine() - line );
}
else
{
redrawLines( line, line - mHexBuffer->cursorLine() );
}
emit fileState( mHexBuffer->fileState() );
}
inline void CHexViewWidget::updateWindow( uint fromOffset, bool finishWindow )
{
SCursorConfig cc;
updateCursor( cc, true, true );
updateView( false, false );
redrawFromOffset( fromOffset, finishWindow );
emit fileState( mHexBuffer->fileState() );
}
inline void CHexViewWidget::updateWindow( void )
{
setTextBufferSize();
mHexBuffer->cursorUp(0); // Makes sure cursor is visible
SCursorConfig cc;
cc.emulateControlButton( true );
updateCursor( cc, true, false );
updateView( true, false );
emit fileState( mHexBuffer->fileState() );
}
inline void CHexViewWidget::setTextBufferSize( void )
{
int w = width();
int h = mHexBuffer->lineHeight();
if( w != mTextBuffer.width() || h != mTextBuffer.height() )
{
mTextBuffer.resize( w, h );
}
}
inline void CHexViewWidget::autoCopy( void )
{
if( mMisc.autoCopyToClipboard == true )
{
copy();
}
}
inline int CHexViewWidget::scrollBarWidth( void )
{
return( mScrollBarSize );
}
inline int CHexViewWidget::dataWidth( void )
{
return( mHexBuffer->lineWidth() );
}
inline int CHexViewWidget::defaultWidth( void )
{
return( dataWidth() + scrollBarWidth() + frameWidth()*2 );
}
inline uint CHexViewWidget::offset( void )
{
return( mHexBuffer->cursorOffset() );
}
inline uint CHexViewWidget::bookmarkCount( void )
{
const QList<SCursorOffset> &list = mHexBuffer->bookmarkList();
return( list.count() );
}
inline bool CHexViewWidget::modified( void )
{
return( mHexBuffer->modified() );
}
inline const QDateTime &CHexViewWidget::diskModifyTime( void )
{
return( mHexBuffer->diskModifyTime() );
}
inline bool CHexViewWidget::losslessEncoding( CConversion::EMode mode )
{
return( mHexBuffer->losslessEncoding(mode) );
}
inline const SEncodeState &CHexViewWidget::encoding( void )
{
return( mHexBuffer->encoding() );
}
inline bool CHexViewWidget::documentPresent( void )
{
return( mHexBuffer->documentPresent() );
}
inline bool CHexViewWidget::urlValid( void )
{
return( mHexBuffer->hasFileName() );
}
inline QString &CHexViewWidget::url( void )
{
return( mHexBuffer->url() );
}
inline void CHexViewWidget::setUrl( QString &url )
{
if( mHexBuffer->url() != url )
{
emit fileRename( mHexBuffer->url(), url );
mHexBuffer->setUrl( url );
}
}
inline const CHexBuffer *CHexViewWidget::hexBuffer( void )
{
return( mHexBuffer );
}
khexedit'CHexViewWidget::CHexViewWidget() (./kdeutils/khexedit/hexviewwidget.cc:176)
CHexViewWidget::CHexViewWidget( QWidget *parent, const char *name,
CHexBuffer *hexBuffer )
: QFrame( parent, name,
#ifdef USE_NORTHWEST_GRAVITY
WNorthWestGravity
#else
0
#endif
), mScrollBarSize( 16 )
{
if( parent == 0 || hexBuffer == 0 ) { return; }
//
// Qt 2.0:
// -------
// I use the "CScrollBar" because sometimes (very seldom) when I
// do a mHorzScroll->hide() the mHorzScroll->isVisible() remains true
// in updateView() for a short while. I need the correct visibility
// because I have to redraw the area - due to the "WNorthWestGravity" usage.
//
// I tried to do a
// "while( mHorzScroll->isVisible() ) { mHorzScroll->hide(); }"
// but then the loop never ended. The "CScrollBar" emits a "hidden()"
// signal whenever is receives a QHideEvent.
//
mVertScroll = new CScrollBar( QScrollBar::Vertical, this );
if( mVertScroll == 0 ) { return; }
mHorzScroll = new CScrollBar( QScrollBar::Horizontal, this );
if( mHorzScroll == 0 ) { return; }
mCorner = new QWidget( this );
if( mCorner == 0 ) { return; }
connect( mHorzScroll, SIGNAL(valueChanged(int)), SLOT(changeXPos(int)) );
connect( mVertScroll, SIGNAL(valueChanged(int)), SLOT(changeYPos(int)) );
connect( mHorzScroll, SIGNAL(hidden()), SLOT(update()) );
connect( mVertScroll, SIGNAL(hidden()), SLOT(update()) );
mHorzScroll->hide();
mVertScroll->hide();
mDragManager = new CDragManager();
if( mDragManager == 0 ) { return; }
#ifdef USE_DRAG_MOVEMENT
mDragManager->setActivateMode( CDragManager::Movement );
#else
mDragManager->setActivateMode( CDragManager::Timer );
#endif
connect( mDragManager, SIGNAL(startDrag(bool)), SLOT(startDrag(bool)) );
setFrameStyle( QFrame::WinPanel|QFrame::Sunken );
setWFlags( WResizeNoErase );
setFocusPolicy( StrongFocus );
mHexBuffer = hexBuffer;
mHexBuffer->cursorReset();
mEditMode = mHexBuffer->editMode();
mShowCursor = false;
mCursorTimerId = 0;
mDocumentMenu = 0;
setTextBufferSize(); // Make sure there is a pixmap buffer
setStartX(0);
setStartY(0);
setAcceptDrops(true);
setDropHighlight(false); // Init state + frame shape
setBackgroundColor( mHexBuffer->backgroundColor() );
}
khexedit'CHexViewWidget::~CHexViewWidget() (./kdeutils/khexedit/hexviewwidget.cc:247)
CHexViewWidget::~CHexViewWidget( void )
{
delete mVertScroll;
delete mHorzScroll;
delete mCorner;
delete mDragManager;
}
khexedit'CHexViewWidget::readFile() (./kdeutils/khexedit/hexviewwidget.cc:256)
int CHexViewWidget::readFile( QFile &file, const QString &url, CProgress &p )
{
int errCode = mHexBuffer->readFile( file, url, p );
if( errCode != Err_Success )
{
return( errCode );
}
initFile();
return( Err_Success );
}
khexedit'CHexViewWidget::insertFile() (./kdeutils/khexedit/hexviewwidget.cc:269)
int CHexViewWidget::insertFile( QFile &file, CProgress &p )
{
int errCode = mHexBuffer->insertFile( file, p );
if( errCode != Err_Success )
{
return( errCode );
}
updateWindow( true, true );
emit dataChanged();
emit cursorChanged( mHexBuffer->cursorState() );
emit layoutChanged( mLayout );
return( Err_Success );
}
khexedit'CHexViewWidget::newFile() (./kdeutils/khexedit/hexviewwidget.cc:286)
int CHexViewWidget::newFile( const QString &url )
{
int errCode = mHexBuffer->newFile( url );
if( errCode != Err_Success )
{
return( errCode );
}
initFile();
return( Err_Success );
}
khexedit'CHexViewWidget::writeFile() (./kdeutils/khexedit/hexviewwidget.cc:299)
int CHexViewWidget::writeFile( QFile &file, CProgress &p )
{
int errCode = mHexBuffer->writeFile( file, p );
if( errCode == Err_Success )
{
emit fileState( mHexBuffer->fileState() );
}
return( errCode );
}
khexedit'CHexViewWidget::closeFile() (./kdeutils/khexedit/hexviewwidget.cc:310)
void CHexViewWidget::closeFile( void )
{
emit fileClosed( mHexBuffer->url() );
mHexBuffer->closeFile();
initFile();
}
khexedit'CHexViewWidget::initFile() (./kdeutils/khexedit/hexviewwidget.cc:319)
void CHexViewWidget::initFile( void )
{
setStartX(0);
setStartY(0);
mHexBuffer->cursorReset();
mHexBuffer->setLayout( mLayout );
mHexBuffer->setFont( mFontInfo );
setEditMode( mEditMode );
setColor( mColor, false );
setCursor( mCursor, false );
setMisc( mMisc );
setBackgroundColor( mHexBuffer->backgroundColor() );
setBackgroundMode( NoBackground );
updateView( true, false );
resizeEvent( 0 );
emit dataChanged();
emit cursorChanged( mHexBuffer->cursorState() );
emit fileState( mHexBuffer->fileState() );
emit encodingChanged( mHexBuffer->encoding() );
emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
emit bookmarkChanged( mHexBuffer->bookmarkList() );
}
khexedit'CHexViewWidget::setBuffer() (./kdeutils/khexedit/hexviewwidget.cc:347)
void CHexViewWidget::setBuffer( CHexBuffer *hexBuffer )
{
if( hexBuffer == 0 || mHexBuffer == hexBuffer )
{
return;
}
unselect();
unmark();
mHexBuffer = hexBuffer;
mHexBuffer->setLayout( mLayout );
mHexBuffer->setFont( mFontInfo );
setEditMode( mEditMode );
setColor( mColor, false );
setCursor( mCursor, false );
setMisc( mMisc );
if( mLayout.lockLine == false )
{
mHexBuffer->matchWidth( width() );
}
setBackgroundColor( hexBuffer->backgroundColor() );
setBackgroundMode( NoBackground );
setEditMode( mEditMode );
updateWindow();
emit dataChanged();
emit cursorChanged( mHexBuffer->cursorState() );
emit fileState( mHexBuffer->fileState() );
emit encodingChanged( mHexBuffer->encoding() );
emit layoutChanged( mLayout );
emit inputModeChanged( mHexBuffer->inputMode() );
emit fileName( mHexBuffer->url(), mHexBuffer->hasFileName() );
emit bookmarkChanged( mHexBuffer->bookmarkList() );
}
khexedit'CHexViewWidget::changeXPos() (./kdeutils/khexedit/hexviewwidget.cc:389)
void CHexViewWidget::changeXPos( int p )
{
int dx = startX() - p;
setStartX(p);
if( QABS(dx) < width() )
{
scroll( dx, 0, contentsRect() );
}
else
{
QWidget::update();
}
//
// If the start position has become 0, then update the view. This
// will remove the scrollbar (if it is visible) if the textarea width
// is wider than the text. The scrollbar will then disappear under the
// mouse pointer.
//
if( startX() == 0 )
{
updateView( false, false );
}
}
khexedit'CHexViewWidget::changeYPos() (./kdeutils/khexedit/hexviewwidget.cc:418)
void CHexViewWidget::changeYPos( int p )
{
int dy = startY() - p;
setStartY(p);
if( QABS( dy ) < height() )
{
scroll( 0, dy, contentsRect() );
}
else
{
QWidget::update();
}
//
// If the start position has become 0, then update the view. This
// will remove the scrollbar (if it is visible) if the textarea height
// is taller than the text. The scrollbar will then disappear under the
// mouse pointer.
//
if( startY() == 0 )
{
updateView( false, false );
}
}
khexedit'CHexViewWidget::clipboardChanged() (./kdeutils/khexedit/hexviewwidget.cc:445)
void CHexViewWidget::clipboardChanged( void )
{
disconnect(QApplication::clipboard(),SIGNAL(dataChanged()),
this,SLOT(clipboardChanged()));
unselect();
}
khexedit'CHexViewWidget::paletteChanged() (./kdeutils/khexedit/hexviewwidget.cc:452)
void CHexViewWidget::paletteChanged( void )
{
setColor( mColor, true );
}
khexedit'CHexViewWidget::fontChanged() (./kdeutils/khexedit/hexviewwidget.cc:458)
void CHexViewWidget::fontChanged( void )
{
//setFont( kapp->fixedFont, true );
}
khexedit'CHexViewWidget::filter() (./kdeutils/khexedit/hexviewwidget.cc:463)
void CHexViewWidget::filter( SFilterControl &fc )
{
int errCode = mHexBuffer->filter( fc );
if( errCode == Err_Success )
{
repaint();
emit dataChanged();
emit cursorChanged( mHexBuffer->cursorState() );
}
}
khexedit'CHexViewWidget::insert() (./kdeutils/khexedit/hexviewwidget.cc:476)
void CHexViewWidget::insert( SInsertData &id )
{
if( id.onCursor == false )
{
mHexBuffer->cursorGoto( id.offset, 7 );
}
SCursorConfig cc;
updateCursor( cc, true );
if( id.size == 0 )
{
return;
}
QByteArray buf( id.size );
if( buf.isNull() == true )
{
return;
}
buf.fill( 0 );
if( id.pattern.size() > 0 )
{
uint size = id.pattern.size()>buf.size() ? buf.size() : id.pattern.size();
if( id.repeatPattern == false )
{
memcpy( &buf[0], &id.pattern[0], size );
if( size < buf.size() )
{
memset( &buf[size], id.pattern[id.pattern.size()-1], buf.size()-size );
}
}
else
{
for( uint i=0; i < buf.size(); i+= size )
{
uint s = i+size > buf.size() ? buf.size()-i : size;
memcpy( &buf[i], &id.pattern[0], s );
}
}
}
insert( buf );
}
khexedit'CHexViewWidget::insert() (./kdeutils/khexedit/hexviewwidget.cc:522)
void CHexViewWidget::insert( const QByteArray &buf )
{
if( mHexBuffer->documentPresent() == false )
{
emit pleaseOpenNewFile();
if( mHexBuffer->documentPresent() == false )
{
return;
}
}
uint offset = mHexBuffer->cursorOffset();
int errCode = mHexBuffer->inputAtCursor( buf, 0 );
if( errCode == Err_Success )
{
updateWindow( offset, true );
emit dataChanged();
}
}
khexedit'CHexViewWidget::append() (./kdeutils/khexedit/hexviewwidget.cc:543)
void CHexViewWidget::append( const QByteArray &buf )
{
if( mHexBuffer->documentPresent() == false )
{
insert( buf );
}
else
{
SCursorConfig cc;
cc.emulateControlButton( true );
cursorEnd( cc );
int errCode = mHexBuffer->inputAtCursor( buf, 0 );
if( errCode == Err_Success )
{
updateWindow( true, true );
emit dataChanged();
}
}
}
khexedit'CHexViewWidget::valueOnCursor() (./kdeutils/khexedit/hexviewwidget.cc:565)
void CHexViewWidget::valueOnCursor( QByteArray &buf, uint size )
{
mHexBuffer->valueOnCursor( buf, size );
}
khexedit'CHexViewWidget::updateView() (./kdeutils/khexedit/hexviewwidget.cc:572)
void CHexViewWidget::updateView( bool redraw, bool fixCursor )
{
int f2 = frameWidth() * 2;
int scrollBarCount = 0; // Number of visible scrollbars
int editWidth = 0;
int editHeight = 0;
for( uint i=0; i < 2; i++ )
{
editWidth = width() - f2; // Total available width
editHeight = height() - f2; // Total available height
int textWidth = dataWidth();
int textHeight = mHexBuffer->totalHeight();
//
// This will move the start position of the horizontal scrollbar
// to the left (if possible) if the text width is smaller than the
// edit width.
//
if( startX() > 0 )
{
int size = mVertScroll->isVisible() == true ? mScrollBarSize : 0;
if( startX() + editWidth - size > textWidth )
{
int position = textWidth - editWidth + size;
setStartX( position > 0 ? position : 0 );
#ifdef USE_NORTHWEST_GRAVITY
redraw = true;
#endif
}
}
int tooMuchX = textWidth - editWidth;
bool horzScrollbarVisible = startX() > 0 || tooMuchX > 0 ? true : false;
if( horzScrollbarVisible == true )
{
editHeight -= mScrollBarSize;
}
//
// This will move the start position of the vertical scrollbar
// to the top (if possible) if the text height is smaller than the
// edit height.
//
if( startY() > 0 )
{
if( startY() + editHeight > textHeight )
{
int position = textHeight - editHeight;
setStartY( position > 0 ? position : 0 );
#ifdef USE_NORTHWEST_GRAVITY
redraw = true;
#endif
}
}
int tooMuchY = textHeight - editHeight;
int startLine = startY() / textHeight;
if( startLine > 0 || tooMuchY > 0 )
{
editWidth -= mScrollBarSize;
tooMuchX += mScrollBarSize;
if( horzScrollbarVisible == false && tooMuchX > 0 )
{
// Horizontal scrollbar will be visible after all.
editHeight -= mScrollBarSize;
tooMuchY += mScrollBarSize;
}
}
if( tooMuchX < startX() ) { tooMuchX = startX(); }
if( tooMuchY < startY() ) { tooMuchY = startY(); }
scrollBarCount = 0;
if( tooMuchX > 0 && documentPresent() == true )
{
mHorzScroll->blockSignals( true );
mHorzScroll->setGeometry( 0, editHeight+f2, editWidth+f2,mScrollBarSize);
mHorzScroll->setRange( 0, tooMuchX );
mHorzScroll->setValue( startX() );
mHorzScroll->setSteps(mHexBuffer->lineHeight(),editWidth-mScrollBarSize);
mHorzScroll->blockSignals( false );
if( mHorzScroll->isVisible() == false ) { mHorzScroll->show(); }
scrollBarCount ++;
}
else
{
if( mHorzScroll->isVisible() == true ) { mHorzScroll->hide(); }
}
if( tooMuchY > 0 && documentPresent() == true )
{
mVertScroll->blockSignals( true );
mVertScroll->setGeometry( editWidth+f2, 0, mScrollBarSize,editHeight+f2);
mVertScroll->setRange( 0, tooMuchY );
mVertScroll->setValue( startY() );
mVertScroll->setSteps(mHexBuffer->lineHeight(),
editHeight-mScrollBarSize );
mVertScroll->blockSignals( false );
if( mVertScroll->isVisible() == false ) { mVertScroll->show(); }
scrollBarCount ++;
}
else
{
if( mVertScroll->isVisible() == true ) { mVertScroll->hide(); }
}
if( fixCursor == true )
{
int position = mHexBuffer->cursorFixedPosition( startY(), height() );
if( position != startY() )
{
setStartY( position );
fixCursor = false;
continue;
}
}
break;
}
if( scrollBarCount == 2 )
{
mCorner->setGeometry( editWidth+f2, editHeight+f2, mScrollBarSize,
mScrollBarSize );
mCorner->show();
}
else
{
mCorner->hide();
}
updateFrameSize();
if( redraw == true )
{
QWidget::update();
}
}
khexedit'CHexViewWidget::setPalette() (./kdeutils/khexedit/hexviewwidget.cc:716)
void CHexViewWidget::setPalette( const QPalette &p )
{
QWidget::setPalette( p );
mCorner->setPalette( p );
mVertScroll->setPalette( p );
mHorzScroll->setPalette( p );
}
khexedit'CHexViewWidget::setLayout() (./kdeutils/khexedit/hexviewwidget.cc:725)
void CHexViewWidget::setLayout( SDisplayLayout &layout )
{
mLayout = layout;
mHexBuffer->setLayout( mLayout );
updateWindow();
emit layoutChanged( mLayout );
emit cursorChanged( mHexBuffer->cursorState() );
emit textWidth( defaultWidth() );
};
khexedit'CHexViewWidget::setInputMode() (./kdeutils/khexedit/hexviewwidget.cc:737)
void CHexViewWidget::setInputMode( SDisplayInputMode &input )
{
mHexBuffer->setInputMode( input );
emit inputModeChanged( mHexBuffer->inputMode() );
}
khexedit'CHexViewWidget::setCursor() (./kdeutils/khexedit/hexviewwidget.cc:744)
void CHexViewWidget::setCursor( const SDisplayCursor &cursor,
bool /*updateDisplay*/ )
{
mCursor = cursor;
mHexBuffer->setCursorShapeModifier( cursor.alwaysBlockShape,
cursor.thickInsertShape );
setupCursorTimer();
redrawFromOffset( mHexBuffer->cursorOffset(), false );
}
khexedit'CHexViewWidget::setColor() (./kdeutils/khexedit/hexviewwidget.cc:755)
void CHexViewWidget::setColor( const SDisplayColor &color,
bool updateDisplay )
{
mColor = color;
mHexBuffer->setColor( mColor );
if( updateDisplay == true )
{
repaint();
}
}
khexedit'CHexViewWidget::setFont() (./kdeutils/khexedit/hexviewwidget.cc:766)
void CHexViewWidget::setFont( const SDisplayFontInfo &fontInfo,
bool updateDisplay )
{
mFontInfo = fontInfo;
mHexBuffer->setFont( mFontInfo );
emit textWidth( defaultWidth() );
if( updateDisplay == true )
{
updateWindow();
}
}
khexedit'CHexViewWidget::setMisc() (./kdeutils/khexedit/hexviewwidget.cc:780)
void CHexViewWidget::setMisc( SDisplayMisc &misc )
{
mMisc = misc;
mHexBuffer->setUndoLevel( misc.undoLevel );
mHexBuffer->setSoundState( misc.inputSound, misc.fatalSound );
}
khexedit'CHexViewWidget::setInsertMode() (./kdeutils/khexedit/hexviewwidget.cc:788)
void CHexViewWidget::setInsertMode( bool insertMode )
{
setEditMode( insertMode == true ? CHexBuffer::EditInsert :
CHexBuffer::EditReplace );
}
khexedit'CHexViewWidget::setEncoding() (./kdeutils/khexedit/hexviewwidget.cc:795)
int CHexViewWidget::setEncoding( CConversion::EMode mode, CProgress &p )
{
int errCode = mHexBuffer->setEncoding( mode, p );
if( errCode == Err_Success )
{
repaint();
emit cursorChanged( mHexBuffer->cursorState() );
emit encodingChanged( mHexBuffer->encoding() );
}
return( errCode );
}
khexedit'CHexViewWidget::reportEncoding() (./kdeutils/khexedit/hexviewwidget.cc:808)
void CHexViewWidget::reportEncoding( void )
{
emit encodingChanged( mHexBuffer->encoding() );
}
khexedit'CHexViewWidget::selectAll() (./kdeutils/khexedit/hexviewwidget.cc:814)
void CHexViewWidget::selectAll( void )
{
setSelection( 0, true );
setSelection( mHexBuffer->documentSize(), false );
autoCopy();
emit cursorChanged( mHexBuffer->cursorState() );
}
khexedit'CHexViewWidget::unselect() (./kdeutils/khexedit/hexviewwidget.cc:822)
void CHexViewWidget::unselect( void )
{
setSelection( 0, true );
emit cursorChanged( mHexBuffer->cursorState() );
}
khexedit'CHexViewWidget::unmark() (./kdeutils/khexedit/hexviewwidget.cc:828)
void CHexViewWidget::unmark( void )
{
setMark( 0, 0, false );
}
khexedit'CHexViewWidget::findFirst() (./kdeutils/khexedit/hexviewwidget.cc:834)
int CHexViewWidget::findFirst( SSearchControl &sc )
{
int errCode = mHexBuffer->findFirst( sc );
if( errCode == Err_Success ) { updateWindow( true, false ); }
return( errCode );
}
khexedit'CHexViewWidget::findNext() (./kdeutils/khexedit/hexviewwidget.cc:841)
int CHexViewWidget::findNext( SSearchControl &sc )
{
int errCode = mHexBuffer->findNext( sc );
if( errCode == Err_Success ) { updateWindow( true, false ); }
return( errCode );
}
khexedit'CHexViewWidget::findWrap() (./kdeutils/khexedit/hexviewwidget.cc:848)
int CHexViewWidget::findWrap( SSearchControl &sc )
{
int errCode = mHexBuffer->findWrap( sc );
if( errCode == Err_Success ) { updateWindow( true, false ); }
return( errCode );
}
khexedit'CHexViewWidget::replaceAll() (./kdeutils/khexedit/hexviewwidget.cc:855)
int CHexViewWidget::replaceAll( SSearchControl &sc, bool init )
{
int errCode = mHexBuffer->replaceAll( sc, init );
if( errCode == Err_Success )
{
updateWindow( true, false );
emit dataChanged();
}
return( errCode );
}
khexedit'CHexViewWidget::replaceMarked() (./kdeutils/khexedit/hexviewwidget.cc:866)
int CHexViewWidget::replaceMarked( SSearchControl &sc )
{
int errCode = mHexBuffer->replaceMarked( sc );
if( errCode == Err_Success )
{
updateWindow( true, false );
emit dataChanged();
}
return( errCode );
}
khexedit'CHexViewWidget::collectStrings() (./kdeutils/khexedit/hexviewwidget.cc:877)
int CHexViewWidget::collectStrings( CStringCollectControl &sc )
{
int errCode = mHexBuffer->collectStrings( sc );
return( errCode );
}
khexedit'CHexViewWidget::collectStatistic() (./kdeutils/khexedit/hexviewwidget.cc:884)
int CHexViewWidget::collectStatistic( SStatisticControl &sc, CProgress &p )
{
int errCode = mHexBuffer->collectStatistic( sc, p );
return( errCode );
}
khexedit'CHexViewWidget::gotoOffset() (./kdeutils/khexedit/hexviewwidget.cc:891)
void CHexViewWidget::gotoOffset( uint offset, uint bit, bool fromCursor,
bool forward )
{
bool reverse = forward == true ? false : true;
mHexBuffer->cursorGoto( offset, bit, reverse, fromCursor );
updateWindow( true, false );
}
khexedit'CHexViewWidget::gotoOffset() (./kdeutils/khexedit/hexviewwidget.cc:900)
void CHexViewWidget::gotoOffset( uint offset )
{
gotoOffset( offset, 7, true, true );
}
khexedit'CHexViewWidget::print() (./kdeutils/khexedit/hexviewwidget.cc:906)
int CHexViewWidget::print( CHexPrinter &printer, CProgress &p )
{
return( mHexBuffer->print( printer, p ) );
}
khexedit'CHexViewWidget::numPage() (./kdeutils/khexedit/hexviewwidget.cc:912)
uint CHexViewWidget::numPage( CHexPrinter &printer )
{
return( mHexBuffer->numPage( printer ) );
}
khexedit'CHexViewWidget::exportText() (./kdeutils/khexedit/hexviewwidget.cc:918)
int CHexViewWidget::exportText( const SExportText &ex, CProgress &p )
{
return( mHexBuffer->exportText( ex, p ) );
}
khexedit'CHexViewWidget::exportHtml() (./kdeutils/khexedit/hexviewwidget.cc:924)
int CHexViewWidget::exportHtml( const SExportHtml &ex, CProgress &p )
{
return( mHexBuffer->exportHtml( ex, p ) );
}
khexedit'CHexViewWidget::exportCArray() (./kdeutils/khexedit/hexviewwidget.cc:930)
int CHexViewWidget::exportCArray( const SExportCArray &ex, CProgress &p )
{
return( mHexBuffer->exportCArray( ex, p ) );
}
khexedit'CHexViewWidget::startDrag() (./kdeutils/khexedit/hexviewwidget.cc:936)
void CHexViewWidget::startDrag( bool asText )
{
QByteArray buf;
if( asText == true )
{
if( mHexBuffer->copySelectedText( buf ) != Err_Success )
{
return;
}
QDragObject *d = new QTextDrag( buf.data(), this );
d->dragCopy();
}
else
{
if( mHexBuffer->copySelectedData( buf ) != Err_Success )
{
return;
}
QDragObject *d = new CHexDrag( buf, this );
d->dragCopy();
}
}
khexedit'CHexViewWidget::copy() (./kdeutils/khexedit/hexviewwidget.cc:961)
void CHexViewWidget::copy( void )
{
QByteArray buf;
if( mHexBuffer->copySelectedData( buf ) != Err_Success )
{
return;
}
disconnect(QApplication::clipboard(),SIGNAL(dataChanged()),
this,SLOT(clipboardChanged()));
//
// Note: Do no give the CHexDrag a parent != 0. The clipboard
// owns the current dragdata and will destroy it on exit or
// when it receives a new object. If the CHexDrag has a parent
// != 0, the CHexDrag object will be destroyed when the parent
// is destroyed. We will then have a double destroy situation
// when the app. is closed (=> segfault).
//
QApplication::clipboard()->setData(new CHexDrag( buf ));
connect(QApplication::clipboard(),SIGNAL(dataChanged()),
this,SLOT(clipboardChanged()));
}
khexedit'CHexViewWidget::copyText() (./kdeutils/khexedit/hexviewwidget.cc:984)
void CHexViewWidget::copyText( int columnSegment )
{
QByteArray buf;
if( mHexBuffer->copySelectedText( buf, columnSegment ) != Err_Success )
{
return;
}
disconnect(QApplication::clipboard(),SIGNAL(dataChanged()),
this,SLOT(clipboardChanged()));
QApplication::clipboard()->setText( buf.data() );
connect(QApplication::clipboard(),SIGNAL(dataChanged()),
this,SLOT(clipboardChanged()));
}
khexedit'CHexViewWidget::paste() (./kdeutils/khexedit/hexviewwidget.cc:1001)
void CHexViewWidget::paste( void )
{
QMimeSource *data = QApplication::clipboard()->data();
if( data != 0 )
{
QByteArray buf;
if( CHexDrag::decode( data, buf ) == true )
{
insert( buf );
return;
}
QString text;
if( QTextDrag::decode( data, text ) == true )
{
QByteArray buf;
if( mClipConvert.decode( buf, text ) == true )
{
insert( buf );
}
return;
}
}
}
khexedit'CHexViewWidget::cut() (./kdeutils/khexedit/hexviewwidget.cc:1028)
void CHexViewWidget::cut( void )
{
copy(); // Always make a copy to the clipboard of what we remove.
bool success = mHexBuffer->cutSelection();
if( success == false )
{
return;
}
updateWindow( false, true );
emit dataChanged();
}
khexedit'CHexViewWidget::undo() (./kdeutils/khexedit/hexviewwidget.cc:1042)
void CHexViewWidget::undo( void )
{
bool success = mHexBuffer->undo();
if( success == false )
{
return;
}
updateWindow( true, true );
emit dataChanged();
}
khexedit'CHexViewWidget::redo() (./kdeutils/khexedit/hexviewwidget.cc:1055)
void CHexViewWidget::redo( void )
{
bool success = mHexBuffer->redo();
if( success == false )
{
return;
}
updateWindow( true, true );
emit dataChanged();
}
khexedit'CHexViewWidget::addBookmark() (./kdeutils/khexedit/hexviewwidget.cc:1068)
void CHexViewWidget::addBookmark( int position )
{
int errCode = mHexBuffer->addBookmark( position );
if( errCode != Err_Success )
{
if( errCode == Err_ListFull )
{
replaceBookmark();
}
return;
}
emit bookmarkChanged( mHexBuffer->bookmarkList() );
}
khexedit'CHexViewWidget::bookmarkMenu() (./kdeutils/khexedit/hexviewwidget.cc:1085)
int CHexViewWidget::bookmarkMenu( const QString &title )
{
QList<SCursorOffset> &list = mHexBuffer->bookmarkList();
if( list.count() == 0 )
{
return( -1 );
}
QString text;
KPopupMenu *popup = new KPopupMenu( title, 0 );
for( uint i=0; i < list.count(); i++ )
{
const SCursorOffset *p = list.at( i );
if( p == 0 ) { continue; }
text.sprintf("%04X:%04X", p->offset>>16, p->offset&0x0000FFFF );
text.prepend( QString("[%1] %2: ").arg(i+1).arg(i18n("Offset")) );
popup->insertItem( text, i );
}
QSize s(popup->sizeHint());
QPoint center( (width()-s.width())/2, (height()-s.height())/2 );
int position = popup->exec( mapToGlobal(center) );
delete popup;
return( position );
}
khexedit'CHexViewWidget::removeBookmark() (./kdeutils/khexedit/hexviewwidget.cc:1114)
void CHexViewWidget::removeBookmark( bool all )
{
if( all == true )
{
bool success = mHexBuffer->removeBookmark( -1 );
if( success == false )
{
return;
}
}
else
{
int position = bookmarkMenu( QString(i18n("Remove bookmark")) );
if( position < 0 )
{
return;
}
bool success = mHexBuffer->removeBookmark( position );
if( success == false )
{
return;
}
}
emit bookmarkChanged( mHexBuffer->bookmarkList() );
}
khexedit'CHexViewWidget::replaceBookmark() (./kdeutils/khexedit/hexviewwidget.cc:1142)
void CHexViewWidget::replaceBookmark( void )
{
QList<SCursorOffset> &list = mHexBuffer->bookmarkList();
if( list.count() == 0 )
{
return;
}
int position = bookmarkMenu( QString(i18n("Replace bookmark")) );
if( position < 0 )
{
return;
}
addBookmark( position );
}
khexedit'CHexViewWidget::gotoBookmark() (./kdeutils/khexedit/hexviewwidget.cc:1159)
void CHexViewWidget::gotoBookmark( uint position )
{
QList<SCursorOffset> &list = mHexBuffer->bookmarkList();
if( position >= list.count() )
{
return;
}
SCursorOffset *p = list.at( position );
if( p == 0 )
{
return;
}
mHexBuffer->cursorGoto( p->offset, p->bit );
updateWindow();
}
khexedit'CHexViewWidget::gotoNextBookmark() (./kdeutils/khexedit/hexviewwidget.cc:1179)
void CHexViewWidget::gotoNextBookmark( bool next )
{
QList<SCursorOffset> &list = mHexBuffer->bookmarkList();
uint offset = mHexBuffer->cursorOffset();
uint diff = ~0;
SCursorOffset *match = 0;
//
// Note: the list is unsorted.
//
if( next == true )
{
for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
{
if( co->offset > offset )
{
if( co->offset-offset < diff )
{
diff = co->offset-offset;
match = co;
}
}
}
}
else
{
for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
{
if( co->offset < offset )
{
if( offset-co->offset < diff )
{
diff = offset-co->offset;
match = co;
}
}
}
}
if( match == 0 )
{
if( next == true )
{
// Wrap: Locate entry with smallest offset.
offset = ~0;
for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
{
if( co->offset < offset )
{
offset = co->offset;
match = co;
}
}
}
else
{
// Wrap: Locate entry with largest offset.
offset=0;
for( SCursorOffset *co = list.first(); co != 0; co = list.next() )
{
if( co->offset > offset )
{
offset = co->offset;
match = co;
}
}
}
}
if( match != 0 )
{
mHexBuffer->cursorGoto( match->offset, match->bit );
updateWindow();
}
}
//
// Used to test the speed of drawing
//
khexedit'CHexViewWidget::benchmark() (./kdeutils/khexedit/hexviewwidget.cc:1267)
void CHexViewWidget::benchmark( void )
{
struct timeval t1, t2;
uint loop = 10;
gettimeofday( &t1, 0 );
for( uint i=0; i< loop; i++ )
{
paintText( contentsRect(), false );
}
gettimeofday( &t2, 0 );
uint area = width() * height();
uint last = (t2.tv_sec-t1.tv_sec) * 1000000 + (t2.tv_usec - t1.tv_usec);
debug( "Duration: %f", (float)last/ 1000000.0 );
debug( "Duration/loop: %f", (float)last/ (1000000.0*(float)loop) );
debug( "Area: %d", area );
debug( "Loop: %d", loop );
}
khexedit'CHexViewWidget::resizeEvent() (./kdeutils/khexedit/hexviewwidget.cc:1293)
void CHexViewWidget::resizeEvent( QResizeEvent * )
{
setTextBufferSize();
if( mLayout.lockLine == true )
{
updateView( false, false );
#ifdef USE_NORTHWEST_GRAVITY
paintFrame();
#endif
}
else
{
bool state = mVertScroll->isVisible();
int size = (state == true ? mScrollBarSize : 0) + frameWidth()*2;
#ifdef USE_NORTHWEST_GRAVITY
int w = dataWidth();
#endif
bool bufferChanged = mHexBuffer->matchWidth( width() - size );
updateView( false, bufferChanged );
if( mVertScroll->isVisible() != state )
{
size = (mVertScroll->isVisible() ? mScrollBarSize : 0) + frameWidth()*2;
bufferChanged = mHexBuffer->matchWidth( width() - size );
updateView( false, bufferChanged );
}
#ifdef USE_NORTHWEST_GRAVITY
if( w != dataWidth() )
{
QWidget::update();
}
else
{
paintFrame();
}
#endif
}
}
khexedit'CHexViewWidget::paintEvent() (./kdeutils/khexedit/hexviewwidget.cc:1337)
void CHexViewWidget::paintEvent( QPaintEvent *e )
{
paintText( e->rect(), true );
}
khexedit'CHexViewWidget::updateFrameSize() (./kdeutils/khexedit/hexviewwidget.cc:1344)
void CHexViewWidget::updateFrameSize( void )
{
int w = width() - (mVertScroll->isVisible() ? mScrollBarSize : 0);
if( w < 0 ) { w = 0; }
int h = height() - (mHorzScroll->isVisible() ? mScrollBarSize : 0);
if( h < 0 ) { h = 0; }
setFrameRect( QRect(0,0,w,h) );
}
khexedit'CHexViewWidget::paintFrame() (./kdeutils/khexedit/hexviewwidget.cc:1356)
void CHexViewWidget::paintFrame( void )
{
QPainter paint;
paint.begin( this );
drawFrame( &paint );
paint.end();
}
khexedit'CHexViewWidget::drawFrame() (./kdeutils/khexedit/hexviewwidget.cc:1366)
void CHexViewWidget::drawFrame( QPainter *p )
{
//
// 2000-01-10 Espen Sand
// I want to display the frame with a custom color whenever the widget
// accepts a drop. The setPalette() function causes quite a bit of flicker
// in the scrollbars (even when PropagationMode is NoChildren), so I
// draw the frame manually when it can accept a drop. Note that the
// code below is for the frame shape "QFrame::WinPanel|QFrame::Plain"
//
if( mDropHighlight == true )
{
qDrawPlainRect( p, frameRect(), QColor("SteelBlue2"), lineWidth() );
}
else
{
QFrame::drawFrame(p); // Use standard drawFrame
}
}
khexedit'CHexViewWidget::keyPressEvent() (./kdeutils/khexedit/hexviewwidget.cc:1388)
void CHexViewWidget::keyPressEvent( QKeyEvent *e )
{
SCursorConfig cc;
cc.state = e->state();
//
// Some special actions that we have to trap here
//
if( e->state() & ControlButton )
{
switch( e->key() )
{
case Key_Space:
e->accept();
toggleEditor();
return;
break;
case Key_1:
e->accept();
cursorStep( cc, 1 );
return;
break;
case Key_2:
e->accept();
cursorStep( cc, 2 );
return;
break;
case Key_4:
e->accept();
cursorStep( cc, 4 );
return;
break;
case Key_8:
e->accept();
cursorStep( cc, 8 );
return;
break;
}
}
if( e->state() & AltButton )
{
if( e->key() == Key_Left || e->key() == Key_Right )
{
emit pleaseStepFile( e->key() == Key_Left ? true : false );
e->accept();
}
else if( e->key() == Key_Up || e->key() == Key_Down )
{
gotoNextBookmark( e->key() == Key_Down ? true : false );
e->accept();
}
else
{
e->ignore();
}
return;
}
switch ( e->key() )
{
case Key_Left:
cursorLeft( cc );
break;
case Key_Right:
cursorRight( cc );
break;
case Key_Up:
cursorUp( cc );
break;
case Key_Down:
cursorDown( cc );
break;
case Key_Home:
cursorHome( cc );
break;
case Key_End:
cursorEnd( cc );
break;
case Key_Next:
cursorPageDown( cc );
break;
case Key_Prior:
cursorPageUp( cc );
break;
case Key_Insert:
cursorInsert( cc );
break;
case Key_Delete:
cursorDelete( cc );
break;
case Key_Backspace:
cursorBackspace( cc );
break;
default:
if( (e->text()[0]).isPrint() == true )
{
cursorInput( e->text()[0] );
}
break;
}
e->accept();
}
khexedit'CHexViewWidget::keyReleaseEvent() (./kdeutils/khexedit/hexviewwidget.cc:1509)
void CHexViewWidget::keyReleaseEvent( QKeyEvent *e )
{
if( e->state() & ShiftButton && shiftButtonState() == false )
{
//
// The shift button was pressed when event was triggered, but is
// now released. I use this as a sign to copy selected data to the
// clipboard. The shiftButtonState() uses X-lib functions so have a
// look in the headerfile (inlined method) if you want to remove
// this dependency.
//
autoCopy();
}
}
khexedit'CHexViewWidget::mousePressEvent() (./kdeutils/khexedit/hexviewwidget.cc:1525)
void CHexViewWidget::mousePressEvent( QMouseEvent *e )
{
//
// The RMB popup menu is managed by the KContextMenuManager
//
if( e->button() == LeftButton )
{
if( e->state() & ControlButton )
{
if( KContextMenuManager::showOnButtonPress() == true
&& mDocumentMenu != 0 )
{
mDocumentMenu->popup( e->globalPos() );
}
}
else
{
bool cellLevel = mMisc.cursorJump == false;
setCursorPosition( e->x(), e->y(), true, cellLevel );
}
}
else if( e->button() == MidButton )
{
paste();
}
}
khexedit'CHexViewWidget::mouseMoveEvent() (./kdeutils/khexedit/hexviewwidget.cc:1554)
void CHexViewWidget::mouseMoveEvent( QMouseEvent *e )
{
if( e->state() & LeftButton )
{
if( mDragManager->start( e ) == false )
{
bool cellLevel = mMisc.cursorJump == false||e->state() & ControlButton;
setCursorPosition( e->x(), e->y(), false, cellLevel );
}
}
}
khexedit'CHexViewWidget::mouseReleaseEvent() (./kdeutils/khexedit/hexviewwidget.cc:1566)
void CHexViewWidget::mouseReleaseEvent( QMouseEvent *e )
{
//
// The RMB popup menu is managed by the KContextMenuManager
//
if( e->button() == LeftButton )
{
if( e->state() & ControlButton )
{
if( KContextMenuManager::showOnButtonPress() == false
&& mDocumentMenu != 0 )
{
mDocumentMenu->popup( e->globalPos() );
}
}
else
{
if( mDragManager->clear() == true )
{
// Remove any selection
SCursorConfig cc;
cc.setKeepSelection( false );
updateCursor( cc, true );
}
else
{
mHexBuffer->cursorResetEditArea();
autoCopy();
}
}
}
}
khexedit'CHexViewWidget::wheelEvent() (./kdeutils/khexedit/hexviewwidget.cc:1603)
void CHexViewWidget::wheelEvent( QWheelEvent *e )
{
if( mVertScroll->isVisible() == true )
{
QApplication::sendEvent( mVertScroll, e );
}
}
khexedit'CHexViewWidget::dragEnterEvent() (./kdeutils/khexedit/hexviewwidget.cc:1612)
void CHexViewWidget::dragEnterEvent( QDragEnterEvent *e )
{
if( QTextDrag::canDecode(e) || CHexDrag::canDecode(e) ||
QUriDrag::canDecode(e))
{
e->accept();
setDropHighlight( true );
}
}
khexedit'CHexViewWidget::dragLeaveEvent() (./kdeutils/khexedit/hexviewwidget.cc:1623)
void CHexViewWidget::dragLeaveEvent( QDragLeaveEvent * )
{
setDropHighlight( false );
}
khexedit'CHexViewWidget::dragMoveEvent() (./kdeutils/khexedit/hexviewwidget.cc:1629)
void CHexViewWidget::dragMoveEvent( QDragMoveEvent *e )
{
//
// Move the cursor if we are dragging (readable) text or binary
// data. Note: the QTextDrag::canDecode() will return true if we
// are dragging a file so we have to test for QUriDrag::canDecode()
// first.
//
if( QUriDrag::canDecode(e) == true )
{
return;
}
if( QTextDrag::canDecode(e) == true || CHexDrag::canDecode(e) == true )
{
int x = startX() + e->pos().x();
int y = startY() + e->pos().y();
if( mHexBuffer->setCursorPosition( x, y, false, false ) == true )
{
SCursorConfig cc;
cc.setKeepSelection( true );
updateCursor( cc, false, false );
}
}
}
khexedit'CHexViewWidget::dropEvent() (./kdeutils/khexedit/hexviewwidget.cc:1657)
void CHexViewWidget::dropEvent( QDropEvent *e )
{
QMimeSource &m = *(QDropEvent*)e;
setDropHighlight( false );
QStringList list;
if( QUriDrag::decodeToUnicodeUris( &m, list ) == true )
{
//
// This widget can not itself open a file so it will simply pass
// the request to a parent that can (hopefully) do this
//
for( QStringList::Iterator it = list.begin(); it != list.end(); it++ )
{
emit pleaseOpenFile( *it, true, 0 );
}
return;
}
QByteArray buf;
if( CHexDrag::decode( &m, buf ) == true )
{
insert( buf );
return;
}
QString text;
if( QTextDrag::decode( &m, text ) == true )
{
bool success = mClipConvert.decode( buf, text );
if( success == true )
{
insert( buf );
}
return;
}
}
khexedit'CHexViewWidget::showEvent() (./kdeutils/khexedit/hexviewwidget.cc:1697)
void CHexViewWidget::showEvent( QShowEvent * )
{
// Currently we do nothing here.
}
khexedit'CHexViewWidget::timerEvent() (./kdeutils/khexedit/hexviewwidget.cc:1705)
void CHexViewWidget::timerEvent( QTimerEvent *e )
{
if( e->timerId() == mCursorTimerId )
{
if( hasFocus() == true )
{
if( mCursor.alwaysVisible == true )
{
mShowCursor = true;
}
else
{
mShowCursor = mShowCursor == true ? false : true;
}
}
else if( mCursor.focusMode == SDisplayCursor::hide )
{
mShowCursor = false;
}
else if( mCursor.focusMode == SDisplayCursor::stopBlinking )
{
mShowCursor = true;
}
else
{
mShowCursor = mShowCursor == true ? false : true;
}
mHexBuffer->setShowCursor( mShowCursor );
paintCursor( CHexBuffer::cursor_curr );
}
}
khexedit'CHexViewWidget::focusInEvent() (./kdeutils/khexedit/hexviewwidget.cc:1737)
void CHexViewWidget::focusInEvent( QFocusEvent * )
{
setupCursorTimer();
paintCursor( CHexBuffer::cursor_curr );
}
khexedit'CHexViewWidget::focusOutEvent() (./kdeutils/khexedit/hexviewwidget.cc:1743)
void CHexViewWidget::focusOutEvent( QFocusEvent * )
{
if( mCursor.focusMode != SDisplayCursor::ignore )
{
setupCursorTimer();
paintCursor( CHexBuffer::cursor_curr );
}
}
khexedit'CHexViewWidget::setSelection() (./kdeutils/khexedit/hexviewwidget.cc:1753)
void CHexViewWidget::setSelection( uint offset, bool init )
{
bool selectionChanged = mHexBuffer->selectionSet( offset, init );
if( selectionChanged == true )
{
uint off1, off2;
mHexBuffer->selectionStartChange( off1, off2 );
if( off1 != off2 )
{
redrawInterval( off1, off2 );
}
mHexBuffer->selectionStopChange( off1, off2 );
if( off1 != off2 )
{
redrawInterval( off1, off2 );
}
}
mHexBuffer->selectionSyncronize();
}
khexedit'CHexViewWidget::setMark() (./kdeutils/khexedit/hexviewwidget.cc:1775)
void CHexViewWidget::setMark( uint offset, uint size, bool moveCursor )
{
bool changed;
if( size == 0 )
{
changed = mHexBuffer->markRemove();
}
else
{
mHexBuffer->markSet( offset, size );
if( moveCursor == true )
{
changed = false;
gotoOffset( offset, 7, false, true );
}
else
{
changed = true;
}
}
if( changed == true )
{
uint off1, off2;
mHexBuffer->markStartChange( off1, off2 );
if( off1 != off2 )
{
redrawInterval( off1, off2 );
}
mHexBuffer->markStopChange( off1, off2 );
if( off1 != off2 )
{
redrawInterval( off1, off2 );
}
}
mHexBuffer->markSyncronize();
}
khexedit'CHexViewWidget::setCursorPosition() (./kdeutils/khexedit/hexviewwidget.cc:1816)
void CHexViewWidget::setCursorPosition(int x, int y, bool init, bool cellLevel)
{
x += startX();
y += startY();
if( mHexBuffer->setCursorPosition( x, y, init, cellLevel ) == false )
{
if( init == true )
{
unselect();
unmark();
}
}
else if( init == false )
{
SCursorConfig cc;
cc.setKeepSelection( true );
updateCursor( cc, false );
}
else
{
SCursorConfig cc;
if( mHexBuffer->cursorInsideSelection() == true )
{
mDragManager->setup( x - startX(), y - startY() );
cc.setKeepSelection( true );
updateCursor( cc, true, false );
}
else
{
cc.setKeepSelection( false );
updateCursor( cc, true );
}
}
}
khexedit'CHexViewWidget::redrawInterval() (./kdeutils/khexedit/hexviewwidget.cc:1854)
void CHexViewWidget::redrawInterval( uint startOffset, uint stopOffset )
{
//
// Can be improved, I repaint the entire line even if the offsets
// only specify one byte.
//
uint lineStart = mHexBuffer->calculateLine( startOffset );
uint lineStop = mHexBuffer->calculateLine( stopOffset );
if( lineStart <= lineStop )
{
redrawLines( lineStart, lineStop - lineStart + 1 );
}
else
{
redrawLines( lineStop, lineStart - lineStop + 1 );
}
}
khexedit'CHexViewWidget::redrawLines() (./kdeutils/khexedit/hexviewwidget.cc:1874)
void CHexViewWidget::redrawLines( uint docLine, int numLine )
{
int lineHeight = mHexBuffer->lineHeight();
int lineOffset = startY() / lineHeight;
// FIXME: startY() should return uint
if( (uint)lineOffset > docLine )
{
numLine -= (lineOffset-docLine);
if( numLine <= 0 ) { return; }
docLine = lineOffset;
}
int t = docLine * lineHeight - startY() + frameWidth();
if( mEditMode == CHexBuffer::EditInsert )
{
QRect r = contentsRect();
r.setTop( t );
paintText( contentsRect().intersect( r ), false );
}
else
{
int h = (numLine + (startY() % lineHeight ? 1 : 0)) * lineHeight;
QRect r( contentsRect().left(), t, contentsRect().width(), h );
paintText( contentsRect().intersect( r ), false );
}
}
khexedit'CHexViewWidget::redrawFromOffset() (./kdeutils/khexedit/hexviewwidget.cc:1904)
void CHexViewWidget::redrawFromOffset( uint offset, bool finishWindow )
{
int lineHeight = mHexBuffer->lineHeight();
uint docLine = mHexBuffer->calculateLine( offset );
int t = docLine * lineHeight - startY() + frameWidth();
if( finishWindow == true )
{
QRect r = contentsRect();
r.setTop( t );
paintText( contentsRect().intersect( r ), false );
}
else
{
int h = t + lineHeight;
QRect r( contentsRect().left(), t, contentsRect().width(), h );
paintText( contentsRect().intersect( r ), false );
}
}
khexedit'CHexViewWidget::paintText() (./kdeutils/khexedit/hexviewwidget.cc:1927)
void CHexViewWidget::paintText( const QRect &rect, bool expand )
{
QRect r = rect;
if( expand == true )
{
#ifdef USE_NORTHWEST_GRAVITY
r.setLeft( r.left() - frameWidth() );
r.setTop( r.top() - frameWidth() );
#endif
}
if( contentsRect().contains( r ) == false )
{
paintFrame();
if( r.left() < frameWidth() ) { r.setLeft( frameWidth() ); }
if( r.top() < frameWidth() ) { r.setTop( frameWidth() ); }
}
int maxX = width() - frameWidth() - 1 -
(mVertScroll->isVisible() ? mScrollBarSize : 0);
int maxY = height() - frameWidth() - 1 -
(mHorzScroll->isVisible() ? mScrollBarSize : 0);
if( r.right() > maxX ) { r.setRight( maxX ); }
if( r.bottom() > maxY ) { r.setBottom( maxY ); }
QPainter paint( &mTextBuffer );
paint.setFont( mHexBuffer->font() );
int lineHeight = mHexBuffer->lineHeight();
int docLine = (startY() + r.y() - frameWidth()) / lineHeight;
if( docLine < 0 ) { docLine = 0; }
int y = docLine * lineHeight - startY();
int yMax = r.height();
int xMax = r.x() + r.width();
y += frameWidth();
int s = 0;
int d = r.y()-y;
int h;
while( yMax > 0 )
{
mHexBuffer->drawText( paint, docLine, startX()-frameWidth(), r.x(), xMax );
if( d != 0 )
{
h = lineHeight - d;
if( h > yMax ) { h = yMax; }
}
else
{
h = yMax > lineHeight ? lineHeight : yMax;
}
bitBlt( this, r.x(), r.y()+s, &mTextBuffer, r.x(), d, r.width(), h );
s += h;
yMax -= h;
docLine += 1;
d = 0;
}
paint.end();
}
khexedit'CHexViewWidget::paintCursor() (./kdeutils/khexedit/hexviewwidget.cc:1994)
void CHexViewWidget::paintCursor( int cursorMode )
{
QPainter paint;
paint.begin( &mTextBuffer );
paint.setFont( mHexBuffer->font() );
int f = frameWidth();
if( cursorMode == CHexBuffer::cursor_prev )
{
int line = mHexBuffer->prevCursorLine();
SCursorPosition p;
mHexBuffer->prevCursor( CHexBuffer::edit_primary, p );
mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
if( p.y + p.h + f > contentsRect().bottom() )
p.h = contentsRect().bottom() - p.y - f + 1;
bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
mHexBuffer->prevCursor( CHexBuffer::edit_secondary, p );
mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
if( p.y + p.h + f > contentsRect().bottom() )
p.h = contentsRect().bottom() - p.y - f + 1;
bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
}
else
{
int line = mHexBuffer->cursorLine();
SCursorPosition p;
mHexBuffer->currCursor( CHexBuffer::edit_primary, p );
mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
if( p.y + p.h + f > contentsRect().bottom() )
p.h = contentsRect().bottom() - p.y - f + 1;
bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
mHexBuffer->currCursor( CHexBuffer::edit_secondary, p );
mHexBuffer->drawText( paint, line, startX(), p.x, p.x + p.w );
if( p.y + p.h + f > contentsRect().bottom() )
p.h = contentsRect().bottom() - p.y - f + 1;
bitBlt( this, p.x+f, p.y+f, &mTextBuffer, p.x, 0, p.w, p.h );
}
paint.end();
}
khexedit'CHexViewWidget::updateCursor() (./kdeutils/khexedit/hexviewwidget.cc:2044)
void CHexViewWidget::updateCursor( SCursorConfig &cc, bool always,
bool touchSelection )
{
if( mHexBuffer->cursorChanged() == false && always == false )
{
return;
}
//
// Make blinking (and perhaps invisible) cursor visible
//
setupCursorTimer();
//
// Clear cursor at old location
//
paintCursor( CHexBuffer::cursor_prev );
//
// Compute the new position of the vertical scroll bar.
//
int position, h;
if( cc.controlButton() == true )
{
//
// The cursor should stay fixed (if possible) in the window while
// the text is scrolled (e.g., PageUp/Down behavior). The position
// of the vertical scrollbar must change just as much as the cursor
// has changed in the vertical direction.
//
h = frameWidth()*2;
h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
position = mHexBuffer->cursorFixedPosition( startY(), height()-h );
changeYPos( position );
}
else
{
h = frameWidth()*2;
h += mHorzScroll->isVisible() == false ? 0 : mScrollBarSize;
position = mHexBuffer->cursorChangePosition( startY(), height()-h );
changeYPos( position );
}
//
// Paint cursor at new location and update the vertical scroll bar.
//
paintCursor( CHexBuffer::cursor_curr );
mVertScroll->blockSignals( true );
mVertScroll->setValue( position );
mVertScroll->blockSignals( false );
if( touchSelection == true )
{
setSelection( mHexBuffer->cursorOffset(), cc.removeSelection() );
unmark();
}
emit cursorChanged( mHexBuffer->cursorState() );
}
khexedit'CHexViewWidget::toggleEditor() (./kdeutils/khexedit/hexviewwidget.cc:2105)
void CHexViewWidget::toggleEditor( void )
{
bool success = mHexBuffer->toggleEditor();
if( success == false )
{
return;
}
SCursorConfig cc;
updateCursor( cc, true );
redrawFromOffset( mHexBuffer->cursorOffset(), false );
}
khexedit'CHexViewWidget::cursorStep() (./kdeutils/khexedit/hexviewwidget.cc:2119)
void CHexViewWidget::cursorStep( SCursorConfig &cc, uint stepSize )
{
mHexBuffer->cursorStep( stepSize, cc.altButton() ? false : true, true );
cc.emulateControlButton( false );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorLeft() (./kdeutils/khexedit/hexviewwidget.cc:2128)
void CHexViewWidget::cursorLeft( SCursorConfig &cc )
{
bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
cc.emulateControlButton( false );
mHexBuffer->cursorLeft( cellLevel );
updateCursor( cc, cellLevel );
}
khexedit'CHexViewWidget::cursorRight() (./kdeutils/khexedit/hexviewwidget.cc:2137)
void CHexViewWidget::cursorRight( SCursorConfig &cc )
{
bool cellLevel = mMisc.cursorJump == false || cc.controlButton();
cc.emulateControlButton( false );
mHexBuffer->cursorRight( cellLevel );
updateCursor( cc, cellLevel );
}
khexedit'CHexViewWidget::cursorUp() (./kdeutils/khexedit/hexviewwidget.cc:2147)
void CHexViewWidget::cursorUp( SCursorConfig &cc )
{
mHexBuffer->cursorUp( 1 );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorDown() (./kdeutils/khexedit/hexviewwidget.cc:2154)
void CHexViewWidget::cursorDown( SCursorConfig &cc )
{
mHexBuffer->cursorDown( 1 );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorHome() (./kdeutils/khexedit/hexviewwidget.cc:2161)
void CHexViewWidget::cursorHome( SCursorConfig &cc )
{
mHexBuffer->cursorHome( cc.controlButton() );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorEnd() (./kdeutils/khexedit/hexviewwidget.cc:2168)
void CHexViewWidget::cursorEnd( SCursorConfig &cc )
{
mHexBuffer->cursorEnd( cc.controlButton() );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorPageDown() (./kdeutils/khexedit/hexviewwidget.cc:2175)
void CHexViewWidget::cursorPageDown( SCursorConfig &cc )
{
mHexBuffer->cursorDown( height() / mHexBuffer->lineHeight() );
cc.emulateControlButton( true );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorPageUp() (./kdeutils/khexedit/hexviewwidget.cc:2183)
void CHexViewWidget::cursorPageUp( SCursorConfig &cc )
{
mHexBuffer->cursorUp( height() / mHexBuffer->lineHeight() );
cc.emulateControlButton( true );
updateCursor( cc );
}
khexedit'CHexViewWidget::cursorInsert() (./kdeutils/khexedit/hexviewwidget.cc:2191)
void CHexViewWidget::cursorInsert( SCursorConfig &/*cc*/ )
{
// Toggle mode
setEditMode( mEditMode == CHexBuffer::EditInsert ?
CHexBuffer::EditReplace : CHexBuffer::EditInsert );
}
khexedit'CHexViewWidget::cursorDelete() (./kdeutils/khexedit/hexviewwidget.cc:2200)
void CHexViewWidget::cursorDelete( SCursorConfig &/*cc*/ )
{
int numLine = mHexBuffer->numLines();
bool success = mHexBuffer->removeAtCursor( false );
if( success == false )
{
return;
}
updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
emit dataChanged();
}
khexedit'CHexViewWidget::cursorBackspace() (./kdeutils/khexedit/hexviewwidget.cc:2215)
void CHexViewWidget::cursorBackspace( SCursorConfig &/*cc*/ )
{
int numLine = mHexBuffer->numLines();
bool success = mHexBuffer->removeAtCursor( true );
if( success == false )
{
return;
}
updateWindow( numLine == mHexBuffer->numLines() ? false : true, true );
emit dataChanged();
}
khexedit'CHexViewWidget::cursorInput() (./kdeutils/khexedit/hexviewwidget.cc:2230)
void CHexViewWidget::cursorInput( QChar c )
{
uint cursorLine = mHexBuffer->cursorLine();
bool success = mHexBuffer->inputAtCursor( c );
if( success == false )
{
return;
}
updateWindow( cursorLine );
emit dataChanged();
}
khexedit'CHexViewWidget::setEditMode() (./kdeutils/khexedit/hexviewwidget.cc:2244)
void CHexViewWidget::setEditMode( CHexBuffer::EEditMode mode )
{
mEditMode = mode;
mHexBuffer->setEditMode( mEditMode, mCursor.alwaysBlockShape,
mCursor.thickInsertShape );
setupCursorTimer();
//
// This will redraw the current line (which contains the cursor)
//
redrawFromOffset( mHexBuffer->cursorOffset(), false );
emit editMode( mEditMode );
}
khexedit'CHexViewWidget::setDropHighlight() (./kdeutils/khexedit/hexviewwidget.cc:2259)
void CHexViewWidget::setDropHighlight( bool dropHighlight )
{
mDropHighlight = dropHighlight;
if( mDropHighlight == true )
{
//
// 2000-01-10 Espen Sand
// Highlight. I have reimplemented QFrame::drawFrame(QPainter *)
// to support a custom frame color. I assume the frame shape is
// "QFrame::WinPanel|QFrame::Plain" in that function.
//
setFrameStyle( QFrame::WinPanel|QFrame::Plain );
}
else
{
setFrameStyle( QFrame::WinPanel|QFrame::Sunken );
}
}
khexedit'CHexViewWidget::hexBuffer() (./kdeutils/khexedit/hexviewwidget.h:570)
inline const CHexBuffer *CHexViewWidget::hexBuffer( void )
{
return( mHexBuffer );
}