Esempio n. 1
0
WelcomeBox::WelcomeBox(QWidget *parentWidget, QGraphicsItem *parentItem)
    : QGraphicsWidget(parentItem)
{
    m_parentWidget = parentWidget;

    setMinimumSize(BOX_W, BOX_H);
    setMaximumSize(BOX_W, BOX_H);

    m_width = static_cast<int>(BOX_W) - 2;
    m_height = static_cast<int>(BOX_H) - 2;    

    QGraphicsWidget *topEmpty = new QGraphicsWidget;
    topEmpty->setMinimumSize(BOX_W, TEXT_BOX_H + 40);
    topEmpty->setMaximumSize(topEmpty->minimumSize());
    QGraphicsWidget *leftEmpty = new QGraphicsWidget;
    leftEmpty->setMinimumSize(25, 20);
    leftEmpty->setMaximumSize(leftEmpty->minimumSize());
    QGraphicsWidget *centerEmpty = new QGraphicsWidget;
    centerEmpty->setMinimumSize(100, 20);
    centerEmpty->setMaximumSize(centerEmpty->minimumSize());
    QGraphicsWidget *rightEmpty = new QGraphicsWidget;
    rightEmpty->setMinimumSize(25, 20);
    rightEmpty->setMaximumSize(rightEmpty->minimumSize());

    QGraphicsGridLayout *layout = new QGraphicsGridLayout;
    layout->addItem(topEmpty, 0, 0, 1, 5);
    layout->addItem(leftEmpty, 1, 0);
    layout->addItem(centerEmpty, 1, 2);
    layout->addItem(rightEmpty, 1, 4);

    GUIManager *gm = GUIManager::instance();
    connect(this, SIGNAL(modeChanged(int)), gm, SLOT(setMode(int)));
    // Modes
    QList<Mode> modes = ModeManager::modes();
    Mode mode;
    QAction *act;

    int i = 1;
    foreach (mode, modes) {
        if (mode.id != ModeManager::ID_WELCOME) {
            act = new QAction(this);
            act->setText(mode.name);
            act->setData(mode.id);
            connect(act, SIGNAL(triggered()), this, SLOT(setMode()));
            layout->addItem(new WelcomeLink(act), i, 1);
            i++;
        }
    }

    // about
    act = new QAction(this);
    act->setText(tr("About Bmin"));
    connect(act, SIGNAL(triggered()), this, SLOT(showAbout()));
    layout->addItem(new WelcomeLink(act), 1, 3);

    // setting layout
    setLayout(layout);
}
Esempio n. 2
0
void tst_QGraphicsLayout::moveAndResizeWidgetInWidget()
{
    QFETCH(bool, instantInvalidatePropagation);

    QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
    QGraphicsScene scene;

    QGraphicsWidget *widget = new QGraphicsWidget;
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget);
    layout->setContentsMargins(0,0,0,0);
    WidgetToTestResizeEvents *innerWidget = new WidgetToTestResizeEvents;
    QGraphicsLinearLayout *innerLayout = new QGraphicsLinearLayout(innerWidget);
    innerLayout->setContentsMargins(0,0,0,0);
    QCOMPARE(widget->maximumSize(), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
    layout->addItem(innerWidget);
    widget->setMinimumSize(1,1);
    widget->setPreferredSize(1000,1000);
    widget->setMaximumSize(2000,2000);
    widget->resize(widget->preferredSize());
    innerWidget->setMinimumSize(1,1);
    qApp->processEvents();
    innerWidget->resizeEventCalled = false;

    QCOMPARE(widget->size(), QSizeF(1000, 1000));
    QCOMPARE(layout->geometry().size(), QSizeF(1000, 1000));
    QCOMPARE(innerWidget->size(), QSizeF(1000, 1000));

    innerLayout->invalidate();
    widget->setMaximumHeight(500);
    widget->setX(1);
    qApp->processEvents();
    QCOMPARE(widget->size(), QSizeF(1000, 500));
    QCOMPARE(innerWidget->size(), QSizeF(1000, 500));
    QVERIFY(innerWidget->resizeEventCalled);
}
void Ut_MPannableViewport::updateSamePosition()
{
    QGraphicsWidget *mainWidget = new QGraphicsWidget();
    QPointF point(0.0, 0.0);

    subject->setMinimumSize(100, 480);
    subject->setPreferredSize(100, 480);
    subject->setMaximumSize(100, 480);

    mainWidget->setMinimumSize(100, 1000);
    mainWidget->setPreferredSize(100, 1000);
    mainWidget->setMaximumSize(100, 1000);

    subject->setWidget(mainWidget);

    subject->updatePosition(point);

    QSignalSpy spy(subject,
                   SIGNAL(positionChanged(QPointF)));

    subject->updatePosition(point);

    // Should not have emitted anything since nothing changed
    QCOMPARE(spy.count(), 0);
}
void Ut_MPannableViewport::updatePosition()
{

    QGraphicsWidget *widget = new QGraphicsWidget();
    widget->setMinimumSize(QSizeF(10,10));
    widget->setMaximumSize(QSizeF(10,10));
    subject->setWidget(widget);

    subject->layout()->activate();

    // Forcing the size of subject to some value
    subject->setMinimumSize(QSizeF(500, 300));
    subject->setMaximumSize(QSizeF(500, 300));
    subject->adjustSize();

    QSignalSpy spy(subject, SIGNAL(positionChanged(QPointF)));

    subject->physics()->setPosition(QPointF(0,75));
    subject->layout()->activate();

    QCOMPARE(static_cast<MPannableViewportPrivate *>(subject->d_ptr)->pannedWidget->pos(), -QPointF(0, 75));

    QCOMPARE(spy.count(), 1);

}
void Ut_MPannableViewport::event()
{
    QEvent *event = new QEvent(QEvent::LayoutRequest);

    QFETCH(QSizeF, viewportSize);
    QFETCH(QSizeF, pannedSize);
    QFETCH(QSizeF, physicsRange);

    QGraphicsWidget *widget = new QGraphicsWidget();
    // Forcing the size of panned widget
    widget->setMinimumSize(pannedSize);
    widget->setPreferredSize(pannedSize);
    widget->setMaximumSize(pannedSize);

    // Forcing the size of subject
    subject->setMinimumSize(viewportSize);
    subject->setPreferredSize(viewportSize);
    subject->setMaximumSize(viewportSize);

    subject->setWidget(widget);

    subject->event(event);

    qApp->processEvents();

    QCOMPARE(subject->physics()->range().size(), physicsRange);
}
static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0),
                                   const QSizeF &preferred = QSize(150.0, 100.0),
                                   const QSizeF &maximum = QSizeF(200.0, 100.0),
                                   const QString &name = QString())
{
    QGraphicsWidget *w = new RectWidget;
    w->setMinimumSize(minimum);
    w->setPreferredSize(preferred);
    w->setMaximumSize(maximum);
    w->setData(0, name);
    return w;
}
void Ut_MPannableViewport::setGeometry()
{
    QFETCH(QSizeF, viewportSize);
    QFETCH(QSizeF, pannedSize);
    QFETCH(QSizeF, physicsRange);

    QGraphicsWidget *widget = new QGraphicsWidget();
    widget->setMinimumSize(pannedSize);
    widget->setMaximumSize(pannedSize);

    subject->setWidget(widget);
    subject->setGeometry(QRectF(QPointF(), viewportSize));

    QCOMPARE(subject->physics()->range().size(), physicsRange);
}
Esempio n. 8
0
void tst_QGraphicsLayout::sizeHints()
{

    QGraphicsView view;
    QGraphicsScene scene;
    QGraphicsWidget *window = new QGraphicsWidget();
    scene.addItem(window);
    QGraphicsLinearLayout *lout = new QGraphicsLinearLayout(window);
    lout->setContentsMargins(0,0,0,0);
    QGraphicsWidget *gw = new QGraphicsWidget(window);
    gw->setMinimumSize(QSizeF(10,10));
    gw->setPreferredSize(QSizeF(100,100));
    gw->setMaximumSize(QSizeF(500,500));
    lout->addItem(gw);
    QCOMPARE(lout->effectiveSizeHint(Qt::MinimumSize), gw->effectiveSizeHint(Qt::MinimumSize));
    QCOMPARE(lout->effectiveSizeHint(Qt::PreferredSize), gw->effectiveSizeHint(Qt::PreferredSize));
    QCOMPARE(lout->effectiveSizeHint(Qt::MaximumSize), gw->effectiveSizeHint(Qt::MaximumSize));

}
Esempio n. 9
0
void tst_QGraphicsLayout::sizeHintOfHiddenLayout()
{
    QGraphicsScene scene;
    QGraphicsWidget *window = new QGraphicsWidget(0, Qt::Window);
    scene.addItem(window);
    TestLayout *lout = new TestLayout(window);
    lout->setContentsMargins(1,2,2,1);
    QGraphicsWidget *w = new QGraphicsWidget;
    w->setPreferredSize(20, 20);
    w->setMaximumSize(50, 50);
    lout->addItem(w);
    window->setLayout(lout);

    for (int pass = 0; pass < 3; ++pass) {
        QCOMPARE(lout->sizeHint(Qt::MinimumSize), QSizeF(3,3));
        QCOMPARE(lout->sizeHint(Qt::PreferredSize), QSizeF(23,23));
        QCOMPARE(lout->sizeHint(Qt::MaximumSize), QSizeF(53,53));
        window->setVisible(pass % 2);
    }
}
Esempio n. 10
0
void tst_QGraphicsLayout::invalidateAndMove()
{
    // Check that if we set the position of an item and invalidate its layout at the same
    // time, the widget keeps its correct size
    QFETCH(bool, instantInvalidatePropagation);
    QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
    QGraphicsScene scene;

    QGraphicsWidget *widget = new QGraphicsWidget;
    new QGraphicsLinearLayout(widget);

    widget->setMinimumSize(1,1);
    widget->setPreferredSize(34,34);
    widget->setMaximumSize(100,100);
    widget->resize(widget->preferredSize());

    scene.addItem(widget);

    qApp->processEvents();

    /* Invalidate and reactivate.  The size should not have changed */
    widget->layout()->invalidate();
    widget->layout()->activate();

    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
    qApp->processEvents();
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());

    widget->layout()->invalidate();
    widget->setX(1);  //Change just the position using setX
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
    qApp->processEvents();
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());

    widget->layout()->invalidate();
    widget->setGeometry(1,1,34,34);  //Change just the position using setGeometry
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
    qApp->processEvents();
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());

    widget->layout()->invalidate();
    widget->setGeometry(1,1,60,60);  //Change just the size using setGeometry
    QCOMPARE(widget->geometry().size(), QSizeF(60,60));
    QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60));
    qApp->processEvents();
    QCOMPARE(widget->geometry().size(), QSizeF(60,60));
    QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60));

    widget->layout()->invalidate();
    widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
    qApp->processEvents();
    QCOMPARE(widget->geometry().size(), widget->preferredSize());
    QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());

    QGraphicsLayout::setInstantInvalidatePropagation(false);
}
void Ut_MPannableViewport::testSizeHint()
{
    struct SquareWidget : public QGraphicsWidget
    {
        SquareWidget() {
            QSizePolicy policy = sizePolicy();
            policy.setHeightForWidth(true);
            setSizePolicy(policy);
        }
        QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const {
           if (which != Qt::PreferredSize || constraint.width() == -1)
              return QGraphicsWidget::sizeHint(which, constraint);
           else
              return QSizeF( constraint.width(), constraint.width() );
        }
    };

    QFETCH(QString, cssName);
    QFETCH(qreal, width);
    QFETCH(qreal, height);

    QGraphicsWidget *widget = new SquareWidget();
    widget->setPreferredWidth(100);
    subject->setWidget(widget);
    subject->setObjectName(cssName);

    QCOMPARE(widget->preferredSize(), QSizeF(100,100));
    QCOMPARE(widget->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    QCOMPARE(subject->layout()->preferredSize(), QSizeF(100,100));
    QCOMPARE(subject->layout()->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    QCOMPARE(subject->preferredSize(), QSizeF(width,height));
    if (cssName == "noCssSize")
        QCOMPARE(subject->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    // Test that the minimum and maximum size of the viewport is the same as the widget if we cannot pan in that direction
    widget->setMinimumSize(30,30);
    widget->setMaximumSize(200,200);

    QCOMPARE(subject->maximumSize(), QSizeF(200,200));

    subject->setPanDirection(0); //Can't pan in either direction
    QCOMPARE(subject->minimumSize(), QSizeF(30,30));
    subject->setPanDirection(Qt::Vertical);
    QCOMPARE(subject->minimumSize(), QSizeF(30,0));
    subject->setPanDirection(Qt::Horizontal);
    QCOMPARE(subject->minimumSize(), QSizeF(0,30));
    subject->setPanDirection(Qt::Horizontal | Qt::Vertical);
    QCOMPARE(subject->minimumSize(), QSizeF(0,0));

    for (int panDirection = 0; panDirection <= (Qt::Vertical | Qt::Horizontal); ++panDirection) {
        subject->setPanDirection((Qt::Orientations)panDirection);
        QCOMPARE(subject->preferredSize(), QSizeF(width,height));
        QCOMPARE(subject->maximumSize(), QSizeF(200,200));
        subject->setPreferredWidth(200);
        if (cssName == "noCssSize" || cssName == "width50")
            QCOMPARE(subject->preferredSize(), QSizeF(200,200));
        else
            QCOMPARE(subject->preferredSize(), QSizeF(200,50));
        subject->setPreferredWidth(-1);
    }
}