//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RiuPlotMainWindow::createToolBars() { caf::CmdFeatureManager* cmdFeatureMgr = caf::CmdFeatureManager::instance(); CVF_ASSERT(cmdFeatureMgr); QStringList toolbarNames; toolbarNames << "Standard" << "Window Management" << "View Snapshots" << "View"; for (QString toolbarName : toolbarNames) { QToolBar* toolbar = addToolBar(toolbarName); toolbar->setObjectName(toolbar->windowTitle()); QStringList toolbarCommands = toolbarCommandIds(toolbarName); for (QString s : toolbarCommands) { toolbar->addAction(cmdFeatureMgr->action(s)); } } m_wellLogPlotToolBarEditor = new caf::PdmUiToolBarEditor("Well Log Plot", this); m_wellLogPlotToolBarEditor->hide(); m_summaryPlotToolBarEditor = new caf::PdmUiToolBarEditor("Summary Plot", this); m_summaryPlotToolBarEditor->hide(); }
ToolbarDialog::ToolbarDialog(QWidget* parent) : QDialog(parent),m_defaultToolBars() { setupUi(this); createDefaultToolBars(); // populate all available actions QList<QAction*> actions = parent->findChildren<QAction*>(QRegExp("action*")); QAction* action; foreach(action, actions) { if (action->actionGroup()->objectName() != "extraGroup") continue; QListWidgetItem* item = new QListWidgetItem(action->toolTip()); item->setIcon(action->icon()); item->setData(Qt::UserRole, QVariant::fromValue((QObject*)action)); listAllActions->addItem(item); } // Important to add special Separator listAllActions->addItem("Separator"); QList<QToolBar*> toolbars = parent->findChildren<QToolBar*>(); QToolBar* toolbar = NULL; int index = 0; foreach(toolbar, toolbars) { index = (int)(toolbar->iconSize().height()/10)-1; if (toolbar->objectName() != "keyToolBar") comboToolbars->addItem(toolbar->windowTitle(), QVariant::fromValue((QObject*)toolbar)); }
void ToolBoxManager::setup( ToolBarItem* toolBar ) const { if ( !toolBar || !_toolBox ) return; // empty tool bar int ct = _toolBox->count(); for ( int i=0; i<ct; i++ ) { // get always the first item widget QWidget* w = _toolBox->widget(0); _toolBox->removeItem(0); delete w; } CommandManager& mgr = Application::Instance->commandManager(); QList<ToolBarItem*> items = toolBar->getItems(); for ( QList<ToolBarItem*>::ConstIterator item = items.begin(); item != items.end(); ++item ) { QToolBar* bar = new QToolBar(); bar->setOrientation(Qt::Vertical); bar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); std::string toolbarName = (*item)->command(); bar->setObjectName(QString::fromLatin1((*item)->command().c_str())); bar->setWindowTitle(QObject::trUtf8(toolbarName.c_str())); // i18n _toolBox->addItem( bar, bar->windowTitle() ); QList<ToolBarItem*> subitems = (*item)->getItems(); for ( QList<ToolBarItem*>::ConstIterator subitem = subitems.begin(); subitem != subitems.end(); ++subitem ) { if ( (*subitem)->command() == "Separator" ) { //bar->addSeparator(); } else { mgr.addTo((*subitem)->command().c_str(), bar); } } // Now set the right size policy for each tool button QList<QToolButton*> tool = bar->findChildren<QToolButton*>(); for (QList<QToolButton*>::Iterator it = tool.begin(); it != tool.end(); ++it) { (*it)->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); // When setting the horizontal size policy but no icon is set we use the following trick // to make the button text left aligned. QIcon icon = (*it)->icon(); if (icon.isNull()) { // Create an icon filled with the button color int size = QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize); QPixmap p(size, size); p.fill(Qt::transparent); (*it)->setIcon(p); } } } }