Ejemplo n.º 1
0
	UbLink::~UbLink()
	{
		if ( !this->isHardLink() )
		{
			if ( this->nodesAreSet() )
			{
				if ( m_StartNode->parentObject()->type() == ImageBlockType )
				{
					UbImageView *obj = static_cast<UbImageView*>(m_StartNode->parentObject());
					obj->disconnect();
				}
				if ( m_EndNode->parentObject()->type() == ImageBlockType )
				{
					UbImageView *obj = static_cast<UbImageView*>(m_EndNode->parentObject());
					obj->disconnect();
				}
			}


			if ( m_StartNode->type()== OutputNodeType )
			{
				QGraphicsObject *parent = m_StartNode->parentObject();
				if ( parent->type()==ImageBlockType )
				{
					//perform unlining
				}
			}
		} 
	}
Ejemplo n.º 2
0
QString chipTanDialog::hhdCode()
{
  QGraphicsObject* rootObject = ui->declarativeView->rootObject();
  if (rootObject)
    return rootObject->property("transferData").toString();
  return QString();
}
Ejemplo n.º 3
0
QGraphicsObject * GridLayoutItem::createNewItemView(int i)
{
  if( m_listController && m_delegate )
  {
    QSharedPointer<OSListItem> itemData = m_listController->itemAt(i);

    OS_ASSERT(itemData);

    QGraphicsObject * graphicsItem = m_delegate->view(itemData);

    OS_ASSERT(graphicsItem);

    graphicsItem->setParentItem(this);

    m_widgetItemPairs.insert( std::make_pair(graphicsItem,itemData) );

    connect(graphicsItem, &QGraphicsObject::destroyed, this, &GridLayoutItem::removePair);

    return graphicsItem;
  }
  else
  {
    return nullptr;
  }
}
Ejemplo n.º 4
0
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    qmlRegisterType<Line>("CustomComponents", 1, 0, "Line");
    qmlRegisterType<MyWebView>("CustomComponents", 1, 0, "MyWebView");

    QScopedPointer<QmlApplicationViewer> viewer(QmlApplicationViewer::create());

    viewer->setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
