/**
 * Draw custom background colours & round corners
 */
void OSUpdaterPopup::paintEvent( QPaintEvent *e )
{
	QPainter bufferPainter(this);
	bufferPainter.setPen(QPen(QColorGroup::Background,2,SolidLine));
	bufferPainter.setBrush( colorGroup().brush( QColorGroup::Background ) );

	bufferPainter.setPen(QPen(QColorGroup::Background,3,SolidLine));
	//draw the line under the title
	bufferPainter.drawLine(0,_title->y() + _title->height() + 3,this->width(),_title->y() + _title->height() + 3);
	bufferPainter.setPen(QPen(QColorGroup::Background,3,SolidLine));
	//draw black border
	bufferPainter.drawRoundRect(0,0,width(),height(),1600/width(),1600/height());
	bufferPainter.setPen(QColor(55,97,155));
	bufferPainter.setBrush(QColor(55,97,155));
	bufferPainter.setBackgroundColor(QColor(55,97,155));
	//set title colour to blue
	_title->setPaletteBackgroundColor(QColor(55,97,155));
	_title->setPaletteForegroundColor(QColor(255,255,255));
	_closeButton->setPalette(QPalette(QColor(55,97,155),QColor(55,97,155)));
	//draw blue background behind title
	bufferPainter.drawRect(0,0,width(),_title->y() + _title->height()+3);

	//do rounded corners
	//create mask the size of the popup
	_mask.resize(width(), height());
	_mask.fill(Qt::black);
	QPainter maskPainter(&_mask);
	maskPainter.setBrush(Qt::white);
	maskPainter.setPen(Qt::white);
	//draw the rounded corners on the mask
	maskPainter.drawRoundRect(_mask.rect(), 1600 / _mask.rect().width(), 1600 / _mask.rect().height());
	
	//apply the mask to this popup.
	setMask(_mask);
}
Exemple #2
0
void PopupMessage::dissolveMask()
{
    if( m_stage == 1 )
    {
        //repaint( false );
        QPainter maskPainter(&m_mask);

        m_mask.fill(Qt::black);

        maskPainter.setBrush(Qt::white);
        maskPainter.setPen(Qt::white);
        maskPainter.drawRect( m_mask.rect() );

        m_dissolveSize += m_dissolveDelta;

        if( m_dissolveSize > 0 )
        {
            //maskPainter.setCompositionMode( Qt::EraseROP );
			//FIXME: QRubberBand

            int x, y, s;
            const int size = 16;

            for (y = 0; y < height() + size; y += size)
            {
                x = width();
                s = m_dissolveSize * x / 128;

                for ( ; x > size; x -= size, s -= 2 )
                {
                    if (s < 0)
                        break;

                    maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s);
                }
            }
        }
        else if( m_dissolveSize < 0 )
        {
            m_dissolveDelta = 1;
            killTimer( m_timerId );

            if( m_timeout )
            {
                m_timerId = startTimer( 40 );
                m_stage = 2;
            }
        }

        setMask(m_mask);
    }
    else if ( m_stage == 2 )
    {
        countDown();
    }
    else
    {
        deleteLater();
    }
}
Exemple #3
0
KexiArrowTip::KexiArrowTip(const QString& text, QWidget* parent)
 : KexiToolTip(text, parent)
 , m_opacity(0.0)
{
	QPalette pal( palette() );
	QColorGroup cg(pal.active());
	cg.setColor(QColorGroup::Foreground, Qt::red);
	pal.setActive(cg);
	setPalette(pal);

	QFontMetrics fm(font());
	QSize sz(fm.boundingRect(m_value.toString()).size());
	sz += QSize(14, 10); //+margins
	m_arrowHeight = sz.height()/2;
	sz += QSize(0, m_arrowHeight); //+arrow height
	resize(sz);

	setAutoMask( false );

	//generate mask
	QPixmap maskPm(size());
	maskPm.fill( black );
	QPainter maskPainter(&maskPm);
	drawFrame(maskPainter);
	QImage maskImg( maskPm.convertToImage() );
	QBitmap bm;
	bm = maskImg.createHeuristicMask();
	setMask( bm );
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pFillPolygon (JNIEnv * env, jclass cls, 
                                       jint qtGraphDesc, jint originX, 
                                       jint originY,
                                       jintArray xp, jintArray yp, 
                                       jint nPoints)
{
	jint *xpoints = env->GetIntArrayElements (xp, NULL);
	jint *ypoints = env->GetIntArrayElements (yp, NULL);
	

    AWT_QT_LOCK; {
	QPointArray qpa(nPoints);
	
	for(int i=0; i<nPoints; i++)
		qpa.setPoint(i, xpoints[i]+originX, ypoints[i]+originY);
		
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
	p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
	p.setPen(Qt::NoPen);	
	p.setBrush(*((QBrush *)(QtGraphDescPool[qtGraphDesc].qb)));
    setPainterClip(&p, qtGraphDesc);
	p.drawPolygon(qpa);
	
	if(maskPainter(qtGraphDesc, p))
		p.drawPolygon(qpa);
    }
    AWT_QT_UNLOCK;
	
	env->ReleaseIntArrayElements (xp, xpoints, JNI_ABORT);
	env->ReleaseIntArrayElements (yp, ypoints, JNI_ABORT);
}
Exemple #5
0
QPixmap KColorCombo2::colorRectPixmap(const QColor &color, bool isDefault, int width, int height)
{
	// Prepare to draw:
	QPixmap  pixmap(width, height);
	QBitmap  mask(width, height);
	QPainter painter(&pixmap);
	QPainter maskPainter(&mask);

	// Draw pixmap:
	drawColorRect(painter, 0, 0, color, isDefault, width, height);

	// Draw mask (make the four corners transparent):
	maskPainter.fillRect(0, 0, width, height, Qt::color1); // opaque
	maskPainter.setPen(Qt::color0); // transparent
	maskPainter.drawPoint(0,         0);
	maskPainter.drawPoint(0,         height - 1);
	maskPainter.drawPoint(width - 1, height - 1);
	maskPainter.drawPoint(width - 1, 0);

	// Finish:
	painter.end();
	maskPainter.end();
	pixmap.setMask(mask);
	return pixmap;
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pDrawString (JNIEnv * env, jclass cls, 
                                      jint qtGraphDesc, jstring string, 
                                      jint x, jint y)
{
	const char *chars;
	jboolean isCopy;
	jsize length;

	chars = env->GetStringUTFChars (string, &isCopy);

	if (chars == NULL) return;

	length = env->GetStringUTFLength (string);

    AWT_QT_LOCK;
	if (length > 0)
	{
		QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
		p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
		p.setPen(*((QPen *)(QtGraphDescPool[qtGraphDesc].qp)));
		p.setFont(*((QFont *)(QtGraphDescPool[qtGraphDesc].font)));
        setPainterClip(&p, qtGraphDesc);
		p.drawText(x, y, QString::fromUtf8(chars, length));
		
		if(maskPainter(qtGraphDesc, p)) {
			p.setFont(*((QFont *)(QtGraphDescPool[qtGraphDesc].font)));
			p.drawText(x, y, QString::fromUtf8(chars, length));
		}
	}
    AWT_QT_UNLOCK;

	env->ReleaseStringUTFChars (string, chars);
}
Exemple #7
0
void TextureMapperQt::drawTexture(const BitmapTexture& texture, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity, const BitmapTexture* maskTexture)
{
    const BitmapTextureQt& textureQt = static_cast<const BitmapTextureQt&>(texture);
    QPainter* painter = m_painter;
    QPixmap pixmap = textureQt.m_pixmap;
    if (m_currentSurface)
        painter = &m_currentSurface->m_painter;

    if (maskTexture && maskTexture->isValid()) {
        const BitmapTextureQt* mask = static_cast<const BitmapTextureQt*>(maskTexture);
        QPixmap intermediatePixmap(pixmap.size());
        intermediatePixmap.fill(Qt::transparent);
        QPainter maskPainter(&intermediatePixmap);
        maskPainter.setCompositionMode(QPainter::CompositionMode_Source);
        maskPainter.drawPixmap(0, 0, pixmap);
        maskPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
        maskPainter.drawPixmap(QRect(0, 0, pixmap.width(), pixmap.height()), mask->m_pixmap, mask->sourceRect());
        maskPainter.end();
        pixmap = intermediatePixmap;
    }

    const qreal prevOpacity = painter->opacity();
    const QTransform prevTransform = painter->transform();
    painter->setOpacity(opacity);
    painter->setTransform(matrix, true);
    painter->drawPixmap(targetRect, pixmap, FloatRect(textureQt.sourceRect()));
    painter->setTransform(prevTransform);
    painter->setOpacity(prevOpacity);
}
QString QtScaledAvatarCache::getScaledAvatarPath(const QString& path) {
	QFileInfo avatarFile(path);
	if (avatarFile.exists()) {
		if (!avatarFile.dir().exists(QString::number(size))) {
			if (!avatarFile.dir().mkdir(QString::number(size))) {
				return path;
			}
		}
		QDir targetDir(avatarFile.dir().absoluteFilePath(QString::number(size)));
		QString targetFile = targetDir.absoluteFilePath(avatarFile.baseName());
		if (!QFileInfo(targetFile).exists()) {
			QPixmap avatarPixmap;
			if (avatarPixmap.load(path)) {
				QPixmap maskedAvatar(avatarPixmap.size());
				maskedAvatar.fill(QColor(0, 0, 0, 0));
				QPainter maskPainter(&maskedAvatar);
				maskPainter.setBrush(Qt::black);
				maskPainter.drawRoundedRect(maskedAvatar.rect(), 25.0, 25.0, Qt::RelativeSize);
				maskPainter.setCompositionMode(QPainter::CompositionMode_SourceIn);
				maskPainter.drawPixmap(0, 0, avatarPixmap);
				maskPainter.end();

				if (!maskedAvatar.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation).save(targetFile, "PNG")) {
					return path;
				}
			} else {
				SWIFT_LOG(debug) << "Failed to load " << Q2PSTRING(path) << std::endl;
			}
		}
		return targetFile;
	}
	else {
		return path;
	}
}
void K3b::WidgetShowEffect::dissolveMask()
{
    if( m_bShow ) {
        m_widget->repaint();
        QPainter maskPainter(&m_mask);

        m_mask.fill(Qt::black);

        maskPainter.setBrush(Qt::white);
        maskPainter.setPen(Qt::white);
        maskPainter.drawRect( m_mask.rect() );

        m_dissolveSize += m_dissolveDelta;

        if( m_dissolveSize > 0 ) {
            //FIXME kde4
            //maskPainter.setRasterOp( Qt::EraseROP );

            int x, y, s;
            const int size = 16;

            for( y = 0; y < m_widget->height() + size; y += size ) {
                x = m_widget->width();
                s = m_dissolveSize * x / 128;

                for( ; x > size; x -= size, s -= 2 ) {
                    if( s < 0 )
                        break;

                    maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s);
                }
            }
        }
        else if( m_dissolveSize < 0 ) {
            m_dissolveDelta = 1;
            killTimer( m_timerId );

            emit widgetShown( m_widget );

            if( m_deleteSelf )
                deleteLater();
        }

        m_widget->setMask( m_mask );
    }

    else {
        // just hide it for now
        emit widgetHidden( m_widget );
        if( !m_bEffectOnly )
            m_widget->hide();

        if( m_deleteSelf )
            deleteLater();
    }
}
Exemple #10
0
void KalziumTip::plainMask()
{
    	QPainter maskPainter(&m_mask);

    	m_mask.fill(Qt::black);

    	maskPainter.setBrush(Qt::white);
    	maskPainter.setPen(Qt::white);
    	maskPainter.drawRoundRect(m_mask.rect(), 1600 / m_mask.rect().width(),
                              1600 / m_mask.rect().height());
    	setMask(m_mask);
    	m_frameTimer.stop();
}
void TestInvocation::dumpPixelsAndCompareWithExpected(WKImageRef imageRef, WKArrayRef repaintRects)
{
    QImage image;
    if (PlatformWebView::windowShapshotEnabled()) {
        WKPageRef page = TestController::shared().mainWebView()->page();
        WKPageForceRepaint(page, this, &forceRepaintDoneCallback);

        TestController::shared().runUntil(m_gotRepaint, TestController::ShortTimeout);

        if (m_gotRepaint)
            image = WKImageCreateQImage(TestController::shared().mainWebView()->windowSnapshotImage().get());
        else {
            m_error = true;
            m_errorMessage = "Timed out waiting for repaint\n";
            m_webProcessIsUnresponsive = true;
            return;
        }
    } else
        image = WKImageCreateQImage(imageRef);

    if (repaintRects) {
        QImage mask(image.size(), image.format());
        mask.fill(QColor(0, 0, 0, 0.66 * 255));

        QPainter maskPainter(&mask);
        maskPainter.setCompositionMode(QPainter::CompositionMode_Source);
        size_t count = WKArrayGetSize(repaintRects);
        for (size_t i = 0; i < count; ++i) {
            WKRect wkRect = WKRectGetValue(static_cast<WKRectRef>(WKArrayGetItemAtIndex(repaintRects, i)));
            QRectF rect(wkRect.origin.x, wkRect.origin.y, wkRect.size.width, wkRect.size.height);
            maskPainter.fillRect(rect, Qt::transparent);
        }

        QPainter painter(&image);
        painter.drawImage(image.rect(), mask);
    }

    QCryptographicHash hash(QCryptographicHash::Md5);
    for (unsigned row = 0; row < image.height(); ++row)
        hash.addData(reinterpret_cast<const char*>(image.constScanLine(row)), image.bytesPerLine());

    QByteArray actualHash = hash.result().toHex();
    ASSERT(actualHash.size() == 32);
    if (!compareActualHashToExpectedAndDumpResults(actualHash)) {
        image.setText("checksum", actualHash);
        dumpImage(image);
    }
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pClearRect (JNIEnv * env, jclass cls, 
                                     jint qtGraphDesc, jint x, jint y, 
                                     jint width, jint height, jint rgb)
{
	QColor qc(rgb);
	
    AWT_QT_LOCK; {
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
    setPainterClip(&p, qtGraphDesc);
	p.fillRect(x, y, width, height, qc);
	if(maskPainter(qtGraphDesc, p))
		p.fillRect(x, y, width, height, qc);
    }
    AWT_QT_UNLOCK;
}
Exemple #13
0
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();
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pDrawRect (JNIEnv * env, jclass cls, 
                                    jint qtGraphDesc, jint x, jint y, 
                                    jint w, jint h)
{
    AWT_QT_LOCK; {
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
	p.setPen(*((QPen *)(QtGraphDescPool[qtGraphDesc].qp)));
	p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
    setPainterClip(&p, qtGraphDesc);
	p.drawRect(x, y, w, h);
	
	if(maskPainter(qtGraphDesc, p))
		p.drawRect(x, y, w, h);
    }
    AWT_QT_UNLOCK;
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pDrawArc (JNIEnv * env, jclass cls, 
                                   jint qtGraphDesc, jint x, jint y, 
                                   jint width, jint height, 
                                   jint start, jint sweep)
{
    AWT_QT_LOCK; {
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
	p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
	p.setPen(*((QPen *)(QtGraphDescPool[qtGraphDesc].qp)));
    setPainterClip(&p, qtGraphDesc);
	p.drawArc(x, y, width, height, start*16, sweep*16);
	
	if(maskPainter(qtGraphDesc, p))
		p.drawArc(x, y, width, height, start*16, sweep*16);
    }
    AWT_QT_UNLOCK;
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pFillOval (JNIEnv * env, jclass cls, 
                                    jint qtGraphDesc, jint x, jint y, 
                                    jint width, jint height)
{
    AWT_QT_LOCK; {
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
	p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
	p.setPen(Qt::NoPen);	
	p.setBrush(*((QBrush *)(QtGraphDescPool[qtGraphDesc].qb)));
    setPainterClip(&p, qtGraphDesc);
	p.drawPie(x, y, width, height, 0, 16*360);
	
	if(maskPainter(qtGraphDesc, p))
		p.drawPie(x, y, width, height, 0, 16*360);
    }
    AWT_QT_UNLOCK;
}
Exemple #17
0
void KalziumTip::dissolveMask()
{
    QPainter maskPainter(&m_mask);

    m_mask.fill(Qt::black);

    maskPainter.setBrush(Qt::white);
    maskPainter.setPen(Qt::white);
    maskPainter.drawRoundRect(m_mask.rect(), 1600 / m_mask.rect().width(),
                              1600 / m_mask.rect().height());

    m_dissolveSize += m_dissolveDelta;

    if (m_dissolveSize > 0)
    {
        maskPainter.setRasterOp(Qt::EraseROP);

        int x, y, s;
        const int size = 16;
	const int heightsize = size + height();

        for (y = 0; y < heightsize; y += size)
        {
            x = width();
            s = m_dissolveSize * x / 128;
            for (; x > -size; x -= size, s -= 2)
            {
                if (s < 0)
                {
                    s = 0;
                }
                maskPainter.drawEllipse(x - s / 2, y - s / 2, s, s);
            }
        }
    }
    else if (m_dissolveSize < 0)
    {
        m_frameTimer.stop();
        m_dissolveDelta = 1;
    }

    setMask(m_mask);
}
JNIEXPORT void JNICALL
Java_java_awt_QtGraphics_pFillRoundRect (JNIEnv * env, jclass cls, 
                                         jint qtGraphDesc, jint x, jint y, 
                                         jint w, jint h,
                                         jint arcW, jint arcH)
{
    AWT_QT_LOCK; {
	QPainter p(QtImageDescPool[QtGraphDescPool[qtGraphDesc].qid].qpd);
	p.setRasterOp(QtGraphDescPool[qtGraphDesc].rasterOp);
	p.setPen(Qt::NoPen);	
	p.setBrush(*((QBrush *)(QtGraphDescPool[qtGraphDesc].qb)));
    setPainterClip(&p, qtGraphDesc);
	p.drawRoundRect(x, y, w, h, arcW, arcH);

	if(maskPainter(qtGraphDesc, p))
		p.drawRoundRect(x, y, w, h, arcW, arcH);	
    }
    AWT_QT_UNLOCK;
}
kpToolWidgetLineWidth::kpToolWidgetLineWidth (QWidget *parent, const char *name)
    : kpToolWidgetBase (parent, name)
{
    setInvertSelectedPixmap ();

    int numLineWidths = sizeof (lineWidths) / sizeof (lineWidths [0]);

    int w = (width () - 2/*margin*/) * 3 / 4;
    int h = (height () - 2/*margin*/ - (numLineWidths - 1)/*spacing*/) * 3 / (numLineWidths * 4);

    for (int i = 0; i < numLineWidths; i++)
    {
        QPixmap pixmap ((w <= 0 ? width () : w),
                        (h <= 0 ? height () : h));
        pixmap.fill (Qt::white);

        QBitmap maskBitmap (pixmap.width (), pixmap.height ());
        maskBitmap.fill (Qt::color0/*transparent*/);
        
        
        QPainter painter (&pixmap), maskPainter (&maskBitmap);
        painter.setPen (Qt::black), maskPainter.setPen (Qt::color1/*opaque*/);
        painter.setBrush (Qt::black), maskPainter.setBrush (Qt::color1/*opaque*/);

        QRect rect = QRect (0, (pixmap.height () - lineWidths [i]) / 2,
                            pixmap.width (), lineWidths [i]);
        painter.drawRect (rect), maskPainter.drawRect (rect);

        painter.end (), maskPainter.end ();
        
        
        pixmap.setMask (maskBitmap);

        addOption (pixmap, QString::number (lineWidths [i]));
        startNewOptionRow ();
    }

    finishConstruction (0, 0);
}
Exemple #20
0
void Popover::generateMask(Direction direction, int offset) {
    mMask = new QBitmap(size());
    mMask->clear();

    QPainter maskPainter(mMask);
    QBrush brush(Qt::color1);
    maskPainter.setBrush(brush);

    // Clip to valid locations.
    offset = std::max(offset, 26);
    if(direction == Direction::Top || direction == Direction::Bottom) {
        offset = std::min(offset, mMask->width()-26);
    } else {
        offset = std::min(offset, mMask->height()-26);
    }

    switch(direction) {
    case Top:
        //Add the rounded rect.
        maskPainter.drawRoundedRect(0,20,mMask->width(),mMask->height()-20,5,5);

        //Add the triangle.
        maskPainter.drawPolygon(QPolygon({
                QPoint(offset, 0),
                QPoint(offset-20, 20),
                QPoint(offset+20, 20)}));

        layout()->setContentsMargins(12, 32, 12, 12);

        break;

    case Right:
        //Add the rounded rect.
        maskPainter.drawRoundedRect(0,0,mMask->width()-20,mMask->height(),5,5);

        //Add the triangle.
        maskPainter.drawPolygon(QPolygon({
                QPoint(mMask->width(), offset),
                QPoint(mMask->width()-20, offset-20),
                QPoint(mMask->width()-20, offset+20)}));
        layout()->setContentsMargins(12, 12, 32, 12);

        break;

    case Bottom:
        //Add the rounded rect.
        maskPainter.drawRoundedRect(0,0,mMask->width(),mMask->height()-20,5,5);

        //Add the triangle.
        maskPainter.drawPolygon(QPolygon({
                QPoint(offset, mMask->height()),
                QPoint(offset-20, mMask->height()-20),
                QPoint(offset+20, mMask->height()-20)}));

        layout()->setContentsMargins(12, 12, 12, 32);

        break;

    case Left:
        //Add the rounded rect.
        maskPainter.drawRoundedRect(20,0,mMask->width()-20,mMask->height(),5,5);

        //Add the triangle.
        maskPainter.drawPolygon(QPolygon({
                QPoint(0, offset),
                QPoint(20, offset-20),
                QPoint(20, offset+20)}));

        layout()->setContentsMargins(32, 12, 12, 12);

        break;
    }

    setMask(*mMask);
}
Exemple #21
0
void FlowPart::orientationPixmap(uint orientation, QPixmap & pm) const {
	const QSize size = pm.size();

	if (!(allowedOrientations() & (1 << orientation))) {
		kdWarning() << k_funcinfo << "Requesting invalid orientation of " << orientation << endl;
		return;
	}

	QBitmap mask(50, 50);

	QPainter maskPainter(&mask);
	mask.fill(Qt::color0);
	maskPainter.setBrush(Qt::color1);
	maskPainter.setPen(Qt::color1);

	QPainter p(&pm);
//	p.setBrush(m_brushCol);
	p.setPen(Qt::black);

	// In order: right corner, top corner, left corner, bottom corner

	QPoint c[4] = {
		QPoint(int(0.7*size.width()), int(0.5*size.height())),
		QPoint(int(0.5*size.width()), int(0.4*size.height())),
		QPoint(int(0.3*size.width()), int(0.5*size.height())),
		QPoint(int(0.5*size.width()), int(0.6*size.height()))
	};

	QPoint d[4];
	d[0] = c[0] + QPoint(7, 0);
	d[1] = c[1] + QPoint(0, -7);
	d[2] = c[2] + QPoint(-7, 0);
	d[3] = c[3] + QPoint(0, 7);

	if (m_stdInput && m_stdOutput && m_altOutput) {
		//BEGIN Draw diamond outline
		QPointArray diamond(4);

		for (uint i = 0; i < 4; ++i)
			diamond[i] = c[i];

		p.drawPolygon(diamond);
		maskPainter.drawPolygon(diamond);
		//END Draw diamond outline

		//BEGIN Draw input
		int pos0 = nodeDirToPos(diamondNodePositioning[orientation][0]);
		p.drawLine(c[pos0], d[pos0]);
		maskPainter.drawLine(c[pos0], d[pos0]);
		//END Draw input

		//BEGIN Draw "true" output as a tick
		QPointArray tick(4);
		tick[0] = QPoint(-3, 0);
		tick[1] = QPoint(0, 2);
		tick[2] = QPoint(0, 2);
		tick[3] = QPoint(4, -2);

		int pos1 = nodeDirToPos(diamondNodePositioning[orientation][1]);

		tick.translate(d[pos1].x(), d[pos1].y());
		p.drawLineSegments(tick);
		maskPainter.drawLineSegments(tick);
		//END Draw "true" output as a tick

		//BEGIN Draw "false" output as a cross
		QPointArray cross(4);

		cross[0] = QPoint(-2, -2);
		cross[1] = QPoint(2, 2);
		cross[2] = QPoint(-2, 2);
		cross[3] = QPoint(2, -2);

		int pos2 = nodeDirToPos(diamondNodePositioning[orientation][2]);

		cross.translate(d[pos2].x(), d[pos2].y());
		p.drawLineSegments(cross);
		maskPainter.drawLineSegments(cross);
		//END Draw "false" output as a cross

	} else if (m_stdInput || m_stdOutput) {
		p.drawRoundRect(int(0.3*size.width()), int(0.4*size.height()), int(0.4*size.width()), int(0.2*size.height()));
		maskPainter.drawRoundRect(int(0.3*size.width()), int(0.4*size.height()), int(0.4*size.width()), int(0.2*size.height()));

		int hal = 5; // half arrow length
		int haw = 3; // half arrow width

		QPoint arrows[4][6] = {
			{ QPoint(hal, 0), QPoint(0, -haw),
				QPoint(hal, 0), QPoint(-hal, 0),
				QPoint(hal, 0), QPoint(0, haw) },

			{ QPoint(0, -hal), QPoint(-haw, 0),
			  QPoint(0, -hal), QPoint(0, hal),
			  QPoint(0, -hal), QPoint(haw, 0) },

			{ QPoint(-hal, 0), QPoint(0, -haw),
			  QPoint(-hal, 0), QPoint(hal, 0),
			  QPoint(-hal, 0), QPoint(0, haw) },

			{ QPoint(0, hal), QPoint(-haw, 0),
			  QPoint(0, hal), QPoint(0, -hal),
			  QPoint(0, hal), QPoint(haw, 0) }
		};

		int inPos = -1;
		int outPos = -1;

		if (m_stdInput && m_stdOutput) {
			inPos = nodeDirToPos(inOutNodePositioning[orientation][0]);
			outPos = nodeDirToPos(inOutNodePositioning[orientation][1]);
		} else if (m_stdInput) {
			inPos = nodeDirToPos(inNodePositioning[orientation]);
		} else if (m_stdOutput) {
			outPos = nodeDirToPos(outNodePositioning[orientation]);
		}

		if (inPos != -1) {
			QPointArray inArrow(6);

			for (int i = 0; i < 6; ++i) {
				inArrow[i] = arrows[(inPos + 2) % 4][i];
			}

			inArrow.translate(d[inPos].x(), d[inPos].y());

			p.drawPolygon(inArrow);
			maskPainter.drawPolygon(inArrow);
		}

		if (outPos != -1) {
			QPointArray outArrow(6);

			for (int i = 0; i < 6; ++i) {
				outArrow[i] = arrows[outPos][i];
			}

			outArrow.translate(d[outPos].x(), d[outPos].y());

			p.drawPolygon(outArrow);
			maskPainter.drawPolygon(outArrow);
		}
	}

	pm.setMask(mask);
}
Exemple #22
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();
}
QDesignerMimeData::QDesignerMimeData(const QDesignerDnDItems &items, QDrag *drag) :
    m_items(items)
{
    enum { Alpha = 200 };
    QPoint decorationTopLeft;
    switch (m_items.size()) {
    case 0:
        break;
    case 1: {
        QWidget *deco = m_items.first()->decoration();
        decorationTopLeft = deco->pos();
        const QPixmap widgetPixmap = QPixmap::grabWidget(deco);
#ifdef TRANSPARENT_DRAG_PIXMAP
        QImage image(widgetPixmap.size(), QImage::Format_ARGB32);
        image.fill(QColor(Qt::transparent).rgba());
        QPainter painter(&image);
        painter.drawPixmap(QPoint(0, 0), widgetPixmap);
        painter.end();
        setImageTransparency(image, Alpha);
        drag->setPixmap(QPixmap::fromImage(image));
#else
        drag->setPixmap(widgetPixmap);
#endif
    }
        break;
    default: {
        // determine size of drag decoration by uniting all geometries
        const QDesignerDnDItems::const_iterator cend = m_items.constEnd();
        QDesignerDnDItems::const_iterator it =m_items.constBegin();
        QRect unitedGeometry = (*it)->decoration()->geometry();
        for (++it; it != cend; ++it )
            unitedGeometry  = unitedGeometry .united((*it)->decoration()->geometry());

        // paint with offset. At the same time, create a mask bitmap, containing widget rectangles.
        QImage image(unitedGeometry.size(), QImage::Format_ARGB32);
        image.fill(QColor(Qt::transparent).rgba());
        QBitmap mask(unitedGeometry.size());
        mask.clear();
        // paint with offset, determine action
        QPainter painter(&image);
        QPainter maskPainter(&mask);
        decorationTopLeft = unitedGeometry.topLeft();
        for (it = m_items.constBegin() ; it != cend; ++it ) {
            QWidget *w = (*it)->decoration();
            const QPixmap wp = QPixmap::grabWidget(w);
            const QPoint pos = w->pos() - decorationTopLeft;
            painter.drawPixmap(pos, wp);
            maskPainter.fillRect(QRect(pos, wp.size()), Qt::color1);
        }
        painter.end();
        maskPainter.end();
#ifdef TRANSPARENT_DRAG_PIXMAP
        setImageTransparency(image, Alpha);
#endif
        QPixmap pixmap = QPixmap::fromImage(image);
        pixmap.setMask(mask);
        drag->setPixmap(pixmap);
    }
        break;
    }
    // determine hot spot and reconstruct the exact starting position as form window
    // introduces some offset when detecting DnD
    m_globalStartPos =  m_items.first()->decoration()->pos() +  m_items.first()->hotSpot();
    m_hotSpot = m_globalStartPos - decorationTopLeft;
    drag->setHotSpot(m_hotSpot);

    drag->setMimeData(this);
}