]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/QWorkArea.C
rename LFUN enum values according to their command (as used in th minibuffer/bind...
[lyx.git] / src / frontends / qt4 / QWorkArea.C
index 3ccf2b4b7906661ccc771780505a6136230a7b5f..b639d8f28f3b7e36ba06aa7f0a70f596efa05e49 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "lcolorcache.h"
 #include "qt_helpers.h"
-
+#include "BufferView.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "LColor.h"
@@ -49,7 +49,7 @@
 using lyx::support::subst;
 #endif
 
-// You can find other qt-immodule, X11 and MACX specific stuff 
+// You can find other qt-immodule, X11 and MACX specific stuff
 // at the end of this file...
 ///////////////////////////////////////////////////////////////
 
@@ -60,7 +60,7 @@ namespace os = lyx::support::os;
 
 namespace {
 
-QWorkArea const * wa_ptr = 0;
+QWorkArea * wa_ptr = 0;
 
 /// return the LyX key state from Qt's
 key_modifier::state q_key_state(Qt::ButtonState state)
@@ -120,8 +120,8 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 {}
 
 
-QWorkArea::QWorkArea(LyXView &, int w, int h)
-       : QAbstractScrollArea(qApp->mainWidget()), WorkArea(), painter_(this)
+QWorkArea::QWorkArea(LyXView & owner, int w, int h)
+    : QAbstractScrollArea(qApp->mainWidget()), WorkArea(), view_(owner), painter_(this)
 {
        setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
@@ -149,13 +149,13 @@ QWorkArea::QWorkArea(LyXView &, int w, int h)
        synthetic_mouse_event_.timeout.timeout.connect(
                boost::bind(&QWorkArea::generateSyntheticMouseEvent,
                            this));
-       
+
        // Initialize the vertical Scroll Bar
        QObject::connect(verticalScrollBar(), SIGNAL(actionTriggered(int)),
                this, SLOT(adjustViewWithScrollBar(int)));
 
        // PageStep only depends on the viewport height.
-       verticalScrollBar()->setPageStep(workHeight_);  
+       verticalScrollBar()->setPageStep(workHeight_);
 
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
                << "\n Area width\t" << width()
@@ -224,13 +224,14 @@ void QWorkArea::adjustViewWithScrollBar(int action)
                << " linestep=" << verticalScrollBar()->lineStep()
                << endl;
 
-       this->scrollDocView(verticalScrollBar()->sliderPosition());
+       view_.view()->scrollDocView(verticalScrollBar()->sliderPosition());
 }
 
 
 void QWorkArea::haveSelection(bool own) const
 {
-       wa_ptr = this;
+       /// \todo ask X11 and MAC devels why this wa_ptr is useful.
+       wa_ptr = const_cast<QWorkArea*>(this);
 
        if (!QApplication::clipboard()->supportsSelection())
                return;
@@ -263,9 +264,9 @@ void QWorkArea::putClipboard(string const & str) const
 #ifdef Q_WS_MACX
        // The MAC clipboard uses \r for lineendings, and we use \n
        QApplication::clipboard()->setText(toqstr(subst(str, '\n', '\r')),
-                                          QClipboard::Selection);
+                                          QClipboard::Selection);
 #else
-       QApplication::clipboard()->setText(toqstr(str), QClipboard::Selection);
+       QApplication::clipboard()->setText(toqstr(str), QClipboard::Selection);
 #endif
        lyxerr[Debug::ACTION] << "putClipboard: " << str << endl;
 }
@@ -277,7 +278,7 @@ void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
 
        /// \todo Ask lyx-devel is this is enough:
        /// if (event->mimeData()->hasFormat("text/plain"))
-       ///     event->acceptProposedAction();
+       ///     event->acceptProposedAction();
 
 }
 
@@ -292,7 +293,7 @@ void QWorkArea::dropEvent(QDropEvent* event)
                for (QStringList::Iterator i = files.begin();
                     i!=files.end(); ++i) {
                        string const file = os::internal_path(fromqstr(*i));
-                       dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+                       view_.view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
                }
        }
 }
@@ -305,13 +306,13 @@ void QWorkArea::mousePressEvent(QMouseEvent * e)
                FuncRequest cmd(LFUN_MOUSE_TRIPLE,
                        dc_event_.x, dc_event_.y,
                        q_button_state(dc_event_.state));
-               this->dispatch(cmd);
+               view_.view()->workAreaDispatch(cmd);
                return;
        }
 
        FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
                              q_button_state(e->button()));
-       this->dispatch(cmd);
+       view_.view()->workAreaDispatch(cmd);
 }
 
 
@@ -322,7 +323,7 @@ void QWorkArea::mouseReleaseEvent(QMouseEvent * e)
 
        FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
                              q_button_state(e->button()));
-       this->dispatch(cmd);
+       view_.view()->workAreaDispatch(cmd);
 }
 
 
@@ -382,17 +383,22 @@ void QWorkArea::mouseMoveEvent(QMouseEvent * e)
                synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
 
                // ... and dispatch the event to the LyX core.
-               this->dispatch(cmd);
+               view_.view()->workAreaDispatch(cmd);
        }
 }
 
 
 void QWorkArea::wheelEvent(QWheelEvent * e)
 {
-       verticalScrollBar()->setValue(verticalScrollBar()->value() - e->delta());
-       adjustViewWithScrollBar();\r
+       // Wheel rotation by one notch results in a delta() of 120 (see
+       // documentation of QWheelEvent)
+       int const lines = QApplication::wheelScrollLines() * e->delta() / 120;
+       verticalScrollBar()->setValue(verticalScrollBar()->value() -
+                       lines *  verticalScrollBar()->lineStep());
+       adjustViewWithScrollBar();
 }
 
