int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mainWin; mainWin.setWindowTitle(QObject::tr("Qt SQL Browser")); Browser browser(&mainWin); mainWin.setCentralWidget(&browser); QMenu *fileMenu = mainWin.menuBar()->addMenu(QObject::tr("&File")); fileMenu->addAction(QObject::tr("Add &Connection..."), &browser, SLOT(addConnection())); fileMenu->addSeparator(); fileMenu->addAction(QObject::tr("&Quit"), &app, SLOT(quit())); QMenu *helpMenu = mainWin.menuBar()->addMenu(QObject::tr("&Help")); helpMenu->addAction(QObject::tr("About"), &browser, SLOT(about())); helpMenu->addAction(QObject::tr("About Qt"), qApp, SLOT(aboutQt())); QObject::connect(&browser, SIGNAL(statusMessage(QString)), mainWin.statusBar(), SLOT(showMessage(QString))); addConnectionsFromCommandline(app.arguments(), &browser); mainWin.show(); if (QSqlDatabase::connectionNames().isEmpty()) QMetaObject::invokeMethod(&browser, "addConnection", Qt::QueuedConnection); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mw; #ifndef Q_WS_MAC app.setWindowIcon(QIcon(QLatin1String(":/trolltech/qdbusviewer/images/qdbusviewer.png"))); #else mw.setWindowTitle(qApp->translate("QtDBusViewer", "Qt D-Bus Viewer")); #endif QTabWidget *mainWidget = new QTabWidget; mw.setCentralWidget(mainWidget); QDBusViewer *sessionBusViewer = new QDBusViewer(QDBusConnection::sessionBus()); QDBusViewer *systemBusViewer = new QDBusViewer(QDBusConnection::systemBus()); mainWidget->addTab(sessionBusViewer, QObject::tr("Session Bus")); mainWidget->addTab(systemBusViewer, QObject::tr("System Bus")); QMenu *fileMenu = mw.menuBar()->addMenu(QObject::tr("&File")); QAction *quitAction = fileMenu->addAction(QObject::tr("&Quit"), &mw, SLOT(close())); Q_UNUSED(quitAction); QMenu *helpMenu = mw.menuBar()->addMenu(QObject::tr("&Help")); QAction *aboutAction = helpMenu->addAction(QObject::tr("&About")); aboutAction->setMenuRole(QAction::AboutRole); QObject::connect(aboutAction, SIGNAL(triggered()), sessionBusViewer, SLOT(about())); QAction *aboutQtAction = helpMenu->addAction(QObject::tr("About &Qt")); aboutQtAction->setMenuRole(QAction::AboutQtRole); QObject::connect(aboutQtAction, SIGNAL(triggered()), &app, SLOT(aboutQt())); mw.show(); return app.exec(); }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> void Application::setMainWidget(QWidget* w) { _mainWidget = w; QMainWindow *mw = dynamic_cast<QMainWindow*>(w); if ( mw ) { QMenu *helpMenu = mw->menuBar()->findChild<QMenu*>("menuHelp"); if ( helpMenu == NULL ) { helpMenu = new QMenu(mw->menuBar()); helpMenu->setObjectName("menuHelp"); helpMenu->setTitle("&Help"); mw->menuBar()->addAction(helpMenu->menuAction()); } QAction *a = helpMenu->addAction("&About SeisComP3"); connect(a, SIGNAL(triggered()), this, SLOT(showAbout())); a = helpMenu->addAction("&Documenation index"); a->setShortcut(QKeySequence("F1")); connect(a, SIGNAL(triggered()), this, SLOT(showHelpIndex())); a = helpMenu->addAction(QString("Documentation for %1").arg(name().c_str())); a->setShortcut(QKeySequence("Shift+F1")); connect(a, SIGNAL(triggered()), this, SLOT(showAppHelp())); a = helpMenu->addAction("&Loaded Plugins"); connect(a, SIGNAL(triggered()), this, SLOT(showPlugins())); } if ( _splash ) _splash->finish(w); }
int main(int argc, char ** argv) { QApplication app( argc, argv ); //MainWindowImpl win; QMainWindow *win = new QMainWindow(0, Qt::Window); PageTemplate tmplt;// = new PageTemplate; book b;// = new book(); tmplt.setBook(&b); QMenu fileMenu("File"); QAction *openBookAction = new QAction(("Open book"), win); QAction *openLibraryAction = new QAction(("Library"), win); fileMenu.addAction(openBookAction); fileMenu.addAction(openLibraryAction); // fileMenu.addAction("Open book", ) fileMenu.addSeparator(); fileMenu.addAction("Quit"); win->connect(openBookAction, SIGNAL(triggered()), &tmplt, SLOT(openBookSlot())); win->connect(openLibraryAction, SIGNAL(triggered()), &tmplt, SLOT(openLibrarySlot())); QMenu prefMenu("Settings"); // prefMenu.addAction("Fonts +"); // prefMenu.addAction("Fonts -"); // prefMenu.addAction("Linespacing +"); // prefMenu.addAction("Linespacing -"); // prefMenu.addSeparator(); // prefMenu.addAction("Settings"); QAction *openSettingsAction = new QAction(("Settings"), win); prefMenu.addAction(openSettingsAction); win->connect(openSettingsAction, SIGNAL(triggered()), &tmplt, SLOT(openSettingsWindow())); QMenu contentsMenu("Contents"); win->menuBar()->addMenu(&fileMenu); win->menuBar()->addMenu(&prefMenu); win->menuBar()->addMenu(&contentsMenu); // win->menuBar()-> addMenu("File")->addSeparator(); // win->menuBar()->addMenu("Settings")->addAction("Preferences"); win->setCentralWidget(&tmplt); tmplt.menuBar = win->menuBar(); tmplt.contentsMenu = &contentsMenu; win->resize(640, 480); //b->loadFB2(); win->show(); app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) ); return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow mw; #ifndef Q_OS_MAC app.setWindowIcon(QIcon(QLatin1String(":/qt-project.org/qdbusviewer/images/qdbusviewer.png"))); #else mw.setWindowTitle(qApp->translate("QtDBusViewer", "Qt D-Bus Viewer")); #endif QTabWidget *mainWidget = new QTabWidget; mw.setCentralWidget(mainWidget); QDBusViewer *sessionBusViewer = new QDBusViewer(QDBusConnection::sessionBus()); QDBusViewer *systemBusViewer = new QDBusViewer(QDBusConnection::systemBus()); mainWidget->addTab(sessionBusViewer, QObject::tr("Session Bus")); mainWidget->addTab(systemBusViewer, QObject::tr("System Bus")); QStringList args = app.arguments(); while (args.count()) { QString arg = args.takeFirst(); if (arg == QLatin1String("--bus")) { QDBusConnection connection = QDBusConnection::connectToBus(args.takeFirst(), "QDBusViewer"); if (connection.isConnected()) { QDBusViewer *customBusViewer = new QDBusViewer(connection); mainWidget->addTab(customBusViewer, QObject::tr("Custom Bus")); } } } QMenu *fileMenu = mw.menuBar()->addMenu(QObject::tr("&File")); QAction *quitAction = fileMenu->addAction(QObject::tr("&Quit"), &mw, SLOT(close())); quitAction->setShortcut(QKeySequence::Quit); quitAction->setMenuRole(QAction::QuitRole); QMenu *helpMenu = mw.menuBar()->addMenu(QObject::tr("&Help")); QAction *aboutAction = helpMenu->addAction(QObject::tr("&About")); aboutAction->setMenuRole(QAction::AboutRole); QObject::connect(aboutAction, SIGNAL(triggered()), sessionBusViewer, SLOT(about())); QAction *aboutQtAction = helpMenu->addAction(QObject::tr("About &Qt")); aboutQtAction->setMenuRole(QAction::AboutQtRole); QObject::connect(aboutQtAction, SIGNAL(triggered()), &app, SLOT(aboutQt())); mw.show(); return app.exec(); }
void tst_QMenu::task208001_stylesheet() { //test if it crash QMainWindow main; main.setStyleSheet("QMenu [title =\"File\"] { color: red;}"); main.menuBar()->addMenu("File"); }
QMenuBar* QMainWindowProto::menuBar () const { QMainWindow *item = qscriptvalue_cast<QMainWindow*>(thisObject()); if (item) return item->menuBar(); return 0; }
int main(int argc, char **argv) { QApplication app(argc, argv); Window *d3dw = new Window; QMainWindow mw; QWidget *w = new QWidget; QVBoxLayout *vl = new QVBoxLayout; vl->addWidget(new QPushButton("Widgets + a native child window with D3D12")); vl->addWidget(new QLabel("Offscreen rendering to a render target that is then used as a texture.\nNow with bundles!")); QWidget *ww = QWidget::createWindowContainer(d3dw); ww->setMinimumHeight(300); vl->addWidget(ww); vl->setStretchFactor(ww, 1.0); w->setLayout(vl); QMenu *fileMenu = mw.menuBar()->addMenu("&File"); fileMenu->addAction("&Save image", d3dw, &Window::readbackAndSave); fileMenu->addAction("E&xit", &app, &QApplication::quit); mw.setCentralWidget(w); mw.resize(400, 400); mw.show(); return app.exec(); }
void QmitkWorkbenchWindowAdvisor::PostWindowCreate() { // very bad hack... berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow(); QMainWindow* mainWindow = static_cast<QMainWindow*>(window->GetShell()->GetControl()); QMenuBar* menuBar = mainWindow->menuBar(); QMenu* fileMenu = menuBar->addMenu("&File"); fileMenu->addAction(new QmitkFileOpenAction(window)); fileMenu->addSeparator(); fileMenu->addAction(new QmitkFileExitAction(window)); berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); const std::vector<berry::IViewDescriptor::Pointer>& viewDescriptors = viewRegistry->GetViews(); QMenu* viewMenu = menuBar->addMenu("Show &View"); // sort elements (converting vector to map...) std::vector<berry::IViewDescriptor::Pointer>::const_iterator iter; std::map<std::string, berry::IViewDescriptor::Pointer> VDMap; for (iter = viewDescriptors.begin(); iter != viewDescriptors.end(); ++iter) { if ((*iter)->GetId() == "org.blueberry.ui.internal.introview") continue; std::pair<std::string, berry::IViewDescriptor::Pointer> p((*iter)->GetLabel(), (*iter)); VDMap.insert(p); } QToolBar* qToolbar = new QToolBar; std::map<std::string, berry::IViewDescriptor::Pointer>::const_iterator MapIter; for (MapIter = VDMap.begin(); MapIter != VDMap.end(); ++MapIter) { berry::QtShowViewAction* viewAction = new berry::QtShowViewAction(window, (*MapIter).second); //m_ViewActions.push_back(viewAction); viewMenu->addAction(viewAction); qToolbar->addAction(viewAction); } mainWindow->addToolBar(qToolbar); QStatusBar* qStatusBar = new QStatusBar(); //creating a QmitkStatusBar for Output on the QStatusBar and connecting it with the MainStatusBar QmitkStatusBar *statusBar = new QmitkStatusBar(qStatusBar); //disabling the SizeGrip in the lower right corner statusBar->SetSizeGripEnabled(false); QmitkProgressBar *progBar = new QmitkProgressBar(); qStatusBar->addPermanentWidget(progBar, 0); progBar->hide(); mainWindow->setStatusBar(qStatusBar); QmitkMemoryUsageIndicatorView* memoryIndicator = new QmitkMemoryUsageIndicatorView(); qStatusBar->addPermanentWidget(memoryIndicator, 0); }
void QgsRasterTerrainAnalysisPlugin::initGui() { //create Action if ( mIface ) { //find raster menu QString rasterText = QCoreApplication::translate( "QgisApp", "&Raster" ); QMainWindow* mainWindow = qobject_cast<QMainWindow*>( mIface->mainWindow() ); if ( !mainWindow ) { return; } QMenuBar* menuBar = mainWindow->menuBar(); if ( !menuBar ) { return; } QMenu* rasterMenu = 0; QList<QAction *> menuBarActions = menuBar->actions(); QList<QAction *>::iterator menuActionIt = menuBarActions.begin(); for ( ; menuActionIt != menuBarActions.end(); ++menuActionIt ) { if (( *menuActionIt )->menu() && ( *menuActionIt )->menu()->title() == rasterText ) { rasterMenu = ( *menuActionIt )->menu(); rasterMenu->addSeparator(); break; } } if ( !rasterMenu ) { return; } mTerrainAnalysisMenu = new QMenu( tr( "Terrain analysis" ), rasterMenu ); mTerrainAnalysisMenu->setObjectName( "mTerrainAnalysisMenu" ); mTerrainAnalysisMenu->setIcon( QIcon( ":/raster/dem.png" ) ); QAction *slopeAction = mTerrainAnalysisMenu->addAction( tr( "Slope" ), this, SLOT( slope() ) ); slopeAction->setObjectName( "slopeAction" ); QAction *aspectAction = mTerrainAnalysisMenu->addAction( tr( "Aspect" ), this, SLOT( aspect() ) ); aspectAction->setObjectName( "aspectAction" ); QAction *hilshadeAction = mTerrainAnalysisMenu->addAction( tr( "Hillshade" ), this, SLOT( hillshade() ) ); hilshadeAction->setObjectName( "hilshadeAction" ); QAction *reliefAction = mTerrainAnalysisMenu->addAction( tr( "Relief" ), this, SLOT( relief() ) ); reliefAction->setObjectName( "reliefAction" ); QAction *ruggednesIndex = mTerrainAnalysisMenu->addAction( tr( "Ruggedness index" ), this, SLOT( ruggedness() ) ); ruggednesIndex->setObjectName( "ruggednesIndex" ); rasterMenu->addMenu( mTerrainAnalysisMenu ); } }
int main(int argc, char **argv) { QApplication app(argc, argv); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); GraphWidget *widget = new GraphWidget; QMainWindow mainWindow; mainWindow.setCentralWidget(widget); #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) mainWindow.menuBar()->addAction("Shuffle", widget, SLOT(shuffle())); mainWindow.menuBar()->addAction("Zoom In", widget, SLOT(zoomIn())); mainWindow.menuBar()->addAction("Zoom Out", widget, SLOT(zoomOut())); mainWindow.showMaximized(); #else mainWindow.show(); #endif return app.exec(); }
int emscriptenQtSDLMain(int argc, char *argv[]) #endif { QApplication *app = new QApplication(argc, argv); qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); GraphWidget *widget = new GraphWidget; QMainWindow *mainWindow = new QMainWindow; mainWindow->setCentralWidget(widget); #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) mainWindow->menuBar()->addAction("Shuffle", widget, SLOT(shuffle())); mainWindow->menuBar()->addAction("Zoom In", widget, SLOT(zoomIn())); mainWindow->menuBar()->addAction("Zoom Out", widget, SLOT(zoomOut())); mainWindow->showMaximized(); #else mainWindow->show(); #endif return app->exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QMainWindow win; win.setWindowTitle("Glypha III"); QWidget *mainWidget = new QWidget; GLWidget *glwid = new GLWidget; glwid->setFixedSize(640, 460); QHBoxLayout *layout = new QHBoxLayout; layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(glwid); mainWidget->setLayout(layout); win.setCentralWidget(mainWidget); QMenu *fileMenu = new QMenu("&File"); QAction *newGameMenu = fileMenu->addAction("&New Game"); QObject::connect(newGameMenu, SIGNAL(triggered()), glwid, SLOT(newGame())); newGameMenu->setShortcut(QKeySequence("Ctrl+N")); QAction *endGameMenu = fileMenu->addAction("&End Game\tCtrl+E"); QObject::connect(endGameMenu, SIGNAL(triggered()), glwid, SLOT(endGame())); endGameMenu->setShortcut(QKeySequence("Ctrl+E")); fileMenu->addSeparator(); QAction *quitMenu = fileMenu->addAction("&Quit"); QObject::connect(quitMenu, SIGNAL(triggered()), qApp, SLOT(quit())); quitMenu->setShortcut(QKeySequence("Ctrl+Q")); win.menuBar()->addMenu(fileMenu); QMenu *helpMenu = new QMenu("&Help"); QAction *helpAction = helpMenu->addAction("&Help"); QObject::connect(helpAction, SIGNAL(triggered()), glwid, SLOT(showHelp())); helpAction->setShortcut(QKeySequence("Ctrl+H")); win.menuBar()->addMenu(helpMenu); win.show(); return app.exec(); }
void tst_QMenu::layoutDirection() { QMainWindow win; win.setLayoutDirection(Qt::RightToLeft); QMenu menu(&win); menu.show(); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); menu.close(); menu.setParent(0); menu.show(); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QCOMPARE(menu.layoutDirection(), QApplication::layoutDirection()); menu.close(); //now the menubar QAction *action = win.menuBar()->addMenu(&menu); win.menuBar()->setActiveAction(action); QVERIFY(QTest::qWaitForWindowExposed(&menu)); QCOMPARE(menu.layoutDirection(), Qt::RightToLeft); }
void tst_QMenu::overrideMenuAction() { //test the override menu action by first creating an action to which we set its menu QMainWindow w; QAction *aFileMenu = new QAction("&File", &w); w.menuBar()->addAction(aFileMenu); QMenu *m = new QMenu(&w); QAction *menuaction = m->menuAction(); connect(m, SIGNAL(triggered(QAction*)), SLOT(onActivated(QAction*))); aFileMenu->setMenu(m); //this sets the override menu action for the QMenu QCOMPARE(m->menuAction(), aFileMenu); #ifdef Q_WS_MAC QSKIP("On Mac, we need to create native key events to test menu action activation", SkipAll); #elif defined(Q_OS_WINCE) QSKIP("On Windows CE, we need to create native key events to test menu action activation", SkipAll); #elif defined(Q_OS_SYMBIAN) QSKIP("On Symbian OS, we need to create native key events to test menu action activation", SkipAll); #endif QAction *aQuit = new QAction("Quit", &w); aQuit->setShortcut(QKeySequence("Ctrl+X")); m->addAction(aQuit); w.show(); QApplication::setActiveWindow(&w); w.setFocus(); QTest::qWaitForWindowShown(&w); QTRY_VERIFY(w.hasFocus()); //test of the action inside the menu QTest::keyClick(&w, Qt::Key_X, Qt::ControlModifier); QTRY_COMPARE(activated, aQuit); //test if the menu still pops out QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier); QTRY_VERIFY(m->isVisible()); delete aFileMenu; //after the deletion of the override menu action, //the menu should have its default menu action back QCOMPARE(m->menuAction(), menuaction); }
OpenGLQtMenu::OpenGLQtMenu() : shadersItem_(nullptr), shaderMapper_(nullptr) { InviwoApplicationQt* qtApp = dynamic_cast<InviwoApplicationQt*>(InviwoApplication::getPtr()); if (qtApp) { QMainWindow* win = qtApp->getMainWindow(); if (win) { InviwoApplication::getPtr()->getProcessorNetwork()->addObserver(this); shadersItem_ = win->menuBar()->addMenu(tr("&Shaders")); shaderMapper_ = new QSignalMapper(this); connect(shaderMapper_, SIGNAL(mapped(QObject*)), this, SLOT(shaderMenuCallback(QObject*))); QAction* reloadShaders = shadersItem_->addAction("Reload All"); connect(reloadShaders, SIGNAL(triggered()), this, SLOT(shadersReload())); } } }
int Dialog::showDialog(const QString& view, QObject* viewModel, int type) { QDialog* dialog = NULL; QMainWindow* mainWindow = NULL; QWidget* windowWidget = NULL; QWidget* layoutWidget = NULL; switch (type) { case Dialog::MainWindow: mainWindow = new QMainWindow(); windowWidget = mainWindow; layoutWidget = new QWidget(windowWidget); mainWindow->setCentralWidget(layoutWidget); break; case Dialog::ModalDialog: dialog = new QDialog(QApplication::activeWindow()); windowWidget = dialog; layoutWidget = dialog; break; default: dialog = new QDialog(); windowWidget = dialog; layoutWidget = dialog; break; } QGridLayout* layout = new QGridLayout(layoutWidget); // Create view QDeclarativeView* v = new QDeclarativeView(layoutWidget); if (viewModel) { int count = viewModel->metaObject()->propertyCount(); for (int i = 0; i < count; ++i) { QMetaProperty p = viewModel->metaObject()->property(i); if (p.isReadable() && p.typeName() == QString("QDeclarativeImageProvider*")) { QString name = p.name(); QDeclarativeImageProvider* value = p.read(viewModel).value<QDeclarativeImageProvider*>(); v->engine()->addImageProvider(name.toLatin1(), new ProxyImageProvider(value)); } } v->rootContext()->setContextProperty("dataContext", viewModel); } QString path; foreach (path, importPaths) v->engine()->addImportPath(path); foreach (path, pluginPaths) v->engine()->addPluginPath(path); v->setSource(QUrl(view)); v->setResizeMode(QDeclarativeView::SizeRootObjectToView); // Initialize dialog QGraphicsObject* root = v->rootObject(); QVariant property = root->property("dialogTitle"); if (property.isValid()) windowWidget->setWindowTitle(property.toString()); property = root->property("dialogMinWidth"); if (property.isValid()) layoutWidget->setMinimumWidth(property.toInt()); property = root->property("dialogMinHeight"); if (property.isValid()) layoutWidget->setMinimumHeight(property.toInt()); property = root->property("dialogMaxWidth"); if (property.isValid()) layoutWidget->setMaximumWidth(property.toInt()); property = root->property("dialogMaxHeight"); if (property.isValid()) layoutWidget->setMaximumHeight(property.toInt()); property = root->property("dialogResizable"); if (property.isValid() && !property.toBool()) layout->setSizeConstraint(QLayout::SetFixedSize); Qt::WindowStates states = windowWidget->windowState(); Qt::WindowFlags flags = windowWidget->windowFlags(); property = root->property("dialogMinimizeButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowMinimizeButtonHint : flags & ~Qt::WindowMinimizeButtonHint; property = root->property("dialogMaximizeButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowMaximizeButtonHint : flags & ~Qt::WindowMaximizeButtonHint; property = root->property("dialogCloseButton"); if (property.isValid()) flags = property.toBool() ? flags | Qt::WindowCloseButtonHint : flags & ~Qt::WindowCloseButtonHint; property = root->property("dialogFullScreen"); if (property.isValid()) states = property.toBool() ? states | Qt::WindowFullScreen : states & ~Qt::WindowFullScreen; flags = flags & ~Qt::WindowContextHelpButtonHint; windowWidget->setWindowFlags(flags); windowWidget->setWindowState(states); property = root->property("dialogToolBar"); if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>")) { QToolBar* toolbar = new QToolBar(mainWindow); toolbar->setMovable(false); toolbar->setFloatable(false); toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); toolbar->setAllowedAreas(Qt::TopToolBarArea); QDeclarativeListProperty<QDeclarativeItem> btnList = property.value< QDeclarativeListProperty<QDeclarativeItem> >(); int btnCount = btnList.count(&btnList); for (int i = 0; i < btnCount; ++i) { QDeclarativeItem* item = btnList.at(&btnList, i); if (!item->property("text").isValid()) continue; QString itemText = item->property("text").toString(); QString itemTooltip = item->property("tooltip").isValid() ? item->property("tooltip").toString() : ""; QString itemIconSource = item->property("iconSource").isValid() ? item->property("iconSource").toString() : ""; int itemIconSize = item->property("iconSize").isValid() ? item->property("iconSize").toInt() : -1; if (itemText == "|") { toolbar->addSeparator(); } else if (itemText == "-") { QWidget* spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); toolbar->addWidget(spacer); } else { QAction* action = new QAction(mainWindow); action->setText(itemText); action->setToolTip(itemTooltip); action->setIcon(QIcon(itemIconSource)); QObject::connect(action, SIGNAL(triggered()), item, SLOT(trigger())); if (item->property("enabled").isValid()) new PropertyBinding(action, "enabled", item, "enabled", PropertyBinding::OneWay, NULL, this); if (item->property("visible").isValid()) new PropertyBinding(action, "visible", item, "visible", PropertyBinding::OneWay, NULL, this); toolbar->addAction(action); } if (itemIconSize != -1) toolbar->setIconSize(QSize(itemIconSize, itemIconSize)); } mainWindow->setUnifiedTitleAndToolBarOnMac(true); mainWindow->addToolBar(toolbar); } property = root->property("dialogMenu"); if (type == Dialog::MainWindow && property.isValid() && property.typeName() == QString("QDeclarativeListProperty<QDeclarativeItem>")) { QDeclarativeListProperty<QDeclarativeItem> list = property.value< QDeclarativeListProperty<QDeclarativeItem> >(); int count = list.count(&list); for (int i = 0; i < count; ++i) { QDeclarativeItem* item = list.at(&list, i); if (!item->property("text").isValid()) continue; QString itemText = item->property("text").toString(); QMenu * menuItem = mainWindow->menuBar()->addMenu(itemText); if (!item->property("submenu").isValid() || item->property("submenu").typeName() != QString("QDeclarativeListProperty<QDeclarativeItem>")) continue; QDeclarativeListProperty<QDeclarativeItem> innerList = item->property("submenu").value< QDeclarativeListProperty<QDeclarativeItem> >(); int innerCount = innerList.count(&innerList); for (int j = 0; j < innerCount; ++j) { QDeclarativeItem* innerItem = innerList.at(&innerList, j); if (!innerItem->property("text").isValid()) continue; QString innerItemText = innerItem->property("text").toString(); QString innerItemShortcut = innerItem->property("shortcut").isValid() ? innerItem->property("shortcut").toString() : ""; QString innerItemIconSource = innerItem->property("iconSource").isValid() ? innerItem->property("iconSource").toString() : ""; if (innerItemText == "-") { menuItem->addSeparator(); } else { QAction * action = menuItem->addAction(QIcon(innerItemIconSource), innerItemText); action->setShortcut(QKeySequence(innerItemShortcut)); QObject::connect(action, SIGNAL(triggered()), innerItem, SLOT(trigger())); if (innerItem->property("enabled").isValid()) new PropertyBinding(action, "enabled", innerItem, "enabled", PropertyBinding::OneWay, NULL, this); if (innerItem->property("visible").isValid()) new PropertyBinding(action, "visible", innerItem, "visible", PropertyBinding::OneWay, NULL, this); } } } } new DialogCallbacks(windowWidget, v, root); // Initialize layout layout->setMargin(0); layout->addWidget(v, 0, 0); // Execute switch (type) { case Dialog::ModalDialog: dialog->exec(); break; case Dialog::MainWindow: { if (mainWindowGeometry.isEmpty()) { mainWindow->adjustSize(); mainWindow->move(QApplication::desktop()->screen()->rect().center() - mainWindow->rect().center()); } else mainWindow->restoreGeometry(mainWindowGeometry); } default: windowWidget->setAttribute(Qt::WA_DeleteOnClose); windowWidget->show(); break; } int result = 0; property = root->property("dialogResult"); if (property.isValid()) result = property.toInt(); if (type == Dialog::ModalDialog) delete dialog; return result; }
int main(int argc, char** argv) { bool timeit = FALSE; QApplication app(argc,argv); bool scrollbars=FALSE; for (int arg=1; arg<argc; arg++) { if (0==strcmp(argv[arg],"-bounce")) { bouncers=atoi(argv[++arg]); } else if (0==strcmp(argv[arg],"-help") || 0==strcmp(argv[arg],"--help")) { showtext=FALSE; } else if (0==strcmp(argv[arg],"-redraws")) { showredraws=TRUE; } else if (0==strcmp(argv[arg],"-lines")) { showlines=TRUE; } else if (0==strcmp(argv[arg],"-btext")) { btext=FALSE; } else if (0==strcmp(argv[arg],"-dsprite")) { dsprite=FALSE; } else if (0==strcmp(argv[arg],"-dpoly")) { dpoly=!dpoly; } else if (0==strcmp(argv[arg],"-delay")) { refresh_delay=atoi(argv[++arg]); } else if (0==strcmp(argv[arg],"-sb")) { scrollbars=TRUE; } else if (0==strcmp(argv[arg],"-noopt")) { QPixmap::setDefaultOptimization( QPixmap::NoOptim ); } else if (0==strcmp(argv[arg],"-bestopt")) { QPixmap::setDefaultOptimization( QPixmap::BestOptim ); #ifdef _WS_WIN_ } else if (0==strcmp(argv[arg],"-bsm")) { extern bool qt_bitblt_bsm; qt_bitblt_bsm=TRUE; #endif } else if (0==strcmp(argv[arg],"-iter")) { iterations=atoi(argv[++arg]); timeit = TRUE; } else { warning("Bad param %s", argv[arg]); } } QMainWindow m; MySpriteField field(IMG_BACKGROUND,scrollbars ? WIDTH*3 : WIDTH, scrollbars ? HEIGHT*3 : HEIGHT); Example example(scrollbars,field,&m); QMenuBar* menu = m.menuBar(); QPopupMenu* file = new QPopupMenu; file->insertItem("New view", &example, SLOT(makeSlave()), CTRL+Key_N); file->insertSeparator(); file->insertItem("Quit", qApp, SLOT(quit()), CTRL+Key_Q); menu->insertItem("&File", file); QPopupMenu* edit = new QPopupMenu; edit->insertItem("New polygon", &example, SLOT(makePolygon())); edit->insertItem("New ellipse", &example, SLOT(makeEllipse())); edit->insertItem("New rectangle", &example, SLOT(makeRectangle())); menu->insertItem("&Edit", edit); MyPopupMenu* options = new MyPopupMenu; options->insertCheckItem("Show help text", &showtext, CTRL+Key_H); options->insertCheckItem("Show bouncing text", &btext, CTRL+Key_T); options->insertCheckItem("Show polygon", &dpoly, CTRL+Key_P); options->insertCheckItem("Show drawn sprite", &dsprite, CTRL+Key_D); options->insertCheckItem("Show redraw areas", &showredraws, CTRL+Key_A); options->insertCheckItem("Show foreground lines", &showlines, CTRL+Key_L); options->insertSeparator(); options->insertRadioItem("1 bouncer", &bouncers, 1); options->insertRadioItem("3 bouncers", &bouncers, 3); options->insertRadioItem("10 bouncers", &bouncers, 10); options->insertRadioItem("30 bouncers", &bouncers, 30); options->insertRadioItem("100 bouncers", &bouncers, 100); options->insertRadioItem("1000 bouncers", &bouncers, 1000); options->insertSeparator(); options->insertRadioItem("No delay", &refresh_delay, 0); options->insertRadioItem("500 fps", &refresh_delay, 2); options->insertRadioItem("100 fps", &refresh_delay, 10); options->insertRadioItem("72 fps", &refresh_delay, 14); options->insertRadioItem("30 fps", &refresh_delay, 33); options->insertRadioItem("10 fps", &refresh_delay, 100); options->insertRadioItem("5 fps", &refresh_delay, 200); options->insertSeparator(); options->insertRadioItem("1/10 speed", &speed, 2); options->insertRadioItem("1/2 speed", &speed, 10); options->insertRadioItem("1x speed", &speed, 20); options->insertRadioItem("2x speed", &speed, 40); options->insertRadioItem("5x speed", &speed, 100); menu->insertItem("&Options",options); m.statusBar(); QObject::connect(options, SIGNAL(variableChanged(bool*)), &example, SLOT(refresh())); QObject::connect(options, SIGNAL(variableChanged(int*)), &example, SLOT(refresh())); QObject::connect(&example, SIGNAL(status(const char*)), m.statusBar(), SLOT(message(const char*))); m.setCentralWidget(&example); app.setMainWidget(&m); m.show(); QTime t; t.start(); app.exec(); if ( timeit ) debug("%dms",t.elapsed()); return 0; }
int main(int argc, char * argv[]) { QList<QWidget*> widgets; QApplication app(argc, argv); QMainWindow mainWindow; mainWindow.setWindowTitle("Test"); QMenu *fileMenu = mainWindow.menuBar()->addMenu("File"); QMenu *editMenu = mainWindow.menuBar()->addMenu("Edit"); QMenu *viewMenu = mainWindow.menuBar()->addMenu("View"); QMenu *toolsMenu = mainWindow.menuBar()->addMenu("Tools"); QMenu *optionsMenu = mainWindow.menuBar()->addMenu("Options"); QMenu *helpMenu = mainWindow.menuBar()->addMenu("Help"); qApp->processEvents(); fileMenu->addAction("Open"); QAction *close = fileMenu->addAction("Close"); fileMenu->addSeparator(); fileMenu->addAction("Exit"); close->setEnabled(false); editMenu->addAction("Cut"); editMenu->addAction("Pase"); editMenu->addAction("Copy"); editMenu->addSeparator(); editMenu->addAction("Find"); viewMenu->addAction("Hide"); viewMenu->addAction("Show"); viewMenu->addAction("Explore"); QAction *visible = viewMenu->addAction("Visible"); visible->setCheckable(true); visible->setChecked(true); toolsMenu->addMenu("Hammer"); toolsMenu->addMenu("Caliper"); toolsMenu->addMenu("Helm"); optionsMenu->addMenu("Settings"); optionsMenu->addMenu("Standard"); optionsMenu->addMenu("Extended"); QMenu *subMenu = helpMenu->addMenu("Help"); subMenu->addAction("Index"); subMenu->addSeparator(); subMenu->addAction("Vodoo Help"); helpMenu->addAction("Contens"); helpMenu->addSeparator(); helpMenu->addAction("About"); QToolBar toolbar; mainWindow.addToolBar(&toolbar); toolbar.addAction(QIcon(qApp->style()->standardPixmap(QStyle::SP_FileIcon)), QString("textAction")); QTextEdit textEdit; mainWindow.setCentralWidget(&textEdit); mainWindow.showMaximized(); app.exec(); }
void QmitkExtWorkbenchWindowAdvisor::PostWindowCreate() { QmitkCommonWorkbenchWindowAdvisor::PostWindowCreate(); // very bad hack... berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow(); QMainWindow* mainWindow = static_cast<QMainWindow*> (window->GetShell()->GetControl()); if (!windowIcon.empty()) { mainWindow->setWindowIcon(QIcon(QString::fromStdString(windowIcon))); } mainWindow->setContextMenuPolicy(Qt::PreventContextMenu); /*mainWindow->setStyleSheet("color: white;" "background-color: #808080;" "selection-color: #659EC7;" "selection-background-color: #808080;" " QMenuBar {" "background-color: #808080; }");*/ // ==== Application menu ============================ QMenuBar* menuBar = mainWindow->menuBar(); menuBar->setContextMenuPolicy(Qt::PreventContextMenu); QMenu* fileMenu = menuBar->addMenu("&File"); fileMenu->setObjectName("FileMenu"); QAction* fileOpenAction = new QmitkExtFileOpenAction(QIcon(":/org.mitk.gui.qt.ext/Load_48.png"), window); fileMenu->addAction(fileOpenAction); fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window); fileSaveProjectAction->setIcon(QIcon(":/org.mitk.gui.qt.ext/Save_48.png")); fileMenu->addAction(fileSaveProjectAction); closeProjectAction = new QmitkCloseProjectAction(window); closeProjectAction->setIcon(QIcon(":/org.mitk.gui.qt.ext/Remove_48.png")); fileMenu->addAction(closeProjectAction); fileMenu->addSeparator(); QAction* fileExitAction = new QmitkFileExitAction(window); fileExitAction->setObjectName("QmitkFileExitAction"); fileMenu->addAction(fileExitAction); berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); const std::vector<berry::IViewDescriptor::Pointer>& viewDescriptors = viewRegistry->GetViews(); // another bad hack to get an edit/undo menu... QMenu* editMenu = menuBar->addMenu("&Edit"); undoAction = editMenu->addAction(QIcon(":/org.mitk.gui.qt.ext/Undo_48.png"), "&Undo", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onUndo()), QKeySequence("CTRL+Z")); undoAction->setToolTip("Undo the last action (not supported by all modules)"); redoAction = editMenu->addAction(QIcon(":/org.mitk.gui.qt.ext/Redo_48.png") , "&Redo", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onRedo()), QKeySequence("CTRL+Y")); redoAction->setToolTip("execute the last action that was undone again (not supported by all modules)"); imageNavigatorAction = new QAction(QIcon(":/org.mitk.gui.qt.ext/Slider.png"), "&Image Navigator", NULL); bool imageNavigatorViewFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.imagenavigator"); if (imageNavigatorViewFound) { QObject::connect(imageNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onImageNavigator())); imageNavigatorAction->setCheckable(true); // add part listener for image navigator imageNavigatorPartListener = new PartListenerForImageNavigator(imageNavigatorAction); window->GetPartService()->AddPartListener(imageNavigatorPartListener); berry::IViewPart::Pointer imageNavigatorView = window->GetActivePage()->FindView("org.mitk.views.imagenavigator"); imageNavigatorAction->setChecked(false); if (imageNavigatorView) { bool isImageNavigatorVisible = window->GetActivePage()->IsPartVisible(imageNavigatorView); if (isImageNavigatorVisible) imageNavigatorAction->setChecked(true); } imageNavigatorAction->setToolTip("Open image navigator for navigating through image"); } // toolbar for showing file open, undo, redo and other main actions QToolBar* mainActionsToolBar = new QToolBar; mainActionsToolBar->setContextMenuPolicy(Qt::PreventContextMenu); #ifdef __APPLE__ mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextUnderIcon ); #else mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextBesideIcon ); #endif mainActionsToolBar->addAction(fileOpenAction); mainActionsToolBar->addAction(fileSaveProjectAction); mainActionsToolBar->addAction(closeProjectAction); mainActionsToolBar->addAction(undoAction); mainActionsToolBar->addAction(redoAction); if (imageNavigatorViewFound) { mainActionsToolBar->addAction(imageNavigatorAction); } mainWindow->addToolBar(mainActionsToolBar); #ifdef __APPLE__ mainWindow->setUnifiedTitleAndToolBarOnMac(true); #endif // ==== Window Menu ========================== QMenu* windowMenu = menuBar->addMenu("Window"); if (showNewWindowMenuItem) { windowMenu->addAction("&New Window", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onNewWindow())); windowMenu->addSeparator(); } QMenu* perspMenu = windowMenu->addMenu("&Open Perspective"); QMenu* viewMenu; if (showViewMenuItem) { viewMenu = windowMenu->addMenu("Show &View"); viewMenu->setObjectName("Show View"); } windowMenu->addSeparator(); resetPerspAction = windowMenu->addAction("&Reset Perspective", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onResetPerspective())); if(showClosePerspectiveMenuItem) closePerspAction = windowMenu->addAction("&Close Perspective", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onClosePerspective())); windowMenu->addSeparator(); windowMenu->addAction("&Preferences...", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onEditPreferences()), QKeySequence("CTRL+P")); // fill perspective menu berry::IPerspectiveRegistry* perspRegistry = window->GetWorkbench()->GetPerspectiveRegistry(); QActionGroup* perspGroup = new QActionGroup(menuBar); std::vector<berry::IPerspectiveDescriptor::Pointer> perspectives( perspRegistry->GetPerspectives()); bool skip = false; for (std::vector<berry::IPerspectiveDescriptor::Pointer>::iterator perspIt = perspectives.begin(); perspIt != perspectives.end(); ++perspIt) { // if perspectiveExcludeList is set, it contains the id-strings of perspectives, which // should not appear as an menu-entry in the perspective menu if (perspectiveExcludeList.size() > 0) { for (unsigned int i=0; i<perspectiveExcludeList.size(); i++) { if (perspectiveExcludeList.at(i) == (*perspIt)->GetId()) { skip = true; break; } } if (skip) { skip = false; continue; } } QAction* perspAction = new berry::QtOpenPerspectiveAction(window, *perspIt, perspGroup); mapPerspIdToAction.insert(std::make_pair((*perspIt)->GetId(), perspAction)); } perspMenu->addActions(perspGroup->actions()); // sort elements (converting vector to map...) std::vector<berry::IViewDescriptor::Pointer>::const_iterator iter; std::map<std::string, berry::IViewDescriptor::Pointer> VDMap; skip = false; for (iter = viewDescriptors.begin(); iter != viewDescriptors.end(); ++iter) { // if viewExcludeList is set, it contains the id-strings of view, which // should not appear as an menu-entry in the menu if (viewExcludeList.size() > 0) { for (unsigned int i=0; i<viewExcludeList.size(); i++) { if (viewExcludeList.at(i) == (*iter)->GetId()) { skip = true; break; } } if (skip) { skip = false; continue; } } if ((*iter)->GetId() == "org.blueberry.ui.internal.introview") continue; if ((*iter)->GetId() == "org.mitk.views.imagenavigator") continue; std::pair<std::string, berry::IViewDescriptor::Pointer> p( (*iter)->GetLabel(), (*iter)); VDMap.insert(p); } // ================================================== // ==== Perspective Toolbar ================================== QToolBar* qPerspectiveToolbar = new QToolBar; if (showPerspectiveToolbar) { qPerspectiveToolbar->addActions(perspGroup->actions()); mainWindow->addToolBar(qPerspectiveToolbar); } else delete qPerspectiveToolbar; // ==== View Toolbar ================================== QToolBar* qToolbar = new QToolBar; std::map<std::string, berry::IViewDescriptor::Pointer>::const_iterator MapIter; for (MapIter = VDMap.begin(); MapIter != VDMap.end(); ++MapIter) { berry::QtShowViewAction* viewAction = new berry::QtShowViewAction(window, (*MapIter).second); viewActions.push_back(viewAction); if(showViewMenuItem) viewMenu->addAction(viewAction); if (showViewToolbar) { qToolbar->addAction(viewAction); } } if (showViewToolbar) { mainWindow->addToolBar(qToolbar); } else delete qToolbar; QSettings settings(GetQSettingsFile(), QSettings::IniFormat); mainWindow->restoreState(settings.value("ToolbarPosition").toByteArray()); // ==================================================== // ===== Help menu ==================================== QMenu* helpMenu = menuBar->addMenu("Help"); helpMenu->addAction("&Welcome",this, SLOT(onIntro())); helpMenu->addAction("&Help Contents",this, SLOT(onHelp()), QKeySequence("F1")); helpMenu->addAction("&About",this, SLOT(onAbout())); // ===================================================== QStatusBar* qStatusBar = new QStatusBar(); //creating a QmitkStatusBar for Output on the QStatusBar and connecting it with the MainStatusBar QmitkStatusBar *statusBar = new QmitkStatusBar(qStatusBar); //disabling the SizeGrip in the lower right corner statusBar->SetSizeGripEnabled(false); QmitkProgressBar *progBar = new QmitkProgressBar(); qStatusBar->addPermanentWidget(progBar, 0); progBar->hide(); // progBar->AddStepsToDo(2); // progBar->Progress(1); mainWindow->setStatusBar(qStatusBar); QmitkMemoryUsageIndicatorView* memoryIndicator = new QmitkMemoryUsageIndicatorView(); qStatusBar->addPermanentWidget(memoryIndicator, 0); }
int main(int argc, char *argv[]) { int retVal = -1; stringstream strStream; try { Miro::Log::init(argc, argv); Miro::Robot::init(argc, argv); Miro::Configuration::init(argc, argv, KNRAPID_INSTALL_PREFIX "/etc"); kn::DdsEntitiesFactorySvcParameters * params = kn::DdsEntitiesFactorySvcParameters::instance(); if (params->defaultLibrary.empty()) { params->defaultLibrary = "RapidQosLibrary"; } kn::DdsSupport::init(argc, argv); Opts::parseArgs(argc, argv); if(Opts::verbosity > 0) { // turn up RTI DDS logging NDDSConfigLogger* logger = NDDSConfigLogger::get_instance(); logger->set_verbosity(NDDS_CONFIG_LOG_VERBOSITY_WARNING); if(Opts::verbosity == 2) { logger->set_verbosity_by_category(NDDS_CONFIG_LOG_CATEGORY_API, NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL); } else if(Opts::verbosity > 2) { logger->set_verbosity(NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL); } } // Hardcode participant name params->participants[0].participantName = "ImageReader"; kn::DdsEntitiesFactorySvc ddsEntities; ddsEntities.init(params); { QApplication app(argc, argv); string topic = Opts::topicName; if(Opts::topicSuffix.size() > 0) { topic = topic + "-" + Opts::topicSuffix; } if(Opts::verbosity > 0) { cout << "subscription topic is " << topic << endl; } QMainWindow mainWindow; RapidImageWidget* imageWidget = new RapidImageWidget(Miro::RobotParameters::instance()->name.c_str(), topic.c_str(), Opts::qosProfile.c_str(), "", // Default library &mainWindow); mainWindow.setCentralWidget(imageWidget); QMenu* fileMenu = mainWindow.menuBar()->addMenu("&File"); fileMenu->addAction( "E&xit", qApp, SLOT(quit()) ); QPixmap iconPix(CameraIconGrey256_xpm); QIcon appIcon(iconPix); mainWindow.setWindowIcon(appIcon); mainWindow.show(); mainWindow.resize(440, 440); retVal = app.exec(); } ddsEntities.fini(); } catch ( const Miro::Exception& me ) { strStream << "Miro::Exception: " << me << endl; } catch ( ... ) { strStream << "Unknown exception in main\n"; } QString str(strStream.str().c_str()); if (!str.isEmpty()) { qWarning("Exception caught: %s", qPrintable(str) ); QMessageBox::critical( NULL, "Exception Caught", str ); } return retVal; }
void ProgramWindow::setup() { if (parentWidget() == NULL) { resize(500,700); setAttribute(Qt::WA_DeleteOnClose, true); } QFrame * mainFrame = new QFrame(this); QFrame * headerFrame = createHeader(); QFrame * centerFrame = createCenter(); layout()->setMargin(0); layout()->setSpacing(0); QGridLayout *layout = new QGridLayout(mainFrame); layout->setMargin(0); layout->setSpacing(0); layout->addWidget(headerFrame,0,0); layout->addWidget(centerFrame,1,0); setCentralWidget(mainFrame); setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding); QSettings settings; if (!settings.value("programwindow/state").isNull()) { restoreState(settings.value("programwindow/state").toByteArray()); } if (!settings.value("programwindow/geometry").isNull()) { restoreGeometry(settings.value("programwindow/geometry").toByteArray()); } installEventFilter(this); // Setup new menu bar for the programming window QMenuBar * menubar = NULL; if (parentWidget()) { QMainWindow * mainWindow = qobject_cast<QMainWindow *>(parentWidget()); if (mainWindow) menubar = mainWindow->menuBar(); } if (menubar == NULL) menubar = menuBar(); m_fileMenu = menubar->addMenu(tr("&File")); QAction *currentAction = new QAction(tr("New Code File"), this); currentAction->setShortcut(tr("Ctrl+N")); currentAction->setStatusTip(tr("Create a new program")); connect(currentAction, SIGNAL(triggered()), this, SLOT(addTab())); m_fileMenu->addAction(currentAction); currentAction = new QAction(tr("&Open Code File..."), this); currentAction->setShortcut(tr("Ctrl+O")); currentAction->setStatusTip(tr("Open a program")); connect(currentAction, SIGNAL(triggered()), this, SLOT(loadProgramFile())); m_fileMenu->addAction(currentAction); m_fileMenu->addSeparator(); m_saveAction = new QAction(tr("&Save Code File"), this); m_saveAction->setShortcut(tr("Ctrl+S")); m_saveAction->setStatusTip(tr("Save the current program")); connect(m_saveAction, SIGNAL(triggered()), this, SLOT(save())); m_fileMenu->addAction(m_saveAction); currentAction = new QAction(tr("Rename Code File"), this); currentAction->setStatusTip(tr("Rename the current program")); connect(currentAction, SIGNAL(triggered()), this, SLOT(rename())); m_fileMenu->addAction(currentAction); currentAction = new QAction(tr("Duplicate tab"), this); currentAction->setStatusTip(tr("Copies the current program into a new tab")); connect(currentAction, SIGNAL(triggered()), this, SLOT(duplicateTab())); m_fileMenu->addAction(currentAction); m_fileMenu->addSeparator(); currentAction = new QAction(tr("Remove tab"), this); currentAction->setShortcut(tr("Ctrl+W")); currentAction->setStatusTip(tr("Remove the current program from the sketch")); connect(currentAction, SIGNAL(triggered()), this, SLOT(closeCurrentTab())); m_fileMenu->addAction(currentAction); m_fileMenu->addSeparator(); m_printAction = new QAction(tr("&Print..."), this); m_printAction->setShortcut(tr("Ctrl+P")); m_printAction->setStatusTip(tr("Print the current program")); connect(m_printAction, SIGNAL(triggered()), this, SLOT(print())); m_fileMenu->addAction(m_printAction); m_fileMenu->addSeparator(); currentAction = new QAction(tr("&Quit"), this); currentAction->setShortcut(tr("Ctrl+Q")); currentAction->setStatusTip(tr("Quit the application")); currentAction->setMenuRole(QAction::QuitRole); connect(currentAction, SIGNAL(triggered()), qApp, SLOT(closeAllWindows2())); m_fileMenu->addAction(currentAction); m_editMenu = menubar->addMenu(tr("&Edit")); m_undoAction = new QAction(tr("Undo"), this); m_undoAction->setShortcuts(QKeySequence::Undo); m_undoAction->setEnabled(false); connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo())); m_editMenu->addAction(m_undoAction); m_redoAction = new QAction(tr("Redo"), this); m_redoAction->setShortcuts(QKeySequence::Redo); m_redoAction->setEnabled(false); connect(m_redoAction, SIGNAL(triggered()), this, SLOT(redo())); m_editMenu->addAction(m_redoAction); m_editMenu->addSeparator(); m_cutAction = new QAction(tr("&Cut"), this); m_cutAction->setShortcut(tr("Ctrl+X")); m_cutAction->setStatusTip(tr("Cut selection")); m_cutAction->setEnabled(false); connect(m_cutAction, SIGNAL(triggered()), this, SLOT(cut())); m_editMenu->addAction(m_cutAction); m_copyAction = new QAction(tr("&Copy"), this); m_copyAction->setShortcut(tr("Ctrl+C")); m_copyAction->setStatusTip(tr("Copy selection")); m_copyAction->setEnabled(false); connect(m_copyAction, SIGNAL(triggered()), this, SLOT(copy())); m_editMenu->addAction(m_copyAction); currentAction = new QAction(tr("&Paste"), this); currentAction->setShortcut(tr("Ctrl+V")); currentAction->setStatusTip(tr("Paste clipboard contents")); // TODO: Check clipboard status and disable appropriately here connect(currentAction, SIGNAL(triggered()), this, SLOT(paste())); m_editMenu->addAction(currentAction); m_editMenu->addSeparator(); currentAction = new QAction(tr("&Select All"), this); currentAction->setShortcut(tr("Ctrl+A")); currentAction->setStatusTip(tr("Select all text")); connect(currentAction, SIGNAL(triggered()), this, SLOT(selectAll())); m_editMenu->addAction(currentAction); m_programMenu = menubar->addMenu(tr("&Code")); QMenu *languageMenu = new QMenu(tr("Select language"), this); m_programMenu->addMenu(languageMenu); QString currentLanguage = settings.value("programwindow/language", "").toString(); QStringList languages = getAvailableLanguages(); QActionGroup *languageActionGroup = new QActionGroup(this); foreach (QString language, languages) { currentAction = new QAction(language, this); currentAction->setCheckable(true); m_languageActions.insert(language, currentAction); languageActionGroup->addAction(currentAction); languageMenu->addAction(currentAction); if (!currentLanguage.isEmpty()) { if (language.compare(currentLanguage) == 0) { currentAction->setChecked(true); } } }
void QmitkExtWorkbenchWindowAdvisor::PostWindowCreate() { // very bad hack... berry::IWorkbenchWindow::Pointer window = this->GetWindowConfigurer()->GetWindow(); QMainWindow* mainWindow = qobject_cast<QMainWindow*> (window->GetShell()->GetControl()); if (!windowIcon.isEmpty()) { mainWindow->setWindowIcon(QIcon(windowIcon)); } mainWindow->setContextMenuPolicy(Qt::PreventContextMenu); /*mainWindow->setStyleSheet("color: white;" "background-color: #808080;" "selection-color: #659EC7;" "selection-background-color: #808080;" " QMenuBar {" "background-color: #808080; }");*/ // Load selected icon theme QStringList searchPaths = QIcon::themeSearchPaths(); searchPaths.push_front( QString(":/org_mitk_icons/icons/") ); QIcon::setThemeSearchPaths( searchPaths ); berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService(); berry::IPreferences::Pointer stylePref = prefService->GetSystemPreferences()->Node(berry::QtPreferences::QT_STYLES_NODE); QString iconTheme = stylePref->Get(berry::QtPreferences::QT_ICON_THEME, "<<default>>"); if( iconTheme == QString( "<<default>>" ) ) { iconTheme = QString( "tango" ); } QIcon::setThemeName( iconTheme ); // ==== Application menu ============================ QMenuBar* menuBar = mainWindow->menuBar(); menuBar->setContextMenuPolicy(Qt::PreventContextMenu); #ifdef __APPLE__ menuBar->setNativeMenuBar(true); #else menuBar->setNativeMenuBar(false); #endif QAction* fileOpenAction = new QmitkFileOpenAction(QIcon::fromTheme("document-open",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-open.svg")), window); fileOpenAction->setShortcut(QKeySequence::Open); QAction* fileSaveAction = new QmitkFileSaveAction(QIcon(":/org.mitk.gui.qt.ext/Save_48.png"), window); fileSaveAction->setShortcut(QKeySequence::Save); fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window); fileSaveProjectAction->setIcon(QIcon::fromTheme("document-save",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-save.svg"))); closeProjectAction = new QmitkCloseProjectAction(window); closeProjectAction->setIcon(QIcon::fromTheme("edit-delete",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-delete.svg"))); auto perspGroup = new QActionGroup(menuBar); std::map<QString, berry::IViewDescriptor::Pointer> VDMap; // sort elements (converting vector to map...) QList<berry::IViewDescriptor::Pointer>::const_iterator iter; berry::IViewRegistry* viewRegistry = berry::PlatformUI::GetWorkbench()->GetViewRegistry(); const QList<berry::IViewDescriptor::Pointer> viewDescriptors = viewRegistry->GetViews(); bool skip = false; for (iter = viewDescriptors.begin(); iter != viewDescriptors.end(); ++iter) { // if viewExcludeList is set, it contains the id-strings of view, which // should not appear as an menu-entry in the menu if (viewExcludeList.size() > 0) { for (int i=0; i<viewExcludeList.size(); i++) { if (viewExcludeList.at(i) == (*iter)->GetId()) { skip = true; break; } } if (skip) { skip = false; continue; } } if ((*iter)->GetId() == "org.blueberry.ui.internal.introview") continue; if ((*iter)->GetId() == "org.mitk.views.imagenavigator") continue; if ((*iter)->GetId() == "org.mitk.views.viewnavigatorview") continue; std::pair<QString, berry::IViewDescriptor::Pointer> p( (*iter)->GetLabel(), (*iter)); VDMap.insert(p); } std::map<QString, berry::IViewDescriptor::Pointer>::const_iterator MapIter; for (MapIter = VDMap.begin(); MapIter != VDMap.end(); ++MapIter) { berry::QtShowViewAction* viewAction = new berry::QtShowViewAction(window, (*MapIter).second); viewActions.push_back(viewAction); } if (!USE_EXPERIMENTAL_COMMAND_CONTRIBUTIONS) { QMenu* fileMenu = menuBar->addMenu("&File"); fileMenu->setObjectName("FileMenu"); fileMenu->addAction(fileOpenAction); fileMenu->addAction(fileSaveAction); fileMenu->addAction(fileSaveProjectAction); fileMenu->addAction(closeProjectAction); fileMenu->addSeparator(); QAction* fileExitAction = new QmitkFileExitAction(window); fileExitAction->setIcon(QIcon::fromTheme("system-log-out",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/system-log-out.svg"))); fileExitAction->setShortcut(QKeySequence::Quit); fileExitAction->setObjectName("QmitkFileExitAction"); fileMenu->addAction(fileExitAction); // another bad hack to get an edit/undo menu... QMenu* editMenu = menuBar->addMenu("&Edit"); undoAction = editMenu->addAction(QIcon::fromTheme("edit-undo",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-undo.svg")), "&Undo", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onUndo()), QKeySequence("CTRL+Z")); undoAction->setToolTip("Undo the last action (not supported by all modules)"); redoAction = editMenu->addAction(QIcon::fromTheme("edit-redo",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-redo.svg")) , "&Redo", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onRedo()), QKeySequence("CTRL+Y")); redoAction->setToolTip("execute the last action that was undone again (not supported by all modules)"); // ==== Window Menu ========================== QMenu* windowMenu = menuBar->addMenu("Window"); if (showNewWindowMenuItem) { windowMenu->addAction("&New Window", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onNewWindow())); windowMenu->addSeparator(); } QMenu* perspMenu = windowMenu->addMenu("&Open Perspective"); QMenu* viewMenu; if (showViewMenuItem) { viewMenu = windowMenu->addMenu("Show &View"); viewMenu->setObjectName("Show View"); } windowMenu->addSeparator(); resetPerspAction = windowMenu->addAction("&Reset Perspective", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onResetPerspective())); if(showClosePerspectiveMenuItem) closePerspAction = windowMenu->addAction("&Close Perspective", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onClosePerspective())); windowMenu->addSeparator(); windowMenu->addAction("&Preferences...", QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onEditPreferences()), QKeySequence("CTRL+P")); // fill perspective menu berry::IPerspectiveRegistry* perspRegistry = window->GetWorkbench()->GetPerspectiveRegistry(); QList<berry::IPerspectiveDescriptor::Pointer> perspectives( perspRegistry->GetPerspectives()); skip = false; for (QList<berry::IPerspectiveDescriptor::Pointer>::iterator perspIt = perspectives.begin(); perspIt != perspectives.end(); ++perspIt) { // if perspectiveExcludeList is set, it contains the id-strings of perspectives, which // should not appear as an menu-entry in the perspective menu if (perspectiveExcludeList.size() > 0) { for (int i=0; i<perspectiveExcludeList.size(); i++) { if (perspectiveExcludeList.at(i) == (*perspIt)->GetId()) { skip = true; break; } } if (skip) { skip = false; continue; } } QAction* perspAction = new berry::QtOpenPerspectiveAction(window, *perspIt, perspGroup); mapPerspIdToAction.insert((*perspIt)->GetId(), perspAction); } perspMenu->addActions(perspGroup->actions()); if (showViewMenuItem) { for (auto viewAction : viewActions) { viewMenu->addAction(viewAction); } } // ===== Help menu ==================================== QMenu* helpMenu = menuBar->addMenu("&Help"); helpMenu->addAction("&Welcome",this, SLOT(onIntro())); helpMenu->addAction("&Open Help Perspective", this, SLOT(onHelpOpenHelpPerspective())); helpMenu->addAction("&Context Help",this, SLOT(onHelp()), QKeySequence("F1")); helpMenu->addAction("&About",this, SLOT(onAbout())); // ===================================================== } else { //undoAction = new QAction(QIcon::fromTheme("edit-undo",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-undo.svg")), // "&Undo", nullptr); undoAction = new QmitkUndoAction(QIcon::fromTheme("edit-undo",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-undo.svg")), nullptr); undoAction->setShortcut(QKeySequence::Undo); redoAction = new QmitkRedoAction(QIcon::fromTheme("edit-redo",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-redo.svg")), nullptr); redoAction->setShortcut(QKeySequence::Redo); } // toolbar for showing file open, undo, redo and other main actions auto mainActionsToolBar = new QToolBar; mainActionsToolBar->setObjectName("mainActionsToolBar"); mainActionsToolBar->setContextMenuPolicy(Qt::PreventContextMenu); #ifdef __APPLE__ mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextUnderIcon ); #else mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextBesideIcon ); #endif imageNavigatorAction = new QAction(QIcon(":/org.mitk.gui.qt.ext/Slider.png"), "&Image Navigator", nullptr); bool imageNavigatorViewFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.imagenavigator"); if(this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor")) { openDicomEditorAction = new QmitkOpenDicomEditorAction(QIcon(":/org.mitk.gui.qt.ext/dcm-icon.png"),window); } if (imageNavigatorViewFound) { QObject::connect(imageNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onImageNavigator())); imageNavigatorAction->setCheckable(true); // add part listener for image navigator imageNavigatorPartListener.reset(new PartListenerForImageNavigator(imageNavigatorAction)); window->GetPartService()->AddPartListener(imageNavigatorPartListener.data()); berry::IViewPart::Pointer imageNavigatorView = window->GetActivePage()->FindView("org.mitk.views.imagenavigator"); imageNavigatorAction->setChecked(false); if (imageNavigatorView) { bool isImageNavigatorVisible = window->GetActivePage()->IsPartVisible(imageNavigatorView); if (isImageNavigatorVisible) imageNavigatorAction->setChecked(true); } imageNavigatorAction->setToolTip("Toggle image navigator for navigating through image"); } viewNavigatorAction = new QAction(QIcon(":/org.mitk.gui.qt.ext/view-manager_48.png"),"&View Navigator", nullptr); viewNavigatorFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.viewnavigatorview"); if (viewNavigatorFound) { QObject::connect(viewNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onViewNavigator())); viewNavigatorAction->setCheckable(true); // add part listener for view navigator viewNavigatorPartListener.reset(new PartListenerForViewNavigator(viewNavigatorAction)); window->GetPartService()->AddPartListener(viewNavigatorPartListener.data()); berry::IViewPart::Pointer viewnavigatorview = window->GetActivePage()->FindView("org.mitk.views.viewnavigatorview"); viewNavigatorAction->setChecked(false); if (viewnavigatorview) { bool isViewNavigatorVisible = window->GetActivePage()->IsPartVisible(viewnavigatorview); if (isViewNavigatorVisible) viewNavigatorAction->setChecked(true); } viewNavigatorAction->setToolTip("Toggle View Navigator"); } mainActionsToolBar->addAction(fileOpenAction); mainActionsToolBar->addAction(fileSaveProjectAction); mainActionsToolBar->addAction(closeProjectAction); mainActionsToolBar->addAction(undoAction); mainActionsToolBar->addAction(redoAction); if(this->GetWindowConfigurer()->GetWindow()->GetWorkbench()->GetEditorRegistry()->FindEditor("org.mitk.editors.dicomeditor")) { mainActionsToolBar->addAction(openDicomEditorAction); } if (imageNavigatorViewFound) { mainActionsToolBar->addAction(imageNavigatorAction); } if (viewNavigatorFound) { mainActionsToolBar->addAction(viewNavigatorAction); } mainWindow->addToolBar(mainActionsToolBar); // ==== Perspective Toolbar ================================== auto qPerspectiveToolbar = new QToolBar; qPerspectiveToolbar->setObjectName("perspectiveToolBar"); if (showPerspectiveToolbar) { qPerspectiveToolbar->addActions(perspGroup->actions()); mainWindow->addToolBar(qPerspectiveToolbar); } else delete qPerspectiveToolbar; // ==== View Toolbar ================================== auto qToolbar = new QToolBar; qToolbar->setObjectName("viewToolBar"); if (showViewToolbar) { mainWindow->addToolBar(qToolbar); for (auto viewAction : viewActions) { qToolbar->addAction(viewAction); } } else delete qToolbar; QSettings settings(GetQSettingsFile(), QSettings::IniFormat); mainWindow->restoreState(settings.value("ToolbarPosition").toByteArray()); auto qStatusBar = new QStatusBar(); //creating a QmitkStatusBar for Output on the QStatusBar and connecting it with the MainStatusBar auto statusBar = new QmitkStatusBar(qStatusBar); //disabling the SizeGrip in the lower right corner statusBar->SetSizeGripEnabled(false); auto progBar = new QmitkProgressBar(); qStatusBar->addPermanentWidget(progBar, 0); progBar->hide(); // progBar->AddStepsToDo(2); // progBar->Progress(1); mainWindow->setStatusBar(qStatusBar); if (showMemoryIndicator) { auto memoryIndicator = new QmitkMemoryUsageIndicatorView(); qStatusBar->addPermanentWidget(memoryIndicator, 0); } }