]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
Fix bug #6997
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index b7e68ff77cdb7343c87a90375e1c4c388ad2fea5..ef79b02fe3e1c7b0f76ef3e8b53cbf8866bbe2af 100644 (file)
@@ -288,7 +288,7 @@ void GuiWorkArea::init()
 
        setFocusPolicy(Qt::StrongFocus);
 
-       viewport()->setCursor(Qt::IBeamCursor);
+       setCursorShape(Qt::IBeamCursor);
 
        synthetic_mouse_event_.timeout.timeout.connect(
                bind(&GuiWorkArea::generateSyntheticMouseEvent,
@@ -320,6 +320,25 @@ GuiWorkArea::~GuiWorkArea()
 }
 
 
+Qt::CursorShape GuiWorkArea::cursorShape() const
+{
+       return viewport()->cursor().shape();
+}
+
+
+void GuiWorkArea::setCursorShape(Qt::CursorShape shape)
+{
+       viewport()->setCursor(shape);
+}
+
+
+void GuiWorkArea::updateCursorShape()
+{
+       setCursorShape(buffer_view_->clickableInset() 
+               ? Qt::PointingHandCursor : Qt::IBeamCursor);
+}
+
+
 void GuiWorkArea::setGuiView(GuiView & gv)
 {
        lyx_view_ = &gv;
@@ -424,6 +443,7 @@ void GuiWorkArea::redraw(bool update_metrics)
        if (update_metrics || lyx_view_ != guiApp->currentView()
                || lyx_view_->currentWorkArea() != this) {
                // FIXME: it would be nice to optimize for the off-screen case.
+               buffer_view_->cursor().fixIfBroken();
                buffer_view_->updateMetrics();
                buffer_view_->cursor().fixIfBroken();
        }
@@ -448,6 +468,8 @@ void GuiWorkArea::redraw(bool update_metrics)
                buffer_view_->coordCache().dump();
 
        setReadOnly(buffer_view_->buffer().isReadonly());
+
+       updateCursorShape();
 }
 
 
@@ -517,6 +539,8 @@ void GuiWorkArea::dispatch(FuncRequest const & cmd0, KeyModifier mod)
                // Show the cursor immediately after any operation
                startBlinkingCursor();
        }
+
+       updateCursorShape();
 }
 
 
@@ -654,11 +678,14 @@ bool GuiWorkArea::event(QEvent * e)
                // which are otherwise reserved to focus switching between controls
                // within a dialog.
                QKeyEvent * ke = static_cast<QKeyEvent*>(e);
-               if ((ke->key() != Qt::Key_Tab && ke->key() != Qt::Key_Backtab)
-                       || ke->modifiers() & Qt::ControlModifier)
-                       return QAbstractScrollArea::event(e);
-               keyPressEvent(ke);
-               return true;
+               if ((ke->key() == Qt::Key_Tab && ke->modifiers() == Qt::NoModifier)
+                       || (ke->key() == Qt::Key_Backtab && (
+                               ke->modifiers() == Qt::ShiftModifier
+                               || ke->modifiers() == Qt::NoModifier))) {
+                       keyPressEvent(ke);
+                       return true;
+               }
+               return QAbstractScrollArea::event(e);
        }
 
        default:
@@ -817,7 +844,24 @@ void GuiWorkArea::wheelEvent(QWheelEvent * ev)
        // Wheel rotation by one notch results in a delta() of 120 (see
        // documentation of QWheelEvent)
        double const delta = ev->delta() / 120.0;
-       if (ev->modifiers() & Qt::ControlModifier) {
+       bool zoom = false;
+       switch (lyxrc.scroll_wheel_zoom) {
+       case LyXRC::SCROLL_WHEEL_ZOOM_CTRL:
+               zoom = ev->modifiers() & Qt::ControlModifier;
+               zoom &= !(ev->modifiers() & (Qt::ShiftModifier | Qt::AltModifier));
+               break;
+       case LyXRC::SCROLL_WHEEL_ZOOM_SHIFT:
+               zoom = ev->modifiers() & Qt::ShiftModifier;
+               zoom &= !(ev->modifiers() & (Qt::ControlModifier | Qt::AltModifier));
+               break;
+       case LyXRC::SCROLL_WHEEL_ZOOM_ALT:
+               zoom = ev->modifiers() & Qt::AltModifier;
+               zoom &= !(ev->modifiers() & (Qt::ShiftModifier | Qt::ControlModifier));
+               break;
+       case LyXRC::SCROLL_WHEEL_ZOOM_OFF:
+               break;
+       }
+       if (zoom) {
                docstring arg = convert<docstring>(int(5 * delta));
                lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg));
                return;
