Skip to content

Commit

Permalink
Walkthrough for adding macros to custom global toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
mwganson authored and wwmayer committed Jul 21, 2019
1 parent e239994 commit 1c6af88
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Gui/DlgCustomizeImp.cpp
Expand Up @@ -78,6 +78,7 @@ DlgCustomizeImp::DlgCustomizeImp(QWidget* parent, Qt::WindowFlags fl)
customLayout->addLayout( layout, 1, 0 );

tabWidget = new QTabWidget( this );
tabWidget->setObjectName(QString::fromLatin1("Gui__Dialog__TabWidget"));//so we can find it in DlgMacroExecuteImp

// make sure that pages are ready to create
GetWidgetFactorySupplier();
Expand Down
20 changes: 14 additions & 6 deletions src/Gui/DlgMacroExecute.ui
Expand Up @@ -166,9 +166,6 @@
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="mode" >
<enum>Gui::FileChooser::Directory</enum>
</property>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -266,13 +263,23 @@
</item>
<item>
<widget class="QPushButton" name="duplicateButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Duplicate</string>
<string>Duplicate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="toolbarButton">
<property name="enabled">
<bool>false</bool>
<bool>false</bool>
</property>
</widget>
<property name="text">
<string>Toolbar</string>
</property>
</widget>
</item>
<item>
<spacer>
Expand Down Expand Up @@ -320,6 +327,7 @@
<tabstop>editButton</tabstop>
<tabstop>renameButton</tabstop>
<tabstop>duplicateButton</tabstop>
<tabstop>toolbarButton</tabstop>
<tabstop>addonsButton</tabstop>
<tabstop>fileChooser</tabstop>
</tabstops>
Expand Down
148 changes: 148 additions & 0 deletions src/Gui/DlgMacroExecuteImp.cpp
Expand Up @@ -26,6 +26,8 @@
# include <QInputDialog>
# include <QHeaderView>
# include <QMessageBox>
# include <QComboBox>
# include <QPointer>
#endif

#include "DlgMacroExecuteImp.h"
Expand All @@ -38,6 +40,8 @@
#include "Document.h"
#include "EditorView.h"
#include "PythonEditor.h"
#include "DlgCustomizeImp.h"
#include "DlgToolbarsImp.h"

#include <App/Application.h>
#include <App/Document.h>
Expand Down Expand Up @@ -136,6 +140,7 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem*

