void Zoomer::drawRubberBand( QPainter *painter ) const { if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) return; const QPolygon pa = adjustedPoints( pickedPoints() ); if ( pa.count() < 1 ) return; const QRectF& rc = pickArea().boundingRect(); // view rect const QPoint p2 = pa[int( pa.count() - 1 )]; QwtPainter::drawLine( painter, p2.x(), rc.top(), p2.x(), rc.bottom() ); // vertical @ 2nd point (automaticall drawn by picker) QwtPainter::drawLine( painter, rc.left(), p2.y(), rc.right(), p2.y() ); // horizontal @ 2nd point if ( pa.count() >= 2 ) { const QPoint p1 = pa[0]; const QRect rect = QRect( p1, p2 ).normalized(); if ( autoYScale_ || rect.height() < minY ) { // select horizontal (indicate by 2 vertical lines) QwtPainter::drawLine( painter, p1.x(), rc.top(), p1.x(), rc.bottom() ); // vertical @ 1st point } else if ( rect.width() < minX ) { QwtPainter::drawLine( painter, rc.left(), p1.y(), rc.right(), p1.y() ); // horizontal @ 1st point } else { QwtPainter::drawLine( painter, p1.x(), rc.top(), p1.x(), rc.bottom() ); // vertical @ 1st point QwtPainter::drawLine( painter, rc.left(), p1.y(), rc.right(), p1.y() ); // horizontal @ 1st point } } }
//virtual bool Zoomer::accept( QPolygon &pa ) const { if ( pa.count() < 2 ) return false; QRect rect = QRect( pa[0], pa[int( pa.count() ) - 1] ); rect = rect.normalized(); if ( rect.width() < 2 && rect.height() < 2 ) return false; pa.resize( 2 ); const QRectF& rc = pickArea().boundingRect(); // view rect if ( rect.width() < minX ) { // make a virtical line pa[ 0 ] = QPoint( rc.left(), rect.top() ); pa[ 1 ] = QPoint( rc.right(), rect.bottom() ); return true; } else if ( rect.height() < minY ) { // make a horizontal line pa[ 0 ] = QPoint( rect.left(), rc.top() ); pa[ 1 ] = QPoint( rect.right(), rc.bottom() ); } else { pa[ 0 ] = rect.topLeft(); pa[ 1 ] = rect.bottomRight(); } return true; }
bool QwtPlotPicker::end( bool ok ) { ok = QwtPicker::end( ok ); if ( !ok ) return false; QwtPlot *plot = QwtPlotPicker::plot(); if ( !plot ) return false; const QPolygon pa = selection(); if ( pa.count() == 0 ) return false; QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( stateMachine() ) selectionType = stateMachine()->selectionType(); switch ( selectionType ) { case QwtPickerMachine::PointSelection: { const QPointF pos = invTransform( pa[0] ); Q_EMIT selected( pos ); break; } case QwtPickerMachine::RectSelection: { if ( pa.count() >= 2 ) { const QPoint p1 = pa[0]; const QPoint p2 = pa[int( pa.count() - 1 )]; const QRect rect = QRect( p1, p2 ).normalized(); Q_EMIT selected( invTransform( rect ) ); } break; } case QwtPickerMachine::PolygonSelection: { QVector<QPointF> dpa( pa.count() ); for ( int i = 0; i < int( pa.count() ); i++ ) dpa[i] = invTransform( pa[i] ); Q_EMIT selected( dpa ); } default: break; } return true; }
// Returns whether there is only 1 distinct point in <points>. static bool Only1PixelInPointArray (const QPolygon &points) { if (points.count () == 0) return false; for (int i = 1; i < (int) points.count (); i++) { if (points [i] != points [0]) return false; } return true; }
QDebug operator<<(QDebug dbg, const QPolygon &a) { dbg.nospace() << "QPolygon("; for (int i = 0; i < a.count(); ++i) dbg.nospace() << a.at(i); dbg.nospace() << ')'; return dbg.space(); }
// public static void kpPixmapFX::drawPolygon (QImage *image, const QPolygon &points, const kpColor &fcolor, int penWidth, const kpColor &bcolor, bool isFinal, const kpColor &fStippleColor) { QPainter p(image); ::QPainterSetPenWithStipple (&p, fcolor, penWidth, fStippleColor); if (bcolor.isValid ()) p.setBrush (QBrush (bcolor.toQColor())); // HACK: seems to be needed if set_Pen_(Qt::color0) else fills with Qt::color0. else p.setBrush (Qt::NoBrush); // Qt bug: single point doesn't show up depending on penWidth. if (Only1PixelInPointArray (points)) { #if DEBUG_KP_PIXMAP_FX qCDebug(kpLogPixmapfx) << "\tinvoking single point hack"; #endif p.drawPoint(points [0]); return; } // TODO: why aren't the ends rounded? p.drawPolygon(points, Qt::OddEvenFill); if ( isFinal ) return; if ( points.count() <= 2 ) return; p.setCompositionMode(QPainter::RasterOp_SourceXorDestination); p.setPen(QPen(Qt::white)); p.drawLine(points[0], points[points.count() - 1]); }
QDebug operator<<(QDebug dbg, const QPolygon &a) { #ifndef Q_BROKEN_DEBUG_STREAM dbg.nospace() << "QPolygon("; for (int i = 0; i < a.count(); ++i) dbg.nospace() << a.at(i); dbg.nospace() << ')'; return dbg.space(); #else qWarning("This compiler doesn't support streaming QPolygon to QDebug"); return dbg; Q_UNUSED(a); #endif }
static void DrawLineShape (kpImage *image, const QPolygon &points, const kpColor &fcolor, int penWidth, const kpColor &bcolor, bool isFinal) { Q_ASSERT (points.count () == 2); kpToolPolyline::DrawShape (image, points, fcolor, penWidth, bcolor, isFinal); }
bool QwtCustomPlotZoomer::accept(QPolygon& p) const { if ( p.count() < 2 ) return false; // Reject zooms which are too small if (abs(p[0].x() - p[1].x()) < 10) return false; // Set the zoom rect to be top to bottm, irrespective of what the user selects in y axis p[0].setY(0); p[1].setY(canvas()->size().height()); return true; }
bool QwtPlotZoomer::accept( QPolygon &pa ) const { if ( pa.count() < 2 ) return false; QRect rect = QRect( pa[0], pa[int( pa.count() ) - 1] ); rect = rect.normalized(); const int minSize = 2; if ( rect.width() < minSize && rect.height() < minSize ) return false; const int minZoomSize = 11; const QPoint center = rect.center(); rect.setSize( rect.size().expandedTo( QSize( minZoomSize, minZoomSize ) ) ); rect.moveCenter( center ); pa.resize( 2 ); pa[0] = rect.topLeft(); pa[1] = rect.bottomRight(); return true; }
Bot::Bot(const QPolygon &path, Map *map, Scene *scene) : Actor("resources/guard.spb", scene), m_map(map), m_currentLine(0), m_positionInLine(0), m_movingForward(true), // m_directionSwitchDelay(0), m_visionCone(this, map, scene) { for(int i = 0; i < path.count() - 1; i++) m_path.append(QLineF(path.at(i), path.at(i + 1))); // m_alarmSound.setSource(QUrl::fromLocalFile("resources/sound/alarm.wav")); // m_alarmSound.setVolume(0.5); // m_alarmSound.setLoopCount(3); }
void GraphPolygonClipper::clipEdge(Edge edge, const QPolygon &pa, QPolygon &cpa) const { if ( pa.count() == 0 ) { cpa.resize(0); return; } unsigned int count = 0; QPoint p1 = pa.point(0); if ( insideEdge(p1, edge) ) addPoint(cpa, count++, p1); const uint nPoints = pa.size(); for ( uint i = 1; i < nPoints; i++ ) { const QPoint p2 = pa.point(i); if ( insideEdge(p2, edge) ) { if ( insideEdge(p1, edge) ) addPoint(cpa, count++, p2); else { addPoint(cpa, count++, intersectEdge(p1, p2, edge)); addPoint(cpa, count++, p2); } } else { if ( insideEdge(p1, edge) ) addPoint(cpa, count++, intersectEdge(p1, p2, edge)); } p1 = p2; } cpa.resize(count); }
void QwtCustomPlotZoomer::drawRubberBand(QPainter* painter) const { if ( rubberBand() < UserRubberBand ) QwtPlotPicker::drawRubberBand( painter ); else { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QPolygon p = selection(); if ( p.count() < 2 ) return; const QPoint& pt1 = p[0]; const QPoint& pt2 = p[1]; const int end = canvas()->size().height(); painter->drawLine(pt1.x(), 0, pt1.x(), end); painter->drawLine(pt2.x(), 0, pt2.x(), end); painter->fillRect(QRect(pt1.x(), 0, pt2.x() - pt1.x(), end), QBrush(QColor("black"), Qt::Dense7Pattern)); } }
void QwtPicker::drawRubberBand( QPainter *painter ) const { if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return; } const QPolygon pa = adjustedPoints( d_data->pickedPoints ); QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( d_data->stateMachine ) selectionType = d_data->stateMachine->selectionType(); switch ( selectionType ) { case QwtPickerMachine::NoSelection: case QwtPickerMachine::PointSelection: { if ( pa.count() < 1 ) return; const QPoint pos = pa[0]; const QRect pRect = pickArea().boundingRect().toRect(); switch ( rubberBand() ) { case VLineRubberBand: { QwtPainter::drawLine( painter, pos.x(), pRect.top(), pos.x(), pRect.bottom() ); break; } case HLineRubberBand: { QwtPainter::drawLine( painter, pRect.left(), pos.y(), pRect.right(), pos.y() ); break; } case CrossRubberBand: { QwtPainter::drawLine( painter, pos.x(), pRect.top(), pos.x(), pRect.bottom() ); QwtPainter::drawLine( painter, pRect.left(), pos.y(), pRect.right(), pos.y() ); break; } default: break; } break; } case QwtPickerMachine::RectSelection: { if ( pa.count() < 2 ) return; const QRect rect = QRect( pa.first(), pa.last() ).normalized(); switch ( rubberBand() ) { case EllipseRubberBand: { QwtPainter::drawEllipse( painter, rect ); break; } case RectRubberBand: { QwtPainter::drawRect( painter, rect ); break; } default: break; } break; } case QwtPickerMachine::PolygonSelection: { if ( rubberBand() == PolygonRubberBand ) painter->drawPolyline( pa ); break; } default: break; } }
void Storage::mouseMoveEvent(QMouseEvent *anEvent) { QPoint pos = anEvent->pos() / scale_; if (anEvent->pos().x() < 0) pos.setX(0); if (width() < anEvent->pos().x()) pos.setX(width() - 1); if (anEvent->pos().y() < 0) pos.setY(0); if (height() < anEvent->pos().y()) pos.setY(height() - 1); /* изменяем прямоугольник */ if ((anEvent->buttons() & Qt::LeftButton) && BoundingBoxTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerBoundBox(pos, prev_cursor_pos_, rect); } /* изменяем эллипс */ if ((anEvent->buttons() & Qt::LeftButton) && EllipseTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerEllipse(pos, prev_cursor_pos_, ell); } /* изменяем стрелу */ if ((anEvent->buttons() & Qt::LeftButton) && ArrowTool == tool_ && NewSelection == state_ && Qt::NoModifier == keyboard_modifier_) { triggerArrow(pos, prev_cursor_pos_, arrow); } /* перемещаем последнюю точку(курсор) многоугольника до создания(точка зафиксирется кликом) новой */ if (PolygonTool == tool_ && NewSelection == state_ && (anEvent->buttons() & Qt::LeftButton)) { QPolygon tmp = poly.getCoordinates(); tmp.setPoint(tmp.count() - 1, pos); poly.setCoordinates(tmp); repaint_needed_ = 1; } // if (-1 != focused_selection_ && // !(anEvent->buttons() & Qt::LeftButton)) { // checkForPoints(&pos); // } //here now 2 /* изменяем многоульник */ // if (-1 != hovered_point_.figureID && // !list_polygon_->isEmpty() && // PolyFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton) && // hovered_point_.figureID == focused_selection_) // { // polygon_.poly.clear(); // polygon_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // Polygon *poly = list_polygon_->at(hovered_point_.figureID); // poly->poly.setPoint(hovered_point_.pointID, pos); // for(int i=0;i< list_polygon_->at(hovered_point_.figureID)->poly.count();++i) // { // if(i!=hovered_point_.pointID) // polygon_.poly << list_polygon_->at(hovered_point_.figureID)->poly.point(i); // else // polygon_.poly << pos; // } // qDebug() << "polygon_.poly =" << polygon_.poly; // repaint_needed_ = 1; // } /* изменяем прямоульник */ // if (-1 != hovered_point_.figureID && // !list_bounding_box_->isEmpty() && // RectFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // bounding_box_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // bounding_box_.rect.setTopLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.topLeft()); // bounding_box_.rect.setTopRight(list_bounding_box_->at(hovered_point_.figureID)->rect.topRight()); // bounding_box_.rect.setBottomRight(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomRight()); // bounding_box_.rect.setBottomLeft(list_bounding_box_->at(hovered_point_.figureID)->rect.bottomLeft()); // BoundingBox *rect = list_bounding_box_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // rect->rect.setTopLeft(pos); // bounding_box_.rect.setTopLeft(pos); // qDebug() << "rect->rect.topLeft" << rect->rect.topLeft(); // } // else if (1 == hovered_point_.pointID) // { // rect->rect.setTopRight(pos); // bounding_box_.rect.setTopRight(pos); // qDebug() << "rect->rect.topRight" << rect->rect.topRight(); // } // else if (2 == hovered_point_.pointID) // { // rect->rect.setBottomRight(pos); // bounding_box_.rect.setBottomRight(pos); // qDebug() << "rect->rect.bottomRight" << rect->rect.bottomRight(); // } // else if (3 == hovered_point_.pointID) // { // rect->rect.setBottomLeft(pos); // bounding_box_.rect.setBottomLeft(pos); // qDebug() << "rect->rect.bottomLeft" << rect->rect.bottomLeft(); // } // repaint_needed_ = 1; // } // /* изменяем эллипс */ // if (-1 != hovered_point_.figureID && // !list_ellipse_->isEmpty() && // EllipseFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // ellipse_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // ellipse_.rect.setTopLeft(list_ellipse_->at(hovered_point_.figureID)->rect.topLeft()); // ellipse_.rect.setTopRight(list_ellipse_->at(hovered_point_.figureID)->rect.topRight()); // ellipse_.rect.setBottomRight(list_ellipse_->at(hovered_point_.figureID)->rect.bottomRight()); // ellipse_.rect.setBottomLeft(list_ellipse_->at(hovered_point_.figureID)->rect.bottomLeft()); // Ellipse *ell = list_ellipse_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // ell->rect.setTopLeft(pos); // ellipse_.rect.setTopLeft(pos); // qDebug() << "rect->rect.topLeft" << ell->rect.topLeft(); // } // else if (1 == hovered_point_.pointID) // { // ell->rect.setTopRight(pos); // ellipse_.rect.setTopRight(pos); // qDebug() << "rect->rect.topRight" << ell->rect.topRight(); // } // else if (2 == hovered_point_.pointID) // { // ell->rect.setBottomRight(pos); // ellipse_.rect.setBottomRight(pos); // qDebug() << "rect->rect.bottomRight" << ell->rect.bottomRight(); // } // else if (3 == hovered_point_.pointID) // { // ell->rect.setBottomLeft(pos); // ellipse_.rect.setBottomLeft(pos); // qDebug() << "rect->rect.bottomLeft" << ell->rect.bottomLeft(); // } // repaint_needed_ = 1; // } // /* изменяем стрелу */ // if (-1 != hovered_point_.figureID && // !list_arrow_->isEmpty() && // ArrowFigure == hovered_point_.figure && // (anEvent->buttons() & Qt::LeftButton)) // { // arrow_.label_ID_ = *label_ID_/*focused_label_ID_selection_*/; // arrow_.line.setP1(list_arrow_->at(hovered_point_.figureID)->line.p1()); // arrow_.line.setP2(list_arrow_->at(hovered_point_.figureID)->line.p2()); // Arrow *arrow = list_arrow_->at(hovered_point_.figureID); // if (0 == hovered_point_.pointID) // { // arrow->line.setP1(pos); // arrow_.line.setP1(pos); // qDebug() << "arrow->line.p1" << arrow->line.p1(); // } // else if (1 == hovered_point_.pointID) // { // arrow->line.setP2(pos); // arrow_.line.setP2(pos); // qDebug() << "arrow->line.p2" << arrow->line.p2(); // } // repaint_needed_ = 1; // } /* когда изображение слишком большое(необходима прокрутка) */ if ((anEvent->buttons() & Qt::MiddleButton) && (scroll_area_->size().height() < size().height() || scroll_area_->size().width() < size().width())) { QPoint globPos = mapToGlobal(pos); QPoint prev = mapToGlobal(prev_cursor_pos_); int horValue = scroll_area_->horizontalScrollBar()->value(); // scroll_area_->horizontalScrollBar() int verValue = scroll_area_->verticalScrollBar()->value(); QPoint delta = globPos - prev; prev_cursor_pos_ = pos; horValue += delta.x(); verValue += delta.y(); scroll_area_->horizontalScrollBar()->setValue(horValue); scroll_area_->verticalScrollBar()->setValue(verValue); } if (repaint_needed_) { update(); repaint_needed_ = 0; } }
bool RectPicker::end(bool ok) { if (!ok)//更改代码处:,正常结束后,并不停止。只有reset时候,end(false)停止选择,重置状态机 QwtPicker::end(ok); if (!ok) return false; QwtPlot *plot = QwtPlotPicker::plot(); if (!plot) return false; const QPolygon points = selection(); if (points.count() == 0) return false; QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if (stateMachine()) selectionType = stateMachine()->selectionType(); switch (selectionType) { case QwtPickerMachine::PointSelection: { const QPointF pos = invTransform(points.first()); Q_EMIT selected(pos); break; } case QwtPickerMachine::RectSelection: { if (points.count() >= 2) { const QPoint p1 = points.first(); const QPoint p2 = points.last(); QPointF pF1 = invTransform(p1); QPointF pF2 = invTransform(p2); const QRect rect = QRect(p1, p2).normalized(); const QRect rect11 = QRect(p1, p2); QPoint pp1 = rect.topLeft(); QPoint pp2 = rect.bottomRight(); //const QRect rect = QRect(p1, p2); QRectF rect1 = invTransform(rect); QPointF topLeft = rect1.topLeft(); QPointF bottomRight = rect1.bottomRight(); Q_EMIT selected(invTransform(rect)); } break; } case QwtPickerMachine::PolygonSelection: { QVector<QPointF> dpa(points.count()); for (int i = 0; i < points.count(); i++) dpa[i] = invTransform(points[i]); Q_EMIT selected(dpa); } default: break; } return ok; }
void QwtCustomPlotPicker::drawRubberBand(QPainter* painter) const { if ( rubberBand() < UserRubberBand ) QwtPlotPicker::drawRubberBand( painter ); else { if ( !isActive() || rubberBandPen().style() == Qt::NoPen ) return; QPolygon p = selection(); if ( p.count() != 1 ) return; const QPoint& pt1 = p[0]; const double x_val = plot()->invTransform(QwtPlot::xBottom,pt1.x()); // determine x value (time or dist) // Draw vertical line where curser is const int bot = 400; const int top = 0; painter->drawLine(pt1.x(), bot, pt1.x(), top); // Set pen and fond for all coming text painter->setPen(QColor(Qt::black)); painter->setFont(QFont("Helvetica", 8, QFont::Bold)); // Compute the index based on the x value int idx; if (_x_axis_units == TimeAxis) { painter->drawText(QPoint(pt1.x()-65, 10), "time: " + DataProcessing::minsFromSecs(x_val)); idx = _data_log->indexFromTime(x_val); } else if (_x_axis_units == DistAxis) { painter->drawText(QPoint(pt1.x()-60, 10), "dist: " + DataProcessing::kmFromMeters(x_val,2)); idx = _data_log->indexFromDist(x_val); } // Using the index, determine the curve values const double hr = (int)_data_log->heartRateFltd(idx); const QPoint pt1_hr(pt1.x(),plot()->transform(QwtPlot::yLeft,hr)); const double speed = _data_log->speedFltd(idx); const QPoint pt1_speed(pt1.x(),plot()->transform(QwtPlot::yLeft,speed)); const double alt = (int)_data_log->altFltd(idx); const QPoint pt1_alt(pt1.x(),plot()->transform(QwtPlot::yRight,alt)); const double cadence = (int)_data_log->cadenceFltd(idx); const QPoint pt1_cadence(pt1.x(),plot()->transform(QwtPlot::yLeft,cadence)); const double power = _data_log->powerFltd(idx); const QPoint pt1_power(pt1.x(),plot()->transform(QwtPlot::yLeft,power)); const double temp = _data_log->temp(idx); const QPoint pt1_temp(pt1.x(),plot()->transform(QwtPlot::yLeft,temp)); // Draw highlights on all curves const QPoint offset(8,-5); const QwtPlotItemList item_list = plot()->itemList(QwtPlotCurve::Rtti_PlotCurve); for (int i = 0; i < item_list.size(); ++i) { if (item_list.at(i)->title().text() == "Heart Rate" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_hr.x(), pt1_hr.y(), pt1_hr.x()+6, pt1_hr.y()); painter->drawText(pt1_hr + offset, QString::number(hr,'g',3)); } if (item_list.at(i)->title().text() == "Speed" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_speed.x(), pt1_speed.y(), pt1_speed.x()+6, pt1_speed.y()); painter->drawText(pt1_speed + offset, QString::number(speed,'g',3)); } if (item_list.at(i)->title().text() == "Elevation" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_alt.x(), pt1_alt.y(), pt1_alt.x()+6, pt1_alt.y()); painter->drawText(pt1_alt + offset, QString::number(alt,'g',4)); } if (item_list.at(i)->title().text() == "Cadence" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_cadence.x(), pt1_cadence.y(), pt1_cadence.x()+6, pt1_cadence.y()); painter->drawText(pt1_cadence + offset, QString::number(cadence,'g',3)); } if (item_list.at(i)->title().text() == "Power" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_power.x(), pt1_power.y(), pt1_power.x()+6, pt1_power.y()); painter->drawText(pt1_power + offset, QString::number(power,'g',3)); } if (item_list.at(i)->title().text() == "Temp" && item_list.at(i)->isVisible()) { painter->drawLine(pt1_temp.x(), pt1_temp.y(), pt1_temp.x()+6, pt1_temp.y()); painter->drawText(pt1_temp + offset, QString::number(temp,'g',3)); } // Draw current values on graph labels if (_hr_cb->isChecked()) _hr_cb->setText("Heart Rate " + QString::number(hr,'g',3).leftJustified(3,' ') + " bpm"); else _hr_cb->setText("Heart Rate"); if (_speed_cb->isChecked()) _speed_cb->setText("Speed " + QString::number(speed,'g',3) + " km/h"); else _speed_cb->setText("Speed"); if (_alt_cb->isChecked()) _alt_cb->setText("Elevation " + QString::number(alt,'g',4).leftJustified(4,' ') + " m"); else _alt_cb->setText("Elevation"); if (_cadence_cb->isChecked()) _cadence_cb->setText("Cadence " + QString::number(cadence,'g',3) + " rpm"); else _cadence_cb->setText("Cadence"); if (_power_cb->isChecked()) _power_cb->setText("Power " + QString::number(power,'g',3) + " W"); else _power_cb->setText("Power"); if (_temp_cb->isChecked()) _temp_cb->setText("Temp " + QString::number(temp,'g',3) + " C"); else _temp_cb->setText("Temp"); } } }
/*! * \see hovered_point_ * \see drawBoundingBoxes(QPainter *aPainter, QPen *aPen) * \see drawPolygons(QPainter *aPainter, QPen *aPen) * * It simply checks all the points of all objects if mouse * pointer is hovered above any of them */ void ImageHolder::checkForPoints(QPoint *aPos) { if ((!list_polygon_->count() && !list_bounding_box_->count()) || !aPos) { return; /* NOTREACHED */ } int newRadius = 0; int x = aPos->x(); int y = aPos->y(); /* center coordinates */ int xc = 0; int yc = 0; for (int i = 0; i < list_polygon_->count(); i++) { QPolygon poly = list_polygon_->at(i)->poly; for (int j = 0; j < poly.count(); j++) { xc = poly.at(j).x(); yc = poly.at(j).y(); newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2)); if (newRadius <= point_radius_) { hovered_point_.figure = PolyFigure; hovered_point_.figureID = i; hovered_point_.pointID = j; repaint_needed_ = 1; return; /* NOTREACHED */ } } } for (int i = 0; i < list_bounding_box_->count(); i++) { QRect rect = list_bounding_box_->at(i)->rect; for (int j = 0; j < 4; j++) { if (!j) { xc = rect.left(); yc = rect.top(); } else if (1 == j) { xc = rect.right(); yc = rect.top(); } else if (2 == j) { xc = rect.right(); yc = rect.bottom(); } else if (3 == j) { xc = rect.left(); yc = rect.bottom(); } newRadius = qSqrt(qPow(x - xc, 2) + qPow(y - yc, 2)); if (newRadius <= point_radius_) { hovered_point_.figure = RectFigure; hovered_point_.figureID = i; hovered_point_.pointID = j; repaint_needed_ = 1; return; /* NOTREACHED */ } } } hovered_point_.figure = NoFigure; hovered_point_.figureID = -1; hovered_point_.pointID = -1; repaint_needed_ = 1; }
/*! Calculate the mask for the rubber band overlay \return Region for the mask \sa QWidget::setMask() */ QRegion QwtPicker::rubberBandMask() const { QRegion mask; if ( !isActive() || rubberBand() == NoRubberBand || rubberBandPen().style() == Qt::NoPen ) { return mask; } const QPolygon pa = adjustedPoints( d_data->pickedPoints ); QwtPickerMachine::SelectionType selectionType = QwtPickerMachine::NoSelection; if ( d_data->stateMachine ) selectionType = d_data->stateMachine->selectionType(); switch ( selectionType ) { case QwtPickerMachine::NoSelection: case QwtPickerMachine::PointSelection: { if ( pa.count() < 1 ) return mask; const QPoint pos = pa[0]; const int pw = rubberBandPen().width(); const QRect pRect = pickArea().boundingRect().toRect(); switch ( rubberBand() ) { case VLineRubberBand: { mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), pos.x(), pRect.bottom() ), pw ); break; } case HLineRubberBand: { mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), pRect.right(), pos.y() ), pw ); break; } case CrossRubberBand: { mask += qwtMaskRegion( QLine( pos.x(), pRect.top(), pos.x(), pRect.bottom() ), pw ); mask += qwtMaskRegion( QLine( pRect.left(), pos.y(), pRect.right(), pos.y() ), pw ); break; } default: break; } break; } case QwtPickerMachine::RectSelection: { if ( pa.count() < 2 ) return mask; const int pw = rubberBandPen().width(); switch ( rubberBand() ) { case RectRubberBand: { const QRect r = QRect( pa.first(), pa.last() ); mask = qwtMaskRegion( r.normalized(), pw ); break; } case EllipseRubberBand: { const QRect r = QRect( pa.first(), pa.last() ); mask += r.adjusted( -pw, -pw, pw, pw ); break; } default: break; } break; } case QwtPickerMachine::PolygonSelection: { const int pw = rubberBandPen().width(); if ( pw <= 1 ) { // because of the join style we better // return a mask for a pen width <= 1 only const int off = 2 * pw; const QRect r = pa.boundingRect(); mask += r.adjusted( -off, -off, off, off ); } break; } default: break; } return mask; }
void KPassivePopup::updateMask() { // get screen-geometry for screen our anchor is on // (geometry can differ from screen to screen! QRect deskRect = QApplication::desktop()->screenGeometry(d->anchor); int xh = 70, xl = 40; if( width() < 80 ) xh = xl = 40; else if( width() < 110 ) xh = width() - 40; bool bottom = (d->anchor.y() + height()) > ((deskRect.y() + deskRect.height()-48)); bool right = (d->anchor.x() + width()) > ((deskRect.x() + deskRect.width()-48)); QPoint corners[4] = { QPoint( width() - 50, 10 ), QPoint( 10, 10 ), QPoint( 10, height() - 50 ), QPoint( width() - 50, height() - 50 ) }; QBitmap mask( width(), height() ); mask.clear(); QPainter p( &mask ); QBrush brush( Qt::color1, Qt::SolidPattern ); p.setBrush( brush ); int i = 0, z = 0; for (; i < 4; ++i) { QPainterPath path; path.moveTo(corners[i].x(),corners[i].y()); path.arcTo(corners[i].x(),corners[i].y(),40,40, i * 90 , 90); QPolygon corner = path.toFillPolygon().toPolygon(); d->surround.resize( z + corner.count() - 1 ); for (int s = 1; s < corner.count() - 1; s++, z++) { d->surround.setPoint( z, corner[s] ); } if (bottom && i == 2) { if (right) { d->surround.resize( z + 3 ); d->surround.setPoint( z++, QPoint( width() - xh, height() - 10 ) ); d->surround.setPoint( z++, QPoint( width() - 20, height() ) ); d->surround.setPoint( z++, QPoint( width() - xl, height() - 10 ) ); } else { d->surround.resize( z + 3 ); d->surround.setPoint( z++, QPoint( xl, height() - 10 ) ); d->surround.setPoint( z++, QPoint( 20, height() ) ); d->surround.setPoint( z++, QPoint( xh, height() - 10 ) ); } } else if (!bottom && i == 0) { if (right) { d->surround.resize( z + 3 ); d->surround.setPoint( z++, QPoint( width() - xl, 10 ) ); d->surround.setPoint( z++, QPoint( width() - 20, 0 ) ); d->surround.setPoint( z++, QPoint( width() - xh, 10 ) ); } else { d->surround.resize( z + 3 ); d->surround.setPoint( z++, QPoint( xh, 10 ) ); d->surround.setPoint( z++, QPoint( 20, 0 ) ); d->surround.setPoint( z++, QPoint( xl, 10 ) ); } } } d->surround.resize( z + 1 ); d->surround.setPoint( z, d->surround[0] ); p.drawPolygon( d->surround ); setMask(mask); move( right ? d->anchor.x() - width() + 20 : ( d->anchor.x() < 11 ? 11 : d->anchor.x() - 20 ), bottom ? d->anchor.y() - height() : ( d->anchor.y() < 11 ? 11 : d->anchor.y() ) ); update(); }