Ejemplo n.º 1
0
PyPanel::PyPanel(const QString& scriptName,
                 const QString& label,
                 bool useUserParameters,
                 GuiApp* app)
    : QWidget( app->getGui() )
    , UserParamHolder()
    , PanelWidget(scriptName.toStdString(), this, app->getGui() )
    , _imp( new PyPanelPrivate() )
{
    setLabel( label.toStdString() );


    int idx = 1;
    std::string name = NATRON_PYTHON_NAMESPACE::makeNameScriptFriendly( scriptName.toStdString() );
    PanelWidget* existing = 0;
    existing = getGui()->findExistingTab(name);
    while (existing) {
        std::stringstream ss;
        ss << name << idx;
        existing = getGui()->findExistingTab( ss.str() );
        if (!existing) {
            name = ss.str();
        }
        ++idx;
    }

    setScriptName(name);


    if (useUserParameters) {
        _imp->holder = DialogParamHolder::create( QString::fromUtf8( name.c_str() ), getGui()->getApp(), this );
        setHolder(_imp->holder);
        _imp->holder->initializeKnobsPublic();
        _imp->mainLayout = new QVBoxLayout(this);
        _imp->mainLayout->setContentsMargins(0, 0, 0, 0);

        _imp->centerContainer = new QWidget(this);
        _imp->centerLayout = new QVBoxLayout(_imp->centerContainer);
        _imp->centerLayout->setContentsMargins(0, 0, 0, 0);

        _imp->panel = new DockablePanel(getGui(),
                                        _imp->holder,
                                        _imp->mainLayout,
                                        DockablePanel::eHeaderModeNoHeader,
                                        false,
                                        boost::shared_ptr<QUndoStack>(),
                                        QString(), QString(),
                                        _imp->centerContainer);
        _imp->panel->turnOffPages();
        _imp->centerLayout->insertWidget(0, _imp->panel);

        _imp->mainLayout->addWidget(_imp->centerContainer);
        _imp->mainLayout->addStretch();
    }
}
Ejemplo n.º 2
0
void CK2Title::init(IObject* obj,  map<int, std::shared_ptr<CK2Character>>& characters, const CK2BuildingFactory* buildingFactory)
{
    rawData = obj;
	titleString = obj->getKey();
	holder = NULL;
	vector<IObject*> holderObjs = obj->getValue("holder");
	if (holderObjs.size() > 0)
	{
		setHolder(characters[ atoi( holderObjs[0]->getLeaf().c_str() ) ].get());
	}
	heir = NULL;
	successionLaw = obj->getLeaf("succession");
	genderLaw = obj->getLeaf("gender");

	vector<IObject*> leavesObj = obj->getLeaves();
	for (unsigned int i = 0; i < leavesObj.size(); i++)
	{
		if (leavesObj[i]->getKey() == "nomination")
		{
			vector<IObject*> nomineeObj = leavesObj[i]->getValue("nominee");
			int nomineeId = atoi( nomineeObj[0]->getLeaf("id").c_str() );

			bool nomineeMarked = false;
			for (unsigned int j = 0; j < nominees.size(); j++)
			{
				if (nominees[j].first == nomineeId)
				{
					nominees[j].second++;
					nomineeMarked = true;
				}
			}
			if (nomineeMarked == false)
			{
				nominees.push_back( make_pair(nomineeId, 1) );
			}
		}
	}

	CA					= "";
	feudalContract	= 0;
	templeContract	= 0;
	cityContract	= 0;
	for (auto law : obj->getValue("law"))
    {
        trySetCrownAuthority(law->getLeaf());
		if (law->getLeaf().substr(0, 15) == "feudal_contract")
		{
			feudalContract = atoi( law->getLeaf().substr(16,1).c_str() );
		}
		else if (law->getLeaf().substr(0, 15) == "temple_contract")
		{
			templeContract = atoi( law->getLeaf().substr(16,1).c_str() );
		}
		else if (law->getLeaf().substr(0, 13) == "city_contract")
		{
			cityContract = atoi( law->getLeaf().substr(14,1).c_str() );
		}
    }

	vector<IObject*> historyObjs = obj->getValue("history");
	if (historyObjs.size() > 0)
	{
		historyObjs = historyObjs[0]->getLeaves();
		for (unsigned int i = 0; i < historyObjs.size(); i++)
		{
			CK2History* newHistory = new CK2History(static_cast<Object*>(historyObjs[i]), characters);
			history.push_back(newHistory);
		}
	}

    initLiege();

	vassals.clear();

	vector<IObject*> deJureLiegeObjs = obj->getValue("de_jure_liege");
	if (deJureLiegeObjs.size() > 0)
	{
		deJureLiegeString = deJureLiegeObjs[0]->getLeaf();
	}
	else
	{
		deJureLiegeString = "";
	}
	if (deJureLiegeString[0] == '"')
	{
		deJureLiegeString = deJureLiegeString.substr(1, deJureLiegeString.size() - 2);
	}

	active = true;
	vector<IObject*> activeObjs = obj->getValue("active");
	if (activeObjs.size() > 0)
	{
		if (activeObjs[0]->getLeaf() == "no")
			active = false;
	}

	vector<IObject*> dynObjs = obj->getValue("dynamic");
	if (dynObjs.size() > 0)
	{
		if (dynObjs[0]->getLeaf() == "yes")
			dynamic = true;
	}

	vector<IObject*> settlementObjs = obj->getValue("settlement");
	if (settlementObjs.size() > 0)
	{
		settlement = new CK2Barony(static_cast<Object*>(settlementObjs[0]), this, NULL, buildingFactory);
		if (holder != NULL)
		{
			holder->addHolding(settlement);
			if (holder->getPrimaryHolding() == NULL)	// if no other capital, a title holding will work
				holder->setPrimaryHolding(settlement);
		}
	}

	independent = true;
	inHRE			= false;
}
Ejemplo n.º 3
0
PyModalDialog::PyModalDialog(Gui* gui,
                             StandardButtons defaultButtons)
    : QDialog(gui)
    , UserParamHolder()
    , _imp( new PyModalDialogPrivate(gui) )
{
    _imp->holder = DialogParamHolder::create( QString(), gui->getApp(), this );
    setHolder(_imp->holder);
    _imp->holder->initializeKnobsPublic();
    _imp->mainLayout = new QVBoxLayout(this);
    _imp->mainLayout->setContentsMargins(0, 0, 0, 0);

    _imp->centerContainer = new QWidget(this);
    _imp->centerLayout = new QVBoxLayout(_imp->centerContainer);
    _imp->centerLayout->setContentsMargins(0, 0, 0, 0);


    _imp->panel = new DockablePanel(gui,
                                    _imp->holder,
                                    _imp->mainLayout,
                                    DockablePanel::eHeaderModeNoHeader,
                                    false,
                                    boost::shared_ptr<QUndoStack>(),
                                    QString(), QString(),
                                    _imp->centerContainer);
    _imp->panel->turnOffPages();
    _imp->panel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
    _imp->centerLayout->insertWidget(0, _imp->panel);

    _imp->mainLayout->addWidget(_imp->centerContainer);

    if ( (defaultButtons & eStandardButtonNoButton) == 0 ) {
        QDialogButtonBox::StandardButtons qbuttons;
        if (defaultButtons & eStandardButtonOk) {
            qbuttons |= QDialogButtonBox::Ok;
        }
        if (defaultButtons & eStandardButtonSave) {
            qbuttons |= QDialogButtonBox::Save;
        }
        if (defaultButtons & eStandardButtonSaveAll) {
            qbuttons |= QDialogButtonBox::SaveAll;
        }
        if (defaultButtons & eStandardButtonOpen) {
            qbuttons |= QDialogButtonBox::Open;
        }
        if (defaultButtons & eStandardButtonYes) {
            qbuttons |= QDialogButtonBox::Yes;
        }
        if (defaultButtons & eStandardButtonYesToAll) {
            qbuttons |= QDialogButtonBox::YesToAll;
        }
        if (defaultButtons & eStandardButtonNo) {
            qbuttons |= QDialogButtonBox::No;
        }
        if (defaultButtons & eStandardButtonNoToAll) {
            qbuttons |= QDialogButtonBox::NoToAll;
        }
        if (defaultButtons & eStandardButtonAbort) {
            qbuttons |= QDialogButtonBox::Abort;
        }
        if (defaultButtons & eStandardButtonRetry) {
            qbuttons |= QDialogButtonBox::Retry;
        }
        if (defaultButtons & eStandardButtonIgnore) {
            qbuttons |= QDialogButtonBox::Ignore;
        }
        if (defaultButtons & eStandardButtonClose) {
            qbuttons |= QDialogButtonBox::Close;
        }
        if (defaultButtons & eStandardButtonCancel) {
            qbuttons |= QDialogButtonBox::Cancel;
        }
        if (defaultButtons & eStandardButtonDiscard) {
            qbuttons |= QDialogButtonBox::Discard;
        }
        if (defaultButtons & eStandardButtonHelp) {
            qbuttons |= QDialogButtonBox::Help;
        }
        if (defaultButtons & eStandardButtonApply) {
            qbuttons |= QDialogButtonBox::Apply;
        }
        if (defaultButtons & eStandardButtonReset) {
            qbuttons |= QDialogButtonBox::Reset;
        }
        if (defaultButtons & eStandardButtonRestoreDefaults) {
            qbuttons |= QDialogButtonBox::RestoreDefaults;
        }


        _imp->buttons = new DialogButtonBox(qbuttons, Qt::Horizontal, this);
        _imp->buttons->setFocusPolicy(Qt::TabFocus);
        QObject::connect( _imp->buttons, SIGNAL(accepted()), this, SLOT(accept()) );
        QObject::connect( _imp->buttons, SIGNAL(rejected()), this, SLOT(reject()) );
        _imp->mainLayout->addWidget(_imp->buttons);
    }
}