/**
 * @brief contextMenuEvent handle context menu events.
 * @param event context menu event.
 */
void VToolDetail::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    QMenu menu;
    QAction *actionOption = menu.addAction(tr("Options"));
    QAction *actionRemove = menu.addAction(tr("Delete"));
    if (_referens > 1)
    {
        actionRemove->setEnabled(false);
    }
    else
    {
        actionRemove->setEnabled(true);
    }
    QAction *selectedAction = menu.exec(event->screenPos());
    if (selectedAction == actionOption)
    {
        QGraphicsScene *scene = this->scene();
        QList<QGraphicsView *> list =  scene->views();
        dialog = new DialogDetail(getData(), list.first());
        connect(qobject_cast< VMainGraphicsScene * >(this->scene()), &VMainGraphicsScene::ChoosedObject,
                dialog, &DialogTool::ChoosedObject);
        connect(dialog, &DialogTool::DialogClosed, this, &VToolDetail::FullUpdateFromGuiOk);
        setDialog();
        dialog->show();
    }
    if (selectedAction == actionRemove)
    {
        DeleteTool();
    }
}
Exemple #2
0
void drawHist(QGraphicsPixmapItem *pixmapItem, std::vector<int> &hist, int maxLevel)
{
    QGraphicsScene *scene = pixmapItem->scene();
    QGraphicsView *view = scene->views()[0];
    int width = view->contentsRect().width();
    int height = view->contentsRect().height();
    QColor black(0, 0, 0);
    QColor white(255, 255, 255);
    QColor red(255, 0, 0);
    QImage image(width, height, QImage::Format_ARGB32);
    image.fill(white);
    QPainter p(&image);
    double shift = (double) image.width() / hist.size();
    double step = (double) image.height() / maxLevel;
    for (unsigned int i = 0; i < hist.size(); ++i)
    {
        if (i == 0 || i == hist.size() - 1)
        {
            p.setPen(red);
            p.setBrush(QBrush(red));
        }
        else if (i == 1)
        {
            p.setPen(black);
            p.setBrush(QBrush(black));
        }
        if (hist[i] == 0)
            continue;
        int curHeight = hist[i] * step;
        p.drawRect(qFloor(i * shift), qFloor(image.height() - curHeight), qFloor(shift), qFloor(curHeight));
    }
    pixmapItem->setPixmap(QPixmap::fromImage(image));
    scene->setSceneRect(QRectF(image.rect()));
}
Exemple #3
0
/*!
*/
void GridItem::moveBall(BallItem *ball, const QVector<GridPos> &path)
{
    if (!ball) {
        qDebug() << "GridItem::moveBall(...): pointer to the ball item is NULL";
        return;
    }

    QVector<GridPos> tmpPath(path);

    // skip the first square
    GridPos firstPos = tmpPath.front();
    freePos(firstPos);
    //

    // the source square becomes available
    BallItemsProvider::instance()->fromUsedToAvailable(firstPos);
    //

    QGraphicsScene *theScene = scene();
    Q_ASSERT(theScene);
    Q_ASSERT(theScene->views().isEmpty() == false);

    theScene->views()[0]->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
    foreach(GridPos pos, tmpPath) {
        if (pos != tmpPath.back()) {
            // do not store the ball item on the positions of the intermediate squares (the 3rd argument
            // is set to false).
            showBall(ball, pos, false);
            pause(100);
        } else {
            // is there any hint ball onto the target square ?
            BallItem *hintBall = ballAt(pos);
            if (hintBall) {
                hideBall(hintBall);
                delete hintBall;

                BallItemsProvider::instance()->removeHint(hintBall);
            }

            // stores the ball item on the position of the target square.
            showBall(ball, pos, true);
        }
        // also wipes the path tracks square by square
        m_pathTracker.removeFrontLine();
        update();
    }
}
Exemple #4
0
QGraphicsView * KWidget::view() const
{
    QGraphicsScene *gs = scene();
    if(gs == NULL)
        return NULL;
    const QList<QGraphicsView*>& lstgv = gs->views();
    if(lstgv.isEmpty())
        return NULL;
    return lstgv[0];
}
void ShaderEffectItem::checkViewportUpdateMode()
{
    if (!m_checkedViewportUpdateMode) {
        QGraphicsScene *s = scene();
        if (s){
            QList<QGraphicsView*> views = s->views();
            for (int i = 0; i < views.count(); i++) {
                if (views[i]->viewportUpdateMode() != QGraphicsView::FullViewportUpdate) {
                    qWarning() << "ShaderEffectItem::checkViewportUpdateMode - consider setting QGraphicsView::FullViewportUpdate mode with OpenGL!";
                }
            }
        }
        m_checkedViewportUpdateMode = true;
    }
}
QWidget *QuickTestEvent::eventWidget()
{
    QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(parent());
    if (!item)
        return 0;
    QGraphicsScene *s = item->scene();
    while (!s && item) {
        item = qobject_cast<QDeclarativeItem *>(item->parent());
        s = item->scene();
    }
    if (!s)
        return 0;
    QList<QGraphicsView *> views = s->views();
    if (views.isEmpty())
        return 0;
    return views.at(0);
}