]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
some remnaming
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index f63d44c64bb4bbfdc612e825b2ce82a0377ecf75..a61d31309a7026098bb4bbae0aeb23c74d7d74f1 100644 (file)
 #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 <QInputContext>
 #include <QLayout>
 #include <QMainWindow>
-#include <QMimeData>
-#include <QUrl>
-#include <QDragEnterEvent>
 #include <QPainter>
 #include <QScrollBar>
 #include <QTimer>
-#include <QInputContext>
 
 #include <boost/bind.hpp>
 #include <boost/current_function.hpp>
 
+#ifdef Q_WS_X11
+#include <QX11Info>
+extern "C" int XEventsQueued(Display *display, int mode);
+#endif
+
 #ifdef Q_WS_WIN
 int const CursorWidth = 2;
 #else
 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)
 {
@@ -122,16 +106,44 @@ public:
 
        void draw(QPainter & painter)
        {
-               // FIXME: do something depending on the cursor shape.
-               if (show_ && rect_.isValid())
-                       painter.fillRect(rect_, color_);
+               if (show_ && rect_.isValid()) {
+                       switch (shape_) {
+                       case L_SHAPE:
+                               painter.fillRect(rect_.x(), rect_.y(), CursorWidth, rect_.height(), color_);
+                               painter.setPen(color_);
+                               painter.drawLine(rect_.bottomLeft().x() + CursorWidth, rect_.bottomLeft().y(),
+                                                                                                rect_.bottomRight().x(), rect_.bottomLeft().y());
+                               break;
+                       
+                       case REVERSED_L_SHAPE:
+                               painter.fillRect(rect_.x() + rect_.height() / 3, rect_.y(), CursorWidth, rect_.height(), color_);
+                               painter.setPen(color_);
+                               painter.drawLine(rect_.bottomRight().x() - CursorWidth, rect_.bottomLeft().y(),
+                                                                                                        rect_.bottomLeft().x(), rect_.bottomLeft().y());
+                               break;
+                                       
+                       default:
+                               painter.fillRect(rect_, color_);
+                               break;
+                       }
+               }
        }
 
        void update(int x, int y, int h, CursorShape shape)
        {
                color_ = guiApp->colorCache().get(Color::cursor);
-               rect_ = QRect(x, y, CursorWidth, h);
                shape_ = shape;
+               switch (shape) {
+               case L_SHAPE:
+                       rect_ = QRect(x, y, CursorWidth + h / 3, h);
+                       break;
+               case REVERSED_L_SHAPE:
+                       rect_ = QRect(x - h / 3, y, CursorWidth + h / 3, h);
+                       break;
+               default: 
+                       rect_ = QRect(x, y, CursorWidth, h);
+                       break;
+               }
        }
 
        void show(bool set_show = true) { show_ = set_show; }
@@ -159,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());
@@ -182,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));
@@ -231,34 +241,23 @@ void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step
 }
 
 
-void GuiWorkArea::adjustViewWithScrollBar(int)
-{
-       scrollBufferView(verticalScrollBar()->sliderPosition());
-}
-
-
-void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
+void GuiWorkArea::adjustViewWithScrollBar(int action)
 {
-       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)
-{
-       QList<QUrl> 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();
 }
 
 
@@ -268,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();
 }
 
@@ -414,6 +409,20 @@ void GuiWorkArea::generateSyntheticMouseEvent()
 
 void GuiWorkArea::keyPressEvent(QKeyEvent * e)
 {
+       // do nothing if there are other events
+       // (the auto repeated events come too fast)
+       // \todo FIXME: remove hard coded Qt keys, process the key binding
+#ifdef Q_WS_X11
+       if (XEventsQueued(QX11Info::display(), 0) > 1 && e->isAutoRepeat() 
+                       && (Qt::Key_PageDown || Qt::Key_PageUp)) {
+               LYXERR(Debug::KEY)      
+                       << BOOST_CURRENT_FUNCTION << endl
+                       << "system is busy: scroll key event ignored" << endl;
+               e->ignore();
+               return;
+       }
+#endif
+
        LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
                << " count=" << e->count()
                << " text=" << fromqstr(e->text())
@@ -421,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);
@@ -455,52 +467,9 @@ 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[LyXFont::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(); 
+       QRect const rc = ev->rect();
        /*
        LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
                << " y: " << rc.y()
@@ -513,6 +482,8 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
                screen_ = QPixmap(viewport()->width(), viewport()->height());
                resizeBufferView();
                updateScreen();
+               WorkArea::hideCursor();
+               WorkArea::showCursor();
                need_resize_ = false;
        }
 
@@ -531,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();
@@ -580,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
@@ -601,7 +557,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                }
        }
 
-       // Hide the cursor during the kana-kanji transformation. 
+       // Hide the cursor during the kana-kanji transformation.
        if (preedit_string.empty())
                startBlinkingCursor();
        else
@@ -610,15 +566,15 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
        // last_width : for checking if last preedit string was/wasn't empty.
        static bool last_width = false;
        if (!last_width && preedit_string.empty()) {
-               // if last_width is last length of preedit string. 
+               // if last_width is last length of preedit string.
                e->accept();
                return;
        }
 
-       QLPainter pain(&screen_);
+       GuiPainter pain(&screen_);
        buffer_view_->updateMetrics(false);
-       paintText(*buffer_view_, pain);
-       LyXFont font = buffer_view_->cursor().getFont();
+       buffer_view_->draw(pain);
+       Font font = buffer_view_->cursor().getFont();
        FontMetrics const & fm = theFontMetrics(font);
        int height = fm.maxHeight();
        int cur_x = cursor_->rect().left();
@@ -698,7 +654,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                // that we are in selecting mode in the input method.
                // FIXME: rLength == preedit_length is not a changing condition
                // FIXME: should be put out of the loop.
-               if (pos >= rStart 
+               if (pos >= rStart
                        && pos < rStart + rLength
                        && !(cursor_pos < rLength && rLength == preedit_length))
                        ps = Painter::preedit_selecting;