Skip to content

Commit

Permalink
Re #4282. Merging floatable_windows into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 5, 2012
2 parents a56f53d + 6a4893c commit 4c24958
Show file tree
Hide file tree
Showing 16 changed files with 846 additions and 200 deletions.
543 changes: 415 additions & 128 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp

Large diffs are not rendered by default.

42 changes: 41 additions & 1 deletion Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Description : QtiPlot's main window
#include <QBuffer>
#include <QLocale>
#include <QSet>
#include <QSettings>
#include "Table.h"
#include "ScriptingEnv.h"
#include "Scripted.h"
Expand Down Expand Up @@ -86,7 +87,12 @@ class ImageMarker;
class TextEditor;
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.
#ifdef Q_OS_MAC
#define SHARED_MENUBAR
#endif

namespace MantidQt
{
Expand Down Expand Up @@ -180,6 +186,7 @@ class ApplicationWindow: public QMainWindow, public Scripted
QList<QToolBar *> toolBarsList();

MdiSubWindow *activeWindow(WindowType type = NoWindow);
void addMdiSubWindow(MdiSubWindow *w, bool showNormal = true);

int matrixUndoStackSize(){return d_matrix_undo_stack_size;};
void setMatrixUndoStackSize(int size);
Expand Down Expand Up @@ -1024,10 +1031,32 @@ public slots:
/// slot to execute download datafiles algorithm - called from ICat interface
void executeDownloadDataFiles(const std::vector<std::string>&,const std::vector<int64_t>&);

/// Activate a subwindow (docked or floating) other than current active one
void activateNewWindow();

FloatingWindow* addMdiSubWindowAsFloating(MdiSubWindow* w, QPoint pos = QPoint(0,0));
QMdiSubWindow* addMdiSubWindowAsDocked(MdiSubWindow* w);
void mdiWindowActivated(MdiSubWindow* w);
void changeToFloating(MdiSubWindow* w);
void changeToDocked(MdiSubWindow* w);
void removeFloatingWindow(FloatingWindow* w);
FloatingWindow* getActiveFloating() const;
QMenuBar* myMenuBar();
#ifdef SHARED_MENUBAR
bool isMenuBarShared() const {return m_sharedMenuBar != NULL;}
void shareMenuBar(bool yes);
#endif
void changeActiveToFloating();
void changeActiveToDocked();

signals:
void modified();
void resultsContextMenu();
void shutting_down();
//void changeToMDI(MdiSubWindow*);

protected:
virtual bool event(QEvent * e);

private:
virtual QMenu * createPopupMenu(){return NULL;};
Expand All @@ -1042,6 +1071,7 @@ public slots:
void openInstrumentWindow(const QStringList &list);
/// this method saves the data on project save
void savedatainNexusFormat(const std::string& wsName,const std::string & fileName);
void updateOnTopFlags();


private slots:
Expand Down Expand Up @@ -1414,10 +1444,20 @@ public slots:
/// Store a list of environments that cannot be used
QSet<QString> m_bad_script_envs;

// Floating windows
QList<FloatingWindow*> m_floatingWindows;
// 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

/// Exit code to set at application end
int m_exitCode;

public:
MantidUI *mantidUI;
QSettings settings;
};
#endif
#endif
62 changes: 61 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 @@ -590,6 +598,44 @@ void ConfigDialog::initAppPage()

initFileLocationsPage();

// Floating windows page
floatingWindowsPage = new QWidget();
QVBoxLayout *floatLayout = new QVBoxLayout(floatingWindowsPage);
QGroupBox *floatBox = new QGroupBox();
floatLayout->addWidget(floatBox);
QGridLayout *floatPageLayout = new QGridLayout(floatBox);

QLabel* comment = new QLabel("Select types of windows to be floating by default.\n"
"You can use Windows menu to make a window floating or docked.");
floatPageLayout->addWidget(comment,0,0);

boxFloatingGraph = new QCheckBox("Graphs");
boxFloatingGraph->setChecked(app->settings.value("/General/FloatingWindows/MultiLayer",false).toBool());
floatPageLayout->addWidget(boxFloatingGraph,1,0);

