Example #1
0
GEvScene::GEvScene(GSequence *parentSeq)
    : QGraphicsScene(parentSeq)
    , m_pSeq(parentSeq)
{
    // to have the scene match the sequence length
    connect(m_pSeq, SIGNAL(LengthChanged(double)), this, SLOT(UpdateLength(double)), Qt::QueuedConnection);

    // background color
    setBackgroundBrush(QColor(230, 255, 230));

    // this is a QGraphicsWidget to use a layout in the scene
    QGraphicsWidget* pGraWid = new QGraphicsWidget();
    addItem(pGraWid);
    m_pChannelLayout = new QGraphicsLinearLayout(Qt::Vertical);
    pGraWid->setLayout(m_pChannelLayout);
    // margins from the view border
    m_pChannelLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
    // spacing between channels
    m_pChannelLayout->setSpacing(1.0);

    // makes the root item, parent of all event in the sequence
    m_pRootEvent = new GSynchEvent(0);
    m_pRootEvent->setParent(this);
    m_pRootEvent->setFlag(QGraphicsItem::ItemIsMovable, false);;
    addItem(m_pRootEvent);
}
Example #2
0
void WaitWidget::setupScene()
{
	// Creamos el objeto efecto
	d->m_effect = new QGraphicsOpacityEffect;
	d->m_effect->setOpacity(0);
	d->m_effect->setEnabled(true);

	// Ahora creamos los proxys para gráficos que nos permita incluirlos en la escena
	QGraphicsProxyWidget *pFrame = d->m_scene.addWidget(d->m_widget);
	pFrame->resize(d->m_widget->width(), d->m_widget->height());

	// Y lo agregamos a un layout gráfico
	QGraphicsLinearLayout *gLayout = new QGraphicsLinearLayout;
	gLayout->setOrientation(Qt::Vertical);
	gLayout->addItem(pFrame);

	// Creamos finalmente un objeto gráfico que lo contiene todo, y lo agregamos a la escena
	QGraphicsWidget *form = new QGraphicsWidget;
	form->setLayout(gLayout);
	form->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
	d->m_scene.addItem(form);

	// Agregamos el efecto de opacidad al aparecer
	form->setGraphicsEffect(d->m_effect);
	form->resize(d->m_widget->width(), d->m_widget->height());
}
QGraphicsWidget *DesignerActionManager::createFormEditorToolBar(QGraphicsItem *parent)
{
    QList<ActionInterface* > actions = Utils::filtered(designerActions(),
                                                       [](ActionInterface *action) {
            return action->type() ==  ActionInterface::FormEditorAction
                && action->action()->isVisible();
    });

    Utils::sort(actions, [](ActionInterface *l, ActionInterface *r) {
        return l->priority() > r->priority();
    });

    QGraphicsWidget *toolbar = new QGraphicsWidget(parent);

    auto layout = new QGraphicsLinearLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);
    toolbar->setLayout(layout);

    for (ActionInterface *action : actions) {
        auto button = new FormEditorToolButton(action->action(), toolbar);
        layout->addItem(button);
    }

    toolbar->resize(toolbar->preferredSize());

    layout->invalidate();
    layout->activate();

    toolbar->update();

    return toolbar;
}
Example #4
0
Dashboard::Dashboard()
    :Pixmap(":/dashboard.png"),  selected(NULL), player(NULL), avatar(NULL),
    weapon(NULL), armor(NULL), defensive_horse(NULL), offensive_horse(NULL), view_as_skill(NULL)
{
    int i;
    for(i=0; i<5; i++){
        magatamas[i].load(QString(":/magatamas/%1.png").arg(i+1));
    }
    magatamas[5] = magatamas[4];

    sort_combobox = new QComboBox;
    sort_combobox->addItem(tr("No sort"));
    sort_combobox->addItem(tr("Sort by suit"));
    sort_combobox->addItem(tr("Sort by type"));
    sort_combobox->addItem(tr("Sort by availability"));
    QGraphicsProxyWidget *sort_widget = new QGraphicsProxyWidget;
    sort_widget->setWidget(sort_combobox);
    connect(sort_combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(sortCards()));

    sort_widget->setParentItem(this);
    sort_widget->setPos(0, 28);

    button_layout  = new QGraphicsLinearLayout(Qt::Horizontal);

    QGraphicsWidget *form = new QGraphicsWidget(this);
    form->setLayout(button_layout);
    form->setPos(sort_widget->pos());
    form->moveBy(sort_widget->boundingRect().width(), -10);

    avatar = new Pixmap;
    avatar->setPos(837, 35);    
    avatar->setParentItem(this);

    kingdom = new QGraphicsPixmapItem(this);
    kingdom->setPos(avatar->pos());

    chain_icon = new Pixmap(":/chain.png");
    chain_icon->setParentItem(this);
    chain_icon->setPos(avatar->pos());
    chain_icon->hide();
    chain_icon->setZValue(1.0);

    back_icon = new Pixmap(":/big-back.png");
    back_icon->setParentItem(this);
    back_icon->setPos(922, 104);
    back_icon->hide();
    back_icon->setZValue(1.0);

    equips << &weapon << &armor << &defensive_horse << &offensive_horse;

    QGraphicsPixmapItem *handcard_pixmap = new QGraphicsPixmapItem(this);
    handcard_pixmap->setPixmap(QPixmap(":/handcard.png"));
    handcard_pixmap->setPos(841, 146);

    handcard_num = new QGraphicsSimpleTextItem(handcard_pixmap);
    handcard_num->setFont(Config.TinyFont);
    handcard_num->setBrush(Qt::white);

    handcard_pixmap->hide();
}
Example #5
0
void MainWindow::createLayout()
{
    QGraphicsLinearLayout *leftLayout = new QGraphicsLinearLayout(
            Qt::Vertical);
    leftLayout->addItem(proxyForName["startButton"]);
    leftLayout->addItem(proxyForName["pauseOrResumeButton"]);
    leftLayout->addItem(proxyForName["stopButton"]);
    leftLayout->addItem(proxyForName["quitButton"]);

    QGraphicsLinearLayout *rightLayout = new QGraphicsLinearLayout(
            Qt::Vertical);
    foreach (const QString &name, QStringList()
            << "initialCountLabel" << "initialCountSpinBox"
            << "currentCountLabel" << "currentCountLCD"
            << "iterationsLabel" << "iterationsLCD"
            << "showIdsCheckBox")
        rightLayout->addItem(proxyForName[name]);

    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
    layout->addItem(leftLayout);
    layout->setItemSpacing(0, DishSize + Margin);
    layout->addItem(rightLayout);

    QGraphicsWidget *widget = new QGraphicsWidget;
    widget->setLayout(layout);
    scene->addItem(widget);

    int width = qRound(layout->preferredWidth());
    int height = DishSize + (2 * Margin);
    setMinimumSize(width, height);
    scene->setSceneRect(0, 0, width, height);
}
Example #6
0
int main(int argc,char **argv) {
	QApplication app(argc,argv);

	QGraphicsScene scene;
	// 要把widget嵌入到QGraphicsScene內,必需要透過QGraphicsProxyWidget才可以
	// addWidget回傳的是QGraphicsProxyWidget,由QGraphicsWidget繼承
	QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
	QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

	QGraphicsGridLayout *layout = new QGraphicsGridLayout;
	// QGraphicsGridLayout的addItem函數必需是QGraphicsWidget
	layout->addItem(textEdit, 0, 0);
	layout->addItem(pushButton, 0, 1);

	QGraphicsWidget *form = new QGraphicsWidget;
	form->setLayout(layout);
	scene.addItem(form);

	QGraphicsView view(&scene);

	view.show();


	return app.exec();
}
Example #7
0
 foreach(QGraphicsGridLayout *layout, _layouts) {
     QGraphicsWidget *form = new QGraphicsWidget;
     form->setLayout(layout);
     addItem(form);
     form->setPos(i, 0);
     i += 200;
 }
