Exemplo n.º 1
0
void FadeMessage::setupScene()
{
    QGraphicsRectItem *parent = m_scene.addRect(0, 0, 800, 600);
    parent->setPen(Qt::NoPen);
    parent->setZValue(0);

    QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/background.jpg"));
    bg->setParentItem(parent);
    bg->setZValue(-1);

    for (int i = 1; i < 5; ++i)
        for (int j = 2; j < 5; ++j) {
            QGraphicsRectItem *item = m_scene.addRect(i * 50, (j - 1) * 50, 38, 38);
            item->setParentItem(parent);
            item->setZValue(1);
            int hue = 12 * (i * 5 + j);
            item->setBrush(QColor::fromHsv(hue, 128, 128));
        }

    QFont font;
    font.setPointSize(font.pointSize() * 2);
    font.setBold(true);
    QFontMetrics fontMetrics(font);
    int fh = fontMetrics.height();

    QString sceneText = "Qt Everywhere!";
    int sceneTextWidth = fontMetrics.width(sceneText);

    QGraphicsRectItem *block = m_scene.addRect(50, 300, sceneTextWidth, fh + 3);
    block->setPen(Qt::NoPen);
    block->setBrush(QColor(102, 153, 51));

    QGraphicsTextItem *text = m_scene.addText(sceneText, font);
    text->setDefaultTextColor(Qt::white);
    text->setPos(50, 300);
    block->setZValue(2);
    block->hide();

    text->setParentItem(block);
    m_message = block;

    m_effect = new QGraphicsColorizeEffect;
    m_effect->setColor(QColor(122, 193, 66));
    m_effect->setStrength(0);
    m_effect->setEnabled(true);
    parent->setGraphicsEffect(m_effect);

    QPushButton *press = new QPushButton;
    press->setText(tr("Press me"));
    connect(press, SIGNAL(clicked()), SLOT(togglePopup()));
    m_scene.addWidget(press);

#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
    press->move(200, 210);
#else
    press->move(300, 500);
#endif
}
Exemplo n.º 2
0
void
ConfigurationSpaceScene::eval()
{
	this->thread->stop();
	
	this->clear();
	
	rl::math::Vector maximum(this->model->getDof());
	this->model->getMaximum(maximum);
	rl::math::Vector minimum(this->model->getDof());
	this->model->getMinimum(minimum);
	
	QGraphicsRectItem* rect = this->addRect(
		minimum(this->x),
		-maximum(this->y),
		std::abs(maximum(this->x) - minimum(this->x)),
		std::abs(maximum(this->y) - minimum(this->y)),
		QPen(Qt::NoPen),
		QBrush(Qt::white)
	);
	
	rect->setZValue(0);
	
	this->thread->delta = this->delta;
	this->thread->model = this->model;
	this->thread->x = this->x;
	this->thread->y = this->y;
	
	this->thread->start();
}
Exemplo n.º 3
0
PoseMeshScene::PoseMeshScene(QObject *parent)
: QGraphicsScene(parent)
{    
   double graphicsWidth  = 512;
   double graphicsHeight = 1024;   

   // This rectangle will be a visual representation 
   // of the bounds that the map can be dragged in  
   mCanvasRect.setLeft(0);
   mCanvasRect.setTop(0);
   mCanvasRect.setWidth(graphicsWidth);
   mCanvasRect.setHeight(graphicsHeight);   

   mVerticalMeshOffset = mCanvasRect.y() + 64;

   QBrush canvasBrush(QColor(192, 192, 255));

   QGraphicsRectItem *canvasItem = addRect(mCanvasRect, QPen(), canvasBrush);  
   canvasItem->setZValue(-100.0f);
   canvasItem->setEnabled(false);

   QBrush backgroundBrush(QPixmap(":/images/checker.png"));  
   setBackgroundBrush(backgroundBrush);

   CreateTest();
}
Exemplo n.º 4
0
void DivePictureItem::setPixmap(const QPixmap &pix)
{
	DivePixmapItem::setPixmap(pix);
	QRectF r = boundingRect();
	QGraphicsRectItem *rect = new QGraphicsRectItem(0 - 10, 0 -10, r.width() + 20, r.height() + 20, this);
	rect->setPen(Qt::NoPen);
	rect->setBrush(QColor(Qt::white));
	rect->setFlag(ItemStacksBehindParent);
	rect->setZValue(-1);

	QGraphicsRectItem *shadow = new QGraphicsRectItem(rect->boundingRect(), this);
	shadow->setPos(5,5);
	shadow->setPen(Qt::NoPen);
	shadow->setBrush(QColor(Qt::lightGray));
	shadow->setFlag(ItemStacksBehindParent);
	shadow->setZValue(-2);
}
Exemplo n.º 5
0
void MemoryTracePane::addStackFrame(int numCells)
{
    QPen pen(Qt::black);
    pen.setWidth(4);
    QGraphicsRectItem *item = new QGraphicsRectItem(stackLocation.x() - 2, stackLocation.y() + MemoryCellGraphicsItem::boxHeight, 
                      static_cast<qreal>(MemoryCellGraphicsItem::boxWidth + 4),
                      static_cast<qreal>(MemoryCellGraphicsItem::boxHeight * numCells), 0);
    item->setPen(pen);
    graphicItemsInStackFrame.push(item);
    isStackFrameAddedStack.push(false);
    item->setZValue(1.0); // This moves the stack frame to the front
    numCellsInStackFrame.push(numCells);
}
Exemplo n.º 6
0
void MemoryTracePane::addHeapFrame(int numCells)
{
    QPen pen(Qt::black);
    pen.setWidth(4);
    QGraphicsRectItem *item = new QGraphicsRectItem(heapLocation.x() - 2,
                                                    heapLocation.y() - MemoryCellGraphicsItem::boxHeight * (numCells - 1),
                      static_cast<qreal>(MemoryCellGraphicsItem::boxWidth + 4),
                      static_cast<qreal>(MemoryCellGraphicsItem::boxHeight * numCells), 0);
    item->setPen(pen);
    heapFrameItemStack.push(item);
    isHeapFrameAddedStack.push(false);
    item->setZValue(1.0); // This moves the heap frame to the front
}
Exemplo n.º 7
0
void TerrainProfileGraph::drawSelectionBox(double position)
{
  if (_selecting && _selectStart != position)
  {
    double selectionMin = osg::minimum(_selectStart, position);
    double selectionMax = osg::maximum(_selectStart, position);
    QGraphicsRectItem* selectionBox = new QGraphicsRectItem(selectionMin, _graphField.y(), selectionMax - selectionMin, _graphField.height());
    selectionBox->setPen(QPen(Qt::NoPen));
    selectionBox->setBrush(QBrush(QColor(0, 0, 0, 64)));
    selectionBox->setZValue(OVERLAY_Z);
    selectionBox->setParentItem(_hoverLine);
  }
}
Exemplo n.º 8
0
void
ConfigurationSpaceScene::addCollision(const qreal& x, const qreal& y, const qreal& w, const qreal& h, const int& rgb)
{
	QGraphicsRectItem* rect = this->addRect(
		x - w / 2.0f,
		-y - h / 2.0f,
		w,
		h,
		QPen(Qt::NoPen),
		QBrush(QColor(rgb, rgb, rgb))
	);
	
	rect->setZValue(1);
}
void
ConfigurationSpaceScene::addCollision(const qreal& x, const qreal& y, const qreal& w, const qreal& h, const int& rgb)
{
	QGraphicsRectItem* rect = this->addRect(
		x - w * static_cast<qreal>(0.5),
		-y - h * static_cast<qreal>(0.5),
		w,
		h,
		QPen(Qt::NoPen),
		QBrush(QColor(rgb, rgb, rgb))
	);
	
	rect->setParentItem(this->scene);
	rect->setZValue(1);
}
Exemplo n.º 10
0
PortGraphicsItem::PortGraphicsItem(QPointF position,
                                   DocumentEntry* relatedEntry,
                                   model::enums::PortDirection direction)
    : SchematicElement(position, relatedEntry) {
    // Ports are measured from the center, not the upper left corner

    QAbstractGraphicsShapeItem* newActual;

    m_direction = direction;
    // select the Pen and Brush based on the Port direction
    switch (direction) {
    case model::enums::PortDirection::IN:
        newActual = factories::GIFactory::createPortAdapterGI();
        this->m_defaultPen = PEN_INPUT_PORT;
        this->m_defaultBrush = BRUSH_INPUT_PORT;
        this->setAcceptDrops(true); // input ports can receive wire drops
        this->setAcceptedMouseButtons(0); // no way to click that
        break;
    case model::enums::PortDirection::OUT:
        newActual = factories::GIFactory::createPortAdapteeGI();
        this->m_defaultPen = PEN_OUTPUT_PORT;
        this->m_defaultBrush = BRUSH_OUTPUT_PORT;
        this->setAcceptedMouseButtons(Qt::LeftButton); // output ports can be dragged from
        break;
    default:
        newActual = factories::GIFactory::createPortInvalidGI();
        this->m_defaultPen = PEN_UNDEFINED_PORT;
        this->m_defaultBrush = BRUSH_UNDEFINED_PORT;
        break;
    }
    Q_CHECK_PTR(newActual);

    newActual->setPen(this->m_defaultPen);
    newActual->setBrush(this->m_defaultBrush);
    this->addActual(newActual);

    qreal r = (qreal)PORT_RADIUS;
    QGraphicsRectItem* background = new QGraphicsRectItem(-r, -r, 2 * r, 2 * r, this);
    background->setBrush(PORT_BACKGROUND_BRUSH);
    background->setPen(PORT_BACKGROUND_PEN);
    background->setZValue(-2);
    this->addActual(background);

    Q_ASSERT(this->actual()->isVisible());
    this->setAcceptHoverEvents(true);
}
Exemplo n.º 11
0
void TutorialDlg::createSceneAndView ()
{
  LOG4CPP_INFO_S ((*mainCat)) << "TutorialDlg::createSceneAndView";

  m_scene = new QGraphicsScene (this);

  m_view = new QGraphicsView (m_scene, this);
  m_view->setMouseTracking (true);
  layout ()->addWidget(m_view);

  // Spacer is used to ensure view is the desired size. Directly setting the size of the view
  // is ineffective since the view then get resized to the smallest rectangle fitting the added items
  QGraphicsRectItem *spacer = new QGraphicsRectItem (0,
                                                     0,
                                                     backgroundSize().width (),
                                                     backgroundSize().height ());
  spacer->setBrush (QBrush (Qt::NoBrush));
  spacer->setPen (QPen (Qt::NoPen));
  spacer->setZValue(-1); // Put behind everything else at the default z of zero
  m_scene->addItem (spacer);
}
Exemplo n.º 12
0
void TerrainProfileGraph::drawHoverCursor(const QPointF& position)
{
  if (_hoverLine)
  {
    _scene->removeItem(_hoverLine);
    delete _hoverLine;
    _hoverLine = 0L;
  }

  if (_graphField.width() < 2 || _graphField.height() < 2)
    return;

  double xPos = position.x() < _graphField.x() ? _graphField.x() : (position.x() > _graphField.x() + _graphField.width() ? _graphField.x() + _graphField.width() : position.x());

  QLineF vLine(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height());

  QPointF* intersect = new QPointF;
  bool foundIntersect = false;
  for (int i=0; i < _graphLines.count(); i++)
  {
    if (vLine.intersect(_graphLines[i], intersect) == QLineF::BoundedIntersection)
    {
      foundIntersect = true;
      break;
    }
  }

  if (foundIntersect)
  {
    // Draw the upper line segment.  Also serves as the parent item.
    _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, intersect->y() - 3);
    _hoverLine->setPen(_hoverPen);
    _hoverLine->setZValue(OVERLAY_Z);
    _scene->addItem(_hoverLine);

    // Draw the box around the intersect point
    QGraphicsRectItem* hoverBox = new QGraphicsRectItem(xPos - 3, intersect->y() - 3, 6, 6);
    hoverBox->setPen(_hoverPen);
    hoverBox->setBrush(Qt::NoBrush);
    hoverBox->setZValue(OVERLAY_Z);
    hoverBox->setParentItem(_hoverLine);

    // Draw the lower line segment
    QGraphicsLineItem* lowerLine = new QGraphicsLineItem(xPos, intersect->y() + 3, xPos, _graphField.y() + _graphField.height() + 5);
    lowerLine->setPen(_hoverPen);
    lowerLine->setZValue(OVERLAY_Z);
    lowerLine->setParentItem(_hoverLine);

    // Draw the text and background
    double y = (1.0 - ((intersect->y() - _graphField.y()) / _graphField.height())) * (_graphMaxY - _graphMinY) + _graphMinY;
    int textOffset = 10;

    QGraphicsSimpleTextItem* hoverText = new QGraphicsSimpleTextItem(QString::number(y) + tr("m"));
    hoverText->setBrush(QBrush(_axesColor));
    hoverText->setFont(_graphFont);
    hoverText->setZValue(OVERLAY_Z);

    if (intersect->x() + textOffset + hoverText->boundingRect().width() < _graphField.x() + _graphField.width())
      hoverText->setPos(intersect->x() + textOffset, intersect->y() - hoverText->boundingRect().height());
    else
      hoverText->setPos(intersect->x() - textOffset - hoverText->boundingRect().width(), intersect->y() - hoverText->boundingRect().height());

    QGraphicsRectItem* hoverTextBackground = new QGraphicsRectItem(hoverText->x() - 3, hoverText->y() - 1, 
                                                                   hoverText->boundingRect().width() + 6,
                                                                   hoverText->boundingRect().height() + 1);
    hoverTextBackground->setPen(_axesPen);
    hoverTextBackground->setBrush(QBrush(_graphColor));
    hoverTextBackground->setZValue(OVERLAY_Z);
    hoverTextBackground->setParentItem(_hoverLine);

    hoverText->setParentItem(_hoverLine);

    // Update callback
    if (_positionCallback.valid())
    {
      double distanceFactor = ((xPos - _graphField.x()) / (double)_graphField.width());

      osg::Vec3d worldStart, worldEnd;
      _calculator->getStart(ALTMODE_ABSOLUTE).toWorld(worldStart);
      _calculator->getEnd(ALTMODE_ABSOLUTE).toWorld(worldEnd);

      double worldX = (worldEnd.x() - worldStart.x()) * distanceFactor + worldStart.x();
      double worldY = (worldEnd.y() - worldStart.y()) * distanceFactor + worldStart.y();
      double worldZ = (worldEnd.z() - worldStart.z()) * distanceFactor + worldStart.z();

      GeoPoint mapPos;
      mapPos.fromWorld(_calculator->getStart().getSRS(), osg::Vec3d(worldX, worldY, worldZ));

      _positionCallback->updatePosition(mapPos.y(), mapPos.x(), hoverText->text().toStdString());
    }
  }
  else
  {
    // No intersect found so just draw the full line at xPos
    _hoverLine = new QGraphicsLineItem(xPos, _graphField.y(), xPos, _graphField.y() + _graphField.height() + 5);
    _hoverLine->setPen(_hoverPen);
    _hoverLine->setZValue(OVERLAY_Z);
    _scene->addItem(_hoverLine);
  }

  // Draw distance text
  double x = ((xPos - _graphField.x()) / _graphField.width()) * _totalDistance;

  BoxedSimpleTextItem* distanceText = new BoxedSimpleTextItem(QString::number(x / 1000.0, 'f', 2) + tr("km"), _backgroundColor);
  distanceText->setBrush(QBrush(_axesColor));
  distanceText->setFont(_graphFont);
  distanceText->setZValue(OVERLAY_Z);
  if(xPos - 2 - distanceText->boundingRect().width() > _graphField.x())
  {
      distanceText->setPos(xPos - 2 - distanceText->boundingRect().width(), _graphField.y() + _graphField.height() + 2);
  }
  else
  {
      distanceText->setPos(xPos + 2, _graphField.y() + _graphField.height() + 2);
  }
  distanceText->setParentItem(_hoverLine);

  // Draw selection box
  drawSelectionBox(xPos);

  delete intersect;
}
Exemplo n.º 13
0
TlinearChart::TlinearChart(Texam* exam, Tchart::Tsettings& settings, QWidget* parent) :
    TmainChart(exam, settings, parent)
{
// Determine y value type and its maximal value to prepare Y axis
  switch (settings.yValue) {
    case TmainLine::e_prepareTime: {
      quint32 prepTime = 0;
      for(int i = 0; i < exam->count(); i++)
        prepTime = qMax(prepTime, exam->question(i)->attempt(0)->prepareTime());
      yAxis->setMaxValue((qreal)prepTime / 10.0);
      yAxis->setUnit(TYaxis::e_prepareTime);
      break;
    }
    case TmainLine::e_attemptsCount: {
      int attemptsNr = 0;
      for(int i = 0; i < exam->count(); i++)
        attemptsNr = qMax(attemptsNr, exam->question(i)->attemptsCount());
      yAxis->setMaxValue(attemptsNr, false);
      yAxis->setUnit(TYaxis::e_attemptsCount);
      break;
    }
    case TmainLine::e_playedCount: {
      int playedNr = 0;
      for(int i = 0; i < exam->count(); i++)
        playedNr = qMax(playedNr, exam->question(i)->totalPlayBacks());
      yAxis->setMaxValue(playedNr, false);
      yAxis->setUnit(TYaxis::e_playedCount);
      break;
    }
    case TmainLine::e_effectiveness: {
      yAxis->setMaxValue(100.0); // 100% looks good for this kind
      yAxis->setUnit(TYaxis::e_effectiveness);
      break;
    }
    default: {
      quint16 maxTime = 0;
      for(int i = 0; i < exam->count(); i++)
        maxTime = qMax(maxTime, exam->question(i)->time);
      yAxis->setMaxValue((qreal)maxTime / 10.0);
      break;
    }
  }
  
	if (settings.order == e_byNumber) {
		xAxis->setAnswersList(currExam->answList(), currExam->level());
		prepareChart(currExam->count());
		m_mainLine = new TmainLine(currExam->answList(), this, settings.yValue);
		if (settings.yValue == TmainLine::e_questionTime) {
			qreal aTime = 0 , prev = 0;
			int firstCorrect = 0, okCount = 0;
			for(int i = 0; i < exam->count(); i++) { // looking for first correct answer
				if (!exam->question(i)->isWrong() || (!exam->question(i)->isWrong() && settings.inclWrongAnsw)) {
					firstCorrect = i;
					prev = exam->question(i)->time;
					okCount++;
					aTime = prev;
					break;
				}
			}
      int prevX = firstCorrect + 1;
      for(int i = firstCorrect + 1; i < exam->count(); i++) {
        if (exam->question(i)->isWrong())
          continue; // skip wrong answers in aver time
        else 
          aTime = (aTime * okCount + (exam->question(i)->time)) / (okCount + 1);
        
        okCount++;
        TgraphicsLine *averProgress = new TgraphicsLine();
        scene->addItem(averProgress);
        averProgress->setPen(QPen(averColor.darker(120), 3, Qt::DotLine));
        averProgress->setLine(xAxis->mapValue(prevX) + xAxis->pos().x(), yAxis->mapValue(prev / 10.0),
                              xAxis->mapValue(i + 1) + xAxis->pos().x(), yAxis->mapValue(aTime / 10.0));
        prevX = i + 1;
        averProgress->setZValue(20);
        prev = aTime;
      }
      
      if (exam->averageReactonTime() > 0) {
          TgraphicsLine *averLine = new TgraphicsLine(0, "<p>" +
              TexTrans::averAnsverTimeTxt() + 
              QString("<br><big><b>%1</b></big></p>").arg(Texam::formatReactTime(exam->averageReactonTime(), true)) );
          scene->addItem(averLine);
          averLine->setZValue(15);
          averLine->setPen(QPen(averColor, 2));
          averLine->setLine(xAxis->mapValue(1) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0),
              xAxis->mapValue(exam->count()) + xAxis->pos().x(), yAxis->mapValue(exam->averageReactonTime() / 10.0));
      }
  // rest of cases are available only for melodies
		}
  }
  
  if (settings.order == e_byNote || settings.order == e_byFret ||
          settings.order == e_byKey || settings.order == e_byAccid || 
          settings.order == e_byQuestAndAnsw || settings.order == e_byMistake) {
      sort();
      xAxis->setAnswersLists(sortedLists, exam->level());
      int ln = 0;
      for (int i = 0; i < sortedLists.size(); i++)
        ln += sortedLists[i].size();
      prepareChart(ln);
      m_mainLine = new TmainLine(sortedLists, this, settings.yValue);
      
      int goodOffset = 0; // 0 when not unrelated question list inside
      if (hasListUnrelated)
        goodOffset = -1; // do not perform a last loop 
      int cnt = 1;
      if (settings.yValue != TmainLine::e_questionTime) {
        QTimer::singleShot(10, this, SLOT(ajustChartHeight()));
        return;
      }
  // paint lines with average time of all the same notes/frets
     for (int i = 0; i < goodSize + goodOffset; i++) { // skip wrong answers if separated
        if (sortedLists[i].size() > 1) {
        TgraphicsLine *averTimeLine = new TgraphicsLine(&sortedLists[i]);

        averTimeLine->setText(sortedLists[i].fullDescription());
        scene->addItem(averTimeLine);
        averTimeLine->setZValue(46);
        averTimeLine->setPen(QPen(averColor, 3)); // sea blue
        averTimeLine->setLine(xAxis->mapValue(cnt - 0.4) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0),
          xAxis->mapValue(cnt + sortedLists[i].size() -0.6) + xAxis->pos().x(), yAxis->mapValue(sortedLists[i].averTime() / 10.0));
        }
        cnt += sortedLists[i].size();
      }
      cnt = 1;
      // paint highlights under grouped items
      for (int i = 0; i < sortedLists.size(); i++) {
          QGraphicsRectItem *groupBg = new QGraphicsRectItem();
          scene->addItem(groupBg);
          QColor hiCol = palette().highlight().color();
          hiCol.setAlpha(60);
          if (i%2) {
            groupBg->setBrush(QBrush(hiCol));
            groupBg->setPen(Qt::NoPen);
            groupBg->setRect(xAxis->mapValue(cnt), 0, sortedLists[i].size() * xAxis->questWidth(), yAxis->boundingRect().height());
            groupBg->setZValue(-1);
          }
          cnt += sortedLists[i].size();
      }
  // fret number over the chart
    if (settings.order == e_byFret) {
      cnt = 1;
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *fretText = getTextItem(30);
        QString hintText = "<b>";
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type");
        else
          hintText += QString("%1").arg(TfingerPos::romanFret(sortedLists[i].first()->qa.pos.fret()));
        hintText += "</b>";
        fretText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(fretText);
				qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < fretText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / fretText->boundingRect().width();
            fretText->setScale(sc);
        }
        fretText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - fretText->boundingRect().width() * sc) / 2,
                         yAxis->mapValue(yAxis->maxValue()));        
        
        cnt += sortedLists[i].size();
      }      
    }
  // key signature names over the chart
    if (settings.order == e_byKey) {
      cnt = 1;
      QColor tc = palette().text().color();
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *keyText = getTextItem(16);
        QString hintText = "<b>";
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type");
        else {
            hintText += QString("%1").arg(sortedLists[i].first()->key.getName());
            hintText += "<br>" + getWasInAnswOrQuest(TQAtype::e_asNote, sortedLists[i].operator[](0).qaPtr);
        }
        hintText += "</b>";
        keyText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(keyText);
        qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < keyText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / keyText->boundingRect().width();
            keyText->setScale(sc);
        }
        keyText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - keyText->boundingRect().width() * sc) / 2, 
                         yAxis->mapValue(yAxis->maxValue()));        
        cnt += sortedLists[i].size();
      }
    }
