DesktopBackgroundDialog::DesktopBackgroundDialog(RazorSettings * cfg, int screen, QSize desktopSize, const QBrush & brush, QWidget * parent)
    : QDialog(parent),
      m_desktopSize(desktopSize),
      m_type(RazorWorkSpaceManager::BackgroundColor),
      m_config(cfg),
      m_screen(screen)
{
    setupUi(this);
    // center it to current desktop
    move(parent->geometry().center() - geometry().center());
    
    // read current wallpaper brush
    if (brush.texture().isNull())
    {
        m_color = brush.color();
        preview();
    }
    else
    {
        QPixmap p = brush.texture().scaled(previewLabel->size(), Qt::IgnoreAspectRatio, Qt::FastTransformation);
        previewLabel->setPixmap(p);
    }

    connect(colorButton, SIGNAL(clicked()),
            this, SLOT(colorButton_clicked()));
    connect(wallpaperButton, SIGNAL(clicked()),
            this, SLOT(wallpaperButton_clicked()));
    connect(systemButton, SIGNAL(clicked()),
            this, SLOT(systemButton_clicked()));
    connect(keepAspectCheckBox, SIGNAL(toggled(bool)),
            this, SLOT(preview()));

    buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
    keepAspectCheckBox->setEnabled(false);
}
void createBrushNode( QDomDocument& doc, QDomNode& parent,
                      const QString& elementName, const QBrush& brush )

{
    QDomElement brushElement = doc.createElement( elementName );
    parent.appendChild( brushElement );
    createColorNode( doc, brushElement, "Color", brush.color() );
    createStringNode( doc, brushElement, "Style",
                      KDGanttXML::brushStyleToString( brush.style() ) );
    if( brush.style() == Qt::TexturePattern && !brush.texture().isNull() )
        createPixmapNode( doc, brushElement, "Pixmap", brush.texture() );
}
Beispiel #3
0
static inline void qwtFillRect( const QWidget *widget, QPainter *painter,
    const QRect &rect, const QBrush &brush)
{
    if ( brush.style() == Qt::TexturePattern )
    {
        painter->save();

        painter->setClipRect( rect );
        painter->drawTiledPixmap(rect, brush.texture(), rect.topLeft());

        painter->restore();
    }
    else if ( brush.gradient() )
    {
        painter->save();

        painter->setClipRect( rect );
        painter->fillRect(0, 0, widget->width(),
            widget->height(), brush);

        painter->restore();
    }
    else
    {
        painter->fillRect(rect, brush);
    }
}
bool QBrushPropertyItem::hasChildren()
{
   if (!m_childrenSet)
   {
      m_childrenSet = true;

      QBrush brush = qvariant_cast<QBrush>(m_metaProperty.read(m_parent->qObject()));

      QPropertyItem* width = new QPropertyItem(brush.color(), "Color", this);
      m_children.append(width);
      connect(width, SIGNAL(valueChanged(const QString&, const QVariant&)), this,
              SLOT(onChildItemValueChanged(const QString&, const QVariant&)));


      int index = staticQtMetaObject.indexOfEnumerator("BrushStyle");
      QMetaEnum enumeration = staticQtMetaObject.enumerator(index);
      QChildEnumPropertyItem* brushStyle = new QChildEnumPropertyItem((int)brush.style(), "Brush Style",enumeration , this);
      m_children.append(brushStyle);
      connect(brushStyle, SIGNAL(valueChanged(const QString&, const QVariant&)), this,
              SLOT(onChildItemValueChanged(const QString&, const QVariant&)));


      QChildImagePropertyItem* textureImage = new QChildImagePropertyItem(brush.texture(), "Texture", this);
      m_children.append(textureImage);
      connect(textureImage, SIGNAL(valueChanged(const QString&, const QVariant&)), this,
              SLOT(onChildItemValueChanged(const QString&, const QVariant&)));

      return true;
   }
void QBrushPropertyItem::setChildValues()
{
   if (!m_isSettingChildren)
   {
      m_isSettingChildren = true;

      QBrush brush = qvariant_cast<QBrush>(m_metaProperty.read(m_parent->qObject()));

      for (int i = 0; i < m_children.count(); i++)
      {
         QPropertyItem* child = m_children[i];
         QString propertyName = child->name();
         QVariant tval;

         if (propertyName == "Color")
         {
            tval = brush.color();
         }
         else if (propertyName == "Brush Style")
         {
            tval = (int)brush.style();
         }
         else if (propertyName == "Texture")
         {
            tval = brush.texture();
         }

         m_model->setData(child->index(), tval);
      }


      m_isSettingChildren = false;
   }
}
QBrush DBrushAdjuster::mapBrush(const QBrush &brush, const QMatrix &matrix  )
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::mapGradient( brush.gradient(), matrix );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
		QPixmap p(brush.texture());
		p = p.transformed(matrix , Qt::SmoothTransformation );
		brush1.setTexture( p );
	}
	
	
	return brush1;
}
QBrush DBrushAdjuster::adjustBrush(const QBrush &brush, const QRect &rect )
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::adjustGradient( brush.gradient(), rect );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
		QPixmap p = (brush.texture()/*.toImage ()*/);
		int offset= 0;
		QRect br = p.rect();
		QMatrix matrix;
		
		float sx = 1, sy = 1;
		if ( rect.width() < br.width() )
		{
			sx = static_cast<float>(rect.width()-offset) / static_cast<float>(br.width());
		}
		if ( rect.height() < br.height() )
		{
			sy = static_cast<float>(rect.height()-offset) / static_cast<float>(br.height());
		}
	
		float factor = qMin(sx, sy);
		matrix.scale(sx, sy);
		p = p.transformed(matrix ,Qt::SmoothTransformation );
	
		matrix.reset();
	
		QPointF pos = br.topLeft();
	
		float tx = offset/2-pos.x(), ty = offset/2-pos.y();
	
		matrix.translate(tx, ty);
		p = p.transformed(matrix ,Qt::SmoothTransformation );
		