+
 void QWorkArea::generateSyntheticMouseEvent()
 {
        // Set things off to generate the _next_ 'pseudo' event.
@@ -407,7 +413,7 @@ void QWorkArea::generateSyntheticMouseEvent()
                synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
 
                // ... and dispatch the event to the LyX core.
-               this->dispatch(synthetic_mouse_event_.cmd);
+               view_.view()->workAreaDispatch(synthetic_mouse_event_.cmd);
        }
 }
 
@@ -424,8 +430,8 @@ void QWorkArea::keyPressEvent(QKeyEvent * e)
 
     boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
     sym->set(e);
-    this->workAreaKeyPress(sym, q_key_state(e->state()));       
+    view_.view()->workAreaKeyPress(sym, q_key_state(e->state()));
+
 }
 
 // This is not used for now...
@@ -443,17 +449,17 @@ void QWorkArea::keyeventTimeout()
                        continue;
                }
 
-       boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
+                boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
                sym->set(ev.get());
 
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << " count=" << ev->count()
-               << " text=" << (const char *) ev->text()
-               << " isAutoRepeat=" << ev->isAutoRepeat()
-               << " key=" << ev->key()
-               << endl;
+                lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
+                                   << " count=" << ev->count()
+                                   << " text=" << (const char *) ev->text()
+                                   << " isAutoRepeat=" << ev->isAutoRepeat()
+                                   << " key=" << ev->key()
+                                   << endl;
 
-               this->workAreaKeyPress(sym, q_key_state(ev->state()));
+                view_.view()->workAreaKeyPress(sym, q_key_state(ev->state()));
                keyeventQueue_.pop();
 
                handle_autos = false;
@@ -476,7 +482,7 @@ void QWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
        FuncRequest cmd(LFUN_MOUSE_DOUBLE,
                dc_event_.x, dc_event_.y,
                q_button_state(dc_event_.state));
-       this->dispatch(cmd);
+       view_.view()->workAreaDispatch(cmd);
 }
 
 
@@ -487,10 +493,12 @@ void QWorkArea::resizeEvent(QResizeEvent * resizeEvent)
 
        verticalScrollBar()->setPageStep(viewport()->height());
 
-       pixmap_.reset(new QPixmap(viewport()->width(), viewport()->height()));
+       screen_device_ = QPixmap(viewport()->width(), viewport()->height());
+       paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32);
 
-       this->workAreaResize();
+       view_.view()->workAreaResize();
 
+       /*
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
                << "\n QWidget width\t" << this->QWidget::width()
                << "\n QWidget height\t" << this->QWidget::height()
@@ -499,10 +507,21 @@ void QWorkArea::resizeEvent(QResizeEvent * resizeEvent)
                << "\n QResizeEvent rect left\t" << rect().left()
                << "\n QResizeEvent rect right\t" << rect().right()
                << endl;
+               */
+}
+
+void QWorkArea::update(int x, int y, int w, int h)
+{
+       //screen_device_.fromImage(paint_device_);
+       QPainter q(&screen_device_);
+       q.drawImage(x, y, paint_device_.copy(x, y, w, h));
+
+       viewport()->update(x, y, w, h);
 }
 
 void QWorkArea::paintEvent(QPaintEvent * e)
 {
+       /*
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
                << "\n QWidget width\t" << this->width()
                << "\n QWidget height\t" << this->height()
@@ -515,9 +534,22 @@ void QWorkArea::paintEvent(QPaintEvent * e)
                << "\n QPaintEvent w\t" << e->rect().width()
                << "\n QPaintEvent h\t" << e->rect().height()
                << endl;
-
+       */
        QPainter q(viewport());
-       q.drawPixmap(e->rect(), *pixmap_.get(), e->rect());
+       q.drawPixmap(e->rect(), screen_device_, e->rect());
+}
+
+
+QPixmap QWorkArea::copyScreen(int x, int y, int w, int h) const
+{
+       return screen_device_.copy(x, y, w, h);
+}
+
+void QWorkArea::drawScreen(int x, int y, QPixmap pixmap)
+{
+       QPainter q(&screen_device_);
+       q.drawPixmap(x, y, pixmap);
+       viewport()->update(x, y, pixmap.width(), pixmap.height());
 }
 
 
@@ -531,7 +563,7 @@ void QWorkArea::paintEvent(QPaintEvent * e)
 #if USE_INPUT_METHODS
 // to make qt-immodule work
 
-void QWorkArea::inputMethodEvent(QInputMethodEvent * e) 
+void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
 {
        QString const text = e->text();
        if (!text.isEmpty()) {
@@ -558,12 +590,12 @@ bool lyxX11EventFilter(XEvent * xev)
        case SelectionRequest:
                lyxerr[Debug::GUI] << "X requested selection." << endl;
                if (wa_ptr)
-                       wa_ptr->selectionRequested();
+                       wa_ptr->view().view()->selectionRequested();
                break;
        case SelectionClear:
                lyxerr[Debug::GUI] << "Lost selection." << endl;
                if (wa_ptr)
-                       wa_ptr->selectionLost();
+                       wa_ptr->view().view()->selectionLost();
                break;
        }
        return false;
@@ -627,7 +659,7 @@ pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
                                        FSRefMakePath(&ref, (UInt8*)qstr_buf,
                                                      1024);
                                        s_arg=QString::fromUtf8(qstr_buf);
-                                       wa_ptr->dispatch(
+                                       wa_ptr->view().view()->workAreaDispatch(
                                                FuncRequest(LFUN_FILE_OPEN,
                                                            fromqstr(s_arg)));
                                        break;