Skip to content

Commit

Permalink
Re #4282. More support for shared menu bar.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Dec 23, 2011
1 parent cc4d0ee commit 863eb39
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 41 deletions.
124 changes: 88 additions & 36 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,26 @@ ApplicationWindow::ApplicationWindow(bool factorySettings)
{
QCoreApplication::setOrganizationName("ISIS");
QCoreApplication::setApplicationName("MantidPlot");
#ifdef SHARED_MENUBAR
#ifdef Q_OS_MAC // Mac
QSettings settings(QSettings::IniFormat,QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
#else
QSettings settings;
#endif
if (settings.value("/General/SharedMenuBar",false).toBool())
{
std::cerr << "Shared" << std::endl;
m_sharedMenuBar = new QMenuBar(NULL);
setMenuBar(m_sharedMenuBar);
}
else
{
std::cerr << "Not shared" << std::endl;
m_sharedMenuBar = NULL;
}
#endif
mantidUI = new MantidUI(this);
setAttribute(Qt::WA_DeleteOnClose);
setMenuBar(new QMenuBar(NULL));
init(factorySettings);
}

Expand Down Expand Up @@ -739,6 +756,15 @@ void ApplicationWindow::initGlobalConstants()
d_keep_plot_aspect = true;
}

QMenuBar* ApplicationWindow::myMenuBar()
{
#ifdef SHARED_MENUBAR
return m_sharedMenuBar == NULL ? menuBar() : m_sharedMenuBar;
#else
return menuBar();
#endif
}

void ApplicationWindow::initToolBars()
{
initPlot3DToolBar();
Expand Down Expand Up @@ -1121,6 +1147,19 @@ void ApplicationWindow::initMainMenu()
view->addAction(actionShowConsole);
//#endif

view->insertSeparator();
view->addAction(actionShowScriptWindow);//Mantid
view->addAction(actionShowScriptInterpreter);
view->insertSeparator();

mantidUI->addMenuItems(view);

view->insertSeparator();
view->addAction(actionToolBars);
view->addAction(actionShowConfigureDialog);
view->insertSeparator();
view->addAction(actionCustomActionDialog);

graph = new QMenu(this);
graph->setObjectName("graphMenu");
graph->setCheckable(true);
Expand Down Expand Up @@ -1355,27 +1394,14 @@ void ApplicationWindow::plotMenuAboutToShow()

void ApplicationWindow::customMenu(MdiSubWindow* w)
{
menuBar()->clear();
menuBar()->insertItem(tr("&File"), fileMenu);
myMenuBar()->clear();
myMenuBar()->insertItem(tr("&File"), fileMenu);
fileMenuAboutToShow();
menuBar()->insertItem(tr("&Edit"), edit);
myMenuBar()->insertItem(tr("&Edit"), edit);
editMenuAboutToShow();
menuBar()->insertItem(tr("&View"), view);
myMenuBar()->insertItem(tr("&View"), view);


view->insertSeparator();
view->addAction(actionShowScriptWindow);//Mantid
view->addAction(actionShowScriptInterpreter);
view->insertSeparator();

mantidUI->addMenuItems(view);

view->insertSeparator();
view->addAction(actionToolBars);
view->addAction(actionShowConfigureDialog);
view->insertSeparator();
view->addAction(actionCustomActionDialog);

//#ifdef SCRIPTING_DIALOG
// scriptingMenu->addAction(actionScriptingLang);
//#endif
Expand Down Expand Up @@ -1403,12 +1429,12 @@ void ApplicationWindow::customMenu(MdiSubWindow* w)
actionShowExportASCIIDialog->setEnabled(false);

if (w->isA("MultiLayer")) {
menuBar()->insertItem(tr("&Graph"), graph);
menuBar()->insertItem(tr("&Data"), plotDataMenu);
myMenuBar()->insertItem(tr("&Graph"), graph);
myMenuBar()->insertItem(tr("&Data"), plotDataMenu);
plotDataMenuAboutToShow();
//menuBar()->insertItem(tr("&Analysis"), analysisMenu);
//myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
//analysisMenuAboutToShow();
menuBar()->insertItem(tr("For&mat"), format);
myMenuBar()->insertItem(tr("For&mat"), format);

format->clear();
format->addAction(actionShowPlotDialog);
Expand All @@ -1423,7 +1449,7 @@ void ApplicationWindow::customMenu(MdiSubWindow* w)
} else if (w->isA("Graph3D")) {
disableActions();

menuBar()->insertItem(tr("For&mat"), format);
myMenuBar()->insertItem(tr("For&mat"), format);

actionPrint->setEnabled(true);
actionSaveTemplate->setEnabled(true);
Expand All @@ -1436,19 +1462,19 @@ void ApplicationWindow::customMenu(MdiSubWindow* w)
if (((Graph3D*)w)->coordStyle() == Qwt3D::NOCOORD)
actionShowAxisDialog->setEnabled(false);
} else if (w->inherits("Table")) {
menuBar()->insertItem(tr("&Plot"), plot2DMenu);
menuBar()->insertItem(tr("&Analysis"), analysisMenu);
myMenuBar()->insertItem(tr("&Plot"), plot2DMenu);
myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
analysisMenuAboutToShow();
menuBar()->insertItem(tr("&Table"), tableMenu);
myMenuBar()->insertItem(tr("&Table"), tableMenu);
tableMenuAboutToShow();
actionTableRecalculate->setEnabled(true);

} else if (w->isA("Matrix")){
actionTableRecalculate->setEnabled(true);
menuBar()->insertItem(tr("3D &Plot"), plot3DMenu);
menuBar()->insertItem(tr("&Matrix"), matrixMenu);
myMenuBar()->insertItem(tr("3D &Plot"), plot3DMenu);
myMenuBar()->insertItem(tr("&Matrix"), matrixMenu);
matrixMenuAboutToShow();
menuBar()->insertItem(tr("&Analysis"), analysisMenu);
myMenuBar()->insertItem(tr("&Analysis"), analysisMenu);
analysisMenuAboutToShow();
d_undo_view->setEmptyLabel(w->objectName() + ": " + tr("Empty Stack"));
QUndoStack *stack = ((Matrix *)w)->undoStack();
Expand All @@ -1470,18 +1496,18 @@ void ApplicationWindow::customMenu(MdiSubWindow* w)
} else
disableActions();

menuBar()->insertItem(tr("&Windows"), windowsMenu);
myMenuBar()->insertItem(tr("&Windows"), windowsMenu);
windowsMenuAboutToShow();
// -- Mantid: add script actions, if any exist --
QListIterator<QMenu*> mIter(d_user_menus);
while( mIter.hasNext() )
{
QMenu* item = mIter.next();
menuBar()->insertItem(tr(item->title()), item);
myMenuBar()->insertItem(tr(item->title()), item);

}

menuBar()->insertItem(tr("&Catalog"),icat);
myMenuBar()->insertItem(tr("&Catalog"),icat);

// Interface menu. Build the interface from the user sub windows list.
// Modifications will be done through the ManageCustomMenus dialog and
Expand Down Expand Up @@ -1518,7 +1544,7 @@ void ApplicationWindow::customMenu(MdiSubWindow* w)
}
}