//    viewer->setMainQmlFile(QLatin1String("qml/HiQMLHtml5/main.qml"));
//    viewer->setMainQmlFile(QLatin1String("qml/HiQMLHtml5/webbrowser.qml"));
    viewer->setMainQmlFile(QLatin1String("qml/HiQMLHtml5/mywebbrowser.qml"));
    viewer->showExpanded();

    QDeclarativeContext *context = viewer->rootContext();
    context->dumpObjectTree();

    qDebug() << " dump...";
    QGraphicsObject* root = viewer->rootObject();
    root->dumpObjectInfo();
    QDeclarativeItem *item = viewer->rootObject()->findChild<QDeclarativeItem*>("webView");
    if (item) {
        qDebug() << "found.";
//        item->dumpObjectInfo();
    }

    return app->exec();
}
Ejemplo n.º 5
0
void VRFSystemView::paint( QPainter *painter, 
                           const QStyleOptionGraphicsItem *option, 
                           QWidget *widget )
{
  // Background and Border

  painter->setRenderHint(QPainter::Antialiasing, true);
  painter->setBrush(QColor(206,206,206));
  painter->setPen(Qt::NoPen);

  QRectF _boudingRect = boundingRect();
  painter->drawRoundedRect(_boudingRect.x(),_boudingRect.y() + 5,_boudingRect.width(),_boudingRect.height() - 10,5,5);

  if( ! m_terminalViews.empty() )
  {
    painter->setPen(QPen(Qt::black,1,Qt::SolidLine, Qt::RoundCap));
    double line1X = vrfIconButton->x() + vrfIconButton->boundingRect().width() / 2.0;
    double line1Y1 = vrfIconButton->y() + vrfIconButton->boundingRect().height() / 2.0;
    QGraphicsObject * lastView = m_terminalViews.back();
    double line1Y2 = lastView->y() + lastView->boundingRect().height() / 2.0;
    painter->drawLine(line1X,line1Y1,
                      line1X,line1Y2);

    for(auto it = m_terminalViews.begin();
        it != m_terminalViews.end();
        ++it)
    {
      double line2Y1 = (*it)->y() + (*it)->boundingRect().height() / 2.0;
      double line2X2 = (*it)->x();
      painter->drawLine(line1X,line2Y1,
                        line2X2,line2Y1);
    }
  }
}
Ejemplo n.º 6
0
void InitQML::fadeIn()
{
     QGraphicsObject *object = this->rootObject();
     if (object) {
        qDebug() << "\tFADE IN";
        object->setProperty("state", "fadein");
    }
}
Ejemplo n.º 7
0
void MainWindow::addCoreElementsView(IView * coreView)
{
	QGraphicsObject *graphObj = dynamic_cast<QGraphicsObject *>(coreView);
	graphObj->setParent(ui->trackingArea);

	m_graphView->addGraphicsItem(graphObj);
	_currentCoreView = graphObj;
}
void Qt4NodeInstanceServer::resizeCanvasSizeToRootItemSize()
{
    QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(rootNodeInstance().internalObject());
    if (rootGraphicsObject) {
        declarativeView()->scene()->addItem(rootGraphicsObject);
        declarativeView()->setSceneRect(rootGraphicsObject->boundingRect());
    }
}
Ejemplo n.º 9
0
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;
    std::sort(children.begin(), children.end(), QGraphicsItemPrivate::insertionOrder);

    QPODVector<PositionedItem,8> oldItems;
    positionedItems.copyAndClear(oldItems);
    for (int ii = 0; ii < children.count(); ++ii) {
        QGraphicsObject *child = children.at(ii)->toGraphicsObject();
        if (!child)
            continue;
        QGraphicsItemPrivate *childPrivate = static_cast<QGraphicsItemPrivate*>(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 || !childPrivate->width() || !childPrivate->height())
                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 || !childPrivate->width() || !childPrivate->height()) {
                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 DockModeClockWindow::focusEvent (bool enable)
{
	if (enable)
		m_clockObject->setProperty ("mainTimerRunning", true);
	else 
		m_clockObject->setProperty ("mainTimerRunning", false);

	DockModeWindow::focusEvent (enable);

}
Ejemplo n.º 11
0
void MainWindow::addTrackerElementsView(IView *elemView)
{

	QGraphicsObject *graphObj = dynamic_cast<QGraphicsObject *>(elemView);
	graphObj->setParent(ui->trackingArea);

	m_graphView->addGraphicsItem(graphObj);
	QRectF viewSceneRect = m_graphView->sceneRect();

	_currentElementView = graphObj;
}
Ejemplo n.º 12
0
void MainWindow::changeUserPass()
{
    QGraphicsObject *obj = rootObject();
    obj->setProperty("authed", false);

    m_userStream->streamDisconnect();
    m_tweetListModel->clear();
    m_mentionsListModel->clear();

    // ### TODO Clear tokens in .ini?
}
Ejemplo n.º 13
0
static QDeclarativePrivate::AutoParentResult qgraphicsobject_autoParent(QObject *obj, QObject *parent)
{
    QGraphicsObject* gobj = qobject_cast<QGraphicsObject*>(obj);
    if (!gobj)
        return QDeclarativePrivate::IncompatibleObject;

    QGraphicsObject* gparent = qobject_cast<QGraphicsObject*>(parent);
    if (!gparent)
        return QDeclarativePrivate::IncompatibleParent;

    gobj->setParentItem(gparent);
    return QDeclarativePrivate::Parented;
}
Ejemplo n.º 14
0
void StatusBarItemGroup::layoutCenter()
{
	int width=0;
	int currRight;
	QRect rect;

	if(m_hasArrow && m_arrowPix && !m_arrowPix->isNull() && (m_arrowAnimProg > 0.0)) {
		width = m_arrowPix->width() + 2.0 * ARROW_SPACING;
	}

	for(int x = 0; x < m_items.size(); x++) {
		QGraphicsObject* item = m_items.at(x);
		if(item) {
			width += item->boundingRect().width() + ITEM_SPACING;
		}
	}

	rect = QRect(-width/2, -m_height/2, width, m_height);

	currRight = width/2;

	if(m_hasArrow && m_arrowPix && !m_arrowPix->isNull() && (m_arrowAnimProg > 0.0)) {
		currRight -=m_arrowPix->width() + 2.0 * ARROW_SPACING;
	}

	for(int x = 0; x < m_items.size(); x++) {
		StatusBarItem* item = m_items.at(x);

		if(item) {
			StatusBarItem::Alignment align = item->alignment();

			if(align == AlignRight) {
				item->setPos(currRight, 0);
			} else if(align == AlignLeft) {
				item->setPos(currRight - item->boundingRect().width(), 0);
			} else {
				item->setPos(currRight - item->boundingRect().width()/2, 0);
			}

			currRight -= item->boundingRect().width() + ITEM_SPACING;
		}
	}

	if(rect != m_bounds) {
		prepareGeometryChange();
		m_bounds = rect;
		Q_EMIT signalBoundingRectChanged();
	}

	update();
}
Ejemplo n.º 15
0
QGesture *FingerSwipeGestureRecognizer::create(QObject *target)
{
	if (target && target->isWidgetType()) {
		QWidget *widget = static_cast<QWidget *>(target);
		widget->setAttribute(Qt::WA_AcceptTouchEvents);

	} else if (target) {
		QGraphicsObject *go = qobject_cast<QGraphicsObject*>(target);
		if (go) {
			go->setAcceptTouchEvents(true);
		}
	}
	return new FingerSwipeGesture();
}
Ejemplo n.º 16
0
void Field::throwBalls(int num, bool directly)
{
    QVector<QPoint> free;
    free.fill(QPoint(0, 0), W * H);
    int nFree = 0;
    for (int i = 0; i < W; i++)
        for (int j = 0; j < H; j++)
            if (at(i, j) == 0)
            {
                free[nFree] = QPoint(i, j);
                nFree++;
            }

#ifdef QT_DEBUG
    for (int i = 0; i < W * H; i++)
    {
        //qDebug("%d, %d", free[i].x(), free[i].y());
    }
#endif
    //return;

    QList<SuggestedBall> ballsToThrow;
    for (int n = 0; n < num; n++)
    {
        if (nFree > 0)
        {
            int at = qrand() % nFree;
            ballsToThrow.append({ free[at], qrand() % COLORS + 1, NULL, NULL });
            free.removeAt(at);
            nFree--;
        }
        else
            ballsToThrow.append({ QPoint(-1, -1), qrand() % COLORS + 1, NULL, NULL });
    }

    if (directly)
    {
        // This is needed on startup only, therefore do nothing except placing balls
        foreach (auto ball, ballsToThrow)
        {
            setAt(ball.pt, ball.color);
            QGraphicsObject *item = new SvgRendererItem(ResourceLoader::instance()->ball(ball.color));
            item->setPos(ball.pt * CELL_SIZE);
            item->setZValue(3);
            m_scene->addItem(item);
            setVectorAt(m_fieldItems, ball.pt, item);
        }
    }
Ejemplo n.º 17
0
QBlockDiagramNodeSlot* QBlockDiagramModel::nodeSlotAroundLinkEnd( QBlockDiagramLinkEnd* a_pEnd )
{
  const QList<QGraphicsItem *>& item_list	= items ();
  QGraphicsItem*  pItem = NULL;
  Q_FOREACH(pItem, item_list)
  {
    QGraphicsObject* pObject = pItem->toGraphicsObject();
    if(pObject != NULL && pObject->inherits("QBlockDiagramItem") && static_cast<QBlockDiagramItem*>(pItem)->isNodeSlot())
    {
      QBlockDiagramNodeSlot* pSlot = static_cast<QBlockDiagramNodeSlot*>(pItem);
      QLineF distance(a_pEnd->scenePos(),pSlot->scenePos());
      if(distance.length() < 20.f && pSlot->acceptsLinkEnd(a_pEnd))
      {
        return pSlot;
      }
    }
  }
Ejemplo n.º 18
0
void MainWindow::startUp()
{
    //read settings
    QSettings settings(QSettings::IniFormat, QSettings::UserScope, "QTwitdget", "QTwitdget");
    m_userId = settings.value("user_id", 0).toInt();
    m_userScreenName = settings.value("user_screenname").toString();
    QString oauthToken = settings.value("oauth_token").toString();
    QString oauthTokenSecret = settings.value("oauth_token_secret").toString();

    if (!m_userScreenName.isEmpty())
        emit userScreenNameChanged();

    if(m_userId != 0 && !oauthToken.isEmpty() && !oauthTokenSecret.isEmpty()){
        m_oauthTwitter->setOAuthToken(oauthToken.toUtf8());
        m_oauthTwitter->setOAuthTokenSecret(oauthTokenSecret.toUtf8());

        //create or change database according to user id
        createDatabase(QString::number(m_userId));

        //show/animate tweets list page
        QGraphicsObject *obj = rootObject();
        obj->setProperty("authed", true);

        //set user id in the models
        m_tweetListModel->setUserID(m_userId);
        m_mentionsListModel->setUserID(m_userId);
        m_directMessagesListModel->setUserID(m_userId);
        m_conversationListModel->setUserID(m_userId);

        //show last tweets from database
        m_tweetListModel->loadTweetsFromDatabase();
        m_mentionsListModel->loadTweetsFromDatabase();
        m_directMessagesListModel->loadTweetsFromDatabase();

        //then fetch last 200 tweets
        m_tweetListModel->fetchLastTweets();
        m_mentionsListModel->fetchLastTweets();
        m_directMessagesListModel->fetchLastTweets();

        m_userStream->startFetching();

    } else {
        changeUserPass();
    }
}
Ejemplo n.º 19
0
void MainWindow::UiSizeChanged() {
  QGraphicsObject *background = qml_Page_->rootObject();
  int a(background->property("width").toInt()),
      b(background->property("height").toInt());

  while (b != 0)
  {
    int t = b;
    b = a % b;
    a = t;
  }
  int new_size = (a > 150)? a : 150;

  qDebug() << "Current main window size is" << this->size();
  qDebug() << "Current tile size is" << new_size;
  background->setProperty("tile_size",new_size);
  emit (tileSizeChanged(new_size));
}
bool MDeclarativeIMObserver::sceneEventFilter(QGraphicsItem * watched, QEvent * event)
{
    if (event->type()==QEvent::InputMethod) {        
        if (m_omitInputMethodEvents) {
            return true;
        }

        QInputMethodEvent *ime = static_cast<QInputMethodEvent*>(event);
		QString newPreedit = ime->preeditString();
		
        QGraphicsObject *g = parentObject();
        if (g != 0 && g->property("maximumLength").isValid()) {
            int maximumTextLength = g->property("maximumLength").toInt();
            int textLength = g->property("text").toString().length();
            int selectedTextLength = g->property("selectedText").toString().length();
            if (textLength == maximumTextLength &&
                newPreedit.length() - ime->replacementLength() > 0 &&
                selectedTextLength == 0) {
                    m_omitInputMethodEvents = true;
                    QInputContext *ic = qApp->inputContext();
                    ic->reset();
                    m_omitInputMethodEvents = false;
                    return true;
            }				
        }

        if (newPreedit!=m_preedit) {
            m_preedit = newPreedit;
            emit preeditChanged();
        }
        
        QList<QInputMethodEvent::Attribute> attributes = ime->attributes();
        QList<QInputMethodEvent::Attribute>::iterator i;
        for (i = attributes.begin(); i != attributes.end(); ++i) {
            QInputMethodEvent::Attribute attribute = *i;
            if (attribute.type == QInputMethodEvent::Cursor) {
                m_preeditCursorPosition = attribute.start;
                emit preeditCursorPositionChanged();
            }
        }
    }

    return QDeclarativeItem::sceneEventFilter(watched,event);
}
Ejemplo n.º 21
0
QList<ServerNodeInstance>  NodeInstanceServer::createInstances(const QVector<InstanceContainer> &containerVector)
{
    Q_ASSERT(m_declarativeView);
    QList<ServerNodeInstance> instanceList;
    foreach(const InstanceContainer &instanceContainer, containerVector) {
        ServerNodeInstance instance = ServerNodeInstance::create(this, instanceContainer);
        insertInstanceRelationship(instance);
        instanceList.append(instance);
        instance.internalObject()->installEventFilter(childrenChangeEventFilter());
        if (instanceContainer.instanceId() == 0) {
            m_rootNodeInstance = instance;
            QGraphicsObject *rootGraphicsObject = qobject_cast<QGraphicsObject*>(instance.internalObject());
            if (rootGraphicsObject) {
                m_declarativeView->scene()->addItem(rootGraphicsObject);
                m_declarativeView->setSceneRect(rootGraphicsObject->boundingRect());
            }

        }
    }
Ejemplo n.º 22
0
QString GaugeWidget::setFile(QString file)
{
	setSource(QUrl::fromLocalFile(file));
	if (rootObject())
	{
		for (int i=0;i<rootObject()->childItems().size();i++)
		{
			QGraphicsObject *obj = qobject_cast<QGraphicsObject*>(rootObject()->childItems()[i]);
			if (obj)
			{
				propertylist.append(obj->property("propertyMapProperty").toString());
			}
		}
		if (rootObject()->property("plugincompat").isValid())
		{
			QString plugincompat = rootObject()->property("plugincompat").toString();
			QLOG_DEBUG() << "Plugin compatability:" << plugincompat;
			return plugincompat;
		}
	}
	return "";
}
Ejemplo n.º 23
0
Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));
    app->setGraphicsSystem("opengl");

    QmlApplicationViewer viewer;
    QGLFormat fmt;
    fmt.setSampleBuffers(false);
    QGLWidget* glWidget = new QGLWidget(fmt);

    viewer.setViewport(glWidget);

    //viewer.setWindowFlags(Qt::FramelessWindowHint);
    //viewer.setAttribute(Qt::WA_TranslucentBackground);
//    /viewer.viewport()->setAutoFillBackground(false);

  //  viewer.setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    viewer.setMainQmlFile(QApplication::applicationDirPath() + "/../qml/FolderListTest/main.qml");

    //viewer.setWindowState(Qt::WindowMaximized);
    viewer.resize(qApp->desktop()->screenGeometry().width(), 3*qApp->desktop()->screenGeometry().height()/5);
    viewer.move(0, qApp->desktop()->screenGeometry().height()/2 - viewer.height()/2);

    if(argc>1)
    {
        QGraphicsObject * param = viewer.rootObject();
        QString s = QString::fromUtf8(argv[1]);
        s.remove("\"");
        QString url = QUrl::fromLocalFile(s).toString();
        param->setProperty("appParam", url);
        qDebug(url.toAscii().data());
    }

    viewer.showExpanded();

    return app->exec();
}
Ejemplo n.º 24
0
void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const PropertyName &newParentProperty)
{
    QDeclarativeProperty property(newParent, newParentProperty, context());

    if (isList(property)) {
        QDeclarativeListReference list = qvariant_cast<QDeclarativeListReference>(property.read());

        if (!hasFullImplementedListInterface(list)) {
            qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";
            return;
        }

        list.append(object);
    } else if (isObject(property)) {
        property.write(objectToVariant(object));
    }

    QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object);

    if (object && !(graphicsObject && graphicsObject->parentItem()))
        object->setParent(newParent);

    Q_ASSERT(objectToVariant(object).isValid());
}
Ejemplo n.º 25
0
Field::Field(QGraphicsScene *scene) //: QObject()
{
    m_scene = scene;
    m_animating = false;

    m_pathItems.fill(NULL, W * H);
    ResourceLoader *loader = ResourceLoader::instance();
    for (int i = 0; i < W; i++)
    {
        for (int j = 0; j < H; j++)
        {
            QGraphicsObject *item = new SvgRendererItem(loader->tile());
            item->setPos(i * CELL_SIZE, j * CELL_SIZE);
#ifdef QT_DEBUG
            //if (j % 2 && i % 2)
            //    item->setScale(0.5);
#endif
            item->setZValue(0);
            m_scene->addItem(item);

            item = new SvgRendererItem(loader->pathmarker());
            item->setPos(i * CELL_SIZE, j * CELL_SIZE);
            item->setZValue(2);
            item->setVisible(false);
            m_scene->addItem(item);
            setVectorAt(m_pathItems, i, j, item);
        }
    }

    m_sel = QPoint(-1, -1);
    m_selItem = new SvgRendererItem(loader->select());
    m_selItem->setZValue(1);
    m_selItem->setVisible(false);
    m_scene->addItem(m_selItem);

    m_field.fill(0, W * H);
    m_fieldItems.fill(NULL, W * H);
    m_next.fill({ QPoint(-1, -1), 0, NULL, NULL }, 3);
}
Ejemplo n.º 26
0
void chipTanDialog::setRootObjectProperty(const char* property, const QVariant& value)
{
  QGraphicsObject* rootObject = ui->declarativeView->rootObject();
  if (rootObject)
    rootObject->setProperty(property, value);
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
//! [10]
Robot::Robot(QGraphicsItem *parent)
    : RobotPart(parent)
{
    setFlag(ItemHasNoContents);

    QGraphicsObject *torsoItem = new RobotTorso(this);
    QGraphicsObject *headItem = new RobotHead(torsoItem);
    QGraphicsObject *upperLeftArmItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerLeftArmItem = new RobotLimb(upperLeftArmItem);
    QGraphicsObject *upperRightArmItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerRightArmItem = new RobotLimb(upperRightArmItem);
    QGraphicsObject *upperRightLegItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerRightLegItem = new RobotLimb(upperRightLegItem);
    QGraphicsObject *upperLeftLegItem = new RobotLimb(torsoItem);
    QGraphicsObject *lowerLeftLegItem = new RobotLimb(upperLeftLegItem);
//! [10]

//! [11]
    headItem->setPos(0, -18);
    upperLeftArmItem->setPos(-15, -10);
    lowerLeftArmItem->setPos(30, 0);
    upperRightArmItem->setPos(15, -10);
    lowerRightArmItem->setPos(30, 0);
    upperRightLegItem->setPos(10, 32);
    lowerRightLegItem->setPos(30, 0);
    upperLeftLegItem->setPos(-10, 32);
    lowerLeftLegItem->setPos(30, 0);
//! [11]

//! [12]
    QParallelAnimationGroup *animation = new QParallelAnimationGroup(this);

    QPropertyAnimation *headAnimation = new QPropertyAnimation(headItem, "rotation");
    headAnimation->setStartValue(20);
    headAnimation->setEndValue(-20);
    QPropertyAnimation *headScaleAnimation = new QPropertyAnimation(headItem, "scale");
    headScaleAnimation->setEndValue(1.1);
    animation->addAnimation(headAnimation);
    animation->addAnimation(headScaleAnimation);
//! [12]

    QPropertyAnimation *upperLeftArmAnimation = new QPropertyAnimation(upperLeftArmItem, "rotation");
    upperLeftArmAnimation->setStartValue(190);
    upperLeftArmAnimation->setEndValue(180);
    animation->addAnimation(upperLeftArmAnimation);

    QPropertyAnimation *lowerLeftArmAnimation = new QPropertyAnimation(lowerLeftArmItem, "rotation");
    lowerLeftArmAnimation->setStartValue(50);
    lowerLeftArmAnimation->setEndValue(10);
    animation->addAnimation(lowerLeftArmAnimation);

    QPropertyAnimation *upperRightArmAnimation = new QPropertyAnimation(upperRightArmItem, "rotation");
    upperRightArmAnimation->setStartValue(300);
    upperRightArmAnimation->setEndValue(310);
    animation->addAnimation(upperRightArmAnimation);

    QPropertyAnimation *lowerRightArmAnimation = new QPropertyAnimation(lowerRightArmItem, "rotation");
    lowerRightArmAnimation->setStartValue(0);
    lowerRightArmAnimation->setEndValue(-70);
    animation->addAnimation(lowerRightArmAnimation);

    QPropertyAnimation *upperLeftLegAnimation = new QPropertyAnimation(upperLeftLegItem, "rotation");
    upperLeftLegAnimation->setStartValue(150);
    upperLeftLegAnimation->setEndValue(80);
    animation->addAnimation(upperLeftLegAnimation);

    QPropertyAnimation *lowerLeftLegAnimation = new QPropertyAnimation(lowerLeftLegItem, "rotation");
    lowerLeftLegAnimation->setStartValue(70);
    lowerLeftLegAnimation->setEndValue(10);
    animation->addAnimation(lowerLeftLegAnimation);

    QPropertyAnimation *upperRightLegAnimation = new QPropertyAnimation(upperRightLegItem, "rotation");
    upperRightLegAnimation->setStartValue(40);
    upperRightLegAnimation->setEndValue(120);
    animation->addAnimation(upperRightLegAnimation);

    QPropertyAnimation *lowerRightLegAnimation = new QPropertyAnimation(lowerRightLegItem, "rotation");
    lowerRightLegAnimation->setStartValue(10);
    lowerRightLegAnimation->setEndValue(50);
    animation->addAnimation(lowerRightLegAnimation);

    QPropertyAnimation *torsoAnimation = new QPropertyAnimation(torsoItem, "rotation");
    torsoAnimation->setStartValue(5);
    torsoAnimation->setEndValue(-20);
    animation->addAnimation(torsoAnimation);

//! [13]
    for (int i = 0; i < animation->animationCount(); ++i) {
        QPropertyAnimation *anim = qobject_cast<QPropertyAnimation *>(animation->animationAt(i));
        anim->setEasingCurve(QEasingCurve::SineCurve);
        anim->setDuration(2000);
    }

    animation->setLoopCount(-1);
    animation->start();
//! [13]
}
Ejemplo n.º 29
0
void InitQML::clear()
{
  QGraphicsObject *object = rootObject();
  if (object)
    object->setProperty("state", "hide");
}
Ejemplo n.º 30
0
void ChatController::fixFlickable(QObject *object)
{
    QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object);
    graphicsObject->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true);
}