QBitmap Slider::drawValue() { QFontMetrics fm(this->font()); QString st; st.setNum(value,'f',precision); QPainter painter; int _x,_y; QBitmap res; if (orientation == 0) { res.resize(width(),(height()-20)/2); res.fill(Qt::color0); painter.begin(&res); painter.setPen(Qt::color1); painter.setBrush(Qt::color1); painter.setFont(this->font()); _x = (int)((res.width()-fm.width(st))/2); _y = (int)(res.height()); painter.drawText(_x,_y,st); } else if (orientation == 1) { res.resize((width()-20)/2,height()); res.fill(Qt::color0); painter.begin(&res); painter.setPen(Qt::color1); painter.setBrush(Qt::color1); painter.setFont(this->font()); _x = 0; _y = (int)((res.height()+fm.height())/2); painter.drawText(_x,_y,st); } painter.end(); return res; }
void OSDWidget::renderOSDText( const QString &text) { static QBitmap mask; // Set a sensible maximum size, don't cover the whole desktop or cross the screen //Actually unused but it definitly should //QSize max = QApplication::desktop() ->screen( m_screen ) ->size() - QSize( MARGIN*2 + 20, 100 ); if(this->m_srt!=0){ delete m_srt; } this->m_srt=new QSimpleRichText(text,this->font(),this->m_context); // The title cannnot be taller than one line // AlignAuto = align Arabic to the right, etc. int w=this->m_srt->widthUsed(); int h=this->m_srt->height(); osdBuffer.resize(w,h); mask.resize(w,h); // Start painting! QPainter bufferPainter( &osdBuffer ); QPainter maskPainter( &mask ); // Draw backing rectangle //bufferPainter.save(); bufferPainter.setPen( Qt::black ); bufferPainter.setBrush( backgroundColor() ); bufferPainter.drawRoundRect( 0,0,w,h, 1500 /w, 1500/h); //bufferPainter.restore(); this->m_srt->draw(&bufferPainter,0,0,QRect(),this->colorGroup()); // Masking for transparency mask.fill( Qt::black ); maskPainter.setBrush( Qt::white ); maskPainter.drawRoundRect(0,0,w,h, 1500/w,1500/h); setMask( mask ); //do last to reduce noticeable change when showing multiple OSDs in succession reposition(QSize(w,h)); m_currentText = text; m_dirty = false; if(this->m_linking&&this==this->mouseGrabber()){ this->releaseMouse(); this->m_linking=false; } update(); }
void QPixmap::resize( int w, int h ) { if ( w < 1 || h < 1 ) { // becomes null QPixmap pm( 0, 0, 0, data->bitmap, data->optim ); *this = pm; return; } int d; if ( depth() > 0 ) d = depth(); else d = isQBitmap() ? 1 : -1; // Create new pixmap QPixmap pm( w, h, d, data->bitmap, data->optim ); #ifdef Q_WS_X11 pm.x11SetScreen( x11Screen() ); #endif // Q_WS_X11 if ( !data->uninit && !isNull() ) // has existing pixmap bitBlt( &pm, 0, 0, this, 0, 0, // copy old pixmap QMIN(width(), w), QMIN(height(),h), CopyROP, TRUE ); #if defined(Q_WS_MAC) if(data->alphapm) { data->alphapm->resize(w, h); } else #elif defined(Q_WS_X11) && !defined(QT_NO_XFTFREETYPE) if (data->alphapm) qWarning("QPixmap::resize: TODO: resize alpha data"); else #endif // Q_WS_X11 if ( data->mask ) { // resize mask as well if ( data->selfmask ) { // preserve self-mask pm.setMask( *((QBitmap*)&pm) ); } else { // independent mask QBitmap m = *data->mask; m.resize( w, h ); pm.setMask( m ); } } *this = pm; }
void OSDWidget::renderOSDText( const QString &txt ) { // Escaped text QString text = Konversation::removeIrcMarkup(txt); static QBitmap mask; //This is various spacings and margins, based on the font to look "just right" const uint METRIC = fontMetrics().width( 'x' ); // Set a sensible maximum size, don't cover the whole desktop or cross the screen QSize max = QApplication::desktop()->screen( m_screen )->size() - QSize( MARGIN*2 + METRIC*2, 100 ); QFont titleFont( "Arial", 12, QFont::Bold ); QFontMetrics titleFm( titleFont ); // The title cannnot be taller than one line // AlignAuto = align Arabic to the right, etc. QRect titleRect = titleFm.boundingRect( 0, 0, max.width() - METRIC, titleFm.height(), AlignAuto, m_appName ); // The osd cannot be larger than the screen QRect textRect = fontMetrics().boundingRect( 0, 0, max.width(), max.height(), AlignAuto | WordBreak, text ); if ( textRect.width() < titleRect.width() ) textRect.setWidth( titleRect.width() ); //this should still be within the screen bounds textRect.addCoords( 0, 0, METRIC*2, titleRect.height() + METRIC ); osdBuffer.resize( textRect.size() ); mask.resize( textRect.size() ); // Start painting! QPainter bufferPainter( &osdBuffer ); QPainter maskPainter( &mask ); // Draw backing rectangle const uint xround = (METRIC * 200) / textRect.width(); const uint yround = (METRIC * 200) / textRect.height(); bufferPainter.setPen( Qt::black ); bufferPainter.setBrush( backgroundColor() ); bufferPainter.drawRoundRect( textRect, xround, yround ); bufferPainter.setFont( font() ); const uint w = textRect.width() - 1; const uint h = textRect.height() - 1; // Draw the text shadow if ( m_shadow ) { bufferPainter.setPen( backgroundColor().dark( 175 ) ); bufferPainter.drawText( METRIC + 3, (METRIC/2) + titleFm.height() + 1, w, h, AlignLeft | WordBreak, text ); } // Draw the text bufferPainter.setPen( foregroundColor() ); bufferPainter.drawText( METRIC, (METRIC/2) + titleFm.height() - 1, w, h, AlignLeft | WordBreak, text ); // Draw the title text bufferPainter.setFont( titleFont ); bufferPainter.drawText( METRIC * 2, (METRIC/2), w, h, AlignLeft, m_appName ); // Masking for transparency mask.fill( Qt::black ); maskPainter.setBrush( Qt::white ); maskPainter.drawRoundRect( textRect, xround, yround ); setMask( mask ); //do last to reduce noticeable change when showing multiple OSDs in succession reposition( textRect.size() ); m_currentText = text; m_dirty = false; update(); }