Skip to content

Commit

Permalink
Re #4282. Almost working on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Dec 22, 2011
1 parent 4cdcf1f commit 3d2abdc
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 88 deletions.
140 changes: 82 additions & 58 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ ApplicationWindow::ApplicationWindow(bool factorySettings)
QCoreApplication::setApplicationName("MantidPlot");
mantidUI = new MantidUI(this);
setAttribute(Qt::WA_DeleteOnClose);
setMenuBar(new QMenuBar(NULL));
init(factorySettings);
}

Expand Down Expand Up @@ -3239,13 +3240,14 @@ void ApplicationWindow::initMatrix(Matrix* m, const QString& caption)
connect(stack, SIGNAL(canUndoChanged(bool)), actionUndo, SLOT(setEnabled(bool)));
connect(stack, SIGNAL(canRedoChanged(bool)), actionRedo, SLOT(setEnabled(bool)));

connect(m, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(modifiedProject(MdiSubWindow*)));
connect(m, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(updateMatrixPlots(MdiSubWindow *)));
connect(m, SIGNAL(resizedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
connect(m, SIGNAL(closedWindow(MdiSubWindow*)), this, SLOT(closeWindow(MdiSubWindow*)));
connect(m, SIGNAL(hiddenWindow(MdiSubWindow*)), this, SLOT(hideWindow(MdiSubWindow*)));
connect(m, SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect(m, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));

//connect(m, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(modifiedProject(MdiSubWindow*)));
//connect(m, SIGNAL(resizedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
//connect(m, SIGNAL(closedWindow(MdiSubWindow*)), this, SLOT(closeWindow(MdiSubWindow*)));
//connect(m, SIGNAL(hiddenWindow(MdiSubWindow*)), this, SLOT(hideWindow(MdiSubWindow*)));
//connect(m, SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
//connect(m, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));

emit modified();
}
Expand Down Expand Up @@ -8336,10 +8338,6 @@ void ApplicationWindow::resizeWindow()
if (!w)
return;

#ifndef MDISUBWINDOW_FLOATABLE
d_workspace->setActiveSubWindow(w); //JZ
#endif

ImageDialog *id = new ImageDialog(this);
id->setAttribute(Qt::WA_DeleteOnClose);
connect (id, SIGNAL(setGeometry(int,int,int,int)), this, SLOT(setWindowGeometry(int,int,int,int)));
Expand Down Expand Up @@ -8370,6 +8368,8 @@ void ApplicationWindow::activateWindow(MdiSubWindow *w)

if (blockWindowActivation) return;

std::cerr << "Activating " << w->windowTitle().toStdString() << std::endl;

if( d_active_window == w ) return;

//FloatingWindow* fw = getActiveFloating();
Expand Down Expand Up @@ -8421,6 +8421,10 @@ void ApplicationWindow::activateWindow(MdiSubWindow *w)
if (f)
f->setActiveWindow(w);

blockWindowActivation = true;
w->parentWidget()->setFocus();
blockWindowActivation = false;

emit modified();
}

Expand Down Expand Up @@ -8521,8 +8525,7 @@ void ApplicationWindow::closeWindow(MdiSubWindow* window)

if (d_active_window == window)
{
std::cerr << "Oops...\n";
d_active_window = NULL;
activateNewWindow();
}
removeWindowFromLists(window);

Expand Down Expand Up @@ -8936,24 +8939,25 @@ void ApplicationWindow::windowsMenuActivated( int id )
MdiSubWindow* w = windows.at( id );
if ( w )
{
QMdiSubWindow* mdi = dynamic_cast<QMdiSubWindow*>(w->parent());
if (mdi)
{
mdi->showNormal();
mdi->setFocus();
if(hidden(w)){
hiddenWindows->takeAt(hiddenWindows->indexOf(w));
setListView(w->objectName(), tr("Normal"));
}
}
else
{// floating window
QMdiSubWindow* mdi = dynamic_cast<QMdiSubWindow*>(d_active_window->parent());
if (mdi)
{
mdi->clearFocus();
}
}
this->activateWindow(w);
//QMdiSubWindow* mdi = dynamic_cast<QMdiSubWindow*>(w->parent());
//if (mdi)
//{
// mdi->showNormal();
// mdi->setFocus();
// if(hidden(w)){
// hiddenWindows->takeAt(hiddenWindows->indexOf(w));
// setListView(w->objectName(), tr("Normal"));
// }
//}
//else
//{// floating window
// QMdiSubWindow* mdi = dynamic_cast<QMdiSubWindow*>(d_active_window->parent());
// if (mdi)
// {
// mdi->clearFocus();
// }
//}
}
}

Expand Down Expand Up @@ -12036,13 +12040,7 @@ void ApplicationWindow::pickDataTool( QAction* action )