// 		brush1 = QBrush(p);
		brush1.setTexture (  p );
	}
	return brush1;
}
void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
{
  QBrush b = palette().brush(QPalette::Active, QPalette::Base);

  // Get the brush, which will have the background pixmap if there is one.
  if (!b.texture().isNull())
  {
    p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
      b.texture(),
      rect.left() + contentsX(),
      rect.top() + contentsY() );
  }

  else
  {
    // Do a normal paint
    K3ListView::paintEmptyArea(p, rect);
  }
}
QBrush DBrushAdjuster::flipBrush(const QBrush &brush, Qt::Orientation o)
{
	QBrush brush1(brush);
	if(brush.gradient())
	{
		QGradient grad = DGradientAdjuster::flipGradient( brush.gradient(), o );
		brush1 = QBrush(grad);
	}
	else if(!brush.texture().isNull())
	{
	}
	return brush1;
}
Beispiel #10
0
    /**
     * Saves the brush info as xmi into the DOM element \a qElement.
     *
     * @param qDoc The QDomDocument object pointing to the xmi document.
     *
     * @param qElement The element into which the pen, brush and font
     *                 info should be saved.
     *
     * @param brush The QBrush whose details should be saved.
     */
    void saveBrushToXMI(QDomDocument &qDoc, QDomElement &qElement,
                        const QBrush& brush)
    {
        QDomElement brushElement = qDoc.createElement(QLatin1String("brush"));

        brushElement.setAttribute(QLatin1String("style"), (quint8)brush.style());
        brushElement.setAttribute(QLatin1String("color"), brush.color().name());

        if(brush.style() == Qt::TexturePattern) {
            savePixmapToXMI(qDoc, brushElement, brush.texture());
        }
        else if(brush.style() == Qt::LinearGradientPattern
                || brush.style() == Qt::RadialGradientPattern
                || brush.style() == Qt::ConicalGradientPattern) {
            saveGradientToXMI(qDoc, brushElement, brush.gradient());
        }

        //TODO: Check if transform of this brush needs to be saved.
        qElement.appendChild(brushElement);
    }