boxFloatingTable = new QCheckBox("Tables");
boxFloatingTable->setChecked(app->settings.value("/General/FloatingWindows/Table",false).toBool());
floatPageLayout->addWidget(boxFloatingTable,2,0);

boxFloatingInstrumentWindow = new QCheckBox("Instrument views");
boxFloatingInstrumentWindow->setChecked(app->settings.value("/General/FloatingWindows/InstrumentWindow",false).toBool());
floatPageLayout->addWidget(boxFloatingInstrumentWindow,3,0);

boxFloatingMantidMatrix = new QCheckBox("Mantid Matrices");
boxFloatingMantidMatrix->setChecked(app->settings.value("/General/FloatingWindows/MantidMatrix",false).toBool());
floatPageLayout->addWidget(boxFloatingMantidMatrix,4,0);

boxFloatingNote = new QCheckBox("Notes");
boxFloatingNote->setChecked(app->settings.value("/General/FloatingWindows/Note",false).toBool());
floatPageLayout->addWidget(boxFloatingNote,5,0);

boxFloatingMatrix = new QCheckBox("Matrices");
boxFloatingMatrix->setChecked(app->settings.value("/General/FloatingWindows/Matrix",false).toBool());
floatPageLayout->addWidget(boxFloatingMatrix,6,0);

floatPageLayout->setRowStretch(7,1);
appTabWidget->addTab(floatingWindowsPage, QString());

connect( boxLanguage, SIGNAL( activated(int) ), this, SLOT( switchToLanguage(int) ) );
connect( fontsBtn, SIGNAL( clicked() ), this, SLOT( pickApplicationFont() ) );
connect( boxSave, SIGNAL( toggled(bool) ), boxMinutes, SLOT( setEnabled(bool) ) );
Expand Down Expand Up @@ -1713,6 +1759,7 @@ void ConfigDialog::languageChange()
appTabWidget->setTabText(appTabWidget->indexOf(appColors), tr("Colors"));
appTabWidget->setTabText(appTabWidget->indexOf(numericFormatPage), tr("Numeric Format"));
appTabWidget->setTabText(appTabWidget->indexOf(fileLocationsPage), tr("File Locations"));
appTabWidget->setTabText(appTabWidget->indexOf(floatingWindowsPage), tr("Floating windows"));

//Mantid Page
mtdTabWidget->setTabText(mtdTabWidget->indexOf(instrumentPage), tr("Instrument"));
Expand All @@ -1727,6 +1774,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 +1994,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 Expand Up @@ -1997,6 +2050,13 @@ void ConfigDialog::apply()
boxNotes->isChecked(),boxInstrWindow->isChecked());
// general page: colors tab
app->setAppColors(btnWorkspace->color(), btnPanels->color(), btnPanelsText->color());
// general page: floating windows tab
app->settings.setValue("/General/FloatingWindows/MultiLayer",boxFloatingGraph->isChecked());
app->settings.setValue("/General/FloatingWindows/Table",boxFloatingTable->isChecked());
app->settings.setValue("/General/FloatingWindows/InstrumentWindow",boxFloatingInstrumentWindow->isChecked());
app->settings.setValue("/General/FloatingWindows/MantidMatrix",boxFloatingMantidMatrix->isChecked());
app->settings.setValue("/General/FloatingWindows/Note",boxFloatingNote->isChecked());
app->settings.setValue("/General/FloatingWindows/Matrix",boxFloatingMatrix->isChecked());
// 3D plots page
QStringList plot3DColors = QStringList() << btnToColor->color().name() << btnLabels->color().name();
plot3DColors << btnMesh->color().name() << btnGrid->color().name() << btnFromColor->color().name();
Expand Down
4 changes: 3 additions & 1 deletion Code/Mantid/MantidPlot/src/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private slots:
QPushButton* buttonTextFont, *buttonHeaderFont;
QStackedWidget * generalDialog;
QWidget *appColors, *tables, *plotOptions, *plotAxes, *plotTicks, *plotFonts, *confirm, *plotPrint;
QWidget *application, *curves, *plots3D, *fitPage, *numericFormatPage;
QWidget *application, *curves, *plots3D, *fitPage, *numericFormatPage, *floatingWindowsPage;
//Mantid
QWidget *instrumentPage;
QComboBox *facility;
Expand Down Expand Up @@ -207,13 +207,15 @@ 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;
QLabel *lblXLogLin, *lblYLogLin, *lblZLogLin;
QComboBox *cbXLog, *cbYLog, *cbZLog;
QCheckBox *boxAutoscaling, *boxShowProjection, *boxMatrices, *boxScaleFonts, *boxResize, *boxAspectRatio;
QComboBox *boxMajTicks, *boxMinTicks, *boxStyle, *boxCurveStyle, *boxSeparator, *boxLanguage, *boxDecimalSeparator;
QCheckBox *boxFloatingGraph, *boxFloatingTable, *boxFloatingInstrumentWindow, *boxFloatingMantidMatrix, *boxFloatingNote, *boxFloatingMatrix;
QSpinBox *boxMinutes, *boxLineWidth, *boxFrameWidth, *boxResolution, *boxMargin, *boxPrecision, *boxAppPrecision;
QSpinBox *boxSymbolSize, *boxMinTicksLength, *boxMajTicksLength, *generatePointsBox;
DoubleSpinBox *boxCurveLineWidth;
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/Graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Graph::Graph(int x, int y, int width, int height, QWidget* parent, Qt::WFlags f)
c_keys = QVector<int>();

