00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QInputDialog>
00027 # include <QHeaderView>
00028 # include <QMessageBox>
00029 # include <QToolBar>
00030 #endif
00031
00032 #include "DlgToolbarsImp.h"
00033 #include "Application.h"
00034 #include "BitmapFactory.h"
00035 #include "Command.h"
00036 #include "ToolBarManager.h"
00037 #include "MainWindow.h"
00038 #include "Widgets.h"
00039 #include "Workbench.h"
00040 #include "WorkbenchManager.h"
00041
00042 using namespace Gui::Dialog;
00043
00044 namespace Gui { namespace Dialog {
00045 typedef std::vector< std::pair<QLatin1String, QString> > GroupMap;
00046
00047 struct GroupMap_find {
00048 const QLatin1String& item;
00049 GroupMap_find(const QLatin1String& item) : item(item) {}
00050 bool operator () (const std::pair<QLatin1String, QString>& elem) const
00051 {
00052 return elem.first == item;
00053 }
00054 };
00055 }
00056 }
00057
00058
00059
00067 DlgCustomToolbars::DlgCustomToolbars(DlgCustomToolbars::Type t, QWidget* parent)
00068 : CustomizeActionPage(parent), type(t)
00069 {
00070 this->setupUi(this);
00071
00072 CommandManager & cCmdMgr = Application::Instance->commandManager();
00073 std::map<std::string,Command*> sCommands = cCmdMgr.getCommands();
00074
00075 GroupMap groupMap;
00076 groupMap.push_back(std::make_pair(QLatin1String("File"), QString()));
00077 groupMap.push_back(std::make_pair(QLatin1String("Edit"), QString()));
00078 groupMap.push_back(std::make_pair(QLatin1String("View"), QString()));
00079 groupMap.push_back(std::make_pair(QLatin1String("Standard-View"), QString()));
00080 groupMap.push_back(std::make_pair(QLatin1String("Tools"), QString()));
00081 groupMap.push_back(std::make_pair(QLatin1String("Window"), QString()));
00082 groupMap.push_back(std::make_pair(QLatin1String("Help"), QString()));
00083 groupMap.push_back(std::make_pair(QLatin1String("Macros"), qApp->translate("Gui::MacroCommand", "Macros")));
00084
00085 for (std::map<std::string,Command*>::iterator it = sCommands.begin(); it != sCommands.end(); ++it) {
00086 QLatin1String group(it->second->getGroupName());
00087 QString text = qApp->translate(it->second->className(), it->second->getGroupName());
00088 GroupMap::iterator jt;
00089 jt = std::find_if(groupMap.begin(), groupMap.end(), GroupMap_find(group));
00090 if (jt != groupMap.end())
00091 jt->second = text;
00092 else
00093 groupMap.push_back(std::make_pair(group, text));
00094 }
00095
00096 int index = 0;
00097 for (GroupMap::iterator it = groupMap.begin(); it != groupMap.end(); ++it, ++index) {
00098 categoryBox->addItem(it->second);
00099 categoryBox->setItemData(index, QVariant(it->first), Qt::UserRole);
00100 }
00101
00102
00103 QStringList workbenches = Application::Instance->workbenches();
00104 workbenches.sort();
00105 index = 0;
00106 for (QStringList::Iterator it = workbenches.begin(); it != workbenches.end(); ++it, ++index) {
00107 QPixmap px = Application::Instance->workbenchIcon(*it);
00108 QString mt = Application::Instance->workbenchMenuText(*it);
00109 if ( px.isNull() )
00110 workbenchBox->addItem(mt);
00111 else
00112 workbenchBox->addItem(px, mt);
00113 workbenchBox->setItemData(index, QVariant(*it), Qt::UserRole);
00114 }
00115
00116 QStringList labels;
00117 labels << tr("Icon") << tr("Command");
00118 commandTreeWidget->setHeaderLabels(labels);
00119 commandTreeWidget->header()->hide();
00120 labels.clear(); labels << tr("Command");
00121 toolbarTreeWidget->setHeaderLabels(labels);
00122 toolbarTreeWidget->header()->hide();
00123
00124 on_categoryBox_activated(categoryBox->currentIndex());
00125 Workbench* w = WorkbenchManager::instance()->active();
00126 if (w) {
00127 QString name = QString::fromAscii(w->name().c_str());
00128 int index = workbenchBox->findData(name);
00129 workbenchBox->setCurrentIndex(index);
00130 }
00131 on_workbenchBox_activated(workbenchBox->currentIndex());
00132 }
00133
00135 DlgCustomToolbars::~DlgCustomToolbars()
00136 {
00137 }
00138
00139 void DlgCustomToolbars::addCustomToolbar(const QString&)
00140 {
00141 }
00142
00143 void DlgCustomToolbars::removeCustomToolbar(const QString&)
00144 {
00145 }
00146
00147 void DlgCustomToolbars::renameCustomToolbar(const QString&, const QString&)
00148 {
00149 }
00150
00151 void DlgCustomToolbars::addCustomCommand(const QString&, const QByteArray&)
00152 {
00153 }
00154
00155 void DlgCustomToolbars::removeCustomCommand(const QString&, const QByteArray&)
00156 {
00157 }
00158
00159 void DlgCustomToolbars::moveUpCustomCommand(const QString&, const QByteArray&)
00160 {
00161 }
00162
00163 void DlgCustomToolbars::moveDownCustomCommand(const QString&, const QByteArray&)
00164 {
00165 }
00166
00167 void DlgCustomToolbars::hideEvent(QHideEvent * event)
00168 {
00169 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00170 QString workbench = data.toString();
00171 exportCustomToolbars(workbench.toAscii());
00172
00173 CustomizeActionPage::hideEvent(event);
00174 }
00175
00176 void DlgCustomToolbars::on_categoryBox_activated(int index)
00177 {
00178 QVariant data = categoryBox->itemData(index, Qt::UserRole);
00179 QString group = data.toString();
00180 commandTreeWidget->clear();
00181
00182 CommandManager & cCmdMgr = Application::Instance->commandManager();
00183 std::vector<Command*> aCmds = cCmdMgr.getGroupCommands(group.toAscii());
00184
00185
00186 QTreeWidgetItem* sepitem = new QTreeWidgetItem(commandTreeWidget);
00187 sepitem->setText(1, tr("<Separator>"));
00188 sepitem->setData(1, Qt::UserRole, QByteArray("Separator"));
00189 sepitem->setSizeHint(0, QSize(32, 32));
00190 sepitem->setBackgroundColor(0, Qt::lightGray);
00191 for (std::vector<Command*>::iterator it = aCmds.begin(); it != aCmds.end(); ++it) {
00192 QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
00193 item->setText(1, qApp->translate((*it)->className(), (*it)->getMenuText()));
00194 item->setToolTip(1, qApp->translate((*it)->className(), (*it)->getToolTipText()));
00195 item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
00196 item->setSizeHint(0, QSize(32, 32));
00197 item->setBackgroundColor(0, Qt::lightGray);
00198 if ((*it)->getPixmap())
00199 item->setIcon(0, BitmapFactory().pixmap((*it)->getPixmap()));
00200 }
00201
00202 commandTreeWidget->resizeColumnToContents(0);
00203 }
00204
00205 void DlgCustomToolbars::on_workbenchBox_activated(int index)
00206 {
00207 QVariant data = workbenchBox->itemData(index, Qt::UserRole);
00208 QString workbench = data.toString();
00209 toolbarTreeWidget->clear();
00210
00211 QByteArray workbenchname = workbench.toAscii();
00212 importCustomToolbars(workbenchname);
00213 }
00214
00215 void DlgCustomToolbars::importCustomToolbars(const QByteArray& name)
00216 {
00217 ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench");
00218 const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar");
00219 hGrp = hGrp->GetGroup(name.constData())->GetGroup(subgroup);
00220
00221 std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups();
00222 CommandManager& rMgr = Application::Instance->commandManager();
00223 for (std::vector<Base::Reference<ParameterGrp> >::iterator it = hGrps.begin(); it != hGrps.end(); ++it) {
00224
00225 QTreeWidgetItem* toplevel = new QTreeWidgetItem(toolbarTreeWidget);
00226 bool active = (*it)->GetBool("Active", true);
00227 toplevel->setCheckState(0, (active ? Qt::Checked : Qt::Unchecked));
00228
00229
00230 std::vector<std::pair<std::string,std::string> > items = (*it)->GetASCIIMap();
00231 for (std::vector<std::pair<std::string,std::string> >::iterator it2 = items.begin(); it2 != items.end(); ++it2) {
00232 if (it2->first == "Separator") {
00233 QTreeWidgetItem* item = new QTreeWidgetItem(toplevel);
00234 item->setText(0, tr("<Separator>"));
00235 item->setData(0, Qt::UserRole, QByteArray("Separator"));
00236 item->setSizeHint(0, QSize(32, 32));
00237 } else if (it2->first == "Name") {
00238 QString toolbarName = QString::fromUtf8(it2->second.c_str());
00239 toplevel->setText(0, toolbarName);
00240 } else {
00241 Command* pCmd = rMgr.getCommandByName(it2->first.c_str());
00242 if (pCmd) {
00243
00244 QTreeWidgetItem* item = new QTreeWidgetItem(toplevel);
00245 item->setText(0, qApp->translate(pCmd->className(), pCmd->getMenuText()));
00246 item->setData(0, Qt::UserRole, QByteArray(it2->first.c_str()));
00247 if (pCmd->getPixmap())
00248 item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
00249 item->setSizeHint(0, QSize(32, 32));
00250 }
00251 }
00252 }
00253 }
00254 }
00255
00256 void DlgCustomToolbars::exportCustomToolbars(const QByteArray& workbench)
00257 {
00258 ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench");
00259 const char* subgroup = (type == Toolbar ? "Toolbar" : "Toolboxbar");
00260 hGrp = hGrp->GetGroup(workbench.constData())->GetGroup(subgroup);
00261 hGrp->Clear();
00262
00263 CommandManager& rMgr = Application::Instance->commandManager();
00264 for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) {
00265 QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i);
00266 QString groupName = QString::fromAscii("Custom_%1").arg(i+1);
00267 QByteArray toolbarName = toplevel->text(0).toUtf8();
00268 ParameterGrp::handle hToolGrp = hGrp->GetGroup(groupName.toAscii());
00269 hToolGrp->SetASCII("Name", toolbarName.constData());
00270 hToolGrp->SetBool("Active", toplevel->checkState(0) == Qt::Checked);
00271 for (int j=0; j<toplevel->childCount(); j++) {
00272 QTreeWidgetItem* child = toplevel->child(j);
00273 QByteArray commandName = child->data(0, Qt::UserRole).toByteArray();
00274 if (commandName == "Separator") {
00275 hToolGrp->SetASCII(commandName, commandName);
00276 } else {
00277 Command* pCmd = rMgr.getCommandByName(commandName);
00278 if (pCmd) {
00279 hToolGrp->SetASCII(pCmd->getName(), pCmd->getAppModuleName());
00280 }
00281 }
00282 }
00283 }
00284 }
00285
00287 void DlgCustomToolbars::on_moveActionRightButton_clicked()
00288 {
00289 QTreeWidgetItem* item = commandTreeWidget->currentItem();
00290 if (item) {
00291 QTreeWidgetItem* current = toolbarTreeWidget->currentItem();
00292 if (current && !current->parent() && toolbarTreeWidget->isItemSelected(current)) {
00293 QTreeWidgetItem* copy = new QTreeWidgetItem(current);
00294 copy->setText(0, item->text(1));
00295 copy->setIcon(0, item->icon(0));
00296 QByteArray data = item->data(1, Qt::UserRole).toByteArray();
00297 copy->setData(0, Qt::UserRole, data);
00298 copy->setSizeHint(0, QSize(32, 32));
00299 addCustomCommand(current->text(0), data);
00300 }
00301 }
00302
00303 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00304 QString workbench = data.toString();
00305 exportCustomToolbars(workbench.toAscii());
00306 }
00307
00309 void DlgCustomToolbars::on_moveActionLeftButton_clicked()
00310 {
00311 QTreeWidgetItem* item = toolbarTreeWidget->currentItem();
00312 if (item && item->parent() && toolbarTreeWidget->isItemSelected(item)) {
00313 QTreeWidgetItem* parent = item->parent();
00314 int index = parent->indexOfChild(item);
00315 parent->takeChild(index);
00316 QByteArray data = item->data(0, Qt::UserRole).toByteArray();
00317 removeCustomCommand(parent->text(0), data);
00318 delete item;
00319 }
00320
00321 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00322 QString workbench = data.toString();
00323 exportCustomToolbars(workbench.toAscii());
00324 }
00325
00327 void DlgCustomToolbars::on_moveActionUpButton_clicked()
00328 {
00329 QTreeWidgetItem* item = toolbarTreeWidget->currentItem();
00330 if (item && item->parent() && toolbarTreeWidget->isItemSelected(item)) {
00331 QTreeWidgetItem* parent = item->parent();
00332 int index = parent->indexOfChild(item);
00333 if (index > 0) {
00334 parent->takeChild(index);
00335 parent->insertChild(index-1, item);
00336 toolbarTreeWidget->setCurrentItem(item);
00337 QByteArray data = item->data(0, Qt::UserRole).toByteArray();
00338 moveUpCustomCommand(parent->text(0), data);
00339 }
00340 }
00341
00342 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00343 QString workbench = data.toString();
00344 exportCustomToolbars(workbench.toAscii());
00345 }
00346
00348 void DlgCustomToolbars::on_moveActionDownButton_clicked()
00349 {
00350 QTreeWidgetItem* item = toolbarTreeWidget->currentItem();
00351 if (item && item->parent() && toolbarTreeWidget->isItemSelected(item)) {
00352 QTreeWidgetItem* parent = item->parent();
00353 int index = parent->indexOfChild(item);
00354 if (index < parent->childCount()-1) {
00355 parent->takeChild(index);
00356 parent->insertChild(index+1, item);
00357 toolbarTreeWidget->setCurrentItem(item);
00358 QByteArray data = item->data(0, Qt::UserRole).toByteArray();
00359 moveDownCustomCommand(parent->text(0), data);
00360 }
00361 }
00362
00363 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00364 QString workbench = data.toString();
00365 exportCustomToolbars(workbench.toAscii());
00366 }
00367
00368 void DlgCustomToolbars::on_newButton_clicked()
00369 {
00370 bool ok;
00371 QString text = QString::fromAscii("Custom%1").arg(toolbarTreeWidget->topLevelItemCount()+1);
00372 text = QInputDialog::getText(this, tr("New toolbar"), tr("Toolbar name:"), QLineEdit::Normal, text, &ok);
00373 if (ok) {
00374
00375 for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) {
00376 QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i);
00377 QString groupName = toplevel->text(0);
00378 if (groupName == text) {
00379 QMessageBox::warning(this, tr("Duplicated name"), tr("The toolbar name '%1' is already used").arg(text));
00380 return;
00381 }
00382 }
00383
00384 QTreeWidgetItem* item = new QTreeWidgetItem(toolbarTreeWidget);
00385 item->setText(0, text);
00386 item->setCheckState(0, Qt::Checked);
00387 toolbarTreeWidget->setItemExpanded(item, true);
00388
00389 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00390 QString workbench = data.toString();
00391 exportCustomToolbars(workbench.toAscii());
00392 addCustomToolbar(text);
00393 }
00394 }
00395
00396 void DlgCustomToolbars::on_deleteButton_clicked()
00397 {
00398 QTreeWidgetItem* item = toolbarTreeWidget->currentItem();
00399 if (item && !item->parent() && toolbarTreeWidget->isItemSelected(item)) {
00400 int index = toolbarTreeWidget->indexOfTopLevelItem(item);
00401 toolbarTreeWidget->takeTopLevelItem(index);
00402 removeCustomToolbar(item->text(0));
00403 delete item;
00404 }
00405
00406 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00407 QString workbench = data.toString();
00408 exportCustomToolbars(workbench.toAscii());
00409 }
00410
00411 void DlgCustomToolbars::on_renameButton_clicked()
00412 {
00413 bool renamed = false;
00414 QTreeWidgetItem* item = toolbarTreeWidget->currentItem();
00415 if (item && !item->parent() && toolbarTreeWidget->isItemSelected(item)) {
00416 bool ok;
00417 QString old_text = item->text(0);
00418 QString text = QInputDialog::getText(this, tr("Rename toolbar"), tr("Toolbar name:"),
00419 QLineEdit::Normal, old_text, &ok);
00420 if (ok && text != old_text) {
00421
00422 for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) {
00423 QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i);
00424 QString groupName = toplevel->text(0);
00425 if (groupName == text && toplevel != item) {
00426 QMessageBox::warning(this, tr("Duplicated name"), tr("The toolbar name '%1' is already used").arg(text));
00427 return;
00428 }
00429 }
00430
00431 item->setText(0, text);
00432 renameCustomToolbar(old_text, text);
00433 renamed = true;
00434 }
00435 }
00436
00437 if (renamed) {
00438 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00439 QString workbench = data.toString();
00440 exportCustomToolbars(workbench.toAscii());
00441 }
00442 }
00443
00444 void DlgCustomToolbars::onAddMacroAction(const QByteArray& macro)
00445 {
00446 QVariant data = categoryBox->itemData(categoryBox->currentIndex(), Qt::UserRole);
00447 QString group = data.toString();
00448 if (group == QLatin1String("Macros"))
00449 {
00450 CommandManager & cCmdMgr = Application::Instance->commandManager();
00451 Command* pCmd = cCmdMgr.getCommandByName(macro);
00452
00453 QTreeWidgetItem* item = new QTreeWidgetItem(commandTreeWidget);
00454 item->setText(1, QString::fromUtf8(pCmd->getMenuText()));
00455 item->setToolTip(1, QString::fromUtf8(pCmd->getToolTipText()));
00456 item->setData(1, Qt::UserRole, macro);
00457 item->setSizeHint(0, QSize(32, 32));
00458 item->setBackgroundColor(0, Qt::lightGray);
00459 if (pCmd->getPixmap())
00460 item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
00461 }
00462 }
00463
00464 void DlgCustomToolbars::onRemoveMacroAction(const QByteArray& macro)
00465 {
00466 QVariant data = categoryBox->itemData(categoryBox->currentIndex(), Qt::UserRole);
00467 QString group = data.toString();
00468 if (group == QLatin1String("Macros"))
00469 {
00470 for (int i=0; i<commandTreeWidget->topLevelItemCount(); i++) {
00471 QTreeWidgetItem* item = commandTreeWidget->topLevelItem(i);
00472 QByteArray command = item->data(1, Qt::UserRole).toByteArray();
00473 if (command == macro) {
00474 commandTreeWidget->takeTopLevelItem(i);
00475 delete item;
00476 break;
00477 }
00478 }
00479 }
00480 }
00481
00482 void DlgCustomToolbars::onModifyMacroAction(const QByteArray& macro)
00483 {
00484 QVariant data = categoryBox->itemData(categoryBox->currentIndex(), Qt::UserRole);
00485 QString group = data.toString();
00486 if (group == QLatin1String("Macros"))
00487 {
00488 CommandManager & cCmdMgr = Application::Instance->commandManager();
00489 Command* pCmd = cCmdMgr.getCommandByName(macro);
00490
00491 for (int i=0; i<commandTreeWidget->topLevelItemCount(); i++) {
00492 QTreeWidgetItem* item = commandTreeWidget->topLevelItem(i);
00493 QByteArray command = item->data(1, Qt::UserRole).toByteArray();
00494 if (command == macro) {
00495 item->setText(1, QString::fromUtf8(pCmd->getMenuText()));
00496 item->setToolTip(1, QString::fromUtf8(pCmd->getToolTipText()));
00497 item->setData(1, Qt::UserRole, macro);
00498 item->setSizeHint(0, QSize(32, 32));
00499 item->setBackgroundColor(0, Qt::lightGray);
00500 if (pCmd->getPixmap())
00501 item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
00502 break;
00503 }
00504 }
00505
00506 for (int i=0; i<toolbarTreeWidget->topLevelItemCount(); i++) {
00507 QTreeWidgetItem* toplevel = toolbarTreeWidget->topLevelItem(i);
00508 for (int j=0; j<toplevel->childCount(); j++) {
00509 QTreeWidgetItem* item = toplevel->child(j);
00510 QByteArray command = item->data(0, Qt::UserRole).toByteArray();
00511 if (command == macro) {
00512 item->setText(0, QString::fromUtf8(pCmd->getMenuText()));
00513 if (pCmd->getPixmap())
00514 item->setIcon(0, BitmapFactory().pixmap(pCmd->getPixmap()));
00515 }
00516 }
00517 }
00518 }
00519 }
00520
00521 void DlgCustomToolbars::changeEvent(QEvent *e)
00522 {
00523 if (e->type() == QEvent::LanguageChange) {
00524 this->retranslateUi(this);
00525 int count = categoryBox->count();
00526
00527 CommandManager & cCmdMgr = Application::Instance->commandManager();
00528 for (int i=0; i<count; i++) {
00529 QVariant data = categoryBox->itemData(i, Qt::UserRole);
00530 std::vector<Command*> aCmds = cCmdMgr.getGroupCommands(data.toByteArray());
00531 if (!aCmds.empty()) {
00532 QString text = qApp->translate(aCmds[0]->className(), aCmds[0]->getGroupName());
00533 categoryBox->setItemText(i, text);
00534 }
00535 }
00536 on_categoryBox_activated(categoryBox->currentIndex());
00537 }
00538 QWidget::changeEvent(e);
00539 }
00540
00541
00542
00543
00544
00552 DlgCustomToolbarsImp::DlgCustomToolbarsImp( QWidget* parent )
00553 : DlgCustomToolbars(DlgCustomToolbars::Toolbar, parent)
00554 {
00555 }
00556
00558 DlgCustomToolbarsImp::~DlgCustomToolbarsImp()
00559 {
00560 }
00561
00562 void DlgCustomToolbarsImp::addCustomToolbar(const QString& name)
00563 {
00564 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00565 Workbench* w = WorkbenchManager::instance()->active();
00566 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00567 QToolBar* bar = getMainWindow()->addToolBar(name);
00568 bar->setObjectName(name);
00569 }
00570 }
00571
00572 void DlgCustomToolbarsImp::removeCustomToolbar(const QString& name)
00573 {
00574 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00575 Workbench* w = WorkbenchManager::instance()->active();
00576 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00577 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
00578 if (bars.size() != 1) return;
00579 QToolBar* tb = bars.front();
00580 getMainWindow()->removeToolBar(tb);
00581 delete tb;
00582 }
00583 }
00584
00585 void DlgCustomToolbarsImp::renameCustomToolbar(const QString& old_name, const QString& new_name)
00586 {
00587 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00588 Workbench* w = WorkbenchManager::instance()->active();
00589 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00590 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(old_name);
00591 if (bars.size() != 1) return;
00592 QToolBar* tb = bars.front();
00593 tb->setObjectName(new_name);
00594 tb->setWindowTitle(new_name);
00595 }
00596 }
00597
00598 void DlgCustomToolbarsImp::addCustomCommand(const QString& name, const QByteArray& cmd)
00599 {
00600 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00601 Workbench* w = WorkbenchManager::instance()->active();
00602 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00603 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
00604 if (bars.size() != 1) return;
00605 CommandManager& mgr = Application::Instance->commandManager();
00606 mgr.addTo(cmd, bars.front());
00607 }
00608 }
00609
00610 void DlgCustomToolbarsImp::removeCustomCommand(const QString& name, const QByteArray& cmd)
00611 {
00612 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00613 Workbench* w = WorkbenchManager::instance()->active();
00614 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00615 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
00616 if (bars.size() != 1) return;
00617 QList<QAction*> actions = bars.front()->actions();
00618 for (QList<QAction*>::ConstIterator it = actions.begin(); it != actions.end(); ++it) {
00619 if ((*it)->data().toByteArray() == cmd) {
00620 bars.front()->removeAction(*it);
00621 break;
00622 }
00623 }
00624 }
00625 }
00626
00627 void DlgCustomToolbarsImp::moveUpCustomCommand(const QString& name, const QByteArray& cmd)
00628 {
00629 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00630 Workbench* w = WorkbenchManager::instance()->active();
00631 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00632 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
00633 if (bars.size() != 1) return;
00634 QList<QAction*> actions = bars.front()->actions();
00635 QAction* before=0;
00636 for (QList<QAction*>::ConstIterator it = actions.begin(); it != actions.end(); ++it) {
00637 if ((*it)->data().toByteArray() == cmd) {
00638 if (before != 0) {
00639 bars.front()->removeAction(*it);
00640 bars.front()->insertAction(before, *it);
00641 break;
00642 }
00643 }
00644
00645 before = *it;
00646 }
00647 }
00648 }
00649
00650 void DlgCustomToolbarsImp::moveDownCustomCommand(const QString& name, const QByteArray& cmd)
00651 {
00652 QVariant data = workbenchBox->itemData(workbenchBox->currentIndex(), Qt::UserRole);
00653 Workbench* w = WorkbenchManager::instance()->active();
00654 if (w && w->name() == std::string((const char*)data.toByteArray())) {
00655 QList<QToolBar*> bars = getMainWindow()->findChildren<QToolBar*>(name);
00656 if (bars.size() != 1) return;
00657 QList<QAction*> actions = bars.front()->actions();
00658 for (QList<QAction*>::ConstIterator it = actions.begin(); it != actions.end(); ++it) {
00659 if ((*it)->data().toByteArray() == cmd) {
00660 QAction* act = *it;
00661 if (*it == actions.back())
00662 break;
00663 ++it;
00664
00665 if (*it == actions.back()) {
00666 bars.front()->removeAction(act);
00667 bars.front()->addAction(act);
00668 break;
00669 }
00670 ++it;
00671 bars.front()->removeAction(act);
00672 bars.front()->insertAction(*it, act);
00673 break;
00674 }
00675 }
00676 }
00677 }
00678
00679 void DlgCustomToolbarsImp::changeEvent(QEvent *e)
00680 {
00681 if (e->type() == QEvent::LanguageChange) {
00682 }
00683 DlgCustomToolbars::changeEvent(e);
00684 }
00685
00686
00687
00688
00696 DlgCustomToolBoxbarsImp::DlgCustomToolBoxbarsImp( QWidget* parent )
00697 : DlgCustomToolbars(DlgCustomToolbars::Toolboxbar, parent)
00698 {
00699 setWindowTitle( tr( "Toolbox bars" ) );
00700 }
00701
00703 DlgCustomToolBoxbarsImp::~DlgCustomToolBoxbarsImp()
00704 {
00705 }
00706
00707 void DlgCustomToolBoxbarsImp::changeEvent(QEvent *e)
00708 {
00709 if (e->type() == QEvent::LanguageChange) {
00710 setWindowTitle( tr( "Toolbox bars" ) );
00711 }
00712 DlgCustomToolbars::changeEvent(e);
00713 }
00714
00715 #include "moc_DlgToolbarsImp.cpp"