本文整理汇总了C++中QTransform::rotate方法的典型用法代码示例。如果您正苦于以下问题:C++ QTransform::rotate方法的具体用法?C++ QTransform::rotate怎么用?C++ QTransform::rotate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTransform
的用法示例。
在下文中一共展示了QTransform::rotate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintWorld
void World::paintWorld(QPainter *painter)
{
if (!_isGameOver) {
for (int q = 0; q < _tankList.size(); q++) {
QTransform transform;
int angle = 0;
switch (_tankList[q]->getAngle()) {
case 1: {
angle = 90;
break;
}
case 2: {
angle = 180;
break;
}
case 3: {
angle = 270;
break;
}
}
transform.rotate(angle);
QImage image;
if (_tankList[q]->getKillAnimation() == 0) {
if (_tankList[q]->getTeam() == 1) {
image = *_images[0];
} else if (_tankList[q]->getTeam() == 0) {
image = *_images[1];
} else if (_tankList[q]->getTeam() == 2) {
image = *_images[9];
painter->drawImage(_tankList[q]->getPos(),image);
continue;
}
image = image.transformed(transform);
painter->drawImage(_tankList[q]->getPos(),image);
} else {
image = *_images[7];
painter->drawImage(_tankList[q]->getPos().x() + _tankList[q]->getSize() / 2 - image.width() / 4,
_tankList[q]->getPos().y() + _tankList[q]->getSize() / 2 - image.height() / 4 ,
image);
}
}
for (int q = 0; q < _wallList.size(); q++) {
QImage image;
switch (_wallList[q]->getType()) {
case 0: {
image = *_images[2];
break;
}
case 1: {
image = *_images[3];
break;
}
case 2: {
image = *_images[5];
break;
}
}
painter->drawImage(_wallList[q]->getPos(), image);
}
for (int q = 0; q < _bulletList.size(); q++) {
QTransform transform;
int angle = 0;
switch (_bulletList[q]->getAngle()) {
case 1: {
angle = 90;
break;
}
case 2: {
angle = 180;
break;
}
case 3: {
angle = 270;
break;
}
}
transform.rotate(angle);
QImage image;
if (_bulletList[q]->getKillAnimation() == 0) {
image = _images[4]->transformed(transform);
painter->drawImage(_bulletList[q]->getPos(),image);
} else {
image = *_images[6];
painter->drawImage(_bulletList[q]->getPos().x() + _bulletList[q]->getSize() / 2 - image.width() / 2,
_bulletList[q]->getPos().y() + _bulletList[q]->getSize() / 2 - image.height() / 2
,image);
}
}
} else {
painter->drawImage(140,205, *_images[8]);
}
}
示例2: run
// This is called from the worker thread, not main thread
bool LoadImageJob::run() {
GFile* gfile = fm_path_to_gfile(path_);
GFileInputStream* fileStream = g_file_read(gfile, cancellable_, &error_);
g_object_unref(gfile);
if(fileStream) { // if the file stream is successfually opened
QBuffer imageBuffer;
GInputStream* inputStream = G_INPUT_STREAM(fileStream);
while(!g_cancellable_is_cancelled(cancellable_)) {
char buffer[4096];
gssize readSize = g_input_stream_read(inputStream,
buffer, 4096,
cancellable_, &error_);
if(readSize == -1 || readSize == 0) // error or EOF
break;
// append the bytes read to the image buffer
imageBuffer.buffer().append(buffer, readSize);
}
g_input_stream_close(inputStream, NULL, NULL);
// FIXME: maybe it's a better idea to implement a GInputStream based QIODevice.
if(!error_ && !g_cancellable_is_cancelled(cancellable_)) { // load the image from buffer if there are no errors
image_ = QImage::fromData(imageBuffer.buffer());
if(!image_.isNull()) { // if the image is loaded correctly
// check if this file is a jpeg file
// FIXME: can we use FmFileInfo instead if it's available?
const char* basename = fm_path_get_basename(path_);
char* mime_type = g_content_type_guess(basename, NULL, 0, NULL);
if(mime_type && strcmp(mime_type, "image/jpeg") == 0) { // this is a jpeg file
// use libexif to extract additional info embedded in jpeg files
ExifLoader *exif_loader = exif_loader_new();
// write image data to exif loader
exif_loader_write(exif_loader, (unsigned char*)imageBuffer.data().constData(), (unsigned int)imageBuffer.size());
ExifData *exif_data = exif_loader_get_data(exif_loader);
exif_loader_unref(exif_loader);
if(exif_data) {
/* reference for EXIF orientation tag:
* http://www.impulseadventure.com/photo/exif-orientation.html */
ExifEntry* orient_ent = exif_data_get_entry(exif_data, EXIF_TAG_ORIENTATION);
if(orient_ent) { /* orientation flag found in EXIF */
gushort orient;
ExifByteOrder bo = exif_data_get_byte_order(exif_data);
/* bo == EXIF_BYTE_ORDER_INTEL ; */
orient = exif_get_short (orient_ent->data, bo);
qreal rotate_degrees = 0.0;
switch(orient) {
case 1: /* no rotation */
break;
case 8:
rotate_degrees = 270.0;
break;
case 3:
rotate_degrees = 180.0;
break;
case 6:
rotate_degrees = 90.0;
break;
}
// rotate the image according to EXIF orientation tag
if(rotate_degrees != 0.0) {
QTransform transform;
transform.rotate(rotate_degrees);
image_ = image_.transformed(transform, Qt::SmoothTransformation);
}
// TODO: handle other EXIF tags as well
}
exif_data_unref(exif_data);
}
}
g_free(mime_type);
}
}
}
return false;
}
示例3: if
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, QgsSymbolV2RenderContext &context, QPointF shift ) const
{
//width
double symbolWidth = mSymbolWidth;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH ) ) //1. priority: data defined setting on symbol layer le
{
context.setOriginalValueVariable( mSymbolWidth );
symbolWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_WIDTH, context, mSymbolWidth ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolWidth = mSize;
}
if ( mSymbolWidthUnit == QgsSymbolV2::MM )
{
symbolWidth *= mmMapUnitScaleFactor;
}
//height
double symbolHeight = mSymbolHeight;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT ) ) //1. priority: data defined setting on symbol layer level
{
context.setOriginalValueVariable( mSymbolHeight );
symbolHeight = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_HEIGHT, context, mSymbolHeight ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolHeight = mSize;
}
if ( mSymbolHeightUnit == QgsSymbolV2::MM )
{
symbolHeight *= mmMapUnitScaleFactor;
}
//outline width
double outlineWidth = mOutlineWidth;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
{
context.setOriginalValueVariable( mOutlineWidth );
outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, mOutlineWidth ).toDouble();
}
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
{
outlineWidth *= outlineWidth;
}
//fill color
bool ok;
QColor fc = mColor;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR ) )
{
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_FILL_COLOR, context, QVariant(), &ok ).toString();
if ( ok )
fc = QgsSymbolLayerV2Utils::decodeColor( colorString );
}
//outline color
QColor oc = mOutlineColor;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR ) )
{
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_COLOR, context, QVariant(), &ok ).toString();
if ( ok )
oc = QgsSymbolLayerV2Utils::decodeColor( colorString );
}
//symbol name
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME ) )
{
context.setOriginalValueVariable( mSymbolName );
symbolName = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_SYMBOL_NAME, context, mSymbolName ).toString();
}
//offset
double offsetX = 0;
double offsetY = 0;
markerOffset( context, offsetX, offsetY );
QPointF off( offsetX, offsetY );
//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
double rotation = 0.0;
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION ) )
{
context.setOriginalValueVariable( mAngle );
rotation = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_ROTATION, context, mAngle ).toDouble() + mLineAngle;
}
else if ( !qgsDoubleNear( mAngle + mLineAngle, 0.0 ) )
{
rotation = mAngle + mLineAngle;
}
rotation = -rotation; //rotation in Qt is counterclockwise
if ( rotation )
off = _rotatedOffset( off, rotation );
QTransform t;
t.translate( shift.x() + offsetX, shift.y() + offsetY );
//.........这里部分代码省略.........
示例4: DrawObj_Item
//.........这里部分代码省略.........
DrawStrokePattern(p, guidePath);
}
else
{
p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation, patternStrokeSkewX, patternStrokeSkewY, patternStrokeMirrorX, patternStrokeMirrorY);
p->setStrokeMode(ScPainter::Pattern);
p->strokePath();
}
}
else if (GrTypeStroke > 0)
{
if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
gradientStrokeVal = "";
if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
if (stroke_gradient.stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
{
if (lineColor() != CommonStrings::None)
{
p->setBrush(strokeQColor);
p->setStrokeMode(ScPainter::Solid);
}
else
{
no_stroke = true;
p->setStrokeMode(ScPainter::None);
}
}
else
{
p->setStrokeMode(ScPainter::Gradient);
p->stroke_gradient = stroke_gradient;
if (GrTypeStroke == 6)
p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY), FPoint(GrStrokeStartX, GrStrokeStartY), GrStrokeScale, GrStrokeSkew);
else
p->setGradient(VGradient::radial, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY), FPoint(GrStrokeFocalX, GrStrokeFocalY), GrStrokeScale, GrStrokeSkew);
}
p->strokePath();
}
else if (lineColor() != CommonStrings::None)
{
p->setStrokeMode(ScPainter::Solid);
p->strokePath();
}
else
no_stroke = true;
}
else
{
p->setStrokeMode(ScPainter::Solid);
multiLine ml = m_Doc->MLineStyles[NamedLStyle];
QColor tmp;
for (int it = ml.size()-1; it > -1; it--)
{
if (ml[it].Color != CommonStrings::None) // && (ml[it].Width != 0))
{
SetQColor(&tmp, ml[it].Color, ml[it].Shade);
p->setPen(tmp, ml[it].Width, static_cast<Qt::PenStyle>(ml[it].Dash), static_cast<Qt::PenCapStyle>(ml[it].LineEnd), static_cast<Qt::PenJoinStyle>(ml[it].LineJoin));
p->strokePath();
}
}
}
}
if (m_startArrowIndex != 0)
{
FPoint Start = PoLine.point(0);
for (int xx = 1; xx < PoLine.size(); xx += 2)
{
FPoint Vector = PoLine.point(xx);
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
QTransform arrowTrans;
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
arrowTrans.scale(m_startArrowScale / 100.0, m_startArrowScale / 100.0);
drawArrow(p, arrowTrans, m_startArrowIndex);
break;
}
}
}
if (m_endArrowIndex != 0)
{
FPoint End = PoLine.point(PoLine.size()-2);
for (uint xx = PoLine.size()-1; xx > 0; xx -= 2)
{
FPoint Vector = PoLine.point(xx);
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
QTransform arrowTrans;
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
arrowTrans.scale(m_endArrowScale / 100.0, m_endArrowScale / 100.0);
drawArrow(p, arrowTrans, m_endArrowIndex);
break;
}
}
}
}
示例5: getVisualBoundingRect
void PageItem_Line::getVisualBoundingRect(double * x1, double * y1, double * x2, double * y2) const
{
double minx = std::numeric_limits<double>::max();
double miny = std::numeric_limits<double>::max();
double maxx = -std::numeric_limits<double>::max();
double maxy = -std::numeric_limits<double>::max();
double extraSpace = 0.0;
if (NamedLStyle.isEmpty())
{
if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
{
extraSpace = m_lineWidth / 2.0;
if ((extraSpace == 0) && m_Doc->view()) // Hairline case
extraSpace = 0.5 / m_Doc->view()->scale();
}
if ((!patternStrokeVal.isEmpty()) && (m_Doc->docPatterns.contains(patternStrokeVal)) && (patternStrokePath))
{
ScPattern *pat = &m_Doc->docPatterns[patternStrokeVal];
QTransform mat;
mat.rotate(patternStrokeRotation);
mat.scale(patternStrokeScaleX / 100.0, patternStrokeScaleY / 100.0);
QRectF p1R = QRectF(0, 0, pat->width / 2.0, pat->height / 2.0);
QRectF p2R = mat.map(p1R).boundingRect();
extraSpace = p2R.height();
}
}
else
{
multiLine ml = m_Doc->MLineStyles[NamedLStyle];
const SingleLine& sl = ml.last();
if (sl.Color != CommonStrings::None)
{
extraSpace = sl.Width / 2.0;
if ((extraSpace == 0) && m_Doc->view()) // Hairline case
extraSpace = 0.5 / m_Doc->view()->scale();
}
}
if (m_rotation != 0)
{
FPointArray pb;
pb.resize(0);
pb.addPoint(FPoint(0.0, -extraSpace, xPos(), yPos(), m_rotation, 1.0, 1.0));
pb.addPoint(FPoint(visualWidth(), -extraSpace, xPos(), yPos(), m_rotation, 1.0, 1.0));
pb.addPoint(FPoint(visualWidth(), +extraSpace, xPos(), yPos(), m_rotation, 1.0, 1.0));
pb.addPoint(FPoint(0.0, +extraSpace, xPos(), yPos(), m_rotation, 1.0, 1.0));
for (uint pc = 0; pc < 4; ++pc)
{
minx = qMin(minx, pb.point(pc).x());
miny = qMin(miny, pb.point(pc).y());
maxx = qMax(maxx, pb.point(pc).x());
maxy = qMax(maxy, pb.point(pc).y());
}
*x1 = minx;
*y1 = miny;
*x2 = maxx;
*y2 = maxy;
}
else
{
*x1 = m_xPos;
*y1 = m_yPos - extraSpace;
*x2 = m_xPos + visualWidth();
*y2 = m_yPos + extraSpace;
}
QRectF totalRect(QPointF(*x1, *y1), QPointF(*x2, *y2));
if (m_startArrowIndex != 0)
{
QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles().at(m_startArrowIndex-1).points.copy();
arrowTrans.translate(m_xPos, m_yPos);
arrowTrans.rotate(m_rotation);
arrowTrans.translate(0, 0);
arrowTrans.scale(m_startArrowScale / 100.0, m_startArrowScale / 100.0);
if (NamedLStyle.isEmpty())
{
if (m_lineWidth != 0.0)
arrowTrans.scale(m_lineWidth, m_lineWidth);
}
else
{
multiLine ml = m_Doc->MLineStyles[NamedLStyle];
if (ml[ml.size()-1].Width != 0.0)
arrowTrans.scale(ml[ml.size()-1].Width, ml[ml.size()-1].Width);
}
arrowTrans.scale(-1,1);
arrow.map(arrowTrans);
FPoint minAr = getMinClipF(&arrow);
FPoint maxAr = getMaxClipF(&arrow);
totalRect = totalRect.united(QRectF(QPointF(minAr.x(), minAr.y()), QPointF(maxAr.x(), maxAr.y())));
}
if (m_endArrowIndex != 0)
{
QTransform arrowTrans;
FPointArray arrow = m_Doc->arrowStyles().at(m_endArrowIndex-1).points.copy();
arrowTrans.translate(m_xPos, m_yPos);
arrowTrans.rotate(m_rotation);
arrowTrans.translate(m_width, 0);
arrowTrans.scale(m_endArrowScale / 100.0, m_endArrowScale / 100.0);
if (NamedLStyle.isEmpty())
//.........这里部分代码省略.........
示例6: digitalPattern_Rotate
bool DataConverter::digitalPattern_Rotate(QPolygonF &points, qreal angle)
{
if (angle == 0.0)
return true;
if (angle < -180.0 || angle > 180.0)
{
qDebug("[DataConverter::digitalPattern_Rotate] Error: Angle: [%f]", angle);
return false;
}
if (points.size() < 10)
{
qDebug("[DataConverter::digitalPattern_Rotate] Error: Polygon Point Count: [%d]", points.size());
return false;
}
//
QTransform transform;
transform.rotate(angle);
points = transform.map(points);
//
int bottomIndex = 0;
{
qreal tmpX = -9999.99;
for (int i = 0; i < points.size(); i++)
{
if (points.at(i).y() < 0.0)
continue;
if (points.at(i).x() > 0.0)
continue;
if (points.at(i).x() > tmpX)
{
tmpX = points.at(i).x();
bottomIndex = i;
}
}
}
qDebug("** bottomIndex: [%d]", bottomIndex);
if (bottomIndex > 0)
{
QPointF tmpPoint;
for (int i = points.size() - 1; i >= bottomIndex; i--)
{
tmpPoint = points.last();
points.pop_back();
points.push_front(tmpPoint);
}
}
return true;
}
示例7: paintEvent
void ImagePane::paintEvent(QPaintEvent* /*event*/)
{
QPainter painter(this);
//draw the transformed version of the text-object image
painter.drawImage(0, 0, transformedImage);
//then we draw the bounding boxes
//TODO inscriptions with at least one graph are a different color (?)
//in case index numbers are visible, set font
QFont font;
font.setPixelSize(30/zoom); //TODO make font size dependent on resolution
painter.setFont(font);
QPen pen;
pen.setWidth(0);
pen.setColor(Qt::red);
painter.setPen(pen);
//make a list of bounding boxes according to current mode
BoxList currentBoxList; //this is a list of all boxes
currentBoxList.clear();
switch(mode)
{
case SURFACE:
currentBoxList.append(*surf); //list of one item, consting of the surface bounding box
break;
case INSCRIPTION:
for(int i=0; i < surf->inscriptionCount(); i++)
currentBoxList.insertBox(surf->inscrAt(i), i);
break;
case GRAPH:
for(int i=0; i < surf->ptrInscrAt(currentInscrIndex)->count(); i++)
currentBoxList.insertBox(surf->ptrInscrAt(currentInscrIndex)->at(i), i);
break;
default:
break;
}
//iterate through the list of bounding boxes
for (int i=0; i<currentBoxList.size(); i++)
{
BoundingBox currentBox = currentBoxList.at(i);
//the bounding boxes need to be rotated and scaled
QTransform boxTransform; //identity matrix
//first we need to handle the bounding box's own rotation
//by inverting the true matrix that was applied to the image
//at the time each bounding box was created
//(note: we don't need to worry about scale, as we took account of that
//when the bounding box was created)
boxTransform.rotate(currentBox.getRotation());
boxTransform = QImage::trueMatrix(boxTransform,
currentImage.width(), currentImage.height());
boxTransform = boxTransform.inverted();
//then we compound the above matrix with the current transformation of the image
QTransform imageTrueTransform = QImage::trueMatrix(transform,
currentImage.width(), currentImage.height());
painter.setWorldTransform(boxTransform * imageTrueTransform);
//now draw the box
//pen color is red; set the pen-color to green if this is the current box.
if(i==currentBoxIndex)
{
QPen pen;
pen.setWidth(0);
pen.setColor(Qt::green);
painter.setPen(pen);
}
painter.drawRect(currentBox);
//and add an (optional) index number
if(indexNumbersVisible)
{
painter.drawText(currentBox.left(), currentBox.top(), 50/zoom, 50/zoom,
Qt::AlignBottom, QString("%1").arg(i+1)); //visible index, so base = 1, not zero
}
//return pen color to red (might be green)
QPen pen;
pen.setWidth(0);
pen.setColor(Qt::red);
painter.setPen(Qt::red);
}
//if label is not resized, it will stay large on zoom out
//resulting in misleading / redundant scroll bars
resize(transformedImage.size()); // keep label same size as image
}
示例8: determineResizingMode
UBRubberBand::enm_resizingMode UBRubberBand::determineResizingMode(QPoint pos)
{
if (mMouseIsPressed)
return mResizingMode;
QRect resizerTop (mResizingBorderHeight , 0 , rect().width()-2*mResizingBorderHeight, mResizingBorderHeight );
QRect resizerBottom (mResizingBorderHeight , rect().height() - mResizingBorderHeight, rect().width()-2*mResizingBorderHeight, mResizingBorderHeight );
QRect resizerLeft (0 , mResizingBorderHeight , mResizingBorderHeight , rect().height() - 2*mResizingBorderHeight);
QRect resizerRight (rect().width()-mResizingBorderHeight, mResizingBorderHeight , mResizingBorderHeight , rect().height() - 2*mResizingBorderHeight);
QRect resizerTopLeft (0 , 0 , mResizingBorderHeight, mResizingBorderHeight);
QRect resizerTopRight (rect().width()-mResizingBorderHeight, 0 , mResizingBorderHeight, mResizingBorderHeight);
QRect resizerBottomLeft (0 , rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
QRect resizerBottomRight(rect().width()-mResizingBorderHeight, rect().height() - mResizingBorderHeight, mResizingBorderHeight, mResizingBorderHeight);
enm_resizingMode resizingMode;
QTransform cursorTransrofm;
if (resizerTop.contains(pos))
{
resizingMode = Top;
cursorTransrofm.rotate(90);
}
else
if (resizerBottom.contains(pos))
{
resizingMode = Bottom;
cursorTransrofm.rotate(90);
}
else
if (resizerLeft.contains(pos))
{
resizingMode = Left;
}
else
if (resizerRight.contains(pos))
{
resizingMode = Right;
}
else
if (resizerTopLeft.contains(pos))
{
resizingMode = TopLeft;
cursorTransrofm.rotate(45);
}
else
if (resizerTopRight.contains(pos))
{
resizingMode = TopRight;
cursorTransrofm.rotate(-45);
}
else
if (resizerBottomLeft.contains(pos))
{
resizingMode = BottomLeft;
cursorTransrofm.rotate(-45);
}
else
if (resizerBottomRight.contains(pos))
{
resizingMode = BottomRight;
cursorTransrofm.rotate(45);
}
else
resizingMode = None;
if (None != resizingMode)
{
QPixmap pix(":/images/cursors/resize.png");
QCursor resizeCursor = QCursor(pix.transformed(cursorTransrofm, Qt::SmoothTransformation), pix.width() / 2, pix.height() / 2);
setCursor(resizeCursor);
}
else
unsetCursor();
return resizingMode;
}
示例9: updateGraphicsItemTransform
void BI_FootprintPad::updateGraphicsItemTransform() noexcept {
QTransform t;
if (mFootprint.getIsMirrored()) t.scale(qreal(-1), qreal(1));
t.rotate(-mRotation.toDeg());
mGraphicsItem->setTransform(t);
}
示例10: paintEvent
void TruckMapWidget::paintEvent(QPaintEvent *evt) {
Lock l(m_scaleFactorMutex);
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
const double scaleMax = 5;
const double scaleMin = 1e-4;
const double offsetViewMaxFactor = 8;
if (m_scaleFactor < scaleMin) {
m_scaleFactor = scaleMin;
} else if (m_scaleFactor > scaleMax) {
m_scaleFactor = scaleMax;
}
// White background.
painter.fillRect(evt->rect(), QBrush(Qt::white));
// Variables for displaying labels on the map.
QString description;
QPointF pt_description;
QRectF rect_description;
QFont fontSettings = this->font();
QPen pen;
// Map coordinate system transformation according to DIN 70000: x = 12am, y = 9am --> m_rotation = +90 (http://www.isupia.de/download/Fahrdynamische%20Größen.pdf)
QTransform transformationDIN70000;
transformationDIN70000.translate(evt->rect().width() / 2, evt->rect().height() / 2);
transformationDIN70000.scale(m_scaleFactor, -m_scaleFactor);
transformationDIN70000.rotate(m_rotation);
// Transformation into the regular coordinate system.
QTransform transformationCartesianCoordinateSystem;
transformationCartesianCoordinateSystem.translate(evt->rect().width() / 2, evt->rect().height() / 2);
transformationCartesianCoordinateSystem.scale(m_scaleFactor, -m_scaleFactor);
transformationCartesianCoordinateSystem.rotate(m_rotation - 90);
// Transformation into the regular coordinate system for descriptions.
QTransform transformationCartesianCoordinateSystemForDescriptions;
transformationCartesianCoordinateSystemForDescriptions.translate(evt->rect().width() / 2, evt->rect().height() / 2);
transformationCartesianCoordinateSystemForDescriptions.scale(1, 1);
transformationCartesianCoordinateSystemForDescriptions.rotate(m_rotation - 90);
// Transformation for descriptions label in image coordinates.
QTransform descriptionTrans;
descriptionTrans.translate(0, 0);
descriptionTrans.scale(1, 1);
descriptionTrans.rotate(0);
// Setup fonts.
fontSettings.setPointSize(10);
painter.setFont(fontSettings);
// Setup axes parameters.
const double scaleMultiplier = ceil((1 / ((m_scaleFactor * 100) / 50)));
const double step = 100 * scaleMultiplier;
const double zeroAxisWidth = 3;
const QColor zeroAxisColor = Qt::black;
const QColor gridAxisColor = Qt::gray;
const QColor textColor = QPalette::Foreground;
const double xStepFact = ceil(width() * offsetViewMaxFactor / step / m_scaleFactor);
const double yStepFact = ceil(height() * offsetViewMaxFactor / step / m_scaleFactor);
// Draw X-axes.
for (double i = -yStepFact * step;i < yStepFact * step;i += step) {
if ((int)(i / step) % 2) {
painter.setPen(gridAxisColor);
}
else {
description.sprintf("%.0f", i/1000.0);
pt_description.setY(i);
painter.setTransform(descriptionTrans);
pt_description = transformationCartesianCoordinateSystem.map(pt_description);
pt_description.setX(10);
pt_description.setY(pt_description.y() - 5);
painter.setPen(QPen(textColor));
painter.drawText(pt_description, description);
if (fabs(i) < 1e-5) {
pen.setWidthF(zeroAxisWidth / m_scaleFactor);
pen.setColor(zeroAxisColor);
}
else {
pen.setWidth(0);
}
painter.setPen(pen);
}
painter.setTransform(transformationDIN70000);
painter.drawLine(-xStepFact * step, i, xStepFact * step, i);
}
// Draw Y-axis segments
for (double i = -xStepFact * step;i < xStepFact * step;i += step) {
if ((int)(i / step) % 2) {
painter.setPen(gridAxisColor);
}
//.........这里部分代码省略.........
示例11: 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);
//.........这里部分代码省略.........
示例12: if
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
{
//width
double symbolWidth = mSymbolWidth;
QgsExpression* widthExpression = expression( "width" );
if ( widthExpression ) //1. priority: data defined setting on symbol layer level
{
symbolWidth = widthExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolWidth = mSize;
}
if ( mSymbolWidthUnit == QgsSymbolV2::MM )
{
symbolWidth *= mmMapUnitScaleFactor;
}
//height
double symbolHeight = mSymbolHeight;
QgsExpression* heightExpression = expression( "height" );
if ( heightExpression ) //1. priority: data defined setting on symbol layer level
{
symbolHeight = heightExpression->evaluate( const_cast<QgsFeature*>( f ) ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolHeight = mSize;
}
if ( mSymbolHeightUnit == QgsSymbolV2::MM )
{
symbolHeight *= mmMapUnitScaleFactor;
}
//outline width
double outlineWidth = mOutlineWidth;
QgsExpression* outlineWidthExpression = expression( "outline_width" );
if ( outlineWidthExpression )
{
outlineWidth = outlineWidthExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
}
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
{
outlineWidth *= outlineWidth;
}
//fill color
QColor fc = mFillColor;
QgsExpression* fillColorExpression = expression( "fill_color" );
if ( fillColorExpression )
{
fc = QColor( fillColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
}
int fillColorIndex = e.closestColorMatch( fc.rgb() );
//outline color
QColor oc = mOutlineColor;
QgsExpression* outlineColorExpression = expression( "outline_color" );
if ( outlineColorExpression )
{
oc = QColor( outlineColorExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString() );
}
int outlineColorIndex = e.closestColorMatch( oc.rgb() );
//symbol name
QString symbolName = mSymbolName;
QgsExpression* symbolNameExpression = expression( "symbol_name" );
if ( symbolNameExpression )
{
QgsExpression* symbolNameExpression = expression( "symbol_name" );
symbolName = symbolNameExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toString();
}
//offset
double offsetX = 0;
double offsetY = 0;
markerOffset( *context, offsetX, offsetY );
QPointF off( offsetX, offsetY );
//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
double rotation = 0.0;
QgsExpression* rotationExpression = expression( "rotation" );
if ( rotationExpression )
{
rotation = rotationExpression->evaluate( const_cast<QgsFeature*>( context->feature() ) ).toDouble();
}
else if ( !qgsDoubleNear( mAngle, 0.0 ) )
{
rotation = mAngle;
}
rotation = -rotation; //rotation in Qt is counterclockwise
if ( rotation )
off = _rotatedOffset( off, rotation );
QTransform t;
t.translate( shift.x() + offsetX, shift.y() + offsetY );
if ( rotation != 0 )
t.rotate( rotation );
//.........这里部分代码省略.........
示例13: run
bool PathStrokerPlugin::run(ScribusDoc* doc, QString)
{
ScribusDoc* currDoc = doc;
if (currDoc == 0)
currDoc = ScCore->primaryMainWindow()->doc;
if (currDoc->m_Selection->count() > 0)
{
QVector<double> m_array;
PageItem *currItem = currDoc->m_Selection->itemAt(0);
FPointArray path = currItem->PoLine;
QPainterPath pp;
if (currItem->itemType() == PageItem::PolyLine)
pp = path.toQPainterPath(false);
else
pp = path.toQPainterPath(true);
if (currItem->NamedLStyle.isEmpty())
{
QPainterPathStroker stroke;
stroke.setCapStyle(currItem->lineEnd());
stroke.setJoinStyle(currItem->lineJoin());
if (currItem->lineStyle() == Qt::SolidLine)
stroke.setDashPattern(currItem->lineStyle());
else
{
getDashArray(currItem->lineStyle(), 1, m_array);
stroke.setDashPattern(m_array);
}
stroke.setWidth(currItem->lineWidth());
QPainterPath result = stroke.createStroke(pp).simplified();
if (currItem->startArrowIndex() != 0)
{
FPoint Start = currItem->PoLine.point(0);
for (uint xx = 1; xx < currItem->PoLine.size(); xx += 2)
{
FPoint Vector = currItem->PoLine.point(xx);
if ((Start.x() != Vector.x()) || (Start.y() != Vector.y()))
{
double r = atan2(Start.y()-Vector.y(),Start.x()-Vector.x())*(180.0/M_PI);
QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->startArrowIndex()-1).points.copy();
arrowTrans.translate(Start.x(), Start.y());
arrowTrans.rotate(r);
arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth());
arrow.map(arrowTrans);
result.addPath(arrow.toQPainterPath(true));
break;
}
}
}
if (currItem->endArrowIndex() != 0)
{
FPoint End = currItem->PoLine.point(currItem->PoLine.size()-2);
for (uint xx = currItem->PoLine.size()-1; xx > 0; xx -= 2)
{
FPoint Vector = currItem->PoLine.point(xx);
if ((End.x() != Vector.x()) || (End.y() != Vector.y()))
{
double r = atan2(End.y()-Vector.y(),End.x()-Vector.x())*(180.0/M_PI);
QTransform arrowTrans;
FPointArray arrow = currDoc->arrowStyles.at(currItem->endArrowIndex()-1).points.copy();
arrowTrans.translate(End.x(), End.y());
arrowTrans.rotate(r);
arrowTrans.scale(currItem->lineWidth(), currItem->lineWidth());
arrow.map(arrowTrans);
result.addPath(arrow.toQPainterPath(true));
break;
}
}
}
currDoc->m_Selection->clear();
PageItem* newItem = currDoc->convertItemTo(currItem, PageItem::Polygon);
newItem->setLineWidth(0);
newItem->setLineStyle(Qt::SolidLine);
newItem->setFillColor(newItem->lineColor());
newItem->setFillShade(newItem->lineShade());
newItem->setFillTransparency(newItem->lineTransparency());
newItem->setFillBlendmode(newItem->lineBlendmode());
FPointArray points;
points.fromQPainterPath(result);
newItem->PoLine = points;
newItem->Frame = false;
newItem->ClipEdited = true;
newItem->FrameType = 3;
currDoc->AdjustItemSize(newItem);
newItem->OldB2 = newItem->width();
newItem->OldH2 = newItem->height();
newItem->updateClip();
newItem->ContourLine = newItem->PoLine.copy();
newItem->setFillEvenOdd(true);
currDoc->m_Selection->addItem(newItem);
}
else
{
currDoc->m_Selection->clear();
multiLine ml = currDoc->MLineStyles[currItem->NamedLStyle];
bool first = true;
for (int it = ml.size()-1; it > -1; it--)
{
if ((ml[it].Color != CommonStrings::None) && (ml[it].Width != 0))
{
//.........这里部分代码省略.........
示例14: if
bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFactor, const QString& layerName, const QgsSymbolV2RenderContext* context, const QgsFeature* f, const QPointF& shift ) const
{
//width
double symbolWidth = mSymbolWidth;
if ( hasDataDefinedProperty( "width" ) ) //1. priority: data defined setting on symbol layer le
{
symbolWidth = evaluateDataDefinedProperty( "width", f, mSymbolWidth ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolWidth = mSize;
}
if ( mSymbolWidthUnit == QgsSymbolV2::MM )
{
symbolWidth *= mmMapUnitScaleFactor;
}
//height
double symbolHeight = mSymbolHeight;
if ( hasDataDefinedProperty( "height" ) ) //1. priority: data defined setting on symbol layer level
{
symbolHeight = evaluateDataDefinedProperty( "height", f, mSymbolHeight ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
symbolHeight = mSize;
}
if ( mSymbolHeightUnit == QgsSymbolV2::MM )
{
symbolHeight *= mmMapUnitScaleFactor;
}
//outline width
double outlineWidth = mOutlineWidth;
if ( hasDataDefinedProperty( "outline_width" ) )
{
outlineWidth = evaluateDataDefinedProperty( "outline_width", f, mOutlineWidth ).toDouble();
}
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
{
outlineWidth *= outlineWidth;
}
//fill color
bool ok;
QColor fc = mFillColor;
if ( hasDataDefinedProperty( "fill_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "fill_color", f, QVariant(), &ok ).toString();
if ( ok )
fc = QColor( colorString );
}
//outline color
QColor oc = mOutlineColor;
if ( hasDataDefinedProperty( "outline_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "outline_color", f, QVariant(), &ok ).toString();
if ( ok )
oc = QColor( colorString );
}
//symbol name
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( "symbol_name" ) )
{
symbolName = evaluateDataDefinedProperty( "symbol_name", f, mSymbolName ).toString();
}
//offset
double offsetX = 0;
double offsetY = 0;
markerOffset( *context, offsetX, offsetY );
QPointF off( offsetX, offsetY );
//priority for rotation: 1. data defined symbol level, 2. symbol layer rotation (mAngle)
double rotation = 0.0;
if ( hasDataDefinedProperty( "rotation" ) )
{
rotation = evaluateDataDefinedProperty( "rotation", f, mAngle ).toDouble();
}
else if ( !qgsDoubleNear( mAngle, 0.0 ) )
{
rotation = mAngle;
}
rotation = -rotation; //rotation in Qt is counterclockwise
if ( rotation )
off = _rotatedOffset( off, rotation );
QTransform t;
t.translate( shift.x() + offsetX, shift.y() + offsetY );
if ( rotation != 0 )
t.rotate( rotation );
double halfWidth = symbolWidth / 2.0;
double halfHeight = symbolHeight / 2.0;
//.........这里部分代码省略.........
示例15: run
bool PathAlongPathPlugin::run(ScribusDoc* doc, const QString&)
{
firstUpdate = true;
m_doc = doc;
originalPathG.clear();
originalRotG.clear();
originalXPosG.clear();
originalYPosG.clear();
patternItemG.clear();
if (m_doc == nullptr)
m_doc = ScCore->primaryMainWindow()->doc;
if (m_doc->m_Selection->count() > 1)
{
if ((m_doc->m_Selection->itemAt(0)->isGroup()) || (m_doc->m_Selection->itemAt(1)->isGroup()))
{
selOffs = 0;
selCount = m_doc->m_Selection->count() - 1;
if (!m_doc->m_Selection->itemAt(0)->isGroup())
{
pathItem = m_doc->m_Selection->itemAt(0);
selOffs = 1;
}
else
pathItem = m_doc->m_Selection->itemAt(selCount);
effectPath = pathItem->PoLine.copy();
QTransform mp;
mp.rotate(pathItem->rotation());
effectPath.map(mp);
PageItem* bxi = m_doc->m_Selection->itemAt(selOffs);
bxi->asGroupFrame()->adjustXYPosition();
originalPathG.append(bxi->PoLine.copy());
originalXPosG.append(bxi->xPos());
originalYPosG.append(bxi->yPos());
originalXPosGi.append(bxi->gXpos);
originalYPosGi.append(bxi->gYpos);
originalRotG.append(bxi->rotation());
originalWidth.append(bxi->width());
originalHeight.append(bxi->height());
originalWidthG.append(bxi->groupWidth);
originalHeightG.append(bxi->groupHeight);
patternItemG.append(bxi);
QList<PageItem*> bxiL = bxi->getAllChildren();
for (int bx = 0; bx < bxiL.count(); ++bx)
{
PageItem* cIte = bxiL.at(bx);
originalPathG.append(cIte->PoLine.copy());
originalXPosG.append(cIte->xPos());
originalYPosG.append(cIte->yPos());
originalWidth.append(cIte->width());
originalHeight.append(cIte->height());
originalWidthG.append(cIte->groupWidth);
originalHeightG.append(cIte->groupHeight);
originalXPosGi.append(cIte->gXpos);
originalYPosGi.append(cIte->gYpos);
originalRotG.append(cIte->rotation());
patternItemG.append(cIte);
}
QPainterPath tmpPath = effectPath.toQPainterPath(false);
PathDialog *dia = new PathDialog(m_doc->scMW(), m_doc->unitIndex(), tmpPath.length(), true);
connect(dia, SIGNAL(updateValues(int, double, double, double, int)), this, SLOT(updateEffectG(int, double, double, double, int)));
if (dia->exec())
{
updateEffectG(dia->effectType, dia->offset, dia->offsetY, dia->gap, dia->rotate);
m_doc->changed();
if (bxi->isGroup())
{
m_doc->resizeGroupToContents(bxi);
bxi->SetRectFrame();
m_doc->view()->DrawNew();
}
}
else
{
updateEffectG(-1, dia->offset, dia->offsetY, dia->gap, dia->rotate);
m_doc->view()->DrawNew();
}
delete dia;
}
else
{