void ApplicationWindow::connectSurfacePlot(Graph3D *plot)
{
connect (plot, SIGNAL(showContextMenu()), this,SLOT(showWindowContextMenu()));
connect (plot, SIGNAL(showOptionsDialog()), this,SLOT(showPlot3dDialog()));
connect (plot, SIGNAL(closedWindow(MdiSubWindow*)), this, SLOT(closeWindow(MdiSubWindow*)));
connect (plot, SIGNAL(hiddenWindow(MdiSubWindow*)), this, SLOT(hideWindow(MdiSubWindow*)));
connect (plot, SIGNAL(statusChanged(MdiSubWindow*)), this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect (plot, SIGNAL(modified()), this, SIGNAL(modified()));

plot->askOnCloseEvent(confirmClosePlot3D);
}

Expand All @@ -12053,22 +12051,18 @@ void ApplicationWindow::connectMultilayerPlot(MultiLayer *g)
connect (g,SIGNAL(showScaleDialog(int)), this, SLOT(showScalePageFromAxisDialog(int)));
connect (g,SIGNAL(showAxisDialog(int)), this, SLOT(showAxisPageFromAxisDialog(int)));
connect (g,SIGNAL(showCurveContextMenu(int)), this, SLOT(showCurveContextMenu(int)));
connect (g,SIGNAL(showContextMenu()),this,SLOT(showWindowContextMenu()));
connect (g,SIGNAL(showCurvesDialog()),this,SLOT(showCurvesDialog()));
connect (g,SIGNAL(drawLineEnded(bool)), btnPointer, SLOT(setOn(bool)));
connect (g,SIGNAL(drawTextOff()),this, SLOT(disableAddText()));
connect (g, SIGNAL(showAxisTitleDialog()), this, SLOT(showAxisTitleDialog()));

connect (g,SIGNAL(showMarkerPopupMenu()),this,SLOT(showMarkerPopupMenu()));
connect (g,SIGNAL(closedWindow(MdiSubWindow*)),this, SLOT(closeWindow(MdiSubWindow*)));
connect (g,SIGNAL(hiddenWindow(MdiSubWindow*)),this, SLOT(hideWindow(MdiSubWindow*)));
connect (g,SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect (g,SIGNAL(cursorInfo(const QString&)),info,SLOT(setText(const QString&)));
connect (g,SIGNAL(showImageDialog()),this,SLOT(showImageDialog()));
connect (g,SIGNAL(createTable(const QString&,int,int,const QString&)),
this,SLOT(newTable(const QString&,int,int,const QString&)));
connect (g,SIGNAL(viewTitleDialog()),this,SLOT(showTitleDialog()));
connect (g,SIGNAL(modifiedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
//connect (g,SIGNAL(modifiedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
connect (g,SIGNAL(resizedWindow(MdiSubWindow*)), this, SLOT(repaintWindows()));
connect (g,SIGNAL(modifiedPlot()), this, SLOT(modifiedProject()));
connect (g,SIGNAL(showLineDialog()),this, SLOT(showLineDialog()));
Expand All @@ -12084,14 +12078,9 @@ void ApplicationWindow::connectMultilayerPlot(MultiLayer *g)
void ApplicationWindow::connectTable(Table* w)
{
connect (w->table(), SIGNAL(selectionChanged()), this, SLOT(customColumnActions()));
connect (w,SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect (w,SIGNAL(hiddenWindow(MdiSubWindow*)),this, SLOT(hideWindow(MdiSubWindow*)));
connect (w,SIGNAL(closedWindow(MdiSubWindow*)),this, SLOT(closeWindow(MdiSubWindow*)));
connect (w,SIGNAL(removedCol(const QString&)),this,SLOT(removeCurves(const QString&)));
connect (w,SIGNAL(modifiedData(Table *, const QString&)),
this, SLOT(updateCurves(Table *, const QString&)));
connect (w,SIGNAL(resizedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
connect (w,SIGNAL(modifiedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
connect (w,SIGNAL(optionsDialog()),this,SLOT(showColumnOptionsDialog()));
connect (w,SIGNAL(colValuesDialog()),this,SLOT(showColumnValuesDialog()));
connect (w,SIGNAL(showContextMenu(bool)),this,SLOT(showTableContextMenu(bool)));
Expand Down Expand Up @@ -15331,9 +15320,6 @@ bool ApplicationWindow::changeFolder(Folder *newFolder, bool force)

if (active_window){
d_active_window = active_window;
#ifndef MDISUBWINDOW_FLOATABLE
d_workspace->setActiveSubWindow(active_window); //JZ
#endif
customMenu(active_window);
customToolBars(active_window);
if (active_window_state == MdiSubWindow::Minimized)
Expand Down Expand Up @@ -17216,9 +17202,12 @@ MultiLayer* ApplicationWindow::waterfallPlot(Table *t, const QStringList& list)

QMdiSubWindow* ApplicationWindow::addSubWindowToMdiArea(MdiSubWindow *w, bool show_normal)
{
connect(w, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(modifiedProject(MdiSubWindow*)));
connect(w, SIGNAL(resizedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
connect(w, SIGNAL(closedWindow(MdiSubWindow*)), this, SLOT(closeWindow(MdiSubWindow*)));
connect(w,SIGNAL(hiddenWindow(MdiSubWindow*)),this, SLOT(hideWindow(MdiSubWindow*)));
connect (w,SIGNAL(showContextMenu()),this,SLOT(showWindowContextMenu()));
connect(w, SIGNAL(hiddenWindow(MdiSubWindow*)), this, SLOT(hideWindow(MdiSubWindow*)));
connect(w, SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect(w, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));

QMdiSubWindow* sw = this->d_workspace->addSubWindow(w);
sw->resize(w->size());
Expand Down Expand Up @@ -17271,8 +17260,9 @@ void ApplicationWindow::goFloat(MdiSubWindow* w)
QAction *goMdi = new QAction("MDI",this);
connect(goMdi,SIGNAL(triggered()),w,SLOT(goMdi()));

// create the outer floating window. It is not a child of ApplicationWindow.
// create the outer floating window.
FloatingWindow* fw =new FloatingWindow(this);//, Qt::WindowStaysOnTopHint);
fw->setWindowTitle(w->windowTitle());
fw->setWidget(w);
fw->resize(sz);
fw->move(p);
Expand Down Expand Up @@ -17349,6 +17339,7 @@ void ApplicationWindow::removeFloatingWindow(FloatingWindow* w)
if (m_floatingWindows.contains(w))
{
m_floatingWindows.remove(w);
closeWindow(static_cast<MdiSubWindow*>(w->widget()));
}
}

Expand Down Expand Up @@ -17378,8 +17369,8 @@ bool ApplicationWindow::eventFilter(QObject *obj, QEvent *evt)
*/
FloatingWindow* ApplicationWindow::getActiveFloating() const
{
if (!d_active_window || !d_active_window->parent()) return NULL;
return dynamic_cast<FloatingWindow*>(d_active_window->parent()->parent());
if (!d_active_window) return NULL;
return d_active_window->getFloatingWindow();
}

bool ApplicationWindow::event(QEvent * e)
Expand Down Expand Up @@ -17422,10 +17413,6 @@ bool ApplicationWindow::event(QEvent * e)
}
activateWindow(sw);
}
else
{
activateWindow(NULL);
}
}
}
return QMainWindow::event(e);
Expand Down Expand Up @@ -17456,5 +17443,42 @@ void ApplicationWindow::showActiveWindowInTitle()
QString title = d_active_window->name();
this->setWindowTitle(title);
}
else
{
this->setWindowTitle("No active window");
}
}

/**
* Activate a subwindow (docked or floating) other than current active one.
* This is required when the current window is closing.
*/
void ApplicationWindow::activateNewWindow()
{
MdiSubWindow* current = d_active_window;
d_active_window = NULL;

// try the docked windows first
QList<QMdiSubWindow*> wl = d_workspace->subWindowList();
foreach(QMdiSubWindow* w,wl)
{
if (w->widget() != static_cast<QWidget*>(current))
{
d_active_window = dynamic_cast<MdiSubWindow*>(w->widget());
if (d_active_window) break;
}
}

// if unsuccessful try the floating windows
if (!d_active_window)
{
foreach(FloatingWindow* w, m_floatingWindows)
{
if (w->widget() != static_cast<QWidget*>(current))
{
d_active_window = dynamic_cast<MdiSubWindow*>(w->widget());
if (d_active_window) break;
}
}
}
}
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,9 @@ 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();

void mdiWindowActivated(MdiSubWindow* w);
void goFloat(MdiSubWindow* w);
void goMdi(FloatingWindow* w);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ 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;
QSplitter* controlPanelLayout = new QSplitter(Qt::Horizontal);
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
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
11 changes: 0 additions & 11 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,6 @@ 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()->addSubWindowToMdiArea(w,makeVisible);
return w;
}
Expand Down Expand Up @@ -1808,13 +1801,9 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)

insWin->selectTab(tab);

//appWindow()->d_workspace->addSubWindow(insWin);
appWindow()->addSubWindowToMdiArea(insWin);
appWindow()->addListViewItem(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
13 changes: 13 additions & 0 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,18 @@ void MdiSubWindow::goMdi()
//d_app->goMdi(this);
}

FloatingWindow* MdiSubWindow::getFloatingWindow() const
{
if (!parent()) return NULL;
return dynamic_cast<FloatingWindow*>(parent());
}

QMdiSubWindow* MdiSubWindow::getDockedWindow() const
{
if (!parent()) return NULL;
return dynamic_cast<QMdiSubWindow*>(parent());
}


/*----------- FloatingWindow ---------*/

Expand Down Expand Up @@ -425,3 +437,4 @@ void FloatingWindow::removeStaysOnTopFlag()
show();
}
}

0 comments on commit 3d2abdc

Please sign in to comment.