bool eventFilter(QObject *pO, QEvent *event)
    {
        if ( event->type() == QEvent::Paint) {
            QWidget* pW = qobject_cast<QWidget*>(pO);
            QColor backColor = NotificationServerSettings::instance()->value("notification_backgroundColor").value<QColor>();
            float fOpacity = NotificationServerSettings::instance()->value("notification_opacity").value<float>();
            QPainter painter ( pW );
            painter.setRenderHint(QPainter::Antialiasing);
            painter.setRenderHint(QPainter::HighQualityAntialiasing);

            // corners
            const int kShadowCornerSize = scShadowSize + scRadiusSize;
            painter.drawPixmap(0, 0, shadowsCorners.at(0));
            painter.drawPixmap(pW->width() - kShadowCornerSize, 0, shadowsCorners.at(1));
            painter.drawPixmap(pW->width() - kShadowCornerSize, pW->height() - kShadowCornerSize, shadowsCorners.at(2));
            painter.drawPixmap(0, pW->height() - kShadowCornerSize, shadowsCorners.at(3));

            //edges
            painter.drawTiledPixmap(kShadowCornerSize, 0,pW->width() - kShadowCornerSize*2, scShadowSize,shadowsEdges.at(0));
            painter.drawTiledPixmap(pW->width() - scShadowSize, kShadowCornerSize,scShadowSize, pW->height() - kShadowCornerSize*2,shadowsEdges.at(1));
            painter.drawTiledPixmap(kShadowCornerSize, pW->height() - scShadowSize,pW->width() - kShadowCornerSize*2, scShadowSize,shadowsEdges.at(2));
            painter.drawTiledPixmap(0, kShadowCornerSize,scShadowSize, pW->height() - kShadowCornerSize*2,shadowsEdges.at(3));


            // rounded pixmap
            painter.setBrush(backColor);
            painter.setPen(backColor);
            painter.setOpacity(fOpacity);
            painter.drawRoundedRect(scShadowSize,scShadowSize,pW->width()-2*scShadowSize, pW->height()-2*scShadowSize,scRadiusSize,scRadiusSize);
        }
    }
void LaptopClient::updateActiveBuffer( )
{
    QRect rTitle = titleRect();
    if( !bufferDirty && (lastBufferWidth == rTitle.width()))
        return;
    if ( rTitle.width() <= 0 || rTitle.height() <= 0 )
	return;
    lastBufferWidth = rTitle.width();
    bufferDirty = false;

    activeBuffer = QPixmap(rTitle.width(), rTitle.height());
    QPainter p;
    QRect r(0, 0, activeBuffer.width(), activeBuffer.height());
    p.begin(&activeBuffer);
    if(aUpperGradient){
        p.drawTiledPixmap(r, *aUpperGradient);
    }
    else{
        p.fillRect(r, options()->color(KDecoration::ColorTitleBar, true));
    }
    if(titlePix)
        p.drawTiledPixmap(r, *titlePix);

    p.setFont(options()->font(true, isToolWindow() ));
    QFontMetrics fm(options()->font(true));
    QPalette g = options()->palette(KDecoration::ColorTitleBar, true);
    g.setCurrentColorGroup( QPalette::Active );
    if(aUpperGradient)
        p.drawTiledPixmap(r.x()+((r.width()-fm.width(caption()))/2)-4,
                          r.y(), fm.width(caption())+8, r.height()-1,
                          *aUpperGradient);
    else
        p.fillRect(r.x()+((r.width()-fm.width(caption()))/2)-4, 0,
                   fm.width(caption())+8, r.height(),
                   g.brush(QPalette::Background));
    p.setPen(g.mid().color());
    p.drawLine(r.x(), r.y(), r.right(), r.y());
    p.drawLine(r.x(), r.y(), r.x(), r.bottom());
    p.setPen(g.color(QPalette::Button));
    p.drawLine(r.right(), r.y(), r.right(), r.bottom());
    p.drawLine(r.x(), r.bottom(), r.right(), r.bottom());
    p.setPen(options()->color(KDecoration::ColorFont, true));
    p.drawText(r.x(), r.y()+1, r.width(), r.height()-1,
               Qt::AlignCenter, caption() );
    g = options()->palette(KDecoration::ColorFrame, true);
    g.setCurrentColorGroup( QPalette::Active );
    p.setPen(g.background().color());
    p.drawPoint(r.x(), r.y());
    p.drawPoint(r.right(), r.y());
    p.drawLine(r.right()+1, r.y(), r.right()+1, r.bottom());
    p.end();
}
Beispiel #3
0
void KviThemedLabel::paintEvent(QPaintEvent *e)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter *p = new QPainter(this);

#if (QT_VERSION >= 0x050000)
	// In Qt5 QStyle::drawPrimitive seems to always overwrite the background, no matter what.
	qDrawShadePanel(p,0,0,width(),height(),palette(),true,1,NULL);

	QRect r(1,1,width()-1,height()-1);
#else
	QStyleOptionFrameV2 option;
	option.initFrom(this);

	style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this);

	QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this);

#endif

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col=KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(r, col);
	} else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, r.topLeft()) : mapTo(m_pKviWindow, r.topLeft());
		p->drawTiledPixmap(r,*(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QLabel::paintEvent(e);
}
	void paintEvent(QPaintEvent *event)
	{
		QPainter *p = new QPainter(this);
		p->drawTiledPixmap(0, 0, width(), height(), *pixmap());
		delete p;
		QLabel::paintEvent(event);
	}
void KviThemedLineEdit::paintEvent(QPaintEvent * event)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter * p = new QPainter(this);
	QPalette pal = palette();

	// In Qt5 QStyle::drawPrimitive seems to always overwrite the background, no matter what.
	qDrawShadePanel(p, 0, 0, width(), height(), palette(), true, 1, nullptr);

	QRect r(1, 1, width() - 2, height() - 2);

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(r, col);
		p->restore();
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt;
		if(m_pKviWindow)
			pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, r.topLeft()) : mapTo(m_pKviWindow, r.topLeft());
		else
			pnt = mapToGlobal(event->rect().topLeft());
		p->drawTiledPixmap(r, *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif

	QLineEdit::paintEvent(event);
}
Beispiel #6
0
void UrlDialogTreeWidget::paintEvent(QPaintEvent * event)
{
    QPainter * p = new QPainter(viewport());
    QStyleOptionViewItem option = viewOptions();
    QRect rect = event->rect();

#ifdef COMPILE_PSEUDO_TRANSPARENCY
    if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
    {
        p->save();
        p->setCompositionMode(QPainter::CompositionMode_Source);
        QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
        col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
        p->fillRect(rect, col);
        p->restore();
    }
    else if(g_pShadedChildGlobalDesktopBackground)
    {
        QPoint pnt = ((KviWindow *)parent())->isDocked() ? viewport()->mapTo(g_pMainWindow, rect.topLeft()) : viewport()->mapTo((KviWindow *)parent(), rect.topLeft());
        p->drawTiledPixmap(rect, *(g_pShadedChildGlobalDesktopBackground), pnt);
    }
    else
    {
#endif
        //FIXME this is not the treewindowlist
        p->fillRect(rect, KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground));
#ifdef COMPILE_PSEUDO_TRANSPARENCY
    }