executeButton->setEnabled(true);
deleteButton->setEnabled(true);
toolbarButton->setEnabled(true);
createButton->setEnabled(true);
editButton->setEnabled(true);
renameButton->setEnabled(true);
Expand All @@ -144,6 +149,7 @@ void DlgMacroExecuteImp::on_userMacroListBox_currentItemChanged(QTreeWidgetItem*
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(true);
editButton->setEnabled(false);
renameButton->setEnabled(false);
Expand All @@ -158,6 +164,7 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte

executeButton->setEnabled(true);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(true); //look but don't touch
renameButton->setEnabled(false);
Expand All @@ -166,6 +173,7 @@ void DlgMacroExecuteImp::on_systemMacroListBox_currentItemChanged(QTreeWidgetIte
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(false);
renameButton->setEnabled(false);
Expand All @@ -182,6 +190,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
if (item) {
executeButton->setEnabled(true);
deleteButton->setEnabled(true);
toolbarButton->setEnabled(true);
createButton->setEnabled(true);
editButton->setEnabled(true);
renameButton->setEnabled(true);
Expand All @@ -190,6 +199,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(true);
editButton->setEnabled(false);
renameButton->setEnabled(false);
Expand All @@ -202,6 +212,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
if (item) {
executeButton->setEnabled(true);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(true); //but you can't save it
renameButton->setEnabled(false);
Expand All @@ -210,6 +221,7 @@ void DlgMacroExecuteImp::on_tabMacroWidget_currentChanged(int index)
else {
executeButton->setEnabled(false);
deleteButton->setEnabled(false);
toolbarButton->setEnabled(false);
createButton->setEnabled(false);
editButton->setEnabled(false);
renameButton->setEnabled(false);
Expand Down Expand Up @@ -401,6 +413,142 @@ void DlgMacroExecuteImp::on_deleteButton_clicked()
}
}

/**
* Walk user through process of adding macro to global custom toolbar
* We create a custom customize dialog with instructions embedded
* within the dialog itself for the user, and the buttons to push in red text
* There are 2 dialogs we need to create: the macros dialog and the
* toolbar dialog.
*/

void DlgMacroExecuteImp::on_toolbarButton_clicked(){

/** advise user of what we are doing, offer chance to cancel **/
QMessageBox msgBox;
msgBox.setText(tr("Guided Walkthrough"));
msgBox.setInformativeText(tr("This will guide you in setting up this macro in a custom \
global toolbar. Instructions will be in red text in the 2 dialogs that follow.\n"));
msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Ok);
int result = msgBox.exec();
if (result == QMessageBox::Cancel){
return;
}
QTreeWidgetItem* item = userMacroListBox->currentItem();
if (!item)
return;

QString fn = item->text(0);
QString bareFileName = fn; //for use as default menu text (filename without extension)
bareFileName.remove(QString::fromLatin1(".FCMacro").remove(QString::fromLatin1(".py")));

/** check if user already has custom toolbar, so we can tailor instructions accordingly **/
bool hasCustomToolbar = true;
if (App::GetApplication().GetParameterGroupByPath( QByteArray("User parameter:BaseApp/Workbench/Global/Toolbar"))->GetGroups().size()==0){
hasCustomToolbar=false;
}

/** first the custom macros page dialog **/

static QPointer<QDialog> dlg = 0;
if (!dlg)
dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setModal(true);
/** title is normally "Customize" **/
dlg->setWindowTitle(tr("Walkthrough, dialog 1 of 2"));

QTabWidget* tabWidget = dlg->findChild<QTabWidget*>(QString::fromLatin1("Gui__Dialog__TabWidget"));
QWidget* setupCustomMacrosPage = tabWidget->findChild<QWidget*>(QString::fromUtf8("Gui__Dialog__DlgCustomActions"));
tabWidget->setCurrentWidget(setupCustomMacrosPage);
QGroupBox* groupBox7 = setupCustomMacrosPage->findChild<QGroupBox*>(QString::fromUtf8("GroupBox7"));
QPushButton* buttonAddAction = setupCustomMacrosPage->findChild<QPushButton*>(QString::fromUtf8("buttonAddAction"));
buttonAddAction->setStyleSheet(QString::fromLatin1("color:red"));

/** normally the groupbox title is "Setup Custom Macros", but we change it here **/
groupBox7->setTitle(tr("Walkthrough instructions: Fill in missing fields (optional) then click Add, then Close"));
groupBox7->setStyleSheet(QString::fromLatin1("QGroupBox::title {color:red}"));

QComboBox* macroListBox = setupCustomMacrosPage->findChild<QComboBox*>(QString::fromUtf8("actionMacros"));
int macroIndex = macroListBox->findText(fn); //fn is the macro filename
macroListBox->setCurrentIndex(macroIndex); //select it for the user so he doesn't have to
QLineEdit* menuText = setupCustomMacrosPage->findChild<QLineEdit*>(QString::fromUtf8("actionMenu"));
menuText->setText(bareFileName); //user can fill in other fields, e.g. tooltip
dlg->exec();

/** now for the toolbar selection dialog **/

dlg = 0;
if (!dlg){
dlg = new Gui::Dialog::DlgCustomizeImp(getMainWindow());
}
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setModal(true);
dlg->setWindowTitle(tr("Walkthrough, dialog 2 of 2"));

tabWidget = dlg->findChild<QTabWidget*>(QString::fromLatin1("Gui__Dialog__TabWidget"));
DlgCustomToolbars* setupToolbarPage = tabWidget->findChild<DlgCustomToolbars*>(QString::fromUtf8("Gui__Dialog__DlgCustomToolbars"));
tabWidget->setCurrentWidget(setupToolbarPage);
QPushButton* moveActionRightButton = setupToolbarPage->findChild<QPushButton*>(QString::fromUtf8("moveActionRightButton"));
moveActionRightButton->setStyleSheet(QString::fromLatin1("background-color: red"));

/** tailor instructions depending on whether user already has custom toolbar created
* if not he needs to click New button to create one first
**/

QString instructions2 = tr("Walkthrough instructions: Click right arrow button (->), then Close.");
QComboBox* workbenchBox = setupToolbarPage->findChild<QComboBox*>(QString::fromUtf8("workbenchBox"));
if (!hasCustomToolbar){
QPushButton* newButton = setupToolbarPage->findChild<QPushButton*>(QString::fromUtf8("newButton"));
newButton->setStyleSheet(QString::fromLatin1("color:red"));
instructions2 = tr("Walkthrough instructions: Click New, then right arrow (->) button, then Close.");
}

/** "label" normally says "Note: the changes become active the next time you load the appropriate workbench" **/

QLabel *label = setupToolbarPage->findChild<QLabel*>(QString::fromLatin1("label"));
label->setText(instructions2);
label->setStyleSheet(QString::fromLatin1("color:red"));

/** find the Global workbench and select it for the user **/

int globalIdx = workbenchBox->findText(tr("Global"));
if (globalIdx != -1){
workbenchBox->setCurrentIndex(globalIdx);
setupToolbarPage->on_workbenchBox_activated(globalIdx);
} else {
workbenchBox->setCurrentIndex(0);
setupToolbarPage->on_workbenchBox_activated(0);
}

/** find Macros category and select it for the user **/

QComboBox* categoryBox = setupToolbarPage->findChild<QComboBox*>(QString::fromUtf8("categoryBox"));
int macrosIdx = categoryBox->findText(tr("Macros"));
if (macrosIdx != -1){
categoryBox->setCurrentIndex(macrosIdx);
setupToolbarPage->on_categoryBox_activated(macrosIdx);
} else {
categoryBox->setCurrentIndex(7); //Macros is our desired selection
setupToolbarPage->on_categoryBox_activated(7);
}

/** the macro we just added in the first dialog will be at the bottom of this list **/

QTreeWidget* commandTreeWidget = setupToolbarPage->findChild<QTreeWidget*>(QString::fromUtf8("commandTreeWidget"));
commandTreeWidget->setCurrentItem(commandTreeWidget->topLevelItem(commandTreeWidget->topLevelItemCount()-1));
commandTreeWidget->scrollToItem(commandTreeWidget->currentItem());

dlg->exec();

QMessageBox msgBox2;
msgBox2.setText(tr("Guided Walkthrough"));
msgBox2.setInformativeText(tr("Your changes will take effect when you switch workbenches."));
msgBox2.exec();
}



/**
* renames the selected macro
*/
Expand Down
1 change: 1 addition & 0 deletions src/Gui/DlgMacroExecuteImp.h
Expand Up @@ -52,6 +52,7 @@ public Q_SLOTS:
void on_editButton_clicked();
void on_renameButton_clicked();
void on_duplicateButton_clicked();
void on_toolbarButton_clicked();
void on_addonsButton_clicked();

protected Q_SLOTS:
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/DlgToolbarsImp.h
Expand Up @@ -26,6 +26,7 @@

#include "ui_DlgToolbars.h"
#include "PropertyPage.h"
#include "DlgMacroExecuteImp.h"

namespace Gui {
namespace Dialog {
Expand All @@ -43,6 +44,7 @@ class DlgCustomToolbars : public CustomizeActionPage, public Ui_DlgCustomToolbar
Q_OBJECT

protected:
friend class DlgMacroExecuteImp;
enum Type { Toolbar, Toolboxbar };

DlgCustomToolbars(Type, QWidget* parent = 0);
Expand Down

0 comments on commit 1c6af88

Please sign in to comment.