Gui::Action * CmdRaytracingNewLuxProject::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; std::string path = App::Application::getResourceDir(); path += "Mod/Raytracing/Templates/"; QDir dir(QString::fromUtf8(path.c_str()), QString::fromAscii("*.lxs")); for (unsigned int i=0; i<dir.count(); i++ ) { QFileInfo fi(dir[i]); QAction* a = pcAction->addAction(fi.baseName()); a->setIcon(Gui::BitmapFactory().pixmap("Raytrace_Lux")); a->setProperty("Template", dir.absoluteFilePath(dir[i])); } _pcAction = pcAction; languageChange(); if (defaultAction) { pcAction->setIcon(defaultAction->icon()); pcAction->setProperty("defaultAction", QVariant(defaultId)); } else if (!pcAction->actions().isEmpty()) { pcAction->setIcon(pcAction->actions()[0]->icon()); pcAction->setProperty("defaultAction", QVariant(0)); } return pcAction; }
Action * PythonGroupCommand::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->getName(), pcAction); int defaultId = 0; try { Base::PyGILStateLocker lock; Py::Object cmd(_pcPyCommand); Py::Callable call(cmd.getAttr("GetCommands")); Py::Tuple args; Py::Tuple ret(call.apply(args)); for (Py::Tuple::iterator it = ret.begin(); it != ret.end(); ++it) { Py::String str(*it); QAction* cmd = pcAction->addAction(QString()); cmd->setProperty("CommandName", QByteArray(static_cast<std::string>(str).c_str())); } if (cmd.hasAttr("GetDefaultCommand")) { Py::Callable call2(cmd.getAttr("GetDefaultCommand")); Py::Int def(call2.apply(args)); defaultId = static_cast<int>(def); } } catch(Py::Exception&) { Base::PyGILStateLocker lock; Base::PyException e; Base::Console().Error("createAction() of the Python command '%s' failed:\n%s\n%s", sName, e.getStackTrace().c_str(), e.what()); } _pcAction = pcAction; languageChange(); if (strcmp(getResource("Pixmap"),"") != 0) { pcAction->setIcon(Gui::BitmapFactory().iconFromTheme(getResource("Pixmap"))); } else { QList<QAction*> a = pcAction->actions(); // if out of range then set to 0 if (defaultId < 0 || defaultId >= a.size()) defaultId = 0; if (a.size() > defaultId) pcAction->setIcon(a[defaultId]->icon()); } pcAction->setProperty("defaultAction", QVariant(defaultId)); return pcAction; }
Gui::Action * CmdDrawingNewPage::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; std::string path = App::Application::getResourceDir(); path += "Mod/Drawing/Templates/"; QDir dir(QString::fromUtf8(path.c_str()), QString::fromAscii("*.svg")); for (unsigned int i=0; i<dir.count(); i++ ) { QRegExp rx(QString::fromAscii("(A|B|C|D|E)(\\d)_(Landscape|Portrait).svg")); if (rx.indexIn(dir[i]) > -1) { QString paper = rx.cap(1); int id = rx.cap(2).toInt(); QString orientation = rx.cap(3); QFile file(QString::fromAscii(":/icons/actions/drawing-landscape-A0.svg")); QAction* a = pcAction->addAction(QString()); if (file.open(QFile::ReadOnly)) { QString s = QString::fromAscii("style=\"font-size:22px\">%1%2</tspan></text>").arg(paper).arg(id); QByteArray data = file.readAll(); data.replace("style=\"font-size:22px\">A0</tspan></text>", s.toAscii()); a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(24,24))); } a->setProperty("TemplatePaper", paper); a->setProperty("TemplateOrientation", orientation); a->setProperty("TemplateId", id); a->setProperty("Template", dir.absoluteFilePath(dir[i])); if (id == 3) { defaultAction = a; defaultId = pcAction->actions().size() - 1; } } } _pcAction = pcAction; languageChange(); if (defaultAction) { pcAction->setIcon(defaultAction->icon()); pcAction->setProperty("defaultAction", QVariant(defaultId)); } else if (!pcAction->actions().isEmpty()) { pcAction->setIcon(pcAction->actions()[0]->icon()); pcAction->setProperty("defaultAction", QVariant(0)); } return pcAction; }
Gui::Action * CmdSketcherCompModifyKnotMultiplicity::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->className(), pcAction); QAction* c1 = pcAction->addAction(QString()); c1->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineIncreaseKnotMultiplicity")); QAction* c2 = pcAction->addAction(QString()); c2->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineDecreaseKnotMultiplicity")); _pcAction = pcAction; languageChange(); pcAction->setIcon(c1->icon()); int defaultId = 0; pcAction->setProperty("defaultAction", QVariant(defaultId)); return pcAction; }
Gui::Action * CmdSketcherCompBSplineShowHideGeometryInformation::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->className(), pcAction); QAction* c1 = pcAction->addAction(QString()); c1->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineDegree")); QAction* c2 = pcAction->addAction(QString()); c2->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplinePolygon")); QAction* c3 = pcAction->addAction(QString()); c3->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineComb")); QAction* c4 = pcAction->addAction(QString()); c4->setIcon(Gui::BitmapFactory().iconFromTheme("Sketcher_BSplineKnotMultiplicity")); _pcAction = pcAction; languageChange(); pcAction->setIcon(c2->icon()); int defaultId = 1; pcAction->setProperty("defaultAction", QVariant(defaultId)); return pcAction; }
Gui::Action * CmdDrawingNewPage::createAction(void) { Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow()); pcAction->setDropDownMenu(true); applyCommandData(this->className(), pcAction); QAction* defaultAction = 0; int defaultId = 0; QString lastPaper; int lastId = -1; std::string path = App::Application::getResourceDir(); path += "Mod/Drawing/Templates/"; QDir dir(QString::fromUtf8(path.c_str()), QString::fromLatin1("*.svg")); for (unsigned int i=0; i<dir.count(); i++ ) { QRegExp rx(QString::fromLatin1("(A|B|C|D|E)(\\d)_(Landscape|Portrait)(_.*\\.|\\.)svg$")); if (rx.indexIn(dir[i]) > -1) { QString paper = rx.cap(1); int id = rx.cap(2).toInt(); QString orientation = rx.cap(3); QString info = rx.cap(4).mid(1); info.chop(1); if (!info.isEmpty()) { info[0] = info[0].toUpper(); } // group by paper size if (!lastPaper.isEmpty()) { if (lastPaper != paper) { QAction* sep = pcAction->addAction(QString()); sep->setSeparator(true); } else if (lastId != id) { QAction* sep = pcAction->addAction(QString()); sep->setSeparator(true); } } lastPaper = paper; lastId = id; QFile file(QString::fromLatin1(":/icons/actions/drawing-landscape-A0.svg")); QAction* a = pcAction->addAction(QString()); if (file.open(QFile::ReadOnly)) { QString s = QString::fromLatin1("style=\"font-size:22px\">%1%2</tspan></text>").arg(paper).arg(id); QByteArray data = file.readAll(); data.replace("style=\"font-size:22px\">A0</tspan></text>", s.toLatin1()); a->setIcon(Gui::BitmapFactory().pixmapFromSvg(data, QSize(64,64))); } a->setProperty("TemplatePaper", paper); a->setProperty("TemplateOrientation", orientation); a->setProperty("TemplateId", id); a->setProperty("TemplateInfo", info); a->setProperty("Template", dir.absoluteFilePath(dir[i])); if (id == 3) { if (!defaultAction) { // set the first found A3 (A3_Landscape) as default defaultAction = a; defaultId = pcAction->actions().size() - 1; } } } } _pcAction = pcAction; languageChange(); if (defaultAction) { pcAction->setIcon(defaultAction->icon()); pcAction->setProperty("defaultAction", QVariant(defaultId)); } else if (!pcAction->actions().isEmpty()) { pcAction->setIcon(pcAction->actions()[0]->icon()); pcAction->setProperty("defaultAction", QVariant(0)); } return pcAction; }