コード例 #1
0
void QBlitterPaintEnginePrivate::clipAndDrawPixmap(const QRectF &clip, const QRectF &target, const QPixmap &pm, const QRectF &sr, bool opacity)
{
    Q_Q(QBlitterPaintEngine);
    QRectF intersectedRect = clip.intersected(target);
    if (intersectedRect.isEmpty())
        return;
    QRectF source = sr;
    if (intersectedRect.size() != target.size()) {
        if (sr.size() == target.size()) {
            // no resize
            qreal deltaTop = target.top() - intersectedRect.top();
            qreal deltaLeft = target.left() - intersectedRect.left();
            qreal deltaBottom = target.bottom() - intersectedRect.bottom();
            qreal deltaRight = target.right() - intersectedRect.right();
            source.adjust(-deltaLeft, -deltaTop, -deltaRight, -deltaBottom);
        } else {
            // resize case
            qreal hFactor = sr.size().width() / target.size().width();
            qreal vFactor = sr.size().height() / target.size().height();
            qreal deltaTop = (target.top() - intersectedRect.top()) * vFactor;
            qreal deltaLeft = (target.left() - intersectedRect.left()) * hFactor;
            qreal deltaBottom = (target.bottom() - intersectedRect.bottom()) * vFactor;
            qreal deltaRight = (target.right() - intersectedRect.right()) * hFactor;
            source.adjust(-deltaLeft, -deltaTop, -deltaRight, -deltaBottom);
        }
    }
    pmData->unmarkRasterOverlay(intersectedRect);
    if (opacity)
        pmData->blittable()->drawPixmapOpacity(intersectedRect, pm, source, q->state()->compositionMode(), q->state()->opacity);
    else
        pmData->blittable()->drawPixmap(intersectedRect, pm, source);
}
コード例 #2
0
//! Wrapper for QPainter::fillRect()
void QwtPainter::fillRect( QPainter *painter,
    const QRectF &rect, const QBrush &brush )
{
    if ( !rect.isValid() )
        return;

    QRectF clipRect;
    const bool deviceClipping = qwtIsClippingNeeded( painter, clipRect );

    /*
      Performance of Qt4 is horrible for a non trivial brush. Without
      clipping expect minutes or hours for repainting large rectangles
      (might result from zooming)
    */

    if ( deviceClipping )
        clipRect &= painter->window();
    else
        clipRect = painter->window();

    if ( painter->hasClipping() )
        clipRect &= painter->clipRegion().boundingRect();

    QRectF r = rect;
    if ( deviceClipping )
        r = r.intersected( clipRect );

    if ( r.isValid() )
        painter->fillRect( r, brush );
}
コード例 #3
0
void PlotGraph::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::white);
    painter->setOpacity(0.7);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);

    painter->setPen(QPen(Qt::black, 3));
    painter->drawLine(
                QPointF(xOrigin, yMax),
                QPointF(xOrigin, yOrigin + 10));
    painter->drawLine(
                QPointF(xOrigin - 5, yOrigin),
                QPointF(xMax, yOrigin));

}
コード例 #4
0
ファイル: BlurItem.cpp プロジェクト: impomezia/screenpic
void BlurItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
  QGraphicsRectItem::mouseMoveEvent(event);

  const QPointF pos = event->scenePos();
  QRectF r;

  r.setTopLeft(m_point);
  r.setBottomRight(event->scenePos());

  if (r.width() < 0) {
    r.setLeft(pos.x());
    r.setRight(m_point.x());
  }

  if (r.height() < 0) {
    r.setTop(pos.y());
    r.setBottom(m_point.y());
  }

  r = r.intersected(m_item->scene()->sceneRect());

  setRect(r);
  setSelected(true);
  m_item->setOffset(r.topLeft());

  reload(m_pixmap);
}
コード例 #5
0
void ListItemCache::draw(QPainter * painter) 
{
    QRectF irect = sourceBoundingRect(Qt::LogicalCoordinates);
    QRectF vrect = painter->clipPath().boundingRect();

    if (vrect.intersects(irect)) {
        QRectF newVisibleRect = irect.intersected(vrect);
        QPixmap pixmap;

        if (!QPixmapCache::find(m_cacheKey, &pixmap) ||
            m_visibleRect.toRect() != newVisibleRect.toRect()) {
            //qDebug() << "ListItemCache: caching" << m_visibleRect
            //    << "->" << newVisibleRect;

            pixmap = QPixmap(sourceBoundingRect().toRect().size());
            pixmap.fill(Qt::transparent);

            QPainter pixmapPainter(&pixmap);
            drawSource(&pixmapPainter);
            pixmapPainter.end();
            m_cacheKey = QPixmapCache::insert(pixmap);

            m_visibleRect = newVisibleRect;
        }

        //qDebug() << "ListItemCache: blitting" << m_visibleRect;
        painter->drawPixmap(0, 0, pixmap);
    } 
}
コード例 #6
0
ファイル: demogoggles.cpp プロジェクト: ctbrowser/luna-sysmgr
//virtual
void DemoGoggles::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
{
	//map myself into the scene
	QRectF sceneRect = mapRectToScene(boundingRect());
	QRectF sourceRect = sceneRect.intersected(m_sceneBgViewrect).translated(-m_sceneBgViewrect.topLeft());
	m_qp_backgroundPmo->paint(painter,boundingRect().toRect(),sourceRect.toRect());
}
コード例 #7
0
void QgsTextAnnotationItem::paint( QPainter * painter )
{
  if ( !painter || !mDocument )
  {
    return;
  }

  drawFrame( painter );
  if ( mMapPositionFixed )
  {
    drawMarkerSymbol( painter );
  }
  double frameWidth = mFrameBorderWidth;
  mDocument->setTextWidth( mFrameSize.width() );

  painter->save();
  painter->translate( mOffsetFromReferencePoint.x() + frameWidth / 2.0,
                      mOffsetFromReferencePoint.y() + frameWidth / 2.0 );

  QRectF clipRect = QRectF( 0, 0, mFrameSize.width() - frameWidth / 2.0, mFrameSize.height() - frameWidth / 2.0 );
  if ( painter->hasClipping() )
  {
    //QTextDocument::drawContents will draw text outside of the painter's clip region
    //when it is passed a clip rectangle. So, we need to intersect it with the
    //painter's clip region to prevent text drawn outside clipped region (eg, outside composer maps, see #10400)
    clipRect = clipRect.intersected( painter->clipRegion().boundingRect() );
  }
  //draw text document
  mDocument->drawContents( painter, clipRect );
  painter->restore();
  if ( isSelected() )
  {
    drawSelectionBoxes( painter );
  }
}
コード例 #8
0
ファイル: PixmapRenderer.cpp プロジェクト: DikBSD/STE
void
PixmapRenderer::drawPixmapNoXRender(QPainter& painter, QPixmap const& pixmap)
{
	QTransform const inv_transform(painter.worldTransform().inverted());
	QRectF const src_rect(inv_transform.map(QRectF(painter.viewport())).boundingRect());
	QRectF const bounded_src_rect(src_rect.intersected(pixmap.rect()));
	painter.drawPixmap(bounded_src_rect, pixmap, bounded_src_rect);
}
コード例 #9
0
ファイル: itemspace.cpp プロジェクト: d42/cashewless-desktop
qreal ItemSpace::positionVisibility (const QRectF& geom)
{
    QRectF visibleArea = QRectF(QPointF(), workingGeom);
    QRectF visibleItemPart = visibleArea.intersected(geom);
    qreal itemSurface = geom.width() * geom.height();
    qreal itemVisibleSurface = visibleItemPart.width() * visibleItemPart.height();
    return (itemVisibleSurface / itemSurface);
}
コード例 #10
0
ファイル: HotPointView.cpp プロジェクト: mmalicki2/QOczko
void HotPointView::selectionChanged( const QRectF& rect )
{
	if (!item) return;	  
	if ( rect.isNull() && m_selection ) {
		graphicsView->scene()->removeItem( m_selection );
		delete m_selection;
		m_selection = 0;
	}

	if ( !rect.isNull() && !m_selection ) {
		m_selection = graphicsView->scene()->addRect( rect.intersected(item->boundingRect()).normalized(), QPen(Qt::DashDotLine), QBrush::QBrush(Qt::DiagCrossPattern));
		m_selection->setParentItem(item);
	}

	if ( !rect.isNull() && m_selection ) {
		m_selection->setRect( rect.intersected(item->boundingRect()).normalized() );
	}
}
コード例 #11
0
ファイル: insideBase.cpp プロジェクト: q4a/attal
void InsideBase::drawBackground( QPainter * painter, const QRectF& rect )
{
	if( _background ) {
		painter->fillRect( rect, Qt::black );
		QRectF tmp = rect.intersected( sceneRect() );
		painter->drawPixmap( tmp, * _background, tmp );
	} else {
		painter->fillRect( rect, Qt::black );
	}
}
コード例 #12
0
ファイル: canvasrect.cpp プロジェクト: pjmahoney/nutmeg
void CanvasRect::paint(QPainter *painter, const QTransform &tran, const QRectF &limits)
{
    QRectF plotRect = bounds();
    // Let's not waste time here...
    if (!limits.intersects(plotRect)) return;

    // TODO: This boilerplate style stuff to a CanvasShape::applyStyle(QPainter*) func?
    QPen pen;
    LineSpec *ln = lineSpec();
    pen.setColor(ln->color());
    pen.setWidthF(ln->width());

    QString style = ln->style();
    if (style == ".") {
        pen.setStyle(Qt::SolidLine);
    } else {
        pen.setStyle( LineSpec::styleMap[style] );
    }

    QBrush brush;
    brush.setStyle(Qt::SolidPattern);
    brush.setColor(fillSpec()->color());

    painter->setRenderHint(QPainter::Antialiasing);

    // Only draw the part of the rect in the view
    QRectF rect = limits.intersected(plotRect);
    // Figure out which sides still need lines...
    QVector<QLineF> lines;
    if (rect.left() == plotRect.left())
        lines << QLineF(rect.bottomLeft(), rect.topLeft());
    if (rect.right() == plotRect.right())
        lines << QLineF(rect.bottomRight(), rect.topRight());
    if (rect.top() == plotRect.top())
        lines << QLineF(rect.topLeft(), rect.topRight());
    if (rect.bottom() == plotRect.bottom())
        lines << QLineF(rect.bottomLeft(), rect.bottomRight());

    // Map the fill and lines
    QRectF mappedRect = tran.mapRect(rect);
    for (int i=0; i<lines.length(); ++i) {
        lines[i] = tran.map(lines[i]);
    }

    // Draw the rect
    painter->setPen(Qt::NoPen);
    painter->setBrush(brush);
    painter->drawRect(mappedRect);

    // Draw the outline
    painter->setBrush(Qt::NoBrush);
    painter->setPen(pen);
    painter->drawLines(lines);
}
コード例 #13
0
void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rectangle)
{
    painter->save();
    painter->setBrushOrigin(0, 0);

    painter->fillRect(rectangle.intersected(rootItemRect()), backgroundBrush());
    // paint rect around editable area
    painter->setPen(Qt::black);
    painter->drawRect( rootItemRect());
    painter->restore();
}
コード例 #14
0
void FormEditorGraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
{
    painter->save();
    painter->setBrushOrigin(0, 0);
    painter->fillRect(rect.intersected(sceneRect()), backgroundBrush());
    // paint rect around editable area
    painter->setPen(Qt::black);
    QRectF frameRect = sceneRect().adjusted(0, 0, 0, 0);
    painter->drawRect(frameRect);
    painter->restore();
}
コード例 #15
0
ファイル: qpaintengine_blitter.cpp プロジェクト: Blizzard/qt4
 void clipAndDrawPixmap(const QRectF &clip, const QRectF &target, const QPixmap &pm, const QRectF &sr) {
     QRectF intersectedRect = clip.intersected(target);
     if (intersectedRect.isEmpty())
         return;
     QRectF source = sr;
     if(intersectedRect.size() != target.size()) {
         qreal deltaTop = target.top() - intersectedRect.top();
         qreal deltaLeft = target.left() - intersectedRect.left();
         qreal deltaBottom = target.bottom() - intersectedRect.bottom();
         qreal deltaRight = target.right() - intersectedRect.right();
         source.adjust(-deltaLeft,-deltaTop,-deltaRight,-deltaBottom);
     }
     pmData->unmarkRasterOverlay(intersectedRect);
     pmData->blittable()->drawPixmap(intersectedRect, pm, source);
 }