@@ -1299,7 +1343,7 @@ EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
 EmbeddedWorkArea::~EmbeddedWorkArea()
 {
        // No need to destroy buffer and bufferview here, because it is done
-       // in theBuffeerList() destruction loop at application exit
+       // in theBufferList() destruction loop at application exit
 }
 
 
@@ -1445,7 +1489,7 @@ void TabWorkArea::mouseDoubleClickEvent(QMouseEvent * event)
 void TabWorkArea::setFullScreen(bool full_screen)
 {
        for (int i = 0; i != count(); ++i) {
-               if (GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i)))
+               if (GuiWorkArea * wa = workArea(i))
                        wa->setFullScreen(full_screen);
        }
 
@@ -1476,12 +1520,18 @@ GuiWorkArea * TabWorkArea::currentWorkArea()
 }
 
 
+GuiWorkArea * TabWorkArea::workArea(int index)
+{
+       return dynamic_cast<GuiWorkArea *>(widget(index));
+}
+
+
 GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
 {
        // FIXME: this method doesn't work if we have more than work area
        // showing the same buffer.
        for (int i = 0; i != count(); ++i) {
-               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
+               GuiWorkArea * wa = workArea(i);
                LASSERT(wa, return 0);
                if (&wa->bufferView().buffer() == &buffer)
                        return wa;
@@ -1493,7 +1543,7 @@ GuiWorkArea * TabWorkArea::workArea(Buffer & buffer)
 void TabWorkArea::closeAll()
 {
        while (count()) {
-               GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(0));
+               GuiWorkArea * wa = workArea(0);
                LASSERT(wa, /**/);
                removeTab(0);
                delete wa;
@@ -1576,7 +1626,7 @@ void TabWorkArea::on_currentTabChanged(int i)
        // returns e.g. on application destruction
        if (i == -1)
                return;
-       GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
+       GuiWorkArea * wa = workArea(i);
        LASSERT(wa, return);
        wa->setUpdatesEnabled(true);
        wa->redraw(true);
@@ -1595,7 +1645,7 @@ void TabWorkArea::closeCurrentBuffer()
        if (clicked_tab_ == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+               wa = workArea(clicked_tab_);
                LASSERT(wa, /**/);
        }
        wa->view().closeWorkArea(wa);
@@ -1608,7 +1658,7 @@ void TabWorkArea::hideCurrentTab()
        if (clicked_tab_ == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(clicked_tab_));
+               wa = workArea(clicked_tab_);
                LASSERT(wa, /**/);
        }
        wa->view().hideWorkArea(wa);
@@ -1622,7 +1672,7 @@ void TabWorkArea::closeTab(int index)
        if (index == -1)
                wa = currentWorkArea();
        else {
-               wa = dynamic_cast<GuiWorkArea *>(widget(index));
+               wa = workArea(index);
                LASSERT(wa, /**/);
        }
        wa->view().closeWorkArea(wa);
@@ -1733,7 +1783,7 @@ void TabWorkArea::updateTabTexts()
        // collect full names first: path into postfix, empty prefix and
        // filename without extension
        for (size_t i = 0; i < n; ++i) {
-               GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(i));
+               GuiWorkArea * i_wa = workArea(i);
                FileName const fn = i_wa->bufferView().buffer().fileName();
                paths.push_back(DisplayPath(i, fn));
        }
@@ -1817,7 +1867,7 @@ void TabWorkArea::updateTabTexts()
 
        // set new tab titles
        for (It it = paths.begin(); it != paths.end(); ++it) {
-               GuiWorkArea * i_wa = dynamic_cast<GuiWorkArea *>(widget(it->tab()));
+               GuiWorkArea * i_wa = workArea(it->tab());
                Buffer & buf = i_wa->bufferView().buffer();
                if (!buf.fileName().empty() && !buf.isClean())
                        setTabText(it->tab(), it->displayString() + "*");