| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | |
| | |
| |
|
| | #include <QtGui> |
| |
|
| |
|
| | #include <Mod/TechDraw/TechDrawGlobal.h> |
| |
|
| | #include <Base/Console.h> |
| |
|
| | #include "CompassDialWidget.h" |
| |
|
| | using namespace TechDrawGui; |
| | using CardinalMap = std::map<int, std::string>; |
| |
|
| | CompassDialWidget::CompassDialWidget(QWidget* parent) : QWidget(parent), |
| | m_markInterval(15), |
| | m_defaultSize(75), |
| | m_defaultMargin(10), |
| | m_designRadius(64) |
| | { |
| | setObjectName(QStringLiteral("Compass")); |
| | m_rect = QRect(0, 0, m_defaultSize, m_defaultSize); |
| | m_angle = 0.0; |
| | m_margin = m_defaultMargin; |
| | m_designDiameter = 2 * m_designRadius; |
| |
|
| | QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); |
| | sizePolicy.setHorizontalStretch(1); |
| | sizePolicy.setVerticalStretch(1); |
| | setSizePolicy(sizePolicy); |
| |
|
| | repaint(); |
| | } |
| |
|
| | QSize CompassDialWidget::sizeHint() const |
| | { |
| | return m_rect.size(); |
| | } |
| |
|
| | QSize CompassDialWidget::minimumSizeHint() const |
| | { |
| | return QRect(0, 0, m_defaultSize, m_defaultSize).size(); |
| | } |
| |
|
| | void CompassDialWidget::paintEvent(QPaintEvent* event) |
| | { |
| | Q_UNUSED(event); |
| | QPainter painter(this); |
| | drawWidget(painter); |
| | QWidget::paintEvent(event); |
| | } |
| |
|
| | void CompassDialWidget::drawWidget(QPainter& painter) |
| | { |
| | painter.setRenderHint(QPainter::Antialiasing, true); |
| |
|
| | |
| | drawBackground(painter); |
| |
|
| | |
| | drawMarkings(painter); |
| |
|
| | |
| | drawNeedle(painter); |
| | } |
| |
|
| | void CompassDialWidget::drawBackground(QPainter& painter) |
| | { |
| | painter.save(); |
| |
|
| | |
| | painter.translate(width() / 2, height() / 2); |
| | double scale = std::min((float) width() / (float) (m_designDiameter + 2.0 * m_margin), |
| | (float) height() / (float) (m_designDiameter + 2.0 * m_margin)); |
| | painter.scale(scale, scale); |
| |
|
| | painter.setPen(QPen(Qt::NoPen)); |
| | |
| | int circleWidth = 2.0 * (m_designRadius + m_margin); |
| | int circleHeight = 2.0 * (m_designRadius + m_margin); |
| | QRect circleRect(-circleWidth / 2, -circleHeight / 2, circleWidth, circleHeight); |
| | painter.drawEllipse(circleRect); |
| | |
| | QPainterPath backPath; |
| | backPath.addEllipse(circleRect); |
| | painter.fillPath(backPath, palette().brush((QPalette::Window))); |
| | |
| | painter.restore(); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | void CompassDialWidget::drawMarkings(QPainter& painter) |
| | { |
| | CardinalMap CompassPointText( { {0, "Y"}, {45, "XY"}, {90, "X"}, {135, "X-Y"}, {180, "-Y"}, |
| | {225, "-X-Y"}, {270, "-X"}, {315, "-XY"} } ); |
| | painter.save(); |
| | int markInterval(15); |
| |
|
| | |
| | painter.translate(width() / 2, height() / 2); |
| | double scale = std::min((float) width() / (float) (m_designDiameter + 2.0 * m_margin), |
| | (float) height() / (float) (m_designDiameter + 2.0 * m_margin)); |
| | painter.scale(scale, scale); |
| |
|
| | |
| | QFont widgetFont = font(); |
| | widgetFont.setPixelSize(12); |
| | QFontMetrics metrics(widgetFont); |
| |
|
| | |
| | int circleWidth = 2.0 * (m_designRadius + m_margin); |
| | int circleHeight = 2.0 * (m_designRadius + m_margin); |
| | QRect circleRect(-circleWidth / 2, -circleHeight / 2, circleWidth, circleHeight); |
| | painter.drawEllipse(circleRect); |
| |
|
| | painter.setFont(widgetFont); |
| | painter.setPen(QPen(palette().color(QPalette::WindowText))); |
| |
|
| | int iDegree = 0; |
| | while ( iDegree < 360 ) { |
| | if (iDegree % 45 == 0) { |
| | |
| | painter.drawLine(0, -40, 0, -50); |
| | QString qPointText = QString::fromStdString(CompassPointText.at(iDegree)); |
| | painter.drawText(-metrics.boundingRect(qPointText).width() / 2.0, -52, qPointText); |
| | |
| | } else { |
| | |
| | painter.drawLine(0, -45, 0, -50); |
| | } |
| |
|
| | |
| | painter.rotate(markInterval); |
| | iDegree += markInterval; |
| | } |
| |
|
| | painter.restore(); |
| | } |
| |
|
| | |
| | void CompassDialWidget::drawNeedle(QPainter& painter) |
| | { |
| | painter.save(); |
| |
|
| | |
| | painter.translate(width() / 2, height() / 2); |
| |
|
| | |
| | painter.rotate(m_angle); |
| | double scale = std::min((float) width() / (float) (m_designDiameter + 2.0 * m_margin), |
| | (float) height() / (float) (m_designDiameter + 2.0 * m_margin)); |
| | painter.scale(scale, scale); |
| |
|
| | |
| | QPen needlePen(palette().color(QPalette::WindowText)); |
| | needlePen.setWidth(2); |
| | needlePen.setStyle(Qt::DashDotLine); |
| | painter.setPen(needlePen); |
| | painter.setBrush(palette().color(QPalette::WindowText)); |
| |
|
| | |
| | int sectionLineExtent(25); |
| | painter.drawLine(0, sectionLineExtent, 0, -sectionLineExtent); |
| | needlePen.setStyle(Qt::SolidLine); |
| | painter.setPen(needlePen); |
| | int viewDirectionExtent(15); |
| | painter.drawLine(-viewDirectionExtent, sectionLineExtent, 0, sectionLineExtent); |
| | painter.drawLine(-viewDirectionExtent, -sectionLineExtent, 0, -sectionLineExtent); |
| |
|
| | |
| | needlePen.setWidth(1); |
| | needlePen.setStyle(Qt::SolidLine); |
| | painter.setPen(needlePen); |
| | int arrowLength(5); |
| | int arrowWidth(3); |
| | painter.drawPolygon( |
| | QPolygon( { QPoint(0, sectionLineExtent), |
| | QPoint(-arrowLength, sectionLineExtent + arrowWidth), |
| | QPoint(-arrowLength, sectionLineExtent - arrowWidth), |
| | QPoint(0, sectionLineExtent) } ) ); |
| | painter.drawPolygon( |
| | QPolygon( { QPoint(0, -sectionLineExtent), |
| | QPoint(-arrowLength, -(sectionLineExtent + arrowWidth)), |
| | QPoint(-arrowLength, -(sectionLineExtent - arrowWidth)), |
| | QPoint(0, -sectionLineExtent) } ) ); |
| |
|
| | |
| | needlePen.setStyle(Qt::SolidLine); |
| | painter.setPen(needlePen); |
| | painter.setBrush(palette().color(QPalette::BrightText)); |
| | int needleExtent(40); |
| | painter.drawPolygon( |
| | QPolygon( { QPoint(needleExtent, 0), |
| | QPoint(0, 5), |
| | QPoint(-15, 2), |
| | QPoint(-15, -2), |
| | QPoint(0, -5), |
| | QPoint(needleExtent, 0) } ) ); |
| |
|
| | |
| | painter.setBrush(palette().color(QPalette::WindowText)); |
| | int pivotSize(4); |
| | QRect pivotRect(-pivotSize / 2, -pivotSize / 2, pivotSize, pivotSize); |
| | painter.drawEllipse(pivotRect); |
| |
|
| | |
| | painter.setBrush(QBrush(Qt::red)); |
| | int pointLength(5); |
| | int pointWidth(3); |
| | painter.drawPolygon( |
| | QPolygon( { QPoint(needleExtent, 0), |
| | QPoint(needleExtent - pointLength, pointWidth), |
| | QPoint(needleExtent - pointLength, -pointWidth), |
| | QPoint(needleExtent, 0) } ) ); |
| |
|
| | painter.restore(); |
| | } |
| |
|
| | |
| | void CompassDialWidget::setAngle(double newAngle) |
| | { |
| | m_angle = fmod(360.0 - newAngle, 360.0); |
| | repaint(); |
| | } |
| |
|
| | void CompassDialWidget::setSize(int newSize) |
| | { |
| | m_rect = QRect(0, 0, newSize, newSize); |
| | repaint(); |
| | } |
| |
|