#endif

    delete p;

    //call paint on all children
    QTreeWidget::paintEvent(event);
}
Beispiel #7
0
void TouchUI::draw( QPainter & painter )
{
	_screen_width = painter.window().width();
	_screen_height = painter.window().height();
	limitScroll();

	// draw background
	QRect rect(0,0,painter.window().width(),_height);
	painter.drawTiledPixmap( rect, _background );
	
	// draw icons
	for ( int i = 0; i < _items.count(); i++ )
	{
        UIItem * t = _items[i];
		int posx = t->x1;
		int posy = t->y1;
		if ( posx < 0 ) posx = _screen_width+posx;
		QSvgRenderer * image = t->image;
		if ( t->highlighted )
			painter.setCompositionMode( QPainter::CompositionMode_HardLight );
		else
			painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
		if ( image == NULL ) continue;
		int h = image->defaultSize().height();
		int w = image->defaultSize().width();
		int img_width = g_config.ui_size;
		int img_height = g_config.ui_size;
		ImageLoadThread::fitImage( w,h, img_width, img_height, false );
		QRectF r( posx+_xoffset, posy+_yoffset, w, h );
		image->render( &painter, r );
	}
}
Beispiel #8
0
void BitmapImage::drawPattern(GraphicsContext* ctxt, const FloatRect& tileRect, const AffineTransform& patternTransform,
                              const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect)
{
    QPixmap* framePixmap = nativeImageForCurrentFrame();
    if (!framePixmap) // If it's too early we won't have an image yet.
        return;

    QPixmap pixmap = *framePixmap;
    QRect tr = QRectF(tileRect).toRect();
    if (tr.x() || tr.y() || tr.width() != pixmap.width() || tr.height() != pixmap.height()) {
        pixmap = pixmap.copy(tr);
    }

    if (patternTransform.isIdentity()) {
        ctxt->save();
        ctxt->setCompositeOperation(op);
        QPainter* p = ctxt->platformContext();
        p->setBrushOrigin(phase);
        p->drawTiledPixmap(destRect, pixmap);
        ctxt->restore();
    } else {
        QBrush b(pixmap);
        b.setMatrix(patternTransform);
        ctxt->save();
        ctxt->setCompositeOperation(op);
        QPainter* p = ctxt->platformContext();
        p->setBrushOrigin(phase);
        p->fillRect(destRect, b);
        ctxt->restore();
    }
}
Beispiel #9
0
void TransparentBg::backgroundUpdated()
{
    if (parent()->inherits("QTextEdit")){
        QTextEdit *text = static_cast<QTextEdit*>(parent());
        const QPixmap *pix = background(text->colorGroup().color(QColorGroup::Base));
        QPoint pp = text->viewportToContents(QPoint(0, 0));
        bgX = pp.x();
        bgY = pp.y();
        if ((pix == NULL) || pix->isNull()){
            if (text->paper().pixmap() && !text->paper().pixmap()->isNull()){
                text->setPaper(QBrush(text->colorGroup().base()));
                text->setStaticBackground(false);
            }
            return;
        }
        QPoint pp1 = text->topLevelWidget()->mapFromGlobal(text->mapToGlobal(QPoint(0, 0)));
        QPixmap bg(bgX + text->width(), bgY + text->height());
        QPainter p;
        p.begin(&bg);
        p.drawTiledPixmap(bgX, bgY, text->width(), text->height(), *pix, pp1.x(), pp1.y());
        p.end();
        text->setPaper(QBrush(text->colorGroup().background(), bg));
        text->setStaticBackground(true);
        text->setBackgroundMode(QWidget::NoBackground);
        text->viewport()->setBackgroundMode(QWidget::NoBackground);
        return;
    }
    if (parent()->inherits("QListView")){
        QListView *p = static_cast<QListView*>(parent());
        p->viewport()->repaint();
    }
}
Beispiel #10
0
void KWMThemeClient::drawTitle(QPainter &dest)
{
    QRect titleRect = titlebar->geometry();
    QRect r(0, 0, titleRect.width(), titleRect.height());
    QPixmap buffer;

    if(buffer.width() == r.width())
        return;

    buffer.resize(r.size());
    QPainter p;
    p.begin(&buffer);

    if(titleSunken){
        qDrawShadeRect(&p, r, options()->colorGroup(KDecorationOptions::ColorFrame, isActive()),
                       true, 1, 0);
        r.setRect(r.x()+1, r.y()+1, r.width()-2, r.height()-2);
    }
    
    KPixmap *fill = isActive() ? aTitlePix : iTitlePix;
    if(fill)
        p.drawTiledPixmap(r, *fill);
    else if(titleGradient){
        fill = isActive() ? aGradient : iGradient;
        if(fill->width() != r.width()){
            fill->resize(r.width(), 20);
            KPixmapEffect::gradient(*fill,
                                    options()->color(KDecorationOptions::ColorTitleBar, isActive()),
                                    options()->color(KDecorationOptions::ColorTitleBlend, isActive()),
                                    grType);
        }
        p.drawTiledPixmap(r, *fill);
    }
    else{
        p.fillRect(r, options()->colorGroup(KDecorationOptions::ColorTitleBar, isActive()).
                   brush(QColorGroup::Button));
    }
    p.setFont(options()->font(isActive()));
    p.setPen(options()->color(KDecorationOptions::ColorFont, isActive()));
    // Add left & right margin
    r.setLeft(r.left()+5);
    r.setRight(r.right()-5);
    p.drawText(r, titleAlign, caption());
    p.end();

    dest.drawPixmap(titleRect.x(), titleRect.y(), buffer);
}
Beispiel #11
0
bool ColorSchemeWallpaper::draw(QPainter& painter, const QRect& rect)
{
    if (!_picture || _picture->isNull())
        return false;

    painter.drawTiledPixmap(rect, *_picture, rect.topLeft());
    return true;
}
Beispiel #12
0
const QPixmap &PlastikClient::captionPixmap() const
{
    bool active = isActive();

    if(m_captionPixmaps[active])
    {
        return *m_captionPixmaps[active];
    }

    // not found, create new pixmap...

    const uint maxCaptionLength = 300; // truncate captions longer than this!
    QString c(caption());
    if(c.length() > maxCaptionLength)
    {
        c.truncate(maxCaptionLength);
        c.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth = fm.width(c);
    int captionHeight = fm.height();

    const int th = layoutMetric(LM_TitleHeight, false) + layoutMetric(LM_TitleEdgeBottom, false);

    QPainter painter;

    const int thickness = 2;

    QPixmap *captionPixmap = new QPixmap(captionWidth + 2 * thickness, th);

    painter.begin(captionPixmap);
    painter.drawTiledPixmap(captionPixmap->rect(), Handler()->pixmap(TitleBarTile, active, isToolWindow()));

    painter.setFont(s_titleFont);
    QPoint tp(1, captionHeight - 1);
    if(Handler()->titleShadow())
    {
        QColor shadowColor;
        if(qGray(Handler()->getColor(TitleFont, active).rgb()) < 100)
            shadowColor = QColor(255, 255, 255);
        else
            shadowColor = QColor(0, 0, 0);

        painter.setPen(alphaBlendColors(options()->color(ColorTitleBar, active), shadowColor, 205));
        painter.drawText(tp + QPoint(1, 2), c);
        painter.setPen(alphaBlendColors(options()->color(ColorTitleBar, active), shadowColor, 225));
        painter.drawText(tp + QPoint(2, 2), c);
        painter.setPen(alphaBlendColors(options()->color(ColorTitleBar, active), shadowColor, 165));
        painter.drawText(tp + QPoint(1, 1), c);
    }
    painter.setPen(Handler()->getColor(TitleFont, active));
    painter.drawText(tp, c);
    painter.end();

    m_captionPixmaps[active] = captionPixmap;
    return *captionPixmap;
}
const QPixmap &PlastikClient::captionPixmap() const
{
    bool active = isActive();

    if (m_captionPixmaps[active]) {
        return *m_captionPixmaps[active];
    }

    // not found, create new pixmap...

    const int maxCaptionLength = 300; // truncate captions longer than this!
    QString c(caption() );
    if (c.length() > maxCaptionLength) {
        c.truncate(maxCaptionLength);
        c.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(c);
    int captionDescent = fm.descent();

    QFontMetrics fm_vmname(s_vmnameFont);
    captionWidth  += fm_vmname.width(qubes_vmname);
    if (fm_vmname.descent() > fm.descent()) captionDescent = fm_vmname.descent();

    const int th  = layoutMetric(LM_TitleHeight, false) + layoutMetric(LM_TitleEdgeBottom, false);

    QPainter painter;

    const int thickness = 2;

    QPixmap *captionPixmap = new QPixmap(captionWidth+2*thickness, th);

    painter.begin(captionPixmap);
    painter.drawTiledPixmap(captionPixmap->rect(),
                            Handler()->pixmap(qubes_label, TitleBarTile, active, isToolWindow()) );

    painter.setFont(s_vmnameFont);
    QRect boundingRect1 = painter.boundingRect(captionPixmap->rect(),
                                              Qt::AlignVCenter | Qt::AlignLeft, qubes_vmname);

    QPoint tp1 = boundingRect1.bottomLeft() - QPoint(0, captionDescent);
    QPoint tp2 = tp1 + QPoint (fm_vmname.width(qubes_vmname) + 5, 0);

    QColor fontColor = Handler()->getColor(qubes_label, TitleFont,active);

    painter.setPen(fontColor );

    painter.drawText(tp1, qubes_vmname );

    painter.setFont(s_titleFont);
    painter.drawText(tp2, c );

    painter.end();

    m_captionPixmaps[active] = captionPixmap;
    return *captionPixmap;
}
Beispiel #14
0
const int TabbedWidget::drawButton(int position, QPainter& painter)
{
    /* Draws the tab buttons. */

    static int x = 0;
    QPixmap tmp_pixmap;

    areas[position] = 0;
    x = (!position) ? 0 : x;

    // Initialize the painter.
    painter.setPen(font_color);
    painter.setFont((position == current_position) ? selected_font : unselected_font);

    // Draw the left border.
    if (position == current_position)
        tmp_pixmap = selected_left_image;
    else if (position != current_position + 1)
        tmp_pixmap = separator_image;

    painter.drawPixmap(x, 0, tmp_pixmap);
    areas[position] += tmp_pixmap.width();
    x += tmp_pixmap.width();

    // Draw the main contents.
    int width;
    QFontMetrics metrics(painter.font());

    width = metrics.width(captions[position]) + 10;

    tmp_pixmap = (position == current_position) ? selected_image : unselected_image;
    painter.drawTiledPixmap(x, 0, width, height(), tmp_pixmap);

    painter.drawText(x, 0, width + 1, height() + 1,
                     Qt::AlignHCenter | Qt::AlignVCenter,  captions[position]);

    areas[position] += width;
    x += width;

    // Draw the right border if needed.
    if (position == current_position)
    {
        painter.drawPixmap(x, 0, selected_right_image);
        areas[position] += selected_right_image.width();
        x += selected_right_image.width();
    }
    else if (position == (int) items.count() - 1)
    {
        painter.drawPixmap(x, 0, separator_image);
        areas[position] += separator_image.width();
        x += separator_image.width();
    }

    return x;
}
Beispiel #15
0
void KoPatternBackground::paint(QPainter &painter, const KoViewConverter &converter, KoShapePaintingContext &/*context*/, const QPainterPath &fillPath) const
{
    Q_D(const KoPatternBackground);
    if (! d->imageData)
        return;

    painter.save();

    if (d->repeat == Tiled) {
        // calculate scaling of pixmap
        QSizeF targetSize = d->targetSize();
        QSizeF imageSize = d->imageData->imageSize();
        qreal scaleX = targetSize.width() / imageSize.width();
        qreal scaleY = targetSize.height() / imageSize.height();

        QRectF targetRect = fillPath.boundingRect();
        // undo scaling on target rectangle
        targetRect.setWidth(targetRect.width() / scaleX);
        targetRect.setHeight(targetRect.height() / scaleY);

        // determine pattern offset
        QPointF offset = d->offsetFromRect(targetRect, imageSize);

        // create matrix for pixmap scaling
        QTransform matrix;
        matrix.scale(scaleX, scaleY);

        painter.setClipPath(fillPath);
        painter.setWorldTransform(matrix, true);
        painter.drawTiledPixmap(targetRect, d->imageData->pixmap(imageSize.toSize()), -offset);
    } else if (d->repeat == Original) {
        QRectF sourceRect(QPointF(0, 0), d->imageData->imageSize());
        QRectF targetRect(QPoint(0, 0), d->targetSize());
        targetRect.moveCenter(fillPath.boundingRect().center());
        painter.setClipPath(fillPath);
        painter.drawPixmap(targetRect, d->imageData->pixmap(sourceRect.size().toSize()), sourceRect);
    } else if (d->repeat == Stretched) {
        painter.setClipPath(fillPath);
        // undo conversion of the scaling so that we can use a nicely scaled image of the correct size
        qreal zoomX, zoomY;
        converter.zoom(&zoomX, &zoomY);
        zoomX = zoomX ? 1 / zoomX : zoomX;
        zoomY = zoomY ? 1 / zoomY : zoomY;
        painter.scale(zoomX, zoomY);

        QRectF targetRect = converter.documentToView(fillPath.boundingRect());
        painter.drawPixmap(targetRect.topLeft(), d->imageData->pixmap(targetRect.size().toSize()));
    }

    painter.restore();
}
Beispiel #16
0
void TabbedWidget::refreshBuffer()
{
    /* Refreshes the back buffer. */

    int x = 0;
    QPainter painter;

    buffer_image.resize(size());
    painter.begin(&buffer_image);

    if (useTranslucency())
        painter.drawTiledPixmap(0, 0, width(), height(), desktop_image);
    else
        buffer_image.fill(Settings::skinbgcolor());

    for (uint i = 0; i < items.count(); i++)
        x = drawButton(i, painter);

    painter.drawTiledPixmap(x, 0, width() - x, height(), background_image);

    painter.end();

    repaint();
}
Beispiel #17
0
void KviThemedComboBox::paintEvent(QPaintEvent * event)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter * p = new QPainter(this);
	QLineEdit * le = lineEdit();
	if(le)
	{
		QRect r = rect();
		QPalette pal = palette();

		QStyleOptionFrame option;

		option.initFrom(this);
		option.rect = contentsRect();
		option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, le);
		option.midLineWidth = 0;
		option.state |= QStyle::State_Sunken;
		if(le->isReadOnly())
			option.state |= QStyle::State_ReadOnly;
		option.features = QStyleOptionFrame::None;
		style()->drawPrimitive(QStyle::PE_FrameLineEdit, &option, p, this);

		r = style()->subElementRect(QStyle::SE_LineEditContents, &option, le);
		int left, right, top, bottom;
		le->getTextMargins(&left, &top, &right, &bottom);
		r.setX(r.x() + left);
		r.setY(r.y() + top);
		r.setRight(r.right() - right);
		r.setBottom(r.bottom() - bottom);
		p->setClipRect(r);
	} // else not editable

	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(contentsRect(), col);
	}
	else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? mapTo(g_pMainWindow, contentsRect().topLeft()) : mapTo(m_pKviWindow, contentsRect().topLeft());
		p->drawTiledPixmap(contentsRect(), *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QComboBox::paintEvent(event);
}
void QPixmap::fill( const QWidget *widget, int xofs, int yofs )
{
    const QPixmap* bgpm = widget->backgroundPixmap();
    fill( widget->backgroundColor() );
    if ( bgpm ) {
	if ( !bgpm->isNull() ) {
	    QPoint ofs = widget->backgroundOffset();
	    xofs += ofs.x();
	    yofs += ofs.y();

	    QPainter p;
	    p.begin( this );
	    p.setPen( NoPen );
	    p.drawTiledPixmap( 0, 0, width(), height(), *widget->backgroundPixmap(), xofs, yofs );
	    p.end();
	}
    }
}
Beispiel #19
0
void KviThemedTreeWidget::paintEvent(QPaintEvent *e)
{
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	QPainter *p = new QPainter(this->viewport());
	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		p->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col=KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		p->fillRect(viewport()->contentsRect(), col);
	} else if(g_pShadedChildGlobalDesktopBackground)
	{
		QPoint pnt = m_pKviWindow->isDocked() ? viewport()->mapTo(g_pMainWindow, contentsRect().topLeft() + viewport()->contentsRect().topLeft()) : viewport()->mapTo(m_pKviWindow, contentsRect().topLeft() + viewport()->contentsRect().topLeft());
		p->drawTiledPixmap(contentsRect(),*(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	delete p;
#endif
	QTreeWidget::paintEvent(e);
}
void NotifierWindowTab::paintEvent(QPaintEvent * e)
{
	QPainter * pPainter = new QPainter(viewport());

//make sure you clean your widget with a transparent
//  color before doing any rendering
//  note the usage of a composition mode Source
//  it's important!

#ifdef COMPILE_PSEUDO_TRANSPARENCY
	if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing())
	{
		pPainter->save();
		pPainter->setCompositionMode(QPainter::CompositionMode_Source);
		QColor col = KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade);
		col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100));
		pPainter->fillRect(e->rect(), col);
		pPainter->restore();
	}
	else if(g_pShadedChildGlobalDesktopBackground) // This doesn't work as the text doesn't actually use the right foreground color
	{
		QPoint pnt = mapToGlobal(e->rect().topLeft());
		pPainter->drawTiledPixmap(e->rect(), *(g_pShadedChildGlobalDesktopBackground), pnt);
	}
	else
	{
#endif
		QPixmap * pPix = KVI_OPTION_PIXMAP(KviOption_pixmapNotifierBackground).pixmap();

		if(pPix)
			KviPixmapUtils::drawPixmapWithPainter(pPainter, pPix, KVI_OPTION_UINT(KviOption_uintNotifierPixmapAlign), e->rect(), e->rect().width(), e->rect().height());
		else
			pPainter->fillRect(e->rect(), KVI_OPTION_COLOR(KviOption_colorNotifierBackground));
#ifdef COMPILE_PSEUDO_TRANSPARENCY
	}