setFocusPolicy(Qt::StrongFocus);
setFocusProxy(d_plot);
//setFocusProxy(d_plot);
setMouseTracking(true );


Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/Graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class Graph: public QWidget

//! Returns a pointer to the parent MultiLayer object.
MultiLayer *multiLayer(){return (MultiLayer *) this->parent()->parent()->parent();};
//MultiLayer *multiLayer(){return (MultiLayer *)(this->parent()->parent());};

//! Change the active tool, deleting the old one if it exists.
void setActiveTool(PlotToolInterface *tool);
Expand Down Expand Up @@ -874,4 +875,4 @@ public slots:
boost::shared_ptr<Mantid::Kernel::Unit> m_yUnits;

};
#endif // GRAPH_H
#endif // GRAPH_H
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +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);
setFocus();
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 @@ -117,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 Expand Up @@ -743,8 +742,9 @@ QString InstrumentWindow::saveToString(const QString& geometry, bool saveAsTempl
/**
* Called just before a show event
*/
void InstrumentWindow::showEvent(QShowEvent*)
void InstrumentWindow::showEvent(QShowEvent* e)
{
MdiSubWindow::showEvent(e);
//updateWindow();
}

Expand Down Expand Up @@ -1154,7 +1154,7 @@ bool InstrumentWindow::eventFilter(QObject *obj, QEvent *ev)
m_instrumentDisplayContextMenuOn = false;
return true;
}
return false;
return MdiSubWindow::eventFilter(obj,ev);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <QPainter>
#include <QList>
#include <cmath>
#include <algorithm>

QList<PeakMarker2D::Style> PeakOverlay::g_defaultStyles;

Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/Mantid/MantidMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ bool MantidMatrix::eventFilter(QObject *object, QEvent *e)
{
// if it's context menu on any of the views
if (e->type() == QEvent::ContextMenu && (object == m_table_viewY || object == m_table_viewX || object == m_table_viewE)){
e->accept();
emit showContextMenu();
return true;
}
Expand Down
32 changes: 8 additions & 24 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,13 @@ bool MantidUI::menuAboutToShow(MdiSubWindow *w)

if (w && w->isA("MantidMatrix"))
{
appWindow()->menuBar()->insertItem(tr("3D &Plot"), appWindow()->plot3DMenu);
appWindow()->myMenuBar()->insertItem(tr("3D &Plot"), appWindow()->plot3DMenu);
appWindow()->actionCopySelection->setEnabled(true);
appWindow()->actionPasteSelection->setEnabled(false);
appWindow()->actionClearSelection->setEnabled(false);
appWindow()->plotMatrixBar->setEnabled (true);

appWindow()->menuBar()->insertItem(tr("&Workspace"),menuMantidMatrix);
appWindow()->myMenuBar()->insertItem(tr("&Workspace"),menuMantidMatrix);
return true;
}

Expand Down Expand Up @@ -428,13 +428,7 @@ MantidMatrix* MantidUI::importMatrixWorkspace(const QString& wsName, int lower,
}
if ( !w ) return 0;

connect(w, SIGNAL(closedWindow(MdiSubWindow*)), appWindow(), SLOT(closeWindow(MdiSubWindow*)));
connect(w,SIGNAL(hiddenWindow(MdiSubWindow*)),appWindow(), SLOT(hideWindow(MdiSubWindow*)));
connect (w,SIGNAL(showContextMenu()),appWindow(),SLOT(showWindowContextMenu()));

appWindow()->d_workspace->addSubWindow(w);
if( makeVisible ) w->showNormal();
else w->showMinimized();
appWindow()->addMdiSubWindow(w,makeVisible);
return w;
}