コード例 #16
0
ファイル: widget.cpp プロジェクト: vultor33/Bacterial
void widget::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::blue);
    painter->setOpacity(0.7);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);
}
コード例 #17
0
bool
Annotations::interference( double x, double y, const QwtText& label, Qt::Alignment align ) const
{
	QRectF rc = boundingRect( x, y, label, align );

	auto it = std::find_if( vec_.begin(), vec_.end(), [=]( const Annotation& a ){
            QwtPlotMarker * marker = a.getPlotMarker();
            QRectF rhs = boundingRect( marker->xValue(), marker->yValue(), marker->label(), align );
            QRectF lhs = rc.intersected( rhs );
            return lhs.width() || lhs.height();
        });

	if ( it == vec_.end() )
		return false;

	return true;
}
コード例 #18
0
void QGraphicsVideoItemPrivate::updateRects()
{
    q_ptr->prepareGeometryChange();
    QSizeF videoSize;
    if (nativeSize.isEmpty()) {
        videoSize = rect.size();
    } else if (aspectRatioMode == Qt::IgnoreAspectRatio) {
        videoSize = rect.size();
    } else {
        // KeepAspectRatio or KeepAspectRatioByExpanding
        videoSize = nativeSize;
        videoSize.scale(rect.size(), aspectRatioMode);
    }
    displayRect = QRectF(QPointF(0, 0), videoSize);
    displayRect.moveCenter(rect.center());
    boundingRect = displayRect.intersected(rect);
}
コード例 #19
0
ファイル: imageview.cpp プロジェクト: MzHub/cefabs
void ImageView::paint(QPainter &p, const QSizeF& sz, double zoom, const QPointF& origin) {
    if (!imageSize().isEmpty()) {
        QTransform tr = viewTransform(sz, zoom, origin);
        QTransform invTr = tr.inverted();
        QRectF wR = invTr.mapRect(QRectF(QPoint(0,0), sz));
        QRectF R = wR.intersected(QRectF(QPoint(0,0), imageSize()));
        if (!R.isEmpty()) {
            p.save();
            p.setTransform(tr, true);
            if (m_handler) {
                m_handler->draw(this, p, R, image());
            } else {
                draw(p, R, image());
            }
            p.restore();
        }
    }
}
コード例 #20
0
void VarianceFilter::execute()
{
    const cv::Mat source = mIn;
    cv::Mat image = source;
    if(mRoiIn.hasValue())
    {
        cv::Size size = image.size();
        QRectF imageRect(0,0, size.width, size.height);
        QRectF roi = mRoiIn;
        roi = roi.intersected(imageRect);
        if(roi.isValid())
            image = image(port::Rect::rect(roi));
    }
    cv::Scalar mean, stdDev;
    cv::meanStdDev(image,mean, stdDev);
    double variance = stdDev.val[0]*stdDev.val[0];
    mVarianceOut.send(variance);
    mMeanOut.send(mean[0]);
}
コード例 #21
0
ファイル: PlotGraph.cpp プロジェクト: vultor33/Bacterial
void PlotGraph::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::white);
    painter->setOpacity(0.7);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);

    painter->setPen(QPen(Qt::black, 3));
    painter->drawLine(QPointF(sceneX + 30, sceneY + 30), QPointF(sceneX + 30, sceneY + sceneHeigth - 30));
    painter->drawLine(QPointF(sceneX + 20, sceneY + sceneHeigth - 80), QPointF(sceneX + sceneWidth - 30, sceneY + sceneHeigth - 80));


    painter->setPen(QPen(Qt::blue, 3));
    painter->drawEllipse(QPointF(sceneX+50,sceneY+30),5,5);
    painter->setPen(QPen(Qt::darkGreen, 3));
    painter->drawEllipse(QPointF(sceneX+50,sceneY+50),5,5);
    painter->setPen(QPen(Qt::darkRed, 3));
    painter->drawEllipse(QPointF(sceneX+50,sceneY+70),5,5);
    painter->setPen(QPen(Qt::darkGray, 3));
    painter->drawEllipse(QPointF(sceneX+50,sceneY+90),5,5);

    QGraphicsTextItem *text1 = this->scene()->addText("Alimento");
    QGraphicsTextItem *text2 = this->scene()->addText("Reagente");
    QGraphicsTextItem *text3 = this->scene()->addText("Metabolito");
    QGraphicsTextItem *text4 = this->scene()->addText("Residuo");
    text1->setPos(sceneX+60,sceneY+20);
    text2->setPos(sceneX+60,sceneY+40);
    text3->setPos(sceneX+60,sceneY+60);
    text4->setPos(sceneX+60,sceneY+80);


}
コード例 #22
0
ファイル: graphwidget.cpp プロジェクト: kuroyuki/QTNodes
void GraphWidget::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
        painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
        painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::lightGray);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);
}
コード例 #23
0
//! [6]
void Graph_GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
{
    Q_UNUSED(rect);

    // Shadow
    QRectF sceneRect = this->sceneRect();
    QRectF rightShadow(sceneRect.right(), sceneRect.top() + 5, 5, sceneRect.height());
    QRectF bottomShadow(sceneRect.left() + 5, sceneRect.bottom(), sceneRect.width(), 5);
    if (rightShadow.intersects(rect) || rightShadow.contains(rect))
        painter->fillRect(rightShadow, Qt::darkGray);
    if (bottomShadow.intersects(rect) || bottomShadow.contains(rect))
        painter->fillRect(bottomShadow, Qt::darkGray);

    // Fill
    QLinearGradient gradient(sceneRect.topLeft(), sceneRect.bottomRight());
    gradient.setColorAt(0, Qt::white);
    gradient.setColorAt(1, Qt::lightGray);
    painter->fillRect(rect.intersected(sceneRect), gradient);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(sceneRect);

    // Text
    QRectF textRect(sceneRect.left() + 4, sceneRect.top() + 4,
                    sceneRect.width() - 4, sceneRect.height() - 4);
//    QString message(tr("Click and drag the nodes around, and zoom with the mouse "
//                       "wheel or the '+' and '-' keys"));

    QFont font = painter->font();
    font.setBold(true);
    font.setPointSize(14);
    painter->setFont(font);
    painter->setPen(Qt::lightGray);
    painter->drawText(textRect.translated(2, 2), message);
    painter->setPen(Qt::black);
    painter->drawText(textRect, message);
}
コード例 #24
0
ファイル: EnlightedItems.cpp プロジェクト: Hakiko/GameEngine
std::unique_ptr<SceneGraph::Node> EnlightedItems::synchronize(
    std::unique_ptr<SceneGraph::Node> root) {
  if (!root) root = std::make_unique<Node>();

  Node* node = static_cast<Node*>(root.get());
  while (node->firstChild()) node->removeChild(node->firstChild());

  if (m_state & Reset) {
    m_state &= ~Reset;
    node->clear();
  }

  while (!m_destroyedFixture.empty()) {
    node->destroyedFixture(m_destroyedFixture.back());
    m_destroyedFixture.pop_back();
  }

  uint it = 0;
  QRectF visibleArea = world()->visibleRect();
  for (StaticLight* light : lightSystem()->visibleLights()) {
    if (!light->dynamicLight()) continue;

    QRectF lightRect = light->matrix().mapRect(light->boundingRect());
    QRectF rect = visibleArea.intersected(lightRect);
    for (QFixture* f : world()->fixtures(rect)) {
      if (f->shadowCaster()) {
        EnlightedNode* enlightedNode = node->getNode(f, light, it++);
        node->appendChild(enlightedNode);
      }
    }
  }

  update();

  return root;
}
コード例 #25
0
//! [55]
QScriptValue rectifier(QScriptContext *ctx, QScriptEngine *eng)
{
    QRectF magicRect = qscriptvalue_cast<QRectF>(ctx->callee().data());
    QRectF sourceRect = qscriptvalue_cast<QRectF>(ctx->argument(0));
    return eng->toScriptValue(sourceRect.intersected(magicRect));
}
コード例 #26
0
void FrequencyPlotView::drawBackground(QPainter* painter, const QRectF& drawRect)
{
	painter->setRenderHint(QPainter::Antialiasing, false);

	QRectF rect = drawRect;
	if (!sceneRect().contains(rect))
	{
		rect = rect.intersected(sceneRect());
		painter->setClipRect(rect);
	}

	FrequencyPlotScene* s = scene();
	QPointF topLeft = mapToScene(0, 0);
	QPointF bottomRight = mapToScene(viewport()->width(), viewport()->height());
	double dbStep = abs(s->yToDb(0) - s->yToDb(30));

	double dbBase = pow(10, floor(log10(dbStep)));
	if (dbStep >= 5 * dbBase)
		dbStep = 5 * dbBase;
	else if (dbStep >= 2 * dbBase)
		dbStep = 2 * dbBase;
	else
		dbStep = dbBase;

	double fromDb = floor(s->yToDb(rect.top() + rect.height()) / dbStep) * dbStep;
	double toDb = ceil(s->yToDb(rect.top()) / dbStep) * dbStep;

	painter->setPen(QColor(200, 200, 200));
	for (double db = fromDb; db <= toDb; db += dbStep)
	{
		double y = floor(s->dbToY(db)) + 0.5;
		if (y != -1)
			painter->drawLine(topLeft.x(), y, bottomRight.x(), y);
	}

	double fromHz = s->xToHz(rect.left());
	double toHz = s->xToHz(rect.left() + rect.width());

	const vector<double>& bands = s->getBands();
	if (bands.empty())
	{
		double hzBase = pow(10, floor(log10(fromHz)));
		fromHz = floor(fromHz / hzBase) * hzBase;
		fromHz += hzBase;
		if (round(fromHz / hzBase) >= 10)
			hzBase *= 10;
		for (double hz = fromHz; hz <= toHz;)
		{
			double x = floor(s->hzToX(hz)) + 0.5;
			if (x >= 0)
				painter->drawLine(x, topLeft.y(), x, bottomRight.y());

			hz += hzBase;
			if (round(hz / hzBase) >= 10)
				hzBase *= 10;
		}
	}
	else
	{
		vector<double>::const_iterator it = lower_bound(bands.cbegin(), bands.cend(), fromHz);
		for (; it != bands.cend() && *it < toHz; it++)
		{
			double hz = *it;
			double x = floor(s->hzToX(hz)) + 0.5;
			if (x >= 0)
				painter->drawLine(x, topLeft.y(), x, bottomRight.y());
		}
	}
}
コード例 #27
0
ファイル: pianoview.cpp プロジェクト: trig-ger/MuseScore
void PianoView::drawBackground(QPainter* p, const QRectF& r)
      {
      if (staff == 0)
            return;
      Score* _score = staff->score();
      setFrameShape(QFrame::NoFrame);

      QRectF r1;
      r1.setCoords(-1000000.0, 0.0, 480.0, 1000000.0);
      QRectF r2;
      r2.setCoords(ticks + MAP_OFFSET, 0.0, 1000000.0, 1000000.0);
      QColor bg(0x71, 0x8d, 0xbe);

      p->fillRect(r, bg);
      if (r.intersects(r1))
            p->fillRect(r.intersected(r1), bg.darker(150));
      if (r.intersects(r2))
            p->fillRect(r.intersected(r2), bg.darker(150));

      //
      // draw horizontal grid lines
      //
      qreal y1 = r.y();
      qreal y2 = y1 + r.height();
      qreal kh = 13.0;
      qreal x1 = r.x();
      qreal x2 = x1 + r.width();

      // int key = floor(y1 / 75);
      int key = floor(y1 / kh);
      qreal y = key * kh;

      for (; key < 75; ++key, y += kh) {
            if (y < y1)
                  continue;
            if (y > y2)
                  break;
            p->setPen(QPen((key % 7) == 5 ? Qt::lightGray : Qt::gray));
            p->drawLine(QLineF(x1, y, x2, y));
            }

      //
      // draw vertical grid lines
      //
      static const int mag[7] = {
            1, 1, 2, 5, 10, 20, 50
            };

      Pos pos1 = pix2pos(x1);
      Pos pos2 = pix2pos(x2);

      //---------------------------------------------------
      //    draw raster
      //---------------------------------------------------

      int bar1, bar2, beat, tick;
      pos1.mbt(&bar1, &beat, &tick);
      pos2.mbt(&bar2, &beat, &tick);

      int n = mag[magStep < 0 ? 0 : magStep];

      bar1 = (bar1 / n) * n;           // round down
      if (bar1 && n >= 2)
            bar1 -= 1;
      bar2 = ((bar2 + n - 1) / n) * n; // round up

      for (int bar = bar1; bar <= bar2;) {
            Pos stick(_score->tempomap(), _score->sigmap(), bar, 0, 0);
            if (magStep > 0) {
                  double x = double(pos2pix(stick));
                  if (x > 0) {
                        p->setPen(QPen(Qt::lightGray, 0.0));
                        p->drawLine(x, y1, x, y2);
                        }
                  else {
                        p->setPen(QPen(Qt::black, 0.0));
                        p->drawLine(x, y1, x, y1);
                        }
                  }
            else {
                  int z = stick.timesig().timesig().numerator();
                  for (int beat = 0; beat < z; beat++) {
                        if (magStep == 0) {
                              Pos xx(_score->tempomap(), _score->sigmap(), bar, beat, 0);
                              int xp = pos2pix(xx);
                              if (xp < 0)
                                    continue;
                              if (xp > 0) {
                                    p->setPen(QPen(beat == 0 ? Qt::lightGray : Qt::gray, 0.0));
                                    p->drawLine(xp, y1, xp, y2);
                                    }
                              else {
                                    p->setPen(QPen(Qt::black, 0.0));
                                    p->drawLine(xp, y1, xp, y2);
                                    }
                              }
                        else {
                              int k;
                              if (magStep == -1)
                                    k = 2;
                              else if (magStep == -2)
                                    k = 4;
                              else if (magStep == -3)
                                    k = 8;
                              else if (magStep == -4)
                                    k = 16;
                              else
                                    k = 32;

                              int n = (MScore::division * 4) / stick.timesig().timesig().denominator();
                              for (int i = 0; i < k; ++i) {
                                    Pos xx(_score->tempomap(), _score->sigmap(), bar, beat, (n * i)/ k);
                                    int xp = pos2pix(xx);
                                    if (xp < 0)
                                          continue;
                                    if (xp > 0) {
                                          p->setPen(QPen(i == 0 && beat == 0 ? Qt::lightGray : Qt::gray, 0.0));
                                          p->drawLine(xp, y1, xp, y2);
                                          }
                                    else {
                                          p->setPen(QPen(Qt::black, 0.0));
                                          p->drawLine(xp, y1, xp, y2);
                                          }
                                    }
                              }
                        }
                  }
            if (bar == 0 && n >= 2)
                  bar += (n-1);
            else
                  bar += n;
            }
      }