menuBar()->insertItem(tr("&Help"), help );
myMenuBar()->insertItem(tr("&Help"), help );

reloadCustomActions();
}
Expand Down Expand Up @@ -5091,6 +5117,7 @@ void ApplicationWindow::saveSettings()
settings.setValue("/height", d_app_rect.height());
settings.endGroup();

settings.setValue("/SharedMenuBar", m_sharedMenuBar != NULL);
settings.setValue("/AutoSearchUpdates", autoSearchUpdates);
settings.setValue("/Language", appLanguage);
settings.setValue("/ShowWindowsPolicy", show_windows_policy);
Expand Down Expand Up @@ -16755,7 +16782,7 @@ void ApplicationWindow::addUserMenu(const QString & topMenu)
customMenu->setName(topMenu);
connect(customMenu, SIGNAL(triggered(QAction*)), this, SLOT(performCustomAction(QAction*)));
d_user_menus.append(customMenu);
menuBar()->insertItem(tr(topMenu), customMenu);
myMenuBar()->insertItem(tr(topMenu), customMenu);
}

void ApplicationWindow::addUserMenuAction(const QString & parentMenu, const QString & itemName, const QString & itemData)
Expand Down Expand Up @@ -16794,7 +16821,7 @@ void ApplicationWindow::removeUserMenu(const QString & parentMenu)
if( !menu ) return;

d_user_menus.removeAt(i);
menuBar()->removeAction(menu->menuAction());
myMenuBar()->removeAction(menu->menuAction());
}

void ApplicationWindow::removeUserMenuAction(const QString & parentMenu, const QString & userAction)
Expand Down Expand Up @@ -17260,7 +17287,12 @@ void ApplicationWindow::goFloat(MdiSubWindow* w)

// create the outer floating window.
FloatingWindow* fw =new FloatingWindow(this);//, Qt::WindowStaysOnTopHint);
fw->setMenuBar(menuBar());
#ifdef SHARED_MENUBAR
if (m_sharedMenuBar != NULL)
{
fw->setMenuBar(m_sharedMenuBar);
}
#endif
fw->setWindowTitle(w->windowTitle());
fw->setMdiSubWindow(w);
fw->resize(sz);
Expand Down Expand Up @@ -17482,3 +17514,23 @@ void ApplicationWindow::activateNewWindow()
}
}
}

#ifdef SHARED_MENUBAR
/**
* Toggles sharing of the menu bar.
*/
void ApplicationWindow::shareMenuBar(bool yes)
{
if (yes == this->isMenuBarShared()) return;
if (yes)
{
m_sharedMenuBar = new QMenuBar(NULL);
setMenuBar(m_sharedMenuBar);
}
else
{
m_sharedMenuBar = NULL;
}
initMainMenu();
}
#endif
14 changes: 14 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class AssociationsDialog;
class MantidMatrix;
class FloatingWindow;

