]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/DockView.h
close floating dock widgets (not currently docked) with escape keypress event
[lyx.git] / src / frontends / qt4 / DockView.h
1 // -*- C++ -*-
2 /**
3  * \file DockView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef DOCK_VIEW_H
13 #define DOCK_VIEW_H
14
15 #include "Dialog.h"
16 #include "GuiView.h"
17
18 #include <QDockWidget>
19 #include <QKeyEvent>
20
21 namespace lyx {
22 namespace frontend {
23
24 /// Dock Widget container for LyX dialogs.
25 /**
26  * This template class that encapsulates a given Widget inside a
27  * QDockWidget and presents a Dialog interface
28  * FIXME: create a DockView.cpp file
29  **/
30 class DockView : public QDockWidget, public Dialog
31 {
32 public:
33         DockView(
34                 GuiView & parent, ///< the main window where to dock.
35                 QString const & name, ///< dialog identifier.
36                 QString const & title, ///< dialog title.
37                 Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
38                 Qt::WindowFlags flags = 0
39         )
40                 : QDockWidget(&parent, flags), Dialog(parent, name, title)
41         {
42                 setObjectName(name);
43                 parent.addDockWidget(area, this);
44                 hide();
45         }
46
47         virtual ~DockView() {}
48
49         virtual QWidget * asQWidget() { return this; }
50         virtual QWidget const * asQWidget() const { return this; }
51
52         /// We don't want to restore geometry session for dock widgets.
53         void restoreSession() {}
54
55         void keyPressEvent(QKeyEvent * ev)
56         {
57                 if (ev->key() == Qt::Key_Escape) {
58                         QMainWindow * mw = static_cast<QMainWindow *>(parent());
59                         if (!mw) {
60                                 ev->ignore();
61                                 return;
62                         }
63                         mw->activateWindow();
64                         mw->setFocus();
65                         if (isFloating())
66                                 hide();
67                         ev->accept();
68                 }
69         }
70         /// Dialog inherited methods
71         //@{
72         void applyView() {}
73         bool isClosing() const { return false; }
74         bool needBufferOpen() const { return false; }
75         //@}
76 };
77
78 } // frontend
79 } // lyx
80
81 #endif // DOCK_VIEW_H