Ejemplo n.º 1
0
//ui--->qml
void PropertiesPane::setSGameName(QString name)
{
    if(namepr.isEmpty())
        return;
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("objectName",name);
}
Ejemplo n.º 2
0
void QmlWindowRenderer::setupPixelStreamItem()
{
    PixelStream* stream = static_cast<PixelStream*>( wallContent_.get( ));
    windowContext_->setContextProperty( "pixelstream", stream );
    QDeclarativeItem* pixelStreamItem = createQmlItem( QML_PIXELSTREAM_URL );
    pixelStreamItem->setParentItem( windowItem_ );
}
Ejemplo n.º 3
0
void LiveViewWindow::showSingleCamera(DVRCamera *camera)
{
    m_liveView->layout()->setGridSize(1, 1);
    QDeclarativeItem *item = m_liveView->layout()->addItem(0, 0);
    if (item)
        item->setProperty("camera", QVariant::fromValue(camera));
}
void KinoafishaWidget::setCinamaList(const QList<Cinema *> cinemaList)
{
    QTime progressTime;
    qDebug() << "Set cinema list to qmlView...";
    progressTime.start();
    QSettings settings;
    QString affishaQmlPatch = settings.value(SETT_KEY_KINOAFISHA_QML_PATCH,
                                             QCoreApplication::applicationDirPath() +
                                             DEFATUL_SETT_VALUE_KINOAFISHA_QML_PATCH).toString();
    qDebug() << "Load qml " << affishaQmlPatch + "/Affisha.qml...";
    QTime loadTime;
    loadTime.start();
    if (!QFile::exists(affishaQmlPatch + "/Affisha.qml"))
    {
        qWarning() << "Affisha.qml not found";
        return;
    }
    setSource(QUrl::fromLocalFile(affishaQmlPatch + "/Affisha.qml"));
    qDebug() << "Load qml finished in " << loadTime.elapsed();
    QDeclarativeItem * rootItem = qobject_cast<QDeclarativeItem *>(rootObject());
    qDebug() << "Kinoafisha widget width " << _screenWidth <<" height " << _screenHeight;
    rootItem->setWidth(_screenWidth);
    rootItem->setHeight(_screenHeight);
    connect(rootObject(), SIGNAL(trailerPlayFinished(int)), this, SIGNAL(traylerPlayedFinised(int)));
    foreach (Cinema *currentCinema, cinemaList)
    {
        addCinema(currentCinema);
    }
Ejemplo n.º 5
0
void PropertiesPane::setSParent(QString f)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("parentName",f);
//    qDebug()<<f;

}
Ejemplo n.º 6
0
void
E6Irc::fixCaps (QObject * root)
{
  if (root) {
    objectCount++;
    QVariant suppressVar = root->property ("noInitialCaps");
    if (suppressVar.isValid()) {
      qDebug () << "found property on " << root ;
      qDebug () << suppressVar;
      if (suppressVar.type() == QVariant::Bool) {
        bool suppress = suppressVar.toBool();
        if (suppress) {
          QDeclarativeItem * item = qobject_cast<QDeclarativeItem*> (root);
          if (item) {
            item->setInputMethodHints (Qt::ImhNoAutoUppercase);
          }
        }
      }
    }
    QObjectList children = root->children();
    for (int i=0; i<children.count(); i++) {
      fixCaps (children.at(i));
    }
  }
}
static void specialSetParentForQmlGraphicsItemChildren(QObject *object, QDeclarativeItem *parent)
{
    QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(object);
    if (item)
        item->setParentItem(parent);
    else
        object->setParent(parent);
}
Ejemplo n.º 8
0
bool QDeclarativeMouseArea::sendMouseEvent(QGraphicsSceneMouseEvent *event)
{
    Q_D(QDeclarativeMouseArea);
    QGraphicsSceneMouseEvent mouseEvent(event->type());
    QRectF myRect = mapToScene(QRectF(0, 0, width(), height())).boundingRect();

    QGraphicsScene *s = scene();
    QDeclarativeItem *grabber = s ? qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem()) : 0;
    bool stealThisEvent = d->stealMouse;
    if ((stealThisEvent || myRect.contains(event->scenePos().toPoint())) && (!grabber || !grabber->keepMouseGrab())) {
        mouseEvent.setAccepted(false);
        for (int i = 0x1; i <= 0x10; i <<= 1) {
            if (event->buttons() & i) {
                Qt::MouseButton button = Qt::MouseButton(i);
                mouseEvent.setButtonDownPos(button, mapFromScene(event->buttonDownPos(button)));
            }
        }
        mouseEvent.setScenePos(event->scenePos());
        mouseEvent.setLastScenePos(event->lastScenePos());
        mouseEvent.setPos(mapFromScene(event->scenePos()));
        mouseEvent.setLastPos(mapFromScene(event->lastScenePos()));

        switch(mouseEvent.type()) {
        case QEvent::GraphicsSceneMouseMove:
            mouseMoveEvent(&mouseEvent);
            break;
        case QEvent::GraphicsSceneMousePress:
            mousePressEvent(&mouseEvent);
            break;
        case QEvent::GraphicsSceneMouseRelease:
            mouseReleaseEvent(&mouseEvent);
            break;
        default:
            break;
        }
        grabber = qobject_cast<QDeclarativeItem*>(s->mouseGrabberItem());
        if (grabber && stealThisEvent && !grabber->keepMouseGrab() && grabber != this)
            grabMouse();

        return stealThisEvent;
    }
    if (mouseEvent.type() == QEvent::GraphicsSceneMouseRelease) {
        if (d->pressed) {
            d->pressed = false;
            d->stealMouse = false;
            if (s && s->mouseGrabberItem() == this)
                ungrabMouse();
            emit canceled();
            emit pressedChanged();
            if (d->hovered) {
                d->hovered = false;
                emit hoveredChanged();
            }
        }
    }
    return false;
}
void QDeclarativeBasePositioner::prePositioning()
{
    Q_D(QDeclarativeBasePositioner);
    if (!isComponentComplete())
        return;

    if (d->doingPositioning)
        return;

    d->queuedPositioning = false;
    d->doingPositioning = true;
    //Need to order children by creation order modified by stacking order
    QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
    qSort(children.begin(), children.end(), d->insertionOrder);

    QPODVector<PositionedItem,8> oldItems;
    positionedItems.copyAndClear(oldItems);
    for (int ii = 0; ii < children.count(); ++ii) {
        QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
        if (!child)
            continue;
        QDeclarativeItemPrivate *childPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(child));
        PositionedItem *item = 0;
        PositionedItem posItem(child);
        int wIdx = oldItems.find(posItem);
        if (wIdx < 0) {
            d->watchChanges(child);
            positionedItems.append(posItem);
            item = &positionedItems[positionedItems.count()-1];
            item->isNew = true;
            if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden)
                item->isVisible = false;
        } else {
            item = &oldItems[wIdx];
            // Items are only omitted from positioning if they are explicitly hidden
            // i.e. their positioning is not affected if an ancestor is hidden.
            if (child->opacity() <= 0.0 || childPrivate->explicitlyHidden) {
                item->isVisible = false;
            } else if (!item->isVisible) {
                item->isVisible = true;
                item->isNew = true;
            } else {
                item->isNew = false;
            }
            positionedItems.append(*item);
        }
    }
    QSizeF contentSize;
    doPositioning(&contentSize);
    if(d->addTransition || d->moveTransition)
        finishApplyTransitions();
    d->doingPositioning = false;
    //Set implicit size to the size of its children
    setImplicitHeight(contentSize.height());
    setImplicitWidth(contentSize.width());
}
Ejemplo n.º 10
0
void QDeclarativeBasePositioner::prePositioning()
{
    Q_D(QDeclarativeBasePositioner);
    if (!isComponentComplete())
        return;

    d->queuedPositioning = false;
    //Need to order children by creation order modified by stacking order
    QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
    qSort(children.begin(), children.end(), d->insertionOrder);

    QPODVector<PositionedItem,8> oldItems;
    positionedItems.copyAndClear(oldItems);
    for (int ii = 0; ii < children.count(); ++ii) {
        QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(ii));
        if (!child)
            continue;
        PositionedItem *item = 0;
        PositionedItem posItem(child);
        int wIdx = oldItems.find(posItem);
        if (wIdx < 0) {
            d->watchChanges(child);
            positionedItems.append(posItem);
            item = &positionedItems[positionedItems.count()-1];
            item->isNew = true;
            if (child->opacity() <= 0.0 || !child->isVisible())
                item->isVisible = false;
        } else {
            item = &oldItems[wIdx];
            if (child->opacity() <= 0.0 || !child->isVisible()) {
                item->isVisible = false;
            } else if (!item->isVisible) {
                item->isVisible = true;
                item->isNew = true;
            } else {
                item->isNew = false;
            }
            positionedItems.append(*item);
        }
    }
    doPositioning();
    if(d->addTransition || d->moveTransition)
        finishApplyTransitions();
    //Set implicit size to the size of its children
    qreal h = 0.0f;
    qreal w = 0.0f;
    for (int i = 0; i < positionedItems.count(); ++i) {
        const PositionedItem &posItem = positionedItems.at(i);
        if (posItem.isVisible) {
            h = qMax(h, posItem.item->y() + posItem.item->height());
            w = qMax(w, posItem.item->x() + posItem.item->width());
        }
    }
    setImplicitHeight(h);
    setImplicitWidth(w);
}
void QDeclarativeViewInspector::reparentQmlObject(QObject *object, QObject *newParent)
{
    if (!newParent)
        return;

    object->setParent(newParent);
    QDeclarativeItem *newParentItem = qobject_cast<QDeclarativeItem*>(newParent);
    QDeclarativeItem *item    = qobject_cast<QDeclarativeItem*>(object);
    if (newParentItem && item)
        item->setParentItem(newParentItem);
}
bool MInverseMouseArea::isClickedOnSoftwareInputPanel(QGraphicsSceneMouseEvent *event) const
{
    QGraphicsItem * item = scene()->itemAt(event->scenePos());
    while(item != NULL) {
        QDeclarativeItem * declItem = dynamic_cast<QDeclarativeItem *>(item);
        if(declItem != NULL && declItem->objectName() == "softwareInputPanel")
            return true;

        item = item->parentItem();
    }
    return false;
}
Ejemplo n.º 13
0
//QTBUG-18362
void tst_qdeclarativebehaviors::delayedRegistration()
{
    QDeclarativeEngine engine;

    QDeclarativeComponent c(&engine, SRCDIR "/data/delayedRegistration.qml");
    QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle*>(c.create());
    QVERIFY(rect != 0);

    QDeclarativeItem *innerRect = rect->property("myItem").value<QDeclarativeItem*>();
    QVERIFY(innerRect != 0);

    QCOMPARE(innerRect->property("x").toInt(), int(0));

    QTRY_COMPARE(innerRect->property("x").toInt(), int(100));
}
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);
}
QPointF MInverseMouseArea::mapToRootItem(QPointF pos) {
    QPointF mappedPos = pos;
    QDeclarativeItem *rootItem = parentItem();

    while (rootItem->parentItem()) {
        if (rootItem->objectName() == "windowContent") {
            break;
        }
        rootItem = rootItem->parentItem();
    }

    if (rootItem) {
        mappedPos = rootItem->mapFromScene(pos);
    }

    return mappedPos;
}
Ejemplo n.º 16
0
void
Panto::start ()
{    

  if (isProbablyPhone) {
    showFullScreen ();
  }
  setSource (QUrl("qrc:/qml/main.qml"));
  if (sizeSet) {
    resize (desiredSize);
  }
  show ();
  
  QDeclarativeItem * root = qobject_cast <QDeclarativeItem*> (rootObject());
  qDebug () << PANTO_PRETTY_FUNCTION << " root " << root;
  if (root) {
    #if 0
    QDeclarativeItem * mouseArea = root->findChild<QDeclarativeItem*> ("GestureTrap");
    if (mouseArea) {
      mouseArea->grabGesture (loopType);
      mouseArea->installEventFilter (this);
    }
    QDeclarativeItem * bigButton = root->findChild<QDeclarativeItem*> ("BigButton");
    if (bigButton) {
      bigButton->grabGesture (loopType);
      bigButton->installEventFilter (this);
    }
    #endif
  }

  //QTimer::singleShot (10*1000, this, SLOT(allDone()));
}
void SDeclarativeIndicatorContainer::doLayoutChildren()
{
    Q_D(SDeclarativeIndicatorContainer);

    int xPosition = 0;
    int itemsShown = 0;
    const QSize itemSize(d->indicatorSize);

    for (int i = 0; i < childItems().count(); i++) {
        QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(childItems().at(i)->toGraphicsObject());
        if (child && child->isVisible()) {
            if (itemsShown >= d->maxIndicatorCount && d->maxIndicatorCount >= 0) {
                child->setSize(QSize(0, 0));
                continue;
            }

            if (itemsShown++)
                xPosition += d->indicatorPadding;

            child->setPos(xPosition, 0);
            child->setSize(itemSize);

            xPosition += child->width();
        }
    }

    setImplicitWidthNotify(xPosition);
    setImplicitHeightNotify(itemSize.height());
    d->layoutRequestPending = false;
}
Ejemplo n.º 18
0
void MaskedItem::setMask(QDeclarativeComponent *component)
{
    if (m_maskComponent == component)
        return;

    QDeclarativeItem *mask = 0;

    if (component) {
        QObject *object = component->create(component->creationContext());
        mask = qobject_cast<QDeclarativeItem *>(object);

        if (!mask)
            qWarning("MaskedItem: Unable to create mask element.");
        else if (!mask->childItems().isEmpty())
            qWarning("MaskedItem: Mask element has children. Due to current limitation, they won't be painted.");
    }

    m_effect->setMask(mask);
    m_maskComponent = component;

    emit maskChanged();
}
Ejemplo n.º 19
0
void ViewManager::ViewManagerPrivate::slotLockedChanged(bool locked)
{
    if(locked) {
        // When the view is locked, all draggers should be destroyed
        QMapIterator<WidgetProperties *, QDeclarativeItem *> iterator =
                QMapIterator<WidgetProperties *, QDeclarativeItem *>(registeredDraggers);
        while (iterator.hasNext()) {
            iterator.next();
            QDeclarativeItem *item = iterator.value();
            registeredDraggers.remove(iterator.key());
            item->deleteLater();
        }

        q->setCurrentDraggedWidget("");
    } else {
        // For each item in the current page, a dragger should
        // be created
        DisplayedPageWidgetsModel * pageModel = displayedPagesModel->pageModel(currentPageIndex);
        for (int i = 0; i < pageModel->rowCount(); i++) {
            emit q->requestCreateDragger(pageModel->widget(i));
        }
    }
}
Ejemplo n.º 20
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