// accidentals over the chart
    if (settings.order == e_byAccid) {
      cnt = 1;
      for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *accidentalText = getTextItem(30);
        QString hintText;
        if (goodOffset && (i == goodSize -1))
          hintText += QApplication::translate("TlinearChart", "questions unrelated<br>with chart type") + "</span>";
        else 
          if (kindOfAccids[i])
            hintText += QString("%1").arg(accidToNotka(kindOfAccids[i], 40));
          else
            hintText += QApplication::translate("TlinearChart", "without accidentals");
        accidentalText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(accidentalText);
        accidentalText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - accidentalText->boundingRect().width()) / 2, 
                         yAxis->mapValue(yAxis->maxValue()));        
        cnt += sortedLists[i].size();
      }      
    }
  // question/answer type over the chart
		if (settings.order == e_byQuestAndAnsw) {
			cnt = 1;
			for (int i = 0; i < goodSize; i++) { 
        QGraphicsTextItem *qaText = getTextItem(30);
				int nootFontSize = fontMetrics().boundingRect("A").height() * 2;
        QString hintText;
				if (exam->melodies()) {
					if (sortedLists[i].first()->questionAs == TQAtype::e_asNote)
						hintText = TexTrans::playMelodyTxt();
					else
						hintText = TexTrans::writeMelodyTxt();
				} else
					hintText = TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->questionAs) + "?", nootFontSize) + 
							"<br>" + TnooFont::span(TquestionAsWdg::qaTypeSymbol(sortedLists[i].first()->answerAs) + "!", nootFontSize);
        qaText->setHtml(hintText);
				TgraphicsTextTip::alignCenter(qaText);
				qreal sc = 1.0;
        if (sortedLists[i].size() * xAxis->questWidth() < qaText->boundingRect().width()) {
            sc = (sortedLists[i].size() * xAxis->questWidth()) / qaText->boundingRect().width();
            qaText->setScale(sc);
        }
        qaText->setPos(xAxis->mapValue(cnt) + 
        (sortedLists[i].size() * xAxis->questWidth() - qaText->boundingRect().width() * sc) / 2, 
                         yAxis->mapValue(0) - yAxis->length());        
        cnt += sortedLists[i].size();
      }
		}  
  }
  QTimer::singleShot(10, this, SLOT(ajustChartHeight()));
}
Exemplo n.º 14
0
QGraphicsItem*
GIFactory::createComponentGI(
    ComponentDescriptor* type) {

    qDebug() << "Generating Graphics item for" << type->text();

    // collect all the information
    QString componentName = type->text();

    QGraphicsItemGroup* parent = new QGraphicsItemGroup();

    // create all the partial items and calculate sizes

    unsigned int inSection_minWidth = 0;
    unsigned int outSection_minWidth = 0;
    unsigned int portSection_lineHeight = 0;

    QList<PortEntry> inPorts = QList<PortEntry>();
    QList<PortEntry> outPorts = QList<PortEntry>();
    for (PortDescriptor * port : type->ports()) {


        PortEntry portEntry = PortEntry(port, parent);
        unsigned int width = portEntry.textGraphics()->boundingRect().width() + 2 * TEXT_PADDING;
        unsigned int height = portEntry.textGraphics()->boundingRect().height() + 2 * TEXT_PADDING;

        // adjust the line height, if needed
        if (height > portSection_lineHeight) {
            portSection_lineHeight = height;
        }

        switch (port->direction()) {
        case model::enums::PortDirection::IN : {
            inPorts.append(portEntry);
            if (width > inSection_minWidth) {
                inSection_minWidth = width;
            }
        }
        break;

        case model::enums::PortDirection::OUT : {
            outPorts.append(portEntry);
            if (width > outSection_minWidth) {
                outSection_minWidth = width;
            }
        }
        break;
        default:
            continue; // do not handle other types.
        }

    }

    std::sort(inPorts.begin(), inPorts.end());
    std::sort(outPorts.begin(), outPorts.end());


    unsigned int portSection_height =
        inPorts.count() > outPorts.count() ?
        inPorts.count() * portSection_lineHeight :
        outPorts.count() * portSection_lineHeight;

    QGraphicsTextItem* text_compName = new QGraphicsTextItem(componentName, parent);
    parent->addToGroup(text_compName);

    unsigned int nameSection_minWidth = text_compName->boundingRect().width() + 2 * TEXT_PADDING;
    unsigned int nameSection_height = text_compName->boundingRect().height() + 2 * TEXT_PADDING;

    // adjust the total width
    unsigned int totalWidth  = 0;
    if (nameSection_minWidth > (inSection_minWidth + outSection_minWidth)) {
        totalWidth = nameSection_minWidth;
        if (inSection_minWidth > totalWidth / 2) { // extend outSection_minWidth
            outSection_minWidth = totalWidth - inSection_minWidth;
        } else if (outSection_minWidth > totalWidth / 2) { // extend inSection_minWidth
            inSection_minWidth = totalWidth - outSection_minWidth;
        } else { // stretch both to totalWidth / 2
            inSection_minWidth = totalWidth / 2;
            outSection_minWidth = totalWidth / 2;
        }
    } else { // adjust nameSection_minWidth
        totalWidth = inSection_minWidth + outSection_minWidth;
    }

    // now actually place all the stuff
    QBrush nameSectionBrush = QBrush(Qt::lightGray, Qt::SolidPattern);
    QBrush portSectionBrush = QBrush(Qt::white, Qt::SolidPattern);
    QPen pen = QPen(Qt::black, Qt::SolidLine);
    QPoint currentPos = QPoint(0, 0);

    // draw the rectangles
    QGraphicsRectItem* nameSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        totalWidth, nameSection_height, parent);
    nameSection->setBrush(nameSectionBrush);
    nameSection->setPen(pen);
    nameSection->setZValue(-1);
    parent->addToGroup(nameSection);

    currentPos.ry() += nameSection_height;
    QGraphicsRectItem* inSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        inSection_minWidth, portSection_height, parent);
    inSection->setBrush(portSectionBrush);
    inSection->setPen(pen);
    inSection->setZValue(-1);
    parent->addToGroup(inSection);

    currentPos.rx() += inSection_minWidth;
    QGraphicsRectItem* outSection = new QGraphicsRectItem(
        currentPos.x(), currentPos.y(),
        outSection_minWidth, portSection_height, parent);
    outSection->setBrush(portSectionBrush);
    outSection->setPen(pen);
    outSection->setZValue(-1);
    parent->addToGroup(outSection);

    // place the texts and set the port positions in the port descriptor
    text_compName->setPos((totalWidth - text_compName->boundingRect().width()) / 2,
                          /*0 + */ TEXT_PADDING);

    currentPos.setX(0);
    currentPos.setY(nameSection_height);
    for(PortEntry inIter : inPorts){
        inIter.textGraphics()->setPos(currentPos.x() + TEXT_PADDING, currentPos.y() + TEXT_PADDING);
        currentPos.ry() += portSection_lineHeight / 2;
        QPoint portPos = QPoint(currentPos.x() - PORT_DIAMETER, currentPos.y());
        inIter.descriptor()->setPosition(portPos);

        QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(portPos, currentPos), parent);
        parent->addToGroup(lineToPort);
        currentPos.ry() += portSection_lineHeight / 2;
    }

    currentPos.setX(totalWidth);
    currentPos.setY(nameSection_height);
   for(PortEntry outIter : outPorts){
        outIter.textGraphics()->setPos(
            currentPos.x() - TEXT_PADDING - outIter.textGraphics()->boundingRect().width(),
            currentPos.y() + TEXT_PADDING);
        currentPos.ry() += portSection_lineHeight / 2;
        QPoint portPos = QPoint(currentPos.x() + PORT_DIAMETER, currentPos.y());
        outIter.descriptor()->setPosition(portPos);

        QGraphicsLineItem* lineToPort = new QGraphicsLineItem(QLineF(currentPos, portPos), parent);
        parent->addToGroup(lineToPort);
        currentPos.ry() += portSection_lineHeight / 2;
    }

    parent->setVisible(true);
    return parent;
}
Exemplo n.º 15
0
void CanvasNavigator::updateParts()/*{{{*/
{
    m_editing = true;
    m_playhead = 0;
    m_start = 0;
    m_canvasBox =  0;
    m_punchIn = 0;
    m_punchOut = 0;
    m_parts.clear();
    m_markers.clear();
    m_scene->clear();
    /*foreach(PartItem* i, m_parts)
        m_scene->removeItem(i);
    while(m_parts.size())
        delete m_parts.takeFirst();*/
    m_heightList.clear();
    m_scene->setSceneRect(QRectF());
    int index = 1;
    //QList<QGraphicsItem*> group;
    MidiTrackList* tl = song->visibletracks();
    ciMidiTrack ci = tl->begin();
    for(; ci != tl->end(); ci++)
    {
        m_heightList.append((*ci)->height());
    }
    ci = tl->begin();
    if(ci != tl->end())
    {
        int mh = (*ci)->height();
        double partHeight = (mh * 8)/100;
        m_start = m_scene->addRect(0.0, 0.0, calcSize(song->len()), partHeight);
        m_start->setBrush(QColor(63, 63, 63));
        m_start->setPen(QPen(QColor(63, 63, 63)));
        m_start->setZValue(-50);
        ci++;//Special case for master
    }
    for(; ci != tl->end(); ci++)
    {
        MidiTrack* track = *ci;
        if(track)
        {
            QList<int> list = m_heightList.mid(0, index);
            int ypos = 0;
            foreach(int i, list)
                ypos += i;
            ypos = (ypos * 8)/100;
            int ih = m_heightList.at(index);
            double partHeight = (ih * 8)/100;

            //qDebug("CanvasNavigator::updateParts: partHeight: %2f, ypos: %d", partHeight, ypos);
            PartList* parts = track->parts();
            if(parts && !parts->empty())
            {
                for(iPart p = parts->begin(); p != parts->end(); p++)
                {
                    Part *part =  p->second;

                    int tick, len;
                    if(part)
                    {
                        tick = part->tick();
                        len = part->lenTick();
                    }
                    double w = calcSize(len);
                    double pos = calcSize(tick);

                    PartItem* item = new PartItem(pos, ypos, w, partHeight);
                    item->setPart(part);
                    m_parts.append(item);
                    //group.append((QGraphicsItem*)item);
                    int i = part->colorIndex();
                    QColor partWaveColor(config.partWaveColors[i]);
                    QColor partColor(config.partColors[i]);
                    //partWaveColor.setAlpha(150);
                    partColor.setAlpha(150);
                    item->setBrush(part->selected() ? partWaveColor : partColor);
                    item->setPen(part->selected() ? partColor : partWaveColor);
                    m_scene->addItem(item);
                }
            }
            ++index;
        }
    }
    QColor colTimeLine = QColor(0, 186, 255);
    int kpos = 0;
    foreach(int i, m_heightList)
        kpos += i;
    //kpos = ((kpos + 400) * 8)/100;
    kpos = ((kpos + 400) * 8)/100;

    m_playhead = new QGraphicsRectItem(0, 0, 1, kpos);
    m_playhead->setBrush(colTimeLine);
    m_playhead->setPen(Qt::NoPen);
    m_playhead->setZValue(124001.0f);
    m_playhead->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_playhead);
    QColor loopColor(139, 225, 69);
    QColor markerColor(243,191,124);
    MarkerList* markers = song->marker();
    for (iMarker m = markers->begin(); m != markers->end(); ++m)
    {
        //double xp = calcSize(m->second.tick());
        QGraphicsRectItem *marker = m_scene->addRect(0, 0, 1, kpos);
        marker->setData(Qt::UserRole, m->second.id());
        m_markers[m->second.id()] = marker;
        marker->setPen(Qt::NoPen);
        marker->setBrush(markerColor);
        marker->setZValue(124002.0f);
        marker->setFlags(QGraphicsItem::ItemIgnoresTransformations);
        m_updateMarkers = true;
    }

    m_punchIn = new QGraphicsRectItem(0, 0, 1, kpos);
    m_punchIn->setBrush(loopColor);
    m_punchIn->setPen(Qt::NoPen);
    m_punchIn->setZValue(124003.0f);
    m_punchIn->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_punchIn);
    m_punchIn->setVisible(song->loop() || song->punchin());

    m_punchOut = new QGraphicsRectItem(0, 0, 1, kpos);
    m_punchOut->setBrush(loopColor);
    m_punchOut->setPen(Qt::NoPen);
    m_punchOut->setZValue(124003.0f);
    m_punchOut->setFlags(QGraphicsItem::ItemIgnoresTransformations);
    m_scene->addItem(m_punchOut);
    m_punchOut->setVisible(song->loop() || song->punchout());

    createCanvasBox();

    //group.append((QGraphicsItem*)m_start);
    //group.append((QGraphicsItem*)m_playhead);
    //if(group.size())
    //{
    //	m_partGroup = m_scene->createItemGroup(group);
    //}
    //else
    m_partGroup = 0;
    updateSpacing();
    m_editing = false;
}/*}}}*/
Exemplo n.º 16
0
void loadFromXml( mlt_producer producer, QGraphicsScene *scene, const char *templateXml, const char *templateText )
{
	scene->clear();
	mlt_properties producer_props = MLT_PRODUCER_PROPERTIES( producer );
	QDomDocument doc;
	QString data = QString::fromUtf8(templateXml);
	QString replacementText = QString::fromUtf8(templateText);
	doc.setContent(data);
	QDomElement title = doc.documentElement();

	// Check for invalid title
	if ( title.isNull() || title.tagName() != "kdenlivetitle" ) return;
	
	// Check title locale
	if ( title.hasAttribute( "LC_NUMERIC" ) ) {
	    QString locale = title.attribute( "LC_NUMERIC" );
	    QLocale::setDefault( locale );
	}
	
        int originalWidth;
        int originalHeight;
	if ( title.hasAttribute("width") ) {
            originalWidth = title.attribute("width").toInt();
            originalHeight = title.attribute("height").toInt();
            scene->setSceneRect(0, 0, originalWidth, originalHeight);
        }
        else {
            originalWidth = scene->sceneRect().width();
            originalHeight = scene->sceneRect().height();
        }
        if ( title.hasAttribute( "out" ) ) {
            mlt_properties_set_position( producer_props, "_animation_out", title.attribute( "out" ).toDouble() );
        }
        else {
            mlt_properties_set_position( producer_props, "_animation_out", mlt_producer_get_out( producer ) );
        }
        
	mlt_properties_set_int( producer_props, "_original_width", originalWidth );
	mlt_properties_set_int( producer_props, "_original_height", originalHeight );

	QDomNode node;
	QDomNodeList items = title.elementsByTagName("item");
        for ( int i = 0; i < items.count(); i++ )
	{
		QGraphicsItem *gitem = NULL;
		node = items.item( i );
		QDomNamedNodeMap nodeAttributes = node.attributes();
		int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
		if ( zValue > -1000 )
		{
			if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsTextItem" )
			{
				QDomNamedNodeMap txtProperties = node.namedItem( "content" ).attributes();
				QFont font( txtProperties.namedItem( "font" ).nodeValue() );
				QDomNode propsNode = txtProperties.namedItem( "font-bold" );
				if ( !propsNode.isNull() )
				{
					// Old: Bold/Not bold.
					font.setBold( propsNode.nodeValue().toInt() );
				}
				else
				{
					// New: Font weight (QFont::)
					font.setWeight( txtProperties.namedItem( "font-weight" ).nodeValue().toInt() );
				}
				font.setItalic( txtProperties.namedItem( "font-italic" ).nodeValue().toInt() );
				font.setUnderline( txtProperties.namedItem( "font-underline" ).nodeValue().toInt() );
				// Older Kdenlive version did not store pixel size but point size
				if ( txtProperties.namedItem( "font-pixel-size" ).isNull() )
				{
					QFont f2;
					f2.setPointSize( txtProperties.namedItem( "font-size" ).nodeValue().toInt() );
					font.setPixelSize( QFontInfo( f2 ).pixelSize() );
				}
				else
					font.setPixelSize( txtProperties.namedItem( "font-pixel-size" ).nodeValue().toInt() );
				QColor col( stringToColor( txtProperties.namedItem( "font-color" ).nodeValue() ) );
				QString text = node.namedItem( "content" ).firstChild().nodeValue();
				if ( !replacementText.isEmpty() )
				{
					text = text.replace( "%s", replacementText );
				}
				QGraphicsTextItem *txt = scene->addText(text, font);
				if (txtProperties.namedItem("font-outline").nodeValue().toDouble()>0.0){
					QTextDocument *doc = txt->document();
					// Make sure some that the text item does not request refresh by itself
					doc->blockSignals(true);
					QTextCursor cursor(doc);
					cursor.select(QTextCursor::Document);
					QTextCharFormat format;
					format.setTextOutline(
							QPen(QColor( stringToColor( txtProperties.namedItem( "font-outline-color" ).nodeValue() ) ),
							txtProperties.namedItem("font-outline").nodeValue().toDouble(),
							Qt::SolidLine,Qt::RoundCap,Qt::RoundJoin)
					);
					format.setForeground(QBrush(col));

					cursor.mergeCharFormat(format);
				} else {
					txt->setDefaultTextColor( col );
				}
				
				// Effects
				if (!txtProperties.namedItem( "typewriter" ).isNull()) {
					// typewriter effect
					mlt_properties_set_int( producer_props, "_animated", 1 );
					QStringList effetData = QStringList() << "typewriter" << text << txtProperties.namedItem( "typewriter" ).nodeValue();
					txt->setData(0, effetData);
					if ( !txtProperties.namedItem( "textwidth" ).isNull() )
						txt->setData( 1, txtProperties.namedItem( "textwidth" ).nodeValue() );
				}
				
				if ( txtProperties.namedItem( "alignment" ).isNull() == false )
				{
					txt->setTextWidth( txt->boundingRect().width() );
					QTextOption opt = txt->document()->defaultTextOption ();
					opt.setAlignment(( Qt::Alignment ) txtProperties.namedItem( "alignment" ).nodeValue().toInt() );
					txt->document()->setDefaultTextOption (opt);
				}
					if ( !txtProperties.namedItem( "kdenlive-axis-x-inverted" ).isNull() )
				{
					//txt->setData(OriginXLeft, txtProperties.namedItem("kdenlive-axis-x-inverted").nodeValue().toInt());
				}
				if ( !txtProperties.namedItem( "kdenlive-axis-y-inverted" ).isNull() )
				{
					//txt->setData(OriginYTop, txtProperties.namedItem("kdenlive-axis-y-inverted").nodeValue().toInt());
				}
					gitem = txt;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsRectItem" )
			{
				QString rect = node.namedItem( "content" ).attributes().namedItem( "rect" ).nodeValue();
				QString br_str = node.namedItem( "content" ).attributes().namedItem( "brushcolor" ).nodeValue();
				QString pen_str = node.namedItem( "content" ).attributes().namedItem( "pencolor" ).nodeValue();
				double penwidth = node.namedItem( "content" ).attributes().namedItem( "penwidth") .nodeValue().toDouble();
				QGraphicsRectItem *rec = scene->addRect( stringToRect( rect ), QPen( QBrush( stringToColor( pen_str ) ), penwidth, Qt::SolidLine, Qt::SquareCap, Qt::RoundJoin ), QBrush( stringToColor( br_str ) ) );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsPixmapItem" )
			{
				const QString url = node.namedItem( "content" ).attributes().namedItem( "url" ).nodeValue();
				const QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QImage img;
				if (base64.isEmpty()){
					img.load(url);
				}else{
					img.loadFromData(QByteArray::fromBase64(base64.toAscii()));
				}
				ImageItem *rec = new ImageItem(img);
				scene->addItem( rec );
				gitem = rec;
			}
			else if ( nodeAttributes.namedItem( "type" ).nodeValue() == "QGraphicsSvgItem" )
			{
				QString url = items.item(i).namedItem("content").attributes().namedItem("url").nodeValue();
				QString base64 = items.item(i).namedItem("content").attributes().namedItem("base64").nodeValue();
				QGraphicsSvgItem *rec = NULL;
				if (base64.isEmpty()){
					rec = new QGraphicsSvgItem(url);
				}else{
					rec = new QGraphicsSvgItem();
					QSvgRenderer *renderer= new QSvgRenderer(QByteArray::fromBase64(base64.toAscii()), rec );
					rec->setSharedRenderer(renderer);
				}
				if (rec){
					scene->addItem(rec);
					gitem = rec;
				}
			}
		}
		//pos and transform
		if ( gitem )
		{
			QPointF p( node.namedItem( "position" ).attributes().namedItem( "x" ).nodeValue().toDouble(),
			           node.namedItem( "position" ).attributes().namedItem( "y" ).nodeValue().toDouble() );
			gitem->setPos( p );
			gitem->setTransform( stringToTransform( node.namedItem( "position" ).firstChild().firstChild().nodeValue() ) );
			int zValue = nodeAttributes.namedItem( "z-index" ).nodeValue().toInt();
			gitem->setZValue( zValue );

#if QT_VERSION >= 0x040600
			// effects
			QDomNode eff = items.item(i).namedItem("effect");
			if (!eff.isNull()) {
				QDomElement e = eff.toElement();
				if (e.attribute("type") == "blur") {
					QGraphicsBlurEffect *blur = new QGraphicsBlurEffect();
					blur->setBlurRadius(e.attribute("blurradius").toInt());
					gitem->setGraphicsEffect(blur);
				}
				else if (e.attribute("type") == "shadow") {
					QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect();
					shadow->setBlurRadius(e.attribute("blurradius").toInt());
					shadow->setOffset(e.attribute("xoffset").toInt(), e.attribute("yoffset").toInt());
					gitem->setGraphicsEffect(shadow);
				}
			}
#endif
		}
	}

	QDomNode n = title.firstChildElement("background");
	if (!n.isNull()) {
		QColor color = QColor( stringToColor( n.attributes().namedItem( "color" ).nodeValue() ) );
                if (color.alpha() > 0) {
                        QGraphicsRectItem *rec = scene->addRect(0, 0, scene->width(), scene->height() , QPen( Qt::NoPen ), QBrush( color ) );
                        rec->setZValue(-1100);
                }
	  
	}

	QString startRect;
	n = title.firstChildElement( "startviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		startRect = n.attributes().namedItem( "rect" ).nodeValue();
	}
	n = title.firstChildElement( "endviewport" );
        // Check if node exists, if it has an x attribute, it is an old version title, don't use viewport
	if (!n.isNull() && !n.toElement().hasAttribute("x"))
	{
		QString rect = n.attributes().namedItem( "rect" ).nodeValue();
		if (startRect != rect)
			mlt_properties_set( producer_props, "_endrect", rect.toUtf8().data() );
	}
	if (!startRect.isEmpty()) {
	  	mlt_properties_set( producer_props, "_startrect", startRect.toUtf8().data() );
	}
	return;
}
Exemplo n.º 17
0
WldScene::WldScene(GraphicsWorkspace * parentView, dataconfigs &configs, WorldData &FileData, QObject *parent) : QGraphicsScene(parent)
{
    setItemIndexMethod(QGraphicsScene::NoIndex);

    //Pointerss
    pConfigs = &configs; // Pointer to Main Configs
    WldData = &FileData; //Ad pointer to level data
    _viewPort = parentView;

    //Options
    opts.animationEnabled = true;
    opts.collisionsEnabled = true;
    grid = true;

    //Indexes
    index_tiles = pConfigs->index_wtiles; //Applaying blocks indexes
    index_scenes = pConfigs->index_wscene;
    index_paths = pConfigs->index_wpaths;
    index_levels = pConfigs->index_wlvl;

    //Editing mode
    EditingMode = 0;
    EraserEnabled = false;
    PasteFromBuffer = false;
    disableMoveItems = false;
    DrawMode=false;

    mouseLeft=false; //Left mouse key is pressed
    mouseMid=false;  //Middle mouse key is pressed
    mouseRight=false;//Right mouse key is pressed

    mouseMoved=false; //Mouse was moved with right mouseKey

    MousePressEventOnly=false;
    MouseMoveEventOnly=false;
    MouseReleaseEventOnly=false;

    last_tile_arrayID=0;
    last_scene_arrayID=0;
    last_path_arrayID=0;
    last_level_arrayID=0;
    last_musicbox_arrayID=0;

    isSelectionDialog=false;

    //Editing process flags
    IsMoved = false;
    haveSelected = false;

    emptyCollisionCheck = false;

    placingItem=0;

    pResizer = NULL;

    contextMenuOpened = false;

    selectedPoint = QPoint(0, 0);
    selectedPointNotUsed=true;
    pointTarget = NULL;
    pointAnimation = NULL;
    pointImg=QPixmap(":/images/set_point.png");

    cursor = NULL;
    resetCursor();
    messageBox = NULL;

    //set dummy images if target not exist or wrong
    uTileImg    = Themes::Image(Themes::dummy_tile);
    uSceneImg   = Themes::Image(Themes::dummy_scenery);
    uPathImg    = Themes::Image(Themes::dummy_path);
    uLevelImg   = Themes::Image(Themes::dummy_wlevel);

    musicBoxImg = Themes::Image(Themes::dummy_musicbox);

    //Build animators for dummies
    SimpleAnimator * tmpAnimator;
        tmpAnimator = new SimpleAnimator(uTileImg, 0);
    animates_Tiles.push_back( tmpAnimator );
        tmpAnimator = new SimpleAnimator(uSceneImg, 0);
    animates_Scenery.push_back( tmpAnimator );
        tmpAnimator = new SimpleAnimator(uPathImg, 0);
    animates_Paths.push_back( tmpAnimator );
        tmpAnimator = new SimpleAnimator(uLevelImg, 0);
    animates_Levels.push_back( tmpAnimator );


    //set Default Z Indexes
    tileZ=0; // tiles
    sceneZ=5; // scenery
    pathZ=10; // paths
    levelZ=15; // levels
    musicZ=20; // musicboxes

    //HistoryIndex
    historyIndex=0;

    //Locks
    lock_tile=false;
    lock_scene=false;
    lock_path=false;
    lock_level=false;
    lock_musbox=false;

    connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));

    long padding=100000;

    QGraphicsRectItem * bigRect = addRect(-padding, -padding, padding*2, padding*2, QPen(Qt::transparent), QBrush(Qt::transparent));
    bigRect->setZValue(-10000000000);


    //Build edit mode classes
    WLD_ModeHand * modeHand = new WLD_ModeHand(this);
    EditModes.push_back(modeHand);

    WLD_ModeSelect * modeSelect = new WLD_ModeSelect(this);
    EditModes.push_back(modeSelect);

    WLD_ModeResize * modeResize = new WLD_ModeResize(this);
    EditModes.push_back(modeResize);

    WLD_ModeErase * modeErase = new WLD_ModeErase(this);
    EditModes.push_back(modeErase);

    WLD_ModePlace * modePlace = new WLD_ModePlace(this);
    EditModes.push_back(modePlace);

    WLD_ModeSquare * modeSquare = new WLD_ModeSquare(this);
    EditModes.push_back(modeSquare);

    WLD_ModeLine * modeLine = new WLD_ModeLine(this);
    EditModes.push_back(modeLine);

    WLD_ModeSetPoint * modeSetPoint = new WLD_ModeSetPoint(this);
    EditModes.push_back(modeSetPoint);

    WLD_ModeFill * modeFill = new WLD_ModeFill(this);
    EditModes.push_back(modeFill);

    CurrentMode = modeSelect;
    CurrentMode->set();
}
Exemplo n.º 18
0
Geometryval::Geometryval(const Mlt::Profile *profile, const Timecode &t, const QPoint &frame_size, int startPoint, QWidget* parent) :
        QWidget(parent),
        m_profile(profile),
        m_paramRect(NULL),
        m_geom(NULL),
        m_path(NULL),
        m_fixedMode(false),
        m_frameSize(frame_size),
        m_startPoint(startPoint),
        m_timePos(t)
{
    setupUi(this);
    toolbarlayout->addWidget(&m_timePos);
    toolbarlayout->insertStretch(-1);

    QVBoxLayout* vbox = new QVBoxLayout(widget);
    m_sceneview = new QGraphicsView(this);
    m_sceneview->setBackgroundBrush(QBrush(Qt::black));
    vbox->addWidget(m_sceneview);
    vbox->setContentsMargins(0, 0, 0, 0);

    QVBoxLayout* vbox2 = new QVBoxLayout(keyframeWidget);
    m_helper = new KeyframeHelper(this);
    vbox2->addWidget(m_helper);
    vbox2->setContentsMargins(0, 0, 0, 0);

    connect(m_helper, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
    connect(m_helper, SIGNAL(keyframeMoved(int)), this, SLOT(slotKeyframeMoved(int)));
    connect(m_helper, SIGNAL(addKeyframe(int)), this, SLOT(slotAddFrame(int)));
    connect(m_helper, SIGNAL(removeKeyframe(int)), this, SLOT(slotDeleteFrame(int)));

    m_scene = new GraphicsSceneRectMove(this);
    m_scene->setTool(TITLE_SELECT);
    m_sceneview->setScene(m_scene);
    m_dar = (m_profile->height() * m_profile->dar()) / (double) m_profile->width();

    m_realWidth = (int)(profile->height() * profile->dar() + 0.5);
    QGraphicsRectItem *frameBorder = new QGraphicsRectItem(QRectF(0, 0, m_realWidth, profile->height()));
    frameBorder->setZValue(-1100);
    frameBorder->setBrush(QColor(255, 255, 0, 30));
    frameBorder->setPen(QPen(QBrush(QColor(255, 255, 255, 255)), 1.0, Qt::DashLine));
    m_scene->addItem(frameBorder);

    buttonNext->setIcon(QIcon::fromTheme("media-skip-forward"));
    buttonNext->setToolTip(i18n("Go to next keyframe"));
    buttonPrevious->setIcon(QIcon::fromTheme("media-skip-backward"));
    buttonPrevious->setToolTip(i18n("Go to previous keyframe"));
    buttonAdd->setIcon(QIcon::fromTheme("document-new"));
    buttonAdd->setToolTip(i18n("Add keyframe"));
    buttonDelete->setIcon(QIcon::fromTheme("edit-delete"));
    buttonDelete->setToolTip(i18n("Delete keyframe"));

    m_configMenu = new QMenu(i18n("Misc..."), this);
    buttonMenu->setMenu(m_configMenu);
    buttonMenu->setPopupMode(QToolButton::MenuButtonPopup);

    m_editOptions = m_configMenu->addAction(QIcon::fromTheme("system-run"), i18n("Show/Hide options"));
    m_editOptions->setCheckable(true);
    buttonMenu->setDefaultAction(m_editOptions);
    connect(m_editOptions, SIGNAL(triggered()), this, SLOT(slotSwitchOptions()));
    slotSwitchOptions();

    m_reset = m_configMenu->addAction(QIcon::fromTheme("view-refresh"), i18n("Reset"), this, SLOT(slotResetPosition()));

    m_syncAction = m_configMenu->addAction(i18n("Sync timeline cursor"), this, SLOT(slotSyncCursor()));
    m_syncAction->setCheckable(true);
    m_syncAction->setChecked(KdenliveSettings::transitionfollowcursor());

    //scene->setSceneRect(0, 0, profile->width * 2, profile->height * 2);
    //view->fitInView(m_frameBorder, Qt::KeepAspectRatio);
    const double sc = 100.0 / profile->height() * 0.8;
    QRectF srect = m_sceneview->sceneRect();
    m_sceneview->setSceneRect(srect.x(), -srect.height() / 3 + 10, srect.width(), srect.height() + srect.height() / 3 * 2 - 10);
    m_scene->setZoom(sc);
    m_sceneview->centerOn(frameBorder);
    m_sceneview->setMouseTracking(true);
    connect(buttonNext , SIGNAL(clicked()) , this , SLOT(slotNextFrame()));
    connect(buttonPrevious , SIGNAL(clicked()) , this , SLOT(slotPreviousFrame()));
    connect(buttonDelete , SIGNAL(clicked()) , this , SLOT(slotDeleteFrame()));
    connect(buttonAdd , SIGNAL(clicked()) , this , SLOT(slotAddFrame()));
    connect(m_scene, SIGNAL(actionFinished()), this, SLOT(slotUpdateTransitionProperties()));

    buttonhcenter->setIcon(QIcon::fromTheme("kdenlive-align-hor"));
    buttonhcenter->setToolTip(i18n("Align item horizontally"));
    buttonvcenter->setIcon(QIcon::fromTheme("kdenlive-align-vert"));
    buttonvcenter->setToolTip(i18n("Align item vertically"));
    buttontop->setIcon(QIcon::fromTheme("kdenlive-align-top"));
    buttontop->setToolTip(i18n("Align item to top"));
    buttonbottom->setIcon(QIcon::fromTheme("kdenlive-align-bottom"));
    buttonbottom->setToolTip(i18n("Align item to bottom"));
    buttonright->setIcon(QIcon::fromTheme("kdenlive-align-right"));
    buttonright->setToolTip(i18n("Align item to right"));
    buttonleft->setIcon(QIcon::fromTheme("kdenlive-align-left"));
    buttonleft->setToolTip(i18n("Align item to left"));

    connect(buttonhcenter, SIGNAL(clicked()), this, SLOT(slotAlignHCenter()));
    connect(buttonvcenter, SIGNAL(clicked()), this, SLOT(slotAlignVCenter()));
    connect(buttontop, SIGNAL(clicked()), this, SLOT(slotAlignTop()));
    connect(buttonbottom, SIGNAL(clicked()), this, SLOT(slotAlignBottom()));
    connect(buttonright, SIGNAL(clicked()), this, SLOT(slotAlignRight()));
    connect(buttonleft, SIGNAL(clicked()), this, SLOT(slotAlignLeft()));
    connect(spinX, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryX(int)));
    connect(spinY, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryY(int)));
    connect(spinWidth, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryWidth(int)));
    connect(spinHeight, SIGNAL(valueChanged(int)), this, SLOT(slotGeometryHeight(int)));
    connect(spinResize, SIGNAL(editingFinished()), this, SLOT(slotResizeCustom()));
    connect(buttonResize, SIGNAL(clicked()), this, SLOT(slotResizeOriginal()));

    connect(this, SIGNAL(parameterChanged()), this, SLOT(slotUpdateGeometry()));
}
Exemplo n.º 19
-1
    void WeekScene::addCalendar()
    {
        const KCalendarSystem* cal = KGlobal::locale()->calendar();

        QGraphicsTextItem* tmp = addText("Dinges");
        QFontMetricsF fm(tmp->font());
        removeItem(tmp);
        delete tmp;


        // first add 7 rectangles for each day of the week
        xoff = fm.width("00:00") + 10;
        yoff = 2 * fm.height() + 10;
        day_width = LongestDayWidth(fm) * 1.5;
        hour_height = fm.height() * 1.5;

        status = addText(i18n("Current schedule:"));
        status->setPos(QPointF(0, 0));
        status->setZValue(2);

        QPen pen(SchedulerPluginSettings::scheduleLineColor());
        QBrush brush(SchedulerPluginSettings::scheduleBackgroundColor());

        for (int i = 0; i < 7; i++)
        {
            QGraphicsRectItem* item = addRect(xoff + day_width * i, yoff, day_width, 24 * hour_height, pen, brush);
            item->setZValue(1);

            QString day = cal->weekDayName(i + 1);

            // make sure day is centered in the middle of the column
            qreal dlen = fm.width(day);
            qreal mid = xoff + day_width * (i + 0.5);
            qreal start = mid - dlen * 0.5;

            QGraphicsTextItem* t = addText(day);
            t->setPos(QPointF(start, fm.height() + 5));
            t->setZValue(2);

            rects.append(item);
        }

        // draw hour lines
        for (int i = 0; i <= 24; i++)
        {
            QGraphicsLineItem* item = addLine(0, yoff + i * hour_height, xoff + 7 * day_width, yoff + i * hour_height, pen);
            item->setZValue(2);

            if (i < 24)
            {
                QGraphicsTextItem* t = addText(QString("%1:00").arg(i));
                t->setPos(QPointF(0, yoff + i * hour_height));
                t->setZValue(2);
            }
            lines.append(item);
        }

        ;
        gline[0] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10);
        gline[0]->setVisible(false);
        gline[1] = new GuidanceLine(xoff, yoff, xoff + 7 * day_width + 10);
        gline[1]->setVisible(false);
        addItem(gline[0]);
        addItem(gline[1]);

        QRectF r = sceneRect();
        r.setHeight(r.height() + 10);
        setSceneRect(r);
    }