Esempio n. 1
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());
}
//=============================================================================
void sstQt01PathPaintWidgetCls::createNewText()
{
    // static int count = 1;
    createShapeItem(textPath, // tr("Line <%1>").arg(++count),
                    randomItemPosition(), randomItemColor(), randomItemPen(),eSstQt01PathText);
}
//=============================================================================
void sstQt01PathPaintWidgetCls::createNewTriangle()
{
    // static int count = 1;
    createShapeItem(trianglePath, // tr("Triangle <%1>").arg(++count),
                    randomItemPosition(), randomItemColor(), randomItemPen(),eSstQt01PathArea);
}
//=============================================================================
void sstQt01PathPaintWidgetCls::createNewPolyLine()
{
    // static int count = 1;
    createShapeItem(polylinePath, // tr("Line <%1>").arg(++count),
                    randomItemPosition(), randomItemColor(), randomItemPen(),eSstQt01PathPLine);
}
//=============================================================================
void sstQt01PathPaintWidgetCls::createNewCircle()
{
    // static int count = 1;
    createShapeItem(circlePath, // tr("Circle <%1>").arg(++count),
                    randomItemPosition(), randomItemColor(), randomItemPen(),eSstQt01PathCircle);
}