//![QDeclarativeView]
// Using QDeclarativeView
QDeclarativeView view;
view.setSource(QUrl::fromLocalFile("MyItem.qml"));
view.show();
QObject *object = view.rootObject();
//![QDeclarativeView]

//![properties]
object->setProperty("width", 500);
QDeclarativeProperty(object, "width").write(500);
//![properties]

//![cast]
QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(object);
item->setWidth(500);
//![cast]

//![findChild]
QObject *rect = object->findChild<QObject*>("rect");
if (rect)
    rect->setProperty("color", "red");
//![findChild]

//![QDeclarativeComponent-b]
delete object;
//![QDeclarativeComponent-b]

withComponent();

    return app.exec();
}
Ejemplo n.º 21
0
void PropertiesPane::setSXanchor(int xanchor)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("anchorX",xanchor);
//    qDebug()<<"anchorx:"<<xanchor;
}
Ejemplo n.º 22
0
void PropertiesPane::setSVisible(bool value)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("shadowVisible",value);
}
Ejemplo n.º 23
0
void PropertiesPane::setSRow(int row)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("rows",row);
}
Ejemplo n.º 24
0
void PropertiesPane::setSCol(int col)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("cols",col);
}
Ejemplo n.º 25
0
void PropertiesPane::setSScale(double value)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("scale",value);
}
Ejemplo n.º 26
0
void TimelineView::updateTimeline(bool updateStartX)
{
    if (!m_delegate)
        return;

    if (!m_ranges.isArray())
        return;

    int length = m_ranges.property("length").toInt32();

    qreal startValue = m_ranges.property(0).property("start").toNumber();
    qreal endValue = m_ranges.property(length-1).property("start").toNumber() + m_ranges.property(length-1).property("duration").toNumber();

    qreal totalRange = endValue - startValue;
    qreal window = m_endTime - m_startTime;

    if (window == 0)    //###
        return;

    qreal spacing = width() / window;
    qreal oldtw = m_totalWidth;
    m_totalWidth = totalRange * spacing;

    // Find region samples
    int minsample = 0;
    int maxsample = 0;

    for (int i = 0; i < length; ++i) {
        if (m_ends.at(i) >= m_startTime)
            break;
        minsample = i;
    }

    for (int i = minsample + 1; i < length; ++i) {
        maxsample = i;
        if (m_starts.at(i) > m_endTime)
            break;
    }

    //### overkill (if we can expose whether or not data is nested)
    for (int i = maxsample + 1; i < length; ++i) {
        if (m_starts.at(i) < m_endTime)
            maxsample = i;
    }

    //qDebug() << maxsample - minsample;

    if (updateStartX) {
        qreal oldStartX = m_startX;
        m_startX = qRound(m_startTime * spacing);
        if (m_startX != oldStartX) {
            emit startXChanged(m_startX);
        }
    }

    //### emitting this before startXChanged was causing issues
    if (m_totalWidth != oldtw)
        emit totalWidthChanged(m_totalWidth);

    //clear items no longer in view
    while (prevMin < minsample) {
        delete m_items.take(prevMin);
        ++prevMin;
    }
    while (prevMax > maxsample) {
        delete m_items.take(prevMax);
        --prevMax;
    }

    // Show items
    int z = 0;
    for (int i = maxsample-1; i >= minsample; --i) {
        QDeclarativeItem *item = 0;
        item = m_items.value(i);
        bool creating = false;
        if (!item) {
            QDeclarativeContext *ctxt = new QDeclarativeContext(qmlContext(this));
            item = qobject_cast<QDeclarativeItem*>(m_delegate->beginCreate(ctxt));
            m_items.insert(i, item);
            creating = true;

            int type = m_ranges.property(i).property("type").toNumber();

            ctxt->setParent(item); //### QDeclarative_setParent_noEvent(ctxt, item); instead?
            ctxt->setContextProperty("duration", qMax(qRound(m_ranges.property(i).property("duration").toNumber()/qreal(1000)),1));
            ctxt->setContextProperty("fileName", m_ranges.property(i).property("fileName").toString());
            ctxt->setContextProperty("line", m_ranges.property(i).property("line").toNumber());
            QString label;
            QVariantList list = m_ranges.property(i).property("label").toVariant().value<QVariantList>();
            for (int i = 0; i < list.size(); ++i) {
                if (i > 0)
                    label += QLatin1Char('\n');
                QString sub = list.at(i).toString();

                //### only do rewrite for bindings...
                if (type == 3) {
                    //### don't construct in loop
                    QRegExp rewrite("\\(function \\$(\\w+)\\(\\) \\{ return (.+) \\}\\)");
                    bool match = rewrite.exactMatch(sub);
                    if (match)
                        sub = rewrite.cap(1) + ": " + rewrite.cap(2);
                }

                label += sub;
            }
            ctxt->setContextProperty("label", label);
            ctxt->setContextProperty("type", type);
            item->setParentItem(this);
        }
        if (item) {
            item->setX(m_starts.at(i)*spacing);
            item->setWidth((m_ends.at(i)-m_starts.at(i)) * spacing);
            item->setZValue(++z);
        }
        if (creating)
            m_delegate->completeCreate();
    }

    prevMin = minsample;
    prevMax = maxsample;
}
Ejemplo n.º 27
0
void PropertiesPane::setSYanchor(int yanchor)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("anchorY",yanchor);
}
Ejemplo n.º 28
0
void PropertiesPane::setSH(int h)
{
    QDeclarativeItem* tm = root->findChild<QDeclarativeItem *>(namepr);
    tm->setProperty("h",h);
}
Ejemplo n.º 29
0
int Dialog::showDialog(const QString& view, QObject* viewModel, int type)
{
    QDialog* dialog = NULL;
    QMainWindow* mainWindow = NULL;
    QWidget* windowWidget = NULL;
    QWidget* layoutWidget = NULL;

    switch (type)
    {
    case Dialog::MainWindow:
        mainWindow = new QMainWindow();
        windowWidget = mainWindow;
        layoutWidget = new QWidget(windowWidget);
        mainWindow->setCentralWidget(layoutWidget);
        break;

    case Dialog::ModalDialog:
        dialog = new QDialog(QApplication::activeWindow());
        windowWidget = dialog;
        layoutWidget = dialog;
        break;

    default:
        dialog = new QDialog();
        windowWidget = dialog;
        layoutWidget = dialog;
        break;
    }

    QGridLayout* layout = new QGridLayout(layoutWidget);

    // Create view

    QDeclarativeView* v = new QDeclarativeView(layoutWidget);

    if (viewModel)
    {
        int count = viewModel->metaObject()->propertyCount();
        for (int i = 0; i < count; ++i)
        {
            QMetaProperty p = viewModel->metaObject()->property(i);
            if (p.isReadable() && p.typeName() == QString("QDeclarativeImageProvider*"))
            {
                QString name = p.name();
                QDeclarativeImageProvider* value = p.read(viewModel).value<QDeclarativeImageProvider*>();

                v->engine()->addImageProvider(name.toLatin1(), new ProxyImageProvider(value));
            }
        }

        v->rootContext()->setContextProperty("dataContext", viewModel);
    }

    QString path;
    foreach (path, importPaths)
        v->engine()->addImportPath(path);
    foreach (path, pluginPaths)
        v->engine()->addPluginPath(path);

    v->setSource(QUrl(view));
    v->setResizeMode(QDeclarativeView::SizeRootObjectToView);

    // Initialize dialog

    QGraphicsObject* root = v->rootObject();

    QVariant property = root->property("dialogTitle");
    if (property.isValid())
        windowWidget->setWindowTitle(property.toString());

    property = root->property("dialogMinWidth");
    if (property.isValid())
        layoutWidget->setMinimumWidth(property.toInt());

    property = root->property("dialogMinHeight");
    if (property.isValid())
        layoutWidget->setMinimumHeight(property.toInt());

    property = root->property("dialogMaxWidth");
    if (property.isValid())
        layoutWidget->setMaximumWidth(property.toInt());

    property = root->property("dialogMaxHeight");
    if (property.isValid())
        layoutWidget->setMaximumHeight(property.toInt());

    property = root->property("dialogResizable");
    if (property.isValid() && !property.toBool())
        layout->setSizeConstraint(QLayout::SetFixedSize);

    Qt::WindowStates states = windowWidget->windowState();
    Qt::WindowFlags flags = windowWidget->windowFlags();

    property = root->property("dialogMinimizeButton");
    if (property.isValid())
        flags = property.toBool() ? flags | Qt::WindowMinimizeButtonHint : flags & ~Qt::WindowMinimizeButtonHint;

    property = root->property("dialogMaximizeButton");
    if (property.isValid())
        flags = property.toBool() ? flags | Qt::WindowMaximizeButtonHint : flags & ~Qt::WindowMaximizeButtonHint;

    property = root->property("dialogCloseButton");
    if (property.isValid())
        flags = property.toBool() ? flags | Qt::WindowCloseButtonHint : flags & ~Qt::WindowCloseButtonHint;

    property = root->property("dialogFullScreen");
    if (property.isValid())
        states = property.toBool() ? states | Qt::WindowFullScreen : states & ~Qt::WindowFullScreen;

    flags = flags & ~Qt::WindowContextHelpButtonHint;

    windowWidget->setWindowFlags(flags);
    windowWidget->setWindowState(states);

    property = root->property("dialogToolBar");
    if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>"))
    {
        QToolBar* toolbar = new QToolBar(mainWindow);
        toolbar->setMovable(false);
        toolbar->setFloatable(false);
        toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
        toolbar->setAllowedAreas(Qt::TopToolBarArea);

        QDeclarativeListProperty<QDeclarativeItem> btnList = property.value< QDeclarativeListProperty<QDeclarativeItem> >();
        int btnCount = btnList.count(&btnList);

        for (int i = 0; i < btnCount; ++i)
        {
            QDeclarativeItem* item = btnList.at(&btnList, i);

            if (!item->property("text").isValid())
                continue;

            QString itemText = item->property("text").toString();
            QString itemTooltip = item->property("tooltip").isValid() ? item->property("tooltip").toString() : "";
            QString itemIconSource = item->property("iconSource").isValid() ? item->property("iconSource").toString() : "";
            int itemIconSize = item->property("iconSize").isValid() ? item->property("iconSize").toInt() : -1;

            if (itemText == "|")
            {
                toolbar->addSeparator();
            }
            else if (itemText == "-")
            {
                QWidget* spacer = new QWidget();
                spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
                toolbar->addWidget(spacer);
            }
            else
            {
                QAction* action = new QAction(mainWindow);
                action->setText(itemText);
                action->setToolTip(itemTooltip);
                action->setIcon(QIcon(itemIconSource));
                QObject::connect(action, SIGNAL(triggered()), item, SLOT(trigger()));

                if (item->property("enabled").isValid())
                    new PropertyBinding(action, "enabled", item, "enabled", PropertyBinding::OneWay, NULL, this);

                if (item->property("visible").isValid())
                    new PropertyBinding(action, "visible", item, "visible", PropertyBinding::OneWay, NULL, this);

                toolbar->addAction(action);
            }

            if (itemIconSize != -1)
                toolbar->setIconSize(QSize(itemIconSize, itemIconSize));
        }

        mainWindow->setUnifiedTitleAndToolBarOnMac(true);
        mainWindow->addToolBar(toolbar);
    }

    property = root->property("dialogMenu");
    if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>"))
    {
        QDeclarativeListProperty<QDeclarativeItem> list = property.value< QDeclarativeListProperty<QDeclarativeItem> >();
        int count = list.count(&list);

        for (int i = 0; i < count; ++i)
        {
            QDeclarativeItem* item = list.at(&list, i);

            if (!item->property("text").isValid())
                continue;

            QString itemText = item->property("text").toString();
            QMenu * menuItem = mainWindow->menuBar()->addMenu(itemText);

            if (!item->property("submenu").isValid() || item->property("submenu").typeName() != QString("QDeclarativeListProperty<QDeclarativeItem>"))
                continue;

            QDeclarativeListProperty<QDeclarativeItem> innerList = item->property("submenu").value< QDeclarativeListProperty<QDeclarativeItem> >();
            int innerCount = innerList.count(&innerList);

            for (int j = 0; j < innerCount; ++j)
            {
                QDeclarativeItem* innerItem = innerList.at(&innerList, j);

                if (!innerItem->property("text").isValid())
                    continue;

                QString innerItemText = innerItem->property("text").toString();
                QString innerItemShortcut = innerItem->property("shortcut").isValid() ? innerItem->property("shortcut").toString() : "";
                QString innerItemIconSource = innerItem->property("iconSource").isValid() ? innerItem->property("iconSource").toString() : "";

                if (innerItemText == "-")
                {
                    menuItem->addSeparator();
                }
                else
                {
                    QAction * action = menuItem->addAction(QIcon(innerItemIconSource), innerItemText);
                    action->setShortcut(QKeySequence(innerItemShortcut));

                    QObject::connect(action, SIGNAL(triggered()), innerItem, SLOT(trigger()));

                    if (innerItem->property("enabled").isValid())
                        new PropertyBinding(action, "enabled", innerItem, "enabled", PropertyBinding::OneWay, NULL, this);

                    if (innerItem->property("visible").isValid())
                        new PropertyBinding(action, "visible", innerItem, "visible", PropertyBinding::OneWay, NULL, this);
                }
            }
        }
    }

    new DialogCallbacks(windowWidget, v, root);

    // Initialize layout

    layout->setMargin(0);
    layout->addWidget(v, 0, 0);

    // Execute

    switch (type)
    {
    case Dialog::ModalDialog:
        dialog->exec();
        break;

    case Dialog::MainWindow:
    {
        if (mainWindowGeometry.isEmpty())
        {
            mainWindow->adjustSize();
            mainWindow->move(QApplication::desktop()->screen()->rect().center() - mainWindow->rect().center());
        }
        else
            mainWindow->restoreGeometry(mainWindowGeometry);
    }

    default:
        windowWidget->setAttribute(Qt::WA_DeleteOnClose);
        windowWidget->show();
        break;
    }

    int result = 0;

    property = root->property("dialogResult");
    if (property.isValid())
        result = property.toInt();

    if (type == Dialog::ModalDialog)
        delete dialog;

    return result;
}
    static void mouseEvent(MouseAction action, QWidget *widget,
                           QObject *item, Qt::MouseButton button,
                           Qt::KeyboardModifiers stateKey, QPointF _pos, int delay=-1)
    {
        QTEST_ASSERT(widget);
        QTEST_ASSERT(item);

        if (delay == -1 || delay < QTest::defaultMouseDelay())
            delay = QTest::defaultMouseDelay();
        if (delay > 0)
            QTest::qWait(delay);

        if (action == MouseClick) {
            mouseEvent(MousePress, widget, item, button, stateKey, _pos);
            mouseEvent(MouseRelease, widget, item, button, stateKey, _pos);
            return;
        }

        QPoint pos;
        QDeclarativeView *view = qobject_cast<QDeclarativeView *>(widget);
        QWidget *eventWidget = widget;
        QDeclarativeItem *ditem = qobject_cast<QDeclarativeItem *>(item);
        if (!ditem) {
            qWarning("Mouse event target is not an Item");
            return;
        }
        pos = view->mapFromScene(ditem->mapToScene(_pos));
        eventWidget = view->viewport();

        QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
        QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);

        stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);

        QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
        switch (action)
        {
            case MousePress:
                me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
                break;
            case MouseRelease:
                me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey);
                break;
            case MouseDoubleClick:
                me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
                break;
            case MouseMove:
                if (button == Qt::NoButton) {
                    // If we send a mouse move event with no button pressed, it will be
                    // rejected (unless mouseTracking is set to true); simulate instead
                    QCursor::setPos(widget->mapToGlobal(pos));
                    qApp->processEvents();
                } else {
                    me = QMouseEvent(QEvent::MouseMove, pos, widget->mapToGlobal(pos), button, button, stateKey);
                }
                break;
            default:
                QTEST_ASSERT(false);
        }
        QSpontaneKeyEvent::setSpontaneous(&me);
        if (!qApp->notify(eventWidget, &me)) {
            static const char *mouseActionNames[] =
                { "MousePress", "MouseRelease", "MouseClick", "MouseDoubleClick", "MouseMove" };
            QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
            QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toAscii().data());
        }
    }