Source Code (Use browser search to find items of interest.)

Class Index

khexedit'CFileInfoDialog (./kdeutils/khexedit/fileinfodialog.h:36)

class CFileInfoDialog : public KDialogBase
{
  Q_OBJECT
  
  public:
    CFileInfoDialog( QWidget *parent=0, const char *name=0,bool modal=false );
    ~CFileInfoDialog( void );

    void setStatistics( void );
    void setStatistics( SStatisticControl &sc );

  public slots:
    void setDirty( void );
    void setClean( void );

  protected slots:
    virtual void slotUser1( void );

  protected:
    virtual void resizeEvent( QResizeEvent * );
    virtual void showEvent( QShowEvent * );
    virtual void timerEvent( QTimerEvent * );

  private:
    void setColumnWidth( void );

  signals:
    void collectStatistic( SStatisticControl &sc );

  private:
    bool mBusy;
    bool mDirty;
    CListView *mFrequencyList;
    QLabel *mFileNameLabel;
    QLabel *mFileSizeLabel;
    QLabel *mDirtyLabel;
};

khexedit'CFileInfoDialog::CFileInfoDialog() (./kdeutils/khexedit/fileinfodialog.cc:32)

CFileInfoDialog::CFileInfoDialog( QWidget *parent,const char *name,bool modal)
  :KDialogBase( Plain, i18n("Statistics"), Help|User1|Cancel, User1,
		parent, name, modal, true, i18n("&Update") ),
   mBusy(false), mDirty(false)
{
  setHelp( "khexedit/khexedit.html", QString::null );

  QString text;
  QVBoxLayout *topLayout = new QVBoxLayout( plainPage(), 0, spacingHint() );
  if( topLayout == 0 ) { return; }

  
  QGridLayout *gbox = new QGridLayout( 2, 2, spacingHint() );
  if( gbox == 0 ) { return; }
  topLayout->addLayout( gbox );
  gbox->setColStretch( 1, 10 );
  
  text = i18n("File name: ");
  QLabel *label = new QLabel( text, plainPage() );
  gbox->addWidget( label, 0, 0 );

  text = i18n("Size [bytes]: ");
  label = new QLabel( text, plainPage() );
  gbox->addWidget( label, 1, 0 );

  mFileNameLabel = new QLabel( plainPage() );
  mFileSizeLabel = new QLabel( plainPage() );
  gbox->addWidget( mFileNameLabel, 0, 1 );
  gbox->addWidget( mFileSizeLabel, 1, 1 );

  mFrequencyList = new CListView( plainPage(), "stringList" );
  mFrequencyList->setFont( KGlobal::fixedFont() );

  mFrequencyList->addColumn( i18n("Hexadecimal") );
  mFrequencyList->addColumn( i18n("Decimal") );
  mFrequencyList->addColumn( i18n("Octal") );
  mFrequencyList->addColumn( i18n("Binary") );
  mFrequencyList->addColumn( i18n("Text") );
  mFrequencyList->addColumn( i18n("Occurrence") );
  mFrequencyList->addColumn( i18n("Percent") );
  mFrequencyList->setAllColumnsShowFocus( true );
  mFrequencyList->setFrameStyle( QFrame::WinPanel + QFrame::Sunken );
  topLayout->addWidget( mFrequencyList, 10 );

  mDirtyLabel = new QLabel( plainPage() );
  mDirtyLabel->setFixedHeight( fontMetrics().height() );
  topLayout->addWidget( mDirtyLabel );

  setStatistics();
  setColumnWidth();
  mFrequencyList->setVisibleItem( 15 );

  //
  // Load the first set of data when this timer expires. I do it this 
  // way so that the dialog will be visible when the load operation starts.
  //
  startTimer( 0 );
}



khexedit'CFileInfoDialog::~CFileInfoDialog() (./kdeutils/khexedit/fileinfodialog.cc:92)

CFileInfoDialog::~CFileInfoDialog( void )
{
}



khexedit'CFileInfoDialog::slotUser1() (./kdeutils/khexedit/fileinfodialog.cc:97)

void CFileInfoDialog::slotUser1( void ) // Update
{
  if( mBusy == true )
  {
    return;
  }
  
  SStatisticControl *sc = new SStatisticControl;
  if( sc == 0 ) { return; }
  
  mBusy = true;  
  emit collectStatistic( *sc );
  mBusy = false;  

  delete sc;
  
}



khexedit'CFileInfoDialog::setDirty() (./kdeutils/khexedit/fileinfodialog.cc:116)

void CFileInfoDialog::setDirty( void )
{
  if( mDirty == true )
  {
    return;
  }
  
  mDirtyLabel->setText(
    i18n("Warning: Document has been modified since last update"));
  mDirty = true;
}



khexedit'CFileInfoDialog::setClean() (./kdeutils/khexedit/fileinfodialog.cc:129)

void CFileInfoDialog::setClean( void )
{
  if( mDirty == false )
  {
    return;
  }
  
  mDirtyLabel->setText("");
  mDirty = false;
}



khexedit'CFileInfoDialog::setStatistics() (./kdeutils/khexedit/fileinfodialog.cc:153)

