]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
some remnaming
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index b9c0a9dab8a78284b644c9f1a9e524c84dd1ef16..a61d31309a7026098bb4bbae0aeb23c74d7d74f1 100644 (file)
@@ -14,8 +14,8 @@
 #include "GuiWorkArea.h"
 
 #include "GuiApplication.h"
-#include "QLPainter.h"
-#include "QKeySymbol.h"
+#include "GuiPainter.h"
+#include "GuiKeySymbol.h"
 #include "qt_helpers.h"
 
 #include "frontends/LyXView.h"
 #include "debug.h"
 #include "FuncRequest.h"
 #include "LyXRC.h"
-#include "rowpainter.h"
 #include "version.h"
 
 #include "support/filetools.h" // LibFileSearch
-#include "support/convert.h"
 
 #include "graphics/GraphicsImage.h"
 #include "graphics/GraphicsLoader.h"
@@ -55,6 +53,8 @@ int const CursorWidth = 2;
 int const CursorWidth = 1;
 #endif
 
+#undef KeyPress
+#undef NoModifier 
 
 using std::endl;
 using std::string;
@@ -63,20 +63,6 @@ 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)
 {
@@ -185,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());
@@ -208,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));
@@ -257,9 +241,22 @@ void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step
 }
 
 
-void GuiWorkArea::adjustViewWithScrollBar(int)
+void GuiWorkArea::adjustViewWithScrollBar(int action)
 {
-       scrollBufferView(verticalScrollBar()->sliderPosition());
+       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());
+
+       if (lyxrc.cursor_follows_scrollbar) {
+               buffer_view_->setCursorFromScrollbar();
+               lyx_view_->updateLayoutChoice();
+       }
+       // Show the cursor immediately after any operation.
+       startBlinkingCursor();
        QApplication::syncX();
 }
 
@@ -270,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();
 }
 
@@ -437,15 +430,18 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * e)
                << " key=" << e->key()
                << endl;
 
-       boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
+       boost::shared_ptr<GuiKeySymbol> 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);
@@ -471,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<int>(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();
@@ -549,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();
@@ -598,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
@@ -633,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();