Example #1
0
int main(int argc, char **argv)
{
	QApplication app(argc, argv);
	
	Test t;

	QtVariantPropertyManager *variantManager = new VariantManager();
	QtVariantProperty *priority = variantManager->addProperty(QVariant::Int, "Priority");

	priority->setToolTip("Task Priority");

	priority->setAttribute("minimum", 1);
	priority->setAttribute("maximum", 5);
	priority->setValue(3);

	QtVariantProperty *reportType = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), "Report Type");
	QStringList types;
	types << "Bug" << "Suggestion" << "To Do";
	reportType->setAttribute("enumNames", types);
	reportType->setValue(1); // current value will be "Suggestion"

	QtVariantProperty *task1 = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), "Task 1");

	task1->addSubProperty(priority);
	task1->addSubProperty(reportType);

	QtTreePropertyBrowser *browser = new QtTreePropertyBrowser();

	QtVariantEditorFactory *variantFactory = new VariantFactory();
	browser->setFactoryForManager(variantManager, variantFactory);

	browser->addProperty(task1);
	browser->show();

	QtVariantProperty *example = variantManager->addProperty(VariantManager::filePathTypeId(), "Example");
	example->setValue("main.cpp");
	example->setAttribute("filter", "Source files (*.cpp *.c)");

	
	QObject::connect(variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
					&t, SLOT(onValueChanged(QtProperty * , const QVariant &)));

	task1->addSubProperty(example);

	return app.exec();
}
Example #2
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QtVariantPropertyManager *variantManager = new QtVariantPropertyManager();

    int i = 0;
    QtProperty *topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
                QString::number(i++) + QLatin1String(" Group Property"));

    QtVariantProperty *item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property"));
    item->setValue(true);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property"));
    item->setValue(20);
    item->setAttribute(QLatin1String("minimum"), 0);
    item->setAttribute(QLatin1String("maximum"), 100);
    item->setAttribute(QLatin1String("singleStep"), 10);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property"));
    item->setValue(1.2345);
    item->setAttribute(QLatin1String("singleStep"), 0.1);
    item->setAttribute(QLatin1String("decimals"), 3);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property"));
    item->setValue("Value");
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property"));
    item->setValue(QDate::currentDate().addDays(2));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property"));
    item->setValue(QTime::currentTime());
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property"));
    item->setValue(QDateTime::currentDateTime());
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property"));
    item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property"));
    item->setValue(QChar(386));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property"));
    item->setValue(QLocale(QLocale::Polish, QLocale::Poland));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property"));
    item->setValue(QPoint(10, 10));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property"));
    item->setValue(QPointF(1.2345, -1.23451));
    item->setAttribute(QLatin1String("decimals"), 3);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property"));
    item->setValue(QSize(20, 20));
    item->setAttribute(QLatin1String("minimum"), QSize(10, 10));
    item->setAttribute(QLatin1String("maximum"), QSize(30, 30));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property"));
    item->setValue(QSizeF(1.2345, 1.2345));
    item->setAttribute(QLatin1String("decimals"), 3);
    item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34));
    item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property"));
    item->setValue(QRect(10, 10, 20, 20));
    topItem->addSubProperty(item);
    item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50));

    item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property"));
    item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345));
    topItem->addSubProperty(item);
    item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50));
    item->setAttribute(QLatin1String("decimals"), 3);

    item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(),
                    QString::number(i++) + QLatin1String(" Enum Property"));
    QStringList enumNames;
    enumNames << "Enum0" << "Enum1" << "Enum2";
    item->setAttribute(QLatin1String("enumNames"), enumNames);
    item->setValue(1);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(),
                    QString::number(i++) + QLatin1String(" Flag Property"));
    QStringList flagNames;
    flagNames << "Flag0" << "Flag1" << "Flag2";
    item->setAttribute(QLatin1String("flagNames"), flagNames);
    item->setValue(5);
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property"));
    topItem->addSubProperty(item);

    item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property"));
    topItem->addSubProperty(item);

    QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();

    QtTreePropertyBrowser *variantEditor = new QtTreePropertyBrowser();
    variantEditor->setFactoryForManager(variantManager, variantFactory);
    variantEditor->addProperty(topItem);
    variantEditor->setPropertiesWithoutValueMarked(true);
    variantEditor->setRootIsDecorated(false);

    variantEditor->show();

    int ret = app.exec();

    delete variantManager;
    delete variantFactory;
    delete variantEditor;

    return ret;
}
QWidget * BorderDrawersLoader::createEditor(BorderDrawerInterface * drawer, bool createCommands)
{
    if (!drawer)
        return 0;

    QtTreePropertyBrowser * browser = new QtTreePropertyBrowser();
    BorderChangeListener * listener = new BorderChangeListener(drawer, browser, createCommands);

    // QVariant type of property
    QtVariantPropertyManager * variantManager = 0;
    KVariantEditorFactory * variantFactory = 0;

    // Integer type of property
    QtIntPropertyManager * integerManager = 0;
    KSliderEditFactory * integerFactory = 0;

    // Double type of property
    QtDoublePropertyManager * doubleManager = 0;
    KDoubleSpinBoxFactory * doubleFactory = 0;

    const QMetaObject * meta = drawer->metaObject();
    int propertiesCount = meta->propertyCount();
    for (int i = 0; i < propertiesCount; ++i)
    {
        QMetaProperty metaProperty = meta->property(i);
        QString propertyName = drawer->propertyName(metaProperty);
        if (propertyName.isEmpty())
            continue;
        QtProperty * property;
        switch (metaProperty.type())
        {
            case QVariant::Int:
                {
                    if (!integerManager || !integerFactory)
                    {
                        integerManager = new QtIntPropertyManager(browser);
                        integerFactory = new KSliderEditFactory(browser);
                        browser->setFactoryForManager(integerManager, integerFactory);
                    }
                    property = integerManager->addProperty(propertyName);
                    integerManager->setValue(property, metaProperty.read(drawer).toInt());
                    integerManager->setMinimum(property, drawer->minimumValue(metaProperty).toInt());
                    integerManager->setMaximum(property, drawer->maximumValue(metaProperty).toInt());
                }
                break;
            case QVariant::Double:
                {
                    if (!doubleManager || !doubleFactory)
                    {
                        doubleManager = new QtDoublePropertyManager(browser);
                        doubleFactory = new KDoubleSpinBoxFactory(browser);
                        browser->setFactoryForManager(doubleManager, doubleFactory);
                    }
                    property = doubleManager->addProperty(propertyName);
                    doubleManager->setValue(property, metaProperty.read(drawer).toDouble());
                    doubleManager->setMinimum(property, drawer->minimumValue(metaProperty).toDouble());
                    doubleManager->setMaximum(property, drawer->maximumValue(metaProperty).toDouble());
                }
                break;
            case Enum:
                {
                }
                break;
            default:
                {
                    if (!variantManager || !variantFactory)
                    {
                        variantManager = new QtVariantPropertyManager(browser);
                        variantFactory = new KVariantEditorFactory(browser);
                        browser->setFactoryForManager(variantManager, variantFactory);
                    }
                    property = variantManager->addProperty(metaProperty.type(), propertyName);
                    variantManager->setValue(property, metaProperty.read(drawer));
                }
        }
        browser->addProperty(property);
    }

    if (integerManager)
    {
        connect(integerFactory, SIGNAL(editingFinished()), listener, SLOT(editingFinished()));
        connect(integerManager, SIGNAL(propertyChanged(QtProperty*)), listener, SLOT(propertyChanged(QtProperty*)));
    }
    if (doubleManager)
    {
        connect(doubleFactory, SIGNAL(editingFinished()), listener, SLOT(editingFinished()));
        connect(doubleManager, SIGNAL(propertyChanged(QtProperty*)), listener, SLOT(propertyChanged(QtProperty*)));
    }
    if (variantManager)
    {
        connect(variantFactory, SIGNAL(editingFinished()), listener, SLOT(editingFinished()));
        connect(variantManager, SIGNAL(propertyChanged(QtProperty*)), listener, SLOT(propertyChanged(QtProperty*)));
    }

    return browser;
}
void PropertiesMgr::initPropertyView()
{

	QtTreePropertyBrowser * tb = (QtTreePropertyBrowser*)ViewMgr::getInstance()->getWidgetWithName("propertiesWidget");
	tb->clear();

	if (m_variantManager == nullptr)
		m_variantManager = new QtVariantPropertyManager();
	else
		disconnect(m_variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), this, SLOT(propertyValueChanged(QtProperty *, const QVariant &)));
	m_variantManager->clear();
	m_particlesSlotProperty.clear();
	m_spineActionNames.clear();
	m_slotsNames.clear();
	QtProperty * actionGroup = m_variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), tr("action properties"));

	m_actionNameProperty = m_variantManager->addProperty(QtVariantPropertyManager::enumTypeId(), "actionName:");
	QStringList spineActionName;
	spineActionName << "";
	m_spineActionNames.push_back("");
	spine::SkeletonAnimation * pSkeleton = DocumentMgr::getInstance()->m_pSpineParticle->m_skeleton;
	for (int i = 0; i < pSkeleton->getSkeleton()->data->animationsCount; ++i)
	{
		spineActionName << pSkeleton->getSkeleton()->data->animations[i]->name;
		m_spineActionNames.push_back(pSkeleton->getSkeleton()->data->animations[i]->name);
	}
	m_actionNameProperty->setAttribute(QLatin1String("enumNames"), spineActionName);
	actionGroup->addSubProperty(m_actionNameProperty);
	int pos = 0;
	if (DocumentMgr::getInstance()->m_currentAction)
	for (auto it : m_spineActionNames)
	{
		if (DocumentMgr::getInstance()->m_currentAction->spineActionName == it)
		{
			m_actionNameProperty->setValue(pos);
			break;
		}
		pos++;
	}
	QtProperty *particleGroup = m_variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), tr("particle properties"));

	QStringList slotsName;
	slotsName << "none";
	m_slotsNames.push_back("none");
	for (int i = 0; i < pSkeleton->getSkeleton()->data->slotsCount; i++)
	{
		slotsName << pSkeleton->getSkeleton()->data->spineSlots[i]->name;
		m_slotsNames.push_back(pSkeleton->getSkeleton()->data->spineSlots[i]->name);
	}

	for (auto & it : DocumentMgr::getInstance()->m_pSpineParticle->m_particles)
	{
		QtProperty *particleinfoGroup = m_variantManager->addProperty(QtVariantPropertyManager::groupTypeId(), it.first.c_str());
		auto particleProperty = m_variantManager->addProperty(QtVariantPropertyManager::enumTypeId(),"slot");

		particleProperty->setAttribute(QLatin1String("enumNames"), slotsName);
		particleinfoGroup->addSubProperty(particleProperty);
		m_particlesSlotProperty.insert(std::make_pair(particleProperty, it.first));
		if (DocumentMgr::getInstance()->m_currentAction)
		{
			auto &slotsData = DocumentMgr::getInstance()->m_currentAction->slotsData;
			auto p = slotsData.find(it.first);
			if (p != slotsData.end())
			{
				int index = 0;
				for (auto &name : m_slotsNames)
				{
					if (name == p->second.slotsName)
					{
						particleProperty->setValue(index);
						break;
					}
						
					index++;
				}
			}
		}

		auto offsetProperty = m_variantManager->addProperty(QVariant::PointF, tr("offset:"));
		offsetProperty->setAttribute(QLatin1String("decimals"), 2);
		if (DocumentMgr::getInstance()->m_currentAction)
		{
			auto &slotsData = DocumentMgr::getInstance()->m_currentAction->slotsData;
			auto p = slotsData.find(it.first);
			if (p != slotsData.end())
			{
				offsetProperty->setValue(QPointF(p->second.offset.x, p->second.offset.y));
			}
		}

		particleinfoGroup->addSubProperty(offsetProperty);
		m_particleOffsetProperty.insert(std::make_pair(offsetProperty, it.first));
		particleGroup->addSubProperty(particleinfoGroup);
	}
	QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();

	tb->setFactoryForManager(m_variantManager, variantFactory);

	tb->addProperty(actionGroup);
	tb->addProperty(particleGroup);

	connect(m_variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)), this, SLOT(propertyValueChanged(QtProperty *, const QVariant &)));
}
Example #5
0
QNEMainWindow::QNEMainWindow(QWidget *parent) :  QMainWindow(parent)
{
	// -------------------------------------
	// central widget
	// -------------------------------------
	QWidget *window = new QWidget();
	setCentralWidget(window);
	QHBoxLayout *layout = new QHBoxLayout;
	window->setLayout(layout);	
	// -------------------------------------
	// Main menu
	// ------------------------------------
	createMenuBar();
	layout->setMenuBar(menuBar);


	// -------------------------------------
	// Tools
	// ------------------------------------

	QVBoxLayout *Tools_Layout = new QVBoxLayout;
    layout->addLayout(Tools_Layout);
	// -------------------------------------
	// Tree
	// ------------------------------------
	QTreeWidget *treeWidget = new QTreeWidget();
	treeWidget->setColumnCount(1);
	treeWidget->setHeaderHidden(true);
	treeWidget->setFixedWidth(250);
	// создаем новый итем (пусть сначала базовый)
	QTreeWidgetItem *topLevelItem=new QTreeWidgetItem(treeWidget);
	// вешаем его на наше дерево в качестве топ узла.
	treeWidget->addTopLevelItem(topLevelItem);
	// укажем текст итема
	topLevelItem->setText(0,"Item");
	// создаем новый итем и сразу вешаем его на наш базовый
	QTreeWidgetItem *item=new QTreeWidgetItem(topLevelItem);
	// укажем текст итема
	item->setText(0,"SubItem");
	Tools_Layout->addWidget(treeWidget);

	// -------------------------------------
	// Property Browser
	// ------------------------------------	
 
	QtIntPropertyManager *intManager;
    QtProperty *priority;
    
    intManager = new QtIntPropertyManager;
    priority = intManager->addProperty("Priority");   
    priority->setToolTip("Task Priority");
    intManager->setRange(priority, 1, 5);
    intManager->setValue(priority, 3);

    QtEnumPropertyManager *enumManager=new QtEnumPropertyManager();
    QtProperty *reportType;
	reportType = enumManager->addProperty("Report Type");  
    QStringList types;   
    types << "Bug" << "Suggestion" << "To Do";
    enumManager->setEnumNames(reportType, types);
    enumManager->setValue(reportType, 1); // "Suggestion"

    QtGroupPropertyManager *groupManager;
    QtProperty *task1;

    groupManager = new QtGroupPropertyManager;
    task1 = groupManager->addProperty("Task 1");
    
    task1->addSubProperty(priority);
    task1->addSubProperty(reportType);

    QtSpinBoxFactory *spinBoxFactory;
    QtEnumEditorFactory *enumFactory;
    
    spinBoxFactory = new QtSpinBoxFactory;
    enumFactory = new QtEnumEditorFactory;
    
    QtTreePropertyBrowser *browser;
    browser = new QtTreePropertyBrowser;
    browser->setFactoryForManager(intManager, spinBoxFactory);
    browser->setFactoryForManager(enumManager, enumFactory);
	browser->setFixedWidth(250);

    browser->addProperty(task1);
   // browser->show();

	Tools_Layout->addWidget(browser);

	// -------------------------------------
	// Graphic view
	// ------------------------------------
	view = new QGraphicsView(this);
	view->setInteractive(true);
	view->setBackgroundBrush(QBrush(QColor(60,60,60), Qt::SolidPattern));
	scene = new QGraphicsScene();
	view->setScene(scene);
	view->setRenderHint(QPainter::Antialiasing, true);
	layout->addWidget(view);

	// -------------------------------------
	// Nodes editor
	// -----------------------------------
	nodesEditor = new QNodesEditor(this);
	nodesEditor->install(scene);


	QNEBlock *b1 = new QNEBlock(0);
	scene->addItem(b1);
	b1->block_name="U1";
	b1->block_type="Source";
	b1->addOutputPort("img");
	b1->setPos(0, 0);

	QNEBlock *b2 = new QNEBlock(0);
	scene->addItem(b2);
	b2->block_name="U2";
	b2->block_type="Threshold";
	b2->addInputPort("img");
	b2->addOutputPort("thr");
	b2->setPos(150, 0);


}