Exemplo n.º 1
0
  QRangeSlider::ELEMENT getElement(const QRect& bbox,
                                   const QPair<int, int>& range,
                                   const QPair<int, int>& cutoffRange,
                                   const QPoint& pos)
  {
    QPolygon p = getMarkerArea(bbox, range, cutoffRange, FIRST);
    if (p.containsPoint(pos, Qt::OddEvenFill))
      return QRangeSlider::FIRST;
    p = getMarkerArea(bbox, range, cutoffRange, SECOND);
    if (p.containsPoint(pos, Qt::OddEvenFill))
      return QRangeSlider::SECOND;

    return QRangeSlider::NONE;
  }
Exemplo n.º 2
0
  QStyle::SubControl hitTestComplexControl(QStyle::ComplexControl control,
                                           const QStyleOptionComplex* option,
                                           const QPoint& position,
                                           const QWidget* widget) const
  {
    if (control == QStyle::CC_CustomBase) {
      QRect bbox = static_cast<const QRangeSlider*>(widget)->getBBox();
      const QRangeSlider* rSlider = static_cast<const QRangeSlider*>(widget);
      QPolygon p = getMarkerArea(bbox, rSlider->range(),
                                 rSlider->cutoffRange(), FIRST);
      if (p.containsPoint(position, Qt::OddEvenFill))
        return QStyle::SC_SliderHandle;
      p = getMarkerArea(bbox, rSlider->range(),
                        rSlider->cutoffRange(), SECOND);
      if (p.containsPoint(position, Qt::OddEvenFill))
        return SC_SliderHandle2;
      return QStyle::SC_None;
    }

    return realStyle_->hitTestComplexControl(control,
                                             option,
                                             position,
                                             widget);
  }
