void StatusBarMessageLabel::paintEvent(QPaintEvent* /* event */)
{
    QPixmap buffer(size());
    QPainter painter(&buffer);

    // draw background
    QColor backgroundColor(colorGroup().background());
    QColor foregroundColor(KGlobalSettings::textColor());
    if (m_illumination > 0) {
        backgroundColor = mixColors(backgroundColor, QColor(255, 255, 64), m_illumination);
        foregroundColor = mixColors(foregroundColor, QColor(0, 0, 0), m_illumination);
    }
    painter.setBrush(backgroundColor);
    painter.setPen(backgroundColor);
    painter.drawRect(QRect(0, 0, width(), height()));

    // draw pixmap
    int x = pixmapGap();
    int y = (height() - m_pixmap.height()) / 2;

    if (!m_pixmap.isNull()) {
        painter.drawPixmap(x, y, m_pixmap);
        x += m_pixmap.width() + pixmapGap();
    }

    // draw text
    painter.setPen(foregroundColor);
    painter.drawText(QRect(x, 0, width() - x, height()), Qt::AlignVCenter | Qt::WordBreak, m_text);
    painter.end();

    bitBlt(this, 0, 0, &buffer);
}
Exemplo n.º 2
0
void ToolSettings::selectTool(tools::Type tool)
{
	tools::ToolSettings *ts = getToolSettingsPage(tool);
	if(!ts) {
		qWarning("selectTool: invalid tool %d", tool);
		return;
	}

	_currenttool = ts;

	// Deselect annotation on tool change
	if(tool != tools::ANNOTATION) {
		int a = _textsettings->selected();
		if(a)
			_textsettings->setSelection(0);
	}

	setWindowTitle(_currenttool->getTitle());
	_widgets->setCurrentWidget(_currenttool->getUi());
	_currenttool->setForeground(foregroundColor());
	_currenttool->setBackground(backgroundColor());
	_currenttool->restoreToolSettings(_toolprops[currentToolSlot()].tool(_currenttool->getName()));
	_toolprops[_currentQuickslot].setCurrentTool(tool);

	updateToolSlot(currentToolSlot(), true);
	emit toolChanged(tool);
	emit sizeChanged(_currenttool->getSize());
	updateSubpixelMode();
}
bool KstViewLabel::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w);
  if (!widget) {
    return false;
  }

  if (!isNew) {
    widget->_text->setText(text());
  }

  widget->_precision->setValue(int(dataPrecision()));
  widget->_rotation->setValue(double(rotation()));
  widget->_fontSize->setValue(int(fontSize()));
  widget->_horizontal->setCurrentItem(horizJustifyWrap());
  widget->_fontColor->setColor(foregroundColor());
  widget->_font->setCurrentFont(fontName());

  widget->_transparent->setChecked(transparent());
  widget->_border->setValue(borderWidth());
  widget->_boxColors->setForeground(borderColor());
  widget->_boxColors->setBackground(backgroundColor());
  widget->_margin->setValue(labelMargin());

  widget->_text->setFocus();

  return true;
}
Exemplo n.º 4
0
void VCWidget::chooseForegroundColor()
{
	QColor color;
	color = QColorDialog::getColor(foregroundColor());
	if (color.isValid())
		setForegroundColor(color);
}
Exemplo n.º 5
0
void kpDualColorButton::mouseMoveEvent (QMouseEvent *e)
{
#if DEBUG_KP_DUAL_COLOR_BUTTON
    qCDebug(kpLogWidgets) << "kpDualColorButton::mouseMoveEvent() pos=" << e->pos ()
              << " buttons=" << e->buttons ()
              << " dragStartPoint=" << m_dragStartPoint << endl;
#endif

    if (m_dragStartPoint == KP_INVALID_POINT)
        return;

    if (!(e->buttons () & Qt::LeftButton))
    {
        m_dragStartPoint = KP_INVALID_POINT;
        return;
    }

    const int delay = QApplication::startDragDistance ();
    if (e->x () < m_dragStartPoint.x () - delay ||
        e->x () > m_dragStartPoint.x () + delay ||
        e->y () < m_dragStartPoint.y () - delay ||
        e->y () > m_dragStartPoint.y () + delay)
    {
    #if DEBUG_KP_DUAL_COLOR_BUTTON
        qCDebug(kpLogWidgets) << "\tstarting drag as long as it's in a rectangle";
    #endif

        kpColor color;

        if (foregroundRect ().contains (m_dragStartPoint))
            color = foregroundColor ();
        else if (backgroundRect ().contains (m_dragStartPoint))
            color = backgroundColor ();
        else
        {
            // "color" is left as invalid.
        }

    #if DEBUG_KP_DUAL_COLOR_BUTTON
        qCDebug(kpLogWidgets) << "\tcolor.isValid=" << color.isValid ()
                  << " rgb=" << (color.isValid () ? (int *) color.toQRgb () : 0)
                  << endl;
    #endif

        if (color.isValid ())
        {
            if (!color.isTransparent ())
                KColorMimeData::createDrag (color.toQColor (), this)->exec ();
        }

        m_dragStartPoint = KP_INVALID_POINT;
    }
}
Exemplo n.º 6
0
/** fill the custom widget with current properties */
bool KstViewLegend::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLegendWidget *widget = dynamic_cast<ViewLegendWidget*>(w);
  if (!widget) {
    return false;
  }

  KstBaseCurveList allCurves = kstObjectSubList<KstDataObject, KstBaseCurve>(KST::dataObjectList);
  
  if (isNew) {
    widget->_fontSize->setValue(0);
    widget->_fontColor->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_font->setCurrentFont(KstApp::inst()->defaultFont());
    widget->_margin->setValue(5);
    widget->_boxColors->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_vertical->setChecked(true);
    widget->_transparent->setChecked(false);
    widget->_border->setValue(2);
    widget->_title->setText("");
    widget->TrackContents->setChecked(true);
 
    for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) {
      (*it)->readLock();
      widget->AvailableCurveList->insertItem((*it)->tagName());
      (*it)->unlock();
    }

  } else { // fill legend properties into widget
    widget->TrackContents->setChecked(trackContents());
    widget->_title->setText(title());
    widget->_fontSize->setValue(int(fontSize()));
    widget->_fontColor->setColor(foregroundColor());
    widget->_font->setCurrentFont(fontName());
    widget->_transparent->setChecked(transparent());
    widget->_border->setValue(borderWidth());
    widget->_boxColors->setColor(borderColor());
    widget->_margin->setValue(_legendMargin);
    widget->_vertical->setChecked(vertical());
    for (KstBaseCurveList::ConstIterator it = _curves.begin(); it != _curves.end(); ++it) {
      (*it)->readLock();
      widget->DisplayedCurveList->insertItem((*it)->tagName());
      (*it)->unlock();
    }
    for (KstBaseCurveList::ConstIterator it = allCurves.begin(); it != allCurves.end(); ++it) {
      (*it)->readLock();
      if (_curves.find(*it) == _curves.end()) {
        widget->AvailableCurveList->insertItem((*it)->tagName());
      }
      (*it)->unlock();
    }
  }
  return false;
}
Exemplo n.º 7
0
void KstViewLegend::drawToBuffer() {
  setDirty(false);

  _backBuffer.buffer().resize(contentsRect().size());
  _backBuffer.buffer().fill(backgroundColor());
  KstPainter p;
  p.begin(&_backBuffer.buffer());
  QPen pen;
  pen.setColor(foregroundColor());
  p.setPen(pen);
  drawToPainter(p);
  p.end();
}
Exemplo n.º 8
0
bool KstViewLabel::fillConfigWidget(QWidget *w, bool isNew) const {
  ViewLabelWidget *widget = dynamic_cast<ViewLabelWidget*>(w);
  if (!widget) {
    return false;
  }
  
  if (isNew) { // probably a new label: set widget to defaults
    widget->_precision->setValue(8);
    widget->_rotation->setValue(0);
    widget->_fontSize->setValue(0);
    widget->_horizontal->setCurrentItem(0);
    widget->_fontColor->setColor(KstSettings::globalSettings()->foregroundColor);
    widget->_font->setCurrentFont(KstApp::inst()->defaultFont());
    widget->_margin->setValue(5);

    widget->_boxColors->setColor(KstSettings::globalSettings()->backgroundColor);

    if (size().width() * size().height() < 25) { // assume a click, and default to just text
      widget->_transparent->setChecked(true);
      widget->_border->setValue(0);
    } else { // someone drew a box, so assume that is what they wanted
      widget->_transparent->setChecked(false);
      widget->_border->setValue(2);
    }

  } else {
    // No, this is broken.  It kills latex.
#if 0
    // replace \n & \t with tabs and newlines for the text edit box
    QString tmpstr = text();
    tmpstr.replace(QString("\\n"), "\n");
    tmpstr.replace(QString("\\t"), "\t");
    widget->_text->setText(tmpstr);
#endif
    widget->_text->setText(text());

    widget->_precision->setValue(int(dataPrecision()));
    widget->_rotation->setValue(double(rotation()));
    widget->_fontSize->setValue(int(fontSize()));
    widget->_horizontal->setCurrentIndex(horizJustifyWrap());
    widget->_fontColor->setColor(foregroundColor());
    widget->_font->setCurrentFont(fontName());

    widget->_transparent->setChecked(transparent());
    widget->_border->setValue(borderWidth());
    widget->_boxColors->setColor(borderColor());
    widget->_margin->setValue(_labelMargin);
  }
  widget->_text->setFocus();
  return true;
}
Exemplo n.º 9
0
	void BorderBar::paintEvent(QPaintEvent *)
	{
		QRectF rect(2, 2, width()-4, height()-4);
		QPainter painter(this);
		painter.setRenderHint(QPainter::Antialiasing, true);		//	边缘平滑..

		painter.setBrush(backgroundColor());
		painter.setPen(Qt::NoPen);
		painter.drawEllipse(rect);
		painter.setBrush(Qt::NoBrush);

		m_pen.setColor(foregroundColor());
		m_pen.setWidth(4);
		painter.setPen(m_pen);

		painter.drawArc(rect, 0.25 * RADIAN, -percentage() * RADIAN);	//	+: 逆时针 -: 顺时针
		DRAWTEXT(painter, m_pen, m_font);		//	绘画文字..
	}
