本文整理汇总了C++中QRectF::top方法的典型用法代码示例。如果您正苦于以下问题:C++ QRectF::top方法的具体用法?C++ QRectF::top怎么用?C++ QRectF::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QRectF
的用法示例。
在下文中一共展示了QRectF::top方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintGanttItem
/*! Paints the gantt item \a idx using \a painter and \a opt
*/
void ItemDelegate::paintGanttItem( QPainter* painter,
const StyleOptionGanttItem& opt,
const QModelIndex& idx )
{
if ( !idx.isValid() ) return;
const ItemType typ = static_cast<ItemType>( idx.model()->data( idx, ItemTypeRole ).toInt() );
const QString& txt = opt.text;
QRectF itemRect = opt.itemRect;
QRectF boundingRect = opt.boundingRect;
boundingRect.setY( itemRect.y() );
boundingRect.setHeight( itemRect.height() );
//qDebug() << "itemRect="<<itemRect<<", boundingRect="<<boundingRect;
painter->save();
QPen pen = defaultPen( typ );
if ( opt.state & QStyle::State_Selected ) pen.setWidth( 2*pen.width() );
painter->setPen( pen );
painter->setBrush( defaultBrush( typ ) );
qreal pw = painter->pen().width()/2.;
switch( typ ) {
case TypeTask:
if ( itemRect.isValid() ) {
// TODO
qreal pw = painter->pen().width()/2.;
pw-=1;
QRectF r = itemRect;
r.translate( 0., r.height()/6. );
r.setHeight( 2.*r.height()/3. );
painter->setBrushOrigin( itemRect.topLeft() );
painter->save();
painter->translate( 0.5, 0.5 );
painter->drawRect( r );
bool ok;
qreal completion = idx.model()->data( idx, KDGantt::TaskCompletionRole ).toDouble( &ok );
if ( ok ) {
qreal h = r.height();
QRectF cr( r.x(), r.y()+h/4. + 1,
r.width()*completion/100., h/2. - 2 );
painter->fillRect( cr, painter->pen().brush() );
}
painter->restore();
Qt::Alignment ta;
switch( opt.displayPosition ) {
case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
}
painter->drawText( boundingRect, ta, txt );
}
break;
case TypeSummary:
if ( opt.itemRect.isValid() ) {
// TODO
pw-=1;
const QRectF r = QRectF( opt.itemRect ).adjusted( -pw, -pw, pw, pw );
QPainterPath path;
const qreal deltaY = r.height()/2.;
const qreal deltaX = qMin( r.width()/qreal(2), deltaY );
path.moveTo( r.topLeft() );
path.lineTo( r.topRight() );
path.lineTo( QPointF( r.right(), r.top() + 2.*deltaY ) );
//path.lineTo( QPointF( r.right()-3./2.*delta, r.top() + delta ) );
path.quadTo( QPointF( r.right()-.5*deltaX, r.top() + deltaY ), QPointF( r.right()-2.*deltaX, r.top() + deltaY ) );
//path.lineTo( QPointF( r.left()+3./2.*delta, r.top() + delta ) );
path.lineTo( QPointF( r.left() + 2.*deltaX, r.top() + deltaY ) );
path.quadTo( QPointF( r.left()+.5*deltaX, r.top() + deltaY ), QPointF( r.left(), r.top() + 2.*deltaY ) );
path.closeSubpath();
painter->setBrushOrigin( itemRect.topLeft() );
painter->save();
painter->translate( 0.5, 0.5 );
painter->drawPath( path );
painter->restore();
Qt::Alignment ta;
switch( opt.displayPosition ) {
case StyleOptionGanttItem::Left: ta = Qt::AlignLeft; break;
case StyleOptionGanttItem::Right: ta = Qt::AlignRight; break;
case StyleOptionGanttItem::Center: ta = Qt::AlignCenter; break;
}
painter->drawText( boundingRect, ta | Qt::AlignVCenter, txt );
}
break;
case TypeEvent: /* TODO */
//qDebug() << opt.boundingRect << opt.itemRect;
if ( opt.boundingRect.isValid() ) {
const qreal pw = painter->pen().width() / 2. - 1;
const QRectF r = QRectF( opt.rect ).adjusted( -pw, -pw, pw, pw );
QPainterPath path;
const qreal delta = static_cast< int >( r.height() / 2 );
path.moveTo( delta, 0. );
path.lineTo( 2.*delta, delta );
path.lineTo( delta, 2.*delta );
path.lineTo( 0., delta );
path.closeSubpath();
painter->save();
painter->translate( r.topLeft() );
painter->translate( 0.5, 0.5 );
//.........这里部分代码省略.........
示例2: paint
//-----------------------------------------------------------------------
// Class MacroItem
//-----------------------------------------------------------------------
void MacroItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
app::Macro::Ptr macroInstance = vertex().dataRef().staticCast<app::Macro>();
Q_ASSERT(!macroInstance.isNull());
graph::VertexItem::paint(painter,option,widget);
QRectF rcInner = innerRect();
// calculate text sizes
QString macroName = macroInstance->getName();
QFontMetrics fmName(*Resource::font(Resource::FONT_MACRONAME));
QRect rectName = fmName.boundingRect(macroName);
QString macroRuntime = macroInstance->getRuntimeString();
QFontMetrics fmStatus(*Resource::font(Resource::FONT_MACROSTATUS));
QRect rectRuntime = fmStatus.boundingRect("000.000 ms");
QPixmap statusIcon;
switch(macroInstance->getState())
{
case app::Macro::Idle:
statusIcon = QPixmap(":/icons/resources/bullet_black.png");
break;
case app::Macro::Running:
statusIcon = QPixmap(":/icons/resources/bullet_orange.png");
break;
case app::Macro::Ok:
if (!toolTip().isEmpty()) setToolTip(QString());
statusIcon = QPixmap(":/icons/resources/bullet_green.png");
break;
case app::Macro::Failure:
setToolTip(macroInstance->getErrorMsg());
statusIcon = QPixmap(":/icons/resources/bullet_red.png");
break;
}
QString macroOrder = QString(QObject::tr("Order No.: "));
if (vertex().topologicalOrder() >= 0)
{
macroOrder += QString("%1").arg(vertex().topologicalOrder());
}
else
{
macroOrder += '-';
}
QPixmap orderStatus;
if (vertex().isInCycle() && vertex().topologicalOrder() == 0 && vertex().topologicalOrderForced())
{
orderStatus = QPixmap(":/icons/resources/anchor.png");
}
else if (vertex().isInCycle() && vertex().topologicalOrder() < 0 && !vertex().topologicalOrderForced())
{
orderStatus = QPixmap(":/icons/resources/cycle.png");
}
else if (!vertex().isInCycle() && vertex().topologicalOrder() < 0)
{
orderStatus = QPixmap(":/icons/resources/error.png");
}
QRect rectOrder = fmStatus.boundingRect(macroOrder);
rectOrder.adjust(0,0,orderStatus.width(),16 - rectOrder.height());
// paint macro name
QRectF rcTextName(rcInner.left(),rcInner.top(),rcInner.width(),(qreal)rectName.height());
painter->setPen(QPen(Qt::black));
painter->setFont(*Resource::font(Resource::FONT_MACRONAME));
painter->drawText(rcTextName,Qt::AlignCenter,macroName);
// paint runtime including indicator
QRectF rcTextRuntime(rcInner.left() + rcInner.width() * 0.02 + statusIcon.width(),rcInner.top() + rectName.height() + 1.0,rcInner.width() - 2 * rcInner.width() * 0.02 - statusIcon.width(),(qreal)rectRuntime.height());
painter->setPen(QPen(Qt::blue));
painter->setFont(*Resource::font(Resource::FONT_MACROSTATUS));
painter->setClipRect(rcTextRuntime);
painter->drawText(rcTextRuntime,Qt::AlignRight,macroRuntime);
painter->setClipRect(rcInner);
painter->drawPixmap(rcInner.left() + rcInner.width() * 0.02,rcTextRuntime.top(),statusIcon.rect().width(),statusIcon.rect().height(),statusIcon);
// paint topological order
QRectF rcTextOrder(rcInner.left() + orderStatus.rect().width() + (rcInner.width() - rectOrder.width()) / 2.0,rcInner.bottom() - (qreal)rectOrder.height(),rcInner.width(),(qreal)rectOrder.height());
painter->setPen(QPen(Qt::black));
painter->drawText(rcTextOrder,Qt::AlignLeft,macroOrder);
if (!orderStatus.isNull())
{
painter->drawPixmap(rcTextOrder.left() - orderStatus.rect().width() - 1.0,rcTextOrder.top(),orderStatus.rect().width(),orderStatus.rect().height(),orderStatus);
}
painter->setClipRect(itemRect());
}
示例3: clipSegmentToRect
static void clipSegmentToRect(qreal x0, qreal y0, qreal x1, qreal y1,
const QRectF &clipRect,
QVector<qreal> &outPoints,
QVector<QPainterPath::ElementType> &outTypes)
{
int type0 = clipPointType(x0, y0, clipRect);
int type1 = clipPointType(x1, y1, clipRect);
bool accept = false;
while (true) {
if (!(type0 | type1)) {
accept = true;
break;
} else if (type0 & type1) {
break;
} else {
qreal x = 0.0;
qreal y = 0.0;
int outsideType = type0 ? type0 : type1;
if (outsideType & BottomPoint) {
x = x0 + (x1 - x0) * (clipRect.bottom() - y0) / (y1 - y0);
y = clipRect.bottom() - 0.1;
} else if (outsideType & TopPoint) {
x = x0 + (x1 - x0) * (clipRect.top() - y0) / (y1 - y0);
y = clipRect.top() + 0.1;
} else if (outsideType & RightPoint) {
y = y0 + (y1 - y0) * (clipRect.right() - x0) / (x1 - x0);
x = clipRect.right() - 0.1;
} else if (outsideType & LeftPoint) {
y = y0 + (y1 - y0) * (clipRect.left() - x0) / (x1 - x0);
x = clipRect.left() + 0.1;
}
if (outsideType == type0) {
x0 = x;
y0 = y;
type0 = clipPointType(x0, y0, clipRect);
} else {
x1 = x;
y1 = y;
type1 = clipPointType(x1, y1, clipRect);
}
}
}
if (accept) {
if (outPoints.size() >= 2) {
qreal lastX, lastY;
lastY = outPoints.at(outPoints.size() - 1);
lastX = outPoints.at(outPoints.size() - 2);
if (!qFuzzyCompare(lastY, y0) || !qFuzzyCompare(lastX, x0)) {
outTypes << QPainterPath::MoveToElement;
outPoints << x0 << y0;
}
} else {
outTypes << QPainterPath::MoveToElement;
outPoints << x0 << y0;
}
outTypes << QPainterPath::LineToElement;
outPoints << x1 << y1;
}
}
示例4: alignScales
//.........这里部分代码省略.........
{
if ( d_data->alignCanvasToScales && rightOffset < 0 )
{
canvasRect.setRight( qMin( canvasRect.right(),
axisRect.right() + rightOffset ) );
}
else
{
if ( rightOffset > 0 )
axisRect.setRight( axisRect.right() - rightOffset );
}
}
}
else // QwtPlot::yLeft, QwtPlot::yRight
{
const QRectF &bottomScaleRect = scaleRect[QwtPlot::xBottom];
const int bottomOffset =
backboneOffset[QwtPlot::xBottom] - endDist + 1;
if ( bottomScaleRect.isValid() )
{
const int dy = bottomOffset + bottomScaleRect.height();
if ( d_data->alignCanvasToScales && dy < 0 )
{
/*
The axis needs more space than the height
of the bottom scale.
*/
canvasRect.setBottom( qMin( canvasRect.bottom(),
axisRect.bottom() + dy ) );
}
else
{
const double maxBottom = bottomScaleRect.top() +
d_data->layoutData.scale[QwtPlot::xBottom].tickOffset;
const double bottom = axisRect.bottom() - bottomOffset;
axisRect.setBottom( qMin( bottom, maxBottom ) );
}
}
else
{
if ( d_data->alignCanvasToScales && bottomOffset < 0 )
{
canvasRect.setBottom( qMin( canvasRect.bottom(),
axisRect.bottom() + bottomOffset ) );
}
else
{
if ( bottomOffset > 0 )
axisRect.setBottom( axisRect.bottom() - bottomOffset );
}
}
const QRectF &topScaleRect = scaleRect[QwtPlot::xTop];
const int topOffset = backboneOffset[QwtPlot::xTop] - startDist;
if ( topScaleRect.isValid() )
{
const int dy = topOffset + topScaleRect.height();
if ( d_data->alignCanvasToScales && dy < 0 )
{
/*
The axis needs more space than the height
of the top scale.
*/
canvasRect.setTop( qMax( canvasRect.top(),
示例5: closeButtonRect
QRectF closeButtonRect(const QRectF& rect) const {
return QRectF(rect.right()-closeButtonRectSize, rect.top(), closeButtonRectSize, closeButtonRectSize);
}
示例6: draw
/*!
\brief Draw the scale
*/
void QwtPlotScaleItem::draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
QwtScaleDraw *sd = d_data->scaleDraw;
if ( d_data->scaleDivFromAxis )
{
const QwtInterval interval =
d_data->scaleInterval( canvasRect, xMap, yMap );
if ( interval != sd->scaleDiv().interval() )
{
QwtScaleDiv scaleDiv = sd->scaleDiv();
scaleDiv.setInterval( interval );
sd->setScaleDiv( scaleDiv );
}
}
QPen pen = painter->pen();
pen.setStyle( Qt::SolidLine );
painter->setPen( pen );
if ( sd->orientation() == Qt::Horizontal )
{
double y;
if ( d_data->borderDistance >= 0 )
{
if ( sd->alignment() == QwtScaleDraw::BottomScale )
y = canvasRect.top() + d_data->borderDistance;
else
{
y = canvasRect.bottom() - d_data->borderDistance;
}
}
else
{
y = yMap.transform( d_data->position );
}
if ( y < canvasRect.top() || y > canvasRect.bottom() )
return;
sd->move( canvasRect.left(), y );
sd->setLength( canvasRect.width() - 1 );
QwtTransform *transform = NULL;
if ( xMap.transformation() )
transform = xMap.transformation()->copy();
sd->setTransformation( transform );
}
else // == Qt::Vertical
{
double x;
if ( d_data->borderDistance >= 0 )
{
if ( sd->alignment() == QwtScaleDraw::RightScale )
x = canvasRect.left() + d_data->borderDistance;
else
{
x = canvasRect.right() - d_data->borderDistance;
}
}
else
{
x = xMap.transform( d_data->position );
}
if ( x < canvasRect.left() || x > canvasRect.right() )
return;
sd->move( x, canvasRect.top() );
sd->setLength( canvasRect.height() - 1 );
QwtTransform *transform = NULL;
if ( yMap.transformation() )
transform = yMap.transformation()->copy();
sd->setTransformation( transform );
}
painter->setFont( d_data->font );
sd->draw( painter, d_data->palette );
}
示例7: paintStruct
void SCgAlphabet::paintStruct(QPainter *painter, const QColor &color,
const QRectF &boundRect, const SCgNodeStructType &type)
{
QPen pen = QPen(QBrush(color, Qt::SolidPattern), 2, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
painter->setPen(pen);
// structure types
QPointF c, d;
switch (type)
{
case StructType_Struct:
float w, h;
w = boundRect.width() / 10.f;
h = boundRect.height() / 10.f;
painter->setBrush(QBrush(color, Qt::SolidPattern));
painter->drawEllipse(-w, -h, w * 2 - 1, h * 2 - 1);
painter->setBrush(QBrush(Qt::NoBrush));
break;
case StructType_Abstract:
{
QPen p = painter->pen();
p.setWidthF(0);
painter->setPen(p);
qreal x1, x2, top, bottom;
top = boundRect.top();
bottom = boundRect.bottom();
x1 = boundRect.left();
x2 = boundRect.right();
for (qreal y = top; y < bottom; y += 3)
painter->drawLine(QLineF(x1, y, x2, y));
break;
}
case StructType_Material:
{
QPen p = painter->pen();
p.setWidthF(0);
painter->setPen(p);
qreal y1, y2, left, right;
left = boundRect.left();
right = boundRect.right();
qreal dist = right - left;
y1 = boundRect.top();
y2 = boundRect.bottom();
for (qreal d = 0; d <= dist; d += 4.2)
{
painter->drawLine(QLineF(left + d, y1, left, y1 + d));
painter->drawLine(QLineF(right - d, y2, right, y2 - d));
}
break;
}
case StructType_Tuple:
c = boundRect.center();
d = QPointF(boundRect.width() / 2.0, 0.f);
painter->drawLine(c - d, c + d);
break;
case StructType_Role:
c = boundRect.center();
d = QPointF(boundRect.width() / 2.0, 0.f);
painter->drawLine(c - d, c + d);
d = QPointF(0.f, boundRect.height() / 2.0);
painter->drawLine(c - d, c + d);
break;
case StructType_Relation:
painter->drawLine(boundRect.topLeft(), boundRect.bottomRight());
painter->drawLine(boundRect.topRight(), boundRect.bottomLeft());
break;
case StructType_Group:
painter->drawLine(boundRect.topLeft(), boundRect.bottomRight());
painter->drawLine(boundRect.topRight(), boundRect.bottomLeft());
painter->drawLine(boundRect.left(), boundRect.center().y(), boundRect.right(), boundRect.center().y());
break;
default:
break;
}
}
示例8: itemChange
QVariant Pin::itemChange(GraphicsItemChange change, const QVariant &value)
{
// Note that pins are only movable within the symbol editor.
PageScene *pageScene = dynamic_cast<PageScene *>(scene());
if (ItemPositionChange == change && pageScene) {
QPointF p = value.toPointF() + pageScene->reparentOffset(this); // p is now the position relative to the current parent.
SymbolEditor *se = dynamic_cast<SymbolEditor *>(pageScene->parent());
if (se) {
QGraphicsItem *anchor = se->closestPinAnchor(parentItem()->mapToScene(p), this);
if (parentItem() != anchor) {
pageScene->reparentWhileDragging(this, anchor);
p = value.toPointF() + pageScene->reparentOffset(this);
setData(FreeSCH::SectionChanged, true);
}
if (QGraphicsLineItem::Type == anchor->type()) {
p.setX(anchor->pos().x());
if (position.side() != PinPosition::Right) {
position.setSide(PinPosition::Right);
attributes.setValue("side", PinPosition::sideNames.at(PinPosition::Right));
reorient();
}
} else if (Section::Type == anchor->type()) {
Section *section = qgraphicsitem_cast<Section *>(anchor);
if (section) {
QRectF r = QRectF(QPointF(0,0), section->rect().size());
PinPosition::PinSide newside = PinPosition::sideIndex(r, p);
switch (newside) {
case PinPosition::Right:
p.setX(r.right());
break;
case PinPosition::Bottom:
p.setY(r.bottom());
break;
case PinPosition::Left:
p.setX(r.left());
break;
default: // top
p.setY(r.top());
break;
}
if (p.x() < 0)
p.setX(0);
if (p.x() > r.width())
p.setX(r.width());
if (p.y() < 0)
p.setY(0);
if (p.y() > r.height())
p.setY(r.height());
if (position.side() != newside) {
position.setSide(newside);
attributes.setValue("side", PinPosition::sideNames.at(newside));
updateOffset(snap(p).toPoint());
reorient();
// As the pin moves around a corner of a section, it can switch sides without its pos() changing.
// In that case the ItemPositionHasChanged event doesn't occur. So we need to emit the moved signal here.
emit moved();
}
}
}
}
return snap(p);
}
if (ItemPositionHasChanged == change && pageScene) {
updateOffset(pos().toPoint());
if (data(FreeSCH::SectionChanged).toBool()) {
setData(FreeSCH::SectionChanged, false);
emit sectionChanged(this, parentItem());
}
emit moved();
}
return QGraphicsItem::itemChange(change, value);
}
示例9: calculatePoints
void UBGraphicsTriangle::calculatePoints(const QRectF& r)
{
switch(mOrientation)
{
case BottomLeft:
A1.setX(r.left()); A1.setY(r.top());
B1.setX(r.left()); B1.setY(r.bottom());
C1.setX(r.right()); C1.setY(r.bottom());
break;
case TopLeft:
A1.setX(r.left()); A1.setY(r.bottom());
B1.setX(r.left()); B1.setY(r.top());
C1.setX(r.right()); C1.setY(r.top());
break;
case TopRight:
A1.setX(r.right()); A1.setY(r.bottom());
B1.setX(r.right()); B1.setY(r.top());
C1.setX(r.left()); C1.setY(r.top());
break;
case BottomRight:
A1.setX(r.right()); A1.setY(r.top());
B1.setX(r.right()); B1.setY(r.bottom());
C1.setX(r.left()); C1.setY(r.bottom());
break;
}
C = sqrt(rect().width() * rect().width() + rect().height() * rect().height());
qreal L = (C * d + rect().width() * d)/ rect().height();
qreal K = (C * d + rect().height() * d)/ rect().width();
switch(mOrientation)
{
case BottomLeft:
A2.setX(r.left() + d); A2.setY(r.top() + K);
B2.setX(r.left() + d); B2.setY(r.bottom() - d);
C2.setX(r.right() - L); C2.setY(r.bottom() - d);
break;
case TopLeft:
A2.setX(r.left() + d); A2.setY(r.bottom() - K);
B2.setX(r.left() + d); B2.setY(r.top() + d);
C2.setX(r.right() - L); C2.setY(r.top() + d);
break;
case TopRight:
A2.setX(r.right() - d); A2.setY(r.bottom() - K);
B2.setX(r.right() - d); B2.setY(r.top() + d);
C2.setX(r.left() + L); C2.setY(r.top() + d);
break;
case BottomRight:
A2.setX(r.right() - d); A2.setY(r.top() + K);
B2.setX(r.right() - d); B2.setY(r.bottom() - d);
C2.setX(r.left() + L); C2.setY(r.bottom() - d);
break;
}
W1 = rect().height() * d / C;
H1 = rect().width() * d / C;
switch(mOrientation)
{
case BottomLeft:
CC.setX(r.right() - L + W1); CC.setY(r.bottom() - d - H1);
break;
case TopLeft:
CC.setX(r.right() - L + W1); CC.setY(r.top() + d + H1);
break;
case TopRight:
CC.setX(r.left() + L - W1); CC.setY(r.top() + d + H1);
break;
case BottomRight:
CC.setX(r.left() + L - W1); CC.setY(r.top() - d - H1);
break;
}
}
示例10: _q_boundGeometryToSizeConstraints
static void _q_boundGeometryToSizeConstraints(const QRectF &startGeometry,
QRectF *rect, Qt::WindowFrameSection section,
const QSizeF &min, const QSizeF &max,
const QGraphicsWidget *widget)
{
const QRectF proposedRect = *rect;
qreal width = qBound(min.width(), proposedRect.width(), max.width());
qreal height = qBound(min.height(), proposedRect.height(), max.height());
const bool hasHFW = QGraphicsLayoutItemPrivate::get(widget)->hasHeightForWidth();
const bool hasWFH = QGraphicsLayoutItemPrivate::get(widget)->hasWidthForHeight();
const bool widthChanged = proposedRect.width() != widget->size().width();
const bool heightChanged = proposedRect.height() != widget->size().height();
if (hasHFW || hasWFH) {
if (widthChanged || heightChanged) {
qreal minExtent;
qreal maxExtent;
qreal constraint;
qreal proposed;
if (hasHFW) {
minExtent = min.height();
maxExtent = max.height();
constraint = width;
proposed = proposedRect.height();
} else {
// width for height
minExtent = min.width();
maxExtent = max.width();
constraint = height;
proposed = proposedRect.width();
}
if (minimumHeightForWidth(constraint, minExtent, maxExtent, widget, hasHFW) > proposed) {
QSizeF effectiveSize = closestAcceptableSize(QSizeF(width, height), widget);
width = effectiveSize.width();
height = effectiveSize.height();
}
}
}
switch (section) {
case Qt::LeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
qRound(width), startGeometry.height());
break;
case Qt::TopLeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.bottom() - qRound(height),
qRound(width), qRound(height));
break;
case Qt::TopSection:
rect->setRect(startGeometry.left(), startGeometry.bottom() - qRound(height),
startGeometry.width(), qRound(height));
break;
case Qt::TopRightSection:
rect->setTop(rect->bottom() - qRound(height));
rect->setWidth(qRound(width));
break;
case Qt::RightSection:
rect->setWidth(qRound(width));
break;
case Qt::BottomRightSection:
rect->setWidth(qRound(width));
rect->setHeight(qRound(height));
break;
case Qt::BottomSection:
rect->setHeight(qRound(height));
break;
case Qt::BottomLeftSection:
rect->setRect(startGeometry.right() - qRound(width), startGeometry.top(),
qRound(width), qRound(height));
break;
default:
break;
}
}
示例11: topCenter
static QPointF topCenter(const QRectF &rect)
{
return QPointF(rect.center().x(), rect.top());
}
示例12: updateRenderTargets
void ShaderEffect::updateRenderTargets()
{
if (!m_changed)
return;
m_changed = false;
int count = m_renderTargets.count();
for (int i = 0; i < count; i++) {
if (m_renderTargets[i]->isLive() || m_renderTargets[i]->isDirtyTexture()) {
m_renderTargets[i]->updateBackbuffer();
ShaderEffectBuffer* target = m_renderTargets[i]->fbo();
if (target && target->isValid() && target->width() > 0 && target->height() > 0) {
QPainter p(target);
p.setCompositionMode(QPainter::CompositionMode_Clear);
p.fillRect(QRect(QPoint(0, 0), target->size()), Qt::transparent);
p.setCompositionMode(QPainter::CompositionMode_SourceOver);
QRectF sourceRect = m_renderTargets[i]->sourceRect();
QSize textureSize = m_renderTargets[i]->textureSize();
qreal yflip = m_renderTargets[i]->isMirrored() ? -1.0 : 1.0; // flip y to match scenegraph, it also flips texturecoordinates
qreal xscale = 1.0;
qreal yscale = 1.0 * yflip;
qreal leftMargin = 0.0;
qreal rightMargin = 0.0;
qreal topMargin = 0.0;
qreal bottomMargin = 0.0;
qreal width = m_renderTargets[i]->sourceItem()->width();
qreal height = m_renderTargets[i]->sourceItem()->height();
if (!sourceRect.isEmpty()) {
leftMargin = -sourceRect.left();
rightMargin = sourceRect.right() - width;
topMargin = -sourceRect.top();
bottomMargin = sourceRect.bottom() - height;
}
if ((width + leftMargin + rightMargin) > 0 && (height + topMargin + bottomMargin) > 0) {
if (!textureSize.isEmpty()) {
qreal textureWidth = textureSize.width();
qreal textureHeight = textureSize.height();
xscale = width / (width + leftMargin + rightMargin);
yscale = height / (height + topMargin + bottomMargin);
p.translate(textureWidth / 2, textureHeight / 2);
p.scale(xscale, yscale * yflip);
p.translate(-textureWidth / 2, -textureHeight / 2);
p.scale(textureWidth / width, textureHeight / height);
} else {
xscale = width / (width + leftMargin + rightMargin);
yscale = height / (height + topMargin + bottomMargin);
p.translate(width / 2, height / 2);
p.scale(xscale, yscale * yflip);
p.translate(-width / 2, -height / 2);
}
}
drawSource(&p);
p.end();
m_renderTargets[i]->markSceneGraphDirty();
}
}
}
}
示例13: evalItemRect
QRectF QgsComposerItem::evalItemRect( const QRectF &newRect, const bool resizeOnly, const QgsExpressionContext* context )
{
QRectF result = newRect;
//TODO QGIS 3.0
//maintain pre 2.12 API. remove when API break allowed
QScopedPointer< QgsExpressionContext > scopedContext;
const QgsExpressionContext* evalContext = context;
if ( !evalContext )
{
scopedContext.reset( createExpressionContext() );
evalContext = scopedContext.data();
}
//data defined position or size set? if so, update rect with data defined values
QVariant exprVal;
//evaulate width and height first, since they may affect position if non-top-left reference point set
if ( dataDefinedEvaluate( QgsComposerObject::ItemWidth, exprVal, *evalContext ) )
{
bool ok;
double width = exprVal.toDouble( &ok );
QgsDebugMsg( QString( "exprVal Width:%1" ).arg( width ) );
if ( ok && !exprVal.isNull() )
{
result.setWidth( width );
}
}
if ( dataDefinedEvaluate( QgsComposerObject::ItemHeight, exprVal, *evalContext ) )
{
bool ok;
double height = exprVal.toDouble( &ok );
QgsDebugMsg( QString( "exprVal Height:%1" ).arg( height ) );
if ( ok && !exprVal.isNull() )
{
result.setHeight( height );
}
}
double x = result.left();
//initially adjust for position mode to get x coordinate
if ( !resizeOnly )
{
//adjust x-coordinate if placement is not done to a left point
if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
{
x += newRect.width() / 2.0;
}
else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
{
x += newRect.width();
}
}
else
{
if ( mLastUsedPositionMode == UpperMiddle || mLastUsedPositionMode == Middle || mLastUsedPositionMode == LowerMiddle )
{
x += rect().width() / 2.0;
}
else if ( mLastUsedPositionMode == UpperRight || mLastUsedPositionMode == MiddleRight || mLastUsedPositionMode == LowerRight )
{
x += rect().width();
}
}
if ( dataDefinedEvaluate( QgsComposerObject::PositionX, exprVal, *evalContext ) )
{
bool ok;
double positionX = exprVal.toDouble( &ok );
QgsDebugMsg( QString( "exprVal Position X:%1" ).arg( positionX ) );
if ( ok && !exprVal.isNull() )
{
x = positionX;
}
}
double y = result.top();
//initially adjust for position mode to get y coordinate
if ( !resizeOnly )
{
//adjust y-coordinate if placement is not done to an upper point
if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
{
y += newRect.height() / 2.0;
}
else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
{
y += newRect.height();
}
}
else
{
if ( mLastUsedPositionMode == MiddleLeft || mLastUsedPositionMode == Middle || mLastUsedPositionMode == MiddleRight )
{
y += rect().height() / 2.0;
}
else if ( mLastUsedPositionMode == LowerLeft || mLastUsedPositionMode == LowerMiddle || mLastUsedPositionMode == LowerRight )
{
y += rect().height();
}
}
if ( dataDefinedEvaluate( QgsComposerObject::PositionY, exprVal, *evalContext ) )
//.........这里部分代码省略.........
示例14: draw
void GridItem::draw( QPainter *painter,
const QwtScaleMap &xMap, const QwtScaleMap &yMap,
const QRectF &canvasRect ) const
{
const bool doAlign = QwtPainter::roundingAlignment( painter );
const QRectF area = QwtScaleMap::invTransform( xMap, yMap, canvasRect );
QList<double> xValues;
if ( m_orientations & Qt::Horizontal )
{
xValues = m_xScaleDiv.ticks( QwtScaleDiv::MajorTick );
if ( m_isXMinEnabled )
{
xValues += m_xScaleDiv.ticks( QwtScaleDiv::MediumTick );
xValues += m_xScaleDiv.ticks( QwtScaleDiv::MinorTick );
}
if ( m_gridAttributes & FillCanvas )
{
xValues += area.left();
xValues += area.right();
}
qSort( xValues );
}
QList<double> yValues;
if ( m_orientations & Qt::Vertical )
{
yValues = m_yScaleDiv.ticks( QwtScaleDiv::MajorTick );
if ( m_isYMinEnabled )
{
yValues += m_yScaleDiv.ticks( QwtScaleDiv::MediumTick );
yValues += m_yScaleDiv.ticks( QwtScaleDiv::MinorTick );
}
if ( m_gridAttributes & FillCanvas )
{
yValues += area.top();
yValues += area.bottom();
}
qSort( yValues );
}
painter->setPen( Qt::NoPen );
if ( ( m_orientations & Qt::Horizontal ) &&
( m_orientations & Qt::Vertical ) )
{
for ( int i = 1; i < xValues.size(); i++ )
{
double x1 = xMap.transform( xValues[i - 1] );
double x2 = xMap.transform( xValues[i] );
if ( doAlign )
{
x1 = qRound( x1 );
x2 = qRound( x2 );
}
for ( int j = 1; j < yValues.size(); j++ )
{
const QRectF rect( xValues[i - 1], yValues[j - 1],
xValues[i] - xValues[i - 1], yValues[j] - yValues[j - 1] );
painter->setBrush( brush( i - 1, j - 1, rect ) );
double y1 = yMap.transform( yValues[j - 1] );
double y2 = yMap.transform( yValues[j] );
if ( doAlign )
{
y1 = qRound( y1 );
y2 = qRound( y2 );
}
QwtPainter::drawRect( painter, x1, y1, x2 - x1, y2 - y1 );
}
}
}
else if ( m_orientations & Qt::Horizontal )
{
for ( int i = 1; i < xValues.size(); i++ )
{
const QRectF rect( xValues[i - 1], area.top(),
xValues[i] - xValues[i - 1], area.bottom() );
painter->setBrush( brush( i - 1, 0, rect ) );
double x1 = xMap.transform( xValues[i - 1] );
double x2 = xMap.transform( xValues[i] );
if ( doAlign )
{
x1 = qRound( x1 );
x2 = qRound( x2 );
//.........这里部分代码省略.........
示例15: hitTest
TableHandle PageItem_Table::hitTest(const QPointF& point, double threshold) const
{
const QPointF framePoint = getTransform().inverted().map(point);
const QPointF gridPoint = framePoint - gridOffset();
const QRectF gridRect = QRectF(0.0, 0.0, tableWidth(), tableHeight());
// Test if hit is outside frame.
if (!QRectF(0.0, 0.0, width(), height()).contains(framePoint))
return TableHandle(TableHandle::None);
// Test if hit is outside table.
if (!gridRect.adjusted(-threshold, -threshold, threshold, threshold).contains(gridPoint))
return TableHandle(TableHandle::None);
const double tableHeight = this->tableHeight();
const double tableWidth = this->tableWidth();
const double x = gridPoint.x();
const double y = gridPoint.y();
// Test if hit is on left edge of table.
if (x <= threshold)
return TableHandle(TableHandle::RowSelect);
// Test if hit is on top edge of table.
if (y <= threshold)
return TableHandle(TableHandle::ColumnSelect);
// Test if hit is on bottom right corner of table.
if (x >= tableWidth - threshold && y >= tableHeight - threshold)
return TableHandle(TableHandle::TableResize);
// Test if hit is on right edge of table.
if (y >= tableHeight - threshold && y <= tableHeight + threshold)
return TableHandle(TableHandle::RowResize, rows() - 1);
// Test if hit is on bottom edge of table.
if (x >= tableWidth - threshold && x <= tableWidth + threshold)
return TableHandle(TableHandle::ColumnResize, columns() - 1);
const TableCell hitCell = cellAt(point);
const QRectF hitRect = hitCell.boundingRect();
// Test if hit is on cell interior.
if (hitRect.adjusted(threshold, threshold, -threshold, -threshold).contains(gridPoint))
return TableHandle(TableHandle::CellSelect); // Hit interior of cell.
const double toLeft = x - hitRect.left();
const double toRight = hitRect.right() - x;
const double toTop = y - hitRect.top();
const double toBottom = hitRect.bottom() - y;
TableHandle handle(TableHandle::None);
// Test which side of the cell was hit.
if (qMin(toLeft, toRight) < qMin(toTop, toBottom))
{
handle.setType(TableHandle::ColumnResize);
handle.setIndex((toLeft < toRight ? hitCell.column() : hitCell.column() + hitCell.columnSpan()) - 1);
}
else
{
handle.setType(TableHandle::RowResize);
handle.setIndex((toTop < toBottom ? hitCell.row() : hitCell.row() + hitCell.rowSpan()) - 1);
}
return handle;
}