Overview
This example shows how to create and modify a toolbar from both new and existing menu items and GUI elements.
Expected Result
Toolbar Result
Example details
The code fragments are from exampleToolbarPluginInit.cxx code.
- Register the menu that is to be used in the plugin. While the order is not strictly important, it represents how the elements are created in the system (menus first, then toolbars):
DtQtMenuAssembler::instance(de).registerMenu(new DtExampleToolbarMenu(de));
DtQtMenuAssembler::instance(de).registerMenu(new DtExampleToolbarMenuItem(de));
- Register the toolbars that are going to be created with the DtQtToolbarAssembler registerToolbar method:
DtQtToolbarAssembler::instance(de).registerToolbar(new DtExampleToolbar(de));
- The toolbar assembler interface allows you to add menu items, menus, separators and GUI elements (widgets) to the toolbar. To add a menu item and separator:
igApp->masterModeToolbarConfiguration().addToolbarPath(
DtToolbarPath::toolbar("DtExampleToolbar").item("DtWireframeItem"));
igApp->masterModeToolbarConfiguration().addToolbarPath(
DtToolbarPath::toolbar("DtExampleToolbar").item("DtShadowsItem"));
igApp->masterModeToolbarConfiguration().addToolbarPath(
DtToolbarPath::toolbar("DtExampleToolbar").separator("DtSeparator_1"));
igApp->masterModeToolbarConfiguration().addToolbarPath(
DtToolbarPath::toolbar("DtExampleToolbar").item("DtExampleToolbarMenuItem"));
- To add a menu:
igApp->masterModeToolbarConfiguration().addToolbarPath(
- You can also create menus that only appear as part of the toolbar and not on the main menu. To do this, the menus and menu items must be registered with the DtQtMenuAssembler class. However, the menu path definitions are registered with the toolbar configuration:
- And reference this new menu the same way as one created in the menu system:
- To add a widget, the widget creator, a subclass of DtWidgetBuilder, must be register with the DtQtToolbarAssember registerWidgetBuilder method. It can then be referenced by the widget call on the toolbar path:
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin64/exampleToolbar_stealth.bat (on Windows) or ./bin64/exampleToolbar_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Example Source Files
exampleToolbarPluginInit.cxx
{
return true;
}
{
namespace vrvExampleToolbarPlugin
{
{
try
{
if(igApp)
{
new DtToolbarExampleCombo);
}
}
DtCATCH_AND_PROPAGATE(DtCorruptedState)
}
}
}
Contains makVrv::DtDe class.
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtVrvApplication implementation.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
The Root IG Application object. To run the IG simply create one, initialize it and call run.
Definition DtVrvApplication.h:58
DtMenuConfiguration & masterModeMenuConfiguration()
Get the menu configuration which may be altered by plugins.
static DtVrvApplication * findFromDe(DtDe &)
DtToolbarConfiguration & masterModeToolbarConfiguration()
Get the toolbar configuration which may be altered by plugins.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
DT_DLL_VRVCOREQT void init(DtDe &de)
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
exampleToolbarMenu.h
#pragma once
{
class DtDe;
namespace vrvExampleToolbarPlugin
{
{
public:
DtExampleToolbar(DtDe&);
virtual ~DtExampleToolbar();
};
{
public:
DtExampleToolbarMenu(DtDe& de);
virtual ~DtExampleToolbarMenu();
};
{
public:
DtExampleSceneToolbarMenu(DtDe& de);
virtual ~DtExampleSceneToolbarMenu();
};
{
public:
virtual ~DtExampleToolbarMenuItem();
virtual void on_triggered();
};
{
public:
DtToolbarExampleCombo();
virtual ~DtToolbarExampleCombo();
virtual QWidget* create( makVrv::DtDe& de, QWidget* parent, const Qt::WindowFlags& flags);
};
}
}
exampleToolbarMenu.cxx
#include <QtWidgets/QToolBar>
#include <QtWidgets/QAction>
#include <QtWidgets/QMessageBox>
#include <QtWidgets/QMenu>
#include <QtWidgets/QComboBox>
{
namespace vrvExampleToolbarPlugin
{
: DtToolbar(de, "DtExampleToolbar")
{
}
DtExampleToolbar::~DtExampleToolbar()
{
}
{
bar->setWindowTitle(QObject::tr("Example Toolbar"));
bar->setObjectName(QObject::tr("Example Toolbar"));
return bar;
}
DtExampleToolbarMenu::DtExampleToolbarMenu(DtDe& de)
: DtMenu(de, std::string("DtExampleToolbarMenu"))
{
}
DtExampleToolbarMenu::~DtExampleToolbarMenu()
{
}
QMenu* DtExampleToolbarMenu::createMenu( DtDe&,
QWidget* parent )
{
QMenu* menu =
new QMenu(QMenu::tr(
"&Toolbars Example"),parent);
return menu;
}
DtExampleSceneToolbarMenu::DtExampleSceneToolbarMenu(DtDe& de)
: DtMenu(de, std::string("DtExampleSceneToolbarMenu"))
{
}
DtExampleSceneToolbarMenu::~DtExampleSceneToolbarMenu()
{
}
QMenu* DtExampleSceneToolbarMenu::createMenu( DtDe&,
QWidget* parent )
{
QMenu* menu =
new QMenu(QMenu::tr(
"&Scene Toolbars Example"),parent);
DtWidgetIconStyleManager::instance(myDe).manageWidget(menu, "TerrainScene.svg");
return menu;
}
DtExampleToolbarMenuItem::DtExampleToolbarMenuItem(DtDe& de)
: DtMenuItem(std::string("DtExampleToolbarMenuItem"))
{
}
DtExampleToolbarMenuItem::~DtExampleToolbarMenuItem()
{
}
QAction* DtExampleToolbarMenuItem::createAction( DtDe&,
QWidget* parent )
{
act->setText(DtMenuItem::tr("&Example Toolbar Item..."));
return act;
}
void DtExampleToolbarMenuItem::on_triggered()
{
if(action)
{
parent = action->parentWidget();
}
QMessageBox::information(parent, "Toolbar Example", "This dialog was triggered from the toolbar example menu item");
}
DtToolbarExampleCombo::DtToolbarExampleCombo()
: DtWidgetBuilder()
{
}
DtToolbarExampleCombo::~DtToolbarExampleCombo()
{
}
{
combo->addItem("Item 1");
combo->addItem("Item 2");
combo->addItem("Item 3");
return combo;
}
}
}
Contains makVrv::DtDeConfiguration class.