X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiWorkArea.cpp;h=ef79b02fe3e1c7b0f76ef3e8b53cbf8866bbe2af;hb=8b7584846c4e1a9c87a004fab479722fee7e3013;hp=bef40d88cbc16e82170ff4fa12d06b5c457d7718;hpb=41cd987dc50eb692cd1d16fc7b075a55d93f4b72;p=lyx.git diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index bef40d88cb..ef79b02fe3 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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(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: @@ -816,9 +843,26 @@ void GuiWorkArea::wheelEvent(QWheelEvent * ev) { // Wheel rotation by one notch results in a delta() of 120 (see // documentation of QWheelEvent) - int const delta = ev->delta() / 120; - if (ev->modifiers() & Qt::ControlModifier) { - docstring arg = convert(5 * delta); + double const delta = ev->delta() / 120.0; + 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(int(5 * delta)); lyx::dispatch(FuncRequest(LFUN_BUFFER_ZOOM_IN, arg)); return; } @@ -830,11 +874,8 @@ void GuiWorkArea::wheelEvent(QWheelEvent * ev) int scroll_value = lines > page_step ? page_step : lines * verticalScrollBar()->singleStep(); - // Take into account the rotation. - scroll_value *= delta; - - // Take into account user preference. - scroll_value = int(scroll_value * lyxrc.mouse_wheel_speed); + // Take into account the rotation and the user preferences. + scroll_value = int(scroll_value * delta * lyxrc.mouse_wheel_speed); LYXERR(Debug::SCROLLING, "wheelScrollLines = " << lines << " delta = " << delta << " scroll_value = " << scroll_value << " page_step = " << page_step); @@ -1302,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 } @@ -1448,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(widget(i))) + if (GuiWorkArea * wa = workArea(i)) wa->setFullScreen(full_screen); } @@ -1479,12 +1520,18 @@ GuiWorkArea * TabWorkArea::currentWorkArea() } +GuiWorkArea * TabWorkArea::workArea(int index) +{ + return dynamic_cast(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(widget(i)); + GuiWorkArea * wa = workArea(i); LASSERT(wa, return 0); if (&wa->bufferView().buffer() == &buffer) return wa; @@ -1496,7 +1543,7 @@ GuiWorkArea * TabWorkArea::workArea(Buffer & buffer) void TabWorkArea::closeAll() { while (count()) { - GuiWorkArea * wa = dynamic_cast(widget(0)); + GuiWorkArea * wa = workArea(0); LASSERT(wa, /**/); removeTab(0); delete wa; @@ -1579,7 +1626,7 @@ void TabWorkArea::on_currentTabChanged(int i) // returns e.g. on application destruction if (i == -1) return; - GuiWorkArea * wa = dynamic_cast(widget(i)); + GuiWorkArea * wa = workArea(i); LASSERT(wa, return); wa->setUpdatesEnabled(true); wa->redraw(true); @@ -1598,7 +1645,7 @@ void TabWorkArea::closeCurrentBuffer() if (clicked_tab_ == -1) wa = currentWorkArea(); else { - wa = dynamic_cast(widget(clicked_tab_)); + wa = workArea(clicked_tab_); LASSERT(wa, /**/); } wa->view().closeWorkArea(wa); @@ -1611,7 +1658,7 @@ void TabWorkArea::hideCurrentTab() if (clicked_tab_ == -1) wa = currentWorkArea(); else { - wa = dynamic_cast(widget(clicked_tab_)); + wa = workArea(clicked_tab_); LASSERT(wa, /**/); } wa->view().hideWorkArea(wa); @@ -1625,7 +1672,7 @@ void TabWorkArea::closeTab(int index) if (index == -1) wa = currentWorkArea(); else { - wa = dynamic_cast(widget(index)); + wa = workArea(index); LASSERT(wa, /**/); } wa->view().closeWorkArea(wa); @@ -1736,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(widget(i)); + GuiWorkArea * i_wa = workArea(i); FileName const fn = i_wa->bufferView().buffer().fileName(); paths.push_back(DisplayPath(i, fn)); } @@ -1820,7 +1867,7 @@ void TabWorkArea::updateTabTexts() // set new tab titles for (It it = paths.begin(); it != paths.end(); ++it) { - GuiWorkArea * i_wa = dynamic_cast(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() + "*");