Skip to content

Commit

Permalink
Re #4282. MdiSubWindow passes closeEvent to its inner widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Jan 9, 2012
1 parent 84abd6b commit fbd451f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
26 changes: 21 additions & 5 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,16 @@ void MdiSubWindow::closeEvent( QCloseEvent *e )
tr("Do you want to hide or delete") + "<p><b>'" + objectName() + "'</b> ?",
tr("Delete"), tr("Hide"), tr("Cancel"), 0, 2)){
case 0:
emit closedWindow(this);
e->accept();
if (widget()->close())
{
e->accept();
emit closedWindow(this);
}
else
{
QMessageBox::critical(parentWidget(),"MantidPlot - Error", "Window cannot be closed");
e->ignore();
}
break;

case 1:
Expand All @@ -170,8 +178,16 @@ void MdiSubWindow::closeEvent( QCloseEvent *e )
break;
}
} else {
emit closedWindow(this);
e->accept();
if (widget()->close())
{
e->accept();
emit closedWindow(this);
}
else
{
QMessageBox::critical(parentWidget(),"MantidPlot - Error", "Window cannot be closed");
e->ignore();
}
}
}

Expand Down Expand Up @@ -447,8 +463,8 @@ QWidget* MdiSubWindow::getWrapperWindow() const
* Constructor.
*/
FloatingWindow::FloatingWindow(ApplicationWindow* appWindow, Qt::WindowFlags f):
//QMainWindow(NULL,f),
QMainWindow(appWindow,f),
//MdiSubWindowParent_t(appWindow,f | Qt::Window),
d_app(appWindow)
{
setFocusPolicy(Qt::StrongFocus);
Expand Down
12 changes: 12 additions & 0 deletions Code/Mantid/MantidPlot/src/MdiSubWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,30 @@ class MdiSubWindowParent_t: public QWidget
{
if (w == NULL)
{// removing widget
if (m_widget)
{
m_widget->setParent(NULL); // I am not sure about this
}
m_widget = NULL;
return;
}

// widget cannot be replaced
if (m_widget)
{
throw std::runtime_error("Widget already set");
}

// setting the internal widget
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0,0,0,0);
layout->addWidget(w);
m_widget = w;
m_widget->setParent(this); // I am not sure about this
}
~MdiSubWindowParent_t()
{
//std::cerr << "MdiSubWindowParent_t deleted\n";
}
QWidget* widget() {return m_widget;}
const QWidget* widget() const {return m_widget;}
Expand Down

0 comments on commit fbd451f

Please sign in to comment.