Exemplo n.º 10
0
PStyle &PStyle::operator =(const PStyle &obj)
{
    inverted(obj.inverted());
    size(obj.size());
    lineWidth(obj.lineWidth());
    smooth(obj.smooth());
    leftPadding(obj.leftPadding());
    rightPadding(obj.rightPadding());
    topPadding(obj.topPadding());
    bottomPadding(obj.bottomPadding());
    foregroundColor(obj.foregroundColor());
    backgroundColor(obj.backgroundColor());
    borderColor(obj.borderColor());
    selectedForegroundColor(obj.selectedForegroundColor());
    selectedBackgroundColor(obj.selectedBackgroundColor());
    selectedBorderColor(obj.selectedBorderColor());

    return *this;
}
Exemplo n.º 11
0
void ToolSettings::selectTool(tools::Tool::Type tool)
{
	tools::ToolSettings *ts = getToolSettingsPage(tool);
	if(!ts) {
		qWarning("selectTool: invalid tool %d", tool);
		return;
	}

	_currenttool = ts;

	setWindowTitle(QStringLiteral("%1. %2").arg(currentToolSlot()+1).arg(_currenttool->getTitle()));
	m_widgets->setCurrentWidget(_currenttool->getUi());
	_currenttool->setForeground(foregroundColor());
	_currenttool->restoreToolSettings(_toolprops[currentToolSlot()].tool(_currenttool->getName()));
	_toolprops[_currentQuickslot].setCurrentTool(tool);

	updateToolSlot(currentToolSlot(), true);
	emit toolChanged(tool);
	emit sizeChanged(_currenttool->getSize());
	updateSubpixelMode();
}
void
BreadcrumbItemSortButton::paintEvent( QPaintEvent *event )
{
    Q_UNUSED( event )
    QPainter painter(this);

    const int buttonHeight = height();
    const int preferredWidth = qMax( minimumWidth(), sizeHint().width() );
    const int buttonWidth = qMin( preferredWidth, width() );

    int left, top, right, bottom;
    getContentsMargins ( &left, &top, &right, &bottom );
    const int padding = 2;

    const int arrowLeft = buttonWidth - m_arrowWidth - padding;
    const int arrowTop = ( ( buttonHeight - top - bottom) - m_arrowHeight )/2;
    m_arrowRect = QRect( arrowLeft, arrowTop, m_arrowWidth, m_arrowHeight );

    drawHoverBackground( &painter );

    const QColor fgColor = foregroundColor();
    QStyleOption option;
    option.initFrom(this);
    option.rect = m_arrowRect;
    option.palette = palette();
    option.palette.setColor(QPalette::Text, fgColor);
    option.palette.setColor(QPalette::WindowText, fgColor);
    option.palette.setColor(QPalette::ButtonText, fgColor);

    if( m_order == Qt::DescendingOrder )
        style()->drawPrimitive( QStyle::PE_IndicatorArrowDown, &option, &painter, this );
    else
        style()->drawPrimitive( QStyle::PE_IndicatorArrowUp, &option, &painter, this );

    QRect newPaintRect( 0, 0, buttonWidth - m_arrowWidth - padding, buttonHeight );
    QPaintEvent newEvent( newPaintRect );
    BreadcrumbItemButton::paintEvent( &newEvent );
}
Exemplo n.º 13
0
void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent* event)
{
    Q_UNUSED(event);

    QPainter painter(this);
    drawHoverBackground(&painter);

    const QColor fgColor = foregroundColor();

    QStyleOption option;
    option.initFrom(this);
    option.rect = QRect(0, 0, width(), height());
    option.palette = palette();
    option.palette.setColor(QPalette::Text, fgColor);
    option.palette.setColor(QPalette::WindowText, fgColor);
    option.palette.setColor(QPalette::ButtonText, fgColor);

    if (layoutDirection() == Qt::LeftToRight) {
        style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this);
    } else {
        style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this);
    }
}
Exemplo n.º 14
0
void AnalogClock::paintEvent( QPaintEvent * )	// paint clock
{
    if ( !isVisible() )				// is is invisible
	return;
    time = QTime::currentTime();		// save current time

    QPointArray pts;
    QPainter paint( this );
    paint.setBrush( foregroundColor() );	// fill with foreground color

    QPoint cp = rect().center();		// widget center point
    int d = QMIN(width(),height());		// we want a circular clock

    QWMatrix matrix;				// setup transformation matrix
    matrix.translate( cp.x(), cp.y() );		// origin at widget center
    matrix.scale( d/1000.0F, d/1000.0F );	// scale coordinate system

    float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
    matrix.rotate( h_angle );			// rotate to draw hour hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
    paint.drawPolygon( pts );			// draw hour hand
    matrix.rotate( -h_angle );			// rotate back to zero

    float m_angle = (time.minute()-15)*6;
    matrix.rotate( m_angle );			// rotate to draw minute hand
    paint.setWorldMatrix( matrix );
    pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
    paint.drawPolygon( pts );			// draw minute hand
    matrix.rotate( -m_angle );			// rotate back to zero

    for ( int i=0; i<12; i++ ) {		// draw hour lines
	paint.setWorldMatrix( matrix );
	paint.drawLine( 450,0, 500,0 );
	matrix.rotate( 30 );
    }
}
Exemplo n.º 15
0
  void ViewerWidget::postDraw(){

    // Reset model view matrix to world coordinates origin
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    camera()->loadModelViewMatrix();
    // TODO restore model loadProjectionMatrixStereo

    // Save OpenGL state
    glPushAttrib(GL_ALL_ATTRIB_BITS);

    glDisable(GL_COLOR_MATERIAL);
    qglColor(foregroundColor());

    if (gridIsDrawn()){
      glLineWidth(1.0);
      drawGrid(5.0, 10);
    }
    if (axisIsDrawn()){
      glLineWidth(2.0);
      drawAxis(1.0);
    }

    // Restore GL state
    glPopAttrib();
    glPopMatrix();

    m_drawAxis = axisIsDrawn();
    m_drawGrid = gridIsDrawn();
    setAxisIsDrawn(false);
    setGridIsDrawn(false);
    QGLViewer::postDraw();

    setAxisIsDrawn(m_drawAxis);
    setGridIsDrawn(m_drawGrid);
  }
