Skip to content

Commit

Permalink
Re #8909. Added TiledWindow window class
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Apr 7, 2014
1 parent 1420469 commit 29a0c88
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 22 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/MantidPlot/CMakeLists.txt
Expand Up @@ -125,6 +125,7 @@ set ( QTIPLOT_SRCS src/ApplicationWindow.cpp
src/TextDialog.cpp
src/TextEditor.cpp
src/TextFileIO.cpp
src/TiledWindow.cpp
src/TitlePicker.cpp
src/TranslateCurveTool.cpp
src/UserFunction.cpp
Expand Down Expand Up @@ -366,6 +367,7 @@ set ( QTIPLOT_HDRS src/ApplicationWindow.h
src/TextDialog.h
src/TextEditor.h
src/TextFileIO.h
src/TiledWindow.h
src/TitlePicker.h
src/TranslateCurveTool.h
src/UserFunction.h
Expand Down Expand Up @@ -646,6 +648,7 @@ set ( QTIPLOT_MOC_FILES src/ApplicationWindow.h
src/TableStatistics.h
src/TextDialog.h
src/TextEditor.h
src/TiledWindow.h
src/TitlePicker.h
src/TranslateCurveTool.h
src/lib/include/CollapsiveGroupBox.h
Expand Down
14 changes: 14 additions & 0 deletions Code/Mantid/MantidPlot/mantidplot.py
Expand Up @@ -169,6 +169,20 @@ def newNote(name=None):
else:
return new_proxy(proxies.MDIWindow, _qti.app.newNote, name)

def newTiledWindow(name=None):
"""Create an empty tiled window.
Args:
name: The name to give to the window (if None, a unique name will be generated).
Returns:
A handle to the created window.
"""
if name is None:
return new_proxy(proxies.TiledWindowProxy, _qti.app.newTiledWindow)
else:
return new_proxy(proxies.TiledWindowProxy, _qti.app.newTiledWindow, name)

#-----------------------------------------------------------------------------
# Intercept qtiplot "plot" command and forward to plotSpectrum for a workspace
def plot(source, *args, **kwargs):
Expand Down
20 changes: 20 additions & 0 deletions Code/Mantid/MantidPlot/mantidplotpy/proxies.py
Expand Up @@ -825,3 +825,23 @@ def __init__(self, toproxy):
QtProxyObject.__init__(self,toproxy)


#-----------------------------------------------------------------------------
class TiledWindowProxy(QtProxyObject):
"""
Proxy for the TiledWindow object.
"""
def __init__(self, toproxy):
QtProxyObject.__init__(self,toproxy)

def addTile(self, tile, row, col):
"""
Add a new sub-window at a given position in the layout.
The layout will re-shape itself if necessary to fit in the new tile.
Args:
tile :: An MdiSubWindow to add.
row :: A row index at which to place the new tile.
col :: A column index at which to place the new tile.
"""
threadsafe_call(self._getHeldObject().addTile, tile._getHeldObject(), row, col)
144 changes: 126 additions & 18 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Expand Up @@ -111,6 +111,7 @@
#include "MdiSubWindow.h"
#include "FloatingWindow.h"
#include "DataPickerTool.h"
#include "TiledWindow.h"

// TODO: move tool-specific code to an extension manager
#include "ScreenPickerTool.h"
Expand Down Expand Up @@ -9213,6 +9214,7 @@ void ApplicationWindow::fileMenuAboutToShow()
newMenu->addAction(actionNewGraph);
newMenu->addAction(actionNewFunctionPlot);
newMenu->addAction(actionNewSurfacePlot);
newMenu->addAction(actionNewTiledWindow);


openMenu=fileMenu->addMenu(tr("&Load"));
Expand Down Expand Up @@ -9706,6 +9708,7 @@ void ApplicationWindow::showListViewPopupMenu(const QPoint &p)
window.addAction(actionNewGraph);
window.addAction(actionNewFunctionPlot);
window.addAction(actionNewSurfacePlot);
window.addAction(actionNewTiledWindow);
cm.insertItem(tr("New &Window"), &window);

cm.insertItem(getQPixmap("newfolder_xpm"), tr("New F&older"), this, SLOT(addFolder()), Qt::Key_F7);
Expand Down Expand Up @@ -12664,6 +12667,10 @@ void ApplicationWindow::createActions()
actionNewTable->setShortcut( tr("Ctrl+T") );
connect(actionNewTable, SIGNAL(activated()), this, SLOT(newTable()));

actionNewTiledWindow = new QAction(QIcon(getQPixmap("table_xpm")), tr("New Tiled &Window"), this);
actionNewTiledWindow->setShortcut( tr("Ctrl+W") );
connect(actionNewTiledWindow, SIGNAL(activated()), this, SLOT(newTiledWindow()));

actionNewMatrix = new QAction(QIcon(getQPixmap("new_matrix_xpm")), tr("New &Matrix"), this);
actionNewMatrix->setShortcut( tr("Ctrl+M") );
connect(actionNewMatrix, SIGNAL(activated()), this, SLOT(newMatrix()));
Expand Down Expand Up @@ -13490,6 +13497,10 @@ void ApplicationWindow::translateActionsStrings()
actionNewTable->setShortcut(tr("Ctrl+T"));
actionNewTable->setToolTip(tr("New table"));

actionNewTiledWindow->setMenuText(tr("New Tiled &Window"));
actionNewTiledWindow->setShortcut(tr("Ctrl+W"));
actionNewTiledWindow->setToolTip(tr("New tiled window"));

actionNewMatrix->setMenuText(tr("New &Matrix"));
actionNewMatrix->setShortcut(tr("Ctrl+M"));
actionNewMatrix->setToolTip(tr("New matrix"));
Expand Down Expand Up @@ -15292,6 +15303,7 @@ void ApplicationWindow::showFolderPopupMenu(Q3ListViewItem *it, const QPoint &p,
window.addAction(actionNewGraph);
window.addAction(actionNewFunctionPlot);
window.addAction(actionNewSurfacePlot);
window.addAction(actionNewTiledWindow);
cm.insertItem(tr("New &Window"), &window);
}

Expand Down Expand Up @@ -17575,15 +17587,55 @@ MultiLayer* ApplicationWindow::waterfallPlot(Table *t, const QStringList& list)
* regardless of what isDefalutFloating() returns.
*/
void ApplicationWindow::addMdiSubWindow(MdiSubWindow *w, bool showNormal)
{
//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(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
//connect(w, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));
//connect(w, SIGNAL(detachFromParent(MdiSubWindow*)),this, SLOT(detachMdiSubwindow(MdiSubWindow*)));

//bool showFloating = isDefaultFloating(w);

//if (showFloating && showNormal)
//{
// addMdiSubWindowAsFloating(w);
//}
//else
//{
// QMdiSubWindow* sw = addMdiSubWindowAsDocked(w);
// if (showNormal)
// {
// sw->showNormal();
// }
// else
// {
// sw->showMinimized();
// }
//}

//addListViewItem(w);
//currentFolder()->addWindow(w);
addMdiSubWindow(w, isDefaultFloating(w), showNormal);
}

/**
* Add a sub-window either as a docked or a floating window.
* @param w :: Pointer to a MdiSubWindow which to add.
* @param showFloating :: If true show as floating else make it docked.
* @param showNormal :: If true show as a normal window, if false show as a minimized docked window
* regardless of what showFloating is.
*/
void ApplicationWindow::addMdiSubWindow(MdiSubWindow *w, bool showFloating, bool showNormal)
{
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(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect(w, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));

bool showFloating = isDefaultFloating(w);
connect(w, SIGNAL(detachFromParent(MdiSubWindow*)),this, SLOT(detachMdiSubwindow(MdiSubWindow*)));

if (showFloating && showNormal)
{
Expand Down Expand Up @@ -17723,18 +17775,21 @@ QMdiSubWindow* ApplicationWindow::addMdiSubWindowAsDocked(MdiSubWindow* w, QPoin
*/
void ApplicationWindow::changeToFloating(MdiSubWindow* w)
{
if ( w->isFloating() ) return;
QMdiSubWindow* sw =w->getDockedWindow();
if (!sw)
if ( sw )
{
return;
// remove the subwindow from the mdi area
d_workspace->removeSubWindow(w);
sw->close();
// create the outer floating window.
addMdiSubWindowAsFloating(w,sw->pos());
}
else
{
// attach w to the ApplicationWindow and create the outer floating window (second argument == true)
addMdiSubWindow(w,true,true);
}

// remove the subwindow from the mdi area
d_workspace->removeSubWindow(w);
sw->close();

// create the outer floating window.
addMdiSubWindowAsFloating(w,sw->pos());
activateWindow(w);
}

Expand All @@ -17743,14 +17798,22 @@ void ApplicationWindow::changeToFloating(MdiSubWindow* w)
*/
void ApplicationWindow::changeToDocked(MdiSubWindow* w)
{
if ( w->isDocked() ) return;
FloatingWindow* fw = w->getFloatingWindow();
if (!fw) return;
fw->removeMdiSubWindow();
removeFloatingWindow(fw);
// main window must be closed or application will freeze
fw->close();
addMdiSubWindowAsDocked(w);
//activateWindow(w);
if ( fw )
{
fw->removeMdiSubWindow();
removeFloatingWindow(fw);
// main window must be closed or application will freeze
fw->close();
// create the outer docked window.
addMdiSubWindowAsDocked(w);
}
else
{
// attach w to the ApplicationWindow and create the outer docked window (second argument == false)
addMdiSubWindow(w,false,true);
}
w->setNormal();
return;
}
Expand Down Expand Up @@ -17784,6 +17847,41 @@ FloatingWindow* ApplicationWindow::getActiveFloating() const
return w->getFloatingWindow();
}

/**
* Detach a subwindow from its parent - docked or floating
*/
void ApplicationWindow::detachMdiSubwindow(MdiSubWindow* w)
{
// remove the window from all internal lists
if ( currentFolder()->hasWindow(w) )
{
currentFolder()->removeWindow(w);
}
removeWindowFromLists(w);
Q3ListViewItem *it=lv->findItem (w->objectName(), 0, Q3ListView::ExactMatch|Q3ListView::CaseSensitive);
if (it)
lv->takeItem(it);

// if it's wrapped in a floating detach from it and close
FloatingWindow *fw = w->getFloatingWindow();
if ( fw )
{
fw->removeMdiSubWindow();
m_floatingWindows.remove(fw);
fw->deleteLater();
return;
}

// the same in docked case
QMdiSubWindow *dw = w->getDockedWindow();
if ( dw )
{
d_workspace->removeSubWindow(w);
dw->close();
}

}

/**
* Filter out the WindowActivate event and set the active subwindow correctly.
* @param e :: An event.
Expand Down Expand Up @@ -17994,3 +18092,13 @@ void ApplicationWindow::about2Start(){
mantidUI->executeAlgorithmAsync(update_script_repo);
}
}

/**
* Create a new TiledWindow with default settings.
*/
TiledWindow *ApplicationWindow::newTiledWindow()
{
TiledWindow *widget = new TiledWindow(this,"",generateUniqueName("TiledWindow"));
addMdiSubWindow( widget );
return widget;
}
10 changes: 10 additions & 0 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Expand Up @@ -91,6 +91,7 @@ class AssociationsDialog;
class MantidMatrix;
class FloatingWindow;
class MantidTable;
class TiledWindow;

// On Mac (and Ubuntu 11 Unity) the menubar must be shared between the main window and other floating windows.
#ifdef Q_OS_MAC
Expand Down Expand Up @@ -194,6 +195,7 @@ class ApplicationWindow: public QMainWindow, public Scripted

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

int matrixUndoStackSize(){return d_matrix_undo_stack_size;};
void setMatrixUndoStackSize(int size);
Expand Down Expand Up @@ -1046,6 +1048,8 @@ public slots:
void changeActiveToDocked();
/// Validate sub-window position coordinates
void validateWindowPos(MdiSubWindow* w, int& x, int& y);
/// Detach a subwindow from its parent - docked or floating
void detachMdiSubwindow(MdiSubWindow* w);

/** Sets whether to prompt the user when closing/deleting a folder */
void setConfirmFolderClose(bool value)
Expand All @@ -1056,6 +1060,11 @@ public slots:
/// Show/hide MantidPlot toolbars.
void setToolbarsVisible(bool visible);

/// \name Tiled widget
//@{
TiledWindow *newTiledWindow();
//@}

signals:
void modified();
void shutting_down();
Expand Down Expand Up @@ -1465,6 +1474,7 @@ public slots:
QActionGroup *coord, *floorstyle, *grids, *plotstyle, *dataTools;
QAction *actionPanPlot;
QAction *actionWaterfallPlot;
QAction *actionNewTiledWindow;

QList<QAction *> d_user_actions;
QList<QMenu* > d_user_menus; //Mantid
Expand Down
14 changes: 10 additions & 4 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.cpp
Expand Up @@ -59,6 +59,7 @@ MdiSubWindow::MdiSubWindow(QWidget *parent, const QString& label, const QString&
d_min_restore_size(QSize())
{
setObjectName(name);
setName(name);
setAttribute(Qt::WA_DeleteOnClose);
setLocale(parent->locale());
confirmClose(false);
Expand Down Expand Up @@ -182,7 +183,7 @@ void MdiSubWindow::move(const QPoint& pos)
*/
void MdiSubWindow::undock()
{
if(isDocked()) emit undockFromMDIArea(this);
if( !isFloating() ) emit undockFromMDIArea(this);
}

/**
Expand All @@ -197,7 +198,7 @@ bool MdiSubWindow::isFloating() const
*/
void MdiSubWindow::dock()
{
if(isFloating()) emit dockToMDIArea(this);
if( !isDocked() ) emit dockToMDIArea(this);
}

/**
Expand All @@ -208,6 +209,13 @@ bool MdiSubWindow::isDocked() const
return (this->getDockedWindow() != NULL);
}

/**
*/
void MdiSubWindow::detach()
{
emit detachFromParent(this);
}

/**
* Handle the close event.
* @param e :: A QCloseEvent event.
Expand Down Expand Up @@ -536,5 +544,3 @@ AppMdiSubWindow::AppMdiSubWindow(QWidget *parent, const QString& label, const QS
{
}



0 comments on commit 29a0c88

Please sign in to comment.