QLine extractBlackGuide(QImage input,QPoint start,bool hor) { QLine line; QPoint step(1,0); if (!hor) { // vertical movement step = QPoint(0,1); } QPoint pt = start; while (pt.x() < input.width() && pt.y() < input.height()) { if (input.pixel(pt) == 0xFF000000) { line.setP1(pt); break; } pt += step; } while (pt.x() < input.width() && pt.y() < input.height()) { if (input.pixel(pt) != 0xFF000000) { line.setP2(pt); break; } pt += step; } return line; }
void qAttitudeIndicator::initRollChar() { QLine line; line.setLine(-size/32,14*size/32,0,15*size/32); target.append(line); line.setLine(0,15*size/32,size/32,14*size/32); target.append(line); line.setLine(size/32,14*size/32,-size/32,14*size/32); target.append(line); }
QHash<QString, QLine> Controller::coordinateAxes(Length length){ QLine x; QLine y; QLine z; int size = length; //z z.setP1(QPoint(0, size)); z.setP2(QPoint(0, -size)); //x x.setP1(QPoint( -size, 0)); x.setP2(QPoint(size, 0)); //z y.setP1(QPoint(size * cos(_alpha * M_PI/180), -size * sin(_alpha * M_PI/180))); y.setP2(QPoint(-size * cos(_alpha * M_PI/180), size * sin(_alpha * M_PI/180))); QHash<QString, QLine> axes = { {"X", x}, {"Y", y}, {"Z", z} }; return axes; }
void map_widget::drawRobotPose(QPainter *painter , QPaintEvent *event) { QPoint Robot_Pose = this->convertToActFrame( sensor_connection->act_pose.x_pos, sensor_connection->act_pose.y_pos, event ); painter->setPen( QPen( Qt::red, 5, Qt::SolidLine, Qt::RoundCap) ); painter->drawPoint( Robot_Pose ); // Draw the orientatian; // Berechne Steigung const double lenght_of_orientation_line = 2.0; double theta = sensor_connection->act_pose.theta; while( theta >= (2* M_PI) ) { theta -= (2* M_PI); } double skew_y = tan( theta ); double skew_x = 1.0; if( theta == 0.5 * M_PI ) { skew_y = 1.0; skew_x = 0.0; } else if( theta == (3.0*M_PI)/2.0 ) { skew_y = -1.0; skew_x = 0.0; } else if( theta >= 0.5 * M_PI && theta < (3.0*M_PI)/2.0) { skew_y *= -1.0; skew_x *= -1.0; } double distance = sqrt( (skew_x*skew_x) + (skew_y*skew_y) ); skew_x = (skew_x * lenght_of_orientation_line) / distance; skew_y = (skew_y * lenght_of_orientation_line) / distance; skew_x *= ((double) event->rect().width() / (double) this->visible_rect.width() ); skew_y *= ((double) event->rect().height() / (double) this->visible_rect.height() ); QLine line; line.setP1( Robot_Pose ); line.setP2( QPoint(Robot_Pose.x() + skew_x, Robot_Pose.y() - skew_y) ); painter->setPen( QPen( Qt::red, 3, Qt::SolidLine, Qt::RoundCap) ); painter->drawLine( line ); }
void qAttitudeIndicator::initTargetChar() { QLine line; line.setLine(-size/4,0,-size/16,0); target.append(line); line.setLine(-size/16,0,0,-size/32); target.append(line); line.setLine(0,-size/32,size/16,0); target.append(line); line.setLine(size/16,0,size/4,0); target.append(line); }
// Draw connection lines between linking // operators (to visualize dependencies). void eGuiOpPage::_drawLinkLines(QPainter *painter) { eASSERT(painter != eNULL); static const QPoint arrowPts[3] = { QPoint(0, 0), QPoint(-ARROW_SIZE, ARROW_SIZE), QPoint(-ARROW_SIZE, -ARROW_SIZE) }; painter->save(); painter->setRenderHint(QPainter::HighQualityAntialiasing, true); painter->setPen(QColor(80, 90, 100)); painter->setBrush(QBrush(QColor(120, 130, 140), Qt::SolidPattern)); for (eU32 i=0; i<m_opPage->getOperatorCount(); i++) { const eIOperator *op = m_opPage->getOperatorByIndex(i); eASSERT(op != eNULL); for (eU32 j=0; j<op->getLinkingCount(); j++) { const eID linkingId = op->getLinkingOperator(j); const eIOperator *linkingOp = eDemoData::findOperator(linkingId); // Lies linking operator on same page? if (linkingOp && linkingOp->getOwnerPage() == m_opPage) { // Yes, so draw line between them. const QRect opRect = _getOperatorRect(op); const QRect linkingRect = _getOperatorRect(linkingOp); // Calculate nearest intersection point and // angle to rotate arrow. const QPoint nip = _getNearestIntersectionPoint(opRect, QLine(linkingRect.center(), opRect.center())); const QLine line(nip, linkingRect.center()); const QPoint p = line.p1()-line.p2(); const eF32 angle = eRadToDeg(eATan2(p.y(), p.x())); painter->drawLine(line); painter->save(); painter->translate(line.p1().x(), line.p1().y()); painter->rotate(angle); painter->drawConvexPolygon(arrowPts, 3); painter->restore(); } } } painter->restore(); }
void line(const QLine& line, Callback&& func) { // Sign of delta x/y int sx = line.dx() > 0 ? 1 : -1; int sy = line.dy() > 0 ? 1 : -1; // Value that determines whether to move on X or Y int error = 0; // Absolute value of delta x/y int deltaerry = line.dy() * sy; int deltaerrx = line.dx() * sx; QPoint point = line.p1(); while ( point != line.p2() ) { func(point); error += deltaerry; while ( error >= deltaerrx / 2 && point.y() != line.y2() ) { func(point); point.setY(point.y() + sy); error -= deltaerrx; } if ( point.x() != line.x2() ) point.setX(point.x() + sx); } func(point); }
void WidgetArea::addPlacementLine(int val, bool vertical, bool& changed) { QLine l; if(vertical) l.setLine(val, -PLACEMENT_SHOW, val, height()+PLACEMENT_SHOW); else l.setLine(-PLACEMENT_SHOW, val, width()+PLACEMENT_SHOW, val); if(m_placementLines.contains(l)) return; m_placementLines.push_back(l); changed = true; }
QString PackageManager::sendLine(QDataStream &stream, QLine line, QPen pen, QString old) { // "order:line:x1:y1:x2:y3:color:size" QString packet = "order:line:"; packet += QString::number(line.x1()) + ":"; packet += QString::number(line.y1()) + ":"; packet += QString::number(line.x2()) + ":"; packet += QString::number(line.y2()) + ":"; packet += pen.color().name() += ":"; packet += QString::number(pen.width()); if (packet != old) stream << packet; return packet; }
QIcon ConfigTabAppearance::createThemeIcon(const QString &fileName) { QSettings settings(fileName, QSettings::IniFormat); Theme theme(settings); QPixmap pix(16, 16); pix.fill(Qt::black); QPainter p(&pix); QRect rect(1, 1, 14, 5); p.setPen(Qt::NoPen); p.setBrush( theme.color("sel_bg") ); p.drawRect(rect); rect.translate(0, 5); p.setBrush( theme.color("bg") ); p.drawRect(rect); rect.translate(0, 5); p.setBrush( theme.color("alt_bg") ); p.drawRect(rect); QLine line; line = QLine(2, 3, 14, 3); QPen pen; p.setOpacity(0.6); pen.setColor( theme.color("sel_fg") ); pen.setDashPattern(QVector<qreal>() << 2 << 1 << 1 << 1 << 3 << 1 << 2 << 10); p.setPen(pen); p.drawLine(line); line.translate(0, 5); pen.setColor( theme.color("fg") ); pen.setDashPattern(QVector<qreal>() << 2 << 1 << 4 << 10); p.setPen(pen); p.drawLine(line); line.translate(0, 5); pen.setDashPattern(QVector<qreal>() << 3 << 1 << 2 << 1); p.setPen(pen); p.drawLine(line); return pix; }
void FwLinePrimitive::setLine(const QLine& line) { if(line != this->line()) { prepareGeometryChanged(); setPos(line.p1()); m_p2 = line.p2() - line.p1(); if(line.y1() == line.y2()) { m_orientation = Fw::O_Horizontal; m_lenght = m_p2.x() - pos().x(); } else if(line.x1() == line.x2()) { m_orientation = Fw::O_Vertical; m_lenght = m_p2.y() - pos().y(); } else { m_orientation = Fw::O_Diagonal; m_lenght = qRound(QLineF(line).length()); } update(); } }
QPoint eGuiOpPage::_getNearestIntersectionPoint(const QRect &r, const QLine &line) const { // First, calculate intersections with all four // rectangle sides. const QLineF lines[4] = { QLineF(r.topLeft(), r.topRight()), QLineF(r.topRight(), r.bottomRight()), QLineF(r.bottomRight(), r.bottomLeft()), QLineF(r.bottomLeft(), r.topLeft()) }; QVector<QPoint> ips; QPointF ip; for (eInt i=0; i<4; i++) { if (lines[i].intersect(line, &ip) == QLineF::BoundedIntersection) { ips.append(ip.toPoint()); } } eASSERT(ips.size() != eNULL); // Second, find nearest intersection point. QPoint nip = ips[0]; eU32 minDist = (nip-line.p2()).manhattanLength(); for (eInt i=1; i<ips.size(); i++) { eU32 dist = (ips[i]-line.p2()).manhattanLength(); if (dist < minDist) { minDist = dist; nip = ips[i]; } } return nip; }
static inline QRegion qwtMaskRegion( const QLine &l, int penWidth ) { const int pw = qMax( penWidth, 1 ); const int pw2 = penWidth / 2; QRegion region; if ( l.x1() == l.x2() ) { region += QRect( l.x1() - pw2, l.y1(), pw, l.y2() ).normalized(); } else if ( l.y1() == l.y2() ) { region += QRect( l.x1(), l.y1() - pw2, l.x2(), pw ).normalized(); } return region; }
double PlotIterPath::pointDistToLine_(const QPoint &p, const QLine &l) { // Project the point on the line. double lx = l.x2() - l.x1(); double ly = l.y2() - l.y1(); double ll = sqrt(lx*lx + ly*ly); double vx = p.x() - l.x1(); double vy = p.y() - l.y1(); double prPar = (vx*lx + vy*ly) / ll; double prPerp = (vx*ly - vy*lx) / ll; // The point is on the "left" side of the line. if(prPar < 0) return sqrt(vx*vx + vy*vy); // The point is on the "right" side of the line. else if(prPar > ll) return sqrt(vx*vx + vy*vy); else return fabs(prPerp); }
QPoint Rotater::get_line_cross_point(QLine base_line, QLine rotate_line) { qreal k = (qreal)rotate_line.dy() / rotate_line.dx(); int x(0), y(0); if (base_line.dy() == 0) { x = (base_line.y1() - rotate_line.y1()) / k + rotate_line.x1(); y = base_line.y1(); } else if (base_line.dx() == 0) { y = (base_line.x1() - rotate_line.x1()) * k + rotate_line.y1(); x = base_line.x1(); } // qDebug() << "k dx dy" << k << rotate_line.dx() << rotate_line.dy(); // qDebug() << "rotate_line x1 y1" << rotate_line.x1() << rotate_line.y1(); // qDebug() << "rotate_line x2 y2" << rotate_line.x2() << rotate_line.y2(); QPoint p(x, y); return p; }
QT_BEGIN_NAMESPACE /*! \class QLine \inmodule QtCore \ingroup painting \brief The QLine class provides a two-dimensional vector using integer precision. A QLine describes a finite length line (or a line segment) on a two-dimensional surface. The start and end points of the line are specified using integer point accuracy for coordinates. Use the QLineF constructor to retrieve a floating point copy. \table \row \li \inlineimage qline-point.png \li \inlineimage qline-coordinates.png \endtable The positions of the line's start and end points can be retrieved using the p1(), x1(), y1(), p2(), x2(), and y2() functions. The dx() and dy() functions return the horizontal and vertical components of the line. Use isNull() to determine whether the QLine represents a valid line or a null line. Finally, the line can be translated a given offset using the translate() function. \sa QLineF, QPolygon, QRect */ /*! \fn QLine::QLine() Constructs a null line. */ /*! \fn QLine::QLine(const QPoint &p1, const QPoint &p2) Constructs a line object that represents the line between \a p1 and \a p2. */ /*! \fn QLine::QLine(int x1, int y1, int x2, int y2) Constructs a line object that represents the line between (\a x1, \a y1) and (\a x2, \a y2). */ /*! \fn bool QLine::isNull() const Returns true if the line is not set up with valid start and end point; otherwise returns false. */ /*! \fn QPoint QLine::p1() const Returns the line's start point. \sa x1(), y1(), p2() */ /*! \fn QPoint QLine::p2() const Returns the line's end point. \sa x2(), y2(), p1() */ /*! \fn int QLine::x1() const Returns the x-coordinate of the line's start point. \sa p1() */ /*! \fn int QLine::y1() const Returns the y-coordinate of the line's start point. \sa p1() */ /*! \fn int QLine::x2() const Returns the x-coordinate of the line's end point. \sa p2() */ /*! \fn int QLine::y2() const Returns the y-coordinate of the line's end point. \sa p2() */ /*! \fn int QLine::dx() const Returns the horizontal component of the line's vector. \sa dy() */ /*! \fn int QLine::dy() const Returns the vertical component of the line's vector. \sa dx() */ /*! \fn bool QLine::operator!=(const QLine &line) const Returns true if the given \a line is not the same as \e this line. A line is different from another line if any of their start or end points differ, or the internal order of the points is different. */ /*! \fn bool QLine::operator==(const QLine &line) const Returns true if the given \a line is the same as \e this line. A line is identical to another line if the start and end points are identical, and the internal order of the points is the same. */ /*! \fn void QLine::translate(const QPoint &offset) Translates this line by the given \a offset. */ /*! \fn void QLine::translate(int dx, int dy) \overload Translates this line the distance specified by \a dx and \a dy. */ /*! \fn QLine QLine::translated(const QPoint &offset) const \since 4.4 Returns this line translated by the given \a offset. */ /*! \fn QLine QLine::translated(int dx, int dy) const \overload \since 4.4 Returns this line translated the distance specified by \a dx and \a dy. */ /*! \fn void QLine::setP1(const QPoint &p1) \since 4.4 Sets the starting point of this line to \a p1. \sa setP2(), p1() */ /*! \fn void QLine::setP2(const QPoint &p2) \since 4.4 Sets the end point of this line to \a p2. \sa setP1(), p2() */ /*! \fn void QLine::setPoints(const QPoint &p1, const QPoint &p2) \since 4.4 Sets the start point of this line to \a p1 and the end point of this line to \a p2. \sa setP1(), setP2(), p1(), p2() */ /*! \fn void QLine::setLine(int x1, int y1, int x2, int y2) \since 4.4 Sets this line to the start in \a x1, \a y1 and end in \a x2, \a y2. \sa setP1(), setP2(), p1(), p2() */ #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug d, const QLine &p) { d << "QLine(" << p.p1() << ',' << p.p2() << ')'; return d; }
template<> Q_INLINE_TEMPLATE QLine _q_interpolate(const QLine &f, const QLine &t, qreal progress) { return QLine( _q_interpolate(f.p1(), t.p1(), progress), _q_interpolate(f.p2(), t.p2(), progress)); }
/*! \overload Creates and returns a QLine object that is a copy of the given \a line, mapped into the coordinate system defined by this matrix. Note that the transformed coordinates are rounded to the nearest integer. */ QLine QMatrix::map(const QLine &line) const { return QLine(map(line.p1()), map(line.p2())); }
foreach (const QLine &line, mLines) { painter->drawLine(line.x1() * pixWidth, line.y1() * pixHeight, line.x2() * pixWidth, line.y2() * pixHeight); }
QLine MathUtils::rotateQLine(QLine &line, qint32 angle) { QLine newLine(MathUtils::rotatePoint(line.p1(), angle).toPoint(), MathUtils::rotatePoint(line.p2(), angle).toPoint()); return newLine; }
/** * @brief RequestInterface::paintEvent */ void RequestInterface::paintEvent(QPaintEvent *) { setWindowTitle("NetworkBuilder"); setWindowIcon(QIcon("../network-logo.jpg")); // reset errors messages errors.clear(); // painter creation QPainter painter(this); // foreach building view for(unsigned int i = 0 ; i < buildingViews.size();i++) { BuildingView *currentBuildingView = buildingViews[i]; // take selected pen if view has been selected if(currentBuildingView == selectedBuildingView) painter.setPen(selectedPen); else painter.setPen(defaultPen); // draw the building painter.drawRect(*currentBuildingView); // add color bool isAdmin = currentBuildingView->getBuilding()->isAdmin(); if(isAdmin) painter.fillRect(*currentBuildingView, buildingAdminColor); else painter.fillRect(*currentBuildingView, buildingColor); // add floors for(unsigned int j=0; j< currentBuildingView->getFloorViews().size(); j++) { FloorView* currentFloorView(currentBuildingView->getFloorViews()[j]); // take selected pen if view has been selected if(selectedFloor == currentFloorView) painter.setPen(selectedPen); else painter.setPen(defaultPen); // get floor coordonates QRect rect(currentBuildingView->x()+15, currentBuildingView->y()+ 15 + j * 90, 120,75); painter.drawRect(rect); // add color if(isAdmin) painter.fillRect(rect, floorAdminColor); else painter.fillRect(rect, floorColor); // add floor name painter.drawText(rect, Qt::AlignHCenter,currentFloorView->getName()); // if all users are null set warning style and add an error in errors if(currentFloorView->getFloor()->isUsersNull()) { painter.setFont(warningTextFont); painter.setPen(warningTextPen); errors.push_back(currentFloorView->getName().toStdString()+" in "+currentBuildingView->getName().toStdString()+ " doesn't have any user."); } // add floor users painter.drawText(rect, Qt::AlignBottom+Qt::AlignCenter, currentFloorView->getUsers()); // reset pen and font painter.setFont(defaultFont); painter.setPen(defaultPen); } //add name painter.drawText(*currentBuildingView,Qt::AlignHCenter,currentBuildingView->getName()); // if all users are null set warning style and add an error in errors if(currentBuildingView->getBuilding()->isUsersNull() && !currentBuildingView->getBuildingPanel()->isReadOnly()) { painter.setFont(warningTextFont); painter.setPen(warningTextPen); errors.push_back(currentBuildingView->getName().toStdString()+" doesn't have any user."); } // add building users painter.drawText(*currentBuildingView, Qt::AlignBottom+Qt::AlignCenter, currentBuildingView->getUsers()); // reset pen and font painter.setFont(defaultFont); painter.setPen(defaultPen); } // foreach b2b view, add it on the board for(unsigned int i = 0; i< b2bViews.size(); i++) { Building_BuildingView *currentB2bView = b2bViews[i]; //check if the view is selected if(currentB2bView == selectedB2bView) painter.setPen(selectedPen); else painter.setPen(defaultPen); // get the line to draw // if there is an intersection between 2 building don't draw if(!currentB2bView->intersect()) { // draw the line QLine line = currentB2bView->getLine(); painter.drawLine(line); // find the middle of the line and right the distance // get the x average and the y average, offset 4 on y to place text above line QPoint mid((line.p2().x()+line.p1().x())/2, (line.p2().y()+line.p1().y())/2-4); // if distance == 0 set warning style and add an error double distance = currentB2bView->getB2b()->getDistance(); if(distance == 0) { painter.setFont(warningTextFont); painter.setPen(warningTextPen); errors.push_back("Distance between "+ currentB2bView->getBuilding1()->getName().toStdString() +" and "+currentB2bView->getBuilding2()->getName().toStdString()+" can't be null."); } // draw distance painter.drawText(mid, currentB2bView->getDistance()); // reset pen and style painter.setPen(defaultPen); painter.setFont(defaultFont); } } painter.end(); }
/** * @brief RequestInterface::mousePressEvent * @param event * find the current focus */ void RequestInterface::mousePressEvent(QMouseEvent *event) { // reset selected view pointers selectedBuildingView = 0; selectedB2bView = 0; selectedFloor = 0; // reset panel to default formPanel->setWidget(defaultPanel); // check if the user select a building or a floor for(unsigned int i = 0 ; i < buildingViews.size();i++) { BuildingView *currentBuildingView = buildingViews[i]; //check first floors for(unsigned int j =0; j < currentBuildingView->getFloorViews().size(); j++) { QRect rect(currentBuildingView->x()+15, currentBuildingView->y()+ 15 + j * 90, 120,75); if(rect.contains(event->pos())) { // select the floor and add the panel selectedFloor = currentBuildingView->getFloorViews()[j]; formPanel->setWidget(selectedFloor->getFloorPanel()); break; } } // if no floor has been selected if(selectedFloor==0 && buildingViews[i]->contains(event->pos())) { // select the building and add the panel selectedBuildingView = buildingViews[i]; formPanel->setWidget(selectedBuildingView->getBuildingPanel()); break; } } // check if the user select a link b2b if no location has been selected if(selectedBuildingView==0 && selectedFloor == 0) { bool selected = false; for(unsigned int i= 0; i< b2bViews.size(); i++) { // get the line QLine line = b2bViews[i]->getLine(); //event coordonates int ex=event->x(); int ey=event->y(); // split vertical line and other cases // ex = line.p1().x() = line.p2().x() with SELECT_MARGIN of error // line.p1().y() < ey < line.p2().y() or line.p2().y() < ey < line.p1().y() with SELECT_MARGIN of error if(line.p2().x()==line.p1().x()) { if(line.p1().x()-SELECT_MARGIN <= ex && ex <= line.p1().x()+SELECT_MARGIN && ((line.p1().y()-SELECT_MARGIN <= ey && line.p2().y()+SELECT_MARGIN>= ey) || (line.p2().y()-SELECT_MARGIN <= ey && line.p1().y()+SELECT_MARGIN>= ey))) { selected=true; } } else { // calculate line equation y = la * x + lb float la = float(line.p2().y()-line.p1().y())/float(line.p2().x()-line.p1().x()); float lb = float(line.p1().y()-la*line.p1().x()); // calculate y coordonate on the line for x=ex float ly = la*ex+lb; // check if ly and ey are close if(ly-SELECT_MARGIN<=ey && ey<=ly+SELECT_MARGIN) { selected =true; } } if(selected) { // select the b2b and add the panel selectedB2bView = b2bViews[i]; formPanel->setWidget(selectedB2bView->getB2bPanel()); break; } } } // update draw update(); }
void PSV_Public::printMes(const QVariant &mes, const QString &frefix) { QString message; int type = mes.type(); switch(type) { case QVariant::Bool : message = mes.toBool() ? "true":"false"; break; case QVariant::Color : { QColor color = mes.value<QColor>(); message = QObject::tr("colorname:%1,r=%2,g=%3,b=%4") .arg(color.name()) .arg(color.red()) .arg(color.green()) .arg(color.blue()); } break; case QVariant::Date: message = mes.toDate().toString("yyyy-MM-dd"); break; case QVariant::DateTime: message = mes.toDateTime().toString("yyyy-MM-dd hh:mm:ss"); break; case QVariant::Double: message = QString::number(mes.toDouble()); break; case QVariant::UInt: case QVariant::Int: message = QString::number(mes.toInt()); break; case QVariant::ULongLong: case QVariant::LongLong: message = QString::number(mes.toLongLong()); break; case QVariant::Line: { QLine line = mes.toLine(); message = QObject::tr("Line x1=%1,y1=%2,x2=%3,y2=%4") .arg(line.x1()).arg(line.y1()).arg(line.x2()).arg(line.y2()); } break; case QVariant::LineF: { QLineF lineF = mes.toLineF(); message = QObject::tr("LineF x1=%1,y1=%2,x2=%3,y2=%4") .arg(lineF.x1()).arg(lineF.y1()).arg(lineF.x2()).arg(lineF.y2()); } break; case QVariant::Point: { QPoint point = mes.toPoint(); message = QObject::tr("point x=%1,y=%2") .arg(point.x()).arg(point.y()); } break; case QVariant::PointF: { QPointF pointF = mes.toPointF(); message = QObject::tr("pointF x=%1,y=%2") .arg(pointF.x()).arg(pointF.y()); } break; case QVariant::Rect: { QRect rect = mes.toRect(); message = QObject::tr("rect x=%1,y=%2,width=%3,height=%4") .arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height()); } break; case QVariant::RectF: { QRectF rectF = mes.toRect(); message = QObject::tr("rectF x=%1,y=%2,width=%3,height=%4") .arg(rectF.x()).arg(rectF.y()).arg(rectF.width()).arg(rectF.height()); } break; default: message = QObject::tr("type = %1,<%2>").arg(type).arg(mes.toString()); break; } QString outMes = QObject::tr("%1 %2").arg(frefix).arg(message); qDebug()<<QObject::tr("PSV_LIB:<%1>%2").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss")).arg(outMes); }
void PuzzlePrinter::drawKillerSudokuCages (const SKGraph* graph, const QVector<int> & edges) { // Killer Sudokus have cages AND groups: so the cages are drawn differently. // We keep the outer wall of the cage on our left and draw a dashed line // just inside that boundary. This reduces ugly criss-crossing of lines. // // Directions and related arrays are all in clockwise order. enum Direction {East, South, West, North, nDirections}; const Direction rightTurn [nDirections] = {South, West, North, East}; const Direction leftTurn [nDirections] = {North, East, South, West}; const int wallOnLeft [nDirections] = {1 << Above, 1 << Right, 1 << Below, 1 << Left}; const int wallAhead [nDirections] = {1 << Right, 1 << Below, 1 << Left, 1 << Above}; const int deltaX [nDirections] = {+1, 0, -1, 0}; const int deltaY [nDirections] = {0, +1, 0, -1}; int cellInc [nDirections] = {graph->order(), +1, -graph->order(), -1}; int offset = (m_sCell + 6) / 12; int longSide = m_sCell; int shortSide = m_sCell - offset - offset; m_p->setPen (m_dashes); for (int n = 0; n < graph->cageCount(); n++) { int topLeft = graph->cageTopLeft(n); int cell = topLeft; int edge = edges.at (cell); int startX = m_topX + m_sCell * graph->cellPosX (cell) + offset; int startY = m_topY + m_sCell * graph->cellPosY (cell) + offset; int dx = 0; int dy = 0; QLine line (startX, startY, startX, startY); Direction direction = East; // Keep drawing until we get back to the starting cell and direction. do { // If there is a wall on the left, follow it. if (edge & wallOnLeft [direction]) { if (edge & wallAhead [direction]) { // Go to wall (shortSide), draw line, turn right, new line. dx = deltaX [direction] * shortSide; dy = deltaY [direction] * shortSide; line.setLine (line.x1(), line.y1(), line.x2() + dx, line.y2() + dy); m_p->drawLine (line); direction = rightTurn [direction]; line.setLine (line.x2(), line.y2(), line.x2(), line.y2()); } else { // Extend to start of next cell (longSide). dx = deltaX [direction] * longSide; dy = deltaY [direction] * longSide; line.setLine (line.x1(), line.y1(), line.x2() + dx, line.y2() + dy); cell = cell + cellInc [direction]; edge = edges.at (cell); } } // Else, if there is no wall on the left ... else { // Draw line, turn left, new line, go to start of next cell. m_p->drawLine (line); direction = leftTurn [direction]; dx = deltaX [direction] * (longSide - shortSide); dy = deltaY [direction] * (longSide - shortSide); line.setLine (line.x2(), line.y2(), line.x2() + dx, line.y2() + dy); cell = cell + cellInc [direction]; edge = edges.at (cell); } } while (! ((cell == topLeft) && (direction == East))); } // Draw next cage. }
void tst_QLine::testSet() { { QLine l; l.setP1(QPoint(1, 2)); l.setP2(QPoint(3, 4)); QCOMPARE(l.x1(), 1); QCOMPARE(l.y1(), 2); QCOMPARE(l.x2(), 3); QCOMPARE(l.y2(), 4); l.setPoints(QPoint(5, 6), QPoint(7, 8)); QCOMPARE(l.x1(), 5); QCOMPARE(l.y1(), 6); QCOMPARE(l.x2(), 7); QCOMPARE(l.y2(), 8); l.setLine(9, 10, 11, 12); QCOMPARE(l.x1(), 9); QCOMPARE(l.y1(), 10); QCOMPARE(l.x2(), 11); QCOMPARE(l.y2(), 12); } { QLineF l; l.setP1(QPointF(1, 2)); l.setP2(QPointF(3, 4)); QCOMPARE(l.x1(), 1.0); QCOMPARE(l.y1(), 2.0); QCOMPARE(l.x2(), 3.0); QCOMPARE(l.y2(), 4.0); l.setPoints(QPointF(5, 6), QPointF(7, 8)); QCOMPARE(l.x1(), 5.0); QCOMPARE(l.y1(), 6.0); QCOMPARE(l.x2(), 7.0); QCOMPARE(l.y2(), 8.0); l.setLine(9.0, 10.0, 11.0, 12.0); QCOMPARE(l.x1(), 9.0); QCOMPARE(l.y1(), 10.0); QCOMPARE(l.x2(), 11.0); QCOMPARE(l.y2(), 12.0); } }