void DualColorButton::mouseMoveEvent(QMouseEvent *event) { if(dragSource_ != NODRAG && (event->buttons() & Qt::LeftButton) && (event->pos() - dragStart_).manhattanLength() > QApplication::startDragDistance()) { QDrag *drag = new QDrag(this); QMimeData *mimedata = new QMimeData; const QColor color = (dragSource_ == FOREGROUND)?foreground_:background_; mimedata->setColorData(color); drag->setMimeData(mimedata); drag->start(Qt::CopyAction); } // Higlight clickable areas QRectF fgr = foregroundRect(); QRectF bgr = backgroundRect(); if(fgr.contains(event->pos())) hilite_ = 1; else if(bgr.contains(event->pos())) hilite_ = 2; else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top()) hilite_ = 3; else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom()) hilite_ = 4; else hilite_ = 0; update(); }
void WhiteBoardColorChooser::paintEvent(QPaintEvent *e) { QFrame::paintEvent(e); QPainter tPaint; tPaint.begin(this); tPaint.drawPixmap(swapPixmapRect().topLeft(), m_swapPixmap); QRect bgRect = backgroundRect(); QRect bgRectInside = QRect(bgRect.x () + 2, bgRect.y () + 2, bgRect.width () - 4, bgRect.height () - 4); tPaint.fillRect(bgRectInside, m_backgroundColor); qDrawShadePanel(&tPaint, bgRect, palette(), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); QRect fgRect = foregroundRect(); QRect fgRectInside = QRect(fgRect.x () + 2, fgRect.y () + 2, fgRect.width () - 4, fgRect.height () - 4); tPaint.fillRect(fgRectInside, m_foregroundColor); qDrawShadePanel(&tPaint, fgRect, palette (), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); tPaint.end(); }
void QtSvgSlider::paintEvent(QPaintEvent * event) { Q_UNUSED(event); QPainter painter(this); //draw background // if (this->isInactive && this->picBackgroundInactive->isValid()) // { // this->picBackgroundInactive->render(&painter, dialRect()); // } // else if (underMouse()) // { // this->picBackgroundHovered->render(&painter, dialRect()); // } // else if(this->shouldGlow) // { // this->picBackgroundGlow->render(&painter, dialRect()); // } // else // { this->picBackground->render(&painter, backgroundRect()); // } //draw indicator this->picIndicator->render(&painter, indicatorRect()); }
/************************************************************************* Perform the actual rendering for this Window. *************************************************************************/ void Static::populateRenderCache() { Rect backgroundRect(Point(0,0), getAbsoluteSize()); // draw frame if (d_frameEnabled) { d_frame.draw(d_renderCache); // adjust destination area for backfrop image. backgroundRect.d_left += d_left_width; backgroundRect.d_right -= d_right_width; backgroundRect.d_top += d_top_height; backgroundRect.d_bottom -= d_bottom_height; } // draw backdrop if (d_backgroundEnabled && (d_background != NULL)) { // factor window alpha into colours to use when rendering background ColourRect colours(d_backgroundCols); colours.modulateAlpha(getEffectiveAlpha()); // cache image for drawing d_renderCache.cacheImage(*d_background, backgroundRect, 0, colours); } }
void DualColorButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); QPen normal = palette().color(QPalette::Mid); QPen hilite = palette().color(QPalette::Light); normal.setCosmetic(true); hilite.setCosmetic(true); painter.setRenderHint(QPainter::Antialiasing); // Draw background box const QRectF bgbox = backgroundRect(); painter.setPen(hilite_==2 ? hilite : normal); painter.setBrush(background_); painter.drawRoundedRect(bgbox, 3, 3); // Draw foreground box const QRectF fgbox = foregroundRect(); painter.setPen(hilite_==1 ? hilite : normal); painter.setBrush(foreground_); painter.drawRoundedRect(fgbox, 3, 3); // Draw reset boxes painter.setPen(hilite_==4 ? hilite : normal); painter.setBrush(Qt::white); painter.drawRect(resetWhiteRect()); painter.setBrush(Qt::black); painter.drawRect(resetBlackRect()); // Draw swap arrow static const QPointF arrows[] = { QPointF(0, 2), QPointF(2, 4), QPointF(2, 3), QPointF(4, 3), QPointF(4, 5), QPointF(3, 5), QPointF(5, 7), QPointF(7, 5), QPointF(6, 5), QPointF(6, 1), QPointF(2, 1), QPointF(2, 0) }; const qreal scale = (1.0 / 8.0) * width() / 3.0; painter.translate(ceil(fgbox.width()) + 0.0, 0); painter.scale(scale, scale); painter.setPen(hilite_==3 ? hilite : normal); painter.setBrush(palette().dark()); painter.drawPolygon(arrows, 12); }
void EmbeddedObjectPainter::paintReplaced(const PaintInfo& paintInfo, const LayoutPoint& paintOffset) { if (!m_layoutEmbeddedObject.showsUnavailablePluginIndicator()) return; if (paintInfo.phase == PaintPhaseSelection) return; GraphicsContext& context = paintInfo.context; if (LayoutObjectDrawingRecorder::useCachedDrawingIfPossible( context, m_layoutEmbeddedObject, paintInfo.phase)) return; LayoutRect contentRect(m_layoutEmbeddedObject.contentBoxRect()); contentRect.moveBy(paintOffset); LayoutObjectDrawingRecorder drawingRecorder(context, m_layoutEmbeddedObject, paintInfo.phase, contentRect); GraphicsContextStateSaver stateSaver(context); context.clip(pixelSnappedIntRect(contentRect)); Font font = replacementTextFont(); const SimpleFontData* fontData = font.primaryFont(); DCHECK(fontData); if (!fontData) return; TextRun textRun(m_layoutEmbeddedObject.unavailablePluginReplacementText()); FloatSize textGeometry(font.width(textRun), fontData->getFontMetrics().height()); LayoutRect backgroundRect( 0, 0, textGeometry.width() + 2 * replacementTextRoundedRectLeftRightTextMargin, replacementTextRoundedRectHeight); backgroundRect.move(contentRect.center() - backgroundRect.center()); backgroundRect = LayoutRect(pixelSnappedIntRect(backgroundRect)); Path roundedBackgroundRect; FloatRect floatBackgroundRect(backgroundRect); roundedBackgroundRect.addRoundedRect( floatBackgroundRect, FloatSize(replacementTextRoundedRectRadius, replacementTextRoundedRectRadius)); context.setFillColor( scaleAlpha(Color::white, replacementTextRoundedRectOpacity)); context.fillPath(roundedBackgroundRect); FloatRect textRect(FloatPoint(), textGeometry); textRect.move(FloatPoint(contentRect.center()) - textRect.center()); TextRunPaintInfo runInfo(textRun); runInfo.bounds = floatBackgroundRect; context.setFillColor(scaleAlpha(Color::black, replacementTextTextOpacity)); context.drawBidiText( font, runInfo, textRect.location() + FloatSize(0, fontData->getFontMetrics().ascent())); }
void DualColorButton::mousePressEvent(QMouseEvent *event) { if(event->button() != Qt::LeftButton) return; dragSource_ = NODRAG; if(backgroundRect().contains(event->pos())) dragSource_ = BACKGROUND; if(foregroundRect().contains(event->pos())) dragSource_ = FOREGROUND; dragStart_ = event->pos(); }
// protected virtual [base QWidget] void kpDualColorButton::dragMoveEvent (QDragMoveEvent *e) { #if DEBUG_KP_DUAL_COLOR_BUTTON qCDebug(kpLogWidgets) << "kpDualColorButton::dragMoveEvent() canDecode=" << KColorMimeData::canDecode (e->mimeData ()) << endl; #endif e->setAccepted ( (foregroundRect ().contains (e->pos ()) || backgroundRect ().contains (e->pos ())) && KColorMimeData::canDecode (e->mimeData ())); }
void kpDualColorButton::mouseMoveEvent (QMouseEvent *e) { #if DEBUG_KP_DUAL_COLOR_BUTTON qCDebug(kpLogWidgets) << "kpDualColorButton::mouseMoveEvent() pos=" << e->pos () << " buttons=" << e->buttons () << " dragStartPoint=" << m_dragStartPoint << endl; #endif if (m_dragStartPoint == KP_INVALID_POINT) return; if (!(e->buttons () & Qt::LeftButton)) { m_dragStartPoint = KP_INVALID_POINT; return; } const int delay = QApplication::startDragDistance (); if (e->x () < m_dragStartPoint.x () - delay || e->x () > m_dragStartPoint.x () + delay || e->y () < m_dragStartPoint.y () - delay || e->y () > m_dragStartPoint.y () + delay) { #if DEBUG_KP_DUAL_COLOR_BUTTON qCDebug(kpLogWidgets) << "\tstarting drag as long as it's in a rectangle"; #endif kpColor color; if (foregroundRect ().contains (m_dragStartPoint)) color = foregroundColor (); else if (backgroundRect ().contains (m_dragStartPoint)) color = backgroundColor (); else { // "color" is left as invalid. } #if DEBUG_KP_DUAL_COLOR_BUTTON qCDebug(kpLogWidgets) << "\tcolor.isValid=" << color.isValid () << " rgb=" << (color.isValid () ? (int *) color.toQRgb () : 0) << endl; #endif if (color.isValid ()) { if (!color.isTransparent ()) KColorMimeData::createDrag (color.toQColor (), this)->exec (); } m_dragStartPoint = KP_INVALID_POINT; } }
void DualColorButton::dropEvent(QDropEvent *event) { const QColor color = qvariant_cast<QColor>(event->mimeData()->colorData()); if(foregroundRect().contains(event->pos())) { foreground_ = color; emit foregroundChanged(color); } else if(backgroundRect().contains(event->pos())) { background_ = color; emit backgroundChanged(color); } update(); }
LayoutRect RenderView::backgroundRect(RenderBox* backgroundRenderer) const { if (!hasColumns()) return unscaledDocumentRect(); ColumnInfo* columnInfo = this->columnInfo(); LayoutRect backgroundRect(0, 0, columnInfo->desiredColumnWidth(), columnInfo->columnHeight() * columnInfo->columnCount()); if (!isHorizontalWritingMode()) backgroundRect = backgroundRect.transposedRect(); backgroundRenderer->flipForWritingMode(backgroundRect); return backgroundRect; }
//______________________________________ void ShadowDemoWidget::updateBackgroundPixmap( void ) { // check if background pixmap needs update QRect backgroundRect( QPoint( 0, 0 ), size() - QSize( 2*_shadowSize, 2*_shadowSize ) ); if( !_backgroundPixmap.isNull() && _backgroundPixmap.size() == backgroundRect.size() ) { return; } _backgroundPixmap = QPixmap( backgroundRect.size() ); _backgroundPixmap.fill( Qt::transparent ); QPainter painter( &_backgroundPixmap ); painter.setRenderHint( QPainter::Antialiasing ); _dummy.resize( backgroundRect.size() ); helper().renderWindowBackground( &painter, backgroundRect, &_dummy, &_dummy, palette().color( QPalette::Window ), 0, 64 ); // float frame helper().drawFloatFrame( &painter, backgroundRect.adjusted( -1, -1, 1, 1 ), palette().color( QPalette::Window ), false ); // add rounded mask painter.save(); painter.setCompositionMode( QPainter::CompositionMode_DestinationIn ); painter.setBrush( Qt::black ); painter.setPen( Qt::NoPen ); if( _square ) { QRectF rectF( backgroundRect ); QPainterPath path; // rotate counterclockwise, cause that makes angles easier path.moveTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); path.arcTo( QRectF( rectF.topLeft(), QSize( 7, 7 ) ), 90, 90 ); path.lineTo( rectF.bottomLeft() ); path.lineTo( rectF.bottomRight() ); path.lineTo( rectF.topRight() + QPointF( 0, 3.5 ) ); path.arcTo( QRectF( rectF.topRight() + QPointF( -7, 0 ), QSize( 7, 7 ) ), 0, 90 ); path.lineTo( rectF.topLeft() + QPointF( 3.5, 0 ) ); painter.drawPath( path ); } else { painter.drawRoundedRect( QRectF( backgroundRect ), 3.5, 3.5 ); } painter.restore(); }
// protected virtual [base QWidget] void kpDualColorButton::dropEvent (QDropEvent *e) { QColor col = KColorMimeData::fromMimeData (e->mimeData ()); #if DEBUG_KP_DUAL_COLOR_BUTTON qCDebug(kpLogWidgets) << "kpDualColorButton::dropEvent() col=" << (int *) col.rgba() << " (with alpha=" << (int *) col.rgba () << ")" << endl; #endif if (col.isValid ()) { if (foregroundRect ().contains (e->pos ())) setForegroundColor (kpColor (col.rgba())); else if (backgroundRect ().contains (e->pos ())) setBackgroundColor (kpColor (col.rgba())); } }
// protected virtual [base QWidget] void kpDualColorButton::mouseDoubleClickEvent (QMouseEvent *e) { int whichColor = -1; if (foregroundRect ().contains (e->pos ())) whichColor = 0; else if (backgroundRect ().contains (e->pos ())) whichColor = 1; if (whichColor == 0 || whichColor == 1) { QColorDialog dialog(this); dialog.setCurrentColor(color(whichColor).toQColor()); dialog.setOptions(QColorDialog::ShowAlphaChannel); if ( dialog.exec() == QDialog::Accepted ) setColor(whichColor, kpColor(dialog.currentColor().rgba())); } }
void DualColorButton::mouseReleaseEvent(QMouseEvent *event) { if(event->button() != Qt::LeftButton) return; QRectF fgr = foregroundRect(); QRectF bgr = backgroundRect(); if(fgr.contains(event->pos())) emit foregroundClicked(foreground_); else if(bgr.contains(event->pos())) emit backgroundClicked(background_); else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top()) swapColors(); else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom()) { foreground_ = Qt::black; background_ = Qt::white; emit foregroundChanged(foreground_); emit backgroundChanged(background_); update(); } }
void WhiteBoardColorChooser::mouseReleaseEvent(QMouseEvent *e) { // qDebug() << "epos:"<< e->pos(); // qDebug() << "foregroundrect" << foregroundRect(); // qDebug() << "backgroundrect" << backgroundRect(); // qDebug() << "swap" << swapPixmapRect(); ColorLayer whichColor = None; if (foregroundRect().contains(e->pos())) { whichColor = ForegroundColor; qDebug() << "> in foreground"; } else if (backgroundRect().contains(e->pos())) { whichColor = BackgroundColor; qDebug() << "> in background"; } else if (swapPixmapRect().contains(e->pos())) { qDebug() << "> in swap"; QColor oldFore = m_foregroundColor; m_foregroundColor = m_backgroundColor; m_backgroundColor = oldFore; emit colorsSwapped(m_foregroundColor, m_backgroundColor); update(); return; } if (whichColor == ForegroundColor || whichColor == BackgroundColor) { QColor col = color(whichColor); if (QColorDialog::getColor(col, this) == QColorDialog::Accepted) { setColor(whichColor, col); update(); } } }
void CCScrollbarLayerImpl::appendQuads(CCQuadCuller& quadList, const CCSharedQuadState* sharedQuadState, bool&) { ScrollbarThemeComposite* theme = static_cast<ScrollbarThemeComposite*>(ScrollbarTheme::theme()); if (!theme) return; bool premultipledAlpha = false; FloatRect uvRect(0, 0, 1, 1); bool flipped = false; IntRect thumbRect = theme->thumbRect(&m_scrollbar); thumbRect.move(-m_scrollbar.x(), -m_scrollbar.y()); if (m_thumbTextureId && theme->hasThumb(&m_scrollbar) && !thumbRect.isEmpty()) { OwnPtr<CCTextureDrawQuad> quad = CCTextureDrawQuad::create(sharedQuadState, thumbRect, m_thumbTextureId, premultipledAlpha, uvRect, flipped); quad->setNeedsBlending(); quadList.append(quad.release()); } if (!m_backgroundTextureId) return; IntRect backgroundRect(IntPoint(), contentBounds()); quadList.append(CCTextureDrawQuad::create(sharedQuadState, backgroundRect, m_backgroundTextureId, premultipledAlpha, uvRect, flipped)); }
// protected virtual [base QWidget] void kpDualColorButton::paintEvent (QPaintEvent *e) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "kpDualColorButton::draw() rect=" << rect () << " contentsRect=" << contentsRect () << endl; #endif // Draw frame first. QFrame::paintEvent (e); QPainter painter (this); // Fill with background. if (isEnabled ()) { kpView::drawTransparentBackground (&painter, contentsRect ().topLeft ()/*checkerboard top-left*/, contentsRect (), true/*preview*/); } else { // Use default widget background. } painter.translate (contentsRect ().x (), contentsRect ().y ()); // Draw "Swap Colours" button (top-right). QPixmap swapPixmap = UserIcon ("colorbutton_swap_16x16"); if (!isEnabled ()) { // Don't let the fill() touch the mask. QBitmap swapBitmapMask = swapPixmap.mask (); swapPixmap.setMask (QBitmap ()); // Grey out the opaque parts of "swapPixmap". swapPixmap.fill (palette ().color (QPalette::Dark)); swapPixmap.setMask (swapBitmapMask); } painter.drawPixmap (swapPixmapRect ().topLeft (), swapPixmap); // Draw background colour patch. QRect bgRect = backgroundRect (); QRect bgRectInside = QRect (bgRect.x () + 2, bgRect.y () + 2, bgRect.width () - 4, bgRect.height () - 4); if (isEnabled ()) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "\tbackgroundColor=" << (int *) m_color [1].toQRgb () << endl; #endif if (m_color [1].isTransparent ()) // only if fully transparent painter.drawPixmap (bgRectInside, UserIcon ("color_transparent_26x26")); else painter.fillRect (bgRectInside, m_color [1].toQColor ()); } else painter.fillRect (bgRectInside, palette().color (QPalette::Button)); qDrawShadePanel (&painter, bgRect, palette(), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); // Draw foreground colour patch. // Must be drawn after background patch since we're on top. QRect fgRect = foregroundRect (); QRect fgRectInside = QRect (fgRect.x () + 2, fgRect.y () + 2, fgRect.width () - 4, fgRect.height () - 4); if (isEnabled ()) { #if DEBUG_KP_DUAL_COLOR_BUTTON && 1 qCDebug(kpLogWidgets) << "\tforegroundColor=" << (int *) m_color [0].toQRgb () << endl; #endif if (m_color [0].isTransparent ()) // only if fully transparent painter.drawPixmap (fgRectInside, UserIcon ("color_transparent_26x26")); else painter.fillRect (fgRectInside, m_color [0].toQColor ()); } else painter.fillRect (fgRectInside, palette ().color (QPalette::Button)); qDrawShadePanel (&painter, fgRect, palette (), false/*not sunken*/, 2/*lineWidth*/, 0/*never fill*/); }
int main() { //Create window, and limit frame rate sf::RenderWindow window (sf::VideoMode(800, 600, 32), "Game", sf::Style::Default); window.setFramerateLimit(60); //------------------------TEXTURES------------------------------ //Declare textures sf::Texture texture; sf::Texture texture1; sf::Texture texture2; //Load image if(!texture.loadFromFile("Sprites/main.png")) { return 1; } if(!texture1.loadFromFile("Sprites/background.png")) { return 1; } if(!texture2.loadFromFile("Sprites/house.png")) { return 1; } //------------------------SPRITES-------------------------- //Creates and places the sprites sf::Sprite sprite; sf::Sprite background; sf::Sprite house; sprite.setPosition(400, 300); background.setPosition(0, 0); house.setPosition(440, 300); //Loads texture into sprite sprite.setTexture(texture); background.setTexture(texture1); house.setTexture(texture2); //-------------------------RECTANGLES-------------------------------- //Declares the rectangles sf::IntRect front(1, 1, 18, 24); sf::IntRect back (20, 1, 18, 24); sf::IntRect left (20, 26, 18, 24); sf::IntRect right (1, 26, 18, 24); //Steps sf::IntRect frontLeft(39, 1, 18, 24); sf::IntRect frontRight(39, 26, 18, 24); sf::IntRect backLeft(); sf::IntRect backRight(); sf::IntRect leftLeft(); sf::IntRect leftRight(); sf::IntRect rightLeft(); sf::IntRect rightRight(); sf::IntRect backgroundRect (0, 0, 800, 600); sf::IntRect houseRect (0, 0, 17, 22); //Crop sprites using rectangles defined above sprite.setTextureRect(front); background.setTextureRect(backgroundRect); house.setTextureRect(houseRect); //-----------------------SOUND------------------------------------------------------ //Declare the Sound Buffer sf::SoundBuffer footstepsBuffer; sf::SoundBuffer bumpBuffer; //Loads the sound file if(!footstepsBuffer.loadFromFile("Sounds/footsteps.wav")) { return 1; } if(!bumpBuffer.loadFromFile("Sounds/bump.wav")) { return 1; } //Declare sound sf::Sound footsteps; sf::Sound bump; //Load Buffer into Sound footsteps.setBuffer(footstepsBuffer); bump.setBuffer(bumpBuffer); //-------------------------------MAIN----------------------------- //Main window loop while(window.isOpen()) { sf::Event event; //Vectors used for collision sf::Vector2i spritePosition(sprite.getPosition()); sf::Vector2i backgroundPosition(background.getPosition()); sf::Vector2i housePosition(house.getPosition()); //Sprite Vectors sf::Vector2i backVector(back.width, back.height); sf::Vector2i frontVector(front.width, front.height); sf::Vector2i rightVector(right.width, right.height); sf::Vector2i leftVector(left.width, left.height); //House Vectors sf::Vector2i houseVector(houseRect.width, houseRect.height); while(window.pollEvent(event)) { if(event.type == sf::Event::Closed) { window.close(); } if(event.key.code == sf::Keyboard::Insert) { sf::Image screenshot = window.capture(); screenshot.saveToFile("Screenshot.png"); } } //-----------------------------------MOVEMENT---------------------------------------- if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { //Change to stepping sprite Sleep(250); sprite.setTextureRect(back); sprite.move(0, -24); //Redeclaring the collision textures sf::Vector2i spritePosition(sprite.getPosition()); sf::Vector2i housePosition(house.getPosition()); if(collision(spritePosition, backVector, housePosition, houseVector) == true) { sprite.move(0, 24); bump.play(); } else { footsteps.play(); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { //Change to stepping sprite Sleep(250); sprite.setTextureRect(front); sprite.move(0, 24); //Redeclaring the collision textures sf::Vector2i spritePosition(sprite.getPosition()); sf::Vector2i housePosition(house.getPosition()); if(collision(spritePosition, frontVector, housePosition, houseVector) == true) { sprite.move(0, -24); bump.play(); } else { footsteps.play(); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { //Change to stepping sprite Sleep(250); sprite.setTextureRect(right); sprite.move(19, 0); //Redeclaring the collision textures sf::Vector2i spritePosition(sprite.getPosition()); sf::Vector2i housePosition(house.getPosition()); if(collision(spritePosition, leftVector, housePosition, houseVector) == true) { sprite.move(-19, 0); bump.play(); } else { footsteps.play(); } } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { //Change to stepping sprite Sleep(250); sprite.setTextureRect(left); sprite.move(-19, 0); //Redeclaring the collision textures sf::Vector2i spritePosition(sprite.getPosition()); sf::Vector2i housePosition(house.getPosition()); if(collision(spritePosition, rightVector, housePosition, houseVector) == true) { sprite.move(19, 0); bump.play(); } else { footsteps.play(); } } //Draw sequence window.clear(); //(Red, Green, Blue, (optional) Alpha) Alpha is transperency //Draw.... window.draw(background); window.draw(house); window.draw(sprite); window.display(); std::cout << x << std::endl; std::cout << y << std::endl; } return 0; }
bool WaterMark::toolOperations() { if (!loadToDImg()) { return false; } QString fileName = settings()[QLatin1String("Watermark image")].toString(); int placement = settings()[QLatin1String("Placement")].toInt(); int size = settings()[QLatin1String("Watermark size")].toInt(); int xMargin = settings()[QLatin1String("X margin")].toInt(); int yMargin = settings()[QLatin1String("Y margin")].toInt(); bool useImage = settings()[QLatin1String("Use image")].toBool(); QString text = settings()[QLatin1String("Text")].toString(); QFont font = settings()[QLatin1String("Font")].toString(); QColor fontColor = settings()[QLatin1String("Color")].toString(); int textOpacity = settings()[QLatin1String("Text opacity")].toInt(); bool useBackground = settings()[QLatin1String("Use background")].toBool(); QColor backgroundColor = settings()[QLatin1String("Background color")].toString(); int backgroundOpacity = settings()[QLatin1String("Background opacity")].toInt(); DImg watermarkImage; DColorComposer* composer = DColorComposer::getComposer(DColorComposer::PorterDuffNone); int marginW = lround(image().width() * (xMargin / 100.0)); int marginH = lround(image().height() * (yMargin / 100.0)); if (useImage) { watermarkImage = DImg(fileName); if (watermarkImage.isNull()) { return false; } DImg tempImage = watermarkImage.smoothScale(image().width() * size / 100, image().height() * size / 100, Qt::KeepAspectRatio); watermarkImage = tempImage; } else { int alignMode; const int radius = 10; if (text.isEmpty()) { return false; } int fontSize = queryFontSize(text, font, size); if (fontSize == 0) { return false; } switch (placement) { case Private::TopLeft: alignMode = Qt::AlignLeft; break; case Private::TopRight: alignMode = Qt::AlignRight; break; case Private::BottomLeft: alignMode = Qt::AlignLeft; break; case Private::Center: alignMode = Qt::AlignCenter; break; default : // BottomRight alignMode = Qt::AlignRight; break; } font.setPointSizeF(fontSize); QFontMetrics fontMt(font); QRect fontRect = fontMt.boundingRect(radius, radius, image().width(), image().height(), 0, text); // Add a transparent layer. QRect backgroundRect(fontRect.x() - radius, fontRect.y() - radius, fontRect.width() + 2 * radius, fontRect.height() + 2 * radius); DImg backgroundLayer(backgroundRect.width(), backgroundRect.height(), image().sixteenBit(), true); DColor transparent(QColor(0, 0, 0)); transparent.setAlpha(0); if (image().sixteenBit()) { transparent.convertToSixteenBit(); } backgroundLayer.fill(transparent); DImg grayTransLayer(fontRect.width(), fontRect.height(), image().sixteenBit(), true); if (useBackground) { DColor grayTrans(backgroundColor); grayTrans.setAlpha(backgroundOpacity * 255 / 100); if (image().sixteenBit()) { grayTrans.convertToSixteenBit(); } grayTransLayer.fill(grayTrans); backgroundLayer.bitBlendImage(composer, &grayTransLayer, 0, 0, grayTransLayer.width(), grayTransLayer.height(), radius, radius); } BlurFilter blur(&backgroundLayer, 0L, radius); blur.startFilterDirectly(); backgroundLayer.putImageData(blur.getTargetImage().bits()); // Draw text QImage img = backgroundLayer.copyQImage(fontRect); QPainter p(&img); fontColor.setAlpha(textOpacity * 255 / 100); p.setPen(QPen(fontColor, 1)); p.setFont(font); p.save(); p.drawText(0, 0, fontRect.width(), fontRect.height(), alignMode, text); p.restore(); p.end(); watermarkImage = DImg(img); } watermarkImage.convertToDepthOfImage(&image()); QRect watermarkRect(0, 0, watermarkImage.width(), watermarkImage.height()); switch (placement) { case Private::TopLeft: watermarkRect.moveTopLeft(QPoint(marginW, marginH)); break; case Private::TopRight: watermarkRect.moveTopRight(QPoint(image().width() - marginW, marginH)); break; case Private::BottomLeft: watermarkRect.moveBottomLeft(QPoint(marginW, image().height() - marginH)); break; case Private::Center: watermarkRect.moveCenter(QPoint((int)(image().width() / 2), (int)(image().height() / 2))); break; default : // BottomRight watermarkRect.moveBottomRight(QPoint(image().width() - marginW, image().height() - marginH)); break; } // TODO: Create watermark filter, move code there, implement FilterAction image().bitBlendImage(composer, &watermarkImage, 0, 0, watermarkImage.width(), watermarkImage.height(), watermarkRect.left(), watermarkRect.top()); delete composer; return (savefromDImg()); }
//----------------------------------------------------------------------------// void FrameComponent::render_impl(Window& srcWindow, Rectf& destRect, const CEGUI::ColourRect* modColours, const Rectf* clipper, bool clipToDisplay) const { Rectf backgroundRect(destRect); Rectf finalRect; Sizef imageSize; Vector2f imageOffsets; ColourRect imageColours; float leftfactor, rightfactor, topfactor, bottomfactor; bool calcColoursPerImage; // vars we use to track what to do with the side pieces. float topOffset = 0, bottomOffset = 0, leftOffset = 0, rightOffset = 0; float topWidth, bottomWidth, leftHeight, rightHeight; topWidth = bottomWidth = destRect.getWidth(); leftHeight = rightHeight = destRect.getHeight(); // calculate final overall colours to be used ColourRect finalColours; initColoursRect(srcWindow, modColours, finalColours); if (finalColours.isMonochromatic()) { calcColoursPerImage = false; imageColours = finalColours; } else { calcColoursPerImage = true; } // top-left image if (const Image* const componentImage = getImage(FIC_TOP_LEFT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.d_min = destRect.d_min; finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. topOffset += imageSize.d_width + imageOffsets.d_x; leftOffset += imageSize.d_height + imageOffsets.d_y; topWidth -= topOffset; leftHeight -= leftOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // top-right image if (const Image* const componentImage = getImage(FIC_TOP_RIGHT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.right() - imageSize.d_width); finalRect.top(destRect.top()); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. rightOffset += imageSize.d_height + imageOffsets.d_y; topWidth -= imageSize.d_width - imageOffsets.d_x; rightHeight -= rightOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // bottom-left image if (const Image* const componentImage = getImage(FIC_BOTTOM_LEFT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.left()); finalRect.top(destRect.bottom() - imageSize.d_height); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. bottomOffset += imageSize.d_width + imageOffsets.d_x; bottomWidth -= bottomOffset; leftHeight -= imageSize.d_height - imageOffsets.d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + imageOffsets.d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + imageOffsets.d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // bottom-right image if (const Image* const componentImage = getImage(FIC_BOTTOM_RIGHT_CORNER, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); imageOffsets = componentImage->getRenderedOffset(); finalRect.left(destRect.right() - imageSize.d_width); finalRect.top(destRect.bottom() - imageSize.d_height); finalRect.setSize(imageSize); finalRect = destRect.getIntersection(finalRect); // update adjustments required to edges do to presence of this element. bottomWidth -= imageSize.d_width - imageOffsets.d_x; rightHeight -= imageSize.d_height - imageOffsets.d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. componentImage->render(srcWindow.getGeometryBuffer(), finalRect, clipper, imageColours); } // top image if (const Image* const componentImage = getImage(FIC_TOP_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left() + topOffset); finalRect.right(finalRect.left() + topWidth); finalRect.top(destRect.top()); finalRect.bottom(finalRect.top() + imageSize.d_height); finalRect = destRect.getIntersection(finalRect); // adjust background area to miss this edge backgroundRect.d_min.d_y += imageSize.d_height + componentImage->getRenderedOffset().d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, VF_TOP_ALIGNED, d_topEdgeFormatting.get(srcWindow), finalRect, imageColours, clipper, clipToDisplay); } // bottom image if (const Image* const componentImage = getImage(FIC_BOTTOM_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left() + bottomOffset); finalRect.right(finalRect.left() + bottomWidth); finalRect.bottom(destRect.bottom()); finalRect.top(finalRect.bottom() - imageSize.d_height); finalRect = destRect.getIntersection (finalRect); // adjust background area to miss this edge backgroundRect.d_max.d_y -= imageSize.d_height - componentImage->getRenderedOffset().d_y; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle(leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, VF_BOTTOM_ALIGNED, d_bottomEdgeFormatting.get(srcWindow), finalRect, imageColours, clipper, clipToDisplay); } // left image if (const Image* const componentImage = getImage(FIC_LEFT_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.left(destRect.left()); finalRect.right(finalRect.left() + imageSize.d_width); finalRect.top(destRect.top() + leftOffset); finalRect.bottom(finalRect.top() + leftHeight); finalRect = destRect.getIntersection(finalRect); // adjust background area to miss this edge backgroundRect.d_min.d_x += imageSize.d_width + componentImage->getRenderedOffset().d_x; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, d_leftEdgeFormatting.get(srcWindow), HF_LEFT_ALIGNED, finalRect, imageColours, clipper, clipToDisplay); } // right image if (const Image* const componentImage = getImage(FIC_RIGHT_EDGE, srcWindow)) { // calculate final destination area imageSize = componentImage->getRenderedSize(); finalRect.top(destRect.top() + rightOffset); finalRect.bottom(finalRect.top() + rightHeight); finalRect.right(destRect.right()); finalRect.left(finalRect.right() - imageSize.d_width); finalRect = destRect.getIntersection (finalRect); // adjust background area to miss this edge backgroundRect.d_max.d_x -= imageSize.d_width - componentImage->getRenderedOffset().d_x; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. renderImage(srcWindow.getGeometryBuffer(), componentImage, d_rightEdgeFormatting.get(srcWindow), HF_RIGHT_ALIGNED, finalRect, imageColours, clipper, clipToDisplay); } if (const Image* const componentImage = getImage(FIC_BACKGROUND, srcWindow)) { // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (backgroundRect.left() + componentImage->getRenderedOffset().d_x) / destRect.getWidth(); rightfactor = leftfactor + backgroundRect.getWidth() / destRect.getWidth(); topfactor = (backgroundRect.top() + componentImage->getRenderedOffset().d_y) / destRect.getHeight(); bottomfactor = topfactor + backgroundRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } const HorizontalFormatting horzFormatting = d_backgroundHorzFormatting.get(srcWindow); const VerticalFormatting vertFormatting = d_backgroundVertFormatting.get(srcWindow); renderImage(srcWindow.getGeometryBuffer(), componentImage, vertFormatting, horzFormatting, backgroundRect, imageColours, clipper, clipToDisplay); } }
void KItemListHeaderWidget::paintRole(QPainter* painter, const QByteArray& role, const QRectF& rect, int orderIndex, QWidget* widget) const { // The following code is based on the code from QHeaderView::paintSection(). // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). QStyleOptionHeader option; option.section = orderIndex; option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal; if (isEnabled()) { option.state |= QStyle::State_Enabled; } if (window() && window()->isActiveWindow()) { option.state |= QStyle::State_Active; } if (m_hoveredRoleIndex == orderIndex) { option.state |= QStyle::State_MouseOver; } if (m_pressedRoleIndex == orderIndex) { option.state |= QStyle::State_Sunken; } if (m_model->sortRole() == role) { option.sortIndicator = (m_model->sortOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp; } option.rect = rect.toRect(); bool paintBackgroundForEmptyArea = false; if (m_columns.count() == 1) { option.position = QStyleOptionHeader::OnlyOneSection; } else if (orderIndex == 0) { option.position = QStyleOptionHeader::Beginning; } else if (orderIndex == m_columns.count() - 1) { // We are just painting the header for the last column. Check if there // is some empty space to the right which needs to be filled. if (rect.right() < size().width()) { option.position = QStyleOptionHeader::Middle; paintBackgroundForEmptyArea = true; } else { option.position = QStyleOptionHeader::End; } } else { option.position = QStyleOptionHeader::Middle; } option.orientation = Qt::Horizontal; option.selectedPosition = QStyleOptionHeader::NotAdjacent; option.text = m_model->roleDescription(role); style()->drawControl(QStyle::CE_Header, &option, painter, widget); if (paintBackgroundForEmptyArea) { option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal; option.section = m_columns.count(); option.sortIndicator = QStyleOptionHeader::None; qreal backgroundRectX = rect.x() + rect.width(); QRectF backgroundRect(backgroundRectX, 0.0, size().width() - backgroundRectX, rect.height()); option.rect = backgroundRect.toRect(); option.position = QStyleOptionHeader::End; option.text = QString(); style()->drawControl(QStyle::CE_Header, &option, painter, widget); } }
void FrameComponent::render_impl(Window& srcWindow, Rect& destRect, float base_z, const CEGUI::ColourRect* modColours, const Rect* clipper, bool clipToDisplay) const { Rect backgroundRect(destRect); Rect finalRect; Size imageSize; ColourRect imageColours; float leftfactor, rightfactor, topfactor, bottomfactor; bool calcColoursPerImage; // vars we use to track what to do with the side pieces. float topOffset = 0, bottomOffset = 0, leftOffset = 0, rightOffset = 0; float topWidth, bottomWidth, leftHeight, rightHeight; topWidth = bottomWidth = destRect.getWidth(); leftHeight = rightHeight = destRect.getHeight(); // calculate final overall colours to be used ColourRect finalColours; initColoursRect(srcWindow, modColours, finalColours); if (finalColours.isMonochromatic()) { calcColoursPerImage = false; imageColours = finalColours; } else { calcColoursPerImage = true; } // top-left image if (d_frameImages[FIC_TOP_LEFT_CORNER]) { // calculate final destination area imageSize = d_frameImages[FIC_TOP_LEFT_CORNER]->getSize(); finalRect.d_left = destRect.d_left; finalRect.d_top = destRect.d_top; finalRect.setSize(imageSize); // update adjustments required to edges do to presence of this element. topOffset += imageSize.d_width; leftOffset += imageSize.d_height; topWidth -= topOffset; leftHeight -= leftOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_TOP_LEFT_CORNER]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_TOP_LEFT_CORNER]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_TOP_LEFT_CORNER], finalRect, base_z, imageColours, 0, clipToDisplay); } // top-right image if (d_frameImages[FIC_TOP_RIGHT_CORNER]) { // calculate final destination area imageSize = d_frameImages[FIC_TOP_RIGHT_CORNER]->getSize(); finalRect.d_left = destRect.d_right - imageSize.d_width; finalRect.d_top = destRect.d_top; finalRect.setSize(imageSize); // update adjustments required to edges do to presence of this element. rightOffset += imageSize.d_height; topWidth -= imageSize.d_width; rightHeight -= rightOffset; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_TOP_RIGHT_CORNER]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_TOP_RIGHT_CORNER]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_TOP_RIGHT_CORNER], finalRect, base_z, imageColours, 0, clipToDisplay); } // bottom-left image if (d_frameImages[FIC_BOTTOM_LEFT_CORNER]) { // calculate final destination area imageSize = d_frameImages[FIC_BOTTOM_LEFT_CORNER]->getSize(); finalRect.d_left = destRect.d_left; finalRect.d_top = destRect.d_bottom - imageSize.d_height; finalRect.setSize(imageSize); // update adjustments required to edges do to presence of this element. bottomOffset += imageSize.d_width; bottomWidth -= bottomOffset; leftHeight -= imageSize.d_height; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_BOTTOM_LEFT_CORNER]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_BOTTOM_LEFT_CORNER]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_BOTTOM_LEFT_CORNER], finalRect, base_z, imageColours, 0, clipToDisplay); } // bottom-right image if (d_frameImages[FIC_BOTTOM_RIGHT_CORNER]) { // calculate final destination area imageSize = d_frameImages[FIC_BOTTOM_RIGHT_CORNER]->getSize(); finalRect.d_left = destRect.d_right - imageSize.d_width; finalRect.d_top = destRect.d_bottom - imageSize.d_height; finalRect.setSize(imageSize); // update adjustments required to edges do to presence of this element. bottomWidth -= imageSize.d_width; rightHeight -= imageSize.d_height; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_BOTTOM_RIGHT_CORNER]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_BOTTOM_RIGHT_CORNER]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_BOTTOM_RIGHT_CORNER], finalRect, base_z, imageColours, 0, clipToDisplay); } // top image if (d_frameImages[FIC_TOP_EDGE]) { // calculate final destination area imageSize = d_frameImages[FIC_TOP_EDGE]->getSize(); finalRect.d_left = destRect.d_left + topOffset; finalRect.d_right = finalRect.d_left + topWidth; finalRect.d_top = destRect.d_top; finalRect.d_bottom = finalRect.d_top + imageSize.d_height; // adjust background area to miss this edge backgroundRect.d_top += imageSize.d_height + d_frameImages[FIC_TOP_EDGE]->getOffsetY();; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_TOP_EDGE]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_TOP_EDGE]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_TOP_EDGE], finalRect, base_z, imageColours, 0, clipToDisplay); } // bottom image if (d_frameImages[FIC_BOTTOM_EDGE]) { // calculate final destination area imageSize = d_frameImages[FIC_BOTTOM_EDGE]->getSize(); finalRect.d_left = destRect.d_left + bottomOffset; finalRect.d_right = finalRect.d_left + bottomWidth; finalRect.d_bottom = destRect.d_bottom; finalRect.d_top = finalRect.d_bottom - imageSize.d_height; // adjust background area to miss this edge backgroundRect.d_bottom -= imageSize.d_height - d_frameImages[FIC_BOTTOM_EDGE]->getOffsetY();; // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_BOTTOM_EDGE]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_BOTTOM_EDGE]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_BOTTOM_EDGE], finalRect, base_z, imageColours, 0, clipToDisplay); } // left image if (d_frameImages[FIC_LEFT_EDGE]) { // calculate final destination area imageSize = d_frameImages[FIC_LEFT_EDGE]->getSize(); finalRect.d_left = destRect.d_left; finalRect.d_right = finalRect.d_left + imageSize.d_width; finalRect.d_top = destRect.d_top + leftOffset; finalRect.d_bottom = finalRect.d_top + leftHeight; // adjust background area to miss this edge backgroundRect.d_left += imageSize.d_width + d_frameImages[FIC_LEFT_EDGE]->getOffsetX(); // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_LEFT_EDGE]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_LEFT_EDGE]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_LEFT_EDGE], finalRect, base_z, imageColours, 0, clipToDisplay); } // right image if (d_frameImages[FIC_RIGHT_EDGE]) { // calculate final destination area imageSize = d_frameImages[FIC_RIGHT_EDGE]->getSize(); finalRect.d_top = destRect.d_top + rightOffset; finalRect.d_bottom = finalRect.d_top + rightHeight; finalRect.d_right = destRect.d_right; finalRect.d_left = finalRect.d_right - imageSize.d_width; // adjust background area to miss this edge backgroundRect.d_right -= imageSize.d_width - d_frameImages[FIC_RIGHT_EDGE]->getOffsetX(); // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (finalRect.d_left + d_frameImages[FIC_RIGHT_EDGE]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + finalRect.getWidth() / destRect.getWidth(); topfactor = (finalRect.d_top + d_frameImages[FIC_RIGHT_EDGE]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + finalRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // draw this element. srcWindow.getRenderCache().cacheImage(*d_frameImages[FIC_RIGHT_EDGE], finalRect, base_z, imageColours, 0, clipToDisplay); } if (d_frameImages[FIC_BACKGROUND]) { // calculate colours that are to be used to this component image if (calcColoursPerImage) { leftfactor = (backgroundRect.d_left + d_frameImages[FIC_BACKGROUND]->getOffsetX()) / destRect.getWidth(); rightfactor = leftfactor + backgroundRect.getWidth() / destRect.getWidth(); topfactor = (backgroundRect.d_top + d_frameImages[FIC_BACKGROUND]->getOffsetY()) / destRect.getHeight(); bottomfactor = topfactor + backgroundRect.getHeight() / destRect.getHeight(); imageColours = finalColours.getSubRectangle( leftfactor, rightfactor, topfactor, bottomfactor); } // render background image. doBackgroundRender(srcWindow, backgroundRect, base_z, imageColours, clipper, clipToDisplay); } }
void QgsComposerTableV2::render( QPainter *p, const QRectF &, const int frameIndex ) { if ( !p ) { return; } bool emptyTable = mTableContents.length() == 0; if ( emptyTable && mEmptyTableMode == QgsComposerTableV2::HideTable ) { //empty table set to hide table mode, so don't draw anything return; } if ( mComposition->plotStyle() == QgsComposition::Print || mComposition->plotStyle() == QgsComposition::Postscript ) { //exporting composition, so force an attribute refresh //we do this in case vector layer has changed via an external source (eg, another database user) refreshAttributes(); } //calculate which rows to show in this frame QPair< int, int > rowsToShow = rowRange( frameIndex ); double gridSize = mShowGrid ? mGridStrokeWidth : 0; double cellHeaderHeight = QgsComposerUtils::fontAscentMM( mHeaderFont ) + 2 * mCellMargin; double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mCellMargin; QRectF cell; //calculate whether a header is required bool drawHeader = (( mHeaderMode == QgsComposerTableV2::FirstFrame && frameIndex < 1 ) || ( mHeaderMode == QgsComposerTableV2::AllFrames ) ); //calculate whether drawing table contents is required bool drawContents = !( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage ); int numberRowsToDraw = rowsToShow.second - rowsToShow.first; int numberEmptyRows = 0; if ( drawContents && mShowEmptyRows ) { numberRowsToDraw = rowsVisible( frameIndex, rowsToShow.first, true ); numberEmptyRows = numberRowsToDraw - rowsToShow.second + rowsToShow.first; } bool mergeCells = false; if ( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage ) { //draw a merged row for the empty table message numberRowsToDraw++; rowsToShow.second++; mergeCells = true; } p->save(); //antialiasing on p->setRenderHint( QPainter::Antialiasing, true ); //draw table background if ( mBackgroundColor.alpha() > 0 ) { p->save(); p->setPen( Qt::NoPen ); p->setBrush( QBrush( mBackgroundColor ) ); double totalHeight = ( drawHeader || ( numberRowsToDraw > 0 ) ? gridSize : 0 ) + ( drawHeader ? cellHeaderHeight + gridSize : 0.0 ); if ( drawContents ) { for ( int row = rowsToShow.first; row < rowsToShow.second; ++row ) { totalHeight += mMaxRowHeightMap[ row + 1 ] + 2 * mCellMargin + gridSize; } if ( numberEmptyRows > 0 ) { //draw empty rows totalHeight += ( cellBodyHeight + gridSize ) * numberEmptyRows; } } else { totalHeight += cellBodyHeight + gridSize; } if ( totalHeight > 0 ) { QRectF backgroundRect( 0, 0, mTableSize.width(), totalHeight ); p->drawRect( backgroundRect ); } p->restore(); } //now draw the text p->setPen( Qt::SolidLine ); double currentX = gridSize; double currentY = gridSize; if ( drawHeader ) { //draw the headers int col = 0; for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt ) { currentX += mCellMargin; Qt::TextFlag textFlag = ( Qt::TextFlag )0; if (( *columnIt )->width() <= 0 ) { //automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text //which may slightly exceed the calculated width //if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width textFlag = Qt::TextDontClip; } cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight ); //calculate alignment of header Qt::AlignmentFlag headerAlign = Qt::AlignLeft; switch ( mHeaderHAlignment ) { case FollowColumn: headerAlign = ( *columnIt )->hAlignment(); break; case HeaderLeft: headerAlign = Qt::AlignLeft; break; case HeaderCenter: headerAlign = Qt::AlignHCenter; break; case HeaderRight: headerAlign = Qt::AlignRight; break; } QgsComposerUtils::drawText( p, cell, ( *columnIt )->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, textFlag ); currentX += mMaxColumnWidthMap[ col ]; currentX += mCellMargin; currentX += gridSize; col++; } currentY += cellHeaderHeight; currentY += gridSize; } //now draw the body cells if ( drawContents ) { //draw the attribute values for ( int row = rowsToShow.first; row < rowsToShow.second; ++row ) { currentX = gridSize; int col = 0; //calculate row height double rowHeight = mMaxRowHeightMap[row + 1] + 2 * mCellMargin; for ( QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin(); columnIt != mColumns.constEnd(); ++columnIt ) { // currentY = gridSize; currentX += mCellMargin; QVariant cellContents = mTableContents.at( row ).at( col ); QString str = cellContents.toString(); Qt::TextFlag textFlag = ( Qt::TextFlag )0; if (( *columnIt )->width() <= 0 && mWrapBehaviour == TruncateText ) { //automatic column width, so we use the Qt::TextDontClip flag when drawing contents, as this works nicer for italicised text //which may slightly exceed the calculated width //if column size was manually set then we do apply text clipping, to avoid painting text outside of columns width textFlag = Qt::TextDontClip; } else if ( textRequiresWrapping( str, ( *columnIt )->width(), mContentFont ) ) { str = wrappedText( str, ( *columnIt )->width(), mContentFont ); } cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], rowHeight ); QgsComposerUtils::drawText( p, cell, str, mContentFont, mContentFontColor, ( *columnIt )->hAlignment(), ( *columnIt )->vAlignment(), textFlag ); currentX += mMaxColumnWidthMap[ col ]; currentX += mCellMargin; currentX += gridSize; col++; } currentY += rowHeight; currentY += gridSize; } } //and the borders if ( mShowGrid ) { QPen gridPen; gridPen.setWidthF( mGridStrokeWidth ); gridPen.setColor( mGridColor ); gridPen.setJoinStyle( Qt::MiterJoin ); p->setPen( gridPen ); drawHorizontalGridLines( p, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader ); drawVerticalGridLines( p, mMaxColumnWidthMap, rowsToShow.first, rowsToShow.second + numberEmptyRows, drawHeader, mergeCells ); } //special case - no records and table is set to ShowMessage mode if ( emptyTable && mEmptyTableMode == QgsComposerTableV2::ShowMessage ) { double messageX = gridSize + mCellMargin; double messageY = gridSize + ( drawHeader ? cellHeaderHeight + gridSize : 0 ); cell = QRectF( messageX, messageY, mTableSize.width() - messageX, cellBodyHeight ); QgsComposerUtils::drawText( p, cell, mEmptyTableMessage, mContentFont, mContentFontColor, Qt::AlignHCenter, Qt::AlignVCenter, ( Qt::TextFlag )0 ); } p->restore(); }