#endif

	delete pPainter;
	e->ignore();
}
void Tile::paintCheckerPattern(GraphicsContext* context, const FloatRect& target)
{
    QPainter* painter = context->platformContext();
    QTransform worldTransform = painter->worldTransform();
    qreal scaleX = worldTransform.m11();
    qreal scaleY = worldTransform.m22();
    
    QRect targetViewRect = QRectF(target.x() * scaleX,
                                  target.y() * scaleY,
                                  target.width() * scaleX,
                                  target.height() * scaleY).toAlignedRect();
    
    QTransform adjustedTransform(1., worldTransform.m12(), worldTransform.m13(),
                  worldTransform.m21(), 1., worldTransform.m23(),
                  worldTransform.m31(), worldTransform.m32(), worldTransform.m33());
    painter->setWorldTransform(adjustedTransform);
    
    painter->drawTiledPixmap(targetViewRect,
                             checkeredPixmap(),
                             QPoint(targetViewRect.left() % checkerSize,
                                    targetViewRect.top() % checkerSize));
    
    painter->setWorldTransform(worldTransform);
}
Beispiel #22
0
void TrayButton::drawButton(QPainter *p)
{
    QPixmap bg(size());
    QPainter pbg;

    pbg.begin(&bg);
    if (parentWidget() && parentWidget()->backgroundPixmap())
        pbg.drawTiledPixmap(0, 0, width(), height(), *(parentWidget()->backgroundPixmap()), x(), y());
    else
        pbg.fillRect(rect(), colorGroup().brush(QColorGroup::Background));


    if (isDown() || isOn())
    {
        // Draw shapes to indicate the down state.
        style().drawPrimitive(QStyle::PE_Panel, &pbg, rect(), colorGroup(),
                              QStyle::Style_Sunken);
    }
    pbg.end();

    p->drawPixmap(0,0,bg); // draw the background

    QPixmap pixmap = iconSet()->pixmap(
                         QIconSet::Automatic,
                         isEnabled() ? QIconSet::Normal : QIconSet::Disabled,
                         isOn() ? QIconSet::On : QIconSet::Off);

    // draw icon
    if(!pixmap.isNull())
    {
        QRect br(1, 1, width()-2, height()-2);
        int dx = (br.width() - pixmap.width()) / 2;
        int dy = (br.height() - pixmap.height()) / 2;
        p->drawPixmap(br.x() + dx, br.y() + dy, pixmap);
    }
}
Beispiel #23
0
void ContinuousPanel::draw(QPainter& painter, const QList<Element*>& el) {
      painter.save();
      painter.setRenderHint(QPainter::Antialiasing, preferences.antialiasedDrawing);
      painter.setRenderHint(QPainter::TextAntialiasing, true);

      // Draw colored rectangle
      painter.setClipping(false);
      QPointF pos(_offsetPanel, 0);
      painter.translate(pos);
      QPen pen;
      pen.setWidthF(0.0);
      pen.setStyle(Qt::NoPen);
      painter.setPen(pen);
      painter.setBrush(preferences.fgColor);
      QRectF bg(_rect);
      bg.setWidth(_widthClef + _widthKeySig + _widthTimeSig + _leftMarginTotal + _panelRightPadding);
      QPixmap* fgPixmap = _sv->fgPixmap();
      if (fgPixmap == 0 || fgPixmap->isNull())
            painter.fillRect(bg, preferences.fgColor);
      else {
            painter.setMatrixEnabled(false);
            painter.drawTiledPixmap(bg, *fgPixmap, bg.topLeft()
               - QPoint(lrint(_sv->matrix().dx()), lrint(_sv->matrix().dy())));
            painter.setMatrixEnabled(true);
            }

      painter.setClipRect(_rect);
      painter.setClipping(true);

      QColor color(MScore::layoutBreakColor);

      // Draw measure text number
      QString text = _mmRestCount ? QString("#%1-%2").arg(_currentMeasureNo+1).arg(_currentMeasureNo+_mmRestCount) : QString("#%1").arg(_currentMeasureNo+1);
      Text* newElement = new Text(_score);
      newElement->setTextStyleType(TextStyleType::DEFAULT);
      newElement->setFlag(ElementFlag::MOVABLE, false);
      newElement->setXmlText(text);
      newElement->textStyle().setFamily("FreeSans");
      newElement->textStyle().setSizeIsSpatiumDependent(true);
      newElement->setColor(color);
      newElement->sameLayout();
      pos = QPointF(_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, _y + newElement->height());
      painter.translate(pos);
      newElement->draw(&painter);
      pos += QPointF(_offsetPanel, 0);
      painter.translate(-pos);
      delete newElement;

      // This second pass draws the elements spaced evently using the width of the largest element
      for (const Element* e : el) {
            e->itemDiscovered = 0;
            if (!e->visible()) {
                  if (_score->printing() || !_score->showInvisible())
                        continue;
                  }

           if (e->type() == Element::Type::STAFF_LINES) {
                  Staff* currentStaff = _score->staff(e->staffIdx());
                  Segment* parent = _score->tick2segmentMM(_currentMeasureTick);

                  pos = QPointF (_offsetPanel, e->pagePos().y());
                  painter.translate(pos);

                  // Draw staff lines
                  StaffLines* newStaffLines = static_cast<StaffLines*>(e->clone());
                  newStaffLines->setWidth(bg.width());
                  newStaffLines->setParent(parent);
                  newStaffLines->setTrack(e->track());
                  newStaffLines->layout();
                  newStaffLines->setColor(color);
                  newStaffLines->draw(&painter);
                  delete newStaffLines;

                  // Draw barline
                  BarLine* newBarLine = new BarLine(_score);
                  newBarLine->setBarLineType(BarLineType::NORMAL);
                  newBarLine->setParent(parent);
                  newBarLine->setTrack(e->track());
                  newBarLine->setSpan(currentStaff->barLineSpan());
                  newBarLine->setSpanFrom(currentStaff->barLineFrom());
                  newBarLine->setSpanTo(currentStaff->barLineTo());
                  newBarLine->layout();
                  newBarLine->setColor(color);
                  newBarLine->draw(&painter);
                  delete newBarLine;

                  // Draw the current staff name
                  QList<StaffName>& staffNamesLong = currentStaff->part()->instrument()->longNames();
                  QString staffName = staffNamesLong.isEmpty() ? " " : staffNamesLong[0].name();
                  if (staffName == "") {
                        QList<StaffName>& staffNamesShort = currentStaff->part()->instrument()->shortNames();
                        staffName = staffNamesShort.isEmpty() ? "" : staffNamesShort[0].name();
                        }

                  Text* newName = new Text(_score);
                  newName->setXmlText(staffName);
                  newName->setParent(parent);
                  newName->setTrack(e->track());
                  newName->setColor(color);
                  newName->textStyle().setFamily("FreeSans");
                  newName->textStyle().setSizeIsSpatiumDependent(true);
                  newName->layout();
                  newName->setPlainText(newName->plainText());
                  newName->layout();
                  if (currentStaff->part()->staff(0) == currentStaff) {
                        double _spatium = _score->spatium();
                        pos = QPointF (_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, 0 - _spatium * 2);
                        painter.translate(pos);
                        newName->draw(&painter);
                        painter.translate(-pos);
                        }
                  delete newName;

                  // Draw the current Clef
                  Clef* newClef = new Clef(_score);
                  ClefType currentClef = currentStaff->clef(_currentMeasureTick);
                  newClef->setClefType(currentClef);
                  newClef->setParent(parent);
                  newClef->setTrack(e->track());
                  newClef->setColor(color);
                  newClef->layout();
                  pos = QPointF(_score->styleP(StyleIdx::clefLeftMargin), 0);
                  painter.translate(pos);
                  newClef->draw(&painter);
                  pos = QPointF(_widthClef,0);
                  painter.translate(pos);
                  delete newClef;

                  // Draw the current KeySignature
                  KeySig* newKs = new KeySig(_score);
                  KeySigEvent currentKeySigEvent = currentStaff->keySigEvent(_currentMeasureTick);
                  newKs->setKeySigEvent(currentKeySigEvent);

                  // The Parent and the track must be set to have the key signature layout adjusted to different clefs
                  // This also adds naturals to the key signature (if set in the score style)
                  newKs->setParent(parent);
                  newKs->setTrack(e->track());
                  newKs->setColor(color);

                  newKs->setHideNaturals(true);
                  pos = QPointF(_score->styleP(StyleIdx::keysigLeftMargin),0);
                  painter.translate(pos);
                  newKs->layout();
                  newKs->draw(&painter);
                  delete newKs;

                  pos = QPointF(_widthKeySig + _xPosTimeSig, 0);
                  painter.translate(pos);

                  // Draw the current TimeSignature
                  TimeSig* newTs = new TimeSig(_score);

                  // Try to get local time signature, if not, get the current measure one
                  TimeSig* currentTimeSig = currentStaff->timeSig(_currentMeasureTick);
                  if (currentTimeSig) {
                        newTs->setFrom(currentTimeSig);
                        newTs->setParent(parent);
                        newTs->setTrack(e->track());
                        newTs->setColor(color);
                        newTs->layout();
                        pos = QPointF(_score->styleP(StyleIdx::timesigLeftMargin),0);
                        painter.translate(pos);
                        newTs->draw(&painter);
                        delete newTs;
                        }
                  pos = QPointF(_offsetPanel + _widthClef + _widthKeySig + _xPosTimeSig + _leftMarginTotal, e->pagePos().y());
                  painter.translate(-pos);
                  }
            }
      painter.restore();
      }
