1
/***************************************************************************
2
* Copyright (c) 2004 Werner Mayer <werner.wm.mayer@gmx.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
#include "DlgCommandsImp.h"
27
#include "Application.h"
29
#include "BitmapFactory.h"
32
using namespace Gui::Dialog;
34
/* TRANSLATOR Gui::Dialog::DlgCustomCommandsImp */
37
* Constructs a DlgCustomCommandsImp which is a child of 'parent', with the
38
* name 'name' and widget flags set to 'f'
40
* The dialog will by default be modeless, unless you set 'modal' to
41
* TRUE to construct a modal dialog.
43
DlgCustomCommandsImp::DlgCustomCommandsImp( QWidget* parent )
44
: CustomizeActionPage(parent)
48
// paints for active and inactive the same color
49
QPalette pal = categoryTreeWidget->palette();
50
pal.setColor(QPalette::Inactive, QPalette::Highlight, pal.color(QPalette::Active, QPalette::Highlight));
51
pal.setColor(QPalette::Inactive, QPalette::HighlightedText, pal.color(QPalette::Active, QPalette::HighlightedText));
52
categoryTreeWidget->setPalette( pal );
54
connect(commandTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
55
this, SLOT(onDescription(QTreeWidgetItem*)));
56
connect(categoryTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)),
57
this, SLOT(onGroupActivated(QTreeWidgetItem*)));
59
CommandManager & cCmdMgr = Application::Instance->commandManager();
60
std::map<std::string,Command*> sCommands = cCmdMgr.getCommands();
62
// do a special sort before adding to the tree view
64
groups << QLatin1String("File") << QLatin1String("Edit")
65
<< QLatin1String("View") << QLatin1String("Standard-View")
66
<< QLatin1String("Tools") << QLatin1String("Window")
67
<< QLatin1String("Help") << QLatin1String("Macros");
68
for (std::map<std::string,Command*>::iterator it = sCommands.begin(); it != sCommands.end(); ++it) {
69
QString group = QLatin1String(it->second->getGroupName());
70
if (!groups.contains(group))
74
QStringList labels; labels << tr("Category");
75
categoryTreeWidget->setHeaderLabels(labels);
76
for ( QStringList::Iterator It = groups.begin(); It != groups.end(); ++It ) {
77
QTreeWidgetItem* item = new QTreeWidgetItem(categoryTreeWidget);
78
item->setText(0, QObject::tr((*It).toAscii()));
79
item->setData(0, Qt::UserRole, QVariant(*It));
83
labels << tr("Icon") << tr("Command");
84
commandTreeWidget->setHeaderLabels(labels);
85
commandTreeWidget->header()->hide();
87
categoryTreeWidget->setCurrentItem(categoryTreeWidget->topLevelItem(0));
90
/** Destroys the object and frees any allocated resources */
91
DlgCustomCommandsImp::~DlgCustomCommandsImp()
95
/** Shows the description for the corresponding command */
96
void DlgCustomCommandsImp::onDescription(QTreeWidgetItem *item)
99
textLabel->setText(item->toolTip(1));
101
textLabel->setText(QString());
104
/** Shows all commands of this category */
105
void DlgCustomCommandsImp::onGroupActivated(QTreeWidgetItem* item)
110
QVariant data = item->data(0, Qt::UserRole);
111
QString group = data.toString();
112
commandTreeWidget->clear();
114
CommandManager & cCmdMgr = Application::Instance->commandManager();
115
std::vector<Command*> aCmds = cCmdMgr.getGroupCommands(group.toAscii());
116
for (std::vector<Command*>::iterator it = aCmds.begin(); it != aCmds.end(); ++it) {
117
QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
118
item->setText(1, QObject::trUtf8((*it)->getMenuText()));
119
item->setToolTip(1, QObject::trUtf8((*it)->getToolTipText()));
120
item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
121
item->setSizeHint(0, QSize(32, 32));
122
item->setBackgroundColor(0, Qt::lightGray);
123
if ((*it)->getPixmap())
124
item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
127
textLabel->setText(QString());
128
commandTreeWidget->resizeColumnToContents(0);
131
void DlgCustomCommandsImp::onAddMacroAction(const QByteArray& macro)
133
QTreeWidgetItem* item = categoryTreeWidget->currentItem();
137
QVariant data = item->data(0, Qt::UserRole);
138
QString group = data.toString();
139
if (group == QLatin1String("Macros"))
141
CommandManager & cCmdMgr = Application::Instance->commandManager();
142
Command* pCmd = cCmdMgr.getCommandByName(macro);
144
QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
145
item->setText(1, QString::fromUtf8(pCmd->getMenuText()));
146
item->setToolTip(1, QString::fromUtf8(pCmd->getToolTipText()));
147
item->setData(1, Qt::UserRole, macro);
148
item->setSizeHint(0, QSize(32, 32));
149
item->setBackgroundColor(0, Qt::lightGray);
150
if (pCmd->getPixmap())
151
item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
155
void DlgCustomCommandsImp::onRemoveMacroAction(const QByteArray& macro)
157
QTreeWidgetItem* item = categoryTreeWidget->currentItem();
161
QVariant data = item->data(0, Qt::UserRole);
162
QString group = data.toString();
163
if (group == QLatin1String("Macros"))
165
for (int i=0; i<commandTreeWidget->topLevelItemCount(); i++) {
166
QTreeWidgetItem* item = commandTreeWidget->topLevelItem(i);
167
QByteArray command = item->data(1, Qt::UserRole).toByteArray();
168
if (command == macro) {
169
commandTreeWidget->takeTopLevelItem(i);
177
void DlgCustomCommandsImp::onModifyMacroAction(const QByteArray& macro)
179
QTreeWidgetItem* item = categoryTreeWidget->currentItem();
183
QVariant data = item->data(0, Qt::UserRole);
184
QString group = data.toString();
185
if (group == QLatin1String("Macros"))
187
CommandManager & cCmdMgr = Application::Instance->commandManager();
188
Command* pCmd = cCmdMgr.getCommandByName(macro);
189
for (int i=0; i<commandTreeWidget->topLevelItemCount(); i++) {
190
QTreeWidgetItem* item = commandTreeWidget->topLevelItem(i);
191
QByteArray command = item->data(1, Qt::UserRole).toByteArray();
192
if (command == macro) {
193
item->setText(1, QString::fromUtf8(pCmd->getMenuText()));
194
item->setToolTip(1, QString::fromUtf8(pCmd->getToolTipText()));
195
item->setData(1, Qt::UserRole, macro);
196
item->setSizeHint(0, QSize(32, 32));
197
item->setBackgroundColor(0, Qt::lightGray);
198
if (pCmd->getPixmap())
199
item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
200
if (commandTreeWidget->isItemSelected(item))
208
#include "moc_DlgCommandsImp.cpp"