Exemplo n.º 3
0
bool Mesh::contains(const QPoint& point) const {
  int n = anchor_points.size();
  for (int i = 0; i < n - 1; ++i) {
    QPolygon polygon;
    polygon << QPoint(anchor_points[i][0].x, anchor_points[i][0].y);
    polygon << QPoint(anchor_points[i][1].x, anchor_points[i][1].y);
    polygon << QPoint(anchor_points[i + 1][1].x, anchor_points[i + 1][1].y);
    polygon << QPoint(anchor_points[i + 1][0].x, anchor_points[i + 1][0].y);

    if (polygon.containsPoint(point, Qt::FillRule::OddEvenFill)) {
      return true;
    }
  }

  return false;
}
/*----------------------------------------------------------------------------*/
void ChannelEdit :: mousePressEvent(QMouseEvent *event)
{
  if(m_audioOpened)
  {
    qreal dX = (qreal)width() / (qreal) m_windowSize;
    if(effectController->mode() == EffectController::SelectMode)
    {
      int size = effects.size();
      int i;
      for(i = 0; i < size; i++)
      {
        EffectProperties *prop = effects[i];
        if(prop->channel() == m_channelId)
        {
          int pos = (int)(dX * (audioController->duration2quants(prop->timeStart()) - m_startPosition));
          QPolygon pol = createPolygon(pos);
          if(pol.containsPoint(event->pos(),Qt::OddEvenFill))
          {
            effectController->selectEffect(prop->id());
            m_selected = prop->id();
            break;
          }
        }
      }
      if(i >= size)
      {
        effectController->selectEffect(-1);
        m_selected = -1;
      }
    }
    else
    if(effectController->mode() == EffectController::AddMode)
    {
      qreal d =  (qreal) m_windowSize/ (qreal)width();
      EffectProperties *prop = effectController->newEffect(effectController->effectToAdd(), m_channelId);
      prop->setTimeStart(audioController->quants2duration(m_startPosition + (qint64)(event->pos().x() * d)));
      effectController->selectEffect(prop->id());
      effectController->setMode(EffectController::SelectMode);
    }
  }

  Inherited::mousePressEvent(event);
}
Exemplo n.º 5
0
void SaxsviewMask::Private::setValue(SaxsviewMask *mask, const QPolygonF& p, double value) {
  if (SaxsviewFrameData *d = (SaxsviewFrameData*)(mask->data())) {
    // QPolygonF::toPolygon() internally uses toPoint() rounding, see above.
    QPolygon polygon;
    foreach (QPointF pt, p)
      polygon << QPoint((int)pt.x(), (int)pt.y());

    const QRect r = polygon.boundingRect();

    if (polygon.size() > 2) {
      for (int x = r.x(); x <= r.x() + r.width(); ++x)
        for (int y = r.y(); y <= r.y() + r.height(); ++y)
          if (polygon.containsPoint(QPoint(x, y), Qt::OddEvenFill))
            d->setValue(x, y, value);

    } else
      bresenham(polygon[0].x(), polygon[0].y(),
                polygon[1].x(), polygon[1].y(),
                d, value);

    modified = true;
    mask->plot()->replot();
  }
}
void ut_redeyereduction::testRedEyeForCircularArea()
{
    QuillImageFilter *filter =
            QuillImageFilterFactory::createImageFilter("org.maemo.red-eye-reduction");

    QVERIFY(filter);
    QCOMPARE(filter->name(), QString("com.meego.red-eye-reduction"));

    QPoint center(100, 100);
    QVERIFY(filter->supportsOption(QuillImageFilter::Center));
    QVERIFY(filter->setOption(QuillImageFilter::Center, QVariant(center)));

    QVariantList list0 = filter->option(QuillImageFilter::SelectionArea).value<QVariantList>();
    QVERIFY(list0.count() == 0); // No radius set yet

    for (int r = 1; r < 101; r+=20)
        {
            QVERIFY(filter->supportsOption(QuillImageFilter::Radius));
            QVERIFY(filter->setOption(QuillImageFilter::Radius, QVariant(r)));

            bool bOK = true;
            QCOMPARE(filter->option(QuillImageFilter::Radius).toList().first().toInt(&bOK), r);
            QCOMPARE(filter->option(QuillImageFilter::Center).toList().first().toPoint(), center);

            QVERIFY(bOK);

            QVERIFY(filter->supportsOption(QuillImageFilter::SelectionArea));

            QPolygon polygon = filter->option(QuillImageFilter::SelectionArea).value<QPolygon>();

            float pi = 3.14159265;
            float margin = 1;
            for (int phi = 0; phi < 360; phi += 10)
                {
                    float x = r * cos( 2.0 * pi * phi / 360.0);
                    if (fabs(x) > margin)
                        x = (x>0 ? 1 : -1) * floor(fabs(x) - margin);
                    else
                        x = 0;
                    float y = r * sin( 2.0 * pi * phi / 360.0);
                    if (fabs(y) > margin)
                        y = (y>0 ? 1 : -1) * floor(fabs(y) - margin);
                    else
                        y = 0;
                    QPoint pt(x, y);
                    pt += center;
                    QVERIFY(polygon.containsPoint(pt, Qt::WindingFill));
                }

            for (int phi = 0; phi < 360; phi += 10)
                {
                    float x = r * cos( 2.0 * pi * phi / 360.0);
                    x = (x>0 ? 1 : -1) * ceil(fabs(x) + margin);
                    float y = r * sin( 2.0 * pi * phi / 360.0);
                    y = (y>0 ? 1 : -1) * ceil(fabs(y) + margin);
                    QPoint pt(x, y);
                    pt += center;
                    QVERIFY(polygon.containsPoint(pt, Qt::WindingFill) == false);
                }
        }
    delete filter;
}
void ut_redeyereduction::testRedEyeForMultipleCircularAreas()
{
    QuillImageFilter *filter =
            QuillImageFilterFactory::createImageFilter("org.maemo.red-eye-reduction");

    QVERIFY(filter);
    QCOMPARE(filter->name(), QString("com.meego.red-eye-reduction"));

    QVariantList centerPoints;
    for (int i = 100; i < 110; i++)
        centerPoints << QPoint(i, i);

    QVERIFY(filter->supportsOption(QuillImageFilter::Center));
    QVERIFY(filter->setOption(QuillImageFilter::Center, QVariant(centerPoints)));

    QVariantList list0 = filter->option(QuillImageFilter::SelectionArea).value<QVariantList>();
    QVERIFY(list0.count() == 0); // No radius set yet

    QVERIFY(filter->supportsOption(QuillImageFilter::Radius));
    QVariantList radii;
    for (int r = 1; r < 101; r++)
        radii << QVariant(r);
    QVERIFY(filter->setOption(QuillImageFilter::Radius, QVariant(radii)));

    QVariantList outRadii = filter->option(QuillImageFilter::Radius).value<QVariantList>();
    for (int i = 0; i < radii.count(); i++) {
            bool bOK = true;
            QCOMPARE(outRadii[i].toInt(), radii[i].toInt(&bOK));
            QVERIFY(bOK);
        }

    QVariantList outCenter = filter->option(QuillImageFilter::Center).value<QVariantList>();
    for (int i = 0; i < centerPoints.count(); i++) {
            QCOMPARE(outCenter[i].toPoint(), centerPoints[i].toPoint());
        }

    QVERIFY(filter->supportsOption(QuillImageFilter::SelectionArea));
    QVariantList polygonList = filter->option(QuillImageFilter::SelectionArea).value<QVariantList>();

    QCOMPARE( polygonList.count(), ( radii.count() < centerPoints.count() ? radii.count() : centerPoints.count() ) );

    for (int i = 0; i < polygonList.count(); i++)
        {
            QPolygon polygon = polygonList[i].value<QPolygon>();

            float pi = 3.14159265;
            float margin = 1;
            for (int phi = 0; phi < 360; phi += 10)
                {
                    float x = radii[i].toInt() * cos( 2.0 * pi * phi / 360.0);
                    if (fabs(x) > margin)
                        x = (x>0 ? 1 : -1) * floor(fabs(x) - margin);
                    else
                        x = 0;
                    float y = radii[i].toInt() * sin( 2.0 * pi * phi / 360.0);
                    if (fabs(y) > margin)
                        y = (y>0 ? 1 : -1) * floor(fabs(y) - margin);
                    else
                        y = 0;
                    QPoint pt(x, y);
                    pt += centerPoints[i].toPoint();
                    QVERIFY(polygon.containsPoint(pt, Qt::WindingFill));
                }

            for (int phi = 0; phi < 360; phi += 10)
                {
                    float x = radii[i].toInt() * cos( 2.0 * pi * phi / 360.0);
                    x = (x>0 ? 1 : -1) * ceil(fabs(x) + margin);
                    float y = radii[i].toInt() * sin( 2.0 * pi * phi / 360.0);
                    y = (y>0 ? 1 : -1) * ceil(fabs(y) + margin);
                    QPoint pt(x, y);
                    pt += centerPoints[i].toPoint();
                    QVERIFY(polygon.containsPoint(pt, Qt::WindingFill) == false);
                }
        }
    delete filter;
}