[Gui] UserEditMode : add menu and toolbar management

This commit is contained in:
0penBrain
2021-05-13 11:16:48 +02:00
parent a8e7992a7d
commit b84bb1a16a
7 changed files with 1467 additions and 2 deletions

View File

@@ -29,6 +29,7 @@
# include <QWhatsThis>
# include <QDesktopServices>
# include <QUrl>
# include <boost_bind_bind.hpp>
#endif
#include <boost/scoped_ptr.hpp>
@@ -63,6 +64,7 @@
using Base::Console;
using Base::Sequencer;
using namespace Gui;
namespace bp = boost::placeholders;
//===========================================================================
@@ -813,6 +815,98 @@ void StdCmdUnitsCalculator::activated(int iMsg)
dlg->show();
}
//===========================================================================
// StdCmdUserEditMode
//===========================================================================
class StdCmdUserEditMode : public Gui::Command
{
public:
StdCmdUserEditMode();
virtual ~StdCmdUserEditMode(){}
virtual void languageChange();
virtual const char* className() const {return "StdCmdUserEditMode";}
void updateIcon(int mode);
protected:
virtual void activated(int iMsg);
virtual bool isActive(void);
virtual Gui::Action * createAction(void);
};
StdCmdUserEditMode::StdCmdUserEditMode()
: Command("Std_UserEditMode")
{
sGroup = QT_TR_NOOP("Edit mode");
sMenuText = QT_TR_NOOP("Edit mode");
sToolTipText = QT_TR_NOOP("Defines behavior when editing an object from tree");
sStatusTip = QT_TR_NOOP("Defines behavior when editing an object from tree");
sWhatsThis = "Std_UserEditMode";
sPixmap = "EditModeDefault";
eType = ForEdit;
this->getGuiApplication()->signalUserEditModeChanged.connect(boost::bind(&StdCmdUserEditMode::updateIcon, this, bp::_1));
}
Gui::Action * StdCmdUserEditMode::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(this->className(), pcAction);
for (auto const &uem : Gui::Application::Instance->listUserEditModes()) {
QAction* act = pcAction->addAction(QString());
act->setCheckable(true);
act->setIcon(BitmapFactory().iconFromTheme(qPrintable(QString::fromLatin1("EditMode")+QString::fromStdString(uem.second))));
act->setObjectName(QString::fromLatin1("Std_EditMode")+QString::fromStdString(uem.second));
act->setWhatsThis(QString::fromLatin1(getWhatsThis()));
if (uem.first == 0) {
pcAction->setIcon(act->icon());
act->setChecked(true);
}
}
_pcAction = pcAction;
languageChange();
return pcAction;
}
void StdCmdUserEditMode::languageChange()
{
Command::languageChange();
if (!_pcAction)
return;
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();
for (int i = 0 ; i < a.count() ; i++) {
auto modeName = Gui::Application::Instance->getUserEditModeName(i);
a[i]->setText(QCoreApplication::translate(
"EditMode", qPrintable(QString::fromStdString(modeName))));
a[i]->setToolTip(QCoreApplication::translate(
"EditMode", qPrintable(QString::fromStdString(modeName)+QString::fromLatin1(" mode"))));
}
}
void StdCmdUserEditMode::updateIcon(int mode)
{
Gui::ActionGroup *actionGroup = dynamic_cast<Gui::ActionGroup *>(_pcAction);
if (!actionGroup)
return;
actionGroup->setCheckedAction(mode);
}
void StdCmdUserEditMode::activated(int iMsg)
{
Gui::Application::Instance->setUserEditMode(iMsg);
}
bool StdCmdUserEditMode::isActive(void)
{
return true;
}
namespace Gui {
void CreateStdCommands(void)
@@ -842,6 +936,7 @@ void CreateStdCommands(void)
rcCmdMgr.addCommand(new StdCmdPythonWebsite());
rcCmdMgr.addCommand(new StdCmdTextDocument());
rcCmdMgr.addCommand(new StdCmdUnitsCalculator());
rcCmdMgr.addCommand(new StdCmdUserEditMode());
//rcCmdMgr.addCommand(new StdCmdMeasurementSimple());
//rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp());
//rcCmdMgr.addCommand(new StdCmdDescription());

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.5 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 22 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 19 KiB

View File

@@ -0,0 +1,231 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="64"
height="64"
viewBox="0 0 64 64"
id="svg2"
version="1.1">
<title
id="title930">Std_AxisCross</title>
<defs
id="defs4">
<linearGradient
id="linearGradient926">
<stop
style="stop-color:#ef2929;stop-opacity:1"
offset="0"
id="stop922" />
<stop
style="stop-color:#a40000;stop-opacity:1"
offset="1"
id="stop924" />
</linearGradient>
<linearGradient
id="linearGradient918">
<stop
style="stop-color:#8ae234;stop-opacity:1"
offset="0"
id="stop914" />
<stop
style="stop-color:#4e9a06;stop-opacity:1"
offset="1"
id="stop916" />
</linearGradient>
<linearGradient
id="linearGradient910">
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="0"
id="stop906" />
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="1"
id="stop908" />
</linearGradient>
<marker
orient="auto"
refY="0"
refX="0"
id="marker4732"
style="overflow:visible">
<path
id="path4734"
style="fill:#00ff00;fill-opacity:1;fill-rule:evenodd;stroke:#00ff08;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="matrix(-1.1,0,0,-1.1,-1.1,0)" />
</marker>
<marker
orient="auto"
refY="0"
refX="0"
id="Arrow2Lstart"
style="overflow:visible">
<path
id="path4174"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.625;stroke-linejoin:round;stroke-opacity:1"
d="M 8.7185878,4.0337352 -2.2072895,0.01601326 8.7185884,-4.0017078 c -1.7454984,2.3720609 -1.7354408,5.6174519 -6e-7,8.035443 z"
transform="matrix(1.1,0,0,1.1,1.1,0)" />
</marker>
<marker
orient="auto"
refY="0"
refX="0"
id="Arrow1Lstart"
style="overflow:visible">
<path
id="path4156"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
transform="matrix(0.8,0,0,0.8,10,0)" />
</marker>
<linearGradient
id="linearGradient4067-6">
<stop
style="stop-color:#888a85;stop-opacity:1;"
offset="0"
id="stop4069-7" />
<stop
style="stop-color:#2e3436;stop-opacity:1;"
offset="1"
id="stop4071-5" />
</linearGradient>
<linearGradient
xlink:href="#linearGradient910"
id="linearGradient912"
x1="16.275192"
y1="999.11859"
x2="20.275194"
y2="1005.3622"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-0.32823259,0.25769489)" />
<linearGradient
xlink:href="#linearGradient918"
id="linearGradient920"
x1="37.791718"
y1="1008.163"
x2="41.744087"
y2="1014.2588"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(0,0.67970822)" />
<linearGradient
xlink:href="#linearGradient926"
id="linearGradient928"
x1="32.554726"
y1="1037.6899"
x2="38.136963"
y2="1044.7837"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(0,0.67970822)" />
</defs>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title>Std_AxisCross</dc:title>
<dc:creator>
<cc:Agent>
<dc:title>[bitacovir]</dc:title>
</cc:Agent>
</dc:creator>
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:date>2020/12/20</dc:date>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
transform="translate(0,-988.36216)">
<g
id="g4036-9-5"
transform="matrix(0.42333463,-1.0406928,1.2322046,0.04560555,-18.902112,1031.4247)"
style="fill:#73d216;fill-opacity:1;stroke:#172a04;stroke-width:1.753;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
<g
id="g4033-8-3"
transform="matrix(0.70857077,0.64561924,-0.7760537,0.70710678,30.848953,1.7173836)"
style="fill:#73d216;fill-opacity:1;stroke:#172a04;stroke-width:1.75119;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
<rect
style="fill:#73d216;fill-opacity:1;stroke:#172a04;stroke-width:1.75119;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3261-1-56"
width="23"
height="6"
x="-25"
y="-38"
transform="scale(-1)" />
</g>
</g>
<path
style="fill:none;fill-opacity:1;stroke:#8ae234;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 17.758513,1025.996 23.516681,-15.1976"
id="path4083-0-29" />
<g
style="fill:#cc0000;fill-opacity:1;stroke:#280000;stroke-width:1.77168;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(-0.09950839,-1.2704661,0.99694669,-0.07808517,-7.0272263,1034.6728)"
id="g4033-8-5">
<rect
transform="matrix(-0.61568026,0.78799608,-0.61567913,-0.78799696,0,0)"
y="-22.253193"
x="11.761694"
height="4.9622731"
width="24.257404"
id="rect3261-1-6"
style="fill:#cc0000;fill-opacity:1;stroke:#280000;stroke-width:1.65466;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<path
style="fill:none;stroke:#ef2929;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 38.136962,1045.4634 17.397878,1027.7269"
id="path4083-0-2" />
<path
id="path872-8"
d="m 44,1049.0419 -8.562552,-14.5923 c -4.048591,1.9848 -5.937899,5.0071 -7.162254,8.3488 z"
style="fill:url(#linearGradient928);fill-opacity:1;stroke:#280000;stroke-width:2.50713;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:url(#linearGradient920);fill-opacity:1;stroke:#172a04;stroke-width:2.50713;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 52.025756,1005.4549 -16.544154,3.5417 c 0.611589,4.4672 2.886818,7.2108 5.674284,9.4235 z"
id="path872-8-1" />
<g
id="g4036-9"
transform="matrix(-0.64428531,-0.92040759,0.70710678,-1.0101525,0.936348,1060.8558)"
style="fill:#3465a4;fill-opacity:1;stroke:#0b1521;stroke-width:1.753;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
<g
id="g4033-8"
transform="matrix(0.53748674,0.48973482,-0.7760537,0.70710678,30.821878,1.6927139)"
style="fill:#3465a4;fill-opacity:1;stroke:#0b1521;stroke-width:1.75119;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1">
<rect
style="fill:#3465a4;fill-opacity:1;stroke:#0b1521;stroke-width:1.75119;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3261-1"
width="23"
height="6"
x="-25"
y="-38"
transform="scale(-1)" />
</g>
</g>
<path
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 16.157967,1027.8686 V 999.86865"
id="path4083-0" />
<path
style="fill:url(#linearGradient912);fill-opacity:1;stroke:#0b1521;stroke-width:2.50713;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 17.171767,991.6197 -5.5,16.0002 c 4.142481,1.7805 7.666483,1.2466 11,0 z"
id="path872" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@@ -240,6 +240,10 @@
<file>document-package.svg</file>
<file>Std_Alignment.svg</file>
<file>Std_DuplicateSelection.svg</file>
<file>EditModeDefault.svg</file>
<file>EditModeTransform.svg</file>
<file>EditModeCutting.svg</file>
<file>EditModeColor.svg</file>
</qresource>
<!-- Demonstrating support for an embedded icon theme -->
<!-- See also http://permalink.gmane.org/gmane.comp.lib.qt.general/26374 -->

View File

@@ -587,7 +587,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Std_Refresh" << "Std_BoxSelection" << "Std_BoxElementSelection"
<< "Std_SelectAll" << "Std_Delete" << "Std_SendToPythonConsole"
<< "Separator" << "Std_Placement" << "Std_TransformManip" << "Std_Alignment"
<< "Std_Edit" << "Separator" << "Std_DlgPreferences";
<< "Std_Edit" << "Separator" << "Std_UserEditMode" << "Separator" << "Std_DlgPreferences";
MenuItem* axoviews = new MenuItem;
axoviews->setCommand("Axonometric");
@@ -712,7 +712,7 @@ ToolBarItem* StdWorkbench::setupToolBars() const
file->setCommand("File");
*file << "Std_New" << "Std_Open" << "Std_Save" << "Std_Print" << "Separator" << "Std_Cut"
<< "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo" << "Separator"
<< "Std_Refresh" << "Separator" << "Std_WhatsThis";
<< "Std_UserEditMode" << "Separator" << "Std_Refresh" << "Separator" << "Std_WhatsThis";
// Workbench switcher
ToolBarItem* wb = new ToolBarItem( root );