示例#1
0
//! Wrapper for QPainter::drawPoints()
void QwtPainter::drawPoints( QPainter *painter,
    const QPoint *points, int pointCount )
{
    QRectF clipRect;
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );

    if ( deviceClipping )
    {
        const int minX = qCeil( clipRect.left() );
        const int maxX = qFloor( clipRect.right() );
        const int minY = qCeil( clipRect.top() );
        const int maxY = qFloor( clipRect.bottom() );

        const QRect r( minX, minY, maxX - minX, maxY - minY );

        QPolygon clippedPolygon( pointCount );
        QPoint *clippedData = clippedPolygon.data();

        int numClippedPoints = 0;
        for ( int i = 0; i < pointCount; i++ )
        {
            if ( r.contains( points[i] ) )
                clippedData[ numClippedPoints++ ] = points[i];
        }
        painter->drawPoints( clippedData, numClippedPoints );
    }
    else
    {
        painter->drawPoints( points, pointCount );
    }
}
void SingleCellViewGraphPanelPlotWidget::optimiseAxis(const int &pAxisId,
                                                      double &pMin,
                                                      double &pMax) const
{
    // Make sure that the given values are different

    if (pMin == pMax) {
        // The given values are the same, so update them so that we can properly
        // optimise them below

        double powerValue = pMin?qFloor(log10(qAbs(pMin)))-1.0:0.0;

        pMin = pMin-pow(10.0, powerValue);
        pMax = pMax+pow(10.0, powerValue);
    }

    // Optimise the axis' values so that they fall onto a factor of the axis'
    // minor step

    uint base = axisScaleEngine(pAxisId)->base();
    double majorStep = QwtScaleArithmetic::divideInterval(pMax-pMin,
                                                          axisMaxMajor(pAxisId),
                                                          base);
    double minorStep = QwtScaleArithmetic::divideInterval(majorStep,
                                                          axisMaxMinor(pAxisId),
                                                          base);

    pMin = qFloor(pMin/minorStep)*minorStep;
    pMax = qCeil(pMax/minorStep)*minorStep;
}
示例#3
0
void Layer::dab(int contextId, const Brush &brush, const Point &point)
{
	Brush effective_brush = brush;
	Layer *l = this;

	if(!brush.incremental()) {
		// Indirect brush: use a sublayer
		l = getSubLayer(contextId, brush.blendingMode(), brush.opacity(1) * 255);

		effective_brush.setOpacity(1.0);
		effective_brush.setOpacity2(brush.isOpacityVariable() ? 0.0 : 1.0);
		effective_brush.setBlendingMode(1);

	} else if(contextId<0) {
		// Special case: negative context IDs are temporary overlay strokes
		l = getSubLayer(contextId, brush.blendingMode(), 255);
		effective_brush.setBlendingMode(1);
	}

	Point p = point;
	if(!effective_brush.subpixel()) {
		p.setX(qFloor(p.x()));
		p.setY(qFloor(p.y()));
	}

	l->directDab(effective_brush, BrushMaskGenerator::cached(effective_brush), p);

	if(_owner)
		_owner->notifyAreaChanged();
}
示例#4
0
文件: grid.cpp 项目: bijanbina/RAIIS
void Grid::pressedSlot(qreal x, qreal y)
{

    int x_send = qFloor(x_last + (x - 0.5) * SCREEN_WIDTH);
    int y_send = qFloor(y_last + (y - 0.5) * SCREEN_HEIGHT);

    qDebug() << (x - x_last) << "\t" << x_last;

    qDebug() << "x: " << x << "y: " << y << "\t pressed\t" << "x send: " <<
                x_send << "y send: " << y_send;

    if ( x_send < 0 || y_send < 0  || x_send > X_MAX || y_send > Y_MAX)
    {
        qDebug() << "Entered Dead Zone!!!";
        return;
    }

    char writeBuffer[WRITE_BUFFER_LENGTH];
    sprintf(writeBuffer,"%d %d\n",x_send,y_send);
    qint64 bytesWritten = port->write(writeBuffer);

    qDebug() << bytesWritten << "is written.";

    x_last += (x - 0.5) * SCREEN_WIDTH;
    y_last += (y - 0.5) * SCREEN_HEIGHT;

}
示例#5
0
const QString & Transport::getTimeLocalStr() {
    timeLocalStr = "";
    qreal timeLocalCopy = timeLocal;

    quint16 hour = qFloor(timeLocalCopy / 3600);
    if(hour < 10) timeLocalStr += "0";
    timeLocalStr += QString::number(hour) + ":";
    timeLocalCopy -= hour*3600;

    quint16 min = qFloor(timeLocalCopy / 60);
    if(min < 10) timeLocalStr += "0";
    timeLocalStr += QString::number(min) + ":";
    timeLocalCopy -= min*60;

    quint8 sec = qFloor(timeLocalCopy);
    if(sec < 10) timeLocalStr += "0";
    timeLocalStr += QString::number(sec) + ":";
    timeLocalCopy -= sec;

    quint16 milli = (timeLocalCopy - qFloor(timeLocalCopy)) * 1000;
    if(milli < 10)       timeLocalStr += "00";
    else if(milli < 100) timeLocalStr += "0";
    timeLocalStr += QString::number(milli);

    return timeLocalStr;
}
示例#6
0
QColor iA3DObjectVis::getOrientationColor( vtkImageData* oi, size_t objID ) const
{
	int ip = qFloor( m_objectTable->GetValue( objID, m_columnMapping->value(iACsvConfig::Phi) ).ToDouble() );
	int it = qFloor( m_objectTable->GetValue( objID, m_columnMapping->value(iACsvConfig::Theta) ).ToDouble() );
	double *p = static_cast<double *>( oi->GetScalarPointer( it, ip, 0 ) );
	return QColor(p[0]*255, p[1]*255, p[2]*255, 255);
}
double RasterData::value(double x, double y) const
{
  if (x >= 0 && x < Statistic::SCREEN_SIZE &&
      y >= 0 && y < Statistic::SCREEN_SIZE)
    return d[qFloor(x)][qFloor(y)] > 0 ? qLn(d[qFloor(x)][qFloor(y)]) : 0.0;
  return 0.0;
}
bool OsmAnd::Frustum2D31::test(const PointI& p_) const
{
    AreaI64 bbox;
    bbox.topLeft = bbox.bottomRight = p0;
    bbox.enlargeToInclude(p1);
    bbox.enlargeToInclude(p2);
    bbox.enlargeToInclude(p3);
    const auto tilesCount = static_cast<int64_t>(1ull << ZoomLevel31);
    const auto xMinK = qFloor(static_cast<double>(bbox.left()) / tilesCount);
    const auto xMaxK = qCeil(static_cast<double>(bbox.right()) / tilesCount);
    const auto yMinK = qFloor(static_cast<double>(bbox.top()) / tilesCount);
    const auto yMaxK = qCeil(static_cast<double>(bbox.bottom()) / tilesCount);

    PointI64 dP;
    const PointI64 p(p_);
    for (auto xK = xMinK; xK <= xMaxK; xK++)
    {
        dP.x = tilesCount * xK;
        for (auto yK = yMinK; yK <= yMaxK; yK++)
        {
            dP.y = tilesCount * yK;
            if (Frustum2DI64::test(p + dP))
                return true;
        }
    }

    return false;
}
示例#9
0
void drawHist(QGraphicsPixmapItem *pixmapItem, std::vector<int> &hist, int maxLevel)
{
    QGraphicsScene *scene = pixmapItem->scene();
    QGraphicsView *view = scene->views()[0];
    int width = view->contentsRect().width();
    int height = view->contentsRect().height();
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    QColor red(255, 0, 0);
    QImage image(width, height, QImage::Format_ARGB32);
    image.fill(white);
    QPainter p(&image);
    double shift = (double) image.width() / hist.size();
    double step = (double) image.height() / maxLevel;
    for (unsigned int i = 0; i < hist.size(); ++i)
    {
        if (i == 0 || i == hist.size() - 1)
        {
            p.setPen(red);
            p.setBrush(QBrush(red));
        }
        else if (i == 1)
        {
            p.setPen(black);
            p.setBrush(QBrush(black));
        }
        if (hist[i] == 0)
            continue;
        int curHeight = hist[i] * step;
        p.drawRect(qFloor(i * shift), qFloor(image.height() - curHeight), qFloor(shift), qFloor(curHeight));
    }
    pixmapItem->setPixmap(QPixmap::fromImage(image));
    scene->setSceneRect(QRectF(image.rect()));
}
示例#10
0
void PlotAxes::setGeometry(const QRect& rect) {
  this->rect = rect;

  linX.set(minTime, rect.left(), maxTime, rect.right());
  linY.set(min, rect.bottom(), max, rect.top());

  qreal tick;

  /// time axis:
  tick = findTimeTickIncrement(maxTime - minTime, rect.width(), TICK_SPACING_X);
  this->timeInterval = tick;
  tickCountX = qFloor((maxTime-minTime) / tick) + 1;
  this->startTimeTick = tick * qCeil(minTime / tick);
  tickX = linX.compose(Util::LinearFunc(tick, startTimeTick));

  /// vertical axis:
  tick = findTickIncrement(max - min, rect.height(), TICK_SPACING_Y);
  this->first = tick * qCeil(min / tick);
  tickCountY = qFloor((max - first) / tick) + 1;
  tickY = linY.compose(Util::LinearFunc(tick, first));
  this->step = tick;

  if (min > 0) {
    base = rect.bottom();
  } else if (max < 0) {
    base = rect.top();
  } else {
    base = linY.get(0);
  }

  emitGeometryChanged();
}
示例#11
0
void XPLANEFlightSimData::parseInputData(QByteArray InputData)
{

		//altitude, latitude, longitude,vertspeed, groundspeed, indicatedairspeed, machspeed, payloadweight, totalweight, fueltotalweight, counter, heading, utc, lcl
		QList<QByteArray> newdata = InputData.split(';');

		if (newdata.length() < 11)
			return;

		mfGroundSpeed = QString(newdata.at(4)).toFloat();
		mfIAS = QString(newdata.at(5)).toFloat();
		mfMach = QString(newdata.at(6)).toFloat();

		mdLatitude = QString(newdata.at(1)).toDouble();
		mdLongitude = QString(newdata.at(2)).toDouble();

		mfAltitude = QString(newdata.at(0)).toFloat();

		mfHeading = QString(newdata.at(11)).toFloat();

		m_LCLTime = QTime(0,0,0);
		m_LCLTime = m_LCLTime.addSecs(qFloor(QString(newdata.at(13)).toFloat()));

		m_UTCTime = QTime(0,0,0);
		m_UTCTime = m_UTCTime.addSecs(qFloor(QString(newdata.at(12)).toFloat()));
		
		qDebug()  << QString(newdata.at(12));
		qDebug()  << QString(newdata.at(13));

		((ACARSSystem*)this->parent())->eventFilter((QObject*)this, ((QEvent*) new ACARSMenuViewEvent(ACARSEVENT::FSUPDATEEVENT)));

}
示例#12
0
void SessionsInner::paintEvent(QPaintEvent *e) {
	QRect r(e->rect());
	Painter p(this);

	p.fillRect(r, st::white->b);
	p.setFont(st::linkFont->f);
	int32 x = st::sessionPadding.left(), xact = st::sessionTerminateSkip + st::sessionTerminate.iconPos.x();// st::sessionTerminateSkip + st::sessionTerminate.width + st::sessionTerminateSkip;
	int32 w = width();
	int32 from = (r.top() >= 0) ? qFloor(r.top() / st::sessionHeight) : 0, count = _list->size();
	if (from < count) {
		int32 to = (r.bottom() >= 0 ? qFloor(r.bottom() / st::sessionHeight) : 0) + 1;
		if (to > count) to = count;
		p.translate(0, from * st::sessionHeight);
		for (int32 i = from; i < to; ++i) {
			const SessionData &auth(_list->at(i));

			p.setFont(st::sessionNameFont->f);
			p.setPen(st::black->p);
			p.drawTextLeft(x, st::sessionPadding.top(), w, auth.name, auth.nameWidth);

			p.setFont(st::sessionActiveFont->f);
			p.setPen(st::sessionActiveColor->p);
			p.drawTextRight(xact, st::sessionPadding.top(), w, auth.active, auth.activeWidth);

			p.setFont(st::sessionInfoFont->f);
			p.setPen(st::black->p);
			p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height, w, auth.info, auth.infoWidth);
			p.setPen(st::sessionInfoColor->p);
			p.drawTextLeft(x, st::sessionPadding.top() + st::sessionNameFont->height + st::sessionInfoFont->height, w, auth.ip, auth.ipWidth);

			p.translate(0, st::sessionHeight);
		}
	}
}
void DigitizeStatePointMatch::handleMouseMove (CmdMediator *cmdMediator,
                                               QPointF posScreen)
{
//  LOG4CPP_DEBUG_S ((*mainCat)) << "DigitizeStatePointMatch::handleMouseMove";

  const DocumentModelPointMatch &modelPointMatch = cmdMediator->document().modelPointMatch();

  m_outline->setRect (posScreen.x() - modelPointMatch.maxPointSize() / 2.0,
                      posScreen.y() - modelPointMatch.maxPointSize() / 2.0,
                      modelPointMatch.maxPointSize(),
                      modelPointMatch.maxPointSize());

  const QImage &img = context().mainWindow().imageFiltered();
  int radiusLimit = cmdMediator->document().modelGeneral().cursorSize();
  bool pixelShouldBeOn = pixelIsOnInImage (img,
                                           qFloor (posScreen.x()),
                                           qFloor (posScreen.y()),
                                           radiusLimit);

  QColor penColorIs = m_outline->pen().color();
  bool pixelIsOn = (penColorIs.red () != penColorIs.green()); // Considered on if not gray scale
  if (pixelShouldBeOn != pixelIsOn) {
    QColor penColorShouldBe (pixelShouldBeOn ? Qt::green : Qt::black);
    m_outline->setPen (QPen (penColorShouldBe));
  }
}
示例#14
0
bool OsmAnd::Frustum2D31::test(const PointI& lp0_, const PointI& lp1_) const
{
    AreaI64 bbox;
    bbox.topLeft = bbox.bottomRight = p0;
    bbox.enlargeToInclude(p1);
    bbox.enlargeToInclude(p2);
    bbox.enlargeToInclude(p3);
    const auto tilesCount = static_cast<int64_t>(1ull << ZoomLevel31);
    const auto xMinK = qFloor(static_cast<double>(bbox.left()) / tilesCount);
    const auto xMaxK = qCeil(static_cast<double>(bbox.right()) / tilesCount);
    const auto yMinK = qFloor(static_cast<double>(bbox.top()) / tilesCount);
    const auto yMaxK = qCeil(static_cast<double>(bbox.bottom()) / tilesCount);

    // 3+ repeats for world include any point in world
    if (qAbs(xMaxK - xMinK) >= 3 && qAbs(yMaxK - yMinK) >= 3)
        return true;

    PointI64 dP;
    const PointI64 lp0(lp0_);
    const PointI64 lp1(lp1_);
    for (auto xK = xMinK; xK <= xMaxK; xK++)
    {
        dP.x = tilesCount * xK;
        for (auto yK = yMinK; yK <= yMaxK; yK++)
        {
            dP.y = tilesCount * yK;
            if (Frustum2DI64::test(lp0 + dP, lp1 + dP))
                return true;
        }
    }

    return false;
}
示例#15
0
/*!
  \brief Draw the needle

  A clock has no single needle but three hands instead. drawNeedle
  translates value() into directions for the hands and calls
  drawHand().

  \param painter Painter
  \param center Center of the clock
  \param radius Maximum length for the hands
  \param dir Dummy, not used.
  \param colorGroup ColorGroup

  \sa drawHand()
*/
void QwtAnalogClock::drawNeedle( QPainter *painter, const QPointF &center,
    double radius, double dir, QPalette::ColorGroup colorGroup ) const
{
    Q_UNUSED( dir );

    if ( isValid() )
    {
        const double hours = value() / ( 60.0 * 60.0 );
        const double minutes = 
            ( value() - qFloor(hours) * 60.0 * 60.0 ) / 60.0;
        const double seconds = value() - qFloor(hours) * 60.0 * 60.0
            - qFloor(minutes) * 60.0;

        double angle[NHands];
        angle[HourHand] = 360.0 * hours / 12.0;
        angle[MinuteHand] = 360.0 * minutes / 60.0;
        angle[SecondHand] = 360.0 * seconds / 60.0;

        for ( int hand = 0; hand < NHands; hand++ )
        {
            double d = angle[hand];
            if ( direction() == Clockwise )
                d = 360.0 - d;

            d -= origin();

            drawHand( painter, ( Hand )hand, center, radius, d, colorGroup );
        }
    }
}
void QSGPainterNode::paint()
{
    QRect dirtyRect = m_dirtyRect.isNull() ? QRect(0, 0, m_size.width(), m_size.height()) : m_dirtyRect;

    QPainter painter;
    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        if (m_image.isNull())
            return;
        painter.begin(&m_image);
    } else {
        if (!m_gl_device) {
            m_gl_device = new QOpenGLPaintDevice(m_fboSize);
            m_gl_device->setPaintFlipped(true);
        }

        if (m_multisampledFbo)
            m_multisampledFbo->bind();
        else
            m_fbo->bind();

        painter.begin(m_gl_device);
    }

    if (m_smoothPainting) {
        painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
    }

    painter.scale(m_contentsScale, m_contentsScale);

    QRect sclip(qFloor(dirtyRect.x()/m_contentsScale),
                qFloor(dirtyRect.y()/m_contentsScale),
                qCeil(dirtyRect.width()/m_contentsScale+dirtyRect.x()/m_contentsScale-qFloor(dirtyRect.x()/m_contentsScale)),
                qCeil(dirtyRect.height()/m_contentsScale+dirtyRect.y()/m_contentsScale-qFloor(dirtyRect.y()/m_contentsScale)));

    if (!m_dirtyRect.isNull())
        painter.setClipRect(sclip);

    painter.setCompositionMode(QPainter::CompositionMode_Source);
    painter.fillRect(sclip, m_fillColor);
    painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

    m_item->paint(&painter);
    painter.end();

    if (m_actualRenderTarget == QQuickPaintedItem::Image) {
        m_texture->setImage(m_image);
        m_texture->setDirtyRect(dirtyRect);
    } else if (m_multisampledFbo) {
        QOpenGLFramebufferObject::blitFramebuffer(m_fbo, dirtyRect, m_multisampledFbo, dirtyRect);
    }

    if (m_multisampledFbo)
        m_multisampledFbo->release();
    else if (m_fbo)
        m_fbo->release();

    m_dirtyRect = QRect();
}
示例#17
0
void QPaintEngine::drawImage(const QRectF &r, const QImage &image, const QRectF &sr,
                             Qt::ImageConversionFlags flags)
{
    QRectF baseSize(0, 0, image.width(), image.height());
    QImage im = image;
    if (baseSize != sr)
        im = im.copy(qFloor(sr.x()), qFloor(sr.y()),
                     qCeil(sr.width()), qCeil(sr.height()));
    QPixmap pm = QPixmap::fromImage(im, flags);
    drawPixmap(r, pm, QRectF(QPointF(0, 0), pm.size()));
}
int FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber (double valueUnformatted,
                                                                        double valueUnformattedOther,
                                                                        bool isXTheta,
                                                                        const DocumentModelGeneral &modelGeneral,
                                                                        const Transformation &transformation) const
{
  LOG4CPP_DEBUG_S ((*mainCat)) << "FormatCoordsUnitsStrategyAbstractBase::precisionDigitsForRawNumber";

  const double PIXEL_SHIFT = 1;
  const int DEFAULT_PRECISION = 5; // Precision used before transformation is available. Equal or greater than x/y pixel counts

  if (transformation.transformIsDefined()) {

    // Measure the resolution if the point is moved some number of pixels in screen coordinates
    QPointF posGraph;
    if (isXTheta) {

      posGraph = QPointF (valueUnformatted,
                          valueUnformattedOther);

    } else {

      posGraph = QPointF (valueUnformattedOther,
                          valueUnformatted);

    }

    QPointF posScreen, posScreenShifted, posGraphShifted;

    transformation.transformRawGraphToScreen (posGraph,
                                              posScreen);

    posScreenShifted = posScreen + QPointF (PIXEL_SHIFT, PIXEL_SHIFT);

    transformation.transformScreenToRawGraph (posScreenShifted,
                                              posGraphShifted);

    double xResolutionPerPixel = (posGraphShifted.x() - posGraph.x()) / PIXEL_SHIFT;
    double yResolutionPerPixel = (posGraphShifted.y() - posGraph.y()) / PIXEL_SHIFT;
    double resolutionPerPixel = (isXTheta ? xResolutionPerPixel : yResolutionPerPixel);

    // Compute number of digits ahead of the decimal point (any single decimal place would work but the decimal point is easiest)
    int powerValue = qFloor (qLn (qAbs (valueUnformatted)) / qLn (10.0));
    int powerResolution = qFloor (qLn (qAbs (resolutionPerPixel)) / qLn (10.0));

    int numberDigitsForResolution = powerValue - powerResolution + 1 + modelGeneral.extraPrecision();

    return numberDigitsForResolution + 1; // Add one just to be safe

  } else {

    return DEFAULT_PRECISION;
  }
}
示例#19
0
/*!
  Render the legend into a given rectangle.

  \param painter Painter
  \param rect Bounding rectangle
  \param fillBackground When true, fill rect with the widget background 

  \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
*/
void QwtLegend::renderLegend( QPainter *painter, 
    const QRectF &rect, bool fillBackground ) const
{
    if ( d_data->itemMap.isEmpty() )
        return;

    if ( fillBackground )
    {
        if ( autoFillBackground() ||
            testAttribute( Qt::WA_StyledBackground ) )
        {
            QwtPainter::drawBackgound( painter, rect, this );
        }
    }

    const QwtDynGridLayout *legendLayout = 
        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );

    QRect layoutRect; 
    layoutRect.setLeft( qCeil( rect.left() ) + left );
    layoutRect.setTop( qCeil( rect.top() ) + top );
    layoutRect.setRight( qFloor( rect.right() ) - right );
    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );

    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( layoutRect, numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index], Qt::IntersectClip );
            renderItem( painter, w, itemRects[index], fillBackground );

            index++;
            painter->restore();
        }
    }
}
void QPicturePaintEngine::writeCmdLength(int pos, const QRectF &r, bool corr)
{
    Q_D(QPicturePaintEngine);
    int newpos = d->pic_d->pictb.pos();            // new position
    int length = newpos - pos;
    QRectF br(r);

    if (length < 255) {                         // write 8-bit length
        d->pic_d->pictb.seek(pos - 1);             // position to right index
        d->s << (quint8)length;
    } else {                                    // write 32-bit length
        d->s << (quint32)0;                    // extend the buffer
        d->pic_d->pictb.seek(pos - 1);             // position to right index
        d->s << (quint8)255;                   // indicate 32-bit length
        char *p = d->pic_d->pictb.buffer().data();
        memmove(p+pos+4, p+pos, length);        // make room for 4 byte
        d->s << (quint32)length;
        newpos += 4;
    }
    d->pic_d->pictb.seek(newpos);                  // set to new position

    if (br.width() > 0.0 || br.height() > 0.0) {
        if (corr) {                             // widen bounding rect
            int w2 = painter()->pen().width() / 2;
            br.setCoords(br.left() - w2, br.top() - w2,
                         br.right() + w2, br.bottom() + w2);
        }
        br = painter()->transform().mapRect(br);
        if (painter()->hasClipping()) {
            QRect cr = painter()->clipRegion().boundingRect();
            br &= cr;
        }

        if (br.width() > 0.0 || br.height() > 0.0) {
            int minx = qFloor(br.left());
            int miny = qFloor(br.top());
            int maxx = qCeil(br.right());
            int maxy = qCeil(br.bottom());

            if (d->pic_d->brect.width() > 0 || d->pic_d->brect.height() > 0) {
                minx = qMin(minx, d->pic_d->brect.left());
                miny = qMin(miny, d->pic_d->brect.top());
                maxx = qMax(maxx, d->pic_d->brect.x() + d->pic_d->brect.width());
                maxy = qMax(maxy, d->pic_d->brect.y() + d->pic_d->brect.height());
                d->pic_d->brect = QRect(minx, miny, maxx - minx, maxy - miny);
            } else {
                d->pic_d->brect = QRect(minx, miny, maxx - minx, maxy - miny);
            }
        }
    }
}
/*!
  Render the legend into a given rectangle.

  \param plot Plot widget
  \param painter Painter
  \param rect Bounding rectangle
*/
void QwtPlotRenderer::renderLegend( const QwtPlot *plot,
    QPainter *painter, const QRectF &rect ) const
{
    if ( !plot->legend() || plot->legend()->isEmpty() )
        return;

    if ( !( d_data->discardFlags & DiscardBackground ) )
    {
        if ( plot->legend()->autoFillBackground() ||
            plot->legend()->testAttribute( Qt::WA_StyledBackground ) )
        {
            qwtRenderBackground( painter, rect, plot->legend() );
        }
    }

    const QwtDynGridLayout *legendLayout = qobject_cast<QwtDynGridLayout *>( 
        plot->legend()->contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    int left, right, top, bottom;
    plot->legend()->getContentsMargins( &left, &top, &right, &bottom );

    QRect layoutRect;
    layoutRect.setLeft( qCeil( rect.left() ) + left );
    layoutRect.setTop( qCeil( rect.top() ) + top );
    layoutRect.setRight( qFloor( rect.right() ) - right );
    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );

    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( layoutRect, numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index] );
            renderLegendItem( plot, painter, w, itemRects[index] );

            index++;
            painter->restore();
        }
    }
}
示例#22
0
void RGB_equalization(QImage &image)
{
    int width = image.width();
    int height = image.height();

    int histSize = 256;
    std::vector<double> histR(histSize, 0.0);
    std::vector<double> histG(histSize, 0.0);
    std::vector<double> histB(histSize, 0.0);

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = qRed(oldColor);
            int green = qGreen(oldColor);
            int blue = qBlue(oldColor);
            ++histR[red];
            ++histG[green];
            ++histB[blue];
        }

    for (int i = 1; i < histSize; ++i)
    {
        histR[i] += histR[i - 1];
        histG[i] += histG[i - 1];
        histB[i] += histB[i - 1];
    }

    for (int i = 0; i < histSize; ++i)
    {
        histR[i] /= width * height;
        histG[i] /= width * height;
        histB[i] /= width * height;
    }

    for (int y = 0; y < height; ++y)
        for (int x = 0; x < width; ++x)
        {
            QRgb oldColor = image.pixel(x, y);
            int red = qRed(oldColor);
            int green = qGreen(oldColor);
            int blue = qBlue(oldColor);
            int newRed = qMin(qFloor(histSize * histR[red]), histSize - 1);
            int newGreen = qMin(qFloor(histSize * histG[green]), histSize - 1);
            int newBlue = qMin(qFloor(histSize * histB[blue]), histSize - 1);
            image.setPixel(x, y, qRgb(newRed, newGreen, newBlue));
        }
}
示例#23
0
void StickerSetInner::paintEvent(QPaintEvent *e) {
	QRect r(e->rect());
	Painter p(this);

	if (_pack.isEmpty()) return;

	int32 rows = _pack.size() / StickerPanPerRow + ((_pack.size() % StickerPanPerRow) ? 1 : 0);
	int32 from = qFloor(e->rect().top() / st::stickersSize.height()), to = qFloor(e->rect().bottom() / st::stickersSize.height()) + 1;

	for (int32 i = from; i < to; ++i) {
		for (int32 j = 0; j < StickerPanPerRow; ++j) {
			int32 index = i * StickerPanPerRow + j;
			if (index >= _pack.size()) break;

			DocumentData *doc = _pack.at(index);
			QPoint pos(st::stickerPanPadding + j * st::stickersSize.width(), i * st::stickersSize.height());

			bool goodThumb = !doc->thumb->isNull() && ((doc->thumb->width() >= 128) || (doc->thumb->height() >= 128));
			if (goodThumb) {
				doc->thumb->load();
			} else {
				bool already = !doc->already().isEmpty(), hasdata = !doc->data.isEmpty();
				if (!doc->loader && doc->status != FileFailed && !already && !hasdata) {
					doc->save(QString());
				}
				if (doc->sticker->img->isNull() && (already || hasdata)) {
					if (already) {
						doc->sticker->img = ImagePtr(doc->already());
					} else {
						doc->sticker->img = ImagePtr(doc->data);
					}
				}
			}

			float64 coef = qMin((st::stickersSize.width() - st::msgRadius * 2) / float64(doc->dimensions.width()), (st::stickersSize.height() - st::msgRadius * 2) / float64(doc->dimensions.height()));
			if (coef > 1) coef = 1;
			int32 w = qRound(coef * doc->dimensions.width()), h = qRound(coef * doc->dimensions.height());
			if (w < 1) w = 1;
			if (h < 1) h = 1;
			QPoint ppos = pos + QPoint((st::stickersSize.width() - w) / 2, (st::stickersSize.height() - h) / 2);
			if (goodThumb) {
				p.drawPixmapLeft(ppos, width(), doc->thumb->pix(w, h));
			} else if (!doc->sticker->img->isNull()) {
				p.drawPixmapLeft(ppos, width(), doc->sticker->img->pix(w, h));
			}
		}
	}
	p.fillRect(0, _bottom - st::stickersAddOrShare, width(), st::stickersAddOrShare, st::emojiPanHeaderBg->b);
}
void SpaceObjectShip :: checkBounds(int minX, int minY, int maxX, int maxY)
{
  if (mCoordX < minX * 80)
    mCoordX = minX * 80;
  if (mCoordY < minY * 80)
    mCoordY = minY * 80;

  if (mCoordX >= maxX * 80)
    mCoordX = maxX * 80 - 1;
  if (mCoordY >= maxY * 80)
    mCoordY = maxY * 80 - 1;

  mX = qFloor(mCoordX / 80);
  mY = qFloor(mCoordY / 80);
}
示例#25
0
void CanvasView::updateOutline(paintcore::Point point) {
	if(!_subpixeloutline) {
		point.setX(qFloor(point.x()));
		point.setY(qFloor(point.y()));
	}
	if(_enableoutline && _showoutline && !_locked && !point.roughlySame(_prevoutlinepoint)) {
		QList<QRectF> rect;
		rect.append(QRectF(_prevoutlinepoint.x() - _outlinesize,
					_prevoutlinepoint.y() - _outlinesize, _dia, _dia));
		rect.append(QRectF(point.x() - _outlinesize,
					point.y() - _outlinesize, _dia, _dia));
		updateScene(rect);
		_prevoutlinepoint = point;
	}
}
int WidgetTableProgression::easingQuinticOut(double x, int start, int change,
    int duration)
{
    x /= duration;
    x--;
    return qFloor(change * (x * x * x * x * x + 1) + start);
}
示例#27
0
void RGBMatrixItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    float timeScale = 50 / float(m_timeScale);

    ShowItem::paint(painter, option, widget);

    quint32 matrixDuration = getDuration();

    if (matrixDuration)
    {
        float xpos = 0;
        int loopCount = m_function->duration() ? qFloor(m_function->duration() / m_matrix->totalDuration()) : 0;

        for (int i = 0; i < loopCount; i++)
        {
            xpos += ((timeScale * float(m_matrix->totalDuration())) / 1000);
            // draw loop vertical delimiter
            painter->setPen(QPen(Qt::white, 1));
            painter->drawLine(int(xpos), 1, int(xpos), TRACK_HEIGHT - 5);
        }
    }

    ShowItem::postPaint(painter);
}
示例#28
0
void IntroWidget::animShow(const QPixmap &bgAnimCache, bool back) {
	if (App::app()) App::app()->mtpPause();

	(back ? _cacheOver : _cacheUnder) = bgAnimCache;

	_a_show.stop();
	stages[current]->show();
	if (stages[current]->hasBack()) {
		_back.setOpacity(1);
		_back.show();
	} else {
		_back.hide();
	}
	(back ? _cacheUnder : _cacheOver) = myGrab(this);

	stages[current]->deactivate();
	stages[current]->hide();
	_back.hide();

	a_coordUnder = back ? anim::ivalue(-qFloor(st::slideShift * width()), 0) : anim::ivalue(0, -qFloor(st::slideShift * width()));
	a_coordOver = back ? anim::ivalue(0, width()) : anim::ivalue(width(), 0);
	a_shadow = back ? anim::fvalue(1, 0) : anim::fvalue(0, 1);
	_a_show.start();

	show();
}
示例#29
0
pcm_sample *WaveformManager::storeCompress(const pcm_sample *raw, unsigned long long spc, unsigned int *blockSize) {

	// Split store into positive and negative 
	// values for the mean based compression
	auto waveUnits = WaveformManager::MaxSize/2;

	*blockSize = qFloor(spc / waveUnits); // total blocks for the channel
	auto sampleIndex = 0ull;
	pcm_sample sample;

	pcm_sample *compressed = new pcm_sample[WaveformManager::MaxSize];

	for(int block = 0; block < WaveformManager::MaxSize;) {

		auto blockPs = 0, blockNg = 0;
		auto accPs = 0.0f, accNg = 0.0f;
		for(auto i = 0u; i < *blockSize; i++) {
			if((sample = raw[sampleIndex]) >= 0.0f) {
				accPs += sample;
				blockPs++;
			} else {
				accNg += sample;
				blockNg++;
			}

			sampleIndex += 2;
		}

		compressed[block++] = blockPs ? (accPs/blockPs) : 0;
		compressed[block++] = blockNg ? (accNg/blockNg) : 0;
	}

	return compressed;

}
示例#30
0
static double floor_with_tolerance( double value )
{
  if ( qAbs( value - qRound( value ) ) < 1e-6 )
    return qRound( value );
  else
    return qFloor( value );
}