Beispiel #24
0
void ContinuousPanel::paint(const QRect&, QPainter& painter)
      {
      qreal _offsetPanel = 0;
      qreal _y = 0;
      qreal _oldWidth = 0;        // The last final panel width
      qreal _newWidth = 0;        // New panel width
      qreal _height = 0;
      qreal _leftMarginTotal = 0; // Sum of all elments left margin
      qreal _panelRightPadding = 5;  // Extra space for the panel after last element

      Measure* measure = _score->firstMeasure();

      if (!_active || !measure) {
            _visible = false;
            return;
            }

      if (measure->mmRest()) {
            measure = measure->mmRest();
            }

      System* system   = measure->system();
      if (system == 0) {
            _visible = false;
            return;
            }

      Segment* s      = measure->first();
      double _spatium = _score->spatium();
      if (_width <= 0)
            _width  = s->x();

      //
      // Set panel height for whole system
      //
      _height = 6 * _spatium;
      _y = system->staffYpage(0) + system->page()->pos().y();
      double y2 = 0.0;
      for (int i = 0; i < _score->nstaves(); ++i) {
            SysStaff* ss = system->staff(i);
            if (!ss->show() || !_score->staff(i)->show())
                  continue;
            y2 = ss->y() + ss->bbox().height();
            }
      _height += y2 + 6*_spatium;
      _y -= 6 * _spatium;

      //
      // Check elements at current panel position
      //
      _offsetPanel = -(_sv->xoffset()) / _sv->mag();
      _rect        = QRect(_offsetPanel + _width, _y, 1, _height);
      Page* page   = _score->pages().front();
      QList<Element*> el = page->items(_rect);
      if (el.empty()) {
            _visible = false;
            return;
            }
      qStableSort(el.begin(), el.end(), elementLessThan);

      const Measure*_currentMeasure = 0;
      for (const Element* e : el) {
            e->itemDiscovered = 0;
            if (!e->visible() && !_score->showInvisible())
                  continue;

            if (e->isMeasure()) {
                  _currentMeasure = toMeasure(e);
                  break;
                  }
            }
      if (!_currentMeasure)
            return;

      // Don't show panel if staff names are visible
      if (_currentMeasure == _score->firstMeasure() && _sv->toPhysical(_currentMeasure->canvasPos()).x() > 0) {
            _visible = false;
            return;
            }

      qreal _xPosMeasure       = _currentMeasure->canvasX();
      qreal _measureWidth      = _currentMeasure->width();
      int tick                 = _currentMeasure->tick();
      Fraction _currentTimeSig = _currentMeasure->timesig();
      //qDebug() << "_sv->xoffset()=" <<_sv->xoffset() << " _sv->mag()="<< _sv->mag() <<" s->x=" << s->x() << " width=" << _width << " currentMeasure=" << _currentMeasure->x() << " _xPosMeasure=" << _xPosMeasure;

      //---------------------------------------------------------
      //   findElementWidths
      //      determines the max width for each element types
      //---------------------------------------------------------

      // The first pass serves to get the maximum width for each elements

      qreal lineWidthName = 0;
      qreal _widthClef    = 0;
      qreal _widthKeySig  = 0;
      qreal _widthTimeSig = 0;
      qreal _xPosTimeSig  = 0;

      for (const Element* e : el) {
            e->itemDiscovered = 0;
            if (!e->visible() && !_score->showInvisible())
                  continue;

            if (e->isRest() && toRest(e)->isGap())
                  continue;

            if (e->isStaffLines()) {
                  Staff* currentStaff = _score->staff(e->staffIdx());
                  Segment* parent = _score->tick2segment(tick);

                  // Find maximum width for the staff name
                  QList<StaffName>& staffNamesLong = currentStaff->part()->instrument()->longNames();
                  QString staffName = staffNamesLong.isEmpty() ? " " : staffNamesLong[0].name();
                  if (staffName == "") {
                        QList<StaffName>& staffNamesShort = currentStaff->part()->instrument()->shortNames();
                        staffName = staffNamesShort.isEmpty() ? "" : staffNamesShort[0].name();
                        }
                  Text* newName = new Text(_score);
                  newName->setXmlText(staffName);
                  newName->setParent(parent);
                  newName->setTrack(e->track());
                  newName->textStyle().setFamily("FreeSans");
                  newName->textStyle().setSizeIsSpatiumDependent(true);
                  newName->layout();
                  newName->setPlainText(newName->plainText());
                  newName->layout();

                  // Find maximum width for the current Clef
                  Clef* newClef = new Clef(_score);
                  ClefType currentClef = currentStaff->clef(tick);
                  newClef->setClefType(currentClef);
                  newClef->setParent(parent);
                  newClef->setTrack(e->track());
                  newClef->layout();
                  if (newClef->width() > _widthClef)
                        _widthClef = newClef->width();

                  // Find maximum width for the current KeySignature
                  KeySig* newKs = new KeySig(_score);
                  KeySigEvent currentKeySigEvent = currentStaff->keySigEvent(tick);
                  newKs->setKeySigEvent(currentKeySigEvent);
                  // The Parent and the Track must be set to have the key signature layout adjusted to different clefs
                  // This also adds naturals to the key signature (if set in the score style)
                  newKs->setParent(parent);
                  newKs->setTrack(e->track());
                  newKs->setHideNaturals(true);
                  newKs->layout();
                  if (newKs->width() > _widthKeySig)
                        _widthKeySig = newKs->width();

                  // Find maximum width for the current TimeSignature
                  TimeSig* newTs = new TimeSig(_score);

                  // Try to get local time signature, if not, get the current measure one
                  TimeSig* currentTimeSig = currentStaff->timeSig(tick);
                  if (currentTimeSig)
                        newTs->setFrom(currentTimeSig);
                  else
                        newTs->setSig(Fraction(_currentTimeSig.numerator(), _currentTimeSig.denominator()), TimeSigType::NORMAL);
                  newTs->setParent(parent);
                  newTs->setTrack(e->track());
                  newTs->layout();

                  if ((newName->width() > lineWidthName) && (newName->xmlText() != ""))
                        lineWidthName = newName->width();

                  if (newTs->width() > _widthTimeSig)
                        _widthTimeSig = newTs->width();

                  delete newClef;
                  delete newName;
                  delete newKs;
                  delete newTs;
                 }
            }

      _leftMarginTotal = _score->styleP(StyleIdx::clefLeftMargin);
      _leftMarginTotal += _score->styleP(StyleIdx::keysigLeftMargin);
      _leftMarginTotal += _score->styleP(StyleIdx::timesigLeftMargin);

      _newWidth = _widthClef + _widthKeySig + _widthTimeSig + _leftMarginTotal + _panelRightPadding;
      _xPosMeasure -= _offsetPanel;

      lineWidthName += _score->spatium() + _score->styleP(StyleIdx::clefLeftMargin) + _widthClef;
      if (_newWidth < lineWidthName) {
            _newWidth = lineWidthName;
            _oldWidth = 0;
            }
      if (_oldWidth == 0) {
            _oldWidth = _newWidth;
            _width = _newWidth;
            }
      else if (_newWidth > 0) {
            if (_newWidth == _width) {
                  _oldWidth = _width;
                  _width = _newWidth;
                  }
            else if (((_xPosMeasure <= _newWidth) && (_xPosMeasure >= _oldWidth)) ||
                     ((_xPosMeasure >= _newWidth) && (_xPosMeasure <= _oldWidth)))
                        _width = _xPosMeasure;
            else if (((_xPosMeasure+_measureWidth <= _newWidth) && (_xPosMeasure+_measureWidth >= _oldWidth)) ||
                     ((_xPosMeasure+_measureWidth >= _newWidth) && (_xPosMeasure+_measureWidth <= _oldWidth)))
                        _width = _xPosMeasure+_measureWidth;
            else {
                  _oldWidth = _width;
                  _width = _newWidth;
                  }
            }

      _rect = QRect(0, _y, _width, _height);

      //====================

      painter.save();

      // Draw colored rectangle
      painter.setClipping(false);
      QPointF pos(_offsetPanel, 0);

      painter.translate(pos);
      QPen pen;
      pen.setWidthF(0.0);
      pen.setStyle(Qt::NoPen);
      painter.setPen(pen);
      painter.setBrush(preferences.fgColor);
      QRectF bg(_rect);

      bg.setWidth(_widthClef + _widthKeySig + _widthTimeSig + _leftMarginTotal + _panelRightPadding);
      QPixmap* fgPixmap = _sv->fgPixmap();
      if (fgPixmap == 0 || fgPixmap->isNull())
            painter.fillRect(bg, preferences.fgColor);
      else {
            painter.setMatrixEnabled(false);
            painter.drawTiledPixmap(bg, *fgPixmap, bg.topLeft()
               - QPoint(lrint(_sv->matrix().dx()), lrint(_sv->matrix().dy())));
            painter.setMatrixEnabled(true);
            }

      painter.setClipRect(_rect);
      painter.setClipping(true);

      QColor color(MScore::layoutBreakColor);

      // Draw measure text number
      QString text = QString("#%1").arg(_currentMeasure->no()+1);
      Text* newElement = new Text(_score);
      newElement->setTextStyleType(TextStyleType::DEFAULT);
      newElement->setFlag(ElementFlag::MOVABLE, false);
      newElement->setXmlText(text);
      newElement->textStyle().setFamily("FreeSans");
      newElement->textStyle().setSizeIsSpatiumDependent(true);
      newElement->setColor(color);
      newElement->sameLayout();
      pos = QPointF(_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, _y + newElement->height());
      painter.translate(pos);
      newElement->draw(&painter);
      pos += QPointF(_offsetPanel, 0);
      painter.translate(-pos);
      delete newElement;

      // This second pass draws the elements spaced evently using the width of the largest element
      for (const Element* e : el) {
            if (!e->visible() && !_score->showInvisible())
                  continue;

            if (e->isRest() && toRest(e)->isGap())
                  continue;

            if (e->isStaffLines()) {
                  painter.save();
                  Staff* currentStaff = _score->staff(e->staffIdx());
                  Segment* parent = _score->tick2segmentMM(tick);

                  pos = QPointF (_offsetPanel, e->pagePos().y());
                  painter.translate(pos);

                  // Draw staff lines
                  StaffLines newStaffLines(*toStaffLines(e));
                  newStaffLines.setParent(parent);
                  newStaffLines.setTrack(e->track());
                  newStaffLines.layout();
                  newStaffLines.setColor(color);
                  newStaffLines.setWidth(bg.width());
                  newStaffLines.draw(&painter);

                  // Draw barline
                  BarLine barLine(_score);
                  barLine.setBarLineType(BarLineType::NORMAL);
                  barLine.setParent(parent);
                  barLine.setTrack(e->track());
                  barLine.setSpan(currentStaff->barLineSpan());
                  barLine.setSpanFrom(currentStaff->barLineFrom());
                  barLine.setSpanTo(currentStaff->barLineTo());
                  barLine.layout();
                  barLine.setColor(color);
                  barLine.draw(&painter);

                  // Draw the current staff name
                  QList<StaffName>& staffNamesLong = currentStaff->part()->instrument()->longNames();
                  QString staffName = staffNamesLong.isEmpty() ? " " : staffNamesLong[0].name();
                  if (staffName == "") {
                        QList<StaffName>& staffNamesShort = currentStaff->part()->instrument()->shortNames();
                        staffName = staffNamesShort.isEmpty() ? "" : staffNamesShort[0].name();
                        }

                  Text* newName = new Text(_score);
                  newName->setXmlText(staffName);
                  newName->setParent(parent);
                  newName->setTrack(e->track());
                  newName->setColor(color);
                  newName->textStyle().setFamily("FreeSans");
                  newName->textStyle().setSizeIsSpatiumDependent(true);
                  newName->layout();
                  newName->setPlainText(newName->plainText());
                  newName->layout();
                  if (currentStaff->part()->staff(0) == currentStaff) {
                        double _spatium = _score->spatium();
                        pos = QPointF (_score->styleP(StyleIdx::clefLeftMargin) + _widthClef, -_spatium * 2);
                        painter.translate(pos);
                        newName->draw(&painter);
                        painter.translate(-pos);
                        }
                  delete newName;

                  qreal posX = 0.0;

                  // Draw the current Clef
                  Clef clef(_score);
                  clef.setClefType(currentStaff->clef(tick));
                  clef.setParent(parent);
                  clef.setTrack(e->track());
                  clef.setColor(color);
                  clef.layout();
                  posX += _score->styleP(StyleIdx::clefLeftMargin);
                  clef.drawAt(&painter, QPointF(posX, clef.pos().y()));
                  posX += _widthClef;

                  // Draw the current KeySignature
                  KeySig newKs(_score);
                  newKs.setKeySigEvent(currentStaff->keySigEvent(tick));

                  // The Parent and the track must be set to have the key signature layout adjusted to different clefs
                  // This also adds naturals to the key signature (if set in the score style)
                  newKs.setParent(parent);
                  newKs.setTrack(e->track());
                  newKs.setColor(color);
                  newKs.setHideNaturals(true);
                  newKs.layout();
                  posX += _score->styleP(StyleIdx::keysigLeftMargin);
                  newKs.drawAt(&painter, QPointF(posX, 0.0));

                  posX += _widthKeySig + _xPosTimeSig;

                  // Draw the current TimeSignature
                  TimeSig newTs(_score);

                  // Try to get local time signature, if not, get the current measure one
                  TimeSig* currentTimeSig = currentStaff->timeSig(tick);
                  if (currentTimeSig) {
                        newTs.setFrom(currentTimeSig);
                        newTs.setParent(parent);
                        newTs.setTrack(e->track());
                        newTs.setColor(color);
                        newTs.layout();
                        posX += _score->styleP(StyleIdx::timesigLeftMargin);
                        newTs.drawAt(&painter, QPointF(posX, 0.0));
                        }
                  painter.restore();
                  }
            }
      painter.restore();
      _visible = true;
      }
