]> git.lyx.org Git - features.git/commitdiff
Some cosmetic changes so that GuiWorkArea can be embeddable in a Qt designer dialog.
authorAbdelrazak Younes <younes@lyx.org>
Sat, 15 Nov 2008 22:34:52 +0000 (22:34 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sat, 15 Nov 2008 22:34:52 +0000 (22:34 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@27499 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/GuiWorkArea.cpp
src/frontends/qt4/GuiWorkArea.h

index dd4d4d824350eedbf9a081113d28e00017e0fcdf..09bf4bb97d59a2820eb1fb2c26c1af47428f42a3 100644 (file)
@@ -233,14 +233,28 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 {}
 
 
+GuiWorkArea::GuiWorkArea(QWidget *)
+       : buffer_view_(0), lyx_view_(0),
+       cursor_visible_(false),
+       need_resize_(false), schedule_redraw_(false),
+       preedit_lines_(1), completer_(new GuiCompleter(this))
+{
+}
+
 
-GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
-       : buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
+GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
+       : buffer_view_(0), lyx_view_(0),
        cursor_visible_(false),
        need_resize_(false), schedule_redraw_(false),
        preedit_lines_(1), completer_(new GuiCompleter(this))
 {
-       buffer.workAreaManager().add(this);
+       setGuiView(gv);
+       setBuffer(buffer);
+}
+
+
+void GuiWorkArea::init()
+{
        // Setup the signals
        connect(&cursor_timeout_, SIGNAL(timeout()),
                this, SLOT(toggleCursor()));
@@ -258,17 +272,6 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        cursor_ = new frontend::CursorWidget();
        cursor_->hide();
 
-       // HACK: Prevents an additional redraw when the scrollbar pops up
-       // which regularily happens on documents with more than one page.
-       // The policy  should be set to "Qt::ScrollBarAsNeeded" soon.
-       // Since we have no geometry information yet, we assume that
-       // a document needs a scrollbar if there is more then four
-       // paragraph in the outermost text.
-       if (buffer.text().paragraphs().size() > 4)
-               setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-       QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
-
-
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        setAcceptDrops(true);
        setMouseTracking(true);
@@ -285,7 +288,7 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        // the viewport because we have our own backing pixmap.
        viewport()->setAttribute(Qt::WA_NoSystemBackground);
 
-       setFocusPolicy(Qt::WheelFocus);
+       setFocusPolicy(Qt::StrongFocus);
 
        viewport()->setCursor(Qt::IBeamCursor);
 
@@ -303,6 +306,8 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
        // Enables input methods for asian languages.
        // Must be set when creating custom text editing widgets.
        setAttribute(Qt::WA_InputMethodEnabled, true);
+
+       dialogMode_ = false;
 }
 
 
@@ -316,6 +321,31 @@ GuiWorkArea::~GuiWorkArea()
 }
 
 
+void GuiWorkArea::setGuiView(GuiView & gv)
+{
+       lyx_view_ = &gv;
+}
+
+
+void GuiWorkArea::setBuffer(Buffer & buffer)
+{
+       delete buffer_view_;
+       buffer_view_ = new BufferView(buffer),
+       buffer.workAreaManager().add(this);
+
+       // HACK: Prevents an additional redraw when the scrollbar pops up
+       // which regularily happens on documents with more than one page.
+       // The policy  should be set to "Qt::ScrollBarAsNeeded" soon.
+       // Since we have no geometry information yet, we assume that
+       // a document needs a scrollbar if there is more then four
+       // paragraph in the outermost text.
+       if (buffer.text().paragraphs().size() > 4)
+               setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
+       QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
+       init();
+}
+
+
 void GuiWorkArea::fixVerticalScrollBar()
 {
        if (!isFullScreen())
@@ -660,8 +690,14 @@ void GuiWorkArea::contextMenuEvent(QContextMenuEvent * e)
 
 void GuiWorkArea::focusInEvent(QFocusEvent * e)
 {
-       if (lyx_view_->currentWorkArea() != this)
-               lyx_view_->setCurrentWorkArea(this);
+       LYXERR(Debug::DEBUG, "GuiWorkArea::focusInEvent(): " << this << std::endl);
+       GuiWorkArea * old_gwa = theGuiApp()->currentView()->currentWorkArea();
+       if (old_gwa)
+               old_gwa->stopBlinkingCursor();
+       lyx_view_->setCurrentWorkArea(this);
+
+       //if (lyx_view_->currentWorkArea() != this) {
+       //      lyx_view_->setCurrentWorkArea(this);
 
        startBlinkingCursor();
        QAbstractScrollArea::focusInEvent(e);
@@ -670,6 +706,7 @@ void GuiWorkArea::focusInEvent(QFocusEvent * e)
 
 void GuiWorkArea::focusOutEvent(QFocusEvent * e)
 {
+       LYXERR(Debug::DEBUG, "GuiWorkArea::focusOutEvent(): " << this << std::endl);
        stopBlinkingCursor();
        QAbstractScrollArea::focusOutEvent(e);
 }
@@ -835,6 +872,18 @@ void GuiWorkArea::generateSyntheticMouseEvent()
 
 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
 {
+       // Do not process here some keys if dialogMode_ is set
+       if (dialogMode_
+               && (ev->modifiers() == Qt::NoModifier
+                   || ev->modifiers() == Qt::ShiftModifier)
+               && (ev->key() == Qt::Key_Escape
+                   || ev->key() == Qt::Key_Enter
+                   || ev->key() == Qt::Key_Return)
+           ) {
+               ev->ignore();
+               return;
+       }
+
        // intercept some keys if completion popup is visible
        if (completer_->popupVisible()) {
                switch (ev->key()) {
index 4d531b9ec3fdfff31d15e16a14938bf3f9dbfb1f..9694977117bb22db3ed8c9036b1c6460a20e7f03 100644 (file)
@@ -101,10 +101,19 @@ class GuiWorkArea : public QAbstractScrollArea, public WorkArea
 
 public:
        ///
-       GuiWorkArea(Buffer & buffer, GuiView & lv);
+       GuiWorkArea(QWidget *);
+       ///
+       GuiWorkArea(Buffer & buffer, GuiView & gv);
        ///
        ~GuiWorkArea();
 
+       ///
+       void setBuffer(Buffer &);
+       ///
+       void setGuiView(GuiView &);
+       /// Dummy methods for Designer.
+       void setWidgetResizable(bool) {}
+       void setWidget(QWidget *) {}
        ///
        void setFullScreen(bool full_screen);
        /// is LyXView in fullscreen mode?
@@ -127,9 +136,20 @@ public:
        ///
        void resizeBufferView();
 
+       bool isInDialog() {
+               return dialogMode_;
+       }
+
        ///
        GuiCompleter & completer() { return *completer_; }
-       
+
+       /// Return true if dialogMode is set
+       bool& dialogMode() { return dialogMode_; }
+
+       /// Return the GuiView this workArea belongs to
+       GuiView const & view() const { return *lyx_view_; }
+       GuiView & view() { return *lyx_view_; }
+
 Q_SIGNALS:
        ///
        void titleChanged(GuiWorkArea *);
@@ -153,6 +173,8 @@ private Q_SLOTS:
 
 private:
        friend class GuiCompleter;
+       ///
+       void init();
 
        /// update the passed area.
        void update(int x, int y, int w, int h);
@@ -238,6 +260,10 @@ private:
 
        ///
        GuiCompleter * completer_;
+
+       /// Special mode in which Esc and Enter (with or without Shift)
+       /// are ignored
+       bool dialogMode_;
 }; // GuiWorkArea