diff --git a/src/Gui/Action.cpp b/src/Gui/Action.cpp index 877d77319..0ba85effb 100644 --- a/src/Gui/Action.cpp +++ b/src/Gui/Action.cpp @@ -40,6 +40,7 @@ #include "Application.h" #include "Command.h" #include "DlgUndoRedo.h" +#include "DlgWorkbenchesImp.h" #include "FileDialog.h" #include "MainWindow.h" #include "WhatsThis.h" @@ -519,26 +520,22 @@ void WorkbenchGroup::refreshWorkbenchList() { QString active = QString::fromAscii(WorkbenchManager::instance()->active()->name().c_str()); QStringList items = Application::Instance->workbenches(); - + QStringList enabled_wbs_list = DlgWorkbenchesImp::load_enabled_workbenches(); QList workbenches = _group->actions(); int numWorkbenches = std::min(workbenches.count(), items.count()); - - // sort by workbench menu text - QMap menuText; - for (int index = 0; index < numWorkbenches; index++) { - QString text = Application::Instance->workbenchMenuText(items[index]); - menuText[text] = items[index]; - } - int i=0; - for (QMap::Iterator it = menuText.begin(); it != menuText.end(); ++it, i++) { - QPixmap px = Application::Instance->workbenchIcon(it.value()); - QString tip = Application::Instance->workbenchToolTip(it.value()); - workbenches[i]->setObjectName(it.value()); + + for (QStringList::Iterator it = enabled_wbs_list.begin(); it != enabled_wbs_list.end(); ++it, i++) { + QString s = *it; + QString name = Application::Instance->workbenchMenuText(*it); + QPixmap px = Application::Instance->workbenchIcon(*it); + QString tip = Application::Instance->workbenchToolTip(*it); + workbenches[i]->setObjectName(*it); workbenches[i]->setIcon(px); - workbenches[i]->setText(it.key()); + workbenches[i]->setText(name); workbenches[i]->setToolTip(tip); - workbenches[i]->setStatusTip(tr("Select the '%1' workbench").arg(it.key())); + workbenches[i]->setStatusTip(tr("Select the '%1' workbench").arg(name)); + workbenches[i]->setVisible(false); workbenches[i]->setVisible(true); // Note: See remark at WorkbenchComboBox::onWorkbenchActivated // Calling setChecked() here causes to uncheck the current item diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 65c498c70..d910c76cf 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -193,6 +193,7 @@ set(Gui_MOC_HDRS DlgSettingsUnitsImp.h DlgTipOfTheDayImp.h DlgToolbarsImp.h + DlgWorkbenchesImp.h TaskDlgRelocation.h DlgUndoRedo.h DockWindow.h @@ -219,6 +220,7 @@ set(Gui_MOC_HDRS PythonDebugger.h PythonEditor.h QuantitySpinBox.h + QListWidgetCustom.h ReportView.h SceneInspector.h SelectionView.h @@ -287,6 +289,7 @@ SET(Gui_UIC_SRCS DlgSettingsMacro.ui DlgTipOfTheDay.ui DlgToolbars.ui + DlgWorkbenches.ui DlgTreeWidget.ui DlgLocationAngle.ui DlgLocationPos.ui @@ -435,6 +438,8 @@ SET(Dialog_Customize_CPP_SRCS DlgCustomizeSpNavSettings.cpp DlgKeyboardImp.cpp DlgToolbarsImp.cpp + DlgWorkbenchesImp.cpp + QListWidgetCustom.cpp ) SET(Dialog_Customize_HPP_SRCS DlgActionsImp.h @@ -444,6 +449,8 @@ SET(Dialog_Customize_HPP_SRCS DlgCustomizeSpNavSettings.h DlgKeyboardImp.h DlgToolbarsImp.h + DlgWorkbenchesImp.h + QListWidgetCustom.h ) SET(Dialog_Customize_SRCS ${Dialog_Customize_CPP_SRCS} @@ -454,6 +461,7 @@ SET(Dialog_Customize_SRCS DlgCustomizeSpNavSettings.ui DlgKeyboard.ui DlgToolbars.ui + DlgWorkbenches.ui ) SOURCE_GROUP("Dialog\\Customize" FILES ${Dialog_Customize_SRCS}) diff --git a/src/Gui/DlgCustomizeImp.cpp b/src/Gui/DlgCustomizeImp.cpp index 864e5b3bb..54284f36f 100644 --- a/src/Gui/DlgCustomizeImp.cpp +++ b/src/Gui/DlgCustomizeImp.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include # include +# include # include #endif @@ -49,7 +50,8 @@ DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WFlags fl) : QDialog(parent, fl) { setModal(false); - resize( 434, 365 ); + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); + resize( 690, 365 ); setWindowTitle(tr("Customize")); setSizeGripEnabled( true ); diff --git a/src/Gui/DlgWorkbenches.ui b/src/Gui/DlgWorkbenches.ui new file mode 100644 index 000000000..d4c5dcad5 --- /dev/null +++ b/src/Gui/DlgWorkbenches.ui @@ -0,0 +1,289 @@ + + + Gui::Dialog::DlgWorkbenches + + + + 0 + 0 + 421 + 354 + + + + Workbenches + + + + 9 + + + 6 + + + + + 6 + + + 0 + + + + + Enabled workbenches + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 33 + 57 + + + + + + + + 6 + + + 0 + + + + + Disabled workbenches + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Expanding + + + + 33 + 57 + + + + + + + + true + + + + 30 + 30 + + + + Move down + + + <html><head/><body><p><span style=" font-weight:600;">Move the selected item down.</span></p><p>The item will be moved down</p></body></html> + + + + + + + :/icons/button_down.svg:/icons/button_down.svg + + + true + + + + + + + true + + + + 30 + 30 + + + + Move left + + + <html><head/><body><p><span style=" font-weight:600;">Remove the selected workbench from enabled workbenches</span></p></body></html> + + + + + + + :/icons/button_left.svg:/icons/button_left.svg + + + true + + + false + + + + + + + true + + + + 30 + 30 + + + + Move right + + + <html><head/><body><p><span style=" font-weight:600;">Move the selected workbench to enabled workbenches.</span></p></body></html> + + + + + + + :/icons/button_right.svg:/icons/button_right.svg + + + + + + + true + + + + 30 + 30 + + + + Sort enabled workbenches + + + <b>Sort enabled workbenches</p> + + + + + + + :/icons/button_sort.svg:/icons/button_sort.svg + + + true + + + + + + + true + + + + 30 + 30 + + + + Move up + + + <html><head/><body><p><span style=" font-weight:600;">Move the selected item up.</span></p><p>The item will be moved up.</p></body></html> + + + + + + + :/icons/button_up.svg:/icons/button_up.svg + + + + + + + <html><head/><body><p><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt; font-weight:600;">Note:</span><span style=" font-family:'MS Shell Dlg 2'; font-size:8pt;"> The changes become active the next time you start FreeCAD</span></p></body></html> + + + + + + + true + + + + 30 + 30 + + + + Add all to enabled workbenches + + + <html><head/><body><p><span style=" font-weight:600;">Remove the selected workbench from enabled workbenches</span></p></body></html> + + + + + + + :/icons/button_add_all.svg:/icons/button_add_all.svg + + + true + + + false + + + + + + + + QListWidgetCustom + QListWidget +
QListWidgetCustom.h
+
+
+ + + + +
diff --git a/src/Gui/DlgWorkbenchesImp.cpp b/src/Gui/DlgWorkbenchesImp.cpp new file mode 100644 index 000000000..6078643b5 --- /dev/null +++ b/src/Gui/DlgWorkbenchesImp.cpp @@ -0,0 +1,234 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * Based on DlgToolbars.cpp file * + * * + * 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_ +# include +#endif + +#include "DlgWorkbenchesImp.h" +#include "Application.h" +#include "BitmapFactory.h" +#include "Command.h" +#include "MainWindow.h" +#include "Widgets.h" +#include "Workbench.h" +#include "WorkbenchManager.h" +#include "QListWidgetCustom.h" + +using namespace Gui::Dialog; + +const QString DlgWorkbenchesImp::all_workbenches = QString::fromAscii("ALL"); + +/* TRANSLATOR Gui::Dialog::DlgWorkbenches */ + +DlgWorkbenchesImp::DlgWorkbenchesImp(QWidget* parent) + : CustomizeActionPage(parent) +{ + this->setupUi(this); + set_lw_properties(lw_enabled_workbenches); + set_lw_properties(lw_disabled_workbenches); + const QString lw_disabled_name = QString::fromAscii("disabled workbenches"); + lw_disabled_workbenches->setAccessibleName(lw_disabled_name); + lw_disabled_workbenches->setSortingEnabled(true); + + QStringList enabled_wbs_list = load_enabled_workbenches(); + QStringList workbenches = Application::Instance->workbenches(); + + for (QStringList::Iterator it = enabled_wbs_list.begin(); it != enabled_wbs_list.end(); ++it) { + if (workbenches.contains(*it)){ + QString wb = *it; + add_workbench(lw_enabled_workbenches, wb); + } else { + qDebug("Ignoring unknown " + it->toLatin1() + " workbench found in user preferences."); + } + } + for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { + if (!enabled_wbs_list.contains(*it)){ + QString wb = *it; + add_workbench(lw_disabled_workbenches, wb); + } + } + lw_enabled_workbenches->setCurrentRow(0); + lw_disabled_workbenches->setCurrentRow(0); +} + +/** Destroys the object and frees any allocated resources */ +DlgWorkbenchesImp::~DlgWorkbenchesImp() +{ +} + +void DlgWorkbenchesImp::set_lw_properties(QListWidgetCustom *lw) +{ + lw->setDragDropMode(QAbstractItemView::DragDrop); + lw->setSelectionMode(QAbstractItemView::SingleSelection); + lw->viewport()->setAcceptDrops(true); + lw->setDropIndicatorShown(true); + lw->setDragEnabled(true); + lw->setDefaultDropAction(Qt::MoveAction); +} + +void DlgWorkbenchesImp::add_workbench(QListWidgetCustom *lw, QString it) +{ + QPixmap px = Application::Instance->workbenchIcon(it); + QString mt = Application::Instance->workbenchMenuText(it); + QListWidgetItem *wi = (new QListWidgetItem(QIcon(px), mt)); + wi->setData(Qt::UserRole, QVariant(it)); + lw->addItem(wi); +} + +void DlgWorkbenchesImp::changeEvent(QEvent *e) +{ + if (e->type() == QEvent::LanguageChange) { + retranslateUi(this); + } + else { + QWidget::changeEvent(e); + } +} + +void DlgWorkbenchesImp::hideEvent(QHideEvent * event) +{ + save_enabled_workbenches(); +} + +void DlgWorkbenchesImp::onAddMacroAction(const QByteArray& macro) +{ +} + +void DlgWorkbenchesImp::onRemoveMacroAction(const QByteArray& macro) +{ +} + +void DlgWorkbenchesImp::onModifyMacroAction(const QByteArray& macro) +{ +} + +void DlgWorkbenchesImp::move_workbench(QListWidgetCustom *lwc_dest, + QListWidgetItem *wi) +{ + QListWidgetItem* item = wi->clone(); + lwc_dest->addItem(item); + lwc_dest->setCurrentItem(item); + delete wi; +} + +void DlgWorkbenchesImp::on_add_to_enabled_workbenches_btn_clicked() +{ + QListWidgetItem* ci = lw_disabled_workbenches->currentItem(); + if (ci) { + move_workbench(lw_enabled_workbenches, ci); + } +} + +void DlgWorkbenchesImp::on_remove_from_enabled_workbenches_btn_clicked() +{ + QListWidgetItem* ci = lw_enabled_workbenches->currentItem(); + if (ci) { + move_workbench(lw_disabled_workbenches, ci); + } +} + +void DlgWorkbenchesImp::shift_workbench(bool up) +{ + int direction; + if (up){ + direction = -1; + } else { + direction = 1; + } + if (lw_enabled_workbenches->currentItem()) { + int index = lw_enabled_workbenches->currentRow(); + QListWidgetItem *item = lw_enabled_workbenches->takeItem(index); + lw_enabled_workbenches->insertItem(index + direction, item); + lw_enabled_workbenches->setCurrentRow(index + direction); + } +} + +void DlgWorkbenchesImp::on_shift_workbench_up_btn_clicked() +{ + shift_workbench(true); +} + +void DlgWorkbenchesImp::on_shift_workbench_down_btn_clicked() +{ + shift_workbench(false); +} + +void DlgWorkbenchesImp::on_sort_enabled_workbenches_btn_clicked() +{ + lw_enabled_workbenches->sortItems(); +} + +void DlgWorkbenchesImp::on_add_all_to_enabled_workbenches_btn_clicked() +{ + while (lw_disabled_workbenches->count() > 0) { + QListWidgetItem* item = lw_disabled_workbenches->item(0); + move_workbench(lw_enabled_workbenches, item); + } +} + +QStringList DlgWorkbenchesImp::load_enabled_workbenches() +{ + QString enabled_wbs; + QStringList enabled_wbs_list; + ParameterGrp::handle hGrp; + + hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); + enabled_wbs = QString::fromStdString(hGrp->GetASCII("Enabled", all_workbenches.toStdString().c_str()).c_str()); + enabled_wbs_list = enabled_wbs.split(QLatin1String(","), QString::SkipEmptyParts); + + if (enabled_wbs_list.at(0) == all_workbenches) { + enabled_wbs_list.removeFirst(); + QStringList workbenches = Application::Instance->workbenches(); + for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) { + enabled_wbs_list.append(*it); + } + enabled_wbs_list.sort(); + } + return enabled_wbs_list; +} + +void DlgWorkbenchesImp::save_enabled_workbenches() +{ + QString enabled_wbs; + ParameterGrp::handle hGrp; + + hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Workbenches"); + hGrp->Clear(); + + if (lw_enabled_workbenches->count() == 0) { + enabled_wbs.append(QString::fromAscii("NoneWorkbench")); + } else { + for (int i = 0; i < lw_enabled_workbenches->count(); i++) { + QVariant item_data = lw_enabled_workbenches->item(i)->data(Qt::UserRole); + QString name = item_data.toString(); + enabled_wbs.append(name + QString::fromAscii(",")); + } + } + hGrp->SetASCII("Enabled", enabled_wbs.toAscii()); +} + +#include "moc_DlgWorkbenchesImp.cpp" diff --git a/src/Gui/DlgWorkbenchesImp.h b/src/Gui/DlgWorkbenchesImp.h new file mode 100644 index 000000000..3f262af3d --- /dev/null +++ b/src/Gui/DlgWorkbenchesImp.h @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * Based on DlgToolbars.h file * + * * + * 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_DIALOG_DLGWORKBENCHES_IMP_H +#define GUI_DIALOG_DLGWORKBENCHES_IMP_H + +#include "ui_DlgWorkbenches.h" +#include "PropertyPage.h" + +namespace Gui { +namespace Dialog { + +class DlgWorkbenchesImp : public CustomizeActionPage, public Ui_DlgWorkbenches +{ + Q_OBJECT + +public: + DlgWorkbenchesImp(QWidget* parent = 0); + ~DlgWorkbenchesImp(); + static QStringList load_enabled_workbenches(); + static const QString all_workbenches; + +protected: + void changeEvent(QEvent *e); + void hideEvent(QHideEvent * event); + +protected Q_SLOTS: + void onAddMacroAction(const QByteArray&); + void onRemoveMacroAction(const QByteArray&); + void onModifyMacroAction(const QByteArray&); + void on_add_to_enabled_workbenches_btn_clicked(); + void on_remove_from_enabled_workbenches_btn_clicked(); + void on_shift_workbench_up_btn_clicked(); + void on_shift_workbench_down_btn_clicked(); + void on_sort_enabled_workbenches_btn_clicked(); + void on_add_all_to_enabled_workbenches_btn_clicked(); + +private: + void set_lw_properties(QListWidgetCustom *lw); + void add_workbench(QListWidgetCustom *lw, QString it); + void move_workbench(QListWidgetCustom *lwc_dest, + QListWidgetItem *wi); + void save_enabled_workbenches(); + void shift_workbench(bool up); +}; + +} // namespace Dialog +} // namespace Gui + +#endif // GUI_DIALOG_DLGWORKBENCHES_IMP_H diff --git a/src/Gui/Icons/button_add_all.svg b/src/Gui/Icons/button_add_all.svg new file mode 100644 index 000000000..6f2a7fbbe --- /dev/null +++ b/src/Gui/Icons/button_add_all.svg @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/button_sort.svg b/src/Gui/Icons/button_sort.svg new file mode 100644 index 000000000..d9f89c6eb --- /dev/null +++ b/src/Gui/Icons/button_sort.svg @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 09eb5136e..d16f5d53b 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -15,6 +15,8 @@ button_left.svg button_right.svg button_up.svg + button_sort.svg + button_add_all.svg button_valid.svg button_invalid.svg macro-execute.svg diff --git a/src/Gui/QListWidgetCustom.cpp b/src/Gui/QListWidgetCustom.cpp new file mode 100644 index 000000000..0c2754e5a --- /dev/null +++ b/src/Gui/QListWidgetCustom.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * * + * 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_ +# include +# include +# include +#endif + +#include "QListWidgetCustom.h" + +QListWidgetCustom::QListWidgetCustom(QWidget * parent) + : QListWidget(parent) +{ +} + +QListWidgetCustom::~QListWidgetCustom() +{ +} + +/* Overriden dragMoveEvent prevents dragging items that originated + * from the same list for "disabled workbenches". Dragging from outside + * is still allowed. Also it blocks dragging from another instance of FreeCAD + */ +void QListWidgetCustom::dragMoveEvent(QDragMoveEvent *e) +{ + if (e->source() != 0) { + const QString disabled_wbs = QString::fromAscii("disabled workbenches"); + if (e->source()->accessibleName() == disabled_wbs) { + if (e->source() == this) { + e->ignore(); + } else { + e->accept(); + } + } else { + e->accept(); + } + } else { + e->ignore(); + } +} diff --git a/src/Gui/QListWidgetCustom.h b/src/Gui/QListWidgetCustom.h new file mode 100644 index 000000000..6e8a4029d --- /dev/null +++ b/src/Gui/QListWidgetCustom.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (c) 2015 FreeCAD Developers * + * Author: Przemo Firszt * + * * + * 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 QLISTWIDGETCUSTOM_HPP +#define QLISTWIDGETCUSTOM_HPP + +#include +#include +#include + +class QListWidgetCustom : public QListWidget { + +public: + QListWidgetCustom (QWidget *parent); + ~QListWidgetCustom (); + +protected: + void dragMoveEvent(QDragMoveEvent *e); +}; + +#endif diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index ccaf868c6..d61f4a466 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -41,6 +41,7 @@ #include "DlgReportViewImp.h" #include "DlgToolbarsImp.h" +#include "DlgWorkbenchesImp.h" #include "DlgActionsImp.h" #include "DlgCommandsImp.h" #include "DlgKeyboardImp.h" @@ -75,6 +76,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() // new CustomPageProducer; new CustomPageProducer; + new CustomPageProducer; new CustomPageProducer; //new CustomPageProducer; new CustomPageProducer;