void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    const QAbstractItemModel *model = index.model();
    Q_ASSERT(model);

    if (!model->parent(index).isValid()) {
        // this is a top-level item.
        QStyleOptionButton buttonOption;

        buttonOption.state = option.state;
#ifdef Q_OS_MAC
        buttonOption.state |= QStyle::State_Raised;
#endif
        buttonOption.state &= ~QStyle::State_HasFocus;

        buttonOption.rect = option.rect;
        buttonOption.palette = option.palette;
        buttonOption.features = QStyleOptionButton::None;

        painter->save();
        QColor buttonColor(230, 230, 230);
        QBrush buttonBrush = option.palette.button();
        if (!buttonBrush.gradient() && buttonBrush.texture().isNull())
            buttonColor = buttonBrush.color();
        QColor outlineColor = buttonColor.darker(150);
        QColor highlightColor = buttonColor.lighter(130);

        // Only draw topline if the previous item is expanded
        QModelIndex previousIndex = model->index(index.row() - 1, index.column());
        bool drawTopline = (index.row() > 0 && m_view->isExpanded(previousIndex));
        int highlightOffset = drawTopline ? 1 : 0;

        QLinearGradient gradient(option.rect.topLeft(), option.rect.bottomLeft());
        gradient.setColorAt(0, buttonColor.lighter(102));
        gradient.setColorAt(1, buttonColor.darker(106));

        painter->setPen(Qt::NoPen);
        painter->setBrush(gradient);
        painter->drawRect(option.rect);
        painter->setPen(highlightColor);
        painter->drawLine(option.rect.topLeft() + QPoint(0, highlightOffset),
                          option.rect.topRight() + QPoint(0, highlightOffset));
        painter->setPen(outlineColor);
        if (drawTopline)
            painter->drawLine(option.rect.topLeft(), option.rect.topRight());
        painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
        painter->restore();

        QStyleOption branchOption;
        static const int i = 9; // ### hardcoded in qcommonstyle.cpp
        QRect r = option.rect;
        branchOption.rect = QRect(r.left() + i/2, r.top() + (r.height() - i)/2, i, i);
        branchOption.palette = option.palette;
        branchOption.state = QStyle::State_Children;

        if (m_view->isExpanded(index))
            branchOption.state |= QStyle::State_Open;

        m_view->style()->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, painter, m_view);

        // draw text
        QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - ((5*i)/2), r.height());
        QString text = elidedText(option.fontMetrics, textrect.width(), Qt::ElideMiddle, 
            model->data(index, Qt::DisplayRole).toString());
        m_view->style()->drawItemText(painter, textrect, Qt::AlignCenter,
            option.palette, m_view->isEnabled(), text);

    } else {
        QItemDelegate::paint(painter, option, index);
    }
}
    //________________________________________________
    void TransitionWidget::grabBackground( QPixmap& pixmap, QWidget* widget, QRect& rect ) const
    {
        if( !widget ) return;

        QWidgetList widgets;
        if( widget->autoFillBackground() )
        { widgets.append( widget ); }

        QWidget *parent(0);

        // get highest level parent
        for( parent = widget->parentWidget(); parent; parent = parent->parentWidget() )
        {

            if( !( parent->isVisible() && parent->rect().isValid() ) ) continue;

            // store in list
            widgets.append( parent );

            // stop at topLevel
            if( parent->isTopLevel() || parent->autoFillBackground() ) break;

        }

        if( !parent ) parent = widget;

        // painting
        QPainter p(&pixmap);
        p.setClipRect( rect );
        const QBrush backgroundBrush = parent->palette().brush( parent->backgroundRole());
        if( backgroundBrush.style() == Qt::TexturePattern)
        {

            p.drawTiledPixmap( rect, backgroundBrush.texture(), widget->mapTo( parent, rect.topLeft() ) );

        } else {

            p.fillRect( pixmap.rect(), backgroundBrush );

        }

        if( parent->isTopLevel() && parent->testAttribute(Qt::WA_StyledBackground))
        {
            QStyleOption option;
            option.initFrom(parent);
            option.rect = rect;
            option.rect.translate( widget->mapTo( parent, rect.topLeft() ) );
            p.translate(-option.rect.topLeft());
            parent->style()->drawPrimitive ( QStyle::PE_Widget, &option, &p, parent );
            p.translate(option.rect.topLeft());
        }

        // draw all widgets in parent list
        // backward
        QPaintEvent event(rect);
        for( int i = widgets.size() - 1; i>=0; i-- )
        {
            QWidget* w = widgets.at(i);
            w->render( &p, -widget->mapTo( w, rect.topLeft() ), rect, 0 );
        }

        // end
        p.end();

    }
