static bool orientationMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix /*op*/) { if (value) { CSSPrimitiveValueImpl *pv = static_cast<CSSPrimitiveValueImpl *>(value); if (!value->isPrimitiveValue() || pv->primitiveType() != CSSPrimitiveValue::CSS_IDENT || (pv->getIdent() != CSS_VAL_PORTRAIT && pv->getIdent() != CSS_VAL_LANDSCAPE)) { return false; } KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; if (printing) { if (pd->width() > pd->height()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } else { if (part->view()->visibleWidth() > part->view()->visibleHeight()) { return (pv->getIdent() == CSS_VAL_LANDSCAPE); } } return (pv->getIdent() == CSS_VAL_PORTRAIT); } return false; }
void QgsComposition::renderPage( QPainter* p, int page ) { if ( mPages.size() <= page ) { return; } QgsPaperItem* paperItem = mPages[page]; if ( !paperItem ) { return; } QPaintDevice* paintDevice = p->device(); if ( !paintDevice ) { return; } QRectF paperRect = QRectF( paperItem->transform().dx(), paperItem->transform().dy(), paperItem->rect().width(), paperItem->rect().height() ); QgsComposition::PlotStyle savedPlotStyle = mPlotStyle; mPlotStyle = QgsComposition::Print; render( p, QRectF( 0, 0, paintDevice->width(), paintDevice->height() ), paperRect ); mPlotStyle = savedPlotStyle; }
static bool device_aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QRect sg; int h = 0, v = 0; if (printing) { sg = QRect(0, 0, pd->width(), pd->height()); } else { sg = QApplication::desktop()->screen(QApplication::desktop()->screenNumber(rootPart->view()))->rect(); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(sg.width() * v, sg.height() * h, op); } return false; } // ({,min-,max-}device-aspect-ratio) // assume if we have a device, its aspect ratio is non-zero return true; }
static bool aspect_ratioMediaFeatureEval(CSSValueImpl *value, RenderStyle *, KHTMLPart *part, MediaFeaturePrefix op) { if (value) { KHTMLPart *rootPart = part; while (rootPart->parentPart()) { rootPart = rootPart->parentPart(); } DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl *>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; QSize vs; int h = 0, v = 0; if (printing) { vs = QSize(pd->width(), pd->height()); } else { vs = QSize(part->view()->visibleWidth(), part->view()->visibleHeight()); } if (parseAspectRatio(value, h, v)) { return v != 0 && compareValue(vs.width() * v, vs.height() * h, op); } return false; } // ({,min-,max-}aspect-ratio) // assume if we have a viewport, its aspect ratio is non-zero return true; }
void ProjectWidgetItemDelegate::paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const { if (index.isValid() && !index.parent().isValid()) { QModelIndex modifiedIndex = index.sibling(index.row(), ProjectWidget::TAG_COLUMN); QStyleOptionViewItemV4 modifiedOption(option); modifiedOption.rect.setX(option.decorationSize.width()); int width = option.fontMetrics.width(modifiedIndex.data().toString()) + option.decorationSize.width(); QPaintEngine* paintEngine = painter->paintEngine(); if (paintEngine != 0) { QPaintDevice* paintDevice = paintEngine->paintDevice(); width = paintDevice->width(); } modifiedOption.rect.setWidth(width); QItemDelegate::paint(painter, modifiedOption, modifiedIndex); return; } QItemDelegate::paint(painter, option, index); }
void QSvgTinyDocument::mapSourceToTarget(QPainter *p, const QRectF &targetRect, const QRectF &sourceRect) { QRectF target = targetRect; if (target.isNull()) { QPaintDevice *dev = p->device(); QRectF deviceRect(0, 0, dev->width(), dev->height()); if (deviceRect.isNull()) { if (sourceRect.isNull()) target = QRectF(QPointF(0, 0), size()); else target = QRectF(QPointF(0, 0), sourceRect.size()); } else { target = deviceRect; } } QRectF source = sourceRect; if (source.isNull()) source = viewBox(); if (source != target && !source.isNull()) { QTransform transform; transform.scale(target.width() / source.width(), target.height() / source.height()); QRectF c2 = transform.mapRect(source); p->translate(target.x() - c2.x(), target.y() - c2.y()); p->scale(target.width() / source.width(), target.height() / source.height()); } }
void MultiLayer::exportPainter(QPaintDevice &paintDevice, bool keepAspect, QRect rect) { QPainter p(&paintDevice); exportPainter(p, keepAspect, rect, QSize(paintDevice.width(), paintDevice.height())); p.end(); }
QPaintDevice *extractPaintDevice(KJS::ExecState *exec, KJS::JSValue *arg) { QPaintDevice *device = 0; ObjectBinding *imp = extractBindingImp<ObjectBinding>(exec, arg); if (imp) { #ifdef __GNUC__ #warning There be dragons here... #endif /** * Because of something odd with multiple inheritence and qobject cast * we need to first cast it to a QObject, then cast it to a QWidget. * All other paint devices in Qt that are objects are single inheritence * so dynamic_cast will work properly. */ QObject *qobject = imp->object<QObject>(); if (qobject) { device = qobject_cast<QWidget *>(qobject); } else { device = imp->object<QPaintDevice>(); } if (device) { qDebug("Height = %d Width = %d", device->height(), device->width()); } } else { VariantBinding *valueImp = extractBindingImp<VariantBinding>(exec, arg); if (valueImp && (valueImp->variant().type() == QVariant::Pixmap || valueImp->variant().type() == QVariant::Image)) { device = static_cast<QPaintDevice *>(valueImp->pointer()); } } return device; }
void QwtPolarRenderer::renderTo( QwtPolarPlot *plot, QPaintDevice &paintDevice ) const { int w = paintDevice.width(); int h = paintDevice.height(); QPainter p( &paintDevice ); render( plot, &p, QRectF( 0, 0, w, h ) ); }
void printerStream::printPixmap(const QPixmap &pm, bool newLine) { #if 0 QPaintDevice *dev = pr.device(); if (fwbdebug) { qDebug("printPixmap: width=%d height=%d", pm.width(), pm.height()); qDebug("printPixmap: printer->resolution()=%d", printer->resolution()); if (dev) { qDebug("printPixmap: device parameters:"); qDebug(" height=%d width=%d", dev->height(), dev->width()); qDebug(" logicalDpiY=%d logicalDpiX=%d", dev->logicalDpiY(), dev->logicalDpiX()); qDebug(" physicalDpiY=%d physicalDpiX=%d", dev->physicalDpiY(), dev->physicalDpiX()); } } #endif int target_w = (int)(pm.width() * pixmap_scaling_ratio); int target_h = (int)(pm.height() * pixmap_scaling_ratio); int pmYOffset = 0; while ( getYSpace()<(pm.height()-pmYOffset) ) { int yFrag = pageBody.height() - yPos; if (pageNo>=fromPage && pageNo<=toPage) { if (fwbdebug) qDebug("Print pixmap 1: yPos=%d pmYOffset=%d " "yFrag=%d target_w=%d target_h=%d", yPos, pmYOffset, yFrag, target_w, target_h); pr.drawPixmap(xmargin, yPos, target_w, target_h, pm, 0, pmYOffset, -1, yFrag); } pmYOffset = pmYOffset + yFrag; flushPage(); beginPage(); // resets yPos } if (pageNo>=fromPage && pageNo<=toPage) { if (fwbdebug) qDebug("Print pixmap 2: yPos=%d pmYOffset=%d target_w=%d target_h=%d", yPos, pmYOffset, target_w, target_h); pr.drawPixmap(xmargin, yPos, target_w, target_h, pm, 0, pmYOffset, -1, -1); } if (newLine) yPos = yPos + (target_h - pmYOffset); }
/*! \brief Render the plot to a paint device ( f.e a QPrinter ) A convenience method, that calculates the target rectangle from the paintdevice metrics. \sa renderTo(QPainter *, const QRect &) */ void QwtPolarPlot::renderTo( QPaintDevice &paintDev ) const { #if QT_VERSION < 0x040000 QPaintDeviceMetrics mpr( &paintDev ); int w = mpr.width(); int h = mpr.height(); #else int w = paintDev.width(); int h = paintDev.height(); #endif const QRect rect( 0, 0, w, h ); QPainter p( &paintDev ); renderTo( &p, rect ); }
static bool widthMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) width = pd->width(); else { width = part->view()->visibleWidth(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); if (value) return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style, logicalDpiY), op); return width > 0; }
void QwtPlot::print(QPaintDevice &paintDev, const QwtPlotPrintFilter &pfilter) const { #if QT_VERSION < 0x040000 QPaintDeviceMetrics mpr(&paintDev); int w = mpr.width(); int h = mpr.height(); #else int w = paintDev.width(); int h = paintDev.height(); #endif QRect rect(0, 0, w, h); double aspect = double(rect.width())/double(rect.height()); if ((aspect < 1.0)) rect.setHeight(int(aspect*rect.width())); QPainter p(&paintDev); print(&p, rect, pfilter); }
static bool device_widthMediaFeatureEval(CSSValueImpl* value, RenderStyle* style, KHTMLPart* part, MediaFeaturePrefix op) { if (value) { KHTMLPart* rootPart = part; while (rootPart->parentPart()) rootPart = rootPart->parentPart(); DOM::DocumentImpl *doc = static_cast<DOM::DocumentImpl*>(rootPart->document().handle()); QPaintDevice *pd = doc->paintDevice(); bool printing = pd ? (pd->devType() == QInternal::Printer) : false; int width; if (printing) width = pd->width(); else { width = QApplication::desktop()->screen(QApplication::desktop()->screenNumber( rootPart->view() ))->rect().width(); doc = static_cast<DOM::DocumentImpl*>(part->document().handle()); } int logicalDpiY = doc->logicalDpiY(); return value->isPrimitiveValue() && compareValue(width, static_cast<CSSPrimitiveValueImpl*>(value)->computeLength(style,logicalDpiY), op); } // ({,min-,max-}device-width) // assume if we have a device, assume non-zero return true; }
void wxQtDCImpl::DoGetSize(int *width, int *height) const { QPaintDevice *pDevice = m_qtPainter->device(); int deviceWidth; int deviceHeight; if ( pDevice ) { deviceWidth = pDevice->width(); deviceHeight = pDevice->height(); } else { deviceWidth = 0; deviceHeight = 0; } if ( width ) *width = deviceWidth; if ( height ) *height = deviceHeight; }
void DrawWidget::drawChannel(QPaintDevice &pd, Channel *ch, QPainter &p, double leftTime, double currentTime, double zoomX, double viewBottom, double zoomY, int viewType) { ZoomLookup *z; if(viewType == DRAW_VIEW_SUMMARY) z = &ch->summaryZoomLookup; else z = &ch->normalZoomLookup; ChannelLocker channelLocker(ch); QColor current = ch->color; QColor invert(255 - current.red(), 255 - current.green(), 255 - current.blue()); p.setPen(current); int viewBottomOffset = toInt(viewBottom / zoomY); printf("viewBottomOffset=%d, %f, %f\n", viewBottomOffset, viewBottom, zoomY); viewBottom = double(viewBottomOffset) * zoomY; // baseX is the no. of chunks a pixel must represent. double baseX = zoomX / ch->timePerChunk(); z->setZoomLevel(baseX); double currentChunk = ch->chunkFractionAtTime(currentTime); double leftFrameTime = currentChunk - ((currentTime - leftTime) / ch->timePerChunk()); //double leftFrameTime = leftTime / ch->timePerChunk(); double frameTime = leftFrameTime; //if(frameTime < 0.0) frameTime = 0.0; int n = 0; int baseElement = int(floor(frameTime / baseX)); if(baseElement < 0) { n -= baseElement; baseElement = 0; } int lastBaseElement = int(floor(double(ch->totalChunks()) / baseX)); Q3PointArray pointArray(pd.width()*2); //QPointArray topPoints(width()*2); //QPointArray bottomPoints(width()*2); //int pointIndex = 0; //int pointIndex = 0; if (baseX > 1) { // More samples than pixels int theWidth = pd.width(); //if(baseElement + theWidth > z->size()) z->setSize(baseElement + theWidth); if(lastBaseElement > z->size()) z->setSize(lastBaseElement); for(; n < theWidth && baseElement < lastBaseElement; n++, baseElement++) { myassert(baseElement >= 0); ZoomElement &ze = z->at(baseElement); if(!ze.isValid()) { if(calcZoomElement(ch, ze, baseElement, baseX)) continue; } if(ze.high() != 0.0f && ze.high() - ze.low() < 1.0) { //if range is closer than one semi-tone then draw a line between them //if(ze.noteLow > 0) { p.setPen(ze.color()); //p.setPen(QPen(ze.color(), lineWidth)); //Note: lineTo doen't draw a pixel on the last point of the line p.drawLine(n, pd.height() - lineTopHalfWidth - toInt(ze.high() / zoomY) + viewBottomOffset, n, pd.height() + lineBottomHalfWidth - toInt(ze.low() / zoomY) + viewBottomOffset); //pointArray.setPoint(pointIndex++, n, height() - lineTopHalfWidth - toInt(ze.high / zoomY) + viewBottomOffset); //pointArray.setPoint(pointIndex++, n, height() + lineBottomHalfWidth - toInt(ze.low / zoomY) + viewBottomOffset); } } //myassert(pointIndex <= width()*2); //p.setPen(ch->color); //p.drawLineSegments(pointArray, 0, pointIndex/2); } else { // More pixels than samples float err = 0.0, pitch = 0.0, prevPitch = 0.0, vol; int intChunk = (int) floor(frameTime); // Integer version of frame time if(intChunk < 0) intChunk = 0; double stepSize = 1.0 / baseX; // So we skip some pixels int x = 0, y; //double start = 0 - stepSize; double start = (double(intChunk) - frameTime) * stepSize; double stop = pd.width() + (2 * stepSize); int squareSize = (int(sqrt(stepSize)) / 2) * 2 + 1; //make it an odd number int halfSquareSize = squareSize/2; int penX=0, penY=0; //topPoints.setPoint(pointIndex, toInt(start), 0); //bottomPoints.setPoint(pointIndex++, toInt(start), height()); for (double n = start; n < stop && intChunk < (int)ch->totalChunks(); n += stepSize, intChunk++) { myassert(intChunk >= 0); //if (intChunk < 0) continue; // So we don't go off the beginning of the array AnalysisData *data = ch->dataAtChunk(intChunk); err = data->getCorrelation(); //vol = dB2ViewVal(data->logrms(), ch->rmsCeiling, ch->rmsFloor); vol = dB2Normalised(data->getLogRms(), ch->rmsCeiling, ch->rmsFloor); //if (err >= CERTAIN_THRESHOLD) { //float val = MIN(ch->dataAtChunk(intChunk)->volumeValue, 1.0); if(gdata->pitchContourMode() == 0) //p.setPen(QPen(colorBetween(colorGroup().background(), ch->color, err*2.0-1.0), lineWidth)); //p.setPen(QPen(colorBetween(gdata->backgroundColor(), ch->color, err*sqrt(data->rms)*10.0), lineWidth)); if(viewType == DRAW_VIEW_PRINT) p.setPen(QPen(colorBetween(QColor(255, 255, 255), ch->color, err*vol), lineWidth)); else p.setPen(QPen(colorBetween(gdata->backgroundColor(), ch->color, err*vol), lineWidth)); else p.setPen(QPen(ch->color, lineWidth)); x = toInt(n); //note = (data->isValid()) ? data->note : 0.0f; //note = (ch->isVisibleNote(data->noteIndex)) ? data->note : 0.0f; pitch = (ch->isVisibleChunk(data)) ? data->getPitch() : 0.0f; myassert(pitch >= 0.0 && pitch <= gdata->topPitch()); //pitch = bound(pitch, 0, gdata->topPitch()); y = pd.height() - 1 - toInt(pitch / zoomY) + viewBottomOffset; //y = height() - 1 - int((note / zoomY) - (viewBottom / zoomY)); if(pitch > 0.0f) { if(fabs(prevPitch - pitch) < 1.0 && n != start) { //if closer than one semi-tone from previous then draw a line between them //p.lineTo(x, y); p.drawLine(penX, penY, x, y); penX = x; penY = y; } else { p.drawPoint(x, y); //p.moveTo(x, y); penX = x; penY = y; } if(stepSize > 10) { //draw squares on the data points //p.setPen(invert); p.setBrush(Qt::NoBrush); p.drawRect(x - halfSquareSize, y - halfSquareSize, squareSize, squareSize); //p.setPen(QPen(current, 2)); } //} else { // p.moveTo(x, height()-1-int(((note-viewBottom) / zoomY))); //} } prevPitch = pitch; } } }
/// \brief Print the document (May be a file too) bool Exporter::doExport() { if(this->format < EXPORT_FORMAT_CSV) { // Choose the color values we need DsoSettingsColorValues *colorValues; if(this->format == EXPORT_FORMAT_IMAGE && this->settings->view.screenColorImages) colorValues = &(this->settings->view.color.screen); else colorValues = &(this->settings->view.color.print); QPaintDevice *paintDevice; if(this->format < EXPORT_FORMAT_IMAGE) { // We need a QPrinter for printing, pdf- and ps-export paintDevice = new QPrinter(QPrinter::HighResolution); static_cast<QPrinter *>(paintDevice)->setOrientation(this->settings->view.zoom ? QPrinter::Portrait : QPrinter::Landscape); static_cast<QPrinter *>(paintDevice)->setPageMargins(20, 20, 20, 20, QPrinter::Millimeter); if(this->format == EXPORT_FORMAT_PRINTER) { // Show the printing dialog QPrintDialog dialog(static_cast<QPrinter *>(paintDevice), static_cast<QWidget *>(this->parent())); dialog.setWindowTitle(tr("Print oscillograph")); if(dialog.exec() != QDialog::Accepted) { delete paintDevice; return false; } } else { // Configure the QPrinter static_cast<QPrinter *>(paintDevice)->setOutputFileName(this->filename); static_cast<QPrinter *>(paintDevice)->setOutputFormat((this->format == EXPORT_FORMAT_PDF) ? QPrinter::PdfFormat : QPrinter::PostScriptFormat); } } else { // We need a QPixmap for image-export paintDevice = new QPixmap(this->settings->options.imageSize); static_cast<QPixmap *>(paintDevice)->fill(colorValues->background); } // Create a painter for our device QPainter painter(paintDevice); // Get line height QFont font; QFontMetrics fontMetrics(font, paintDevice); double lineHeight = fontMetrics.height(); painter.setBrush(Qt::SolidPattern); this->dataAnalyzer->mutex()->lock(); // Draw the settings table double stretchBase = (double) (paintDevice->width() - lineHeight * 10) / 4; // Print trigger details painter.setPen(colorValues->voltage[this->settings->scope.trigger.source]); QString levelString = Helper::valueToString(this->settings->scope.voltage[this->settings->scope.trigger.source].trigger, Helper::UNIT_VOLTS, 3); QString pretriggerString = tr("%L1%").arg((int) (this->settings->scope.trigger.position * 100 + 0.5)); painter.drawText(QRectF(0, 0, lineHeight * 10, lineHeight), tr("%1 %2 %3 %4").arg(this->settings->scope.voltage[this->settings->scope.trigger.source].name, Dso::slopeString(this->settings->scope.trigger.slope), levelString, pretriggerString)); // Print sample count painter.setPen(colorValues->text); painter.drawText(QRectF(lineHeight * 10, 0, stretchBase, lineHeight), tr("%1 S").arg(this->dataAnalyzer->sampleCount()), QTextOption(Qt::AlignRight)); // Print samplerate painter.drawText(QRectF(lineHeight * 10 + stretchBase, 0, stretchBase, lineHeight), Helper::valueToString(this->settings->scope.horizontal.samplerate, Helper::UNIT_SAMPLES) + tr("/s"), QTextOption(Qt::AlignRight)); // Print timebase painter.drawText(QRectF(lineHeight * 10 + stretchBase * 2, 0, stretchBase, lineHeight), Helper::valueToString(this->settings->scope.horizontal.timebase, Helper::UNIT_SECONDS, 0) + tr("/div"), QTextOption(Qt::AlignRight)); // Print frequencybase painter.drawText(QRectF(lineHeight * 10 + stretchBase * 3, 0, stretchBase, lineHeight), Helper::valueToString(this->settings->scope.horizontal.frequencybase, Helper::UNIT_HERTZ, 0) + tr("/div"), QTextOption(Qt::AlignRight)); // Draw the measurement table stretchBase = (double) (paintDevice->width() - lineHeight * 6) / 10; int channelCount = 0; for(int channel = this->settings->scope.voltage.count() - 1; channel >= 0; channel--) { if((this->settings->scope.voltage[channel].used || this->settings->scope.spectrum[channel].used) && this->dataAnalyzer->data(channel)) { ++channelCount; double top = (double) paintDevice->height() - channelCount * lineHeight; // Print label painter.setPen(colorValues->voltage[channel]); painter.drawText(QRectF(0, top, lineHeight * 4, lineHeight), this->settings->scope.voltage[channel].name); // Print coupling/math mode if((unsigned int) channel < this->settings->scope.physicalChannels) painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight), Dso::couplingString((Dso::Coupling) this->settings->scope.voltage[channel].misc)); else painter.drawText(QRectF(lineHeight * 4, top, lineHeight * 2, lineHeight), Dso::mathModeString((Dso::MathMode) this->settings->scope.voltage[channel].misc)); // Print voltage gain painter.drawText(QRectF(lineHeight * 6, top, stretchBase * 2, lineHeight), Helper::valueToString(this->settings->scope.voltage[channel].gain, Helper::UNIT_VOLTS, 0) + tr("/div"), QTextOption(Qt::AlignRight)); // Print spectrum magnitude painter.setPen(colorValues->spectrum[channel]); painter.drawText(QRectF(lineHeight * 6 + stretchBase * 2, top, stretchBase * 2, lineHeight), Helper::valueToString(this->settings->scope.spectrum[channel].magnitude, Helper::UNIT_DECIBEL, 0) + tr("/div"), QTextOption(Qt::AlignRight)); // Amplitude string representation (4 significant digits) painter.setPen(colorValues->text); painter.drawText(QRectF(lineHeight * 6 + stretchBase * 4, top, stretchBase * 3, lineHeight), Helper::valueToString(this->dataAnalyzer->data(channel)->amplitude, Helper::UNIT_VOLTS, 4), QTextOption(Qt::AlignRight)); // Frequency string representation (5 significant digits) painter.drawText(QRectF(lineHeight * 6 + stretchBase * 7, top, stretchBase * 3, lineHeight), Helper::valueToString(this->dataAnalyzer->data(channel)->frequency, Helper::UNIT_HERTZ, 5), QTextOption(Qt::AlignRight)); } } // Draw the marker table double scopeHeight; stretchBase = (double) (paintDevice->width() - lineHeight * 10) / 4; painter.setPen(colorValues->text); // Calculate variables needed for zoomed scope double divs = fabs(this->settings->scope.horizontal.marker[1] - this->settings->scope.horizontal.marker[0]); double time = divs * this->settings->scope.horizontal.timebase; double zoomFactor = DIVS_TIME / divs; double zoomOffset = (this->settings->scope.horizontal.marker[0] + this->settings->scope.horizontal.marker[1]) / 2; if(this->settings->view.zoom) { scopeHeight = (double) (paintDevice->height() - (channelCount + 5) * lineHeight) / 2; double top = 2.5 * lineHeight + scopeHeight; painter.drawText(QRectF(0, top, stretchBase, lineHeight), tr("Zoom x%L1").arg(DIVS_TIME / divs, -1, 'g', 3)); painter.drawText(QRectF(lineHeight * 10, top, stretchBase, lineHeight), Helper::valueToString(time, Helper::UNIT_SECONDS, 4), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(lineHeight * 10 + stretchBase, top, stretchBase, lineHeight), Helper::valueToString(1.0 / time, Helper::UNIT_HERTZ, 4), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(lineHeight * 10 + stretchBase * 2, top, stretchBase, lineHeight), Helper::valueToString(time / DIVS_TIME, Helper::UNIT_SECONDS, 3) + tr("/div"), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(lineHeight * 10 + stretchBase * 3, top, stretchBase, lineHeight), Helper::valueToString(divs * this->settings->scope.horizontal.frequencybase / DIVS_TIME, Helper::UNIT_HERTZ, 3) + tr("/div"), QTextOption(Qt::AlignRight)); } else { scopeHeight = (double) paintDevice->height() - (channelCount + 4) * lineHeight; double top = 2.5 * lineHeight + scopeHeight; painter.drawText(QRectF(0, top, stretchBase, lineHeight), tr("Marker 1/2")); painter.drawText(QRectF(lineHeight * 10, top, stretchBase * 2, lineHeight), Helper::valueToString(time, Helper::UNIT_SECONDS, 4), QTextOption(Qt::AlignRight)); painter.drawText(QRectF(lineHeight * 10 + stretchBase * 2, top, stretchBase * 2, lineHeight), Helper::valueToString(1.0 / time, Helper::UNIT_HERTZ, 4), QTextOption(Qt::AlignRight)); } // Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph painter.setMatrix(QMatrix((paintDevice->width() - 1) / DIVS_TIME, 0, 0, -(scopeHeight - 1) / DIVS_VOLTAGE, (double) (paintDevice->width() - 1) / 2, (scopeHeight - 1) / 2 + lineHeight * 1.5), false); // Draw the graphs painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(Qt::NoBrush); for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); ++zoomed) { switch(this->settings->scope.horizontal.format) { case Dso::GRAPHFORMAT_TY: // Add graphs for channels for(int channel = 0 ; channel < this->settings->scope.voltage.count(); ++channel) { if(this->settings->scope.voltage[channel].used && this->dataAnalyzer->data(channel)) { painter.setPen(colorValues->voltage[channel]); // What's the horizontal distance between sampling points? double horizontalFactor = this->dataAnalyzer->data(channel)->samples.voltage.interval / this->settings->scope.horizontal.timebase; // How many samples are visible? double centerPosition, centerOffset; if(zoomed) { centerPosition = (zoomOffset + DIVS_TIME / 2) / horizontalFactor; centerOffset = DIVS_TIME / horizontalFactor / zoomFactor / 2; } else { centerPosition = DIVS_TIME / 2 / horizontalFactor; centerOffset = DIVS_TIME / horizontalFactor / 2; } unsigned int firstPosition = qMax((int) (centerPosition - centerOffset), 0); unsigned int lastPosition = qMin((int) (centerPosition + centerOffset), (int) this->dataAnalyzer->data(channel)->samples.voltage.sample.size() - 1); // Draw graph QPointF *graph = new QPointF[lastPosition - firstPosition + 1]; for(unsigned int position = firstPosition; position <= lastPosition; ++position) graph[position - firstPosition] = QPointF(position * horizontalFactor - DIVS_TIME / 2, this->dataAnalyzer->data(channel)->samples.voltage.sample[position] / this->settings->scope.voltage[channel].gain + this->settings->scope.voltage[channel].offset); painter.drawPolyline(graph, lastPosition - firstPosition + 1); delete[] graph; } } // Add spectrum graphs for (int channel = 0; channel < this->settings->scope.spectrum.count(); ++channel) { if(this->settings->scope.spectrum[channel].used && this->dataAnalyzer->data(channel)) { painter.setPen(colorValues->spectrum[channel]); // What's the horizontal distance between sampling points? double horizontalFactor = this->dataAnalyzer->data(channel)->samples.spectrum.interval / this->settings->scope.horizontal.frequencybase; // How many samples are visible? double centerPosition, centerOffset; if(zoomed) { centerPosition = (zoomOffset + DIVS_TIME / 2) / horizontalFactor; centerOffset = DIVS_TIME / horizontalFactor / zoomFactor / 2; } else { centerPosition = DIVS_TIME / 2 / horizontalFactor; centerOffset = DIVS_TIME / horizontalFactor / 2; } unsigned int firstPosition = qMax((int) (centerPosition - centerOffset), 0); unsigned int lastPosition = qMin((int) (centerPosition + centerOffset), (int) this->dataAnalyzer->data(channel)->samples.spectrum.sample.size() - 1); // Draw graph QPointF *graph = new QPointF[lastPosition - firstPosition + 1]; for(unsigned int position = firstPosition; position <= lastPosition; ++position) graph[position - firstPosition] = QPointF(position * horizontalFactor - DIVS_TIME / 2, this->dataAnalyzer->data(channel)->samples.spectrum.sample[position] / this->settings->scope.spectrum[channel].magnitude + this->settings->scope.spectrum[channel].offset); painter.drawPolyline(graph, lastPosition - firstPosition + 1); delete[] graph; } } break; case Dso::GRAPHFORMAT_XY: break; default: break; } // Set DIVS_TIME / zoomFactor x DIVS_VOLTAGE matrix for zoomed oscillograph painter.setMatrix(QMatrix((paintDevice->width() - 1) / DIVS_TIME * zoomFactor, 0, 0, -(scopeHeight - 1) / DIVS_VOLTAGE, (double) (paintDevice->width() - 1) / 2 - zoomOffset * zoomFactor * (paintDevice->width() - 1) / DIVS_TIME, (scopeHeight - 1) * 1.5 + lineHeight * 4), false); } this->dataAnalyzer->mutex()->unlock(); // Draw grids painter.setRenderHint(QPainter::Antialiasing, false); for(int zoomed = 0; zoomed < (this->settings->view.zoom ? 2 : 1); ++zoomed) { // Set DIVS_TIME x DIVS_VOLTAGE matrix for oscillograph painter.setMatrix(QMatrix((paintDevice->width() - 1) / DIVS_TIME, 0, 0, -(scopeHeight - 1) / DIVS_VOLTAGE, (double) (paintDevice->width() - 1) / 2, (scopeHeight - 1) * (zoomed + 0.5) + lineHeight * 1.5 + lineHeight * 2.5 * zoomed), false); // Grid lines painter.setPen(colorValues->grid); if(this->format < EXPORT_FORMAT_IMAGE) { // Draw vertical lines for(int div = 1; div < DIVS_TIME / 2; ++div) { for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; ++dot) { painter.drawLine(QPointF((double) -div - 0.02, (double) -dot / 5), QPointF((double) -div + 0.02, (double) -dot / 5)); painter.drawLine(QPointF((double) -div - 0.02, (double) dot / 5), QPointF((double) -div + 0.02, (double) dot / 5)); painter.drawLine(QPointF((double) div - 0.02, (double) -dot / 5), QPointF((double) div + 0.02, (double) -dot / 5)); painter.drawLine(QPointF((double) div - 0.02, (double) dot / 5), QPointF((double) div + 0.02, (double) dot / 5)); } } // Draw horizontal lines for(int div = 1; div < DIVS_VOLTAGE / 2; ++div) { for(int dot = 1; dot < DIVS_TIME / 2 * 5; ++dot) { painter.drawLine(QPointF((double) -dot / 5, (double) -div - 0.02), QPointF((double) -dot / 5, (double) -div + 0.02)); painter.drawLine(QPointF((double) dot / 5, (double) -div - 0.02), QPointF((double) dot / 5, (double) -div + 0.02)); painter.drawLine(QPointF((double) -dot / 5, (double) div - 0.02), QPointF((double) -dot / 5, (double) div + 0.02)); painter.drawLine(QPointF((double) dot / 5, (double) div - 0.02), QPointF((double) dot / 5, (double) div + 0.02)); } } } else { // Draw vertical lines for(int div = 1; div < DIVS_TIME / 2; ++div) { for(int dot = 1; dot < DIVS_VOLTAGE / 2 * 5; ++dot) { painter.drawPoint(QPointF(-div, (double) -dot / 5)); painter.drawPoint(QPointF(-div, (double) dot / 5)); painter.drawPoint(QPointF(div, (double) -dot / 5)); painter.drawPoint(QPointF(div, (double) dot / 5)); } } // Draw horizontal lines for(int div = 1; div < DIVS_VOLTAGE / 2; ++div) { for(int dot = 1; dot < DIVS_TIME / 2 * 5; ++dot) { if(dot % 5 == 0) continue; // Already done by vertical lines painter.drawPoint(QPointF((double) -dot / 5, -div)); painter.drawPoint(QPointF((double) dot / 5, -div)); painter.drawPoint(QPointF((double) -dot / 5, div)); painter.drawPoint(QPointF((double) dot / 5, div)); } } } // Axes painter.setPen(colorValues->axes); painter.drawLine(QPointF(-DIVS_TIME / 2, 0), QPointF(DIVS_TIME / 2, 0)); painter.drawLine(QPointF(0, -DIVS_VOLTAGE / 2), QPointF(0, DIVS_VOLTAGE / 2)); for(double div = 0.2; div <= DIVS_TIME / 2; div += 0.2) { painter.drawLine(QPointF(div, -0.05), QPointF(div, 0.05)); painter.drawLine(QPointF(-div, -0.05), QPointF(-div, 0.05)); } for(double div = 0.2; div <= DIVS_VOLTAGE / 2; div += 0.2) { painter.drawLine(QPointF(-0.05, div), QPointF(0.05, div)); painter.drawLine(QPointF(-0.05, -div), QPointF(0.05, -div)); } // Borders painter.setPen(colorValues->border); painter.drawRect(QRectF(-DIVS_TIME / 2, -DIVS_VOLTAGE / 2, DIVS_TIME, DIVS_VOLTAGE)); } painter.end(); if(this->format == EXPORT_FORMAT_IMAGE) static_cast<QPixmap *>(paintDevice)->save(this->filename); delete paintDevice; return true; } else { QFile csvFile(this->filename); if(!csvFile.open(QIODevice::WriteOnly | QIODevice::Text)) return false; QTextStream csvStream(&csvFile); for(int channel = 0 ; channel < this->settings->scope.voltage.count(); ++channel) { if(this->dataAnalyzer->data(channel)) { if(this->settings->scope.voltage[channel].used) { // Start with channel name and the sample interval csvStream << "\"" << this->settings->scope.voltage[channel].name << "\"," << this->dataAnalyzer->data(channel)->samples.voltage.interval; // And now all sample values in volts for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.voltage.sample.size(); ++position) csvStream << "," << this->dataAnalyzer->data(channel)->samples.voltage.sample[position]; // Finally a newline csvStream << '\n'; } if(this->settings->scope.spectrum[channel].used) { // Start with channel name and the sample interval csvStream << "\"" << this->settings->scope.spectrum[channel].name << "\"," << this->dataAnalyzer->data(channel)->samples.spectrum.interval; // And now all magnitudes in dB for(unsigned int position = 0; position < this->dataAnalyzer->data(channel)->samples.spectrum.sample.size(); ++position) csvStream << "," << this->dataAnalyzer->data(channel)->samples.spectrum.sample[position]; // Finally a newline csvStream << '\n'; } } } csvFile.close(); return true; } }
bool printerStream::begin() { if( !pr.begin(printer) ) // paint on printer return false; active=true; pageWidth = printer->width(); pageHeight = printer->height(); if (fwbdebug) { qDebug("printer dimensions: %dx%d",pageWidth,pageHeight); qDebug("Margin: %.1f", margin); } dpiy = printer->logicalDpiY(); ymargin = (int) ( (margin/2.54)*dpiy ); // assuming printer's resolutions by X and Y axes are the same xmargin = ymargin; pageBody = QRect( xmargin, ymargin, printer->width() - 2 * xmargin, printer->height() - 2 * ymargin ); yHeaderHeight = int((headerHeight / 2.54) * dpiy); yHeaderLine = int(((headerHeight - 0.5) / 2.54) * dpiy); pr.setFont(headerFont); QFontMetrics fm = pr.fontMetrics(); QRect br = fm.boundingRect("Page 999"); headerTextBox = QRect(xmargin, ymargin + yHeaderLine - fm.lineSpacing() - 1, printer->width() - 2 * xmargin, fm.lineSpacing() + 1); headerBox = QRect(xmargin, ymargin, printer->width() - 2 * xmargin, yHeaderHeight); if (fwbdebug) { qDebug("dpiy=%d", dpiy); qDebug("yHeaderHeight=%d", yHeaderHeight); qDebug("yHeaderLine=%d", yHeaderLine); qDebug("fm.lineSpacing()=%d", fm.lineSpacing()); qDebug("bounding rect for the header text: l=%d,t=%d,w=%d,h=%d", br.left(), br.top(), br.width(), br.height()); qDebug("headerBox: l=%d,t=%d,w=%d,h=%d", headerBox.left(), headerBox.top(), headerBox.width(), headerBox.height()); qDebug("headerTextBox: l=%d,t=%d,w=%d,h=%d", headerTextBox.left(), headerTextBox.top(), headerTextBox.width(), headerTextBox.height()); } yPos = 0; pageNo = 1; QPaintDevice *dev = pr.device(); // lets table with width 1000 pixels be drawn 80% of the page width pixmap_scaling_ratio = float(dev->width()) * 0.8 / 1000 * table_scaling; return true; }
void QgsDecorationCopyright::render( const QgsMapSettings &mapSettings, QgsRenderContext &context ) { Q_UNUSED( mapSettings ); if ( !enabled() ) return; context.painter()->save(); context.painter()->setRenderHint( QPainter::Antialiasing, true ); QString displayString = QgsExpression::replaceExpressionText( mLabelText, &context.expressionContext() ); QStringList displayStringList = displayString.split( QStringLiteral( "\n" ) ); QFontMetricsF fm( mTextFormat.scaledFont( context ) ); double textWidth = QgsTextRenderer::textWidth( context, mTextFormat, displayStringList, &fm ); double textHeight = QgsTextRenderer::textHeight( context, mTextFormat, displayStringList, QgsTextRenderer::Point, &fm ); QPaintDevice *device = context.painter()->device(); int deviceHeight = device->height() / device->devicePixelRatioF(); int deviceWidth = device->width() / device->devicePixelRatioF(); float xOffset( 0 ), yOffset( 0 ); // Set margin according to selected units switch ( mMarginUnit ) { case QgsUnitTypes::RenderMillimeters: { int pixelsInchX = context.painter()->device()->logicalDpiX(); int pixelsInchY = context.painter()->device()->logicalDpiY(); xOffset = pixelsInchX * INCHES_TO_MM * mMarginHorizontal; yOffset = pixelsInchY * INCHES_TO_MM * mMarginVertical; break; } case QgsUnitTypes::RenderPixels: { xOffset = mMarginHorizontal; yOffset = mMarginVertical; break; } case QgsUnitTypes::RenderPercentage: { xOffset = ( ( deviceWidth - textWidth ) / 100. ) * mMarginHorizontal; yOffset = ( ( deviceHeight - textHeight ) / 100. ) * mMarginVertical; break; } case QgsUnitTypes::RenderMapUnits: case QgsUnitTypes::RenderPoints: case QgsUnitTypes::RenderInches: case QgsUnitTypes::RenderUnknownUnit: case QgsUnitTypes::RenderMetersInMapUnits: break; } // Determine placement of label from form combo box QgsTextRenderer::HAlignment horizontalAlignment = QgsTextRenderer::AlignLeft; switch ( mPlacement ) { case BottomLeft: // Bottom Left, xOffset is set above yOffset = deviceHeight - yOffset; break; case TopLeft: // Top left, xOffset is set above yOffset = yOffset + textHeight; break; case TopRight: // Top Right yOffset = yOffset + textHeight; xOffset = deviceWidth - xOffset; horizontalAlignment = QgsTextRenderer::AlignRight; break; case BottomRight: // Bottom Right yOffset = deviceHeight - yOffset; xOffset = deviceWidth - xOffset; horizontalAlignment = QgsTextRenderer::AlignRight; break; default: QgsDebugMsg( QStringLiteral( "Unknown placement index of %1" ).arg( static_cast<int>( mPlacement ) ) ); } //Paint label to canvas QgsTextRenderer::drawText( QPointF( xOffset, yOffset ), 0.0, horizontalAlignment, displayStringList, context, mTextFormat ); context.painter()->restore(); }
QRect QGLPainterSurface::viewportGL() const { QPaintDevice *device = m_painter->device(); return QRect(0, 0, device->width(), device->height()); }