コード例 #1
0
void K3bListViewItem::paintProgressBar( QPainter* p, const QColorGroup& cgh, int col, int width )
{
  ColumnInfo* info = getColumnInfo( col );

  QStyle::SFlags flags = QStyle::Style_Default;
  if( listView()->isEnabled() )
    flags |= QStyle::Style_Enabled;
  if( listView()->hasFocus() )
    flags |= QStyle::Style_HasFocus;

  // FIXME: the QPainter is translated so 0, m_vMargin is the upper left of our paint rect
  QRect r( 0, m_vMargin, width, height()-2*m_vMargin );

  // create the double buffer pixmap
  static QPixmap *doubleBuffer = 0;
  if( !doubleBuffer )
    doubleBuffer = new QPixmap;
  doubleBuffer->resize( width, height() );

  QPainter dbPainter( doubleBuffer );

  // clear the background (we cannot use paintEmptyArea since it's protected in QListView)
  if( K3bListView* lv = dynamic_cast<K3bListView*>(listView()) )
    lv->paintEmptyArea( &dbPainter, r );
  else
    dbPainter.fillRect( 0, 0, width, height(),
			cgh.brush( QPalette::backgroundRoleFromMode(listView()->viewport()->backgroundMode()) ) );

  // we want a little additional margin
  r.setLeft( r.left()+1 );
  r.setWidth( r.width()-2 );
  r.setTop( r.top()+1 );
  r.setHeight( r.height()-2 );

  // this might be a stupid hack but most styles do not reimplement drawPrimitive PE_ProgressBarChunk
  // so this way the user is happy....
  static QProgressBar* s_dummyProgressBar = 0;
  if( !s_dummyProgressBar ) {
    s_dummyProgressBar = new QProgressBar();
  }

  s_dummyProgressBar->setTotalSteps( info->totalProgressSteps );
  s_dummyProgressBar->setProgress( info->progressValue );

  // some styles use the widget's geometry
  s_dummyProgressBar->setGeometry( r );

  listView()->style().drawControl(QStyle::CE_ProgressBarContents, &dbPainter, s_dummyProgressBar, r, cgh, flags );
  listView()->style().drawControl(QStyle::CE_ProgressBarLabel, &dbPainter, s_dummyProgressBar, r, cgh, flags );

  // now we really paint the progress in the listview
  p->drawPixmap( 0, 0, *doubleBuffer );
}
コード例 #2
0
ファイル: widget.cpp プロジェクト: termos23/pi_test1
void Widget::paintEvent(QPaintEvent *e)
{
// рисуем с двойным буфером
    doubleBuffer = new QPixmap(this->width(), this->height()-20);
    QPainter painter(this);
    QPainter dbPainter(doubleBuffer);
    dbPainter.eraseRect(0, 0, this->width(), this->height()-20);
    GamePainter gamePainter;
    gamePainter.drowGame(&dbPainter,this->width(), this->height()-20, game);
    painter.drawPixmap(0, 20, *doubleBuffer, 0, 0, this->width(), this->height()-20);
//ухаха, килем пейнтеров
    painter.end();
    dbPainter.end();
}