//=============================================================================
int sstQt01PathStoreViewCls::createDefaultItems(int iKey)
{
  //-----------------------------------------------------------------------------
  if ( iKey != 0) return -1;

  QPainterPath circlePath;
  QPainterPath squarePath;
  QPainterPath trianglePath;

  circlePath.addEllipse(QRect(0, 0, 100, 100));
  squarePath.addRect(QRect(0, 0, 100, 100));

  qreal x = trianglePath.currentPosition().x();
  qreal y = trianglePath.currentPosition().y();
  trianglePath.moveTo(x + 120 / 2, y);
  trianglePath.lineTo(0, 100);
  trianglePath.lineTo(120, 100);
  trianglePath.lineTo(x + 120 / 2, y);

  sstQt01ShapeItem oItem;

  oItem.createShapeItem(circlePath, "Circle", initialItemPosition(circlePath),
                  initialItemColor(),eSstQt01PathCircle);
  this->appendShapeItem(oItem);

  oItem.createShapeItem(squarePath, "Square", initialItemPosition(squarePath),
                  initialItemColor(),eSstQt01PathArea);
  this->appendShapeItem(oItem);

  oItem.createShapeItem(trianglePath, "Triangle",
                  initialItemPosition(trianglePath), initialItemColor(),eSstQt01PathArea);
  this->appendShapeItem(oItem);

  return 0;
}
示例#2
0
//! [0]
SortingBox::SortingBox()
{
//! [0] //! [1]
    setMouseTracking(true);
//! [1] //! [2]
    setBackgroundRole(QPalette::Base);
//! [2]

    itemInMotion = 0;

//! [3]
    newCircleButton = createToolButton(tr("New Circle"),
                                       QIcon(":/images/circle.png"),
                                       SLOT(createNewCircle()));

    newSquareButton = createToolButton(tr("New Square"),
                                       QIcon(":/images/square.png"),
                                       SLOT(createNewSquare()));

    newTriangleButton = createToolButton(tr("New Triangle"),
                                         QIcon(":/images/triangle.png"),
                                         SLOT(createNewTriangle()));

    circlePath.addEllipse(QRect(0, 0, 100, 100));
    squarePath.addRect(QRect(0, 0, 100, 100));

    qreal x = trianglePath.currentPosition().x();
    qreal y = trianglePath.currentPosition().y();
    trianglePath.moveTo(x + 120 / 2, y);
    trianglePath.lineTo(0, 100);
    trianglePath.lineTo(120, 100);
    trianglePath.lineTo(x + 120 / 2, y);

//! [3] //! [4]
    setWindowTitle(tr("Tool Tips"));
    resize(500, 300);

    createShapeItem(circlePath, tr("Circle"), initialItemPosition(circlePath),
                    initialItemColor());
    createShapeItem(squarePath, tr("Square"), initialItemPosition(squarePath),
                    initialItemColor());
    createShapeItem(trianglePath, tr("Triangle"),
                    initialItemPosition(trianglePath), initialItemColor());
}