void MultiLayer::exportToEPS(const QString& fname, int res, QPrinter::Orientation o, QPrinter::PageSize pageSize, QPrinter::ColorMode col) { QPrinter printer; printer.setResolution(res); printer.setPageSize(pageSize); printer.setColorMode(col); printer.setOrientation(o); printer.setFullPage(TRUE); printer.setOutputToFile (TRUE); printer.setOutputFileName(fname); QPainter paint(&printer); QPaintDeviceMetrics pdmTo(&printer); int dpiy = pdmTo.logicalDpiY(); int margin = (int) ( (0.5/2.54)*dpiy ); // 5 mm margins QSize size = canvas->size(); double scaleFactorX=(double)(pdmTo.width() - 2*margin)/(double)size.width(); double scaleFactorY=(double)(pdmTo.height() - 2*margin)/(double)size.height(); for (int i=0;i<(int)graphsList->count();i++) { Graph *gr=(Graph *)graphsList->at(i); Plot *myPlot= (Plot *)gr->plotWidget(); PrintFilter filter(myPlot); filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintCanvasBackground); QPoint pos=gr->pos(); pos=QPoint(int(margin + pos.x()*scaleFactorX),int(margin + pos.y()*scaleFactorY)); int width=int(myPlot->frameGeometry().width()*scaleFactorX); int height=int(myPlot->frameGeometry().height()*scaleFactorY); QRect rect = QRect(pos,QSize(width,height)); if (myPlot->paletteBackgroundColor() != QColor(white)) paint.fillRect(rect, myPlot->paletteBackgroundColor()); int lw = myPlot->lineWidth(); if ( lw > 0) { myPlot->printFrame(&paint, rect); rect.moveBy ( lw, lw); rect.setWidth(rect.width() - 2*lw); rect.setHeight(rect.height() - 2*lw); } myPlot->print(&paint, rect, filter); } if (hasOverlapingLayers()) updateTransparency(); }
void Container::drawCopiedWidgetRect(QMouseEvent *mev) { // We've been dragging a widget, but Ctrl was hold, so we start copy if(m_state == MovingWidget) { //FormManager::self()->undo(); // undo last moving //m_moving->move(m_initialPos); if(m_form->formWidget()) { m_container->repaint(); m_form->formWidget()->initBuffer(); } m_state = CopyingWidget; } //m_copyRect.moveTopLeft(m_container->mapFromGlobal( mev->globalPos()) - m_grab); if(m_form->formWidget()) { QValueList<QRect> rectList; for(QWidget *w = m_form->selectedWidgets()->first(); w; w = m_form->selectedWidgets()->next()) { QRect drawRect = w->geometry(); QPoint p = mev->pos() - m_grab; drawRect.moveBy(p.x(), p.y()); p = m_container->mapTo(m_form->widget(), QPoint(0, 0)); //drawRect = QRect( ((QWidget*)s)->mapTo(m_form->widget(), drawRect.topLeft()), drawRect.size()); drawRect.moveBy(p.x(), p.y()); rectList.append(drawRect); } m_form->formWidget()->drawRects(rectList, 2); } }
void UIListTreeType::CreateLevel(int level) { if (level > levels) { int oldlevels = levels + 1; levels = level; for (int i = oldlevels; i <= levels; i++) { QString levelname = QString("level%1").arg(i + 1); QRect curlevelarea = m_levelsize; curlevelarea.moveBy(m_totalarea.x(), m_totalarea.y()); curlevelarea.moveBy((m_levelsize.width() + m_levelspacing) * i, 0); UIListBtnType *newlevel = new UIListBtnType(levelname, curlevelarea, m_order, false, true); newlevel->SetFontActive(m_active); newlevel->SetFontInactive(m_inactive); newlevel->SetItemRegColor(m_itemRegBeg, m_itemRegEnd, m_itemRegAlpha); newlevel->SetItemSelColor(m_itemSelBeg, m_itemSelEnd, m_itemSelAlpha); newlevel->SetSpacing(m_spacing); newlevel->SetMargin(m_margin); newlevel->SetParentListTree(this); listLevels.append(newlevel); } } }
void UIListTreeType::RedrawCurrent(void) { if (!currentlevel) { return; } QRect dr = currentlevel->GetArea(); dr.moveBy(currentlevel->GetDrawOffset(), 0); dr.moveBy(m_parent->GetAreaRect().x(), m_parent->GetAreaRect().y()); emit requestRegionUpdate(dr); }
void UIListBtnType::calculateScreenArea() { QRect r = m_rect; r.moveBy(m_parent->GetAreaRect().left(), m_parent->GetAreaRect().top()); screen_area = r; }
void PrettyPopupMenu::paintEvent( QPaintEvent* e ) { generateSidePixmap(); QPainter p( this ); QRect r = sideImageRect(); r.setTop( r.bottom() - s_sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { QRect drawRect = r.intersect( e->rect() ).intersect( sideImageRect() ); QRect pixRect = drawRect; pixRect.moveBy( -r.left(), -r.top() ); p.drawImage( drawRect.topLeft(), s_sidePixmap, pixRect ); } p.setClipRegion( e->region() ); //NOTE The order is important here. drawContents() must be called before drawPrimitive(), // otherwise we get rendering glitches. drawContents( &p ); style().drawPrimitive( QStyle::PE_PanelPopup, &p, QRect( 0, 0, width(), height() ), colorGroup(), QStyle::Style_Default, QStyleOption( frameWidth(), 0 ) ); }
void Plotter::mouseReleaseEvent(QMouseEvent *event) { if (event->button() == LeftButton) { rubberBandIsShown = false; updateRubberBandRegion(); unsetCursor(); QRect rect = rubberBandRect.normalize(); if (rect.width() < 4 || rect.height() < 4) return; rect.moveBy(-Margin, -Margin); PlotSettings prevSettings = zoomStack[curZoom]; PlotSettings settings; double dx = prevSettings.spanX() / (width() - 2 * Margin); double dy = prevSettings.spanY() / (height() - 2 * Margin); settings.minX = prevSettings.minX + dx * rect.left(); settings.maxX = prevSettings.minX + dx * rect.right(); settings.minY = prevSettings.maxY - dy * rect.bottom(); settings.maxY = prevSettings.maxY - dy * rect.top(); settings.adjust(); zoomStack.resize(curZoom + 1); zoomStack.push_back(settings); zoomIn(); } }
void KdmRect::drawContents( QPainter *p, const QRect &r ) { // choose the correct rect class RectStruct::RectClass *rClass = &rect.normal; if (state == Sactive && rect.active.present) rClass = &rect.active; if (state == Sprelight && rect.prelight.present) rClass = &rect.prelight; if (rClass->alpha <= 0 || !rClass->color.isValid()) return; if (rClass->alpha == 1) p->fillRect( area, QBrush( rClass->color ) ); else { QRect backRect = r; backRect.moveBy( area.x(), area.y() ); QPixmap backPixmap( backRect.size() ); bitBlt( &backPixmap, QPoint( 0, 0 ), p->device(), backRect ); QImage backImage = backPixmap.convertToImage(); KImageEffect::blend( rClass->color, backImage, rClass->alpha ); p->drawImage( backRect.x(), backRect.y(), backImage ); // area.moveBy(1,1); } }
void Kanagram::drawText(QPainter &p, const QString &text, const QPoint ¢er, bool withMargin, int xMargin, int yMargin, QRect *rect, bool highlight, int fontSize) { QRect r; QFont font = m_blackboardFont; font.setPointSize(fontSize); font.setBold(true); p.setFont(font); r = p.boundingRect(QRect(), Qt::AlignAuto, text); r = QRect(0, 0, r.width() + xMargin, r.height() + yMargin); r.moveBy(center.x() - r.width() / 2, center.y() - r.height() / 2); if (withMargin) { p.fillRect(r, m_fillColor); p.setPen(QPen(black, 3)); p.drawRoundRect(r.left(), r.top(), r.width(), r.height(), 15, 15); } if (!highlight) p.setPen(m_chalkColor); else p.setPen(m_chalkHighlightColor); p.drawText(r, Qt::AlignCenter, text); if(rect) *rect = r; }
/*! \return the bounding rect for the label */ QRect QwtArrowButton::labelRect() const { const int m = Margin; QRect r = rect(); r.setRect(r.x() + m, r.y() + m, r.width() - 2 * m, r.height() - 2 * m); if ( isDown() ) { int ph, pv; #if QT_VERSION < 0x040000 ph = style().pixelMetric( QStyle::PM_ButtonShiftHorizontal, this); pv = style().pixelMetric( QStyle::PM_ButtonShiftVertical, this); r.moveBy(ph, pv); #else QStyleOptionButton option = styleOpt(this); ph = style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal, &option, this); pv = style()->pixelMetric( QStyle::PM_ButtonShiftVertical, &option, this); r.translate(ph, pv); #endif } return r; }
void Kanagram::drawSwitcher(QPainter &p, const int xMargin, const int yMargin) { const int padding = 5; QString text = m_game->getDocTitle(); QFont font = m_blackboardFont; font.setPointSize(14); QFontMetrics fm(font); QRect r = innerRect(m_blackboardRect, xMargin, yMargin); r.normalize(); r.moveBy(- padding - (m_overSwitcher ? m_arrowOver : m_arrow )->width(), yMargin); r.setHeight( (m_overSwitcher ? m_arrowOver : m_arrow )->height()); m_switcherRect = p.boundingRect(r, Qt::AlignVCenter|Qt::AlignRight, text); p.setFont(font); if (m_overSwitcher) { p.setPen(m_chalkHighlightColor); p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrowOver); } else { p.setPen(m_chalkColor); p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrow); } m_switcherRect.moveBy(0, -2); p.drawText(m_switcherRect, Qt::AlignVCenter|Qt::AlignRight, text); }
void PanelKMenu::paintEvent(QPaintEvent * e) { if (sidePixmap.isNull()) { PanelServiceMenu::paintEvent(e); return; } QPainter p(this); p.setClipRegion(e->region()); style().drawPrimitive( QStyle::PE_PanelPopup, &p, QRect( 0, 0, width(), height() ), colorGroup(), QStyle::Style_Default, QStyleOption( frameWidth(), 0 ) ); QRect r = sideImageRect(); r.setBottom( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { p.drawTiledPixmap( r, sideTilePixmap ); } r = sideImageRect(); r.setTop( r.bottom() - sidePixmap.height() ); if ( r.intersects( e->rect() ) ) { QRect drawRect = r.intersect( e->rect() ); QRect pixRect = drawRect; pixRect.moveBy( -r.left(), -r.top() ); p.drawPixmap( drawRect.topLeft(), sidePixmap, pixRect ); } drawContents( &p ); }
/** Repaint custom item upon system notification */ void CustomItem::paintEvent(QPaintEvent *e) { #if REPORT_LEVEL <= LOG_INFORMATION QRect r(e->rect()); reportToLog(LOG_INFORMATION, LC_HIGHUI, "CustomItem::paintEvent (%d,%d,%d,%d)\n", r.left(), r.top(), r.right(), r.bottom()); #endif Item::paintEvent(e); if (hasFocus()) { QPainter painter(this); QRect focusRect = drawable->geometry(); // focusRect.setWidth(focusRect.width() + 3); // focusRect.setHeight(focusRect.height() + 3); focusRect.moveBy(-2, -2); focusRect.rRight() += 4; focusRect.rBottom() += 4; style().drawFocusRect(&painter, focusRect, colorGroup()); } }
void KNoteTip::reposition() { if(!mNoteIVI) return; QRect rect = mNoteIVI->rect(); QPoint off = mView->mapToGlobal(mView->contentsToViewport(QPoint(0, 0))); rect.moveBy(off.x(), off.y()); QPoint pos = rect.center(); // should the tooltip be shown to the left or to the right of the ivi? QRect desk = KGlobalSettings::desktopGeometry(pos); if(rect.center().x() + width() > desk.right()) { // to the left if(pos.x() - width() < 0) pos.setX(0); else pos.setX(pos.x() - width()); } // should the tooltip be shown above or below the ivi ? if(rect.bottom() + height() > desk.bottom()) { // above pos.setY(rect.top() - height()); } else pos.setY(rect.bottom()); move(pos); update(); }
QRect Kanagram::innerRect(const QRect &rect, const int xMargin, const int yMargin) { QRect r = rect; if (xMargin>0) { r.setWidth(r.width() - 2 * xMargin); r.moveBy(xMargin, 0); } if (yMargin>0) { r.setHeight(r.height() - 2 * yMargin); r.moveBy(0, yMargin); } return r; }
QRect ossimQtVceShape::boundingRectAdvanced() const { int dx = int(x()+xVelocity())-int(x()); int dy = int(y()+yVelocity())-int(y()); QRect r = boundingVceShapeRect(); r.moveBy(dx,dy); return r; }
void MainWin::shiftDown(QRect &rect, int offset) const { #if QT_VERSION < 0x040000 rect.moveBy(0, offset); #else rect.translate(0, offset); #endif }
void UIListTreeType::DrawRegion(QPainter *p, QRect &area, int order, int context) { if (m_context != -1 && m_context != context) return; QPtrListIterator<UIListBtnType> it(listLevels); UIListBtnType *child; int maxx = 0; while ((child = it.current()) != 0) { if (child->IsVisible()) maxx = child->GetArea().right(); ++it; } it.toFirst(); while ((child = it.current()) != 0) { if (!child->IsVisible()) break; int offset = 0; if (maxx > m_totalarea.right()) offset = -1 * (maxx - m_totalarea.right()); child->SetDrawOffset(offset); QRect drawRect = child->GetArea(); drawRect.moveBy(offset, 0); drawRect.moveBy(m_parent->GetAreaRect().x(), m_parent->GetAreaRect().y()); if (child->GetArea().right() + offset > m_totalarea.left() && drawRect == area) { child->SetDrawOffset(0 - child->GetArea().x()); child->Draw(p, order, context, list_tree_active); child->SetDrawOffset(offset); } ++it; } }
void ossimQtVceShape::drawSelection(QPainter& painter) { QBrush oldBrush = painter.brush(); QBrush brush = QBrush(QColor(0,0,0)); QRect bounds = boundingVceShapeRect(); QRect ulRect = bounds; QRect urRect = bounds; QRect lrRect = bounds; QRect llRect = bounds; int bw = bounds.width(); int bh = bounds.height(); int w = theSelectionBoxSize.width(); int h = theSelectionBoxSize.height(); ulRect.moveBy(-w, -h); ulRect.setSize(theSelectionBoxSize); llRect.moveBy(-w, bh); llRect.setSize(theSelectionBoxSize); lrRect.moveBy(bw, bh); lrRect.setSize(theSelectionBoxSize); urRect.moveBy(bw, -h); urRect.setSize(theSelectionBoxSize); painter.fillRect(ulRect, brush); painter.fillRect(urRect, brush); painter.fillRect(lrRect, brush); painter.fillRect(llRect, brush); painter.setBrush(oldBrush); }
void MultiLayer::printAllLayers(QPainter *painter) { if (!painter) return; QPaintDeviceMetrics metrics(painter->device()); int dpiy = metrics.logicalDpiY(); int margin = (int) ( (1/2.54)*dpiy ); // 1 cm margins QSize size=maxSize(); double scaleFactorX=(double)(metrics.width()-2*margin)/(double)size.width(); double scaleFactorY=(double)(metrics.height()-2*margin)/(double)size.height(); for (int i=0; i<(int)graphsList->count(); i++) { Graph *gr=(Graph *)graphsList->at(i); Plot *myPlot= gr->plotWidget(); PrintFilter filter(myPlot); filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintCanvasBackground); QPoint pos=gr->pos(); pos=QPoint(margin + int(pos.x()*scaleFactorX), margin + int(pos.y()*scaleFactorY)); int width=int(myPlot->frameGeometry().width()*scaleFactorX); int height=int(myPlot->frameGeometry().height()*scaleFactorY); QRect rect = QRect(pos,QSize(width,height)); if (myPlot->paletteBackgroundColor() != QColor(white)) painter->fillRect(rect, myPlot->paletteBackgroundColor()); int lw = myPlot->lineWidth(); if ( lw > 0) { myPlot->printFrame(painter, rect); rect.moveBy (lw, lw); rect.setWidth(rect.width() - 2*lw); rect.setHeight(rect.height() - 2*lw); } myPlot->print(painter, rect, filter); } if (hasOverlapingLayers()) updateTransparency(); }
void ThumbnailList::updateWidgets() { // find all widgets that intersects the viewport and update them QRect viewportRect( contentsX(), contentsY(), visibleWidth(), visibleHeight() ); QValueList<ThumbnailWidget *>::iterator vIt = m_visibleThumbnails.begin(), vEnd = m_visibleThumbnails.end(); for ( ; vIt != vEnd; ++vIt ) { ThumbnailWidget * t = *vIt; QRect widgetRect( childX( t ), childY( t ), t->width(), t->height() ); // update only the exposed area of the widget (saves pixels..) QRect relativeRect = viewportRect.intersect( widgetRect ); if ( !relativeRect.isValid() ) continue; relativeRect.moveBy( -widgetRect.left(), -widgetRect.top() ); t->update( relativeRect ); } }
void QSimpleRichText::draw( QPainter *p, int x, int y, const QRect& clipRect, const QColorGroup& cg, const QBrush* paper ) const { QRect r = clipRect; if ( !r.isNull() ) r.moveBy( -x, -y ); if ( paper ) d->doc->setPaper( new QBrush( *paper ) ); QColorGroup g = cg; if ( d->doc->paper() ) g.setBrush( QColorGroup::Base, *d->doc->paper() ); p->save(); p->translate( x, y ); d->doc->draw( p, r, g, paper ); p->translate( -x, -y ); p->restore(); }
void QSRectClass::moveBy(QSEnv *env) { QRect *r = rect(env); if (env->numArgs() != 2) { env->throwError(QString::fromLatin1("Rect.moveBy() called with %1 arguments. 2 arguments expected."). arg(env->numArgs())); return; } if (!env->arg(0).isNumber() || !env->arg(1).isNumber()) { env->throwError(QString::fromLatin1("Rect.moveBy() called with arguments of type %1 and %2. " "Type Number and Number are expeced"). arg(env->arg(0).typeName()).arg(env->arg(1).typeName())); return; } r->moveBy(env->arg(0).toInteger(), env->arg(1).toInteger()); }
// public virtual [base kpCommand] void kpToolAutoCropCommand::execute () { if (!m_contentsRect.isValid ()) m_contentsRect = contentsRect (); getUndoPixmaps (); kpDocument *doc = document (); if (!doc) return; QPixmap pixmapWithoutBorder = kpTool::neededPixmap (*doc->pixmap (m_actOnSelection), m_contentsRect); if (!m_actOnSelection) doc->setPixmap (pixmapWithoutBorder); else { m_oldSelection = *doc->selection (); m_oldSelection.setPixmap (QPixmap ()); // m_contentsRect is relative to the top of the sel // while sel is relative to the top of the doc QRect rect = m_contentsRect; rect.moveBy (m_oldSelection.x (), m_oldSelection.y ()); kpSelection sel (kpSelection::Rectangle, rect, pixmapWithoutBorder, m_oldSelection.transparency ()); doc->setSelection (sel); if (m_mainWindow->tool ()) m_mainWindow->tool ()->somethingBelowTheCursorChanged (); } }
void PageView::viewportPaintEvent(QPaintEvent* e) { // Region from which rectangles occupied by child widgets will by substracted. QRegion backgroundArea(e->rect()); if (widgetList != 0) { for (unsigned int i = 0; i < widgetList->count(); i++) { DocumentWidget* item = widgetList->at(i); // Check if the Widget needs to be updated. if (!item->geometry().intersects(e->rect())) continue; QRect widgetGeometry = item->geometry(); // Draw the widget. if (e->rect().intersects(widgetGeometry)) { QRect widgetRect = e->rect().intersect(widgetGeometry); widgetRect.moveBy(-widgetGeometry.left(), -widgetGeometry.top()); item->update(widgetRect); } // Substract the painted area. backgroundArea -= widgetGeometry.intersect(e->rect()); } } // Paint the background. QPainter p(viewport()); QMemArray<QRect> backgroundRects = backgroundArea.rects(); for (unsigned int i = 0; i < backgroundRects.count(); i++) p.fillRect(backgroundRects[i], colorGroup().mid()); }
void Q3SimpleRichText::draw(QPainter *p, int x, int y, const QRect& clipRect, const QColorGroup &cg, const QBrush* paper) const { p->save(); if (d->cachedWidth < 0) d->adjustSize(); QRect r = clipRect; if (!r.isNull()) r.moveBy(-x, -y); if (paper) d->doc->setPaper(new QBrush(*paper)); QPalette pal2 = cg; if (d->doc->paper()) pal2.setBrush(QPalette::Base, *d->doc->paper()); if (!clipRect.isNull()) p->setClipRect(clipRect); p->translate(x, y); d->doc->draw(p, r, pal2, paper); p->translate(-x, -y); p->restore(); }
/*! Find the bounding rect for the label. The coordinates of the rect are relative to spacing + ticklength from the backbone in direction of the tick. \param font Font used for painting \param value Value */ QRect QwtScaleDraw::labelRect(const QFont &font, double value) const { QwtText lbl = tickLabel(font, value); if ( lbl.isEmpty() ) return QRect(0, 0, 0, 0); const QPoint pos = labelPosition(value); QSize labelSize = lbl.textSize(font); if ( labelSize.height() % 2 ) { labelSize.setHeight(labelSize.height() + 1); } const QwtMatrix m = labelMatrix(pos, labelSize); #if 0 QRect br = QwtMetricsMap::translate(m, QRect(QPoint(0, 0), labelSize)); #else QwtPolygon pol(4); pol.setPoint(0, 0, 0); pol.setPoint(1, 0, labelSize.height() - 1 ); pol.setPoint(2, labelSize.width() - 1, 0); pol.setPoint(3, labelSize.width() - 1, labelSize.height() - 1 ); pol = QwtMetricsMap::translate(m, pol); QRect br = pol.boundingRect(); #endif #if QT_VERSION < 0x040000 br.moveBy(-pos.x(), -pos.y()); #else br.translate(-pos.x(), -pos.y()); #endif return br; }
void MythUIType::Draw(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect) { m_NeedsRedraw = false; m_DirtyRegion = QRegion(QRect(0, 0, 0, 0)); if (!m_Visible) return; QRect realArea = m_Area; realArea.moveBy(xoffset, yoffset); if (!realArea.intersects(clipRect)) return; DrawSelf(p, xoffset, yoffset, alphaMod, clipRect); QValueVector<MythUIType *>::Iterator it; for (it = m_ChildrenList.begin(); it != m_ChildrenList.end(); ++it) { (*it)->Draw(p, xoffset + m_Area.x(), yoffset + m_Area.y(), CalcAlpha(alphaMod), clipRect); } }
void PagePainter::paintPageOnPainter( const KPDFPage * page, int id, int flags, QPainter * destPainter, const QRect & limits, int width, int height ) { QPixmap * pixmap = 0; // if a pixmap is present for given id, use it if ( page->m_pixmaps.contains( id ) ) pixmap = page->m_pixmaps[ id ]; // else find the closest match using pixmaps of other IDs (great optim!) else if ( !page->m_pixmaps.isEmpty() && width != -1 ) { int minDistance = -1; QMap< int,QPixmap * >::const_iterator it = page->m_pixmaps.begin(), end = page->m_pixmaps.end(); for ( ; it != end; ++it ) { int pixWidth = (*it)->width(), distance = pixWidth > width ? pixWidth - width : width - pixWidth; if ( minDistance == -1 || distance < minDistance ) { pixmap = *it; minDistance = distance; } } } // if have no pixmap, draw blank page with gray cross and exit if ( !pixmap ) { QColor color = Qt::white; if ( KpdfSettings::changeColors() ) { switch ( KpdfSettings::renderMode() ) { case KpdfSettings::EnumRenderMode::Inverted: color = Qt::black; break; case KpdfSettings::EnumRenderMode::Paper: color = KpdfSettings::paperColor(); break; case KpdfSettings::EnumRenderMode::Recolor: color = KpdfSettings::recolorBackground(); break; default: ; } } destPainter->fillRect( limits, color ); // draw a cross (to that the pixmap as not yet been loaded) // helps a lot on pages that take much to render destPainter->setPen( Qt::gray ); destPainter->drawLine( 0, 0, width-1, height-1 ); destPainter->drawLine( 0, height-1, width-1, 0 ); // idea here: draw a hourglass (or kpdf icon :-) on top-left corner return; } // find out what to paint over the pixmap (manipulations / overlays) bool paintAccessibility = (flags & Accessibility) && KpdfSettings::changeColors() && (KpdfSettings::renderMode() != KpdfSettings::EnumRenderMode::Paper); bool paintHighlights = (flags & Highlights) && !page->m_highlights.isEmpty(); bool enhanceLinks = (flags & EnhanceLinks) && KpdfSettings::highlightLinks(); bool enhanceImages = (flags & EnhanceImages) && KpdfSettings::highlightImages(); // check if there are really some highlightRects to paint if ( paintHighlights ) { // precalc normalized 'limits rect' for intersection double nXMin = (double)limits.left() / (double)width, nXMax = (double)limits.right() / (double)width, nYMin = (double)limits.top() / (double)height, nYMax = (double)limits.bottom() / (double)height; // if no rect intersects limits, disable paintHighlights paintHighlights = false; QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end(); for ( ; hIt != hEnd; ++hIt ) { if ( (*hIt)->intersects( nXMin, nYMin, nXMax, nYMax ) ) { paintHighlights = true; break; } } } // use backBuffer if 'pixmap direct manipulation' is needed bool backBuffer = paintAccessibility || paintHighlights; QPixmap * backPixmap = 0; QPainter * p = destPainter; if ( backBuffer ) { // let's paint using a buffered painter backPixmap = new QPixmap( limits.width(), limits.height() ); p = new QPainter( backPixmap ); p->translate( -limits.left(), -limits.top() ); } // 1. fast blit the pixmap if it has the right size.. if ( pixmap->width() == width && pixmap->height() == height ) p->drawPixmap( limits.topLeft(), *pixmap, limits ); // ..else set a scale matrix to the painter and paint a quick 'zoomed' pixmap else { p->save(); // TODO paint only the needed part (note: hope that Qt4 transforms are faster) p->scale( width / (double)pixmap->width(), height / (double)pixmap->height() ); p->drawPixmap( 0,0, *pixmap, 0,0, pixmap->width(), pixmap->height() ); p->restore(); } // 2. mangle pixmap: convert it to 32-bit qimage and perform pixel-level manipulations if ( backBuffer ) { QImage backImage = backPixmap->convertToImage(); // 2.1. modify pixmap following accessibility settings if ( paintAccessibility ) { switch ( KpdfSettings::renderMode() ) { case KpdfSettings::EnumRenderMode::Inverted: // Invert image pixels using QImage internal function backImage.invertPixels(false); break; case KpdfSettings::EnumRenderMode::Recolor: // Recolor image using KImageEffect::flatten with dither:0 KImageEffect::flatten( backImage, KpdfSettings::recolorForeground(), KpdfSettings::recolorBackground() ); break; case KpdfSettings::EnumRenderMode::BlackWhite: // Manual Gray and Contrast unsigned int * data = (unsigned int *)backImage.bits(); int val, pixels = backImage.width() * backImage.height(), con = KpdfSettings::bWContrast(), thr = 255 - KpdfSettings::bWThreshold(); for( int i = 0; i < pixels; ++i ) { val = qGray( data[i] ); if ( val > thr ) val = 128 + (127 * (val - thr)) / (255 - thr); else if ( val < thr ) val = (128 * val) / thr; if ( con > 2 ) { val = con * ( val - thr ) / 2 + thr; if ( val > 255 ) val = 255; else if ( val < 0 ) val = 0; } data[i] = qRgba( val, val, val, 255 ); } break; } } // 2.2. highlight rects in page if ( paintHighlights ) { // draw highlights that are inside the 'limits' paint region QValueList< HighlightRect * >::const_iterator hIt = page->m_highlights.begin(), hEnd = page->m_highlights.end(); for ( ; hIt != hEnd; ++hIt ) { HighlightRect * r = *hIt; QRect highlightRect = r->geometry( width, height ); if ( highlightRect.isValid() && highlightRect.intersects( limits ) ) { // find out the rect to highlight on pixmap highlightRect = highlightRect.intersect( limits ); highlightRect.moveBy( -limits.left(), -limits.top() ); // highlight composition (product: highlight color * destcolor) unsigned int * data = (unsigned int *)backImage.bits(); int val, newR, newG, newB, rh = r->color.red(), gh = r->color.green(), bh = r->color.blue(), offset = highlightRect.top() * backImage.width(); for( int y = highlightRect.top(); y <= highlightRect.bottom(); ++y ) { for( int x = highlightRect.left(); x <= highlightRect.right(); ++x ) { val = data[ x + offset ]; newR = (qRed(val) * rh) / 255; newG = (qGreen(val) * gh) / 255; newB = (qBlue(val) * bh) / 255; data[ x + offset ] = qRgba( newR, newG, newB, 255 ); } offset += backImage.width(); } } } } backPixmap->convertFromImage( backImage ); } // 3. visually enchance links and images if requested if ( enhanceLinks || enhanceImages ) { QColor normalColor = QApplication::palette().active().highlight(); QColor lightColor = normalColor.light( 140 ); // enlarging limits for intersection is like growing the 'rectGeometry' below QRect limitsEnlarged = limits; limitsEnlarged.addCoords( -2, -2, 2, 2 ); // draw rects that are inside the 'limits' paint region as opaque rects QValueList< ObjectRect * >::const_iterator lIt = page->m_rects.begin(), lEnd = page->m_rects.end(); for ( ; lIt != lEnd; ++lIt ) { ObjectRect * rect = *lIt; if ( (enhanceLinks && rect->objectType() == ObjectRect::Link) || (enhanceImages && rect->objectType() == ObjectRect::Image) ) { QRect rectGeometry = rect->geometry( width, height ); if ( rectGeometry.intersects( limitsEnlarged ) ) { // expand rect and draw inner border rectGeometry.addCoords( -1,-1,1,1 ); p->setPen( lightColor ); p->drawRect( rectGeometry ); // expand rect to draw outer border rectGeometry.addCoords( -1,-1,1,1 ); p->setPen( normalColor ); p->drawRect( rectGeometry ); } } } } // 4. if was backbuffering, copy the backPixmap to destination if ( backBuffer ) { delete p; destPainter->drawPixmap( limits.left(), limits.top(), *backPixmap ); delete backPixmap; } }
bool QwtPBPaintFilter::cmd(int c, QPainter *painter, QPDevCmdParam *param) { switch(c) { case PdcDrawTextFormatted: case PdcDrawText2Formatted: { Qt::TextFormat textFormat = d_button->usedTextFormat(); if ( textFormat == Qt::PlainText ) { param[1].ival = d_button->alignment(); QRect &r = *((QRect *)param[0].rect); r = indentRect(r); return QPicture::cmd(c, painter, param); } if ( textFormat == Qt::RichText ) { if ( !d_inFilter ) // avoid recursive calls { d_inFilter = TRUE; QwtRichText richText(*param[2].str, painter->font(), d_button->alignment(), painter->pen().color()); richText.draw(painter, indentRect(*param[0].rect)); d_inFilter = FALSE; return TRUE; } } break; } case PdcDrawPixmap: { if ( d_inFilter ) // avoid recursive calls { // There might be pixmaps embedded in rich text. // This problem is solved by the d_inFilter guard // above too. break; } if ( isLabel(param[1].pixmap) && !(d_button->alignment() & Qt::AlignCenter)) { const QRect contentsRect = #if QT_VERSION >= 300 d_button->style().subRect( QStyle::SR_PushButtonContents, d_button); #else d_button->style().pushButtonContentsRect( (QPushButton *)d_button); #endif QRect pixRect = contentsRect; if ( !d_iconRect.isEmpty() ) pixRect.setX(d_iconRect.right()); // Many styles move the label right/down // when the button is down. #if QT_VERSION >= 300 const QRect &r = *((QRect *)param[0].rect); #else const QRect r(*param[0].point, param[1].pixmap->size()); #endif const int offsetY = r.center().y() - pixRect.center().y(); const int offsetX = d_iconRect.isEmpty() ? offsetY : 0; pixRect.moveBy(offsetX, offsetY); if ( d_button->indent() > 0 ) { const int indent = d_button->indent(); const int align = d_button->alignment(); if ( align & Qt::AlignRight ) pixRect.setRight(pixRect.right() - indent); else if ( align & Qt::AlignLeft ) pixRect.setLeft(pixRect.left() + indent); if ( align & Qt::AlignTop ) pixRect.setTop(pixRect.top() + indent); else if ( align & Qt::AlignBottom ) pixRect.setBottom(pixRect.bottom() - indent); } pixRect &= contentsRect; // clip to contentsRect d_inFilter = TRUE; d_button->style().drawItem(painter, #if QT_VERSION >= 300 pixRect, #else pixRect.x(), pixRect.y(), pixRect.width(), pixRect.height(), #endif d_button->alignment(), d_button->colorGroup(), d_button->isEnabled(), param[1].pixmap, QString::null); d_inFilter = FALSE; return TRUE; } else { // We save the position of the icon. We need it later // to align the label pixmap. Hope that there are no styles // that paint the pixmap before the icon. #if QT_VERSION < 300 d_iconRect = QRect(*param[0].point, param[1].pixmap->size()); #else d_iconRect = *param[0].rect; #endif } break; } } return QPicture::cmd(c, painter, param); }