#ifndef DOCK_VIEW_H
#define DOCK_VIEW_H
-#include "controllers/Dialog.h"
+#include "Dialog.h"
#include "GuiView.h"
-#include "qt_helpers.h"
-#include "debug.h"
#include <QDockWidget>
+#include <QKeyEvent>
namespace lyx {
namespace frontend {
/// Dock Widget container for LyX dialogs.
-/// This template class that encapsulates a given Widget inside a
-/// QDockWidget and presents a Dialog interface
-template<class MyController, class MyWidget>
+/**
+ * This template class that encapsulates a given Widget inside a
+ * QDockWidget and presents a Dialog interface
+ * FIXME: create a DockView.cpp file
+ **/
class DockView : public QDockWidget, public Dialog
{
public:
DockView(
- GuiViewBase & parent, ///< the main window where to dock.
- std::string const & name, ///< dialog identifier.
+ GuiView & parent, ///< the main window where to dock.
+ QString const & name, ///< dialog identifier.
+ QString const & title, ///< dialog title.
Qt::DockWidgetArea area = Qt::LeftDockWidgetArea, ///< Position of the dock (and also drawer)
Qt::WindowFlags flags = 0
)
- : QDockWidget(&parent, flags), name_(name)
+ : QDockWidget(&parent, flags), Dialog(parent, name, title)
{
- if (flags & Qt::Drawer)
- setFeatures(QDockWidget::NoDockWidgetFeatures);
- MyController * c = new MyController(*this);
- controller_ = c;
- controller_->setLyXView(parent);
- widget_ = new MyWidget(*c);
- setWidget(widget_);
- setWindowTitle(widget_->windowTitle());
+ setObjectName(name);
parent.addDockWidget(area, this);
+ hide();
}
- ~DockView() { delete widget_; delete controller_; }
+ virtual ~DockView() {}
+
+ virtual QWidget * asQWidget() { return this; }
+ virtual QWidget const * asQWidget() const { return this; }
+
+ /// We don't want to restore geometry session for dock widgets.
+ void restoreSession() {}
+
+ void keyPressEvent(QKeyEvent * ev)
+ {
+ if (ev->key() == Qt::Key_Escape) {
+ QMainWindow * mw = static_cast<QMainWindow *>(parent());
+ if (!mw) {
+ ev->ignore();
+ return;
+ }
+ mw->activateWindow();
+ mw->setFocus();
+ if (isFloating())
+ hide();
+ ev->accept();
+ }
+ }
/// Dialog inherited methods
//@{
void applyView() {}
- void hideView() { QDockWidget::hide(); }
- void showView() { QDockWidget::show(); }
- bool isVisibleView() const { return QDockWidget::isVisible(); }
- void checkStatus() {}
- void redraw() { redrawView(); }
- void redrawView() {}
- void updateView()
- {
- widget_->updateView();
- QDockWidget::update();
- }
bool isClosing() const { return false; }
- void partialUpdateView(int /*id*/) {}
- Controller & controller() const { return *controller_; }
- std::string name() const { return name_; }
+ bool needBufferOpen() const { return false; }
//@}
-private:
- /// The encapsulated widget.
- MyWidget * widget_;
- Controller * controller_;
- std::string name_;
};
} // frontend