Beispiel #25
0
int TabBar::drawButton(int x, int y, int index, QPainter& painter)
{
    QString title;
    int sessionId;
    bool selected;
    QFont font = KGlobalSettings::generalFont();
    int textWidth = 0;

    sessionId = m_tabs.at(index);
    selected = (sessionId == m_selectedSessionId);
    title = m_tabTitles[sessionId];

    if (selected)
    {
        painter.drawPixmap(x, y, m_skin->tabBarSelectedLeftCornerImage());
        x += m_skin->tabBarSelectedLeftCornerImage().width();
    }
    else if (index != m_tabs.indexOf(m_selectedSessionId) + 1)
    {
        painter.drawPixmap(x, y, m_skin->tabBarSeparatorImage());
        x += m_skin->tabBarSeparatorImage().width();
    }

    if (selected) font.setBold(true);
    else font.setBold(false);

    painter.setFont(font);

    QFontMetrics fontMetrics(font);
    textWidth = fontMetrics.width(title) + 10;

    // Draw the Prevent Closing image in the tab button.
    if (m_mainWindow->sessionStack()->isSessionClosable(sessionId) == false)
    {
        if (selected)
            painter.drawTiledPixmap(x, y,
                    m_skin->tabBarPreventClosingImagePosition().x() +
                    m_skin->tabBarPreventClosingImage().width(), height(),
                    m_skin->tabBarSelectedBackgroundImage());
        else
            painter.drawTiledPixmap(x, y,
                    m_skin->tabBarPreventClosingImagePosition().x() +
                    m_skin->tabBarPreventClosingImage().width(), height(),
                    m_skin->tabBarUnselectedBackgroundImage());

        painter.drawPixmap(x + m_skin->tabBarPreventClosingImagePosition().x(),
                           m_skin->tabBarPreventClosingImagePosition().y(),
                           m_skin->tabBarPreventClosingImage());

        x += m_skin->tabBarPreventClosingImagePosition().x();
        x += m_skin->tabBarPreventClosingImage().width();
    }

    if (selected)
        painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarSelectedBackgroundImage());
    else
        painter.drawTiledPixmap(x, y, textWidth, height(), m_skin->tabBarUnselectedBackgroundImage());

    painter.drawText(x, y, textWidth + 1, height() + 2, Qt::AlignHCenter | Qt::AlignVCenter, title);

    x += textWidth;

    if (selected)
    {
        painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSelectedRightCornerImage());
        x += m_skin->tabBarSelectedRightCornerImage().width();
    }
    else if (index != m_tabs.indexOf(m_selectedSessionId) - 1)
    {
        painter.drawPixmap(x, m_skin->tabBarPosition().y(), m_skin->tabBarSeparatorImage());
        x += m_skin->tabBarSeparatorImage().width();
    }

    return x;
}
Beispiel #26
0
void ImageIface::paint(QPaintDevice* const device, const QRect& rect, QPainter* const painter)
{
    int       x = rect.x();
    int       y = rect.y();
    int       w = rect.width();
    int       h = rect.height();
    QPainter* p = 0;
    QPainter  localPainter;

    if (painter)
    {
        p = painter;
    }
    else
    {
        p = &localPainter;
        p->begin(device);
    }

    int width  = w > 0 ? qMin(d->previewWidth,  w) : d->previewWidth;
    int height = h > 0 ? qMin(d->previewHeight, h) : d->previewHeight;

    if (!d->targetPreviewImage.isNull())
    {
        if (d->targetPreviewImage.hasAlpha())
        {
            p->drawTiledPixmap(x, y, width, height, d->checkPixmap());
        }

        QPixmap              pixImage;
        bool doSoftProofing              = d->core->softProofingEnabled();
        ICCSettingsContainer iccSettings = d->core->getICCSettings();

        if (iccSettings.enableCM && (iccSettings.useManagedView || doSoftProofing))
        {
            IccManager   manager(d->targetPreviewImage);
            IccTransform monitorICCtrans;

            if (doSoftProofing)
            {
                monitorICCtrans = manager.displaySoftProofingTransform(iccSettings.defaultProofProfile);
            }
            else
            {
                monitorICCtrans = manager.displayTransform();
            }

            pixImage = d->targetPreviewImage.convertToPixmap(monitorICCtrans);
        }
        else
        {
            pixImage = d->targetPreviewImage.convertToPixmap();
        }

        p->drawPixmap(x, y, pixImage, 0, 0, width, height);

        // Show the Over/Under exposure pixels indicators

        ExposureSettingsContainer* const expoSettings = d->core->getExposureSettings();

        if (expoSettings && (expoSettings->underExposureIndicator || expoSettings->overExposureIndicator))
        {
            QImage pureColorMask = d->targetPreviewImage.pureColorMask(expoSettings);
            QPixmap pixMask      = QPixmap::fromImage(pureColorMask);
            p->drawPixmap(x, y, pixMask, 0, 0, width, height);
        }
    }

    if (!painter)
    {
        p->end();
    }
}
Beispiel #27
0
void KniftyClient::update_captionBuffer()
{
    if (!KniftyHandler::initialized()) return;

    const uint maxCaptionLength = 300; // truncate captions longer than this!
    QString captionText(caption() );
    if (captionText.length() > maxCaptionLength) {
        captionText.truncate(maxCaptionLength);
        captionText.append(" [...]");
    }

    QFontMetrics fm(s_titleFont);
    int captionWidth  = fm.width(captionText);

    QPixmap textPixmap;
    QPainter painter;
    if(KniftyHandler::titleShadow())
    {
        // prepare the shadow
        textPixmap = QPixmap(captionWidth+2*2, s_titleHeight ); // 2*2 px shadow space
        textPixmap.fill(QColor(0,0,0));
        textPixmap.setMask( textPixmap.createHeuristicMask(TRUE) );
        painter.begin(&textPixmap);
        painter.setFont(s_titleFont);
        painter.setPen(white);
        painter.drawText(textPixmap.rect(), AlignCenter, captionText );
        painter.end();
    }

    QImage shadow;
    ShadowEngine se;

    // active
    aCaptionBuffer->resize(captionWidth+4, s_titleHeight ); // 4 px shadow
    painter.begin(aCaptionBuffer);
    painter.drawTiledPixmap(aCaptionBuffer->rect(), *aTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        shadow = se.makeShadow(textPixmap, QColor(0, 0, 0));
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, true));
    painter.drawText(aCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();


    // inactive
    iCaptionBuffer->resize(captionWidth+4, s_titleHeight );
    painter.begin(iCaptionBuffer);
    painter.drawTiledPixmap(iCaptionBuffer->rect(), *iTitleBarTile);
    if(KniftyHandler::titleShadow())
    {
        painter.drawImage(1, 1, shadow);
    }
    painter.setFont(s_titleFont);
    painter.setPen(options()->color(KDecoration::ColorFont, false));
    painter.drawText(iCaptionBuffer->rect(), AlignCenter, captionText );
    painter.end();

    captionBufferDirty = false;
}
Beispiel #28
0
void Platform::drawPlatform(QPainter &painter)
{
    rectPlat = new QRect(platformPosX, platformHeight, platformLength, 65);
    painter.drawRect(*rectPlat);
    painter.drawTiledPixmap(*rectPlat, *platform);
}//Draws the platform
Beispiel #29
0
void Piano::draw(QPainter& p, const QRect& r)
{
    QPoint offset(0, KH*2);
    p.drawTiledPixmap(r, *octave, r.topLeft()+offset);

    if (_curSelectedPitch != -1 && _curSelectedPitch != curPitch)
    {
        int y = pitch2y(_curSelectedPitch);
        QPixmap* pm;
        switch(_curSelectedPitch % 12) {
        case 0:
        case 5:
            pm = mk7;
            break;
        case 2:
        case 7:
        case 9:
            pm = mk6;
            break;
        case 4:
        case 11:
            pm = mk5;
            break;
        default:
            pm = mk8;
            break;
        }
        p.drawPixmap(0, y, *pm);
    }

    if (curPitch != -1)
    {
        int y = pitch2y(curPitch);
        QPixmap* pm;
        switch(curPitch % 12) {
        case 0:
        case 5:
            pm = mk3;
            break;
        case 2:
        case 7:
        case 9:
            pm = mk2;
            break;
        case 4:
        case 11:
            pm = mk1;
            break;
        default:
            pm = mk4;
            break;
        }
        p.drawPixmap(0, y, *pm);
    }

    // draw C notes
    for (int drawKey = 0; drawKey < 8; drawKey++) {
        int octaveSize=91;

        int drawY = octaveSize * drawKey + 82 - KH*2;
        if (drawY > r.y() && drawY < r.y() + r.height()) {
            p.drawPixmap(0,drawY,*c_keys[drawKey]);
        }
    }


    if(!_midiEditor)
        return;
    MusECore::PartList* part_list = _midiEditor->parts();
    MusECore::Part* cur_part = _midiEditor->curCanvasPart();
    if(!part_list || !cur_part)
        return;

    MusECore::MidiTrack* track = (MusECore::MidiTrack*)(cur_part->track());
    int channel      = track->outChannel();
    MusECore::MidiPort* port   = &MusEGlobal::midiPorts[track->outPort()];
    MusECore::MidiCtrlValListList* cll = port->controller();
    const int min = channel << 24;
    const int max = min + 0x1000000;

    for(MusECore::ciMidiCtrlValList it = cll->lower_bound(min); it != cll->lower_bound(max); ++it)
    {
        MusECore::MidiCtrlValList* cl = it->second;
        MusECore::MidiController* c   = port->midiController(cl->num());
        if(!c->isPerNoteController())
            continue;
        int cnum = c->num();
        int num = cl->num();
        int pitch = num & 0x7f;
        bool used = false;
        MusECore::EventList* el = cur_part->events();
        for (MusECore::ciEvent ie = el->begin(); ie != el->end(); ++ie)
        {
            MusECore::Event e = ie->second;
            if(e.type() != MusECore::Controller)
                continue;
            int ctl_num = e.dataA();
            if((ctl_num | 0xff) == cnum && (ctl_num & 0x7f) == pitch)
            {
                used = true;
                break;
            }
        }

        bool off = cl->hwVal() == MusECore::CTRL_VAL_UNKNOWN;  // Does it have a value or is it 'off'?

        int y = pitch2y(pitch) + 3;
        if(used)
        {
            if(off)
                p.drawPixmap(0, y, 6, 6, *greendot12x12Icon);
            else
                p.drawPixmap(0, y, 6, 6, *orangedot12x12Icon);
        }
        else
        {
            if(off)
                p.drawPixmap(0, y, 6, 6, *graydot12x12Icon);
            else
                p.drawPixmap(0, y, 6, 6, *bluedot12x12Icon);
        }
    }

}
Beispiel #30
0
void ArthurFrame::paintEvent(QPaintEvent *e)
{
#ifdef Q_WS_QWS
    static QPixmap *static_image = 0;
#else
    static QImage *static_image = 0;
#endif
    QPainter painter;
    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        if (!static_image || static_image->size() != size()) {
            delete static_image;
#ifdef Q_WS_QWS
            static_image = new QPixmap(size());
#else
            static_image = new QImage(size(), QImage::Format_RGB32);
#endif
        }
        painter.begin(static_image);

        int o = 10;

        QBrush bg = palette().brush(QPalette::Background);
        painter.fillRect(0, 0, o, o, bg);
        painter.fillRect(width() - o, 0, o, o, bg);
        painter.fillRect(0, height() - o, o, o, bg);
        painter.fillRect(width() - o, height() - o, o, o, bg);
    } else {
#ifdef QT_OPENGL_SUPPORT
        if (m_use_opengl) {
            painter.begin(glw);
            painter.fillRect(QRectF(0, 0, glw->width(), glw->height()), palette().color(backgroundRole()));
        } else {
            painter.begin(this);
        }
#else
        painter.begin(this);
#endif
    }

    painter.setClipRect(e->rect());

    painter.setRenderHint(QPainter::Antialiasing);

    QPainterPath clipPath;

    QRect r = rect();
    qreal left = r.x() + 1;
    qreal top = r.y() + 1;
    qreal right = r.right();
    qreal bottom = r.bottom();
    qreal radius2 = 8 * 2;

    clipPath.moveTo(right - radius2, top);
    clipPath.arcTo(right - radius2, top, radius2, radius2, 90, -90);
    clipPath.arcTo(right - radius2, bottom - radius2, radius2, radius2, 0, -90);
    clipPath.arcTo(left, bottom - radius2, radius2, radius2, 270, -90);
    clipPath.arcTo(left, top, radius2, radius2, 180, -90);
    clipPath.closeSubpath();

    painter.save();
    painter.setClipPath(clipPath, Qt::IntersectClip);

    painter.drawTiledPixmap(rect(), m_tile);

    // client painting

    paint(&painter);

    painter.restore();

    painter.save();
    if (m_show_doc)
        paintDescription(&painter);
    painter.restore();

    int level = 180;
    painter.setPen(QPen(QColor(level, level, level), 2));
    painter.setBrush(Qt::NoBrush);
    painter.drawPath(clipPath);

    if (preferImage()
#ifdef QT_OPENGL_SUPPORT
        && !m_use_opengl
#endif
        ) {
        painter.end();
        painter.begin(this);
#ifdef Q_WS_QWS
        painter.drawPixmap(e->rect(), *static_image, e->rect());
#else
        painter.drawImage(e->rect(), *static_image, e->rect());
#endif
    }

#ifdef QT_OPENGL_SUPPORT
    if (m_use_opengl && (inherits("PathDeformRenderer") || inherits("PathStrokeRenderer") || inherits("CompositionRenderer") || m_show_doc))
        glw->swapBuffers();
#endif
}