X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fqt4%2FGuiWorkArea.cpp;h=a61d31309a7026098bb4bbae0aeb23c74d7d74f1;hb=50de85396c785a454fe07b77d815c57f3e462282;hp=5a8bb268e317310a7968ff5a6a265318439f80c3;hpb=7429f0c2bf0b5499cdf108aeedcc16a23a4c8c6d;p=lyx.git diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 5a8bb268e3..a61d31309a 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -14,36 +14,30 @@ #include "GuiWorkArea.h" #include "GuiApplication.h" -#include "QLPainter.h" -#include "QKeySymbol.h" +#include "GuiPainter.h" +#include "GuiKeySymbol.h" #include "qt_helpers.h" -#include "LyXView.h" +#include "frontends/LyXView.h" #include "BufferView.h" -#include "rowpainter.h" +#include "Color.h" #include "debug.h" #include "FuncRequest.h" -#include "Color.h" -#include "version.h" #include "LyXRC.h" +#include "version.h" #include "support/filetools.h" // LibFileSearch -#include "support/os.h" -#include "support/convert.h" #include "graphics/GraphicsImage.h" #include "graphics/GraphicsLoader.h" +#include #include #include -#include -#include -#include #include #include #include -#include #include #include @@ -59,31 +53,16 @@ int const CursorWidth = 2; int const CursorWidth = 1; #endif +#undef KeyPress +#undef NoModifier using std::endl; using std::string; -namespace os = lyx::support::os; - - namespace lyx { using support::FileName; -/// return the LyX key state from Qt's -static key_modifier::state q_key_state(Qt::KeyboardModifiers state) -{ - key_modifier::state k = key_modifier::none; - if (state & Qt::ControlModifier) - k |= key_modifier::ctrl; - if (state & Qt::ShiftModifier) - k |= key_modifier::shift; - if (state & Qt::AltModifier || state & Qt::MetaModifier) - k |= key_modifier::alt; - return k; -} - - /// return the LyX mouse button state from Qt's static mouse_button::state q_button_state(Qt::MouseButton button) { @@ -192,8 +171,8 @@ SyntheticMouseEvent::SyntheticMouseEvent() {} -GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view) - : WorkArea(id, lyx_view), need_resize_(false), schedule_redraw_(false), +GuiWorkArea::GuiWorkArea(Buffer & buf, LyXView & lv) + : WorkArea(buf, lv), need_resize_(false), schedule_redraw_(false), preedit_lines_(1) { screen_ = QPixmap(viewport()->width(), viewport()->height()); @@ -215,8 +194,6 @@ GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view) viewport()->setCursor(Qt::IBeamCursor); - resize(w, h); - synthetic_mouse_event_.timeout.timeout.connect( boost::bind(&GuiWorkArea::generateSyntheticMouseEvent, this)); @@ -264,35 +241,23 @@ void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step } -void GuiWorkArea::adjustViewWithScrollBar(int) -{ - scrollBufferView(verticalScrollBar()->sliderPosition()); - QApplication::syncX(); -} - - -void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event) -{ - if (event->mimeData()->hasUrls()) - event->accept(); - /// \todo Ask lyx-devel is this is enough: - /// if (event->mimeData()->hasFormat("text/plain")) - /// event->acceptProposedAction(); -} - - -void GuiWorkArea::dropEvent(QDropEvent* event) +void GuiWorkArea::adjustViewWithScrollBar(int action) { - QList files = event->mimeData()->urls(); - if (files.isEmpty()) - return; + stopBlinkingCursor(); + if (action == QAbstractSlider::SliderPageStepAdd) + buffer_view_->scrollDown(viewport()->height()); + else if (action == QAbstractSlider::SliderPageStepSub) + buffer_view_->scrollUp(viewport()->height()); + else + buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition()); - LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl; - for (int i = 0; i!=files.size(); ++i) { - string const file = os::internal_path(fromqstr(files.at(i).toLocalFile())); - if (!file.empty()) - dispatch(FuncRequest(LFUN_FILE_OPEN, file)); + if (lyxrc.cursor_follows_scrollbar) { + buffer_view_->setCursorFromScrollbar(); + lyx_view_->updateLayoutChoice(); } + // Show the cursor immediately after any operation. + startBlinkingCursor(); + QApplication::syncX(); } @@ -302,17 +267,13 @@ void GuiWorkArea::focusInEvent(QFocusEvent * /*event*/) // if (theApp() == 0 || &lyx_view_ == theApp()->currentView()) // return; - theApp()->setCurrentView(lyx_view_); + theApp()->setCurrentView(*lyx_view_); // Repaint the whole screen. // Note: this is different from redraw() as only the backing pixmap // will be redrawn, which is cheap. viewport()->repaint(); - // FIXME: it would be better to send a signal "newBuffer()" - // in BufferList that could be connected to the different tabbars. - lyx_view_.updateTab(); - startBlinkingCursor(); } @@ -469,15 +430,18 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * e) << " key=" << e->key() << endl; - boost::shared_ptr sym(new QKeySymbol); + boost::shared_ptr sym(new GuiKeySymbol); sym->set(e); processKeySym(sym, q_key_state(e->modifiers())); } -void GuiWorkArea::doubleClickTimeout() { + +void GuiWorkArea::doubleClickTimeout() +{ dc_event_.active = false; } + void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e) { dc_event_ = double_click(e); @@ -503,49 +467,6 @@ void GuiWorkArea::update(int x, int y, int w, int h) } -void GuiWorkArea::doGreyOut(QLPainter & pain) -{ - pain.fillRectangle(0, 0, width(), height(), - Color::bottomarea); - - //if (!lyxrc.show_banner) - // return; - LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl; - /// The text to be written on top of the pixmap - QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version"); - FileName const file = support::libFileSearch("images", "banner", "png"); - if (file.empty()) - return; - - QPixmap pm(toqstr(file.absFilename())); - if (!pm) { - lyxerr << "could not load splash screen: '" << file << "'" << endl; - return; - } - - QFont font; - // The font used to display the version info - font.setStyleHint(QFont::SansSerif); - font.setWeight(QFont::Bold); - font.setPointSize(convert(lyxrc.font_sizes[Font::SIZE_LARGE])); - - int const w = pm.width(); - int const h = pm.height(); - - int x = (width() - w) / 2; - int y = (height() - h) / 2; - - pain.drawPixmap(x, y, pm); - - x += 260; - y += 270; - - pain.setPen(QColor(255, 255, 0)); - pain.setFont(font); - pain.drawText(x, y, text); -} - - void GuiWorkArea::paintEvent(QPaintEvent * ev) { QRect const rc = ev->rect(); @@ -561,6 +482,8 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev) screen_ = QPixmap(viewport()->width(), viewport()->height()); resizeBufferView(); updateScreen(); + WorkArea::hideCursor(); + WorkArea::showCursor(); need_resize_ = false; } @@ -579,28 +502,18 @@ void GuiWorkArea::expose(int x, int y, int w, int h) void GuiWorkArea::updateScreen() { - QLPainter pain(&screen_); - - if (greyed_out_) { - LYXERR(Debug::GUI) << "splash screen requested" << endl; - verticalScrollBar()->hide(); - doGreyOut(pain); - return; - } - + GuiPainter pain(&screen_); verticalScrollBar()->show(); - paintText(*buffer_view_, pain); + buffer_view_->draw(pain); } void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape) { if (schedule_redraw_) { - if (buffer_view_ && buffer_view_->buffer()) { - buffer_view_->update(Update::Force); - updateScreen(); - viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height())); - } + buffer_view_->update(Update::Force); + updateScreen(); + viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height())); schedule_redraw_ = false; // Show the cursor immediately after the update. hideCursor(); @@ -628,11 +541,6 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e) docstring const & preedit_string = qstring_to_ucs4(e->preeditString()); - if(greyed_out_) { - e->ignore(); - return; - } - if (!commit_string.isEmpty()) { LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION @@ -663,9 +571,9 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e) return; } - QLPainter pain(&screen_); + GuiPainter pain(&screen_); buffer_view_->updateMetrics(false); - paintText(*buffer_view_, pain); + buffer_view_->draw(pain); Font font = buffer_view_->cursor().getFont(); FontMetrics const & fm = theFontMetrics(font); int height = fm.maxHeight();