void ApplicationMenuPage::createContent()
{
    MApplicationPage::createContent();
    pannableViewport()->setAcceptGesturesFromAnyDirection(true);

    setStyleName(inv("CommonApplicationPage"));

    QGraphicsWidget *panel = centralWidget();

    infoLabel = new MLabel(panel);
    infoLabel->setObjectName("infoLabel");
    infoLabel->setStyleName(inv("CommonBodyText"));
    infoLabel->setWordWrap(true);
    infoLabel->setAlignment(Qt::AlignTop);

    actionItalic = new MAction(panel);
    actionItalic->setObjectName("actionItalic");
    actionItalic->setLocation(MAction::ApplicationMenuLocation);
    addAction(actionItalic);
    connect(actionItalic, SIGNAL(triggered()), this, SLOT(makeTextItalic()));

    actionNormal = new MAction(panel);
    actionNormal->setObjectName("actionNormal");
    actionNormal->setLocation(MAction::ApplicationMenuLocation);
    addAction(actionNormal);
    connect(actionNormal, SIGNAL(triggered()), this, SLOT(makeTextNormal()));

    MWidgetAction *widgetAction = new MWidgetAction(panel);
    widgetAction->setLocation(MAction::ApplicationMenuLocation);

    QStringList list;
    for (int i = 0; i < 5; ++i) {
        list << QString::number(100 + i);
    }
    comboBox = new MComboBox;
    comboBox->setObjectName("comboBox");
    comboBox->addItems(list);

    comboBox->setIconVisible(false);
    comboBox->setTitle("ComboBox");
    comboBox->setCurrentIndex(0);
    widgetAction->setWidget(comboBox);
    addAction(widgetAction);

    MLayout *layout = new MLayout(panel);
    layout->setContentsMargins(0, 0, 0, 0);
    panel->setLayout(layout);
    policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    policy->setContentsMargins(0, 0, 0, 0);
    policy->setSpacing(0);

    policy->addItem(infoLabel);

    retranslateUi();
}
Example #9
0
UpcomingEventsListWidget::UpcomingEventsListWidget( QGraphicsWidget *parent )
    : Plasma::ScrollWidget( parent )
    , m_sigmap( new QSignalMapper( this ) )
{
    // The widgets are displayed line by line with only one column
    m_layout = new QGraphicsLinearLayout( Qt::Vertical );
    QGraphicsWidget *content = new QGraphicsWidget( this );
    content->setLayout( m_layout );
    setWidget( content );
    connect( m_sigmap, SIGNAL(mapped(QObject*)), this, SIGNAL(mapRequested(QObject*)) );
}
Example #10
0
bool ImageStripScene::setCurrentDirectory(const QString& path)
{
    QMutexLocker locker(&m_mutex);
    QDir         directory(path);
    QImageReader reader;
    
    if(directory.exists()) {
        clear();
        
        if(m_loader) {
            m_loader->disconnect(this);
            m_loader->stopExecution();
            
            if(!m_loader->wait(500)) {
                m_loader->terminate();
                m_loader->wait();
            }
        }
        
        delete m_loader;
        
        m_numItems = 0;
        m_loader   = new ImageLoader(m_imgSize);
        connect(m_loader, SIGNAL(sigItemContentChanged(ImageItem*)), SLOT(slotItemContentChanged(ImageItem*)));
        
        QStringList            files  = directory.entryList(QDir::Files);
        QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
        
        for(QStringList::iterator name=files.begin(); name!=files.end(); ++name) {
            QString path = directory.absoluteFilePath(*name);
            reader.setFileName(path);
            
            if(reader.canRead()) {
                ImageItem* item = new ImageItem(m_imgSize, path, m_loader);
                m_loader->addPath(item, path);
                layout->addItem(item);
                ++m_numItems;
            }
        }
        
        QGraphicsWidget* widget = new QGraphicsWidget();
        widget->setLayout(layout);
        widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        
        addItem(widget);
        setSceneRect(widget->boundingRect());
        
        m_loader->start(QThread::LowPriority);
        return true;
    }
    
    return false;
}
Example #11
0
void tst_qdeclarativelayoutitem::test_resizing()
{
    //Create Layout (must be done in C++)
    QGraphicsView view;
    QGraphicsScene scene;
    QGraphicsWidget *widget = new QGraphicsWidget();
    QGraphicsLinearLayout *layout = new QGraphicsLinearLayout();
    widget->setLayout(layout);
    scene.addItem(widget);
    view.setScene(&scene);
    //Add the QML snippet into the layout
    QDeclarativeEngine engine;
    QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/layoutItem.qml"));
    QDeclarativeLayoutItem* obj = static_cast<QDeclarativeLayoutItem*>(c.create());
    QVERIFY(obj);
    QCOMPARE(obj->minimumSize(), QSizeF(100,100));
    QCOMPARE(obj->preferredSize(), QSizeF(200,200));
    QCOMPARE(obj->maximumSize(), QSizeF(300,300));

    layout->addItem(obj);
    layout->setContentsMargins(0,0,0,0);
    widget->setContentsMargins(0,0,0,0);
    view.show();

    QVERIFY(obj!= 0);

    widget->setGeometry(QRectF(0,0, 400,400));
    QCOMPARE(obj->width(), 300.0);
    QCOMPARE(obj->height(), 300.0);

    widget->setGeometry(QRectF(0,0, 300,300));
    QCOMPARE(obj->width(), 300.0);
    QCOMPARE(obj->height(), 300.0);

    widget->setGeometry(QRectF(0,0, 200,200));
    QCOMPARE(obj->width(), 200.0);
    QCOMPARE(obj->height(), 200.0);

    widget->setGeometry(QRectF(0,0, 100,100));
    QCOMPARE(obj->width(), 100.0);
    QCOMPARE(obj->height(), 100.0);

    widget->setGeometry(QRectF(0,0, 40,40));
    QCOMPARE(obj->width(), 100.0);
    QCOMPARE(obj->height(), 100.0);

    widget->setGeometry(QRectF(0,0, 412,112));
    QCOMPARE(obj->width(), 300.0);
    QCOMPARE(obj->height(), 112.0);
}
GraphicsProxySimpleBrowser::GraphicsProxySimpleBrowser(QGraphicsItem *parent) :
    QGraphicsWidget(parent)
  , mGraphicsWebView(0)
{
    QWebSettings *gs = QWebSettings::globalSettings();
    gs->setAttribute(QWebSettings::JavaEnabled, true);
    gs->setAttribute(QWebSettings::PluginsEnabled, true);
    gs->setAttribute(QWebSettings::LocalStorageDatabaseEnabled, true);
    gs->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true);
    gs->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true);
    gs->setAttribute(QWebSettings::JavascriptCanAccessClipboard, true);
    gs->setAttribute(QWebSettings::DnsPrefetchEnabled, true);

    setAutoFillBackground(true);

    mGraphicsWebView = new QGraphicsProxyWidget();
    mGraphicsWebView->setWidget(new SimpleBrowser());

    mLabel = new QLabel("QGraphicsProxyWidget");

    mCloseButton = new QToolButton();
    mCloseButton->setAutoRaise(true);
    mCloseButton->setText("X");

    QGraphicsLinearLayout *mainLayer = new QGraphicsLinearLayout(Qt::Vertical);

    QGraphicsLinearLayout *titleLayout = new QGraphicsLinearLayout(Qt::Horizontal);

    QGraphicsProxyWidget *proxyLabel = new QGraphicsProxyWidget();
    proxyLabel->setWidget(mLabel);

    QGraphicsProxyWidget *proxyCloseButton = new QGraphicsProxyWidget();
    proxyCloseButton->setWidget(mCloseButton);

    titleLayout->addItem(proxyLabel);
    titleLayout->addItem(proxyCloseButton);

    QGraphicsWidget *titleLayoutItem = new QGraphicsWidget();
    titleLayoutItem->setLayout(titleLayout);

    mainLayer->addItem(titleLayoutItem);
    mainLayer->addItem(mGraphicsWebView);

    setLayout(mainLayer);

    connect(mCloseButton, SIGNAL(clicked()), this, SLOT(on_mCloseButton_clicked()));

    setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);

}
Example #13
0
GraphScene::GraphScene(QObject *parent)
    : QGraphicsScene(parent)
    , m_gridLayout(new QGraphicsGridLayout)
    , m_inDrag(false), m_dragArrow(NULL), m_dragStartNode(NULL)
    , m_inputNode(NULL), m_outputNode(NULL)
{
    setBackgroundBrush(Qt::white);

    m_gridLayout->setHorizontalSpacing(NODEITEM_PIXEL_DISTANCE); // Set up layout-related stuff
    m_gridLayout->setVerticalSpacing(NODEITEM_PIXEL_DISTANCE);
    QGraphicsWidget *form = new QGraphicsWidget;
    form->setLayout(m_gridLayout);
    addItem(form);

    init(StandardInit);                                     // Init a standard scene
}
void SheetsPage::createContent()
{
    MApplicationPage::createContent();

    QGraphicsWidget *panel = centralWidget();

    MLayout *layout = new MLayout(panel);
    layout->setContentsMargins(0, 0, 0, 0);
    panel->setLayout(layout);
    policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    policy->setContentsMargins(0, 0, 0, 0);
    policy->setSpacing(0);

    populateLayout();

    retranslateUi();
}
/*
 * 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));
    }
}
void tst_QGraphicsLinearLayout::heightForWidth()
{
    QFETCH(bool, hfw);
    QFETCH(bool, nested);

    QGraphicsScene scene;
    QGraphicsWidget *form = new QGraphicsWidget;
    scene.addItem(form);

    QGraphicsLinearLayout *outerlayout = 0;
    if (nested) {
       outerlayout = new QGraphicsLinearLayout(form);
       for (int i = 0; i < 8; i++) {
           QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
           outerlayout->addItem(layout);
           outerlayout = layout;
       }
    }

    QGraphicsLinearLayout *qlayout = 0;
    qlayout = new QGraphicsLinearLayout(Qt::Vertical);
    if (nested)
        outerlayout->addItem(qlayout);
    else
        form->setLayout(qlayout);

    MySquareWidget *widget = new MySquareWidget;
    for (int i = 0; i < 1; i++) {
        widget = new MySquareWidget;
        QSizePolicy sizepolicy = widget->sizePolicy();
        sizepolicy.setHeightForWidth(hfw);
        widget->setSizePolicy(sizepolicy);
        qlayout->addItem(widget);
    }
    // make sure only one iteration is done.
    // run with tst_QGraphicsLinearLayout.exe "heightForWidth" -tickcounter -iterations 6
    // this will iterate 6 times the whole test, (not only the benchmark)
    // which should reduce warmup time and give a realistic picture of the performance of
    // effectiveSizeHint()
    QSizeF constraint(hfw ? 100 : -1, -1);
    QBENCHMARK {
        (void)form->effectiveSizeHint(Qt::PreferredSize, constraint);
    }

}
void MAdvancedListItemPrivate::createLayout()
{
    Q_Q(MAdvancedListItem);

    switch (listItemStyle) {
    case MAdvancedListItem::IconWithTitleProgressIndicatorAndTwoSideIcons: {
            layout()->addItem(q->imageWidget(), 0, 0, 3, 1);

            layout()->addItem(q->titleLabelWidget(), 0, 1);
            layout()->addItem(q->progressIndicator(), 1, 1);

            QGraphicsWidget * panel = new QGraphicsWidget(q);
            QGraphicsLinearLayout * panelLayout = new QGraphicsLinearLayout(Qt::Vertical);
            panelLayout->setContentsMargins(0, 0, 0, 0);
            panelLayout->setSpacing(0);
            panel->setLayout(panelLayout);

            q->sideTopImageWidget()->setParentItem(panel);
            q->sideBottomImageWidget()->setParentItem(panel);

            panelLayout->addItem(q->sideTopImageWidget());
            panelLayout->addItem(q->sideBottomImageWidget());

            layout()->addItem(panel, 0, 2, 3, 1, Qt::AlignVCenter);
            layout()->addItem(new QGraphicsWidget(q), 2, 1);

            break;
        }
    case MAdvancedListItem::IconWithTitleProgressIndicatorAndTopSideIcon: {
            q->sideTopImageWidget()->setParentItem(q);
            q->sideBottomImageWidget()->setParentItem(q);

            layout()->addItem(q->imageWidget(), 0, 0, 3, 1);
            layout()->addItem(q->titleLabelWidget(), 0, 1);
            layout()->addItem(q->progressIndicator(), 1, 1, 1, 2);
            layout()->addItem(q->sideTopImageWidget(), 0, 2, Qt::AlignBottom);
            layout()->addItem(new QGraphicsWidget(q), 2, 1);
            break;
        }
    default:
        break;
    }
}
void ActivityManager::initExtenderItem(Plasma::ExtenderItem *item) {
  // create the widget
  QGraphicsWidget *widget = new QGraphicsWidget(this);
  // TODO: use the size of the longest activity name
  widget->setPreferredWidth(350);
  // create the layout
  QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget);
  layout->setOrientation(Qt::Vertical);
  widget->setLayout(layout);
  // set up the widget
  item->setWidget(widget);
  // create a lock/unlock action
  toggleLockAction = new QAction(item);
  toggleLockAction->setIcon(KIcon("object-locked"));
  toggleLockAction->setEnabled(true);
  toggleLockAction->setVisible(true);
  toggleLockAction->setToolTip(i18n("Activities are unlocked. Click to lock."));
  item->addAction("toggleLock", toggleLockAction);
  connect(toggleLockAction, SIGNAL(triggered()), this, SLOT(toggleLock()));
}
GSequenceGraphicsScene::GSequenceGraphicsScene(GSequence *parentSeq)
	: QGraphicsScene(parentSeq)
	, m_pSeq(parentSeq)
{
	// to have the scene match the sequence length
	connect(m_pSeq, SIGNAL(LengthChanged(double)), this, SLOT(UpdateLength(double)), Qt::QueuedConnection);

	// background color
	setBackgroundBrush(QColor(230, 255, 230));

	// this is a QGraphicsWidget to use a layout in the scene
	QGraphicsWidget* pGraWid = new QGraphicsWidget();
	addItem(pGraWid);
	m_pChanLay = new QGraphicsLinearLayout(Qt::Vertical);
	pGraWid->setLayout(m_pChanLay);
	// margins from the view border
	m_pChanLay->setContentsMargins(0.0, 0.0, 0.0, 0.0);
	// spacing between channels
	m_pChanLay->setSpacing(1.0);
}
Example #20
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);
    }
}
Example #21
0
void tst_QGraphicsLayout::verifyActivate()
{
    QGraphicsScene scene;
    QGraphicsView view(&scene);

    QGraphicsWidget *window = new QGraphicsWidget();
    scene.addItem(window);
    TestLayout *lout = new TestLayout(window);
    QGraphicsWidget *w = new QGraphicsWidget();
    lout->addItem(w);
    window->setLayout(lout);

    QCOMPARE(lout->m_count, 0);
    window->setVisible(false);
    QCOMPARE(lout->m_count, 0);
    window->setVisible(true);
    // on polish or the first time a widget is shown, the widget is resized.
    QCOMPARE(lout->m_count, 1);

}
Example #22
0
void CountryPage::createContent()
{
  if (m_pageMode == CountryModel::BY_ARTIST)
    m_countryModel = new CountryModel(m_dbStorage, m_artistID);
  else
    m_countryModel = new CountryModel(m_dbStorage);

  QGraphicsWidget *panel = centralWidget();
  MLayout *layout = new MLayout(panel);
  layout->setAnimation(NULL);
  panel->setLayout(layout);
  m_policy = new MLinearLayoutPolicy(layout, Qt::Vertical);

  // No country label
  m_noCountryLabel = new MLabel(tr("No events to show.<br/>"
                                   "Possible reasons:<br/>"
                                   "<ul>"
                                   "<li>None of your artist is on tour.</li>"
                                   "<li>You don't have added an artist yet.</li>"
                                   "</ul>"));
  m_noCountryLabel->setAlignment(Qt::AlignJustify);
  if (m_countryModel->rowCount() == 0) {
    m_policy->addItem(m_noCountryLabel);
    m_noCountryLabelVisible = true;
  } else
    m_noCountryLabelVisible = false;

  MList *countryList = new MList();
  countryList->setSelectionMode(MList::SingleSelection);

  CountryItemCreator *cellCreator = new CountryItemCreator();
  countryList->setCellCreator(cellCreator);
  countryList->setItemModel(m_countryModel);
  m_policy->addItem(countryList);

  connect (countryList, SIGNAL(itemClicked(QModelIndex)),
           this, SLOT(slotCountryClicked(QModelIndex)));
  connect (DBManager::instance(m_dbStorage), SIGNAL(locationCreated(int)),
           this, SLOT(slotLocationCreated(int)));
}
QtSyncStatusLogView::QtSyncStatusLogView(QtSyncStatusLog& log, QGraphicsItem *parent)
    : HbView(parent),
      mSyncLog(log)
{
    setTitle("QtSyncStatusSpy");
    createMenu();
    
    QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(Qt::Vertical);
    HbScrollArea* scrollArea = new HbScrollArea(this);
    scrollArea->setScrollDirections(Qt::Vertical);
    QGraphicsLinearLayout* layout2 = new QGraphicsLinearLayout(Qt::Vertical);
    QGraphicsWidget* content = new QGraphicsWidget(this);
    
    mTextItem = new HbTextItem();
    layout2->addItem(mTextItem);
    layout2->setContentsMargins(5, 5, 5, 5);
    content->setLayout(layout2);
    scrollArea->setContentWidget(content);

    layout->addItem(scrollArea);
    layout->setStretchFactor(scrollArea, 1);
    setLayout(layout);
}
Example #24
0
void ArtistPage::createContent()
{
  MApplicationPage::createContent();

  QGraphicsWidget *panel = centralWidget();
  MLayout* layout = new MLayout(panel);
  m_policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
  layout->setAnimation(NULL);
  panel->setLayout(layout);
  layout->setLandscapePolicy(m_policy);
  layout->setPortraitPolicy(m_policy);

  if (m_pageMode == ALL_ARTISTS) {
    // Menu Actions
    MAction* actionImportLastfm = new MAction(panel);
    actionImportLastfm->setText(tr("Import from Last.fm"));
    actionImportLastfm->setLocation(MAction::ApplicationMenuLocation);
    addAction(actionImportLastfm);
    connect(actionImportLastfm, SIGNAL(triggered()), this, SLOT(slotImportLastfm()));

    MAction* actionAddArtist = new MAction(panel);
    actionAddArtist->setText(tr("Add artist"));
    actionAddArtist->setLocation(MAction::ApplicationMenuLocation);
    addAction(actionAddArtist);
    connect(actionAddArtist, SIGNAL(triggered()), this, SLOT(slotAddArtist()));

    // Toolbar Actions
    MAction* actionFilter = new MAction("icon-m-toolbar-filter", "", this);
    actionFilter->setLocation(MAction::ToolBarLocation);
    addAction(actionFilter);
    connect(actionFilter, SIGNAL(triggered()), this, SLOT(slotShowFilter()));
  }

  MAction* actionRefresh = new MAction("icon-m-toolbar-refresh", "", this);
  actionRefresh->setLocation(MAction::ToolBarLocation);
  addAction(actionRefresh);
  connect(actionRefresh, SIGNAL(triggered()), this, SLOT(slotRefreshEvents()));

  MAction* actionSearch = new MAction("icon-m-toolbar-search", "", this);
  actionSearch->setLocation(MAction::ToolBarLocation);
  addAction(actionSearch);
  connect(actionSearch, SIGNAL(triggered()), this, SLOT(slotShowSearch()));

  // setup model
  m_artistsModel = new ArtistModel(m_dbStorage, artistsModelQuery());

  // filtering text box
  QGraphicsLinearLayout *containerLayout = new QGraphicsLinearLayout(Qt::Horizontal);

  MLabel* filterLabel = new MLabel(tr("Filter artist:"));
  containerLayout->addItem(filterLabel);

  m_filter = new MTextEdit(MTextEditModel::SingleLine, QString());
  containerLayout->addItem(m_filter);
  m_filter->setObjectName("CommonSingleInputField");
  connect(m_filter, SIGNAL(textChanged()), this, SLOT(slotFilterChanged()));

  m_filterWidget = new MWidget();
  m_filterWidget->setLayout(containerLayout);

  // No artist found label
  m_noArtistLabel = new MLabel(tr("No artist available, add them using one of "
                                  "menu options."));
  m_noArtistLabel->setAlignment(Qt::AlignCenter);
  if (m_artistsModel->rowCount() == 0)
    m_policy->addItem(m_noArtistLabel);

  // MList with fast view
  MList* artistsList = new MList();
  artistsList->setSelectionMode(MList::SingleSelection);

  // Content item creator and item model for the list
  artistsList->setCellCreator(new ArtistItemCreator(m_pageMode, m_dbStorage,
                                                    m_country));
  artistsList->setItemModel(m_artistsModel);
  m_policy->addItem(artistsList);

  connect(artistsList, SIGNAL(itemClicked(QModelIndex)),
           this, SLOT(slotArtistClicked(QModelIndex)));
  connect(DBManager::instance(m_dbStorage), SIGNAL(artistAdded(int,bool)),
           this, SLOT(slotArtistAdded(int,bool)));

  if (m_pageMode == ARTIST_NEAR_LOCATION_SEARCH) {
    //overwrite history
    MApplicationWindow* appWindow = applicationWindow();
    MScene* scene = appWindow->scene();
    MSceneManager* sceneManager = scene->sceneManager();
    QList<MSceneWindow*> history = sceneManager->pageHistory();
    if (history.last()->metaObject()->className() == NearLocationSearchPage::staticMetaObject.className()) {
      // overwrite history only if the last page is NearLocationSearchPage
      history.removeAt(history.size()-1);
      if (history.last()->metaObject()->className() != NearLocationMainPage::staticMetaObject.className()) {
        MApplicationPage* prevPage = new NearLocationMainPage();
        history << prevPage;
      }
      sceneManager->setPageHistory(history);
    }

    //search events
    m_lastfm->getEventsNearLocation(m_latitude, m_longitude, m_distance);
  }

  if (m_dbStorage == DBManager::DISK) {
    DBManager* db = DBManager::instance(m_dbStorage);
    QStringList incompleteArtists = db->incompleteArtists();
    foreach(QString artist, incompleteArtists) {
      m_lastfm->getEventsForArtist(artist);
    }
Example #25
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QGraphicsScene scene;
    scene.setSceneRect(0, 0, 800, 480);

    QSizeF minSize(30, 100);
    QSizeF prefSize(210, 100);
    QSizeF maxSize(300, 100);

    QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A");
    QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B");
    QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C");
    QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D");
    QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E");
    QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)");
    QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)");

    QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
    l->setSpacing(0);

    QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
    w->setPos(20, 20);
    w->setLayout(l);

    // vertical
    QGraphicsAnchor *anchor = l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
    anchor = l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);

    anchor = l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
    anchor = l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
    anchor = l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);

    anchor = l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
    anchor = l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);

    anchor = l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
    anchor = l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);

    // horizontal
    anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
    anchor = l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
    anchor = l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);

    anchor = l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
    anchor = l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);

    anchor = l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
    anchor = l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
    anchor = l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);

    anchor = l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
    anchor = l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
    anchor = l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);


    scene.addItem(w);
    scene.setBackgroundBrush(Qt::darkGreen);
    QGraphicsView *view = new QGraphicsView(&scene);
    view->show();

    return app.exec();
}
Example #26
0
void WicdApplet::init()
{
    m_theme->resize(contentsRect().size());
    
    Plasma::ToolTipManager::self()->registerWidget(this);

    //load dataengine
    Plasma::DataEngine *engine = dataEngine("wicd");
    if (!engine->isValid()) {
        setFailedToLaunch(true, i18n("Unable to load the Wicd data engine."));
        return;
    }
    
    setupActions();
    
    //build the popup dialog
    QGraphicsWidget *appletDialog = new QGraphicsWidget(this);
    m_dialoglayout = new QGraphicsLinearLayout(Qt::Vertical);
    
    //Network list
    m_scrollWidget = new Plasma::ScrollWidget(appletDialog);
    m_scrollWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_scrollWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape);
    m_scrollWidget->setMaximumHeight(400);

    m_networkView = new NetworkView(m_scrollWidget);
    m_scrollWidget->setWidget(m_networkView);

    m_busyWidget = new Plasma::BusyWidget(m_scrollWidget);
    m_busyWidget->hide();

    m_dialoglayout->addItem(m_scrollWidget);
    
    //Separator
    m_dialoglayout->addItem(new Plasma::Separator(appletDialog));
    
    //Bottom bar
    QGraphicsLinearLayout* bottombarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
    
    m_messageBox = new Plasma::Label(appletDialog);
    m_messageBox->setWordWrap(false);
    bottombarLayout->addItem(m_messageBox);
    
    bottombarLayout->addStretch();
    
    m_abortButton = new Plasma::ToolButton(appletDialog);
    m_abortButton->setIcon(KIcon("dialog-cancel"));
    m_abortButton->nativeWidget()->setToolTip(i18n("Abort"));
    connect(m_abortButton, SIGNAL(clicked()), this, SLOT(cancelConnect()));
    bottombarLayout->addItem(m_abortButton);
    
    Plasma::ToolButton *reloadButton = new Plasma::ToolButton(appletDialog);
    reloadButton->nativeWidget()->setToolTip(i18n("Reload"));
    reloadButton->setAction(action("reload"));
    bottombarLayout->addItem(reloadButton);
    
    m_dialoglayout->addItem(bottombarLayout);
    
    appletDialog->setLayout(m_dialoglayout);
    setGraphicsWidget(appletDialog);

    setHasConfigurationInterface(true);
    
    // read config
    configChanged();

    connect(Plasma::Theme::defaultTheme(), SIGNAL(themeChanged()), SLOT(updateColors()));


    //prevent notification on startup
    m_status.State = 10;
    m_isScanning = false;
    //connect dataengine
    m_wicdService = engine->serviceForSource("");
    engine->connectSource("status", this);
    engine->connectSource("daemon", this);
}
// ----------------------------------------------------------------------------
// CReporterSendSelectedDialog::createcontent
// ----------------------------------------------------------------------------
void CReporterSendSelectedDialog::createcontent()
{
    Q_D(CReporterSendSelectedDialog);
    setObjectName("CrashReporterSendSelectedDialog");

    int nbrOfFiles = d_ptr->files.count();
    QString message;

    if (nbrOfFiles == 1) {
        //% "<p>This system has 1 stored crash report. Select reports to send to %1 for analysis or to delete.</p>"
        message = qtTrId("qtn_system_has_1_crash_report_send_to_%s").arg(d->server);

    }
    else {
        //% "<p>This system has %1 stored crash reports. Select reports to send to %2 for analysis or to delete.</p>"
        message = qtTrId("qtn_system_has_%1_crash_reports_send_to_%2").arg(nbrOfFiles).arg(d->server);

    }

    // Create content to be placed on central widget.
    QGraphicsWidget *panel = centralWidget();

    // Create layout and policy.
    MLayout *layout = new MLayout(panel);
    layout->setContentsMargins(0,0,0,0);
    panel->setLayout(layout);
    MLinearLayoutPolicy  *policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    policy->setObjectName("DialogMainLayout");

    // Create message label and hack it to support wordwrapping
    MLabel *messagelabel = new MLabel(message, panel);
    messagelabel->setWordWrap(true);
    messagelabel->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
    messagelabel->setObjectName("DialogMessageLabel");
    messagelabel->setStyleName("CommonFieldLabelInverted");

    d->list = new MList(panel);
    d->cellCreator = new MContentItemCreator;

    d->list->setCellCreator(d->cellCreator);
    d->model = new CReporterSendFileListModel(d->files);
    d->list->setItemModel(d->model);
    d->list->setSelectionMode(MList::MultiSelection);

    // Add widgets to the layout
    policy->addItem(messagelabel, Qt::AlignLeft | Qt::AlignTop);
    policy->addItem(d->list, Qt::AlignLeft | Qt::AlignTop);

    // Add buttons to button area.
    QSignalMapper *mapper = new QSignalMapper(this);
    //% "Send Selected"
    MButton* dialogButton = new MButton(qtTrId("qtn_send_selected_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    MButtonModel *dialogButton = addButton(qtTrId("qtn_send_selected_button"), M::ActionRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::SendSelectedButton));

    //% "Send All"
    dialogButton = new MButton(qtTrId("qtn_send_all_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    dialogButton = addButton(qtTrId("qtn_send_all_button"), M::ActionRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::SendAllButton));

    //% "Delete Selected"
    dialogButton = new MButton(qtTrId("qtn_delete_selected_button"));
    dialogButton->setStyleName("CommonSingleButtonInverted");
    policy->addItem(dialogButton, Qt::AlignCenter);
//    dialogButton = addButton(qtTrId("qtn_delete_selected_button"), M::DestructiveRole);
    connect(dialogButton, SIGNAL(clicked()), mapper, SLOT(map()));
    mapper->setMapping(dialogButton, static_cast<int>(CReporter::DeleteSelectedButton));

    connect(mapper, SIGNAL(mapped(int)), SIGNAL(actionPerformed(int)));
    connect(mapper, SIGNAL(mapped(int)), SLOT(accept()));
}
Example #28
0
void tst_QGraphicsLayout::automaticReparenting()
{
    QGraphicsView view;
    QGraphicsScene scene;
    {
        QGraphicsWidget *w = new QGraphicsWidget();
        QGraphicsLinearLayout *l = new QGraphicsLinearLayout(w);
        QGraphicsWidget *w1 = new QGraphicsWidget;
        l->addItem(w1);
        scene.addItem(w);
        QCOMPARE(w1->parentWidget(), w);
        delete w;
    }
    {
        QGraphicsWidget *w = new QGraphicsWidget();
        QGraphicsLinearLayout *l = new QGraphicsLinearLayout(w);
        QGraphicsWidget *w1 = new QGraphicsWidget;
        l->addItem(w1);
        scene.addItem(w);
        QCOMPARE(w1->parentWidget(), w);

        QGraphicsWidget *ww = new QGraphicsWidget();
        QGraphicsLinearLayout *l1 = new QGraphicsLinearLayout(ww);
#ifdef QT_DEBUG
        QTest::ignoreMessage(QtWarningMsg, "QGraphicsLayout::addChildLayoutItem: QGraphicsWidget \"\""
                             " in wrong parent; moved to correct parent");
#endif
        l1->addItem(w1);
        QCOMPARE(w1->parentWidget(), ww);
        delete w;
    }

    QGraphicsWidget *window = new QGraphicsWidget();
    scene.addItem(window);
    view.show();
    QGraphicsLinearLayout *l1 = new QGraphicsLinearLayout();
    QGraphicsWidget *w1 = new QGraphicsWidget();
    l1->addItem(w1);
    QGraphicsWidget *w2 = new QGraphicsWidget();
    l1->addItem(w2);
    QCOMPARE(w1->parentItem(), static_cast<QGraphicsItem*>(0));
    QCOMPARE(w2->parentItem(), static_cast<QGraphicsItem*>(0));
    scene.addItem(w1);
    QCOMPARE(w1->parentItem(), static_cast<QGraphicsItem*>(0));
    window->setLayout(l1);
    QCOMPARE(w1->parentItem(), static_cast<QGraphicsItem*>(window));
    QCOMPARE(w2->parentItem(), static_cast<QGraphicsItem*>(window));

    // Sublayouts    
    QGraphicsLinearLayout *l2 = new QGraphicsLinearLayout();
    QGraphicsWidget *w3 = new QGraphicsWidget();
    l2->addItem(w3);
    QGraphicsWidget *w4 = new QGraphicsWidget();
    l2->addItem(w4);
    QGraphicsLinearLayout *l3 = new QGraphicsLinearLayout();
    l2->addItem(l3);
    QGraphicsWidget *window2 = new QGraphicsWidget();
    scene.addItem(window2);
    window2->setLayout(l2);

    QCOMPARE(w3->parentItem(), static_cast<QGraphicsItem*>(window2));
    QCOMPARE(w4->parentItem(), static_cast<QGraphicsItem*>(window2));

    // graphics item with another parent
    QGraphicsLinearLayout *l5 = new QGraphicsLinearLayout();
    l5->addItem(w1);
    l5->addItem(w2);
    QCOMPARE(w1->parentItem(), static_cast<QGraphicsItem*>(window));
    QCOMPARE(w2->parentItem(), static_cast<QGraphicsItem*>(window));
    QGraphicsLinearLayout *l4 = new QGraphicsLinearLayout();
    l4->addItem(l5);
    QGraphicsWidget *window3 = new QGraphicsWidget();
    scene.addItem(window3);
    window3->setLayout(l4);

    QCOMPARE(w1->parentItem(), static_cast<QGraphicsItem*>(window3));
    QCOMPARE(w2->parentItem(), static_cast<QGraphicsItem*>(window3));
}
void Ut_MGridLayoutPolicy::testHeightForWidthInSubLayout()
{
    QFETCH(bool, useMLayout);
    QFETCH(bool, useInnerMLayout);
    QFETCH(bool, putInnerWidgetInWidget);

    QGraphicsWidget *form = new QGraphicsWidget;


    MGridLayoutPolicy *mpolicy = NULL;
    QGraphicsGridLayout *qlayout = NULL;

    if (useMLayout) {
        MLayout *mlayout = new MLayout(form);
        mlayout->setContentsMargins(0, 0, 0, 0);
        mpolicy = new MGridLayoutPolicy(mlayout);
        mpolicy->setSpacing(0);
    } else {
        qlayout = new QGraphicsGridLayout(form);
        qlayout->setContentsMargins(0, 0, 0, 0);
        qlayout->setSpacing(0);
    }

    QGraphicsWidget *topSpacer = createSpacer();
    QGraphicsWidget *leftSpacer = createSpacer();
    QGraphicsWidget *rightSpacer = createSpacer();
    leftSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    rightSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

    QGraphicsWidget *square = new SquareWidget;

    QGraphicsLayout *innerLayout = NULL;
    if (useInnerMLayout) {
        innerLayout = new MLayout();
        MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(static_cast<MLayout *>(innerLayout), Qt::Horizontal);
        policy->addItem(square);
    } else {
        innerLayout = new QGraphicsLinearLayout(Qt::Horizontal);
        static_cast<QGraphicsLinearLayout *>(innerLayout)->addItem(square);
    }
    innerLayout->setContentsMargins(0,0,0,0);

    QGraphicsLayoutItem *innerItem;
    if (putInnerWidgetInWidget) {
        QGraphicsWidget *innerWidget = new QGraphicsWidget;
        innerWidget->setLayout(innerLayout);
        innerItem = innerWidget;
    } else {
        innerItem = innerLayout;
    }

    if (useMLayout) {
        mpolicy->addItem(topSpacer, 0, 1);
        mpolicy->addItem(leftSpacer, 1, 0);
        mpolicy->addItem(rightSpacer, 1, 2);
        mpolicy->addItem(innerItem, 1, 1);
    } else {
        qlayout->addItem(topSpacer, 0, 1);
        qlayout->addItem(leftSpacer, 1, 0);
        qlayout->addItem(rightSpacer, 1, 2);
        qlayout->addItem(innerItem, 1, 1);
    }


    QCOMPARE(form->preferredSize(), QSizeF(500,500));
    QCOMPARE(form->effectiveSizeHint(Qt::PreferredSize, QSizeF(100,-1)), QSizeF(100,100));

    delete form;
}
Example #30
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();
}