本文整理汇总了C++中QRectF::width方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::width方法的具体用法?C++ QRectF::width怎么用?C++ QRectF::width使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRectF
的用法示例。
在下文中一共展示了QRectF::width方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resizeToZoneContents
void ZoneViewWidget::resizeToZoneContents()
{
QRectF zoneRect = zone->getOptimumRect();
qreal totalZoneHeight = zoneRect.height();
if (zoneRect.height() > 500)
zoneRect.setHeight(500);
QSizeF newSize(qMax(QGraphicsWidget::layout()->effectiveSizeHint(Qt::MinimumSize, QSizeF()).width(), zoneRect.width() + scrollBar->width() + 10), zoneRect.height() + extraHeight + 10);
setMaximumSize(newSize);
resize(newSize);
zone->setGeometry(QRectF(0, -scrollBar->value(), zoneContainer->size().width(), totalZoneHeight));
scrollBar->setMaximum(totalZoneHeight - zoneRect.height());
if (layout())
layout()->invalidate();
}
示例2: paintEvent
void QtGradientWidget::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
QPainter p(this);
if (d_ptr->m_backgroundCheckered) {
int pixSize = 40;
QPixmap pm(2 * pixSize, 2 * pixSize);
QPainter pmp(&pm);
pmp.fillRect(0, 0, pixSize, pixSize, Qt::white);
pmp.fillRect(pixSize, pixSize, pixSize, pixSize, Qt::white);
pmp.fillRect(0, pixSize, pixSize, pixSize, Qt::black);
pmp.fillRect(pixSize, 0, pixSize, pixSize, Qt::black);
p.setBrushOrigin((size().width() % pixSize + pixSize) / 2, (size().height() % pixSize + pixSize) / 2);
p.fillRect(rect(), pm);
p.setBrushOrigin(0, 0);
}
QGradient *gradient = 0;
switch (d_ptr->m_gradientType) {
case QGradient::LinearGradient:
gradient = new QLinearGradient(d_ptr->m_startLinear, d_ptr->m_endLinear);
break;
case QGradient::RadialGradient:
gradient = new QRadialGradient(d_ptr->m_centralRadial, d_ptr->m_radiusRadial, d_ptr->m_focalRadial);
break;
case QGradient::ConicalGradient:
gradient = new QConicalGradient(d_ptr->m_centralConical, d_ptr->m_angleConical);
break;
default:
break;
}
if (!gradient)
return;
gradient->setStops(d_ptr->m_gradientStops);
gradient->setSpread(d_ptr->m_gradientSpread);
p.save();
p.scale(size().width(), size().height());
p.fillRect(QRect(0, 0, 1, 1), *gradient);
p.restore();
p.setRenderHint(QPainter::Antialiasing);
QColor c = QColor::fromRgbF(0.5, 0.5, 0.5, 0.5);
QBrush br(c);
p.setBrush(br);
QPen pen(Qt::white);
pen.setWidthF(1);
p.setPen(pen);
QPen dragPen = pen;
dragPen.setWidthF(2);
if (d_ptr->m_gradientType == QGradient::LinearGradient) {
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::StartLinearHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_startLinear, d_ptr->m_handleSize);
p.restore();
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::EndLinearHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_endLinear, d_ptr->m_handleSize);
p.restore();
} else if (d_ptr->m_gradientType == QGradient::RadialGradient) {
QPointF central = d_ptr->toViewport(d_ptr->m_centralRadial);
p.save();
QRectF r = d_ptr->pointRect(central, 2 * d_ptr->m_handleSize / 3);
QRectF r1(0, r.y(), size().width(), r.height());
QRectF r2(r.x(), 0, r.width(), r.y());
QRectF r3(r.x(), r.y() + r.height(), r.width(), size().height() - r.y() - r.height());
p.fillRect(r1, c);
p.fillRect(r2, c);
p.fillRect(r3, c);
p.setBrush(Qt::NoBrush);
p.save();
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::CentralRadialHandle)
p.setPen(dragPen);
d_ptr->paintPoint(&p, d_ptr->m_centralRadial, d_ptr->m_handleSize);
p.restore();
const QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial * size().width(),
central.y() - d_ptr->m_radiusRadial * size().height(),
2 * d_ptr->m_radiusRadial * size().width(),
2 * d_ptr->m_radiusRadial * size().height());
QRegion region(r1.toRect());
region += r2.toRect();
region += r3.toRect();
p.setClipRegion(region);
p.drawEllipse(rect);
if (d_ptr->m_dragHandle == QtGradientWidgetPrivate::RadiusRadialHandle) {
p.save();
p.setPen(dragPen);
QRectF rect = QRectF(central.x() - d_ptr->m_radiusRadial / d_ptr->m_radiusFactor * size().width(),
//.........这里部分代码省略.........
示例3: paint
void TopologyNode::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
Q_UNUSED(widget)
QRectF itemRect = boundingRect();
#ifdef POWERLINE_REVISION
if(m_name == QString("POWERLINE"))
{
QString imagePath;
if(option->state & QStyle::State_MouseOver)
{
imagePath = GENIE2_RES("map/devices/PowerLineSelected.png");
}
else
{
imagePath = GENIE2_RES("map/devices/PowerLineNormal.png");
}
QPixmap nodePixmap(imagePath);
painter->drawPixmap(itemRect.topLeft(),nodePixmap);
return;
}
#endif
#ifdef PLUGIN_TARGET
if((mNodeFlags & NF_ISCENTRALROUTER)||(m_deviceType==MDT_ROUTER))
{
Q_ASSERT (m_paintStrategy);
m_paintStrategy->paint(painter,(option->state & QStyle::State_MouseOver),(mNodeFlags &NF_ISONLINE));
}
else
#endif
{
int pixmapRole = DTIR_NORMAL;
if((option->state & QStyle::State_MouseOver) && (mNodeFlags & NF_ISONLINE) && (m_deviceType != MDT_INTERNET))
{
pixmapRole = DTIR_SELECTED;
}
else if(!(mNodeFlags&NF_ISONLINE))
{
pixmapRole = DTIR_OFFLINE;
}
QString pixmapPath;
if(mNodeFlags & NF_ISLOCALHOST)
{
pixmapPath = getLocalHostImagePath(pixmapRole);
}
else if(mNodeFlags & NF_ISCENTRALROUTER)
{
pixmapPath = getCentralRouterImagePath(pixmapRole);
}
else
{
pixmapPath = getDeviceTypeImagePath(m_deviceType,pixmapRole);
}
QPixmap nodePixmap(pixmapPath);
painter->drawPixmap(itemRect.topLeft(),nodePixmap);
}
//draw indicator pixmap
paintSubIcons(painter,itemRect);
//draw name
if(!(mNodeFlags & NF_ISCENTRALROUTER) && (m_deviceType != MDT_INTERNET )
&&(m_deviceType != MDT_ROUTER))
{
QColor penColor = ((mNodeFlags & NF_ISONLINE) ? ((option->state & QStyle::State_MouseOver) ? Qt::white : Qt::black) : QColor(204,204,204));
painter->setPen(penColor);
QFont font(painter->font());
#ifdef Q_OS_MACX
font.setPointSize(10);
#else
font.setPointSize(8);
#endif
painter->setFont(font);
QFontMetrics fm(font);
QString labelText = m_name;
if(fm.width(labelText) > (itemRect.width() - 2*fm.width('X')))
{
for(int k = 0 ; k < labelText.size() ; ++k)
{
if(fm.width(labelText.left(k)) + fm.width("...") >= (itemRect.width() - 2*fm.width('X')))
{
labelText = labelText.left(k) + "...";
break;
}
//.........这里部分代码省略.........
示例4: plot
void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
{
struct divecomputer *dc;
if (d)
dc = select_dc(&d->dc);
if (!forceRedraw && dive == d && (d && dc == diveDC))
return;
clear();
dive = d;
diveDC = d ? dc : NULL;
if (!isVisible() || !dive) {
return;
}
scene()->setSceneRect(0,0, viewport()->width()-50, viewport()->height()-50);
QSettings s;
s.beginGroup("ProfileMap");
QPointF toolTipPos = s.value("tooltip_position", QPointF(0,0)).toPointF();
s.endGroup();
toolTip = new ToolTipItem();
toolTip->setPos(toolTipPos);
scene()->addItem(toolTip);
// Fix this for printing / screen later.
// plot_set_scale(scale_mode_t);
if (!dc->samples) {
static struct sample fake[4];
static struct divecomputer fakedc;
fakedc = dive->dc;
fakedc.sample = fake;
fakedc.samples = 4;
/* The dive has no samples, so create a few fake ones. This assumes an
ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
int duration = dive->dc.duration.seconds;
int maxdepth = dive->dc.maxdepth.mm;
int asc_desc_time = dive->dc.maxdepth.mm*60/9000;
if (asc_desc_time * 2 >= duration)
asc_desc_time = duration / 2;
fake[1].time.seconds = asc_desc_time;
fake[1].depth.mm = maxdepth;
fake[2].time.seconds = duration - asc_desc_time;
fake[2].depth.mm = maxdepth;
fake[3].time.seconds = duration * 1.00;
fakedc.events = dc->events;
dc = &fakedc;
}
/*
* Set up limits that are independent of
* the dive computer
*/
calculate_max_limits(dive, dc, &gc);
QRectF profile_grid_area = scene()->sceneRect();
gc.maxx = (profile_grid_area.width() - 2 * profile_grid_area.x());
gc.maxy = (profile_grid_area.height() - 2 * profile_grid_area.y());
/* This is per-dive-computer. Right now we just do the first one */
gc.pi = *create_plot_info(dive, dc, &gc);
/* Depth profile */
plot_depth_profile();
plot_events(dc);
/* Temperature profile */
plot_temperature_profile();
/* Cylinder pressure plot */
plot_cylinder_pressure(dive, dc);
/* Text on top of all graphs.. */
plot_temperature_text();
plot_depth_text();
plot_cylinder_pressure_text();
plot_deco_text();
/* Bounding box */
QPen pen = defaultPen;
pen.setColor(profile_color[TIME_GRID].at(0));
QGraphicsRectItem *rect = new QGraphicsRectItem(profile_grid_area);
rect->setPen(pen);
scene()->addItem(rect);
/* Put the dive computer name in the lower left corner */
QString nick(get_dc_nickname(dc->model, dc->deviceid));
if (nick.isEmpty())
nick = QString(dc->model);
//.........这里部分代码省略.........
示例5: expandLineBreaks
/*!
Expand all line breaks in text labels, and calculate the height
of their widgets in orientation of the text.
\param options Options how to layout the legend
\param rect Bounding rectangle for title, footer, axes and canvas.
\param dimTitle Expanded height of the title widget
\param dimFooter Expanded height of the footer widget
\param dimAxis Expanded heights of the axis in axis orientation.
\sa Options
*/
void QwtPlotLayout::expandLineBreaks( Options options, const QRectF &rect,
int &dimTitle, int &dimFooter, int dimAxis[QwtPlot::axisCnt] ) const
{
dimTitle = dimFooter = 0;
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
dimAxis[axis] = 0;
int backboneOffset[QwtPlot::axisCnt];
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
backboneOffset[axis] = 0;
if ( !( options & IgnoreFrames ) )
backboneOffset[axis] += d_data->layoutData.canvas.contentsMargins[ axis ];
if ( !d_data->alignCanvasToScales[axis] )
backboneOffset[axis] += d_data->canvasMargin[axis];
}
bool done = false;
while ( !done )
{
done = true;
// the size for the 4 axis depend on each other. Expanding
// the height of a horizontal axis will shrink the height
// for the vertical axis, shrinking the height of a vertical
// axis will result in a line break what will expand the
// width and results in shrinking the width of a horizontal
// axis what might result in a line break of a horizontal
// axis ... . So we loop as long until no size changes.
if ( !( ( options & IgnoreTitle ) ||
d_data->layoutData.title.text.isEmpty() ) )
{
double w = rect.width();
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
!= d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
{
// center to the canvas
w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight];
}
int d = qCeil( d_data->layoutData.title.text.heightForWidth( w ) );
if ( !( options & IgnoreFrames ) )
d += 2 * d_data->layoutData.title.frameWidth;
if ( d > dimTitle )
{
dimTitle = d;
done = false;
}
}
if ( !( ( options & IgnoreFooter ) ||
d_data->layoutData.footer.text.isEmpty() ) )
{
double w = rect.width();
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
!= d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
{
// center to the canvas
w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight];
}
int d = qCeil( d_data->layoutData.footer.text.heightForWidth( w ) );
if ( !( options & IgnoreFrames ) )
d += 2 * d_data->layoutData.footer.frameWidth;
if ( d > dimFooter )
{
dimFooter = d;
done = false;
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
const struct LayoutData::t_scaleData &scaleData =
d_data->layoutData.scale[axis];
if ( scaleData.isEnabled )
{
double length;
if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
{
length = rect.width() - dimAxis[QwtPlot::yLeft]
//.........这里部分代码省略.........
示例6: addCentroid
void QGL2PEXVertexArray::addPath(const QVectorPath &path, GLfloat curveInverseScale, bool outline)
{
const QPointF* const points = reinterpret_cast<const QPointF*>(path.points());
const QPainterPath::ElementType* const elements = path.elements();
if (boundingRectDirty) {
minX = maxX = points[0].x();
minY = maxY = points[0].y();
boundingRectDirty = false;
}
if (!outline && !path.isConvex())
addCentroid(path, 0);
int lastMoveTo = vertexArray.size();
vertexArray.add(points[0]); // The first element is always a moveTo
do {
if (!elements) {
// qDebug("QVectorPath has no elements");
// If the path has a null elements pointer, the elements implicitly
// start with a moveTo (already added) and continue with lineTos:
for (int i=1; i<path.elementCount(); ++i)
lineToArray(points[i].x(), points[i].y());
break;
}
// qDebug("QVectorPath has element types");
for (int i=1; i<path.elementCount(); ++i) {
switch (elements[i]) {
case QPainterPath::MoveToElement:
if (!outline)
addClosingLine(lastMoveTo);
// qDebug("element[%d] is a MoveToElement", i);
vertexArrayStops.add(vertexArray.size());
if (!outline) {
if (!path.isConvex()) addCentroid(path, i);
lastMoveTo = vertexArray.size();
}
lineToArray(points[i].x(), points[i].y()); // Add the moveTo as a new vertex
break;
case QPainterPath::LineToElement:
// qDebug("element[%d] is a LineToElement", i);
lineToArray(points[i].x(), points[i].y());
break;
case QPainterPath::CurveToElement: {
QBezier b = QBezier::fromPoints(*(((const QPointF *) points) + i - 1),
points[i],
points[i+1],
points[i+2]);
QRectF bounds = b.bounds();
// threshold based on same algorithm as in qtriangulatingstroker.cpp
int threshold = qMin<float>(64, qMax(bounds.width(), bounds.height()) * 3.14f / (curveInverseScale * 6));
if (threshold < 3) threshold = 3;
qreal one_over_threshold_minus_1 = qreal(1) / (threshold - 1);
for (int t=0; t<threshold; ++t) {
QPointF pt = b.pointAt(t * one_over_threshold_minus_1);
lineToArray(pt.x(), pt.y());
}
i += 2;
break; }
default:
break;
}
}
} while (0);
if (!outline)
addClosingLine(lastMoveTo);
vertexArrayStops.add(vertexArray.size());
}
示例7: drawLegendIdentifier
/*!
\brief Draw the identifier representing the curve on the legend
\param painter Üainter
\param rect Bounding rectangle for the identifier
\sa setLegendAttribute
*/
void QwtPlotCurve::drawLegendIdentifier(
QPainter *painter, const QRectF &rect ) const
{
if ( rect.isEmpty() )
return;
const int dim = qMin( rect.width(), rect.height() );
QSize size( dim, dim );
QRectF r( 0, 0, size.width(), size.height() );
r.moveCenter( rect.center() );
if ( d_data->legendAttributes == 0 )
{
QBrush brush = d_data->brush;
if ( brush.style() == Qt::NoBrush )
{
if ( style() != QwtPlotCurve::NoCurve )
brush = QBrush( pen().color() );
else if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
brush = QBrush( d_data->symbol->pen().color() );
}
}
if ( brush.style() != Qt::NoBrush )
painter->fillRect( r, brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowBrush )
{
if ( d_data->brush.style() != Qt::NoBrush )
painter->fillRect( r, d_data->brush );
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowLine )
{
if ( pen() != Qt::NoPen )
{
painter->setPen( pen() );
QwtPainter::drawLine( painter, rect.left(), rect.center().y(),
rect.right() - 1.0, rect.center().y() );
}
}
if ( d_data->legendAttributes & QwtPlotCurve::LegendShowSymbol )
{
if ( d_data->symbol &&
( d_data->symbol->style() != QwtSymbol::NoSymbol ) )
{
QSize symbolSize = d_data->symbol->boundingSize();
symbolSize -= QSize( 2, 2 );
// scale the symbol size down if it doesn't fit into rect.
double xRatio = 1.0;
if ( rect.width() < symbolSize.width() )
xRatio = rect.width() / symbolSize.width();
double yRatio = 1.0;
if ( rect.height() < symbolSize.height() )
yRatio = rect.height() / symbolSize.height();
const double ratio = qMin( xRatio, yRatio );
painter->save();
painter->scale( ratio, ratio );
d_data->symbol->drawSymbol( painter, rect.center() / ratio );
painter->restore();
}
}
}
示例8: drawMapObject
void IsometricRenderer::drawMapObject(QPainter *painter,
const MapObject *object,
const QColor &color) const
{
painter->save();
QPen pen(Qt::black);
if (object->tile()) {
const QPixmap &img = object->tile()->image();
QPointF paintOrigin(-img.width() / 2, -img.height());
paintOrigin += tileToPixelCoords(object->position()).toPoint();
painter->drawPixmap(paintOrigin, img);
const QFontMetrics fm = painter->fontMetrics();
QString name = fm.elidedText(object->name(), Qt::ElideRight,
img.width() + 2);
if (!name.isEmpty())
painter->drawText(QPoint(paintOrigin.x(), paintOrigin.y() - 5 + 1), name);
pen.setStyle(Qt::SolidLine);
painter->setPen(pen);
painter->drawRect(QRectF(paintOrigin, img.size()));
pen.setStyle(Qt::DotLine);
pen.setColor(color);
painter->setPen(pen);
painter->drawRect(QRectF(paintOrigin, img.size()));
if (!name.isEmpty())
painter->drawText(QPoint(paintOrigin.x(), paintOrigin.y() - 5), name);
} else {
QColor brushColor = color;
brushColor.setAlpha(50);
QBrush brush(brushColor);
pen.setJoinStyle(Qt::RoundJoin);
pen.setCapStyle(Qt::RoundCap);
pen.setWidth(2);
painter->setPen(pen);
painter->setRenderHint(QPainter::Antialiasing);
// TODO: Draw the object name
// TODO: Do something sensible to make null-sized objects usable
switch (object->shape()) {
case MapObject::Ellipse: {
QPointF topLeft(tileToPixelCoords(object->bounds().topLeft()));
QPointF bottomLeft(tileToPixelCoords(object->bounds().bottomLeft()));
QPointF topRight(tileToPixelCoords(object->bounds().topRight()));
const qreal headerX = bottomLeft.x();
const qreal headerY = topLeft.y();
QRectF rect(bottomLeft, topRight);
const QFontMetrics fm = painter->fontMetrics();
QString name = fm.elidedText(object->name(), Qt::ElideRight,
rect.width() + 2);
QPolygonF polygon = tileRectToPolygon(object->bounds());
float tw = map()->tileWidth();
float th = map()->tileHeight();
QPointF transformScale(1, 1);
if (tw > th)
transformScale = QPointF(1, th/tw);
else
transformScale = QPointF(tw/th, 1);
QPointF l1 = polygon.at(1) - polygon.at(0);
QPointF l2 = polygon.at(3) - polygon.at(0);
QTransform trans;
trans.scale(transformScale.x(), transformScale.y());
trans.rotate(45);
QTransform iTrans = trans.inverted();
QPointF l1x = iTrans.map(l1);
QPointF l2x = iTrans.map(l2);
QSizeF ellipseSize(l1x.manhattanLength(), l2x.manhattanLength());
painter->save();
painter->setPen(pen);
painter->translate(polygon.at(0));
painter->scale(transformScale.x(), transformScale.y());
painter->rotate(45);
painter->drawEllipse(QRectF(QPointF(0, 0), ellipseSize));
painter->restore();
painter->setBrush(Qt::NoBrush);
painter->drawPolygon(polygon);
if (!name.isEmpty())
painter->drawText(QPoint(headerX, headerY - 5), name);
pen.setColor(color);
painter->setPen(pen);
painter->setBrush(Qt::NoBrush);
painter->translate(QPointF(0, -1));
painter->drawPolygon(polygon);
//.........这里部分代码省略.........
示例9: parseDoc
bool OsmImport::parseDoc(QDomDocument &doc)
{
QDomNodeList list = doc.elementsByTagName("node");
for (int i = 0; i < list.count(); i++)
{
nodes.append(new osmNode(list.at(i).toElement()));
}
list = doc.elementsByTagName("way");
for (int i = 0; i < list.count(); i++)
{
ways.append(new osmWay(list.at(i).toElement(), nodes));
}
bool importPrimary();
bool importSecondary();
bool importTertiary();
bool importMotorway();
bool importService();
bool importPath();
bool importSteps();
bool importTrack();
bool importFootway();
bool importResidential();
bool importLiving_street();
bool importCycleway();
bool importTurning_circle();
bool importPedestrian();
bool importUnclassified();
bool doPrimary = ImportSettings::instance()->importPrimary();
bool doSecondary = ImportSettings::instance()->importSecondary();
bool doTertiary = ImportSettings::instance()->importTertiary();
bool doMotorway = ImportSettings::instance()->importMotorway();
bool doService = ImportSettings::instance()->importService();
bool doPath = ImportSettings::instance()->importPath();
bool doSteps = ImportSettings::instance()->importSteps();
bool doTrack = ImportSettings::instance()->importTrack();
bool doFootpath = ImportSettings::instance()->importFootway();
bool doResidential = ImportSettings::instance()->importResidential();
bool doLiving_street = ImportSettings::instance()->importLiving_street();
bool doCycleway = ImportSettings::instance()->importCycleway();
bool doTurning_circle = ImportSettings::instance()->importTurning_circle();
bool doPedestrian = ImportSettings::instance()->importPedestrian();
bool doUnclassified = ImportSettings::instance()->importUnclassified();
for (int i = 0; i < ways.count(); i++)
{
osmWay *w = ways.at(i);
osmWay::wayType t = w->type;
if ((t == osmWay::primary && doPrimary) ||
(t == osmWay::secondary && doSecondary) ||
(t == osmWay::tertiary && doTertiary) ||
(t == osmWay::motorway && doMotorway) ||
(t == osmWay::service && doService) ||
(t == osmWay::path && doPath) ||
(t == osmWay::steps && doSteps) ||
(t == osmWay::track && doTrack) ||
(t == osmWay::footway && doFootpath) ||
(t == osmWay::residential && doResidential) ||
(t == osmWay::living_street && doLiving_street) ||
(t == osmWay::cycleway && doCycleway) ||
(t == osmWay::turning_circle && doTurning_circle) ||
(t == osmWay::pedestrian && doPedestrian) ||
(t == osmWay::unclassified && doUnclassified))
{
project->XVector = w->XVector;
project->YVector = w->YVector;
project->ZVector = w->ZVector;
if (project->XVector.size() > 0)
{
project->addLineStrip(w->name,w->maxSpeed,w->bridge,w->numLanes,w->type);
}
}
}
qDeleteAll(ways.begin(), ways.end());
qDeleteAll(nodes.begin(), nodes.end());
ways.clear();
nodes.clear();
// resize
BoundingBoxVisitor *visitor = new BoundingBoxVisitor();
project->getProjectData()->getRoadSystem()->accept(visitor);
project->getProjectData()->getScenerySystem()->accept(visitor);
QRectF box = visitor->getBoundingBox();
SetProjectDimensionsCommand *command = new SetProjectDimensionsCommand(project->getProjectData(), box.bottom() + 0.1 * box.height(), box.top() - 0.1 * box.height(), box.right() + 0.1 * box.width(), box.left() - 0.1 * box.width());
project->getProjectSettings()->executeCommand(command);
return true;
}
示例10: shift
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
{
int map[4];
bool p1_p2_equal = (orig->x1 == orig->x2 && orig->y1 == orig->y2);
bool p2_p3_equal = (orig->x2 == orig->x3 && orig->y2 == orig->y3);
bool p3_p4_equal = (orig->x3 == orig->x4 && orig->y3 == orig->y4);
QPointF points[4];
int np = 0;
points[np] = QPointF(orig->x1, orig->y1);
map[0] = 0;
++np;
if (!p1_p2_equal) {
points[np] = QPointF(orig->x2, orig->y2);
++np;
}
map[1] = np - 1;
if (!p2_p3_equal) {
points[np] = QPointF(orig->x3, orig->y3);
++np;
}
map[2] = np - 1;
if (!p3_p4_equal) {
points[np] = QPointF(orig->x4, orig->y4);
++np;
}
map[3] = np - 1;
if (np == 1)
return Discard;
QRectF b = orig->bounds();
if (np == 4 && b.width() < .1*offset && b.height() < .1*offset) {
qreal l = (orig->x1 - orig->x2)*(orig->x1 - orig->x2) +
(orig->y1 - orig->y2)*(orig->y1 - orig->y2) *
(orig->x3 - orig->x4)*(orig->x3 - orig->x4) +
(orig->y3 - orig->y4)*(orig->y3 - orig->y4);
qreal dot = (orig->x1 - orig->x2)*(orig->x3 - orig->x4) +
(orig->y1 - orig->y2)*(orig->y3 - orig->y4);
if (dot < 0 && dot*dot < 0.8*l)
// the points are close and reverse dirction. Approximate the whole
// thing by a semi circle
return Circle;
}
QPointF points_shifted[4];
QLineF prev = QLineF(QPointF(), points[1] - points[0]);
QPointF prev_normal = prev.normalVector().unitVector().p2();
points_shifted[0] = points[0] + offset * prev_normal;
for (int i = 1; i < np - 1; ++i) {
QLineF next = QLineF(QPointF(), points[i + 1] - points[i]);
QPointF next_normal = next.normalVector().unitVector().p2();
QPointF normal_sum = prev_normal + next_normal;
qreal r = qreal(1.0) + prev_normal.x() * next_normal.x()
+ prev_normal.y() * next_normal.y();
if (qFuzzyIsNull(r)) {
points_shifted[i] = points[i] + offset * prev_normal;
} else {
qreal k = offset / r;
points_shifted[i] = points[i] + k * normal_sum;
}
prev_normal = next_normal;
}
points_shifted[np - 1] = points[np - 1] + offset * prev_normal;
*shifted = QBezier::fromPoints(points_shifted[map[0]], points_shifted[map[1]],
points_shifted[map[2]], points_shifted[map[3]]);
return good_offset(orig, shifted, offset, threshold);
}
示例11: resized
//-------------------------------------------------------------------------
void QGuidoItemContainer::resized(const QRectF& newRect)
{
if ( newRect.toRect() == rect().toRect() )
return;
if ( mResizeMode == RESIZE_GRID )
{
QRectF oldRect = rect();
mGuidoItem->setGridWidth( mGuidoItem->gridWidth() * newRect.width() / rect().width() + 0.5f );
mGuidoItem->setGridHeight( mGuidoItem->gridHeight() * newRect.height() / rect().height() + 0.5f );
guidoGeometryChanged();
QSizeF dSize( rect().size() - oldRect.size() );
moveBy( dSize.width() * ( newRect.x() ? -1 : 0 ) , dSize.height() * ( newRect.y() ? -1 : 0 ) );
}
else if ( mResizeMode == RESIZE_FORMAT )
{
QRectF oldRect = rect();
GuidoPageFormat f = mGuidoItem->guidoPageFormat();
f.width = f.width * newRect.width() / rect().width();
f.height = f.height * newRect.height() / rect().height();
mGuidoItem->setGuidoPageFormat(f);
//Control if how the page format was actually supported,
//and set it to its actual value.
if ( rect().toRect() != newRect.toRect() ) //has use int comparison, float isn't reliable
{
f = mGuidoItem->guidoPageFormat();
f.width = f.width * rect().width() / newRect.width();
f.height = f.height * rect().height() / newRect.height();
mGuidoItem->setGuidoPageFormat(f);
}
QSizeF dSize( rect().size() - oldRect.size() );
// moveBy( newRect.x() , newRect.y() );
moveBy( dSize.width() * ( newRect.x() ? -1 : 0 ) , dSize.height() * ( newRect.y() ? -1 : 0 ) );
}
else
{
float xScale = mGuidoItem->transform().m11();
float yScale = mGuidoItem->transform().m22();
float dx = newRect.x();
float dy = newRect.y();
float sx = ( newRect.width() / rect().width() );
float sy = ( newRect.height() / rect().height() );
float boundedSx = sx;
float boundedSy = sy;
if ( mMaxScale )
boundedSx = qMin( mMaxScale/xScale , boundedSx );
boundedSx = qMax( mMinScale/xScale , boundedSx );
if ( mMaxScale )
boundedSy = qMin( mMaxScale/yScale , boundedSy );
boundedSy = qMax( mMinScale/yScale , boundedSy );
dx = dx * (boundedSx - 1 ) / ( sx - 1 );
dy = dy * (boundedSy - 1 ) / ( sy - 1 );
moveBy( dx , dy );
float newscale = (boundedSx > boundedSy ? boundedSx : boundedSy) * mGuidoItem->scale();
mGuidoItem->setScale( newscale );
// mGuidoItem->scale( boundedSx , boundedSy );
guidoGeometryChanged();
Q_EMIT scaleChanged( mGuidoItem->transform().m11() );
}
mResizeMode = RESIZE_NORMAL;
if ( mResizer )
mResizer->setKeepAspectRatio(true);
}
示例12: drawForeground
void MScene::drawForeground(QPainter *painter, const QRectF &rect)
{
Q_D(MScene);
/* Overlay information on the widgets in development mode */
if (MApplication::showBoundingRect() || MApplication::showSize() || MApplication::showPosition() || MApplication::showMargins() || MApplication::showObjectNames() || MApplication::showStyleNames()) {
QList<QGraphicsItem *> itemList = items(rect);
QList<QGraphicsItem *>::iterator item;
painter->setFont(TextFont);
int fontHeight = d->metrics.height();
QTransform rotationMatrix;
painter->setTransform(rotationMatrix);
QList<QGraphicsItem *>::iterator end = itemList.end();
for (item = itemList.begin(); item != end; ++item) {
QRectF br = (*item)->boundingRect();
QPolygonF bp = (*item)->mapToScene(br);
if (MApplication::showBoundingRect()) {
if (!dynamic_cast<MApplicationPage *>(*item)) { // filter out page for clarity
painter->setOpacity(BoundingRectOpacity);
painter->setPen(d->boundingRectLinePen);
painter->setBrush(d->boundingRectFillBrush);
painter->drawPolygon(bp);
}
}
if (MApplication::showMargins()) {
// Draw content margins
QGraphicsLayoutItem *layoutItem = dynamic_cast<QGraphicsLayoutItem *>(*item);
if (layoutItem) {
qreal left, top, right, bottom;
layoutItem->getContentsMargins(&left, &top, &right, &bottom);
QRectF outerRect = (*item)->mapRectToScene(br);
QRectF innerRect = (*item)->mapRectToScene(br.adjusted(left, top, -right, -bottom));
QRectF leftRect(outerRect.x(), outerRect.y(), innerRect.x() - outerRect.x(), outerRect.height());
QRectF topRect(innerRect.x(), outerRect.y(), innerRect.width(), innerRect.y() - outerRect.y());
QRectF rightRect(innerRect.bottomRight().x(), outerRect.y(), outerRect.bottomRight().x() - innerRect.bottomRight().x(), outerRect.height());
QRectF bottomRect(innerRect.x(), innerRect.bottomRight().y(), innerRect.width(), outerRect.bottomRight().y() - innerRect.bottomRight().y());
painter->setOpacity(0.5);
d->fillMarginRectWithPattern(painter, leftRect, leftRect.width());
d->fillMarginRectWithPattern(painter, topRect, topRect.height());
d->fillMarginRectWithPattern(painter, rightRect, rightRect.width());
d->fillMarginRectWithPattern(painter, bottomRect, bottomRect.height());
}
painter->setOpacity(1.0);
}
if (MApplication::showPosition()) {
QPointF topLeft = ((*item)->mapToScene(br.topLeft()));
QString posStr = QString("(%1, %2)").arg(topLeft.x()).arg(topLeft.y());
painter->setPen(Qt::black);
painter->drawText(topLeft += QPointF(5, fontHeight), posStr);
painter->setPen(Qt::white);
painter->drawText(topLeft -= QPointF(1, 1), posStr);
}
if (MApplication::showSize()) {
QPointF bottomRight = ((*item)->mapToScene(br.bottomRight()));
QPointF pos = (*item)->mapToScene(br.topLeft());
QString sizeStr = QString("%1x%2 (%3,%4)").arg(br.width()).arg(br.height()).arg(pos.x()).arg(pos.y());
painter->setPen(Qt::black);
painter->drawText(bottomRight -= QPointF(d->metrics.width(sizeStr), 2), sizeStr);
painter->setPen(Qt::white);
painter->drawText(bottomRight -= QPointF(1, 1), sizeStr);
}
if (MApplication::showObjectNames()) {
d->drawObjectNames(painter, item);
}
if (MApplication::showStyleNames()) {
d->drawStyleNames(painter, item);
}
}
}
bool countingFps = MApplication::logFps() || MApplication::showFps();
if (countingFps) {
if (d->fps.frameCount < 0) {
d->fps.time.restart();
d->fps.frameCount = 0;
}
++d->fps.frameCount;
int ms = d->fps.time.elapsed();
if (ms > FpsRefreshInterval) {
float fps = d->fps.frameCount * 1000.0f / ms;
d->fps.time.restart();
d->fps.frameCount = 0;
if (MApplication::logFps()) {
QTime time = d->fps.time.currentTime();
d->logFpsCounter(&time, fps);
//.........这里部分代码省略.........
示例13: updateSymbolism
//Update the meaning menu when an item is selected
void SymbolismMenu::updateSymbolism(PaintingItem *item)
{
m_item = item;
if (!item)
{
hide();
return;
}
QRectF box = item->sceneBoundingRect();
if (LandscapeContentListing *info = item->getListing())
{
m_screen->setText("symbolismName", QString::fromStdString(StringHelper::toUpper(info->getDescription().toStdString())));
m_screen->setText("symbolismTextOff1", QString::fromStdString(StringHelper::toUpper(info->getMeaning1().toStdString())));
m_screen->setText("symbolismTextOn1", QString::fromStdString(StringHelper::toUpper(info->getMeaning1().toStdString())));
m_screen->setText("symbolismTextOff2", QString::fromStdString(StringHelper::toUpper(info->getMeaning2().toStdString())));
m_screen->setText("symbolismTextOn2", QString::fromStdString(StringHelper::toUpper(info->getMeaning2().toStdString())));
m_screen->setText("symbolismTextOff3", QString::fromStdString(StringHelper::toUpper(info->getMeaning3().toStdString())));
m_screen->setText("symbolismTextOn3", QString::fromStdString(StringHelper::toUpper(info->getMeaning3().toStdString())));
}
switch (m_item->getSymbolSelected())
{
case 1:
m_screen->setToggleGroupOnState("symbolismToggle", "symbolismToggle1");
break;
case 2:
m_screen->setToggleGroupOnState("symbolismToggle", "symbolismToggle2");
break;
case 3:
m_screen->setToggleGroupOnState("symbolismToggle", "symbolismToggle3");
break;
case -1:
default:
m_screen->setToggleGroupOnState("symbolismToggle", "symbolismToggle1");
m_item->setSymbolSelected(1);
break;
}
//Chaning the menu position based on the item's position
//TODO- hard coding
qreal x = box.left() - 289;
qreal y = box.top() - 20;
if (x < 0)
{
x = box.left() + box.width();
}
if (y < 0)
{
y = box.bottom() + 10;
x = box.left() - 20;
}
if (y > 588)
{
x = box.left() - 20;
y = box.top() - 289 - 70;
}
m_screen->getContainer("symbolismOverlay")->setPosition(vec2(x, y));
show();
}
示例14: getArea
QRectF MyGraphBase::getArea() const
{
QRectF sceneRect = this->sceneRect();
return QRectF( sceneRect.x(), sceneRect.y(),
sceneRect.width() - 20, sceneRect.height() );
}
示例15: updateRegionOfInterest
void CameraBinFocus::updateRegionOfInterest(const QRectF &focusRect, int priority)
{
if (m_cameraState != QCamera::ActiveState)
return;
GstElement * const cameraSource = m_session->cameraSource();
if (!cameraSource)
return;
GstStructure *region = gst_structure_new(
"region",
"region-x" , G_TYPE_UINT , uint(m_viewfinderResolution.width() * focusRect.x()),
"region-y" , G_TYPE_UINT, uint(m_viewfinderResolution.height() * focusRect.y()),
"region-w" , G_TYPE_UINT , uint(m_viewfinderResolution.width() * focusRect.width()),
"region-h" , G_TYPE_UINT, uint(m_viewfinderResolution.height() * focusRect.height()),
"region-priority" , G_TYPE_UINT, priority,
NULL);
GValue regionValue = G_VALUE_INIT;
g_value_init(®ionValue, GST_TYPE_STRUCTURE);
gst_value_set_structure(®ionValue, region);
gst_structure_free(region);
GValue regions = G_VALUE_INIT;
g_value_init(®ions, GST_TYPE_LIST);
gst_value_list_append_value(®ions, ®ionValue);
g_value_unset(®ionValue);
GstStructure *regionsOfInterest = gst_structure_new(
"regions-of-interest",
"frame-width" , G_TYPE_UINT , m_viewfinderResolution.width(),
"frame-height" , G_TYPE_UINT, m_viewfinderResolution.height(),
NULL);
gst_structure_set_value(regionsOfInterest, "regions", ®ions);
g_value_unset(®ions);
GstEvent *event = gst_event_new_custom(GST_EVENT_CUSTOM_UPSTREAM, regionsOfInterest);
gst_element_send_event(cameraSource, event);
}