use QMainWindow.closeEvent for close events

The current code uses the QWidget.destroyed signal
to emit a close event into matplotlib. This is a very
bad idea, as it is a heavy abuse of Qt functionality.

When a main window is closed in Qt, it and its children
are deleted if the DeleteOnClose flag is set (which we
did set). This causes the QWidget.destroyed signal to be
called. Setting the DeleteOnClose flag is a very bad
idea, since objects should only be deleted by the
garbage collector. Soon after, PyQt4 will complain
that "the underlying C++ object has been deleted", since
the object is alive for python but dead for C++.

This patch changes the machinery to use the
QMainWindow.closeEvent to emit a close_event, which is
what one actually wants.
Merge pull request #1498 from tecki/qtcloseevent

use QMainWindow.closeEvent for close events