Exemplo n.º 16
0
void QtHighlightEditor::ruleToDialog(const HighlightRule& rule)
{
	ui_.chatRadio->setEnabled(true);
	ui_.roomRadio->setEnabled(true);

	if (rule.getMatchMUC()) {
		ui_.chatRadio->setChecked(false);
		ui_.roomRadio->setChecked(true);
	} else {
		ui_.chatRadio->setChecked(true);
		ui_.roomRadio->setChecked(false);
	}

	ui_.allMsgRadio->setEnabled(true);
	ui_.allMsgRadio->setChecked(true); /* this is the default radio button */
	jid_->setText("");
	ui_.keyword->setText("");
	ui_.matchPartialWords->setChecked(false);
	ui_.matchCase->setChecked(false);

	ui_.nickIsKeyword->setEnabled(true);
	if (rule.getNickIsKeyword()) {
		ui_.nickIsKeyword->setChecked(true);
	}

	ui_.senderRadio->setEnabled(true);
	std::vector<std::string> senders = rule.getSenders();
	if (!senders.empty()) {
		ui_.senderRadio->setChecked(true);
		jid_->setText(P2QSTRING(senders[0]));
	}

	ui_.keywordRadio->setEnabled(true);
	std::vector<std::string> keywords = rule.getKeywords();
	if (!keywords.empty()) {
		ui_.keywordRadio->setChecked(true);
		ui_.keyword->setText(P2QSTRING(keywords[0]));
		ui_.matchPartialWords->setChecked(!rule.getMatchWholeWords());
		ui_.matchCase->setChecked(rule.getMatchCase());
	}

	const HighlightAction& action = rule.getAction();

	ui_.noColorRadio->setEnabled(true);
	ui_.customColorRadio->setEnabled(true);
	if (action.getTextColor().empty() && action.getTextBackground().empty()) {
		ui_.noColorRadio->setChecked(true);
		ui_.foregroundColor->setEnabled(false);
		ui_.backgroundColor->setEnabled(false);
	} else {
		ui_.foregroundColor->setEnabled(true);
		ui_.backgroundColor->setEnabled(true);
		QColor foregroundColor(P2QSTRING(action.getTextColor()));
		ui_.foregroundColor->setColor(foregroundColor);
		QColor backgroundColor(P2QSTRING(action.getTextBackground()));
		ui_.backgroundColor->setColor(backgroundColor);
		ui_.customColorRadio->setChecked(true);
	}

	ui_.noSoundRadio->setEnabled(true);
	ui_.defaultSoundRadio->setEnabled(true);
	ui_.customSoundRadio->setEnabled(true);
	ui_.soundFile->setText("");
	ui_.soundFile->setEnabled(false);
	ui_.soundFileButton->setEnabled(false);
	if (action.playSound()) {
		if (action.getSoundFile().empty()) {
			ui_.defaultSoundRadio->setChecked(true);
		} else {
			ui_.customSoundRadio->setChecked(true);
			ui_.soundFile->setText(P2QSTRING(action.getSoundFile()));
			ui_.soundFile->setEnabled(true);
			ui_.soundFileButton->setEnabled(true);
		}
	} else {
		ui_.noSoundRadio->setChecked(true);
	}

	/* set radio button child option states */
	setChildWidgetStates();
}
Exemplo n.º 17
0
void KdmClock::paintEvent( QPaintEvent * )
{
	if (!isVisible())
		return;

	QPainter p( this );
	drawFrame( &p );

	QPixmap pm( contentsRect().size() );
	QPainter paint;
	paint.begin( &pm );
	paint.fillRect( contentsRect(), mBackgroundBrush );

	// get current time
	QTime time = QTime::currentTime();

/*
	if (mDigital) {
		QString buf;
		if (mSecond)
			buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(),
			             time.second() );
		else
			buf.sprintf( "%02d:%02d", time.hour(), time.minute() );
		mFont.setPointSize( QMIN( (int)(width()/buf.length()*1.5),height() ) );
		paint.setFont( mFont );
		paint.setPen( backgroundColor() );
		paint.drawText( contentsRect(),AlignHCenter|AlignVCenter, buf,-1,0,0 );
	} else {
*/
		QPointArray pts;
		QPoint cp = contentsRect().center() - QPoint( 2,2 );
		int d = QMIN( contentsRect().width()-15,contentsRect().height()-15 );
		paint.setPen( foregroundColor() );
		paint.setBrush( foregroundColor() );

		QWMatrix matrix;
		matrix.translate( cp.x(), cp.y() );
		matrix.scale( d/1000.0F, d/1000.0F );

		// Hour
		float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
		matrix.rotate( h_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -20,0,  0,-20, 300,0, 0,20 );
		paint.drawPolygon( pts );
		matrix.rotate( -h_angle );

		// Minute
		float m_angle = (time.minute()-15)*6;
		matrix.rotate( m_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
		paint.drawPolygon( pts );
		matrix.rotate( -m_angle );

		// Second
		float s_angle = (time.second()-15)*6;
		matrix.rotate( s_angle );
		paint.setWorldMatrix( matrix );
		pts.setPoints( 4,0,0,0,0,400,0,0,0 );
		if (mSecond)
			paint.drawPolygon( pts );
		matrix.rotate( -s_angle );

		// quadrante
		for (int i=0 ; i < 60 ; i++) {
			paint.setWorldMatrix( matrix );
			if ((i % 5) == 0)
				paint.drawLine( 450,0, 500,0 ); // draw hour lines
			else
				paint.drawPoint( 480,0 ); // draw second lines
			matrix.rotate( 6 );
		}

//	} // if (mDigital)
	paint.end();

	// flicker free code by Remi Guyomarch <*****@*****.**>
	bitBlt( this, contentsRect().topLeft(), &pm );
}
Exemplo n.º 18
0
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();
}
void KstViewLabel::drawToPainter(Label::Parsed *lp, QPainter& p) {
  int hJust = KST_JUSTIFY_H(_justify);
  if (QApplication::reverseLayout()) {
    if (hJust == KST_JUSTIFY_H_NONE) {
      hJust = KST_JUSTIFY_H_RIGHT;
    }
  } else {
    if (hJust == KST_JUSTIFY_H_NONE) {
      hJust = KST_JUSTIFY_H_LEFT;
    }
  }

  RenderContext rc(_fontName, _absFontSize, &p);
  rc.setSubstituteScalars(_replace);
  rc.precision = _dataPrecision;
  rc._cache = &_cache.data;
  _cache.valid = false;
  _cache.data.clear();
  double rotationRadians = M_PI * (int(_rotation) % 360) / 180;
  double absin = fabs(sin(rotationRadians));
  double abcos = fabs(cos(rotationRadians));

  int tx = 0, ty = 0; // translation
  const QRect cr(contentsRect());

  switch (hJust) {
    case KST_JUSTIFY_H_RIGHT:
      rc.x = -_textWidth / 2;
      tx = cr.width() - int(_textWidth * abcos + _textHeight * absin) / 2 - _labelMargin*_ascent/10;
      break;
    case KST_JUSTIFY_H_CENTER:
      rc.x = -_textWidth / 2;
      tx = cr.width() / 2;
      break;
    case KST_JUSTIFY_H_NONE:
      abort(); // should never be able to happen
    case KST_JUSTIFY_H_LEFT:
    default:
      rc.x = -_textWidth / 2;
      tx = int(_textWidth * abcos + _textHeight * absin) / 2  + _labelMargin*_ascent/10;
      break;
  }

  rc.y = _ascent - _textHeight / 2;
  ty = int(_textHeight * abcos + _textWidth * absin) / 2 + _labelMargin*_ascent/10;

  p.translate(tx, ty);
  p.rotate(_rotation);

  rc.pen = foregroundColor();

  rc.xStart = rc.x;
#ifdef BENCHMARK
  QTime t;
  t.start();
#endif
  if (lp && lp->chunk) {
    renderLabel(rc, lp->chunk, _vectorsUsed, _scalarsUsed, _stringsUsed);
    _cache.valid = true;
  }
#ifdef BENCHMARK
  kstdDebug() << "render took: " << t.elapsed() << endl;
  t.start();
#endif
  QApplication::syncX();
#ifdef BENCHMARK
  kstdDebug() << "sync X took: " << t.elapsed() << endl;
#endif
}