void CFileInfoDialog::setStatistics( void ) // Default
{
  setClean();
  mFrequencyList->clear();
  mFileNameLabel->setText("");
  mFileSizeLabel->setText("");

  QString u("?");
  QString d, h, o, b, c;
  QListViewItem *item = 0;

  char buf[10];
  memset( buf, 0, sizeof( buf ) );
  
  for( uint i=0; i<256; i++ )
  { 
    h.sprintf("0x%02x", i );
    d.sprintf("%03d", i );
    o.sprintf("%03o", i );
    b.sprintf("%s", printBin(i) );

    if( QChar((char)i).isPrint() == true )
    {
      c = QChar((char)i);
    }
    else
    {
      c = QChar('.');
    }

    item = new QListViewItem( mFrequencyList, item, h, d, o, b, c, u, u );
    if( i == 0 )
    {
      mFrequencyList->setSelected( item, true );
    }
  }
}




khexedit'CFileInfoDialog::setStatistics() (./kdeutils/khexedit/fileinfodialog.cc:193)

void CFileInfoDialog::setStatistics( SStatisticControl &sc )
{
  setClean();
  mFrequencyList->clear();
  mFileNameLabel->setText( sc.documentName );
  mFileSizeLabel->setText( QString("%1").arg(sc.documentSize));

  QString d, h, o, b, c, n, p;
  QListViewItem *item = 0;
  
  uint size, pre, i;

  for( i=size=0; i<256; i++ )
  { 
    if( sc.occurence[i] > size ) { size = sc.occurence[i]; }
  }
  for( pre = 1; size > 0 ; pre++ )
  {
    size /= 10;
  }

  for( i=0; i<256; i++ )
  { 
    h.sprintf("0x%02x", i );
    d.sprintf("%03d", i );
    o.sprintf("%03o", i );
    b.sprintf("%s", printBin(i) );

    n = QString("%1").arg( sc.occurence[i], pre );
    if( sc.documentSize == 0 )
    {
      p.sprintf("0.00" );
    }
    else
    {
      double val = 100.0*((double)sc.occurence[i]/(double)sc.documentSize);
      p = QString("%1").arg( val, 6, 'f', 2 );
    }

    if( QChar((char)i).isPrint() == true )
    {
      c = QChar((char)i);
    }
    else
    {
      c = QChar('.');
    }

    item = new QListViewItem( mFrequencyList, item, h, d, o, b, c, n, p );
    if( i == 0 )
    {
      mFrequencyList->setSelected( item, true );
    }
  }
}




khexedit'CFileInfoDialog::setColumnWidth() (./kdeutils/khexedit/fileinfodialog.cc:251)

void CFileInfoDialog::setColumnWidth( void )
{
  const QFontMetrics &fm = mFrequencyList->fontMetrics();
  int w0, w1, w2, w3, w4;

  w0 = -fm.minLeftBearing() - fm.minRightBearing() + 8 + fm.maxWidth();
  w3 = 0;

  w1  = fm.width( mFrequencyList->header()->label(0) ) + w0;
  w2  = fm.width('0')*6;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 0, w1 > w2 ? w1 : w2 );
  
  w1  = fm.boundingRect( mFrequencyList->header()->label(1) ).width() + w0;
  w2  = fm.width('0')*5;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 1, w1 > w2 ? w1 : w2 );

  w1  = fm.boundingRect( mFrequencyList->header()->label(2) ).width() + w0;
  w2  = fm.width('0')*5;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 2, w1 > w2 ? w1 : w2 );

  w1  = fm.boundingRect( mFrequencyList->header()->label(3) ).width() + w0;
  w2  = fm.width('0')*10;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 3, w1 > w2 ? w1 : w2 );

  w1  = fm.boundingRect( mFrequencyList->header()->label(4) ).width() + w0;
  w2  = fm.width('0')*3;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 4, w1 > w2 ? w1 : w2 );
  
  w1  = fm.boundingRect( mFrequencyList->header()->label(5) ).width() + w0;
  w2  = fm.width('0')*10;
  w3 += w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 5, w1 > w2 ? w1 : w2 );

  w4 = mFrequencyList->viewport()->width() - w3;
  w1 = fm.boundingRect( mFrequencyList->header()->label(6) ).width() + w0;
  w2 = fm.width('0')*3;
  w1 = w1 > w2 ? w1 : w2;
  mFrequencyList->setColumnWidth( 6, w1 > w4 ? w1 : w4 );
}



khexedit'CFileInfoDialog::resizeEvent() (./kdeutils/khexedit/fileinfodialog.cc:297)

void CFileInfoDialog::resizeEvent( QResizeEvent * )
{
  setColumnWidth();
}



khexedit'CFileInfoDialog::showEvent() (./kdeutils/khexedit/fileinfodialog.cc:303)

void CFileInfoDialog::showEvent( QShowEvent *e )
{
  KDialogBase::showEvent(e);
  setColumnWidth();
  mFrequencyList->setFocus();
}



khexedit'CFileInfoDialog::timerEvent() (./kdeutils/khexedit/fileinfodialog.cc:311)

void CFileInfoDialog::timerEvent( QTimerEvent * )
{
  killTimers();
  slotUser1();
}