Expand All @@ -447,10 +441,9 @@ void MantidUI::importWorkspace(const QString& wsName, bool showDlg, bool makeVis
{
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
MantidMatrix* mm = importMatrixWorkspace(wsName,-1, -1, showDlg,makeVisible);
appWindow()->addListViewItem(mm);
if (!mm)
{Table * t=importTableWorkspace(wsName,showDlg,makeVisible);
appWindow()->addListViewItem(t);
{
Table * t=importTableWorkspace(wsName,showDlg,makeVisible);
}
QApplication::restoreOverrideCursor();
}
Expand All @@ -474,7 +467,6 @@ void MantidUI::importTransposed()
{
ws = boost::dynamic_pointer_cast<ITableWorkspace>(AnalysisDataService::Instance().retrieve(wsName.toStdString()));
Table *t = importTableWorkspace(wsName,true,true,true);
appWindow()->addListViewItem(t);
}
QApplication::restoreOverrideCursor();
}
Expand Down Expand Up @@ -1818,12 +1810,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)

insWin->selectTab(tab);

appWindow()->d_workspace->addSubWindow(insWin);
appWindow()->addListViewItem(insWin);
appWindow()->addMdiSubWindow(insWin);

connect(insWin, SIGNAL(closedWindow(MdiSubWindow*)), appWindow(), SLOT(closeWindow(MdiSubWindow*)));
connect(insWin,SIGNAL(hiddenWindow(MdiSubWindow*)), appWindow(), SLOT(hideWindow(MdiSubWindow*)));
connect (insWin,SIGNAL(showContextMenu()), appWindow(),SLOT(showWindowContextMenu()));
connect(insWin,SIGNAL(plotSpectra(const QString&,const std::set<int>&)),this,
SLOT(plotSpectraList(const QString&,const std::set<int>&)));
connect(insWin,SIGNAL(createDetectorTable(const QString&,const std::vector<int>&,bool)),this,
Expand Down Expand Up @@ -1880,7 +1868,7 @@ void MantidUI::mantidMenuAboutToShow()

void MantidUI::insertMenu()
{
appWindow()->menuBar()->insertItem(tr("Man&tid"), mantidMenu);
appWindow()->myMenuBar()->insertItem(tr("Man&tid"), mantidMenu);
}

void MantidUI::clearAllMemory()
Expand Down Expand Up @@ -3213,12 +3201,8 @@ MantidMatrix* MantidUI::openMatrixWorkspace(ApplicationWindow* parent,const QStr
w = new MantidMatrix(ws, appWindow(), "Mantid",wsName, lower, upper);
if ( !w ) return 0;

connect(w, SIGNAL(closedWindow(MdiSubWindow*)), appWindow(), SLOT(closeWindow(MdiSubWindow*)));
connect(w,SIGNAL(hiddenWindow(MdiSubWindow*)),appWindow(), SLOT(hideWindow(MdiSubWindow*)));
connect (w,SIGNAL(showContextMenu()),appWindow(),SLOT(showWindowContextMenu()));
appWindow()->addMdiSubWindow(w);

appWindow()->d_workspace->addSubWindow(w);
w->showNormal();
return w;
}

Expand Down

0 comments on commit 4c24958

Please sign in to comment.