示例#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);
}
示例#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);
}
QGraphicsWidget *createSpacer()
{
    QGraphicsWidget *spacer = new QGraphicsWidget();

    spacer->hide();
    spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    spacer->setMinimumSize(0, 0);
    spacer->setPreferredSize(0, 0);

    return spacer;
}
示例#7
0
void tst_QGraphicsLayout::changingMinimumSize()
{
    QFETCH(bool, instantInvalidatePropagation);
    QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
    QGraphicsWidget *widget = new QGraphicsWidget;
    qApp->processEvents();
    widget->setMinimumSize(300,300);
    qApp->processEvents();
    QCOMPARE(widget->size(), QSizeF(300,300));
    QGraphicsLayout::setInstantInvalidatePropagation(false);
}
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::rangeOfViewportShouldBeSizeOfPannedWidgetMinusViewportSize()
{
    // Forcing the size of subject to some value
    subject->setMinimumSize(QSizeF(500, 300));
    subject->setMaximumSize(QSizeF(500, 300));

    QGraphicsWidget *widget = new QGraphicsWidget();
    widget->setMinimumSize(1000,1000);
    subject->setWidget(widget);

    subject->adjustSize();

    QCOMPARE(subject->range(), QRectF(0,0,500,700));
}
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);
}
void Ut_MPannableViewport::testSignalsOnDestroy()
{
    QFETCH(bool, instantInvalidateEnabled);

    bool oldInstantInvalidateEnabled = QGraphicsLayout::instantInvalidatePropagation();

    QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidateEnabled);

    QGraphicsWidget *panel = new QGraphicsWidget;
    panel->setMinimumSize(500, 500);

    subject->setParentItem(panel);
    subject->setAutoRange(true);
    MWidgetController *widget = new MWidgetController(subject);
    widget->setMinimumHeight(1000);
    subject->resize(panel->minimumSize());
    subject->setWidget(widget);

    qApp->processEvents();
    qApp->processEvents();

    QCOMPARE(subject->size(), panel->minimumSize());
    QCOMPARE(widget->size().height(), (qreal)1000);

    QSignalSpy rangeChangedSpy(subject, SIGNAL(rangeChanged(QRectF)));
    QSignalSpy positionChangedSpy(subject, SIGNAL(positionChanged(QPointF)));

    QSignalSpy subjectDestroyedSpy(subject, SIGNAL(destroyed()));
    QSignalSpy widgetDestroyedSpy(widget, SIGNAL(destroyed()));

    delete panel;
    subject = 0;

    QCOMPARE(rangeChangedSpy.count(), 0);
    QCOMPARE(positionChangedSpy.count(), 0);
    QCOMPARE(subjectDestroyedSpy.count(), 1);
    QCOMPARE(widgetDestroyedSpy.count(), 1);

    qApp->processEvents();

    QCOMPARE(rangeChangedSpy.count(), 0);
    QCOMPARE(positionChangedSpy.count(), 0);
    QCOMPARE(subjectDestroyedSpy.count(), 1);
    QCOMPARE(widgetDestroyedSpy.count(), 1);

    QGraphicsLayout::setInstantInvalidatePropagation(oldInstantInvalidateEnabled);
}
/*
 * While the pannedWidget is populated, sizePosChanged() signal should be
 * emitted only once for each actual change in pannedWidget's size.
 *
 * See NB#143428
 */
void Ut_MPannableViewport::sizePosChangedAfterPopulatingPannedWidget()
{
    QGraphicsWidget *mainWidget = new QGraphicsWidget();
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
    QGraphicsWidget *childWidget;

    //Settle initial layout position
    subject->adjustSize();

    mainWidget->setLayout(layout);

    subject->setWidget(mainWidget);

    QSignalSpy spyRange(subject,
                   SIGNAL(rangeChanged(QRectF)));
    QSignalSpy spyViewportSize(subject,
                   SIGNAL(viewportSizeChanged(QSizeF)));
    QSignalSpy spyPosition(subject,
                   SIGNAL(positionChanged(QPointF)));


    for (int i = 0; i < 30; i++) {
        childWidget = new QGraphicsWidget;

        childWidget->setMinimumSize(100, 200);
        childWidget->setPreferredSize(100, 200);

        layout->addItem(childWidget);
    }

    // Force layout to work.
    subject->adjustSize();

    // Check consecutive signals (if any), are different from each other.
    // We don't want to send out the very same event twice.
    for (int i = 1; i < spyRange.size(); i++) {
        QVERIFY(spyRange.at(i) != spyRange.at(i - 1));
    }
    for (int i = 1; i < spyPosition.size(); i++) {
        QVERIFY(spyPosition.at(i) != spyPosition.at(i - 1));
    }
    for (int i = 1; i < spyViewportSize.size(); i++) {
        QVERIFY(spyViewportSize.at(i) != spyViewportSize.at(i - 1));
    }
}
示例#13
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));

}
示例#14
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsScene *scene = new QGraphicsScene();

    Widget *a = new Widget(Qt::blue, Qt::white, "a");
    a->setPreferredSize(100, 100);
    Widget *b = new Widget(Qt::green, Qt::black, "b");
    b->setPreferredSize(100, 100);
    Widget *c = new Widget(Qt::red, Qt::black, "c");
    c->setPreferredSize(100, 100);

    QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
/*
    //! [adding a corner anchor in two steps]
    layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
    layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);
    //! [adding a corner anchor in two steps]
*/
    //! [adding a corner anchor]
    layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);
    //! [adding a corner anchor]

    //! [adding anchors]
    layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
    layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom);
    //! [adding anchors]

    // Place a third widget below the second.
    layout->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);

/*
    //! [adding anchors to match sizes in two steps]
    layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
    layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);
    //! [adding anchors to match sizes in two steps]
*/

    //! [adding anchors to match sizes]
    layout->addAnchors(b, c, Qt::Horizontal);
    //! [adding anchors to match sizes]

    // Anchor the bottom-right corner of the third widget to the bottom-right
    // corner of the layout.
    layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);

    QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    w->setPos(20, 20);
    w->setMinimumSize(100, 100);
    w->setPreferredSize(320, 240);
    w->setLayout(layout);
    w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
    scene->addItem(w);

    QGraphicsView *view = new QGraphicsView();
    view->setScene(scene);
    view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
    view->resize(360, 320);
    view->show();

    return app.exec();
}
示例#15
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);
    }
}