QTransform scaleToPercent(const QSizeF &size) { const qreal w = qMax(static_cast<qreal>(1e-5), size.width()); const qreal h = qMax(static_cast<qreal>(1e-5), size.height()); return QTransform().scale(100/w, 100/h); }
void RectangleShape::updatePath(const QSizeF &size) { qreal rx = 0; qreal ry = 0; if (m_cornerRadiusX > 0 && m_cornerRadiusY > 0) { rx = size.width() / 200.0 * m_cornerRadiusX; ry = size.height() / 200.0 * m_cornerRadiusY; } qreal x2 = size.width() - rx; qreal y2 = size.height() - ry; QPointF curvePoints[12]; int requiredCurvePointCount = 4; if (rx && m_cornerRadiusX < 100) requiredCurvePointCount += 2; if (ry && m_cornerRadiusY < 100) requiredCurvePointCount += 2; createPoints(requiredCurvePointCount); KoSubpath &points = *m_subpaths[0]; int cp = 0; // first path starts and closes path points[cp]->setProperty(KoPathPoint::StartSubpath); points[cp]->setProperty(KoPathPoint::CloseSubpath); points[cp]->setPoint(QPointF(rx, 0)); points[cp]->removeControlPoint1(); points[cp]->removeControlPoint2(); if (m_cornerRadiusX < 100 || m_cornerRadiusY == 0) { // end point of the top edge points[++cp]->setPoint(QPointF(x2, 0)); points[cp]->removeControlPoint1(); points[cp]->removeControlPoint2(); } if (rx) { // the top right radius arcToCurve(rx, ry, 90, -90, points[cp]->point(), curvePoints); points[cp]->setControlPoint2(curvePoints[0]); points[++cp]->setControlPoint1(curvePoints[1]); points[cp]->setPoint(curvePoints[2]); points[cp]->removeControlPoint2(); } if (m_cornerRadiusY < 100 || m_cornerRadiusX == 0) { // the right edge points[++cp]->setPoint(QPointF(size.width(), y2)); points[cp]->removeControlPoint1(); points[cp]->removeControlPoint2(); } if (rx) { // the bottom right radius arcToCurve(rx, ry, 0, -90, points[cp]->point(), curvePoints); points[cp]->setControlPoint2(curvePoints[0]); points[++cp]->setControlPoint1(curvePoints[1]); points[cp]->setPoint(curvePoints[2]); points[cp]->removeControlPoint2(); } if (m_cornerRadiusX < 100 || m_cornerRadiusY == 0) { // the bottom edge points[++cp]->setPoint(QPointF(rx, size.height())); points[cp]->removeControlPoint1(); points[cp]->removeControlPoint2(); } if (rx) { // the bottom left radius arcToCurve(rx, ry, 270, -90, points[cp]->point(), curvePoints); points[cp]->setControlPoint2(curvePoints[0]); points[++cp]->setControlPoint1(curvePoints[1]); points[cp]->setPoint(curvePoints[2]); points[cp]->removeControlPoint2(); } if ((m_cornerRadiusY < 100 || m_cornerRadiusX == 0) && ry) { // the right edge points[++cp]->setPoint(QPointF(0, ry)); points[cp]->removeControlPoint1(); points[cp]->removeControlPoint2(); } if (rx) { // the top left radius arcToCurve(rx, ry, 180, -90, points[cp]->point(), curvePoints); points[cp]->setControlPoint2(curvePoints[0]); points[0]->setControlPoint1(curvePoints[1]); points[0]->setPoint(curvePoints[2]); } // unset all stop/close path properties for (int i = 1; i < cp; ++i) { points[i]->unsetProperty(KoPathPoint::StopSubpath); points[i]->unsetProperty(KoPathPoint::CloseSubpath); } // last point stops and closes path points.last()->setProperty(KoPathPoint::StopSubpath); points.last()->setProperty(KoPathPoint::CloseSubpath); }
void QgsComposerMultiFrame::recalculateFrameSizes() { if ( mFrameItems.size() < 1 ) { return; } QSizeF size = totalSize(); double totalHeight = size.height(); if ( totalHeight < 1 ) { return; } double currentY = 0; double currentHeight = 0; QgsComposerFrame* currentItem = 0; for ( int i = 0; i < mFrameItems.size(); ++i ) { if ( currentY >= totalHeight ) { if ( mResizeMode == ExtendToNextPage ) //remove unneeded frames in extent mode { for ( int j = mFrameItems.size(); j > i; --j ) { removeFrame( j - 1 ); } } return; } currentItem = mFrameItems.value( i ); currentHeight = currentItem->rect().height(); currentItem->setContentSection( QRectF( 0, currentY, currentItem->rect().width(), currentHeight ) ); currentItem->update(); currentY += currentHeight; } //at end of frames but there is still content left. Add other pages if ResizeMode == if ( mResizeMode == ExtendToNextPage ) { while ( currentY < totalHeight ) { //find out on which page the lower left point of the last frame is int page = currentItem->transform().dy() / ( mComposition->paperHeight() + mComposition->spaceBetweenPages() ); //add new pages if necessary if ( mComposition->numPages() < ( page + 2 ) ) { mComposition->setNumPages( page + 2 ); } //copy last frame QgsComposerFrame* newFrame = new QgsComposerFrame( mComposition, this, currentItem->transform().dx(), currentItem->transform().dy() + mComposition->paperHeight() + mComposition->spaceBetweenPages(), currentItem->rect().width(), currentItem->rect().height() ); newFrame->setContentSection( QRectF( 0, currentY, newFrame->rect().width(), newFrame->rect().height() ) ); currentY += newFrame->rect().height(); currentItem = newFrame; addFrame( newFrame, false ); } } }
// Apply a simple variant type to a DOM property static bool applySimpleProperty(const QVariant &v, bool translateString, DomProperty *dom_prop) { switch (v.type()) { case QVariant::String: { DomString *str = new DomString(); str->setText(v.toString()); if (!translateString) str->setAttributeNotr(QStringLiteral("true")); dom_prop->setElementString(str); } return true; case QVariant::ByteArray: dom_prop->setElementCstring(QString::fromUtf8(v.toByteArray())); return true; case QVariant::Int: dom_prop->setElementNumber(v.toInt()); return true; case QVariant::UInt: dom_prop->setElementUInt(v.toUInt()); return true; case QVariant::LongLong: dom_prop->setElementLongLong(v.toLongLong()); return true; case QVariant::ULongLong: dom_prop->setElementULongLong(v.toULongLong()); return true; case QVariant::Double: dom_prop->setElementDouble(v.toDouble()); return true; case QVariant::Bool: dom_prop->setElementBool(v.toBool() ? QFormBuilderStrings::instance().trueValue : QFormBuilderStrings::instance().falseValue); return true; case QVariant::Char: { DomChar *ch = new DomChar(); const QChar character = v.toChar(); ch->setElementUnicode(character.unicode()); dom_prop->setElementChar(ch); } return true; case QVariant::Point: { DomPoint *pt = new DomPoint(); const QPoint point = v.toPoint(); pt->setElementX(point.x()); pt->setElementY(point.y()); dom_prop->setElementPoint(pt); } return true; case QVariant::PointF: { DomPointF *ptf = new DomPointF(); const QPointF pointf = v.toPointF(); ptf->setElementX(pointf.x()); ptf->setElementY(pointf.y()); dom_prop->setElementPointF(ptf); } return true; case QVariant::Color: { DomColor *clr = new DomColor(); const QColor color = qvariant_cast<QColor>(v); clr->setElementRed(color.red()); clr->setElementGreen(color.green()); clr->setElementBlue(color.blue()); const int alphaChannel = color.alpha(); if (alphaChannel != 255) clr->setAttributeAlpha(alphaChannel); dom_prop->setElementColor(clr); } return true; case QVariant::Size: { DomSize *sz = new DomSize(); const QSize size = v.toSize(); sz->setElementWidth(size.width()); sz->setElementHeight(size.height()); dom_prop->setElementSize(sz); } return true; case QVariant::SizeF: { DomSizeF *szf = new DomSizeF(); const QSizeF sizef = v.toSizeF(); szf->setElementWidth(sizef.width()); szf->setElementHeight(sizef.height()); dom_prop->setElementSizeF(szf); } return true; case QVariant::Rect: { DomRect *rc = new DomRect(); const QRect rect = v.toRect(); rc->setElementX(rect.x()); rc->setElementY(rect.y()); rc->setElementWidth(rect.width()); rc->setElementHeight(rect.height()); dom_prop->setElementRect(rc); } return true; case QVariant::RectF: { DomRectF *rcf = new DomRectF(); const QRectF rectf = v.toRectF(); rcf->setElementX(rectf.x()); rcf->setElementY(rectf.y()); rcf->setElementWidth(rectf.width()); rcf->setElementHeight(rectf.height()); dom_prop->setElementRectF(rcf); } return true; case QVariant::Font: { DomFont *fnt = new DomFont(); const QFont font = qvariant_cast<QFont>(v); const uint mask = font.resolve(); if (mask & QFont::WeightResolved) { fnt->setElementBold(font.bold()); fnt->setElementWeight(font.weight()); } if (mask & QFont::FamilyResolved) fnt->setElementFamily(font.family()); if (mask & QFont::StyleResolved) fnt->setElementItalic(font.italic()); if (mask & QFont::SizeResolved) fnt->setElementPointSize(font.pointSize()); if (mask & QFont::StrikeOutResolved) fnt->setElementStrikeOut(font.strikeOut()); if (mask & QFont::UnderlineResolved) fnt->setElementUnderline(font.underline()); if (mask & QFont::KerningResolved) fnt->setElementKerning(font.kerning()); if (mask & QFont::StyleStrategyResolved) { const QMetaEnum styleStrategy_enum = metaEnum<QAbstractFormBuilderGadget>("styleStrategy"); fnt->setElementStyleStrategy(QLatin1String(styleStrategy_enum.valueToKey(font.styleStrategy()))); } dom_prop->setElementFont(fnt); } return true; #ifndef QT_NO_CURSOR case QVariant::Cursor: { const QMetaEnum cursorShape_enum = metaEnum<QAbstractFormBuilderGadget>("cursorShape"); dom_prop->setElementCursorShape(QLatin1String(cursorShape_enum.valueToKey(qvariant_cast<QCursor>(v).shape()))); } return true; #endif case QVariant::KeySequence: { DomString *s = new DomString(); s->setText(qvariant_cast<QKeySequence>(v).toString(QKeySequence::PortableText)); dom_prop->setElementString(s); } return true; case QVariant::Locale: { DomLocale *dom = new DomLocale(); const QLocale locale = qvariant_cast<QLocale>(v); const QMetaEnum language_enum = metaEnum<QAbstractFormBuilderGadget>("language"); const QMetaEnum country_enum = metaEnum<QAbstractFormBuilderGadget>("country"); dom->setAttributeLanguage(QLatin1String(language_enum.valueToKey(locale.language()))); dom->setAttributeCountry(QLatin1String(country_enum.valueToKey(locale.country()))); dom_prop->setElementLocale(dom); } return true; case QVariant::SizePolicy: { DomSizePolicy *dom = new DomSizePolicy(); const QSizePolicy sizePolicy = qvariant_cast<QSizePolicy>(v); dom->setElementHorStretch(sizePolicy.horizontalStretch()); dom->setElementVerStretch(sizePolicy.verticalStretch()); const QMetaEnum sizeType_enum = metaEnum<QAbstractFormBuilderGadget>("sizeType"); dom->setAttributeHSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.horizontalPolicy()))); dom->setAttributeVSizeType(QLatin1String(sizeType_enum.valueToKey(sizePolicy.verticalPolicy()))); dom_prop->setElementSizePolicy(dom); } return true; case QVariant::Date: { DomDate *dom = new DomDate(); const QDate date = qvariant_cast<QDate>(v); dom->setElementYear(date.year()); dom->setElementMonth(date.month()); dom->setElementDay(date.day()); dom_prop->setElementDate(dom); } return true; case QVariant::Time: { DomTime *dom = new DomTime(); const QTime time = qvariant_cast<QTime>(v); dom->setElementHour(time.hour()); dom->setElementMinute(time.minute()); dom->setElementSecond(time.second()); dom_prop->setElementTime(dom); } return true; case QVariant::DateTime: { DomDateTime *dom = new DomDateTime(); const QDateTime dateTime = qvariant_cast<QDateTime>(v); dom->setElementHour(dateTime.time().hour()); dom->setElementMinute(dateTime.time().minute()); dom->setElementSecond(dateTime.time().second()); dom->setElementYear(dateTime.date().year()); dom->setElementMonth(dateTime.date().month()); dom->setElementDay(dateTime.date().day()); dom_prop->setElementDateTime(dom); } return true; case QVariant::Url: { DomUrl *dom = new DomUrl(); const QUrl url = v.toUrl(); DomString *str = new DomString(); str->setText(url.toString()); dom->setElementString(str); dom_prop->setElementUrl(dom); } return true; case QVariant::StringList: { DomStringList *sl = new DomStringList; sl->setElementString(qvariant_cast<QStringList>(v)); dom_prop->setElementStringList(sl); } return true; default: break; } return false; }
QImage *ConvertThread::loadSvgImage(const QString &imagePath) { QSvgRenderer renderer; if (shared.svgModifiersEnabled) { SvgModifier modifier(pd.imagePath); // modify SVG file if (!shared.svgRemoveTextString.isNull()) modifier.removeText(shared.svgRemoveTextString); if (shared.svgRemoveEmptyGroup) modifier.removeEmptyGroups(); // save SVG file if (shared.svgSave) { QString svgTargetFileName = targetFilePath.left(targetFilePath.lastIndexOf('.')+1) + "svg"; QFile file(svgTargetFileName); // ask overwrite if (file.exists()) { shared.mutex.lock(); emit question(svgTargetFileName, Overwrite); shared.mutex.unlock(); } if (shared.overwriteResult == QMessageBox::Yes || shared.overwriteResult == QMessageBox::YesToAll) { if (!file.open(QIODevice::WriteOnly)) { emit imageStatus(pd.imgData, tr("Failed to save new SVG file"), Failed); return NULL; } file.write(modifier.content()); } } // and load QByteArray buffer to renderer if (!renderer.load(modifier.content())) { emit imageStatus(pd.imgData, tr("Failed to open changed SVG file"), Failed); return NULL; } } else if (!renderer.load(pd.imagePath)) { emit imageStatus(pd.imgData, tr("Failed to open SVG file"), Failed); return NULL; } sizeComputed = computeSize(&renderer, pd.imagePath); if (sizeComputed == 2) return NULL; // keep aspect ratio if (shared.maintainAspect) { qreal w = width; qreal h = height; qreal targetRatio = w / h; QSizeF svgSize = renderer.defaultSize(); qreal currentRatio = svgSize.width() / svgSize.height(); if (currentRatio != targetRatio) { qreal diffRatio; if (currentRatio > targetRatio) diffRatio = w / svgSize.width(); else diffRatio = h / svgSize.height(); width = diffRatio * svgSize.width(); height = diffRatio * svgSize.height(); } } // create image QImage *img = new QImage(width, height, QImage::Format_ARGB32); fillImage(img); QPainter painter(img); renderer.render(&painter); // don't scale rendered image hasWidth = false; hasHeight = false; // finaly return the image pointer return img; }
bool QgsAlignRaster::checkInputParameters() { mErrorMessage.clear(); if ( mCrsWkt == "_error_" ) { mErrorMessage = QObject::tr( "Unable to reproject." ); return false; } if ( mCellSizeX == 0 || mCellSizeY == 0 ) { mErrorMessage = QObject::tr( "Cell size must not be zero." ); return false; } mXSize = mYSize = 0; for ( int i = 0; i < 6; ++i ) mGeoTransform[i] = 0; double finalExtent[4] = { 0, 0, 0, 0 }; // for each raster: determine their extent in projected cfg for ( int i = 0; i < mRasters.count(); ++i ) { Item& r = mRasters[i]; RasterInfo info( r.inputFilename ); QSizeF cs; QgsRectangle extent; if ( !suggestedWarpOutput( info, mCrsWkt, &cs, 0, &extent ) ) { mErrorMessage = QString( "Failed to get suggested warp output.\n\n" "File:\n%1\n\n" "Source WKT:\n%2\n\nDestination WKT:\n%3" ) .arg( r.inputFilename ) .arg( info.mCrsWkt ) .arg( mCrsWkt ); return false; } r.srcCellSizeInDestCRS = cs.width() * cs.height(); if ( finalExtent[0] == 0 && finalExtent[1] == 0 && finalExtent[2] == 0 && finalExtent[3] == 0 ) { // initialize with the first layer finalExtent[0] = extent.xMinimum(); finalExtent[1] = extent.yMinimum(); finalExtent[2] = extent.xMaximum(); finalExtent[3] = extent.yMaximum(); } else { // use intersection of rects if ( extent.xMinimum() > finalExtent[0] ) finalExtent[0] = extent.xMinimum(); if ( extent.yMinimum() > finalExtent[1] ) finalExtent[1] = extent.yMinimum(); if ( extent.xMaximum() < finalExtent[2] ) finalExtent[2] = extent.xMaximum(); if ( extent.yMaximum() < finalExtent[3] ) finalExtent[3] = extent.yMaximum(); } } // count in extra clip extent (if present) // 1. align requested rect to the grid - extend the rect if necessary // 2. intersect with clip extent with final extent if ( !( mClipExtent[0] == 0 && mClipExtent[1] == 0 && mClipExtent[2] == 0 && mClipExtent[3] == 0 ) ) { // extend clip extent to grid double clipX0 = floor_with_tolerance(( mClipExtent[0] - mGridOffsetX ) / mCellSizeX ) * mCellSizeX + mGridOffsetX; double clipY0 = floor_with_tolerance(( mClipExtent[1] - mGridOffsetY ) / mCellSizeY ) * mCellSizeY + mGridOffsetY; double clipX1 = ceil_with_tolerance(( mClipExtent[2] - clipX0 ) / mCellSizeX ) * mCellSizeX + clipX0; double clipY1 = ceil_with_tolerance(( mClipExtent[3] - clipY0 ) / mCellSizeY ) * mCellSizeY + clipY0; if ( clipX0 > finalExtent[0] ) finalExtent[0] = clipX0; if ( clipY0 > finalExtent[1] ) finalExtent[1] = clipY0; if ( clipX1 < finalExtent[2] ) finalExtent[2] = clipX1; if ( clipY1 < finalExtent[3] ) finalExtent[3] = clipY1; } // align to grid - shrink the rect if necessary // output raster grid configuration (with no rotation/shear) // ... and raster width/height double originX = ceil_with_tolerance(( finalExtent[0] - mGridOffsetX ) / mCellSizeX ) * mCellSizeX + mGridOffsetX;; double originY = ceil_with_tolerance(( finalExtent[1] - mGridOffsetY ) / mCellSizeY ) * mCellSizeY + mGridOffsetY; int xSize = floor_with_tolerance(( finalExtent[2] - originX ) / mCellSizeX ); int ySize = floor_with_tolerance(( finalExtent[3] - originY ) / mCellSizeY ); if ( xSize <= 0 || ySize <= 0 ) { mErrorMessage = QObject::tr( "No common intersecting area." ); return false; } mXSize = xSize; mYSize = ySize; // build final geotransform... mGeoTransform[0] = originX; mGeoTransform[1] = mCellSizeX; mGeoTransform[2] = 0; mGeoTransform[3] = originY + ( mCellSizeY * ySize ); mGeoTransform[4] = 0; mGeoTransform[5] = -mCellSizeY; return true; }
/*! Render a plot to a file Supported formats are: - pdf\n - ps\n - svg\n - all image formats supported by Qt, see QImageWriter::supportedImageFormats() \param plot Plot widget \param fileName Path of the file, where the document will be stored \param format Format for the document \param sizeMM Size for the document in millimeters. \param resolution Resolution in dots per Inch (dpi) \sa renderTo(), render(), QwtPainter::setRoundingAlignment() */ void QwtPolarRenderer::renderDocument( QwtPolarPlot *plot, const QString &fileName, const QString &format, const QSizeF &sizeMM, int resolution ) { if ( plot == NULL || sizeMM.isEmpty() || resolution <= 0 ) return; QString title = plot->title().text(); if ( title.isEmpty() ) title = "Plot Document"; const double mmToInch = 1.0 / 25.4; const QSizeF size = sizeMM * mmToInch * resolution; const QRectF documentRect( 0.0, 0.0, size.width(), size.height() ); const QString fmt = format.toLower(); if ( format == "pdf" || format == "ps" ) { QPrinter printer; printer.setFullPage( true ); printer.setPaperSize( sizeMM, QPrinter::Millimeter ); printer.setDocName( title ); printer.setOutputFileName( fileName ); printer.setOutputFormat( ( format == "pdf" ) ? QPrinter::PdfFormat : QPrinter::PostScriptFormat ); printer.setResolution( resolution ); QPainter painter( &printer ); render( plot, &painter, documentRect ); } #ifndef QWT_NO_POLAR_SVG #ifdef QT_SVG_LIB #if QT_VERSION >= 0x040500 else if ( format == "svg" ) { QSvgGenerator generator; generator.setTitle( title ); generator.setFileName( fileName ); generator.setResolution( resolution ); generator.setViewBox( documentRect ); QPainter painter( &generator ); render( plot, &painter, documentRect ); } #endif #endif #endif else { if ( QImageWriter::supportedImageFormats().indexOf( format.toLatin1() ) >= 0 ) { const QRect imageRect = documentRect.toRect(); const int dotsPerMeter = qRound( resolution * mmToInch * 1000.0 ); QImage image( imageRect.size(), QImage::Format_ARGB32 ); image.setDotsPerMeterX( dotsPerMeter ); image.setDotsPerMeterY( dotsPerMeter ); image.fill( QColor( Qt::white ).rgb() ); QPainter painter( &image ); render( plot, &painter, imageRect ); painter.end(); image.save( fileName, format.toLatin1() ); } } }
void QgsPieDiagram::renderDiagram( const QgsAttributes& att, QgsRenderContext& c, const QgsDiagramSettings& s, const QPointF& position ) { QPainter* p = c.painter(); if ( !p ) { return; } //get sum of values QList<double> values; double currentVal = 0; double valSum = 0; int valCount = 0; QList<int>::const_iterator catIt = s.categoryIndices.constBegin(); for ( ; catIt != s.categoryIndices.constEnd(); ++catIt ) { currentVal = att[*catIt].toDouble(); values.push_back( currentVal ); valSum += currentVal; if ( currentVal ) valCount++; } //draw the slices double totalAngle = 0; double currentAngle; //convert from mm / map units to painter units QSizeF spu = sizePainterUnits( s.size, s, c ); double w = spu.width(); double h = spu.height(); double baseX = position.x(); double baseY = position.y() - h; mPen.setColor( s.penColor ); setPenWidth( mPen, s, c ); p->setPen( mPen ); // there are some values > 0 available if ( valSum > 0 ) { QList<double>::const_iterator valIt = values.constBegin(); QList< QColor >::const_iterator colIt = s.categoryColors.constBegin(); for ( ; valIt != values.constEnd(); ++valIt, ++colIt ) { if ( *valIt ) { currentAngle = *valIt / valSum * 360 * 16; mCategoryBrush.setColor( *colIt ); p->setBrush( mCategoryBrush ); // if only 1 value is > 0, draw a circle if ( valCount == 1 ) { p->drawEllipse( baseX, baseY, w, h ); } else { p->drawPie( baseX, baseY, w, h, totalAngle + s.angleOffset, currentAngle ); } totalAngle += currentAngle; } } } else // valSum > 0 { // draw empty circle if no values are defined at all mCategoryBrush.setColor( Qt::transparent ); p->setBrush( mCategoryBrush ); p->drawEllipse( baseX, baseY, w, h ); } }
/** * Overrides the standard paint event. */ void ActivityWidget::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) { QRectF r = rect(); const QSizeF sz = size(); qreal w = sz.width(); qreal h = sz.height(); p->setPen(QPen(lineColor(), lineWidth())); p->setBrush(brush()); switch(m_activityType) { case Normal: p->drawRoundRect(r, (h * 60) / w, 60); break; case Initial: p->setBrush(QBrush(lineColor())); p->drawEllipse(r); break; case Final: p->setBrush(Qt::NoBrush); p->drawEllipse(r); Widget_Utils::drawCrossInEllipse(p, r); break; case End: { p->setBrush(Qt::NoBrush); qreal adj = lineWidth() + 1; p->drawEllipse(r.adjusted(+adj, +adj, -adj, -adj)); p->setBrush(lineColor()); adj = lineWidth() + 3; p->drawEllipse(r.adjusted(+adj, +adj, -adj, -adj)); break; } case Branch: { QPolygonF array(4); array[0] = QPointF(w / 2, 0); array[1] = QPointF(w, h / 2); array[2] = QPointF(w / 2, h); array[3] = QPointF(0, h / 2); p->drawPolygon(array); } break; case Invok: p->drawRoundRect(r, (h * 60) / w, 60); { qreal x = w - (w/5); qreal y = h - (h/3); p->drawLine(QLineF(x, y, x, y + 20)); p->drawLine(QLineF(x - 10, y + 10, x + 10, y + 10)); p->drawLine(QLineF(x - 10, y + 10, x - 10, y + 20)); p->drawLine(QLineF(x + 10, y + 10, x + 10, y + 20)); } break; case Param: p->drawRoundRect(r, (h * 60) / w, 60); break; } }
double QgsTextDiagram::legendSize( double value, const QgsDiagramSettings &s, const QgsDiagramInterpolationSettings &is ) const { QSizeF size = sizeForValue( value, s, is ); return qMax( size.width(), size.height() ); }
void QgsTextDiagram::renderDiagram( const QgsFeature& feature, QgsRenderContext& c, const QgsDiagramSettings& s, QPointF position ) { QPainter* p = c.painter(); if ( !p ) { return; } //convert from mm / map units to painter units QSizeF spu = sizePainterUnits( s.size, s, c ); double w = spu.width(); double h = spu.height(); double baseX = position.x(); double baseY = position.y() - h; QVector<QPointF> textPositions; //midpoints for text placement int nCategories = s.categoryAttributes.size(); for ( int i = 0; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { textPositions.push_back( QPointF( baseX + ( w / nCategories ) * i + w / nCategories / 2.0, baseY + h / 2.0 ) ); } else //vertical { textPositions.push_back( QPointF( baseX + w / 2.0, baseY + h / nCategories * i + w / nCategories / 2.0 ) ); } } mPen.setColor( s.penColor ); setPenWidth( mPen, s, c ); p->setPen( mPen ); mBrush.setColor( s.backgroundColor ); p->setBrush( mBrush ); //draw shapes and separator lines first if ( mShape == Circle ) { p->drawEllipse( baseX, baseY, w, h ); //draw separator lines QList<QPointF> intersect; //intersections between shape and separation lines QPointF center( baseX + w / 2.0, baseY + h / 2.0 ); double r1 = w / 2.0; double r2 = h / 2.0; for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { lineEllipseIntersection( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ), center, r1, r2, intersect ); } else //vertical { lineEllipseIntersection( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ), center, r1, r2, intersect ); } if ( intersect.size() > 1 ) { p->drawLine( intersect.at( 0 ), intersect.at( 1 ) ); } } } else if ( mShape == Rectangle ) { p->drawRect( QRectF( baseX, baseY, w, h ) ); for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { p->drawLine( QPointF( baseX + w / nCategories * i, baseY ), QPointF( baseX + w / nCategories * i, baseY + h ) ); } else { p->drawLine( QPointF( baseX, baseY + h / nCategories * i ), QPointF( baseX + w, baseY + h / nCategories * i ) ); } } } else //triangle { QPolygonF triangle; triangle << QPointF( baseX, baseY + h ) << QPointF( baseX + w, baseY + h ) << QPointF( baseX + w / 2.0, baseY ); p->drawPolygon( triangle ); QLineF triangleEdgeLeft( baseX + w / 2.0, baseY, baseX, baseY + h ); QLineF triangleEdgeRight( baseX + w, baseY + h, baseX + w / 2.0, baseY ); QPointF intersectionPoint1, intersectionPoint2; for ( int i = 1; i < nCategories; ++i ) { if ( mOrientation == Horizontal ) { QLineF verticalLine( baseX + w / nCategories * i, baseY + h, baseX + w / nCategories * i, baseY ); if ( baseX + w / nCategories * i < baseX + w / 2.0 ) { verticalLine.intersect( triangleEdgeLeft, &intersectionPoint1 ); } else { verticalLine.intersect( triangleEdgeRight, &intersectionPoint1 ); } p->drawLine( QPointF( baseX + w / nCategories * i, baseY + h ), intersectionPoint1 ); } else //vertical { QLineF horizontalLine( baseX, baseY + h / nCategories * i, baseX + w, baseY + h / nCategories * i ); horizontalLine.intersect( triangleEdgeLeft, &intersectionPoint1 ); horizontalLine.intersect( triangleEdgeRight, &intersectionPoint2 ); p->drawLine( intersectionPoint1, intersectionPoint2 ); } } } //draw text QFont sFont = scaledFont( s, c ); QFontMetricsF fontMetrics( sFont ); p->setFont( sFont ); QgsExpressionContext expressionContext = c.expressionContext(); expressionContext.setFeature( feature ); if ( feature.fields() ) expressionContext.setFields( *feature.fields() ); for ( int i = 0; i < textPositions.size(); ++i ) { QgsExpression* expression = getExpression( s.categoryAttributes.at( i ), expressionContext ); QString val = expression->evaluate( &expressionContext ).toString(); //find out dimesions double textWidth = fontMetrics.width( val ); double textHeight = fontMetrics.height(); mPen.setColor( s.categoryColors.at( i ) ); p->setPen( mPen ); QPointF position = textPositions.at( i ); // Calculate vertical placement double xOffset = 0; switch ( s.labelPlacementMethod ) { case QgsDiagramSettings::Height: xOffset = textHeight / 2.0; break; case QgsDiagramSettings::XHeight: xOffset = fontMetrics.xHeight(); break; } p->drawText( QPointF( position.x() - textWidth / 2.0, position.y() + xOffset ), val ); } }
static inline QSize qCeiling(const QSizeF &s) { return QSize(qCeil(s.width()), qCeil(s.height())); }
bool KisZoomAndPanTest::checkRotation(ZoomAndPanTester &t, qreal angle) { // save old values QPoint oldOffset = t.coordinatesConverter()->documentOffset(); QPointF oldCenteringCorrection = t.coordinatesConverter()->centeringCorrection(); QPointF oldPreferredCenter = t.canvasController()->preferredCenter(); QPointF oldRealCenterPoint = t.coordinatesConverter()->widgetToImage(t.coordinatesConverter()->widgetCenterPoint()); QSize oldDocumentSize = t.canvasController()->documentSize(); qreal baseAngle = t.coordinatesConverter()->rotationAngle(); t.canvasController()->rotateCanvas(angle); // save result values QPoint newOffset = t.coordinatesConverter()->documentOffset(); QPointF newCenteringCorrection = t.coordinatesConverter()->centeringCorrection(); QPointF newPreferredCenter = t.canvasController()->preferredCenter(); QPointF newRealCenterPoint = t.coordinatesConverter()->widgetToImage(t.coordinatesConverter()->widgetCenterPoint()); QSize newDocumentSize = t.canvasController()->documentSize(); // calculate theoretical preferred center QTransform rot; rot.rotate(angle); QSizeF dSize = t.coordinatesConverter()->imageSizeInFlakePixels(); QPointF dPoint(dSize.width(), dSize.height()); QPointF expectedPreferredCenter = (oldPreferredCenter - dPoint * correctionMatrix(baseAngle)) * rot + dPoint * correctionMatrix(baseAngle + angle); // calculate theoretical offset based on the real preferred center QPointF wPoint(t.canvasWidget()->size().width(), t.canvasWidget()->size().height()); QPointF expectedOldOffset = oldPreferredCenter - 0.5 * wPoint; QPointF expectedNewOffset = newPreferredCenter - 0.5 * wPoint; bool preferredCenterAsExpected = compareWithRounding(expectedPreferredCenter, newPreferredCenter, 2); bool oldOffsetAsExpected = compareWithRounding(expectedOldOffset + oldCenteringCorrection, QPointF(oldOffset), 2); bool newOffsetAsExpected = compareWithRounding(expectedNewOffset + newCenteringCorrection, QPointF(newOffset), 3); qreal zoom = t.zoomController()->zoomAction()->effectiveZoom(); bool realCenterPointAsExpected = compareWithRounding(oldRealCenterPoint, newRealCenterPoint, 2/zoom); if (!oldOffsetAsExpected || !newOffsetAsExpected || !preferredCenterAsExpected || !realCenterPointAsExpected) { qDebug() << "***** ROTATE **************"; if(!oldOffsetAsExpected) { qDebug() << " ### Old offset invariant broken"; } if(!newOffsetAsExpected) { qDebug() << " ### New offset invariant broken"; } if(!preferredCenterAsExpected) { qDebug() << " ### Preferred center invariant broken"; } if(!realCenterPointAsExpected) { qDebug() << " ### *Real* center invariant broken"; } qDebug() << ppVar(expectedOldOffset); qDebug() << ppVar(expectedNewOffset); qDebug() << ppVar(expectedPreferredCenter); qDebug() << ppVar(oldOffset) << ppVar(newOffset); qDebug() << ppVar(oldCenteringCorrection) << ppVar(newCenteringCorrection); qDebug() << ppVar(oldPreferredCenter) << ppVar(newPreferredCenter); qDebug() << ppVar(oldRealCenterPoint) << ppVar(newRealCenterPoint); qDebug() << ppVar(oldDocumentSize) << ppVar(newDocumentSize); qDebug() << ppVar(baseAngle) << "deg"; qDebug() << ppVar(angle) << "deg"; qDebug() << "***************************"; } return preferredCenterAsExpected && oldOffsetAsExpected && newOffsetAsExpected && realCenterPointAsExpected; }
QTransform scaleFromPercent(const QSizeF &size) { const qreal w = qMax(static_cast<qreal>(1e-5), size.width()); const qreal h = qMax(static_cast<qreal>(1e-5), size.height()); return QTransform().scale(w/100, h/100); }
void qDrawRoundedCorners(QPainter *p, qreal x1, qreal y1, qreal x2, qreal y2, const QSizeF& r1, const QSizeF& r2, Edge edge, BorderStyle s, QBrush c) { const qreal pw = (edge == TopEdge || edge == BottomEdge) ? y2-y1 : x2-x1; if (s == BorderStyle_Double) { qreal wby3 = pw/3; switch (edge) { case TopEdge: case BottomEdge: qDrawRoundedCorners(p, x1, y1, x2, y1+wby3, r1, r2, edge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x1, y2-wby3, x2, y2, r1, r2, edge, BorderStyle_Solid, c); break; case LeftEdge: qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, LeftEdge, BorderStyle_Solid, c); break; case RightEdge: qDrawRoundedCorners(p, x1, y1+1, x1+wby3, y2, r1, r2, RightEdge, BorderStyle_Solid, c); qDrawRoundedCorners(p, x2-wby3, y1+1, x2, y2, r1, r2, RightEdge, BorderStyle_Solid, c); break; default: break; } return; } else if (s == BorderStyle_Ridge || s == BorderStyle_Groove) { BorderStyle s1, s2; if (s == BorderStyle_Groove) { s1 = BorderStyle_Inset; s2 = BorderStyle_Outset; } else { s1 = BorderStyle_Outset; s2 = BorderStyle_Inset; } int pwby2 = qRound(pw/2); switch (edge) { case TopEdge: qDrawRoundedCorners(p, x1, y1, x2, y1 + pwby2, r1, r2, TopEdge, s1, c); qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, TopEdge, s2, c); break; case BottomEdge: qDrawRoundedCorners(p, x1, y1 + pwby2, x2, y2, r1, r2, BottomEdge, s1, c); qDrawRoundedCorners(p, x1, y1, x2, y2-pwby2, r1, r2, BottomEdge, s2, c); break; case LeftEdge: qDrawRoundedCorners(p, x1, y1, x1 + pwby2, y2, r1, r2, LeftEdge, s1, c); qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, LeftEdge, s2, c); break; case RightEdge: qDrawRoundedCorners(p, x1 + pwby2, y1, x2, y2, r1, r2, RightEdge, s1, c); qDrawRoundedCorners(p, x1, y1, x2 - pwby2, y2, r1, r2, RightEdge, s2, c); break; default: break; } } else if ((s == BorderStyle_Outset && (edge == TopEdge || edge == LeftEdge)) || (s == BorderStyle_Inset && (edge == BottomEdge || edge == RightEdge))) c = c.color().lighter(); p->save(); qreal pwby2 = pw/2; p->setBrush(Qt::NoBrush); QPen pen = qPenFromStyle(c, pw, s); pen.setCapStyle(Qt::SquareCap); // this eliminates the offby1 errors that we might hit below p->setPen(pen); switch (edge) { case TopEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 - r1.width() + pwby2, y1 + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, -45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - r2.width() + pwby2, y1 + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 45*16, 45*16); break; case BottomEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 - r1.width() + pwby2, y2 - 2*r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), -90 * 16, -45 * 16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - r2.width() + pwby2, y2 - 2*r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), -90 * 16, 45 * 16); break; case LeftEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x1 + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 135*16, 45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x1 + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 180*16, 45*16); break; case RightEdge: if (!r1.isEmpty()) p->drawArc(QRectF(x2 - 2*r1.width() + pwby2, y1 - r1.height() + pwby2, 2*r1.width() - pw, 2*r1.height() - pw), 45*16, -45*16); if (!r2.isEmpty()) p->drawArc(QRectF(x2 - 2*r2.width() + pwby2, y2 - r2.height() + pwby2, 2*r2.width() - pw, 2*r2.height() - pw), 315*16, 45*16); break; default: break; } p->restore(); }
void ShaderNodeUI::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { if (!isSelected()) { painter->setPen(QPen(QColor(0, 0, 0))); } else { painter->setPen(QPen(QColor(0, 0, 255))); } // normal node painter->setBrush(QBrush(QColor(192, 192, 192))); QRectF mainNodeRect(QPointF(kNodePortRadius, 0.0f), QPointF(m_nodeSize.width(), m_nodeSize.height())); painter->drawRoundedRect(mainNodeRect, 5.0f, 5.0f); QFont font; QFontMetrics fontMetrics(font); painter->setPen(QPen(QColor(0, 0, 0))); // draw header line painter->drawLine(QPointF(kNodePortRadius, kNodeHeaderHeight), QPointF(m_nodeSize.width(), kNodeHeaderHeight)); // draw node name in the header... QSizeF textSize = fontMetrics.size(0, m_name.c_str()); QPointF rectCentre(m_nodeSize.width() / 2.0, kNodeHeaderHeight / 2.0); QPointF textPos = rectCentre; textPos += QPointF(-textSize.width() / 2.0, textSize.height() / 2.0 - 2.0f); painter->drawText(textPos.x(), textPos.y(), m_name.c_str()); // draw input ports const std::vector<ShaderNode::InputShaderPort>& aInputPorts = m_pActualNode->getInputPorts(); for (unsigned int i = 0; i < aInputPorts.size(); i++) { const ShaderNode::InputShaderPort& port = aInputPorts[i]; float heightOffset = (float)i * kNodePortSpacing; // draw outer main circle painter->setBrush(QBrush(QColor(232, 232, 64))); painter->drawEllipse(QPointF(kNodePortRadius, kNodeFirstPortHeight + heightOffset), kNodePortRadius, kNodePortRadius); QSizeF portNameTextSize = fontMetrics.size(0, port.name.c_str()); QPointF portTextPos(kNodePortRadius * 3.0f, kNodeFirstPortHeight + heightOffset); portTextPos += QPointF(0.0f, portNameTextSize.height() / 4.0f); painter->drawText(portTextPos.x(), portTextPos.y(), port.name.c_str()); } float outputPortStartHeight = ((float)aInputPorts.size() * kNodePortSpacing) + kNodeFirstPortHeight; // draw output ports const std::vector<ShaderNode::OutputShaderPort>& aOutputPorts = m_pActualNode->getOutputPorts(); for (unsigned int i = 0; i < aOutputPorts.size(); i++) { const ShaderNode::OutputShaderPort& port = aOutputPorts[i]; float heightOffset = (float)i * kNodePortSpacing; painter->setBrush(QBrush(QColor(128, 128, 232))); painter->drawEllipse(QPointF(m_nodeSize.width(), outputPortStartHeight + heightOffset), kNodePortRadius, kNodePortRadius); QSizeF portNameTextSize = fontMetrics.size(0, port.name.c_str()); QPointF portTextPos(m_nodeSize.width() - kNodePortRadius * 3.0f, outputPortStartHeight + heightOffset); portTextPos -= QPointF(portNameTextSize.width(), 0.0f); portTextPos += QPointF(0.0f, portNameTextSize.height() / 4.0f); painter->drawText(portTextPos.x(), portTextPos.y(), port.name.c_str()); } }
bool QgsAlignRaster::setParametersFromRaster( const RasterInfo& rasterInfo, const QString& customCRSWkt, QSizeF customCellSize, QPointF customGridOffset ) { if ( customCRSWkt.isEmpty() || customCRSWkt == rasterInfo.crs() ) { // use ref. layer to init input mCrsWkt = rasterInfo.crs(); if ( !customCellSize.isValid() ) { mCellSizeX = rasterInfo.cellSize().width(); mCellSizeY = rasterInfo.cellSize().height(); } else { mCellSizeX = customCellSize.width(); mCellSizeY = customCellSize.height(); } if ( customGridOffset.x() < 0 || customGridOffset.y() < 0 ) { if ( !customCellSize.isValid() ) { // using original raster's grid offset to be aligned with origin mGridOffsetX = rasterInfo.gridOffset().x(); mGridOffsetY = rasterInfo.gridOffset().y(); } else { // if using custom cell size: offset so that we are aligned // with the original raster's origin point mGridOffsetX = fmod_with_tolerance( rasterInfo.origin().x(), customCellSize.width() ); mGridOffsetY = fmod_with_tolerance( rasterInfo.origin().y(), customCellSize.height() ); } } else { mGridOffsetX = customGridOffset.x(); mGridOffsetY = customGridOffset.x(); } } else { QSizeF cs; QPointF go; if ( !suggestedWarpOutput( rasterInfo, customCRSWkt, &cs, &go ) ) { mCrsWkt = "_error_"; mCellSizeX = mCellSizeY = 0; mGridOffsetX = mGridOffsetY = 0; return false; } mCrsWkt = customCRSWkt; if ( !customCellSize.isValid() ) { mCellSizeX = cs.width(); mCellSizeY = cs.height(); } else { mCellSizeX = customCellSize.width(); mCellSizeY = customCellSize.height(); } if ( customGridOffset.x() < 0 || customGridOffset.y() < 0 ) { mGridOffsetX = go.x(); mGridOffsetY = go.y(); } else { mGridOffsetX = customGridOffset.x(); mGridOffsetY = customGridOffset.x(); } } return true; }
QVariant KConfigGroup::convertToQVariant(const char *pKey, const QByteArray& value, const QVariant& aDefault) { // if a type handler is added here you must add a QVConversions definition // to conversion_check.h, or ConversionCheck::to_QVariant will not allow // readEntry<T> to convert to QVariant. switch( aDefault.type() ) { case QVariant::Invalid: return QVariant(); case QVariant::String: // this should return the raw string not the dollar expanded string. // imho if processed string is wanted should call // readEntry(key, QString) not readEntry(key, QVariant) return QString::fromUtf8(value); case QVariant::List: case QVariant::StringList: return KConfigGroupPrivate::deserializeList(QString::fromUtf8(value)); case QVariant::ByteArray: return value; case QVariant::Bool: { const QByteArray lower(value.toLower()); if (lower == "false" || lower == "no" || lower == "off" || lower == "0") return false; return true; } case QVariant::Double: case QMetaType::Float: case QVariant::Int: case QVariant::UInt: case QVariant::LongLong: case QVariant::ULongLong: { QVariant tmp = value; if ( !tmp.convert(aDefault.type()) ) tmp = aDefault; return tmp; } case QVariant::Point: { const QList<int> list = asIntList(value); if ( list.count() != 2 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 2, list.count() ); return aDefault; } return QPoint(list.at( 0 ), list.at( 1 )); } case QVariant::PointF: { const QList<qreal> list = asRealList(value); if ( list.count() != 2 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 2, list.count() ); return aDefault; } return QPointF(list.at( 0 ), list.at( 1 )); } case QVariant::Rect: { const QList<int> list = asIntList(value); if ( list.count() != 4 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 4, list.count() ); return aDefault; } const QRect rect(list.at( 0 ), list.at( 1 ), list.at( 2 ), list.at( 3 )); if ( !rect.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return rect; } case QVariant::RectF: { const QList<qreal> list = asRealList(value); if ( list.count() != 4 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 4, list.count() ); return aDefault; } const QRectF rect(list.at( 0 ), list.at( 1 ), list.at( 2 ), list.at( 3 )); if ( !rect.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return rect; } case QVariant::Size: { const QList<int> list = asIntList(value); if ( list.count() != 2 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 2, list.count() ); return aDefault; } const QSize size(list.at( 0 ), list.at( 1 )); if ( !size.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return size; } case QVariant::SizeF: { const QList<qreal> list = asRealList(value); if ( list.count() != 2 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 2, list.count() ); return aDefault; } const QSizeF size(list.at( 0 ), list.at( 1 )); if ( !size.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return size; } case QVariant::DateTime: { const QList<int> list = asIntList(value); if ( list.count() != 6 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 6, list.count() ); return aDefault; } const QDate date( list.at( 0 ), list.at( 1 ), list.at( 2 ) ); const QTime time( list.at( 3 ), list.at( 4 ), list.at( 5 ) ); const QDateTime dt( date, time ); if ( !dt.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return dt; } case QVariant::Date: { QList<int> list = asIntList(value); if ( list.count() == 6 ) list = list.mid(0, 3); // don't break config files that stored QDate as QDateTime if ( list.count() != 3 ) { qWarning() << errString( pKey, value, aDefault ) << formatError( 3, list.count() ); return aDefault; } const QDate date( list.at( 0 ), list.at( 1 ), list.at( 2 ) ); if ( !date.isValid() ) { qWarning() << errString( pKey, value, aDefault ); return aDefault; } return date; } case QVariant::Color: case QVariant::Font: qWarning() << "KConfigGroup::readEntry was passed GUI type '" << aDefault.typeName() << "' but kdeui isn't linked! If it is linked to your program, " "this is a platform bug. Please inform the KDE developers"; break; case QVariant::Url: return QUrl(QString::fromUtf8(value)); default: break; } qWarning() << "unhandled type " << aDefault.typeName(); return QVariant(); }
void CAPresentationHandler::resizeCanvas (const QSizeF& canvasSize) { QSizeF pageSize = d->paView->activePage()->boundingRect().size(); QGraphicsWidget* canvasItem = canvas()->canvasItem(); QSizeF newSize (pageSize); newSize.scale (canvasSize, Qt::KeepAspectRatio); if (canvasSize.width() < canvasSize.height()) { canvasItem->setGeometry (0, (canvasSize.height() - newSize.height()) / 2, newSize.width(), newSize.height()); documentController()->canvasController()->zoomHandler()->setZoom (canvasSize.width() / pageSize.width() * 0.75); } else { canvasItem->setGeometry ( (canvasSize.width() - newSize.width()) / 2, 0, newSize.width(), newSize.height()); documentController()->canvasController()->zoomHandler()->setZoom (canvasSize.height() / pageSize.height() * 0.75); } }
void KConfigGroup::writeEntry( const char* key, const QVariant &value, WriteConfigFlags flags ) { Q_ASSERT_X(isValid(), "KConfigGroup::writeEntry", "accessing an invalid group"); Q_ASSERT_X(!d->bConst, "KConfigGroup::writeEntry", "writing to a read-only group"); if ( writeEntryGui( this, key, value, flags ) ) return; // GUI type that was handled QByteArray data; // if a type handler is added here you must add a QVConversions definition // to conversion_check.h, or ConversionCheck::to_QVariant will not allow // writeEntry<T> to convert to QVariant. switch( value.type() ) { case QVariant::Invalid: data = ""; break; case QVariant::ByteArray: data = value.toByteArray(); break; case QVariant::String: case QVariant::Int: case QVariant::UInt: case QVariant::Double: case QMetaType::Float: case QVariant::Bool: case QVariant::LongLong: case QVariant::ULongLong: data = value.toString().toUtf8(); break; case QVariant::List: if (!value.canConvert(QVariant::StringList)) qWarning() << "not all types in \"" << key << "\" can convert to QString," " information will be lost"; case QVariant::StringList: writeEntry( key, value.toList(), flags ); return; case QVariant::Point: { QVariantList list; const QPoint rPoint = value.toPoint(); list.insert( 0, rPoint.x() ); list.insert( 1, rPoint.y() ); writeEntry( key, list, flags ); return; } case QVariant::PointF: { QVariantList list; const QPointF point = value.toPointF(); list.insert( 0, point.x() ); list.insert( 1, point.y() ); writeEntry( key, list, flags ); return; } case QVariant::Rect:{ QVariantList list; const QRect rRect = value.toRect(); list.insert( 0, rRect.left() ); list.insert( 1, rRect.top() ); list.insert( 2, rRect.width() ); list.insert( 3, rRect.height() ); writeEntry( key, list, flags ); return; } case QVariant::RectF:{ QVariantList list; const QRectF rRectF = value.toRectF(); list.insert(0, rRectF.left()); list.insert(1, rRectF.top()); list.insert(2, rRectF.width()); list.insert(3, rRectF.height()); writeEntry(key, list, flags); return; } case QVariant::Size:{ QVariantList list; const QSize rSize = value.toSize(); list.insert( 0, rSize.width() ); list.insert( 1, rSize.height() ); writeEntry( key, list, flags ); return; } case QVariant::SizeF:{ QVariantList list; const QSizeF rSizeF = value.toSizeF(); list.insert(0, rSizeF.width()); list.insert(1, rSizeF.height()); writeEntry(key, list, flags); return; } case QVariant::Date: { QVariantList list; const QDate date = value.toDate(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); writeEntry( key, list, flags ); return; } case QVariant::DateTime: { QVariantList list; const QDateTime rDateTime = value.toDateTime(); const QTime time = rDateTime.time(); const QDate date = rDateTime.date(); list.insert( 0, date.year() ); list.insert( 1, date.month() ); list.insert( 2, date.day() ); list.insert( 3, time.hour() ); list.insert( 4, time.minute() ); list.insert( 5, time.second() ); writeEntry( key, list, flags ); return; } case QVariant::Color: case QVariant::Font: qWarning() << "KConfigGroup::writeEntry was passed GUI type '" << value.typeName() << "' but kdeui isn't linked! If it is linked to your program, this is a platform bug. " "Please inform the KDE developers"; break; case QVariant::Url: data = QUrl(value.toUrl()).toString().toUtf8(); break; default: qWarning() << "KConfigGroup::writeEntry - unhandled type" << value.typeName() << "in group" << name(); } writeEntry(key, data, flags); }
QgsLabelFeature* QgsVectorLayerDiagramProvider::registerDiagram( QgsFeature& feat, QgsRenderContext &context, QgsGeometry* obstacleGeometry ) { const QgsMapSettings& mapSettings = mEngine->mapSettings(); const QgsDiagramRenderer* dr = mSettings.getRenderer(); if ( dr ) { QList<QgsDiagramSettings> settingList = dr->diagramSettings(); if ( !settingList.isEmpty() && settingList.at( 0 ).scaleBasedVisibility ) { double minScale = settingList.at( 0 ).minScaleDenominator; if ( minScale > 0 && context.rendererScale() < minScale ) { return nullptr; } double maxScale = settingList.at( 0 ).maxScaleDenominator; if ( maxScale > 0 && context.rendererScale() > maxScale ) { return nullptr; } } } //convert geom to geos QgsGeometry geom = feat.geometry(); QgsGeometry extentGeom = QgsGeometry::fromRect( mapSettings.visibleExtent() ); if ( !qgsDoubleNear( mapSettings.rotation(), 0.0 ) ) { //PAL features are prerotated, so extent also needs to be unrotated extentGeom.rotate( -mapSettings.rotation(), mapSettings.visibleExtent().center() ); } const GEOSGeometry* geos_geom = nullptr; QScopedPointer<QgsGeometry> scopedPreparedGeom; if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, mSettings.coordinateTransform(), &extentGeom ) ) { scopedPreparedGeom.reset( new QgsGeometry( QgsPalLabeling::prepareGeometry( geom, context, mSettings.coordinateTransform(), &extentGeom ) ) ); QgsGeometry* preparedGeom = scopedPreparedGeom.data(); if ( preparedGeom->isEmpty() ) return nullptr; geos_geom = preparedGeom->asGeos(); } else { geos_geom = geom.asGeos(); } if ( !geos_geom ) return nullptr; // invalid geometry GEOSGeometry* geomCopy = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom ); const GEOSGeometry* geosObstacleGeom = nullptr; QScopedPointer<QgsGeometry> scopedObstacleGeom; if ( mSettings.isObstacle() && obstacleGeometry && QgsPalLabeling::geometryRequiresPreparation( *obstacleGeometry, context, mSettings.coordinateTransform(), &extentGeom ) ) { QgsGeometry preparedObstacleGeom = QgsPalLabeling::prepareGeometry( *obstacleGeometry, context, mSettings.coordinateTransform(), &extentGeom ); geosObstacleGeom = preparedObstacleGeom.asGeos(); } else if ( mSettings.isObstacle() && obstacleGeometry ) { geosObstacleGeom = obstacleGeometry->asGeos(); } GEOSGeometry* geosObstacleGeomClone = nullptr; if ( geosObstacleGeom ) { geosObstacleGeomClone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geosObstacleGeom ); } double diagramWidth = 0; double diagramHeight = 0; if ( dr ) { QSizeF diagSize = dr->sizeMapUnits( feat, context ); if ( diagSize.isValid() ) { diagramWidth = diagSize.width(); diagramHeight = diagSize.height(); } } // feature to the layer bool alwaysShow = mSettings.showAllDiagrams(); int ddColX = mSettings.xPosColumn; int ddColY = mSettings.yPosColumn; double ddPosX = 0.0; double ddPosY = 0.0; bool ddPos = ( ddColX >= 0 && ddColY >= 0 ); if ( ddPos && ! feat.attribute( ddColX ).isNull() && ! feat.attribute( ddColY ).isNull() ) { bool posXOk, posYOk; ddPosX = feat.attribute( ddColX ).toDouble( &posXOk ); ddPosY = feat.attribute( ddColY ).toDouble( &posYOk ); if ( !posXOk || !posYOk ) { ddPos = false; } else { QgsCoordinateTransform ct = mSettings.coordinateTransform(); if ( ct.isValid() && !ct.isShortCircuited() ) { double z = 0; ct.transformInPlace( ddPosX, ddPosY, z ); } //data defined diagram position is always centered ddPosX -= diagramWidth / 2.0; ddPosY -= diagramHeight / 2.0; } } else ddPos = false; int ddColShow = mSettings.showColumn; if ( ddColShow >= 0 && ! feat.attribute( ddColShow ).isNull() ) { bool showOk; bool ddShow = feat.attribute( ddColShow ).toDouble( &showOk ); if ( showOk && ! ddShow ) return nullptr; } QgsDiagramLabelFeature* lf = new QgsDiagramLabelFeature( feat.id(), geomCopy, QSizeF( diagramWidth, diagramHeight ) ); lf->setHasFixedPosition( ddPos ); lf->setFixedPosition( QgsPoint( ddPosX, ddPosY ) ); lf->setHasFixedAngle( true ); lf->setFixedAngle( 0 ); lf->setAlwaysShow( alwaysShow ); lf->setIsObstacle( mSettings.isObstacle() ); lf->setZIndex( mSettings.getZIndex() ); if ( geosObstacleGeomClone ) { lf->setObstacleGeometry( geosObstacleGeomClone ); } if ( dr ) { //append the diagram attributes to lbl lf->setAttributes( feat.attributes() ); } QgsPoint ptZero = mapSettings.mapToPixel().toMapCoordinates( 0, 0 ); QgsPoint ptOne = mapSettings.mapToPixel().toMapCoordinates( 1, 0 ); lf->setDistLabel( ptOne.distance( ptZero ) * mSettings.distance() ); return lf; }
void qSizeFFromScriptValue(const QScriptValue& object, QSizeF& qSizeF) { qSizeF.setWidth(object.property("width").toVariant().toFloat()); qSizeF.setHeight(object.property("height").toVariant().toFloat()); }
/** * Renders a \a cell with the given \a origin at \a pos, taking into account * the flipping and tile offset. * * For performance reasons, the actual drawing is delayed until a different * kind of tile has to be drawn. For this reason it is necessary to call * flush when finished doing drawCell calls. This function is also called by * the destructor so usually an explicit call is not needed. */ void CellRenderer::render(const Cell &cell, const QPointF &pos, const QSizeF &cellSize, Origin origin) { if (mTile != cell.tile) flush(); const QPixmap &image = cell.tile->currentFrameImage(); const QSizeF size = image.size(); const QSizeF objectSize = (cellSize == QSizeF(0,0)) ? size : cellSize; const QSizeF scale(objectSize.width() / size.width(), objectSize.height() / size.height()); const QPoint offset = cell.tile->offset(); const QPointF sizeHalf = QPointF(objectSize.width() / 2, objectSize.height() / 2); QPainter::PixmapFragment fragment; fragment.x = pos.x() + (offset.x() * scale.width()) + sizeHalf.x(); fragment.y = pos.y() + (offset.y() * scale.height()) + sizeHalf.y() - objectSize.height(); fragment.sourceLeft = 0; fragment.sourceTop = 0; fragment.width = size.width(); fragment.height = size.height(); fragment.scaleX = cell.flippedHorizontally ? -1 : 1; fragment.scaleY = cell.flippedVertically ? -1 : 1; fragment.rotation = 0; fragment.opacity = 1; bool flippedHorizontally = cell.flippedHorizontally; bool flippedVertically = cell.flippedVertically; if (origin == BottomCenter) fragment.x -= sizeHalf.x(); if (cell.flippedAntiDiagonally) { fragment.rotation = 90; flippedHorizontally = cell.flippedVertically; flippedVertically = !cell.flippedHorizontally; // Compensate for the swap of image dimensions const qreal halfDiff = sizeHalf.y() - sizeHalf.x(); fragment.y += halfDiff; if (origin != BottomCenter) fragment.x += halfDiff; } fragment.scaleX = scale.width() * (flippedHorizontally ? -1 : 1); fragment.scaleY = scale.height() * (flippedVertically ? -1 : 1); if (mIsOpenGL || (fragment.scaleX > 0 && fragment.scaleY > 0)) { mTile = cell.tile; mFragments.append(fragment); return; } // The Raster paint engine as of Qt 4.8.4 / 5.0.2 does not support // drawing fragments with a negative scaling factor. flush(); // make sure we drew all tiles so far const QTransform oldTransform = mPainter->transform(); QTransform transform = oldTransform; transform.translate(fragment.x, fragment.y); transform.rotate(fragment.rotation); transform.scale(fragment.scaleX, fragment.scaleY); const QRectF target(fragment.width * -0.5, fragment.height * -0.5, fragment.width, fragment.height); const QRectF source(0, 0, fragment.width, fragment.height); mPainter->setTransform(transform); mPainter->drawPixmap(target, image, source); mPainter->setTransform(oldTransform); }
void CorrlPlot::calcPositions() { // update flag geomChanged = false; if (mapXToY.size() > 0) { QSizeF size = worldSize(); double pix = pixelSize(); // calc sides of bounding box double xLft = -0.5*size.width()+20*pix; double xRgt = 0.5*size.width()-10*pix; double yTop = 0.5*size.height()-10*pix; double yBot = -0.5*size.height()+20*pix; // get number of values per axis double numX = attribute1->getSizeCurValues(); double numY = attribute2->getSizeCurValues(); // calc intervals per axis double fracX = 1.0; if (numX > 1) { fracX = (1.0/(double)(numX))*(xRgt-xLft); } double fracY = 1.0; if (numY > 1) { fracY = (1.0/(double)(numY))*(yTop-yBot); } // clear prev positions positions.clear(); radii.clear(); // calc positions double maxRadius = Utils::maxx(maxRadHintPx*pix, 0.5*Utils::minn(fracX, fracY)); for (size_t i = 0; i < mapXToY.size(); ++i) { vector< Position2D > tempPos; positions.push_back(tempPos); vector< double > tempRad; radii.push_back(tempRad); for (size_t j = 0; j < mapXToY[i].size(); ++j) { // fraction of total number double frac = (double)number[i][j]/(double)maxNumber; // radius double maxArea = PI*maxRadius*maxRadius; double area = frac*maxArea; double radius = sqrt(area/PI); if (radius < minRadHintPx*pix) { radius = minRadHintPx*pix; } radii[i].push_back(radius); double x = xLft + 0.5*fracX + i*fracX; double y = yBot + 0.5*fracY + mapXToY[i][j]*fracY; Position2D pos; pos.x = x; pos.y = y; positions[i].push_back(pos); } } // diagram scale factor to draw 120 x 120 pix diagram scaleDgrm = 120.0*(pix/2.0); } }
void QgsBrowserPropertiesWrapLabel::adjustHeight( const QSizeF& size ) { int height = size.height() + 2 * frameWidth(); setMinimumHeight( height ); setMaximumHeight( height ); }
void QSGPropertyAnimator::updateProperty(QObject *target, const QString& p) { QSGAnimatedProperty *ap = m_controller->registeredProperty(p, target); if (ap && m_duration > 0) { if (m_elapsed > m_startTime && ((m_elapsed < m_startTime + m_loops * m_duration) || (m_loops < 0))) { QVariant value = ap->value(); qreal tx = int(m_elapsed - m_startTime) % int(m_duration); switch (value.type()) { case QMetaType::Double: value = QVariant(m_from.toReal() + (m_to.toReal() - m_from.toReal()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QColor: { QColor from = qvariant_cast<QColor>(m_from); QColor to = qvariant_cast<QColor>(m_to); QColor result = qvariant_cast<QColor>(value); result.setRed(from.red() + (to.red() - from.red()) * m_easing.valueForProgress(tx / m_duration)); result.setGreen(from.green() + (to.green() - from.green()) * m_easing.valueForProgress(tx / m_duration)); result.setBlue(from.blue() + (to.blue() - from.blue()) * m_easing.valueForProgress(tx / m_duration)); result.setAlpha(from.alpha() + (to.alpha() - from.alpha()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::Int: value = QVariant(m_from.toInt() + (m_to.toInt() - m_from.toInt()) * m_easing.valueForProgress(tx / m_duration)); break; case QMetaType::QSize: { QSize from = m_from.toSize(); QSize to = m_to.toSize(); QSize result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QSizeF: { QSizeF from = m_from.toSize(); QSizeF to = m_to.toSize(); QSizeF result = value.toSize(); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPoint: { QPoint from = m_from.toPoint(); QPoint to = m_to.toPoint(); QPoint result = value.toPoint(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QPointF: { QPointF from = m_from.toPointF(); QPointF to = m_to.toPointF(); QPointF result = value.toPointF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRect: { QRect from = m_from.toRect(); QRect to = m_to.toRect(); QRect result = value.toRect(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QRectF: { QRectF from = m_from.toRectF(); QRectF to = m_to.toRectF(); QRectF result = value.toRectF(); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setWidth(from.width() + (to.width() - from.width()) * m_easing.valueForProgress(tx / m_duration)); result.setHeight(from.height() + (to.height() - from.height()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } case QMetaType::QVector3D: { QVector3D from = qvariant_cast<QVector3D>(m_from); QVector3D to = qvariant_cast<QVector3D>(m_to); QVector3D result = qvariant_cast<QVector3D>(value); result.setX(from.x() + (to.x() - from.x()) * m_easing.valueForProgress(tx / m_duration)); result.setY(from.y() + (to.y() - from.y()) * m_easing.valueForProgress(tx / m_duration)); result.setZ(from.z() + (to.z() - from.z()) * m_easing.valueForProgress(tx / m_duration)); value = result; break; } default: break; } ap->setValue(value); } } }
void InspectorImage::valueChanged(int idx) { QDoubleSpinBox* b1 = b.sizeWidth; QDoubleSpinBox* b2 = b.sizeHeight; QDoubleSpinBox* b3 = b.scaleWidth; QDoubleSpinBox* b4 = b.scaleHeight; Image* image = static_cast<Image*>(inspector->element()); if (idx == ImageControl::AUTOSCALE) { bool v = !b.autoscale->isChecked(); b1->setEnabled(v); b2->setEnabled(v); b.scaleWidth->setEnabled(v); b.scaleHeight->setEnabled(v); } if (idx == ImageControl::SIZE_W) { if (b.lockAspectRatio->isChecked()) { QSizeF sz = image->getProperty(P_ID::SIZE).toSizeF(); qreal ratio = sz.width() / sz.height(); qreal h = b1->value() / ratio; b2->blockSignals(true); b2->setValue(h); b2->blockSignals(false); InspectorBase::valueChanged(SIZE_H); } updateScaleFromSize(QSizeF(b1->value(), b2->value())); } else if (idx == ImageControl::SIZE_H) { if (b.lockAspectRatio->isChecked()) { QSizeF sz = image->getProperty(P_ID::SIZE).toSizeF(); qreal ratio = sz.width() / sz.height(); qreal w = b2->value() * ratio; b1->blockSignals(true); b1->setValue(w); b1->blockSignals(false); InspectorBase::valueChanged(ImageControl::SIZE_W); } updateScaleFromSize(QSizeF(b1->value(), b2->value())); } else if (idx == ImageControl::SCALE_W) { if (b.lockAspectRatio->isChecked()) { /* ImageControl::LOCK_RATIO keeps original ratio: // NEEDS case "else if(idx == ImageControl::LOCK_RATIO) ..." to restore original ratio on checking ImageControl::LOCK_RATIO b4->blockSignals(true); b4->setValue(b3->value()); b4->blockSignals(false);*/ /* ImageControl::LOCK_RATIO keeps current ratio: */ QSizeF sz = inspector->element()->getProperty(P_ID::SCALE).toSizeF(); qreal ratio = sz.width() / sz.height(); qreal w = b3->value() / ratio; b4->blockSignals(true); b4->setValue(w); b4->blockSignals(false); InspectorBase::valueChanged(ImageControl::SCALE_H); } updateSizeFromScale(QSizeF(b3->value(), b4->value())); } else if (idx == SCALE_H) { if (b.lockAspectRatio->isChecked()) { /* ImageControl::LOCK_RATIO keeps original ratio: // NEEDS case "else if(idx == ImageControl::LOCK_RATIO) ..." to restore original ratio on checking ImageControl::LOCK_RATIO b3->blockSignals(true); b3->setValue(b4->value()); b3->blockSignals(false);*/ /* ImageControl::LOCK_RATIO keeps current ratio: */ QSizeF sz = inspector->element()->getProperty(P_ID::SCALE).toSizeF(); qreal ratio = sz.width() / sz.height(); qreal w = b4->value() * ratio; b3->blockSignals(true); b3->setValue(w); b3->blockSignals(false); InspectorBase::valueChanged(ImageControl::SCALE_W); } updateSizeFromScale(QSizeF(b3->value(), b4->value())); } else if (idx == SIZE_IS_SPATIUM) { QCheckBox* cb = static_cast<QCheckBox*>(iList[idx].w); qreal _spatium = inspector->element()->spatium(); b1->blockSignals(true); b2->blockSignals(true); if (cb->isChecked()) { b1->setSuffix("sp"); b2->setSuffix("sp"); b1->setValue(b1->value() * DPMM / _spatium); b2->setValue(b2->value() * DPMM / _spatium); } else { b1->setSuffix("mm"); b2->setSuffix("mm"); b1->setValue(b1->value() * _spatium / DPMM); b2->setValue(b2->value() * _spatium / DPMM); } b1->blockSignals(false); b2->blockSignals(false); } InspectorBase::valueChanged(idx); }
void ExpandingTextEdit::updateHeight(const QSizeF &documentSize) { m_minimumHeight = qRound(documentSize.height()) + frameWidth() * 2; updateGeometry(); }
QScriptValue qSizeFToScriptValue(QScriptEngine* engine, const QSizeF& qSizeF) { QScriptValue obj = engine->newObject(); obj.setProperty("width", qSizeF.width()); obj.setProperty("height", qSizeF.height()); return obj; }
void CanvasSizeDialog::setupDialog(const QSizeF & size, const QString & sizeUnits, const QSizeF & resolution, const QString & resolutionUnits) { this->setCaption(i18n("Canvas size")); QWidget * main = new QWidget(this); setMainWidget(main); QVBoxLayout * vLayout = new QVBoxLayout(main); main->setLayout(vLayout); /// ----------------------- TEMPLATES PART ----------------------- QGridLayout * gridLayout = new QGridLayout(); d->paperSize = new KComboBox(main); d->paperSize->addItem( "Custom" ); d->paperSize->insertSeparator(1); d->paperSize->addItems(d->paperSizes.keys()); d->paperSize->setCurrentIndex(0); gridLayout->addWidget(new QLabel("Template:", main),0,0); gridLayout->addWidget(d->paperSize,0,1); vLayout->addLayout(gridLayout); /// ----------------------- CANVAS SIZE PART ----------------------- d->sizeWidget = new QGroupBox(i18n("Canvas size"), main); vLayout->addWidget(d->sizeWidget); gridLayout = new QGridLayout(d->sizeWidget); d->sizeWidget->setLayout(gridLayout); // Width widget d->xSize = new QDoubleSpinBox(d->sizeWidget); d->xSize->setMinimum(0.00001); d->xSize->setMaximum(999999); d->xSize->setValue(size.width()); d->WIDTH = CanvasSize::toPixels(size.width(), resolution.width(), CanvasSize::sizeUnit(sizeUnits), CanvasSize::resolutionUnit(resolutionUnits)); gridLayout->addWidget(new QLabel("Width:", d->sizeWidget),0,0); gridLayout->addWidget(d->xSize,0,1); // Height widget d->ySize = new QDoubleSpinBox(d->sizeWidget); d->ySize->setMinimum(0.00001); d->ySize->setMaximum(999999); d->ySize->setValue(size.height()); d->HEIGHT = CanvasSize::toPixels(size.height(), resolution.height(), CanvasSize::sizeUnit(sizeUnits), CanvasSize::resolutionUnit(resolutionUnits)); gridLayout->addWidget(new QLabel("Height:", d->sizeWidget),1,0); gridLayout->addWidget(d->ySize,1,1); // Unit widget d->sizeUnitsWidget = new KComboBox(d->sizeWidget); d->sizeUnitsWidget->addItems(CanvasSize::sizeUnitsNames()); d->sizeUnitsWidget->setCurrentItem(sizeUnits); d->currentSizeUnit = sizeUnits; gridLayout->addWidget(d->sizeUnitsWidget,1,2); // Orientation buttons d->horizontalButton = new KPushButton(KIcon(":horizontal_orientation.png"),"",d->sizeWidget); d->horizontalButton->setCheckable(true); d->horizontalButton->setFlat(true); d->horizontalButton->setIconSize(QSize(24,24)); d->verticalButton = new KPushButton(KIcon(":vertical_orientation.png"),"",d->sizeWidget); d->verticalButton->setCheckable(true); d->verticalButton->setFlat(true); d->verticalButton->setIconSize(QSize(24,24)); QHBoxLayout * hLayout = new QHBoxLayout(); hLayout->addWidget(d->horizontalButton); hLayout->addWidget(d->verticalButton); gridLayout->addWidget(new QLabel("Orientation:", d->sizeWidget),2,0); gridLayout->addLayout(hLayout,2,1); d->sizeLabel = new QLabel(d->sizeWidget); gridLayout->addWidget(d->sizeLabel,2, 2); /// ----------------------- ADVANCED PART ----------------------- d->advancedWidget = new QGroupBox(i18n("Advanced"), main); vLayout->addWidget(d->advancedWidget); gridLayout = new QGridLayout(d->advancedWidget); d->advancedWidget->setLayout(gridLayout); // x resolution widget d->xResolution = new QDoubleSpinBox(d->advancedWidget); d->xResolution->setMinimum(0); d->xResolution->setMaximum(999999); d->xResolution->setValue(resolution.width()); d->xResolution->setDecimals(3); d->WIDTH_RES = resolution.width() * CanvasSize::resolutionUnitFactor(resolutionUnits); gridLayout->addWidget(new QLabel("Resolution X:", d->advancedWidget),0,0); gridLayout->addWidget(d->xResolution,0,1); // y resolution widget d->yResolution = new QDoubleSpinBox(d->advancedWidget); d->yResolution->setMinimum(0); d->yResolution->setMaximum(999999); d->yResolution->setValue(resolution.height()); d->yResolution->setDecimals(3); d->HEIGHT_RES = resolution.height() * CanvasSize::resolutionUnitFactor(resolutionUnits); gridLayout->addWidget(new QLabel("Resolution Y:", d->advancedWidget),1,0); gridLayout->addWidget(d->yResolution,1,1); // Unit widget d->resolutionUnitsWidget = new KComboBox(d->sizeWidget); d->resolutionUnitsWidget->addItems(CanvasSize::resolutionUnitsNames()); d->resolutionUnitsWidget->setCurrentItem(resolutionUnits); d->currentResolutionUnit = resolutionUnits; gridLayout->addWidget(d->resolutionUnitsWidget,1,2); this->prepareSignalsConnections(); d->updateSizeLabel(); }