コード例 #28
0
ファイル: GLWindow.cpp プロジェクト: TACC/DisplayCluster
bool GLWindow::setPerspectiveView(double x, double y, double w, double h)
{
    // we want a perspective view for an area over the entire display bounded by (x,y,w,h)
    // this windows area is produced by intersection((left_,right_,bottom_,top_), (x,y,w,h))
    // in the current coordinate system, bottom is at the top of the screen, top at the bottom...
    QRectF screenRect = QRectF(left_, bottom_, right_-left_, top_-bottom_);
    QRectF windowRect = QRectF(x, y, w, h);
    QRectF boundRect = screenRect.intersected(windowRect);

    // if bounding rectangle is empty, return false to indicate no rendering should be done
    if(boundRect.isEmpty() == true)
    {
        return false;
    }

    if(boundRect != screenRect)
    {
        // x,y for viewport is lower-left corner
        // the y coordinate needs to be shifted from the top of the screen to the bottom, and y-direction inverted
        int viewPortX = (int)((boundRect.x() - screenRect.x()) / screenRect.width() * width());
        int viewPortY = (int)((screenRect.height() - (boundRect.y() + boundRect.height() - screenRect.y())) / screenRect.height() * height());
        int viewPortW = (int)(boundRect.width() / screenRect.width() * width());
        int viewPortH = (int)(boundRect.height() / screenRect.height() * height());

        glViewport(viewPortX, viewPortY, viewPortW, viewPortH);
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    double near = 0.001;
    double far = 100.;

    double aspect = (double)g_configuration->getTotalHeight() / (double)g_configuration->getTotalWidth() * windowRect.height() / windowRect.width();

    double winFovY = 45.0 * aspect;

    double top = tan(0.5 * winFovY * M_PI/180.) * near;
    double bottom = -top;
    double left = 1./aspect * bottom;
    double right = 1./aspect * top;

    // this window's portion of the entire view above is bounded by (left_, right_) and (bottom_, top_)
    // the full frustum would be for this screen:
    // glFrustum(left + left_ * (right-left), left + right_ * (right-left), top + top_ * (bottom-top), top + bottom_ * (bottom-top), near, far);
    double fLeft = left + (boundRect.x() - windowRect.x()) / windowRect.width() * (right-left);
    double fRight = fLeft + boundRect.width() / windowRect.width() * (right-left);
    double fBottom = top + (boundRect.y() - windowRect.y()) / windowRect.height() * (bottom-top);
    double fTop = fBottom + boundRect.height() / windowRect.height() * (bottom-top);

    glFrustum(fLeft, fRight, fTop, fBottom, near, far);

    glPushMatrix();

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // don't clear the GL_COLOR_BUFFER_BIT since this may be an overlay. only clear depth
    glClear(GL_DEPTH_BUFFER_BIT);

    // new lookat matrix
    glLoadIdentity();

    gluLookAt(0,0,1, 0,0,0, 0,1,0);

    // setup lighting
    GLfloat LightAmbient[] = { 0.01, 0.01, 0.01, 1.0 };
    GLfloat LightDiffuse[] = { .5, .5, .5, 1.0 };
    GLfloat LightSpecular[] = { .9,.9,.9, 1.0 };

    GLfloat LightPosition[] = { 0,0,1000000, 1.0 };

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LightAmbient);
    glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1);

    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
    glLightfv(GL_LIGHT1, GL_SPECULAR, LightSpecular);
    glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);

    glEnable(GL_LIGHT1);

    // glEnable(GL_LIGHTING) needs to be called to actually use lighting. ditto for depth testing.
    // let other code enable / disable such settings so glPushAttrib() and glPopAttrib() can be used appropriately

    return true;
}