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
00026 #ifndef _PreComp_
00027 # include <boost/signals.hpp>
00028 # include <boost/bind.hpp>
00029 # include <QActionEvent>
00030 # include <QApplication>
00031 # include <QEvent>
00032 # include <QMessageBox>
00033 # include <QToolBar>
00034 # include <QToolButton>
00035 #endif
00036
00037 #include "Action.h"
00038 #include "Application.h"
00039 #include "Command.h"
00040 #include "DlgUndoRedo.h"
00041 #include "FileDialog.h"
00042 #include "MainWindow.h"
00043 #include "WhatsThis.h"
00044 #include "Workbench.h"
00045 #include "WorkbenchManager.h"
00046
00047 #include <Base/Exception.h>
00048 #include <App/Application.h>
00049
00050 using namespace Gui;
00051 using namespace Gui::Dialog;
00052
00057 Action::Action (Command* pcCmd,QObject * parent)
00058 : QObject(parent), _action(new QAction( this )), _pcCmd(pcCmd)
00059 {
00060 _action->setObjectName(QString::fromAscii(_pcCmd->getName()));
00061 connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
00062 }
00063
00064 Action::~Action()
00065 {
00066 delete _action;
00067 }
00068
00072 void Action::addTo(QWidget *w)
00073 {
00074 w->addAction(_action);
00075 }
00076
00080 void Action::onActivated ()
00081 {
00082 _pcCmd->invoke(0);
00083 }
00084
00088 void Action::onToggled(bool b)
00089 {
00090 _pcCmd->invoke( b ? 1 : 0 );
00091 }
00092
00093 void Action::setCheckable(bool b)
00094 {
00095 _action->setCheckable(b);
00096 if (b) {
00097 disconnect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
00098 connect(_action, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
00099 }
00100 else {
00101 connect(_action, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
00102 disconnect(_action, SIGNAL(toggled(bool)), this, SLOT(onToggled(bool)));
00103 }
00104 }
00105
00106 void Action::setChecked(bool b)
00107 {
00108 _action->setChecked(b);
00109 }
00110
00111 bool Action::isChecked() const
00112 {
00113 return _action->isChecked();
00114 }
00115
00119 void Action::setEnabled(bool b)
00120 {
00121 _action->setEnabled(b);
00122 }
00123
00124 void Action::setVisible(bool b)
00125 {
00126 _action->setVisible(b);
00127 }
00128
00129 void Action::setShortcut(const QString & key)
00130 {
00131 _action->setShortcut(key);
00132 }
00133
00134 QKeySequence Action::shortcut() const
00135 {
00136 return _action->shortcut();
00137 }
00138
00139 void Action::setIcon (const QIcon & icon)
00140 {
00141 _action->setIcon(icon);
00142 }
00143
00144 void Action::setStatusTip(const QString & s)
00145 {
00146 _action->setStatusTip(s);
00147 }
00148
00149 QString Action::statusTip() const
00150 {
00151 return _action->statusTip();
00152 }
00153
00154 void Action::setText(const QString & s)
00155 {
00156 _action->setText(s);
00157 }
00158
00159 QString Action::text() const
00160 {
00161 return _action->text();
00162 }
00163
00164 void Action::setToolTip(const QString & s)
00165 {
00166 _action->setToolTip(s);
00167 }
00168
00169 QString Action::toolTip() const
00170 {
00171 return _action->toolTip();
00172 }
00173
00174 void Action::setWhatsThis(const QString & s)
00175 {
00176 _action->setWhatsThis(s);
00177 }
00178
00179 QString Action::whatsThis() const
00180 {
00181 return _action->whatsThis();
00182 }
00183
00184
00185
00190 ActionGroup::ActionGroup ( Command* pcCmd,QObject * parent)
00191 : Action(pcCmd, parent), _group(0), _dropDown(false)
00192 {
00193 _group = new QActionGroup(this);
00194 connect(_group, SIGNAL(triggered(QAction*)), this, SLOT(onActivated (QAction*)));
00195 }
00196
00197 ActionGroup::~ActionGroup()
00198 {
00199 delete _group;
00200 }
00201
00205 void ActionGroup::addTo(QWidget *w)
00206 {
00207
00208
00209
00210
00211 if (_dropDown) {
00212 if (w->inherits("QMenu")) {
00213 QMenu* menu = qobject_cast<QMenu*>(w);
00214 menu = menu->addMenu(_action->text());
00215 menu->addActions(_group->actions());
00216 }
00217 else if (w->inherits("QToolBar")) {
00218 w->addAction(_action);
00219 QToolButton* tb = w->findChildren<QToolButton*>().last();
00220 tb->setPopupMode(QToolButton::MenuButtonPopup);
00221 QList<QAction*> acts = _group->actions();
00222 QMenu* menu = new QMenu(tb);
00223 menu->addActions(acts);
00224 tb->setMenu(menu);
00225
00226 }
00227 else {
00228 w->addActions(_group->actions());
00229 }
00230 }
00231 else {
00232 w->addActions(_group->actions());
00233 }
00234 }
00235
00236 void ActionGroup::setEnabled( bool b )
00237 {
00238 Action::setEnabled(b);
00239 _group->setEnabled(b);
00240 }
00241
00242 void ActionGroup::setDisabled (bool b)
00243 {
00244 Action::setEnabled(!b);
00245 _group->setDisabled(b);
00246 }
00247
00248 void ActionGroup::setExclusive (bool b)
00249 {
00250 _group->setExclusive(b);
00251 }
00252
00253 void ActionGroup::setVisible( bool b )
00254 {
00255 Action::setVisible(b);
00256 _group->setVisible(b);
00257 }
00258
00259 QAction* ActionGroup::addAction(const QString& text)
00260 {
00261 int index = _group->actions().size();
00262 QAction* action = _group->addAction(text);
00263 action->setData(QVariant(index));
00264 return action;
00265 }
00266
00267 QList<QAction*> ActionGroup::actions() const
00268 {
00269 return _group->actions();
00270 }
00271
00272 int ActionGroup::checkedAction() const
00273 {
00274 QAction* checked = _group->checkedAction();
00275 return checked ? checked->data().toInt() : -1;
00276 }
00277
00278 void ActionGroup::setCheckedAction(int i)
00279 {
00280 _group->actions()[i]->setChecked(true);
00281 }
00282
00286 void ActionGroup::onActivated ()
00287 {
00288 _pcCmd->invoke(this->property("defaultAction").toInt());
00289 }
00290
00294 void ActionGroup::onActivated (QAction* a)
00295 {
00296 int index = _group->actions().indexOf(a);
00297
00298 QList<QWidget*> widgets = a->associatedWidgets();
00299 for (QList<QWidget*>::iterator it = widgets.begin(); it != widgets.end(); ++it) {
00300 QMenu* menu = qobject_cast<QMenu*>(*it);
00301 if (menu) {
00302 QToolButton* button = qobject_cast<QToolButton*>(menu->parent());
00303 if (button) {
00304 button->setIcon(a->icon());
00305 this->setProperty("defaultAction", QVariant(index));
00306 }
00307 }
00308 }
00309
00310 _pcCmd->invoke(index);
00311 }
00312
00313
00314
00315 namespace Gui {
00316
00322 class WorkbenchActionEvent : public QEvent
00323 {
00324 public:
00325 WorkbenchActionEvent(QAction* a)
00326 : QEvent(QEvent::User), act(a)
00327 { }
00328 ~WorkbenchActionEvent()
00329 { }
00330 QAction* action() const
00331 { return act; }
00332 private:
00333 QAction* act;
00334 };
00335 }
00336
00337 WorkbenchComboBox::WorkbenchComboBox(WorkbenchGroup* wb, QWidget* parent) : QComboBox(parent), group(wb)
00338 {
00339 connect(this, SIGNAL(activated(int)), this, SLOT(onActivated(int)));
00340 connect(getMainWindow(), SIGNAL(workbenchActivated(const QString&)),
00341 this, SLOT(onWorkbenchActivated(const QString&)));
00342 }
00343
00344 WorkbenchComboBox::~WorkbenchComboBox()
00345 {
00346 }
00347
00348 void WorkbenchComboBox::actionEvent ( QActionEvent* e )
00349 {
00350 QAction *action = e->action();
00351 switch (e->type()) {
00352 case QEvent::ActionAdded:
00353 {
00354 if (action->isVisible()) {
00355 QIcon icon = action->icon();
00356 if (icon.isNull())
00357 this->addItem(action->text(), action->data());
00358 else
00359 this->addItem(icon, action->text(), action->data());
00360 if (action->isChecked())
00361 this->setCurrentIndex(action->data().toInt());
00362 }
00363 break;
00364 }
00365 case QEvent::ActionChanged:
00366 {
00367 QVariant data = action->data();
00368 int index = this->findData(data);
00369
00370 if (index < 0 && action->isVisible()) {
00371 QString text = action->text();
00372 QIcon icon = action->icon();
00373 if (icon.isNull())
00374 this->addItem(action->text(), data);
00375 else
00376 this->addItem(icon, action->text(), data);
00377 }
00378
00379 else if (index >=0 && !action->isVisible()) {
00380 this->removeItem(index);
00381 }
00382 break;
00383 }
00384 case QEvent::ActionRemoved:
00385 {
00386
00387 break;
00388 }
00389 default:
00390 break;
00391 }
00392 }
00393
00394 void WorkbenchComboBox::onActivated(int i)
00395 {
00396
00397 int index = itemData(i).toInt();
00398 WorkbenchActionEvent* ev = new WorkbenchActionEvent(this->actions()[index]);
00399 QApplication::postEvent(this->group, ev);
00400 }
00401
00402 void WorkbenchComboBox::onActivated(QAction* action)
00403 {
00404
00405 QVariant data = action->data();
00406 int index = this->findData(data);
00407 setCurrentIndex(index);
00408 }
00409
00410 void WorkbenchComboBox::onWorkbenchActivated(const QString& name)
00411 {
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422 QList<QAction*> a = actions();
00423 for (QList<QAction*>::Iterator it = a.begin(); it != a.end(); ++it) {
00424 if ((*it)->objectName() == name) {
00425 if (!(*it)->isChecked())
00426 (*it)->trigger();
00427 break;
00428 }
00429 }
00430 }
00431
00432
00433 WorkbenchGroup::WorkbenchGroup ( Command* pcCmd, QObject * parent )
00434 : ActionGroup( pcCmd, parent )
00435 {
00436 for (int i=0; i<50; i++) {
00437 QAction* action = _group->addAction(QLatin1String(""));
00438 action->setVisible(false);
00439 action->setCheckable(true);
00440 action->setData(QVariant(i));
00441 }
00442
00443 Application::Instance->signalActivateWorkbench.connect(boost::bind(&WorkbenchGroup::slotActivateWorkbench, this, _1));
00444 Application::Instance->signalAddWorkbench.connect(boost::bind(&WorkbenchGroup::slotAddWorkbench, this, _1));
00445 Application::Instance->signalRemoveWorkbench.connect(boost::bind(&WorkbenchGroup::slotRemoveWorkbench, this, _1));
00446 }
00447
00448 WorkbenchGroup::~WorkbenchGroup()
00449 {
00450 }
00451
00452 void WorkbenchGroup::addTo(QWidget *w)
00453 {
00454 refreshWorkbenchList();
00455 if (w->inherits("QToolBar")) {
00456 QToolBar* bar = qobject_cast<QToolBar*>(w);
00457 QComboBox* box = new WorkbenchComboBox(this, w);
00458 box->setToolTip(_action->toolTip());
00459 box->setStatusTip(_action->statusTip());
00460 box->setWhatsThis(_action->whatsThis());
00461 box->addActions(_group->actions());
00462 connect(_group, SIGNAL(triggered(QAction*)), box, SLOT(onActivated (QAction*)));
00463 bar->addWidget(box);
00464 }
00465 else if (w->inherits("QMenu")) {
00466 QMenu* menu = qobject_cast<QMenu*>(w);
00467 menu = menu->addMenu(_action->text());
00468 menu->addActions(_group->actions());
00469 }
00470 }
00471
00472 void WorkbenchGroup::refreshWorkbenchList()
00473 {
00474 QString active = QString::fromAscii(WorkbenchManager::instance()->active()->name().c_str());
00475 QStringList items = Application::Instance->workbenches();
00476
00477 QList<QAction*> workbenches = _group->actions();
00478 int numWorkbenches = std::min<int>(workbenches.count(), items.count());
00479
00480
00481 QMap<QString, QString> menuText;
00482 for (int index = 0; index < numWorkbenches; index++) {
00483 QString text = Application::Instance->workbenchMenuText(items[index]);
00484 menuText[text] = items[index];
00485 }
00486
00487 int i=0;
00488 for (QMap<QString, QString>::Iterator it = menuText.begin(); it != menuText.end(); ++it, i++) {
00489 QPixmap px = Application::Instance->workbenchIcon(it.value());
00490 QString tip = Application::Instance->workbenchToolTip(it.value());
00491 workbenches[i]->setObjectName(it.value());
00492 workbenches[i]->setIcon(px);
00493 workbenches[i]->setText(it.key());
00494 workbenches[i]->setToolTip(tip);
00495 workbenches[i]->setStatusTip(tr("Select the '%1' workbench").arg(it.key()));
00496 workbenches[i]->setVisible(true);
00497
00498
00499
00500
00501
00502 }
00503
00504
00505 for (int index = numWorkbenches; index < workbenches.count(); index++) {
00506 workbenches[i]->setObjectName(QString());
00507 workbenches[i]->setIcon(QIcon());
00508 workbenches[i]->setText(QString());
00509 workbenches[index]->setVisible(false);
00510 }
00511 }
00512
00513 void WorkbenchGroup::customEvent( QEvent* e )
00514 {
00515 if (e->type() == QEvent::User) {
00516 Gui::WorkbenchActionEvent* ce = (Gui::WorkbenchActionEvent*)e;
00517 ce->action()->trigger();
00518 }
00519 }
00520
00521 void WorkbenchGroup::slotActivateWorkbench(const char* )
00522 {
00523 }
00524
00525 void WorkbenchGroup::slotAddWorkbench(const char* name)
00526 {
00527 QList<QAction*> workbenches = _group->actions();
00528 for (QList<QAction*>::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) {
00529 if (!(*it)->isVisible()) {
00530 QString wb = QString::fromAscii(name);
00531 QPixmap px = Application::Instance->workbenchIcon(wb);
00532 QString text = Application::Instance->workbenchMenuText(wb);
00533 QString tip = Application::Instance->workbenchToolTip(wb);
00534 (*it)->setIcon(px);
00535 (*it)->setObjectName(wb);
00536 (*it)->setText(text);
00537 (*it)->setToolTip(tip);
00538 (*it)->setStatusTip(tr("Select the '%1' workbench").arg(wb));
00539 (*it)->setVisible(true);
00540 break;
00541 }
00542 }
00543 }
00544
00545 void WorkbenchGroup::slotRemoveWorkbench(const char* name)
00546 {
00547 QString workbench = QString::fromAscii(name);
00548 QList<QAction*> workbenches = _group->actions();
00549 for (QList<QAction*>::Iterator it = workbenches.begin(); it != workbenches.end(); ++it) {
00550 if ((*it)->objectName() == workbench) {
00551 (*it)->setObjectName(QString());
00552 (*it)->setIcon(QIcon());
00553 (*it)->setText(QString());
00554 (*it)->setToolTip(QString());
00555 (*it)->setStatusTip(QString());
00556 (*it)->setVisible(false);
00557 break;
00558 }
00559 }
00560 }
00561
00562
00563
00564
00565
00566 RecentFilesAction::RecentFilesAction ( Command* pcCmd, QObject * parent )
00567 : ActionGroup( pcCmd, parent ), visibleItems(4), maximumItems(20)
00568 {
00569 restore();
00570 }
00571
00572 RecentFilesAction::~RecentFilesAction()
00573 {
00574 save();
00575 }
00576
00578 void RecentFilesAction::appendFile(const QString& filename)
00579 {
00580
00581 QStringList files = this->files();
00582
00583
00584 files.removeAll(filename);
00585 files.prepend(filename);
00586 setFiles(files);
00587 }
00588
00593 void RecentFilesAction::setFiles(const QStringList& files)
00594 {
00595 QList<QAction*> recentFiles = _group->actions();
00596
00597 int numRecentFiles = std::min<int>(recentFiles.count(), files.count());
00598 for (int index = 0; index < numRecentFiles; index++) {
00599 QFileInfo fi(files[index]);
00600 recentFiles[index]->setText(QString::fromAscii("&%1 %2").arg(index+1).arg(fi.fileName()));
00601 recentFiles[index]->setStatusTip(tr("Open file %1").arg(files[index]));
00602 recentFiles[index]->setToolTip(files[index]);
00603 recentFiles[index]->setData(QVariant(index));
00604 recentFiles[index]->setVisible(true);
00605 }
00606
00607
00608 numRecentFiles = std::min<int>(numRecentFiles, this->visibleItems);
00609 for (int index = numRecentFiles; index < recentFiles.count(); index++) {
00610 recentFiles[index]->setVisible(false);
00611 recentFiles[index]->setText(QString());
00612 recentFiles[index]->setToolTip(QString());
00613 }
00614 }
00615
00619 QStringList RecentFilesAction::files() const
00620 {
00621 QStringList files;
00622 QList<QAction*> recentFiles = _group->actions();
00623 for (int index = 0; index < recentFiles.count(); index++) {
00624 QString file = recentFiles[index]->toolTip();
00625 if (file.isEmpty())
00626 break;
00627 files.append(file);
00628 }
00629
00630 return files;
00631 }
00632
00633 void RecentFilesAction::activateFile(int id)
00634 {
00635
00636 QStringList files = this->files();
00637 if (id < 0 || id >= files.count())
00638 return;
00639
00640 QString filename = files[id];
00641 QFileInfo fi(filename);
00642 if (!fi.exists() || !fi.isFile()) {
00643 QMessageBox::critical(getMainWindow(), tr("File not found"), tr("The file '%1' cannot be opened.").arg(filename));
00644 files.removeAll(filename);
00645 setFiles(files);
00646 }
00647 else {
00648
00649 SelectModule::Dict dict = SelectModule::importHandler(filename);
00650 for (SelectModule::Dict::iterator it = dict.begin(); it != dict.end(); ++it) {
00651 Application::Instance->open(it.key().toUtf8(), it.value().toAscii());
00652 break;
00653 }
00654 }
00655 }
00656
00657 void RecentFilesAction::resizeList(int size)
00658 {
00659 this->visibleItems = size;
00660 int diff = this->visibleItems - this->maximumItems;
00661
00662 for (int i=0; i<diff; i++)
00663 _group->addAction(QLatin1String(""))->setVisible(false);
00664 setFiles(files());
00665 }
00666
00668 void RecentFilesAction::restore()
00669 {
00670 ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Preferences");
00671 if (hGrp->HasGroup("RecentFiles")) {
00672 hGrp = hGrp->GetGroup("RecentFiles");
00673
00674
00675 this->visibleItems = hGrp->GetInt("RecentFiles", this->visibleItems);
00676 }
00677
00678 int count = std::max<int>(this->maximumItems, this->visibleItems);
00679 for (int i=0; i<count; i++)
00680 _group->addAction(QLatin1String(""))->setVisible(false);
00681 std::vector<std::string> MRU = hGrp->GetASCIIs("MRU");
00682 QStringList files;
00683 for (std::vector<std::string>::iterator it = MRU.begin(); it!=MRU.end();++it)
00684 files.append(QString::fromUtf8(it->c_str()));
00685 setFiles(files);
00686 }
00687
00689 void RecentFilesAction::save()
00690 {
00691 ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
00692 ->GetGroup("Preferences")->GetGroup("RecentFiles");
00693 int count = hGrp->GetInt("RecentFiles", this->visibleItems);
00694 hGrp->Clear();
00695 hGrp->SetInt("RecentFiles", count);
00696
00697
00698 QList<QAction*> recentFiles = _group->actions();
00699 int num = std::min<int>(count, recentFiles.count());
00700 for (int index = 0; index < num; index++) {
00701 QString key = QString::fromAscii("MRU%1").arg(index);
00702 QString value = recentFiles[index]->toolTip();
00703 if (value.isEmpty())
00704 break;
00705 hGrp->SetASCII(key.toAscii(), value.toUtf8());
00706 }
00707 }
00708
00709
00710
00711 UndoAction::UndoAction (Command* pcCmd,QObject * parent)
00712 : Action(pcCmd, parent)
00713 {
00714 _toolAction = new QAction(this);
00715 _toolAction->setMenu(new UndoDialog());
00716 connect(_toolAction, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
00717 }
00718
00719 UndoAction::~UndoAction()
00720 {
00721 QMenu* menu = _toolAction->menu();
00722 delete menu;
00723 delete _toolAction;
00724 }
00725
00726 void UndoAction::addTo (QWidget * w)
00727 {
00728 if (w->inherits("QToolBar")) {
00729
00730
00731
00732 _toolAction->setText(_action->text());
00733 _toolAction->setToolTip(_action->toolTip());
00734 _toolAction->setStatusTip(_action->statusTip());
00735 _toolAction->setWhatsThis(_action->whatsThis());
00736 _toolAction->setIcon(_action->icon());
00737 w->addAction(_toolAction);
00738 }
00739 else {
00740 w->addAction(_action);
00741 }
00742 }
00743
00744 void UndoAction::setEnabled(bool b)
00745 {
00746 Action::setEnabled(b);
00747 _toolAction->setEnabled(b);
00748 }
00749
00750 void UndoAction::setVisible(bool b)
00751 {
00752 Action::setVisible(b);
00753 _toolAction->setVisible(b);
00754 }
00755
00756
00757
00758 RedoAction::RedoAction ( Command* pcCmd,QObject * parent )
00759 : Action(pcCmd, parent)
00760 {
00761 _toolAction = new QAction(this);
00762 _toolAction->setMenu(new RedoDialog());
00763 connect(_toolAction, SIGNAL(triggered(bool)), this, SLOT(onActivated()));
00764 }
00765
00766 RedoAction::~RedoAction()
00767 {
00768 QMenu* menu = _toolAction->menu();
00769 delete menu;
00770 delete _toolAction;
00771 }
00772
00773 void RedoAction::addTo ( QWidget * w )
00774 {
00775 if (w->inherits("QToolBar")) {
00776
00777
00778
00779 _toolAction->setText(_action->text());
00780 _toolAction->setToolTip(_action->toolTip());
00781 _toolAction->setStatusTip(_action->statusTip());
00782 _toolAction->setWhatsThis(_action->whatsThis());
00783 _toolAction->setIcon(_action->icon());
00784 w->addAction(_toolAction);
00785 }
00786 else {
00787 w->addAction(_action);
00788 }
00789 }
00790
00791 void RedoAction::setEnabled ( bool b )
00792 {
00793 Action::setEnabled(b);
00794 _toolAction->setEnabled(b);
00795 }
00796
00797 void RedoAction::setVisible ( bool b )
00798 {
00799 Action::setVisible(b);
00800 _toolAction->setVisible(b);
00801 }
00802
00803
00804
00805 DockWidgetAction::DockWidgetAction ( Command* pcCmd, QObject * parent )
00806 : Action(pcCmd, parent), _menu(0)
00807 {
00808 }
00809
00810 DockWidgetAction::~DockWidgetAction()
00811 {
00812 delete _menu;
00813 }
00814
00815 void DockWidgetAction::addTo ( QWidget * w )
00816 {
00817 if (!_menu) {
00818 _menu = new QMenu();
00819 _action->setMenu(_menu);
00820 connect(_menu, SIGNAL(aboutToShow()), getMainWindow(), SLOT(onDockWindowMenuAboutToShow()));
00821 }
00822
00823 w->addAction(_action);
00824 }
00825
00826
00827
00828 ToolBarAction::ToolBarAction ( Command* pcCmd, QObject * parent )
00829 : Action(pcCmd, parent), _menu(0)
00830 {
00831 }
00832
00833 ToolBarAction::~ToolBarAction()
00834 {
00835 delete _menu;
00836 }
00837
00838 void ToolBarAction::addTo ( QWidget * w )
00839 {
00840 if (!_menu) {
00841 _menu = new QMenu();
00842 _action->setMenu(_menu);
00843 connect(_menu, SIGNAL(aboutToShow()), getMainWindow(), SLOT(onToolBarMenuAboutToShow()));
00844 }
00845
00846 w->addAction(_action);
00847 }
00848
00849
00850
00851 WindowAction::WindowAction ( Command* pcCmd, QObject * parent )
00852 : ActionGroup(pcCmd, parent), _menu(0)
00853 {
00854 }
00855
00856 WindowAction::~WindowAction()
00857 {
00858 }
00859
00860 void WindowAction::addTo ( QWidget * w )
00861 {
00862 QMenu* menu = qobject_cast<QMenu*>(w);
00863 if (!menu) {
00864 if (!_menu) {
00865 _menu = new QMenu();
00866 _action->setMenu(_menu);
00867 _menu->addActions(_group->actions());
00868 connect(_menu, SIGNAL(aboutToShow()),
00869 getMainWindow(), SLOT(onWindowsMenuAboutToShow()));
00870 }
00871
00872 w->addAction(_action);
00873 }
00874 else {
00875 menu->addActions(_group->actions());
00876 connect(menu, SIGNAL(aboutToShow()),
00877 getMainWindow(), SLOT(onWindowsMenuAboutToShow()));
00878 }
00879 }
00880
00881 #include "moc_Action.cpp"