]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.C
enable Font cache only for MacOSX and inline width() for other platform.
[lyx.git] / src / frontends / qt4 / GuiWorkArea.C
index 47464a2b86aa2eadb30552c69d3f0f06a49b3c6b..dfbf30fbca6fe50b2bd944cbd47cb096678461b9 100644 (file)
@@ -9,23 +9,22 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#undef QT3_SUPPORT
-
 #include <config.h>
 
-
 #include "GuiWorkArea.h"
 
+#include "GuiApplication.h"
 #include "QLPainter.h"
 #include "QLyXKeySym.h"
-
-#include "ColorCache.h"
 #include "qt_helpers.h"
-#include "Application.h"
+
+#include "LyXView.h"
+
 #include "BufferView.h"
 #include "debug.h"
 #include "funcrequest.h"
 #include "LColor.h"
+
 #include "support/os.h"
 
 #include <QLayout>
@@ -129,16 +128,11 @@ GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
 
        viewport()->setAutoFillBackground(false);
        viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
-
-       viewport()->setFocusPolicy(Qt::WheelFocus);
-       viewport()->setFocus();
        setFocusPolicy(Qt::WheelFocus);
 
        viewport()->setCursor(Qt::IBeamCursor);
 
        resize(w, h);
-       workWidth_ = w;
-       workHeight_ = h;
 
        synthetic_mouse_event_.timeout.timeout.connect(
                boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
@@ -149,7 +143,7 @@ GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
                this, SLOT(adjustViewWithScrollBar(int)));
 
        // PageStep only depends on the viewport height.
-       verticalScrollBar()->setPageStep(workHeight_);
+       verticalScrollBar()->setPageStep(viewport()->height());
 
        lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
                << "\n Area width\t" << width()
@@ -177,6 +171,7 @@ GuiWorkArea::GuiWorkArea(int w, int h, LyXView & lyx_view)
        setAttribute(Qt::WA_InputMethodEnabled, true);
 }
 
+
 GuiWorkArea::~GuiWorkArea()
 {
 }
@@ -222,7 +217,7 @@ void GuiWorkArea::dropEvent(QDropEvent* event)
 
        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).toString()));
+               string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
                if (!file.empty())
                        dispatch(FuncRequest(LFUN_FILE_OPEN, file));
        }
@@ -423,36 +418,14 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
 
 void GuiWorkArea::resizeEvent(QResizeEvent *)
 {
-       workWidth_ = viewport()->width();
-       workHeight_ = viewport()->height();
-
        verticalScrollBar()->setPageStep(viewport()->height());
-
-//     screen_device_ = QPixmap(viewport()->width(), viewport()->height());
-//     paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32);
        paint_device_ = QPixmap(viewport()->width(), viewport()->height());
-
        resizeBufferView();
-
-       /*
-       lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
-               << "\n QWidget width\t" << this->QWidget::width()
-               << "\n QWidget height\t" << this->QWidget::height()
-               << "\n viewport width\t" << viewport()->width()
-               << "\n viewport height\t" << viewport()->height()
-               << "\n QResizeEvent rect left\t" << rect().left()
-               << "\n QResizeEvent rect right\t" << rect().right()
-               << endl;
-               */
 }
 
 
 void GuiWorkArea::update(int x, int y, int w, int h)
 {
-       //screen_device_.fromImage(paint_device_);
-       //QPainter q(&screen_device_);
-       //q.drawImage(x, y, paint_device_.copy(x, y, w, h));
-
        viewport()->update(x, y, w, h);
 }
 
@@ -519,7 +492,7 @@ void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
 
        show_vcursor_ = true;
 
-       QColor const & required_color = lcolorcache.get(LColor::cursor);
+       QColor const & required_color = guiApp->colorCache().get(LColor::cursor);
 
        if (x==cursor_x_ && y==cursor_y_ && h==cursor_h_
                && cursor_color_ == required_color
@@ -596,13 +569,29 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                // ideally, such special coding should not be necessary
                if (text == "^")
                        key = Qt::Key_AsciiCircum;
-               QKeyEvent ev(QEvent::KeyPress, key, 0, text);
+               // FIXME: Needs for investigation, this key is not really used,
+               // the ctor below just check if key is different from 0.
+               QKeyEvent ev(QEvent::KeyPress, key,
+                       Qt::NoModifier, text);
                keyPressEvent(&ev);
        }
        e->accept();
 }
 
 
+void GuiWorkArea::focusInEvent(QFocusEvent * ev)
+{
+       QAbstractScrollArea::focusInEvent(ev);
+       lyx_view_.updateToolbars();
+}
+
+
+void GuiWorkArea::focusOutEvent(QFocusEvent * ev)
+{
+       QAbstractScrollArea::focusOutEvent(ev);
+       lyx_view_.updateToolbars();
+}
+
 } // namespace frontend
 } // namespace lyx