예제 #1
0
void GraphicsScene::hideAllItemsExceptImage()
{
  LOG4CPP_INFO_S ((*mainCat)) << "GraphicsScene::hideAllItemsExceptImage";

  for (int index = 0; index < QGraphicsScene::items().count(); index++) {
    QGraphicsItem *item = QGraphicsScene::items().at(index);

    if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt() == GRAPHICS_ITEM_TYPE_IMAGE) {

      item->show();

    } else {

      item->hide();

    }
  }
}
예제 #2
0
void SunMenuItemView::reinitializeDisplayedItemPosition()
{
    qint32 maxWidth = width();
    qint32 maxHeight;
    QGraphicsItem* gi = displayedItem()->graphicsItem();

    //default
    gi->resetTransform();

    // Calculate maxHeight as smaller chord(only for small sweepLengths)
    if (sweepLength() <= 90)
    {
        qreal biggerChord = 2 * (innerRadius() + maxWidth)
                * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2));
        qreal smallerChord = 2 * innerRadius()
                * /*qAbs*/(qSin((M_PI / 180) * sweepLength() / 2));
        maxHeight = (0.2 * smallerChord + 1.4 * biggerChord) / 2;
    }
    else
        maxHeight = displayedItem()->maximumHeight();

    //hide item if it too small
    if (maxWidth < 10 || maxHeight < 5)
    {
        gi->hide();
        return;
    }

    QRectF graphicsItemRect;

    if (sweepLength() == 360 && innerRadius() == 0)
    {
        displayedItem()->setMaximumSize(2 * maxWidth /*diameter*/, maxHeight);
        graphicsItemRect = gi->boundingRect();
        gi->setPos(-graphicsItemRect.width() / 2,
                   -graphicsItemRect.height() / 2);

        gi->show();
        return;
    }

    displayedItem()->setMaximumSize(maxWidth - 10, maxHeight);
    graphicsItemRect = gi->boundingRect();

    /////////////////////////////////////////////////////////////////////////////////
    //positioning mDisplayedItem (rotation and coordinates).
    qreal rotationAngle = startAngle() + sweepLength() / 2;

    // Getting distance and angle (polar coordinates) + some centering adjustments
    // We assume that (0,0) item's coordinate is it's top left corner
    //(like QGraphicsSimpleTextItem and QGraphicsProxyWidget).
    qreal angle, distance;
    if (rotationAngle >= 270 || rotationAngle <= 90)
    {
        distance = innerRadius() + maxWidth / 2 - graphicsItemRect.width() / 2;
        angle = rotationAngle
                + (180 / M_PI)
                * qAtan(graphicsItemRect.height() / (2 * distance));
    }
    else
    {
        distance = innerRadius() + maxWidth / 2 + graphicsItemRect.width() / 2;
        angle = rotationAngle
                - (180 / M_PI)
                * qAtan(graphicsItemRect.height() / (2 * distance));

        rotationAngle -= 180;
    }

    gi->setPos(distance * qCos((M_PI / 180) * angle),
               -distance * qSin((M_PI / 180) * angle));
    gi->setRotation(-rotationAngle); //minus - because this function rotates clockwise.

    gi->show();
    ///////////////////////////////////////////////////////////////////////////////////
}