Beispiel #13
0
void QBlitterPaintEngine::fillRect(const QRectF &rect, const QBrush &brush)
{
    if (rect.size().isEmpty())
        return;

    Q_D(QBlitterPaintEngine);

    if (qbrush_style(brush) == Qt::SolidPattern
        && d->caps.canBlitterAlphaFillRect()) {
        d->fillRect(rect, qbrush_color(brush), true);
    } else if (qbrush_style(brush) == Qt::SolidPattern
        && qbrush_color(brush).alpha() == 0xff
        && d->caps.canBlitterFillRect()) {
        d->fillRect(rect, qbrush_color(brush), false);
    } else if ((brush.style() == Qt::TexturePattern) &&
               (brush.transform().type() <= QTransform::TxTranslate) &&
                ((d->caps.canBlitterDrawPixmapOpacity(brush.texture())) ||
                 (d->caps.canBlitterDrawPixmap(rect, brush.texture(), rect)))) {
        bool rectIsFilled = false;
        QRectF transformedRect = state()->matrix.mapRect(rect);
        qreal x = transformedRect.x();
        qreal y = transformedRect.y();
        QPixmap pm = brush.texture();
        d->unlock();
        int srcX = int(rect.x() - state()->brushOrigin.x() - brush.transform().dx()) % pm.width();
        if (srcX < 0)
            srcX = pm.width() + srcX;
        const int startX = srcX;
        int srcY = int(rect.y() - state()->brushOrigin.y() - brush.transform().dy()) % pm.height();
        if (srcY < 0)
            srcY = pm.height() + srcY;
        while (!rectIsFilled) {
            qreal blitWidth = (pm.width() ) - srcX;
            qreal blitHeight = (pm.height() ) - srcY;
            if (x + blitWidth > transformedRect.right())
                blitWidth = transformedRect.right() -x;
            if (y + blitHeight > transformedRect.bottom())
                blitHeight = transformedRect.bottom() - y;
            const QClipData *clipData = d->clip();
            if (clipData->hasRectClip) {
                QRect targetRect = QRect(x, y, blitWidth, blitHeight).intersected(clipData->clipRect);
                if (targetRect.isValid()) {
                    int tmpSrcX  = srcX + (targetRect.x() - x);
                    int tmpSrcY = srcY + (targetRect.y() - y);
                    QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height());
                    d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect);
                }
            } else if (clipData->hasRegionClip) {
                QVector<QRect> clipRects = clipData->clipRegion.rects();
                QRect unclippedTargetRect(x, y, blitWidth, blitHeight);
                QRegion intersectedRects = clipData->clipRegion.intersected(unclippedTargetRect);

                for (int i = 0; i < intersectedRects.rects().size(); ++i) {
                    QRect targetRect = intersectedRects.rects().at(i);
                    if (!targetRect.isValid() || targetRect.isEmpty())
                        continue;
                    int tmpSrcX = srcX + (targetRect.x() - x);
                    int tmpSrcY = srcY + (targetRect.y() - y);
                    QRect srcRect(tmpSrcX, tmpSrcY, targetRect.width(), targetRect.height());
                    d->pmData->blittable()->drawPixmap(targetRect, pm, srcRect);
                }
            }
            x+=blitWidth;
            if (qFuzzyCompare(x, transformedRect.right())) {
                x = transformedRect.x();
                srcX = startX;
                srcY = 0;
                y += blitHeight;
                if (qFuzzyCompare(y, transformedRect.bottom()))
                    rectIsFilled = true;
            } else
                srcX = 0;
        }
    } else {
        d->lock();
        d->pmData->markRasterOverlay(rect);
        QRasterPaintEngine::fillRect(rect, brush);
    }

}
    ComPtr<ID2D1Brush> to_d2d_brush(const QBrush &newBrush, bool *needsEmulation)
    {
        HRESULT hr;
        ComPtr<ID2D1Brush> result;

        Q_ASSERT(needsEmulation);

        *needsEmulation = false;

        switch (newBrush.style()) {
        case Qt::NoBrush:
            break;

        case Qt::SolidPattern:
        {
            ComPtr<ID2D1SolidColorBrush> solid;

            hr = dc()->CreateSolidColorBrush(to_d2d_color_f(newBrush.color()), &solid);
            if (FAILED(hr)) {
                qWarning("%s: Could not create solid color brush: %#x", __FUNCTION__, hr);
                break;
            }

            hr = solid.As(&result);
            if (FAILED(hr))
                qWarning("%s: Could not convert solid color brush: %#x", __FUNCTION__, hr);
        }
            break;

        case Qt::Dense1Pattern:
        case Qt::Dense2Pattern:
        case Qt::Dense3Pattern:
        case Qt::Dense4Pattern:
        case Qt::Dense5Pattern:
        case Qt::Dense6Pattern:
        case Qt::Dense7Pattern:
        case Qt::HorPattern:
        case Qt::VerPattern:
        case Qt::CrossPattern:
        case Qt::BDiagPattern:
        case Qt::FDiagPattern:
        case Qt::DiagCrossPattern:
        {
            ComPtr<ID2D1BitmapBrush1> bitmapBrush;
            D2D1_BITMAP_BRUSH_PROPERTIES1 bitmapBrushProperties = {
                D2D1_EXTEND_MODE_WRAP,
                D2D1_EXTEND_MODE_WRAP,
                interpolationMode()
            };

            QImage brushImg = qt_imageForBrush(newBrush.style(), false);
            brushImg.setColor(0, newBrush.color().rgba());
            brushImg.setColor(1, qRgba(0, 0, 0, 0));

            QWindowsDirect2DBitmap bitmap;
            bool success = bitmap.fromImage(brushImg, Qt::AutoColor);
            if (!success) {
                qWarning("%s: Could not create Direct2D bitmap from Qt pattern brush image", __FUNCTION__);
                break;
            }

            hr = dc()->CreateBitmapBrush(bitmap.bitmap(),
                                         bitmapBrushProperties,
                                         &bitmapBrush);
            if (FAILED(hr)) {
                qWarning("%s: Could not create Direct2D bitmap brush for Qt pattern brush: %#x", __FUNCTION__, hr);
                break;
            }

            hr = bitmapBrush.As(&result);
            if (FAILED(hr))
                qWarning("%s: Could not convert Direct2D bitmap brush for Qt pattern brush: %#x", __FUNCTION__, hr);
        }
            break;

        case Qt::LinearGradientPattern:
        case Qt::RadialGradientPattern:
        case Qt::ConicalGradientPattern:
            *needsEmulation = true;
            break;

        case Qt::TexturePattern:
        {
            ComPtr<ID2D1BitmapBrush1> bitmapBrush;
            D2D1_BITMAP_BRUSH_PROPERTIES1 bitmapBrushProperties = {
                D2D1_EXTEND_MODE_WRAP,
                D2D1_EXTEND_MODE_WRAP,
                interpolationMode()
            };

            QWindowsDirect2DPlatformPixmap *pp = static_cast<QWindowsDirect2DPlatformPixmap *>(newBrush.texture().handle());
            QWindowsDirect2DBitmap *bitmap = pp->bitmap();
            hr = dc()->CreateBitmapBrush(bitmap->bitmap(),
                                         bitmapBrushProperties,
                                         &bitmapBrush);

            if (FAILED(hr)) {
                qWarning("%s: Could not create texture brush: %#x", __FUNCTION__, hr);
                break;
            }

            hr = bitmapBrush.As(&result);
            if (FAILED(hr))
                qWarning("%s: Could not convert texture brush: %#x", __FUNCTION__, hr);
        }
            break;
        }

        if (result && !newBrush.transform().isIdentity())
            result->SetTransform(to_d2d_matrix_3x2_f(newBrush.transform()));

        return result;
    }
