GmckJobProgressOSD
::GmckJobProgressOSD( QWidget* parent
) : QWidget( parent, Qt
::Window | Qt
::WindowStaysOnTopHint | Qt
::X11BypassWindowManagerHint ),
m_dirty(true),
m_progress(0),
m_dragging(false),
m_screen(0),
m_position(s_outerMargin, s_outerMargin)
{
m_osdBuffer = pix;
setFocusPolicy( Qt::NoFocus );
// dummy size
resize( 100, 20 );
}
void GmckJobProgressOSD::renderOSD()
{
// -----------------------------------------
// | download |
// | GMCK ========== 40% |
// | |
// -----------------------------------------
// calculate needed size
if( true ) {
QPixmap icon
(":/icons/icon16x16.png");
int margin = 10;
int textWidth = fontMetrics().width( m_text );
// do not change the size every time the text changes, just in case we are too small
QSize newSize
( qMax
( qMax
( 2*margin
+ icon.
width() + margin
+ textWidth,
100 ), width
() ),
qMax( 2*margin + icon.height(), 2*margin + fontMetrics().height()*2 ) );
m_osdBuffer = m_osdBuffer.scaled( newSize );
p.setPen( Qt::white );
// draw the background and the frame
QRect thisRect
( -1,
-1, newSize.
width()+1, newSize.
height()+1 );
p.
fillRect( thisRect,
QColor(233,
116,
37));
p.drawRect( thisRect );
// draw the gmck icon
p.drawPixmap( margin, (newSize.height()-icon.height())/2, icon );
// draw the text
QSize textSize
= fontMetrics
().
size( 0, m_text
);
int textX = 2*margin + icon.width();
int textY = margin + fontMetrics().ascent();
p.drawText( textX, textY, m_text );
// draw the progress
textY += fontMetrics().descent() + 4;
QRect progressRect
( textX, textY, newSize.
width()-textX
-margin, newSize.
height()-textY
-margin
);
p.drawRect( progressRect );
progressRect.setWidth( m_progress > 0 ? m_progress*progressRect.width()/100 : 0 );
p.fillRect( progressRect, Qt::white );
// reposition the osd
reposition( newSize );
resize(newSize);
m_dirty = false;
update();
}
}
{
p->drawPixmap(0,0,m_osdBuffer);
}
GmckJobProgressOSD::GmckJobProgressOSD( QWidget* parent )
: QWidget( parent, Qt::Window | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint ),
m_dirty(true),
m_progress(0),
m_dragging(false),
m_screen(0),
m_position(s_outerMargin, s_outerMargin)
{
QPixmap pix(10,10);
m_osdBuffer = pix;
setFocusPolicy( Qt::NoFocus );
// dummy size
resize( 100, 20 );
}
void GmckJobProgressOSD::renderOSD()
{
// -----------------------------------------
// | download |
// | GMCK ========== 40% |
// | |
// -----------------------------------------
// calculate needed size
if( true ) {
QPixmap icon(":/icons/icon16x16.png");
int margin = 10;
int textWidth = fontMetrics().width( m_text );
// do not change the size every time the text changes, just in case we are too small
QSize newSize( qMax( qMax( 2*margin + icon.width() + margin + textWidth, 100 ), width() ),
qMax( 2*margin + icon.height(), 2*margin + fontMetrics().height()*2 ) );
m_osdBuffer = m_osdBuffer.scaled( newSize );
QPainter p( &m_osdBuffer );
p.setPen( Qt::white );
// draw the background and the frame
QRect thisRect( -1, -1, newSize.width()+1, newSize.height()+1 );
p.fillRect( thisRect, QColor(233,116,37));
p.drawRect( thisRect );
// draw the gmck icon
p.drawPixmap( margin, (newSize.height()-icon.height())/2, icon );
// draw the text
QSize textSize = fontMetrics().size( 0, m_text );
int textX = 2*margin + icon.width();
int textY = margin + fontMetrics().ascent();
p.drawText( textX, textY, m_text );
// draw the progress
textY += fontMetrics().descent() + 4;
QRect progressRect( textX, textY, newSize.width()-textX-margin, newSize.height()-textY-margin );
p.drawRect( progressRect );
progressRect.setWidth( m_progress > 0 ? m_progress*progressRect.width()/100 : 0 );
p.fillRect( progressRect, Qt::white );
// reposition the osd
reposition( newSize );
resize(newSize);
m_dirty = false;
update();
}
}
void GmckJobProgressOSD::paintEvent( QPaintEvent* )
{
QPainter *p = new QPainter(this);
p->drawPixmap(0,0,m_osdBuffer);
}
To copy to clipboard, switch view to plain text mode
Bookmarks