Gui: implement WorkbenchSwitcher class to encapsulate the parameter details
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#include "Macro.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PythonEditor.h"
|
||||
#include "UserSettings.h"
|
||||
#include "WhatsThis.h"
|
||||
#include "Widgets.h"
|
||||
#include "Workbench.h"
|
||||
@@ -725,8 +726,7 @@ void WorkbenchGroup::addTo(QWidget *widget)
|
||||
auto* box = new WorkbenchComboBox(this, widget);
|
||||
setupBox(box);
|
||||
|
||||
std::string pos = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow")->GetASCII("WSPosition", "WSToolbar");
|
||||
bool left = (pos == "WSLeftCorner");
|
||||
bool left = WorkbenchSwitcher::isLeftCorner(WorkbenchSwitcher::getValue());
|
||||
qobject_cast<QMenuBar*>(widget)->setCornerWidget(box, left ? Qt::TopLeftCorner : Qt::TopRightCorner);
|
||||
}
|
||||
else if (widget->inherits("QMenu")) {
|
||||
|
||||
@@ -1127,6 +1127,7 @@ SET(FreeCADGui_CPP_SRCS
|
||||
WaitCursor.cpp
|
||||
ManualAlignment.cpp
|
||||
TransactionObject.cpp
|
||||
UserSettings.cpp
|
||||
)
|
||||
SET(FreeCADGui_SRCS
|
||||
Application.h
|
||||
@@ -1161,6 +1162,7 @@ SET(FreeCADGui_SRCS
|
||||
WaitCursor.h
|
||||
ManualAlignment.h
|
||||
TransactionObject.h
|
||||
UserSettings.h
|
||||
${FreeCADGui_SDK_MOC_HDRS}
|
||||
)
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "DlgRevertToBackupConfigImp.h"
|
||||
#include "MainWindow.h"
|
||||
#include "PreferencePackManager.h"
|
||||
#include "UserSettings.h"
|
||||
#include "Language/Translator.h"
|
||||
|
||||
using namespace Gui::Dialog;
|
||||
@@ -104,8 +105,6 @@ DlgGeneralImp::DlgGeneralImp( QWidget* parent )
|
||||
else
|
||||
ui->RevertToSavedConfig->setEnabled(true);
|
||||
connect(ui->RevertToSavedConfig, &QPushButton::clicked, this, &DlgGeneralImp::revertToSavedConfig);
|
||||
|
||||
wsPositions << "WSToolbar" << "WSLeftCorner" << "WSRightCorner";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,10 +501,7 @@ void DlgGeneralImp::saveWorkbenchSelector()
|
||||
{
|
||||
//save workbench selector position
|
||||
auto index = ui->WorkbenchSelectorPosition->currentIndex();
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
if (index >= 0 && index < wsPositions.size()) {
|
||||
hGrp->SetASCII("WSPosition", wsPositions[index].c_str());
|
||||
}
|
||||
WorkbenchSwitcher::setIndex(index);
|
||||
}
|
||||
|
||||
void DlgGeneralImp::loadWorkbenchSelector()
|
||||
@@ -515,11 +511,7 @@ void DlgGeneralImp::loadWorkbenchSelector()
|
||||
ui->WorkbenchSelectorPosition->addItem(tr("Toolbar"));
|
||||
ui->WorkbenchSelectorPosition->addItem(tr("Left corner"));
|
||||
ui->WorkbenchSelectorPosition->addItem(tr("Right corner"));
|
||||
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
std::string pos = hGrp->GetASCII("WSPosition", "WSToolbar");
|
||||
int index = std::max(0, wsPositions.indexOf(pos));
|
||||
ui->WorkbenchSelectorPosition->setCurrentIndex(index);
|
||||
ui->WorkbenchSelectorPosition->setCurrentIndex(WorkbenchSwitcher::getIndex());
|
||||
}
|
||||
|
||||
#include "moc_DlgGeneralImp.cpp"
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "PropertyPage.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <QVector>
|
||||
|
||||
class QTabWidget;
|
||||
|
||||
@@ -74,7 +73,6 @@ private:
|
||||
void loadWorkbenchSelector();
|
||||
|
||||
private:
|
||||
QVector<std::string> wsPositions;
|
||||
int localeIndex;
|
||||
std::unique_ptr<Ui_DlgGeneral> ui;
|
||||
std::unique_ptr<DlgCreateNewPreferencePackImp> newPreferencePackDialog;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "Application.h"
|
||||
#include "Command.h"
|
||||
#include "MainWindow.h"
|
||||
#include "UserSettings.h"
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
@@ -370,13 +371,13 @@ void MenuManager::setupMenuBarCornerWidgets() const
|
||||
{
|
||||
/*Note: currently only workbench selector uses corner widget.*/
|
||||
QMenuBar* menuBar = getMainWindow()->menuBar();
|
||||
std::string pos = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow")->GetASCII("WSPosition", "WSToolbar");
|
||||
std::string pos = WorkbenchSwitcher::getValue();
|
||||
|
||||
bool showLeftWidget = false;
|
||||
bool showRightWidget = false;
|
||||
|
||||
//Right corner widget
|
||||
if (pos == "WSRightCorner") {
|
||||
if (WorkbenchSwitcher::isRightCorner(pos)) {
|
||||
//add workbench selector to menubar right corner widget.
|
||||
if (!menuBar->cornerWidget(Qt::TopRightCorner)) {
|
||||
Application::Instance->commandManager().addTo("Std_Workbench", menuBar);
|
||||
@@ -384,7 +385,7 @@ void MenuManager::setupMenuBarCornerWidgets() const
|
||||
showRightWidget = true;
|
||||
}
|
||||
//Left corner widget
|
||||
else if (pos == "WSLeftCorner") {
|
||||
else if (WorkbenchSwitcher::isLeftCorner(pos)) {
|
||||
//add workbench selector to menubar left corner widget.
|
||||
if (!menuBar->cornerWidget(Qt::TopLeftCorner)) {
|
||||
Application::Instance->commandManager().addTo("Std_Workbench", menuBar);
|
||||
|
||||
86
src/Gui/UserSettings.cpp
Normal file
86
src/Gui/UserSettings.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
|
||||
#include "UserSettings.h"
|
||||
#include <App/Application.h>
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
namespace {
|
||||
|
||||
ParameterGrp::handle getWSParameter()
|
||||
{
|
||||
return App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::string WorkbenchSwitcher::getValue()
|
||||
{
|
||||
return getWSParameter()->GetASCII("WSPosition", "WSToolbar");
|
||||
}
|
||||
|
||||
bool WorkbenchSwitcher::isLeftCorner(const std::string& value)
|
||||
{
|
||||
return (value == "WSLeftCorner");
|
||||
}
|
||||
|
||||
bool WorkbenchSwitcher::isRightCorner(const std::string& value)
|
||||
{
|
||||
return (value == "WSRightCorner");
|
||||
}
|
||||
|
||||
bool WorkbenchSwitcher::isToolbar(const std::string& value)
|
||||
{
|
||||
return (value == "WSToolbar");
|
||||
}
|
||||
|
||||
QVector<std::string> WorkbenchSwitcher::values()
|
||||
{
|
||||
QVector<std::string> wsPositions;
|
||||
wsPositions << "WSToolbar" << "WSLeftCorner" << "WSRightCorner";
|
||||
return wsPositions;
|
||||
}
|
||||
|
||||
int WorkbenchSwitcher::getIndex()
|
||||
{
|
||||
auto hGrp = getWSParameter();
|
||||
std::string pos = hGrp->GetASCII("WSPosition", "WSToolbar");
|
||||
auto wsPositions = values();
|
||||
int index = std::max(0, wsPositions.indexOf(pos));
|
||||
return index;
|
||||
}
|
||||
|
||||
void WorkbenchSwitcher::setIndex(int index)
|
||||
{
|
||||
auto wsPositions = values();
|
||||
auto hGrp = getWSParameter();
|
||||
if (index >= 0 && index < wsPositions.size()) {
|
||||
hGrp->SetASCII("WSPosition", wsPositions[index].c_str());
|
||||
}
|
||||
}
|
||||
48
src/Gui/UserSettings.h
Normal file
48
src/Gui/UserSettings.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GUI_USERSETTINGS_H
|
||||
#define GUI_USERSETTINGS_H
|
||||
|
||||
#include <FCGlobal.h>
|
||||
#include <string>
|
||||
#include <QVector>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class GuiExport WorkbenchSwitcher
|
||||
{
|
||||
public:
|
||||
static bool isLeftCorner(const std::string&);
|
||||
static bool isRightCorner(const std::string&);
|
||||
static bool isToolbar(const std::string&);
|
||||
static std::string getValue();
|
||||
static int getIndex();
|
||||
static void setIndex(int);
|
||||
|
||||
private:
|
||||
static QVector<std::string> values();
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // GUI_USERSETTINGS_H
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "Selection.h"
|
||||
#include "ToolBarManager.h"
|
||||
#include "ToolBoxManager.h"
|
||||
#include "UserSettings.h"
|
||||
#include "Window.h"
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -751,9 +752,7 @@ ToolBarItem* StdWorkbench::setupToolBars() const
|
||||
<< "Std_Refresh" << "Separator" << "Std_WhatsThis";
|
||||
|
||||
// Workbench switcher
|
||||
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/MainWindow");
|
||||
std::string defaultPos = "WSToolbar";
|
||||
if (hGrp->GetASCII("WSPosition", defaultPos.c_str()) == defaultPos) {
|
||||
if (WorkbenchSwitcher::isToolbar(WorkbenchSwitcher::getValue())) {
|
||||
auto wb = new ToolBarItem(root);
|
||||
wb->setCommand("Workbench");
|
||||
*wb << "Std_Workbench";
|
||||
|
||||
Reference in New Issue
Block a user