Beispiel #15
0
HBRUSH EmfPaintEngine::convertBrush(const QBrush& brush)
{
	LOGBRUSH lbrush = {BS_NULL, 0, 0};

	if (!brush.color().alpha())
		return CreateBrushIndirect( &lbrush );

	if (brush.color().alpha() < 255){//semi-transparent brush color
		qWarning ("Semi-transparent brushes are not supported by EmfEngine.");

		#ifdef Q_WS_WIN
		QPixmap pix(4, 4);
		pix.fill(Qt::white);
		QPainter p;
		p.begin(&pix);
		p.setPen(QPen(Qt::NoPen));
		p.setBrush(brush);
		p.drawRect(QRect(0, 0, 4, 4));
		p.end();

		HBITMAP hBmp = pix.toWinHBITMAP();
		HBRUSH wbrush = CreatePatternBrush(hBmp);
		DeleteObject(hBmp);
		return wbrush;
		#endif
	}

	LONG lbHatch = HS_HORIZONTAL;
	UINT lbStyle = BS_HATCHED;
	switch(brush.style()){
		case Qt::NoBrush:
			lbStyle = BS_NULL;
		break;

		case Qt::SolidPattern:
			lbStyle = BS_SOLID;
		break;

		case Qt::Dense1Pattern:
		case Qt::Dense2Pattern:
		case Qt::Dense3Pattern:
		case Qt::Dense4Pattern:
		case Qt::Dense5Pattern:
		case Qt::Dense6Pattern:
		case Qt::Dense7Pattern:
		{
		#ifdef Q_WS_WIN
			QPixmap pix(4, 4);
			pix.fill(Qt::white);
			QPainter p;
			p.begin(&pix);
			p.setPen(QPen(Qt::NoPen));
			p.setBrush(brush);
			p.drawRect(QRect(0, 0, 4, 4));
			p.end();

			HBITMAP hbm = pix.toWinHBITMAP();
			HBRUSH wbrush = CreatePatternBrush(hbm);
			DeleteObject(hbm);
			return wbrush;
		#endif
		}
		break;

		case Qt::HorPattern:
		break;

		case Qt::VerPattern:
			lbHatch = HS_VERTICAL;
		break;

		case Qt::CrossPattern:
			lbHatch = HS_CROSS;
		break;

		case Qt::BDiagPattern:
			lbHatch = HS_BDIAGONAL;
		break;

		case Qt::FDiagPattern:
			lbHatch = HS_FDIAGONAL;
		break;

		case Qt::DiagCrossPattern:
			lbHatch = HS_DIAGCROSS;
		break;

		case Qt::LinearGradientPattern:
		{
			qWarning("EmfEngine: Qt::LinearGradientPattern is not supported.");
			return CreateBrushIndirect( &lbrush );
		}
		break;

		case Qt::ConicalGradientPattern:
		{
			qWarning("EmfEngine: Qt::ConicalGradientPattern is not supported.");
			return CreateBrushIndirect( &lbrush );
		}
		break;

		case Qt::RadialGradientPattern:
		{
			qWarning("EmfEngine: Qt::RadialGradientPattern is not supported.");
			return CreateBrushIndirect( &lbrush );
		}

		case Qt::TexturePattern:
		#ifdef Q_WS_WIN
		{
			HBITMAP hbm = brush.texture().toWinHBITMAP();
			HBRUSH wbrush = CreatePatternBrush(hbm);
			DeleteObject(hbm);
			return wbrush;
		}
		#endif
		break;

		default:
			lbStyle = BS_SOLID;
		break;
	}

	LOGBRUSH logbrush = {lbStyle, RGB(brush.color().red(), brush.color().green(), brush.color().blue()), lbHatch};
	return CreateBrushIndirect( &logbrush );
}