// On Mac and Ubuntu 11 Unity the menubar must be shared between the main window and other floating windows.
#ifndef Q_OS_WIN32
#define SHARED_MENUBAR
#endif

namespace MantidQt
{
namespace MantidWidgets
Expand Down Expand Up @@ -1032,6 +1037,11 @@ public slots:
void removeFloatingWindow(FloatingWindow* w);
FloatingWindow* getActiveFloating() const;
void showActiveWindowInTitle();
QMenuBar* myMenuBar();
#ifdef SHARED_MENUBAR
bool isMenuBarShared() const {return m_sharedMenuBar != NULL;}
void shareMenuBar(bool yes);
#endif

signals:
void modified();
Expand Down Expand Up @@ -1433,6 +1443,10 @@ public slots:
// To block activating new window when a floating window is in process of resetting flags
bool blockWindowActivation;

#ifdef SHARED_MENUBAR
QMenuBar* m_sharedMenuBar; ///< Pointer to the shared menubar
#endif

public:
MantidUI *mantidUI;
};
Expand Down
16 changes: 15 additions & 1 deletion Code/Mantid/MantidPlot/src/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,15 @@ void ConfigDialog::initAppPage()
boxSearchUpdates->setChecked(app->autoSearchUpdates);
topBoxLayout->addWidget( boxSearchUpdates, 9, 0, 1, 2 );

topBoxLayout->setRowStretch(10, 1);
#ifdef SHARED_MENUBAR
boxSharedMenuBar = new QCheckBox();
boxSharedMenuBar->setChecked(app->isMenuBarShared());
topBoxLayout->addWidget( boxSharedMenuBar, 10, 0, 1, 2 );
topBoxLayout->setRowStretch(11, 1);
#else
boxSharedMenuBar = NULL;
topBoxLayout->setRowStretch(10, 1);
#endif

appTabWidget->addTab(application, QString());

Expand Down Expand Up @@ -1727,6 +1735,9 @@ void ConfigDialog::languageChange()
boxSave->setText(tr("Save every"));
boxBackupProject->setText(tr("&Backup project before saving"));
boxSearchUpdates->setText(tr("Check for new versions at startup"));
#ifdef SHARED_MENUBAR
boxSharedMenuBar->setText(tr("Share menu bar"));
#endif
boxMinutes->setSuffix(tr(" minutes"));
lblScriptingLanguage->setText(tr("Default scripting language"));
lblUndoStackSize->setText(tr("Matrix Undo Stack Size"));
Expand Down Expand Up @@ -1944,6 +1955,9 @@ void ConfigDialog::apply()
setFont(appFont);
app->changeAppStyle(boxStyle->currentText());
app->autoSearchUpdates = boxSearchUpdates->isChecked();
#ifdef SHARED_MENUBAR
app->shareMenuBar(boxSharedMenuBar->isChecked());
#endif
app->setSaveSettings(boxSave->isChecked(), boxMinutes->value());
app->d_backup_files = boxBackupProject->isChecked();
app->defaultScriptingLang = boxScriptingLanguage->currentText();
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ private slots:

QPushButton* buttonAxesFont, *buttonNumbersFont, *buttonLegendFont, *buttonTitleFont, *fontsBtn;
QCheckBox *boxSearchUpdates, *boxOrthogonal, *logBox, *plotLabelBox, *scaleErrorsBox;
QCheckBox *boxSharedMenuBar;
QCheckBox *boxTitle, *boxFrame, *boxPlots3D, *boxPlots2D, *boxTables, *boxNotes, *boxFolders,*boxInstrWindow;
QCheckBox *boxSave, *boxBackbones, *boxShowLegend, *boxSmoothMesh;
QCheckBox *boxAllAxes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,
m_savedialog_dir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory"));

setFocusPolicy(Qt::StrongFocus);
QWidget *frame = new QWidget();
QVBoxLayout* mainLayout = new QVBoxLayout;
//QWidget *frame = new QWidget();
QVBoxLayout* mainLayout = new QVBoxLayout(this);
QSplitter* controlPanelLayout = new QSplitter(Qt::Horizontal);

//Add Tab control panel and Render window
Expand Down Expand Up @@ -116,8 +116,8 @@ InstrumentWindow::InstrumentWindow(const QString& wsName, const QString& label,
connect(mControlsTab,SIGNAL(currentChanged(int)),this,SLOT(tabChanged(int)));

//Set the main frame to the window
frame->setLayout(mainLayout);
setWidget(frame);
//frame->setLayout(mainLayout);
//setWidget(frame);

// Init actions
mInfoAction = new QAction(tr("&Details"), this);
Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <QVBoxLayout>
#include <QMainWindow>

#include <stdexcept>

class QEvent;
class QCloseEvent;
class QString;
Expand Down

0 comments on commit 863eb39

Please sign in to comment.