]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
Use QFontMetrics information for underlines (and friends) width and position
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index e5b2cf57c950cbdd4651a6038f3a75e475123659..2411206771be4cd6c0b6f7bfc467bf7b0d2f81d5 100644 (file)
@@ -246,6 +246,7 @@ SyntheticMouseEvent::SyntheticMouseEvent()
 GuiWorkArea::Private::Private(GuiWorkArea * parent)
 : p(parent), screen_(0), buffer_view_(0), lyx_view_(0), cursor_visible_(false),
 need_resize_(false), schedule_redraw_(false), preedit_lines_(1),
+pixel_ratio_(1.0),
 completer_(new GuiCompleter(p, p))
 {
 }
@@ -261,11 +262,22 @@ GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & gv)
 : d(new Private(this))
 {
        setGuiView(gv);
+       buffer.params().display_pixel_ratio = theGuiApp()->pixelRatio();
        setBuffer(buffer);
        init();
 }
 
 
+double GuiWorkArea::pixelRatio() const
+{
+#if QT_VERSION >= 0x050000
+       return devicePixelRatio();
+#else
+       return 1.0;
+#endif
+}
+
+
 void GuiWorkArea::init()
 {
        // Setup the signals
@@ -628,6 +640,12 @@ void GuiWorkArea::Private::showCursor()
                && !completer_->inlineVisible();
        cursor_visible_ = true;
        cursor_->recomputeWidth();
+
+       //int cur_x = buffer_view_->getPos(cur).x_;
+       // We may have decided to slide the cursor row so that cursor
+       // is visible.
+       p.x_ -= buffer_view_->horizScrollOffset();
+
        showCursor(p.x_, p.y_, h, l_shape, isrtl, completable);
 }
 
@@ -677,6 +695,7 @@ void GuiWorkArea::scrollTo(int value)
        }
        // Show the cursor immediately after any operation.
        startBlinkingCursor();
+       // FIXME QT5
 #ifdef Q_WS_X11
        QApplication::syncX();
 #endif
@@ -799,7 +818,7 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
                return;
        }
 
-#if (QT_VERSION < 0x050000)
+#if (QT_VERSION < 0x050000) && !defined(__HAIKU__)
        inputContext()->reset();
 #endif
 
@@ -1042,7 +1061,7 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
        // do nothing if there are other events
        // (the auto repeated events come too fast)
        // it looks like this is only needed on X11
-#ifdef Q_WS_X11
+#if defined(Q_WS_X11) || defined(QPA_XCB)
        if (qApp->hasPendingEvents() && ev->isAutoRepeat()) {
                switch (ev->key()) {
                case Qt::Key_PageDown:
@@ -1120,11 +1139,11 @@ void GuiWorkArea::Private::update(int x, int y, int w, int h)
 
 void GuiWorkArea::paintEvent(QPaintEvent * ev)
 {
-       QRect const rc = ev->rect();
+       QRectF const rc = ev->rect();
        // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
        //      << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
 
-       if (d->need_resize_) {
+       if (d->needResize()) {
                d->resetScreen();
                d->resizeBufferView();
                if (d->cursor_visible_) {
@@ -1134,10 +1153,15 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
        }
 
        QPainter pain(viewport());
+       double const pr = pixelRatio();
+       QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr, rc.width() * pr, rc.height() * pr);
+
        if (lyxrc.use_qimage) {
-               pain.drawImage(rc, static_cast<QImage const &>(*d->screen_), rc);
+               QImage const & image = static_cast<QImage const &>(*d->screen_);
+               pain.drawImage(rc, image, rcs);
        } else {
-               pain.drawPixmap(rc, static_cast<QPixmap const &>(*d->screen_), rc);
+               QPixmap const & pixmap = static_cast<QPixmap const &>(*d->screen_);
+               pain.drawPixmap(rc, pixmap, rcs);
        }
        d->cursor_->draw(pain);
        ev->accept();
@@ -1146,7 +1170,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
 
 void GuiWorkArea::Private::updateScreen()
 {
-       GuiPainter pain(screen_);
+       GuiPainter pain(screen_, p->pixelRatio());
        buffer_view_->draw(pain);
 }
 
@@ -1220,7 +1244,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                return;
        }
 
-       GuiPainter pain(d->screen_);
+       GuiPainter pain(d->screen_, pixelRatio());
        d->buffer_view_->updateMetrics();
        d->buffer_view_->draw(pain);
        FontInfo font = d->buffer_view_->cursor().getFont().fontInfo();
@@ -1536,7 +1560,7 @@ TabWorkArea::TabWorkArea(QWidget * parent)
        closeBufferButton = new QToolButton(this);
        closeBufferButton->setPalette(pal);
        // FIXME: rename the icon to closebuffer.png
-       closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "png")));
+       closeBufferButton->setIcon(QIcon(getPixmap("images/", "closetab", "svgz,png")));
        closeBufferButton->setText("Close File");
        closeBufferButton->setAutoRaise(true);
        closeBufferButton->setCursor(Qt::ArrowCursor);
@@ -1987,8 +2011,14 @@ void TabWorkArea::updateTabTexts()
                QString tab_text = it->displayString().replace("&", "&&");
                if (!buf.fileName().empty() && !buf.isClean())
                        tab_text += "*";
+               QString tab_tooltip = it->abs();
+               if (buf.isReadonly()) {
+                       setTabIcon(tab_index, QIcon(getPixmap("images/", "emblem-readonly", "svgz,png")));
+                       tab_tooltip = qt_("%1 (read only)").arg(it->abs());
+               } else
+                       setTabIcon(tab_index, QIcon());
                setTabText(tab_index, tab_text);
-               setTabToolTip(tab_index, it->abs());
+               setTabToolTip(tab_index, tab_tooltip);
        }
 }
 
@@ -2002,9 +2032,9 @@ void TabWorkArea::showContextMenu(const QPoint & pos)
 
        // show tab popup
        QMenu popup;
-       popup.addAction(QIcon(getPixmap("images/", "hidetab", "png")),
+       popup.addAction(QIcon(getPixmap("images/", "hidetab", "svgz,png")),
                qt_("Hide tab"), this, SLOT(hideCurrentTab()));
-       popup.addAction(QIcon(getPixmap("images/", "closetab", "png")),
+       popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")),
                qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
        popup.exec(tabBar()->mapToGlobal(pos));