]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
Two separators collapse into one
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index 346295d37000c3c848a82e0d6d2c4c7a4442ba2e..aa5e285da733a6e6bdb76727f5a08368e6b44d57 100644 (file)
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/gettext.h"
-#include "support/FileName.h"
 #include "support/lassert.h"
+#include "support/TempFile.h"
 
 #include "frontends/Application.h"
 #include "frontends/FontMetrics.h"
 #include "frontends/WorkAreaManager.h"
 
 #include <QContextMenuEvent>
+#if (QT_VERSION < 0x050000)
 #include <QInputContext>
+#endif
+#include <QDrag>
 #include <QHelpEvent>
-#ifdef Q_WS_MACX
-#include <QMacStyle>
+#ifdef Q_OS_MAC
+#include <QProxyStyle>
 #endif
 #include <QMainWindow>
+#include <QMimeData>
 #include <QMenu>
 #include <QPainter>
 #include <QPalette>
 #include <QPixmapCache>
 #include <QScrollBar>
+#include <QStyleOption>
+#include <QStylePainter>
 #include <QTimer>
 #include <QToolButton>
 #include <QToolTip>
@@ -74,6 +80,7 @@
 #include "support/bind.h"
 
 #include <cmath>
+#include <iostream>
 
 int const TabIndicatorWidth = 3;
 
@@ -125,7 +132,9 @@ namespace frontend {
 
 class CursorWidget {
 public:
-       CursorWidget() {
+       CursorWidget() : rtl_(false), l_shape_(false), completable_(false),
+               show_(false), x_(0), cursor_width_(0)
+       {
                recomputeWidth();
        }
 
@@ -237,9 +246,12 @@ 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),
-completer_(new GuiCompleter(p, p))
+: p(parent), screen_(0), buffer_view_(0), lyx_view_(0),
+  cursor_visible_(false), cursor_(0),
+  need_resize_(false), schedule_redraw_(false), preedit_lines_(1),
+  pixel_ratio_(1.0),
+  completer_(new GuiCompleter(p, p)), dialog_mode_(false),
+  read_only_(false), clean_(true)
 {
 }
 
@@ -254,11 +266,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
@@ -369,6 +392,7 @@ void GuiWorkArea::setBuffer(Buffer & buffer)
        if (buffer.text().paragraphs().size() > 4)
                setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
        QTimer::singleShot(50, this, SLOT(fixVerticalScrollBar()));
+       Q_EMIT bufferViewChanged();
 }
 
 
@@ -482,6 +506,14 @@ void GuiWorkArea::redraw(bool update_metrics)
 }
 
 
+// Keep in sync with GuiWorkArea::processKeySym below
+bool GuiWorkArea::queryKeySym(KeySymbol const & key, KeyModifier mod) const
+{
+       return guiApp->queryKeySym(key, mod);
+}
+
+
+// Keep in sync with GuiWorkArea::queryKeySym above
 void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
 {
        if (d->lyx_view_->isFullScreen() && d->lyx_view_->menuBar()->isVisible()
@@ -499,28 +531,15 @@ void GuiWorkArea::processKeySym(KeySymbol const & key, KeyModifier mod)
 }
 
 
-void GuiWorkArea::Private::dispatch(FuncRequest const & cmd0, KeyModifier mod)
+void GuiWorkArea::Private::dispatch(FuncRequest const & cmd)
 {
        // Handle drag&drop
-       if (cmd0.action() == LFUN_FILE_OPEN) {
+       if (cmd.action() == LFUN_FILE_OPEN) {
                DispatchResult dr;
-               lyx_view_->dispatch(cmd0, dr);
+               lyx_view_->dispatch(cmd, dr);
                return;
        }
 
-       FuncRequest cmd;
-
-       if (cmd0.action() == LFUN_MOUSE_PRESS) {
-               if (mod == ShiftModifier)
-                       cmd = FuncRequest(cmd0, "region-select");
-               else if (mod == ControlModifier)
-                       cmd = FuncRequest(cmd0, "paragraph-select");
-               else
-                       cmd = cmd0;
-       }
-       else
-               cmd = cmd0;
-
        bool const notJustMovingTheMouse =
                cmd.action() != LFUN_MOUSE_MOTION || cmd.button() != mouse_button::none;
 
@@ -621,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);
 }
 
@@ -647,14 +672,13 @@ void GuiWorkArea::toggleCursor()
 void GuiWorkArea::Private::updateScrollbar()
 {
        ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
-       // WARNING: don't touch at the scrollbar value like this:
-       //   verticalScrollBar()->setValue(scroll_.position);
-       // because this would cause a recursive signal/slot calling with
-       // GuiWorkArea::scrollTo
+       // Block signals to prevent setRange() and setSliderPosition from causing
+       // recursive calls via the signal valueChanged. (#10311)
+       QSignalBlocker blocker(p->verticalScrollBar());
        p->verticalScrollBar()->setRange(scroll_.min, scroll_.max);
        p->verticalScrollBar()->setPageStep(scroll_.page_step);
        p->verticalScrollBar()->setSingleStep(scroll_.single_step);
-       p->verticalScrollBar()->setSliderPosition(scroll_.position);
+       p->verticalScrollBar()->setSliderPosition(0);
 }
 
 
@@ -670,7 +694,10 @@ void GuiWorkArea::scrollTo(int value)
        }
        // Show the cursor immediately after any operation.
        startBlinkingCursor();
+       // FIXME QT5
+#ifdef Q_WS_X11
        QApplication::syncX();
+#endif
 }
 
 
@@ -683,7 +710,7 @@ bool GuiWorkArea::event(QEvent * e)
                        QPoint pos = helpEvent->pos();
                        if (pos.x() < viewport()->width()) {
                                QString s = toqstr(d->buffer_view_->toolTip(pos.x(), pos.y()));
-                               QToolTip::showText(helpEvent->globalPos(), s);
+                               QToolTip::showText(helpEvent->globalPos(), formatToolTip(s,35));
                        }
                        else
                                QToolTip::hideText();
@@ -693,7 +720,13 @@ bool GuiWorkArea::event(QEvent * e)
                return true;
        }
 
-       case QEvent::ShortcutOverride: {
+       case QEvent::ShortcutOverride:
+               // keyPressEvent is ShortcutOverride-aware and only accepts the event in
+               // this case
+               keyPressEvent(static_cast<QKeyEvent *>(e));
+               return e->isAccepted();
+
+       case QEvent::KeyPress: {
                // We catch this event in order to catch the Tab or Shift+Tab key press
                // which are otherwise reserved to focus switching between controls
                // within a dialog.
@@ -784,17 +817,19 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e)
        if (d->dc_event_.active && d->dc_event_ == *e) {
                d->dc_event_.active = false;
                FuncRequest cmd(LFUN_MOUSE_TRIPLE, e->x(), e->y(),
-                       q_button_state(e->button()));
+                       q_button_state(e->button()), q_key_state(e->modifiers()));
                d->dispatch(cmd);
                e->accept();
                return;
        }
 
+#if (QT_VERSION < 0x050000) && !defined(__HAIKU__)
        inputContext()->reset();
+#endif
 
        FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
-               q_button_state(e->button()));
-       d->dispatch(cmd, q_key_state(e->modifiers()));
+                       q_button_state(e->button()), q_key_state(e->modifiers()));
+       d->dispatch(cmd);
 
        // Save the context menu on mouse press, because also the mouse
        // cursor is set on mouse press. Afterwards, we can either release
@@ -814,7 +849,7 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e)
                d->synthetic_mouse_event_.timeout.stop();
 
        FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
-                             q_button_state(e->button()));
+                       q_button_state(e->button()), q_key_state(e->modifiers()));
        d->dispatch(cmd);
        e->accept();
 }
@@ -825,7 +860,7 @@ void GuiWorkArea::mouseMoveEvent(QMouseEvent * e)
        // we kill the triple click if we move
        doubleClickTimeout();
        FuncRequest cmd(LFUN_MOUSE_MOTION, e->x(), e->y(),
-               q_motion_state(e->buttons()));
+                       q_motion_state(e->buttons()), q_key_state(e->modifiers()));
 
        e->accept();
 
@@ -904,8 +939,10 @@ void GuiWorkArea::wheelEvent(QWheelEvent * ev)
        int const lines = qApp->wheelScrollLines();
        int const page_step = verticalScrollBar()->pageStep();
        // Test if the wheel mouse is set to one screen at a time.
-       int scroll_value = lines > page_step
-               ? page_step : lines * verticalScrollBar()->singleStep();
+       // This is according to
+       // https://doc.qt.io/qt-5/qapplication.html#wheelScrollLines-prop
+       int scroll_value =
+               min(lines * verticalScrollBar()->singleStep(), page_step);
 
        // Take into account the rotation and the user preferences.
        scroll_value = int(scroll_value * delta * lyxrc.mouse_wheel_speed);
@@ -958,7 +995,7 @@ void GuiWorkArea::generateSyntheticMouseEvent()
                d->buffer_view_->scroll(up ? -step : step);
                d->buffer_view_->updateMetrics();
        } else {
-               d->buffer_view_->scrollDocView(value + up ? -step : step, false);
+               d->buffer_view_->scrollDocView(value + (up ? -step : step), false);
        }
 
        // In which paragraph do we have to set the cursor ?
@@ -987,11 +1024,11 @@ void GuiWorkArea::generateSyntheticMouseEvent()
                        break;
                yy += h;
        }
-       
+
        // Find the position of the cursor
        bool bound;
        int x = d->synthetic_mouse_event_.cmd.x();
-       pos_type const pos = rit->pos() + tm.getColumnNearX(pit, *rit, x, bound);
+       pos_type const pos = tm.getPosNearX(*rit, x, bound);
 
        // Set the cursor
        cur.pit() = pit;
@@ -1005,6 +1042,10 @@ void GuiWorkArea::generateSyntheticMouseEvent()
 
 void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
 {
+       // this is also called for ShortcutOverride events. In this case, one must
+       // not act but simply accept the event explicitly.
+       bool const act = (ev->type() != QEvent::ShortcutOverride);
+
        // Do not process here some keys if dialog_mode_ is set
        if (d->dialog_mode_
                && (ev->modifiers() == Qt::NoModifier
@@ -1022,7 +1063,8 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
                switch (ev->key()) {
                case Qt::Key_Enter:
                case Qt::Key_Return:
-                       d->completer_->activate();
+                       if (act)
+                               d->completer_->activate();
                        ev->accept();
                        return;
                }
@@ -1031,8 +1073,10 @@ 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 (qApp->hasPendingEvents() && ev->isAutoRepeat()) {
+#if defined(Q_WS_X11) || defined(QPA_XCB)
+       // FIXME: this is a weird way to implement event compression. Also, this is
+       // broken with IBus.
+       if (act && qApp->hasPendingEvents() && ev->isAutoRepeat()) {
                switch (ev->key()) {
                case Qt::Key_PageDown:
                case Qt::Key_PageUp:
@@ -1047,7 +1091,7 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
        }
 #endif
 
-       KeyModifier m = q_key_state(ev->modifiers());
+       KeyModifier const m = q_key_state(ev->modifiers());
 
        std::string str;
        if (m & ShiftModifier)
@@ -1058,16 +1102,20 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * ev)
                str += "Alt-";
        if (m & MetaModifier)
                str += "Meta-";
-       
-       LYXERR(Debug::KEY, " count: " << ev->count() << " text: " << ev->text()
-               << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key()
-               << " keyState: " << str);
+
+       if (act)
+               LYXERR(Debug::KEY, " count: " << ev->count() << " text: " << ev->text()
+                      << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key()
+                      << " keyState: " << str);
 
        KeySymbol sym;
        setKeySymbol(&sym, ev);
        if (sym.isOK()) {
-               processKeySym(sym, q_key_state(ev->modifiers()));
-               ev->accept();
+               if (act) {
+                       processKeySym(sym, m);
+                       ev->accept();
+               } else
+                       ev->setAccepted(queryKeySym(sym, m));
        } else {
                ev->ignore();
        }
@@ -1084,10 +1132,9 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * ev)
 {
        d->dc_event_ = DoubleClick(ev);
        QTimer::singleShot(QApplication::doubleClickInterval(), this,
-                          SLOT(doubleClickTimeout()));
-       FuncRequest cmd(LFUN_MOUSE_DOUBLE,
-                       ev->x(), ev->y(),
-                       q_button_state(ev->button()));
+                       SLOT(doubleClickTimeout()));
+       FuncRequest cmd(LFUN_MOUSE_DOUBLE, ev->x(), ev->y(),
+                       q_button_state(ev->button()), q_key_state(ev->modifiers()));
        d->dispatch(cmd);
        ev->accept();
 }
@@ -1109,11 +1156,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_) {
@@ -1123,10 +1170,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();
@@ -1135,7 +1187,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
 
 void GuiWorkArea::Private::updateScreen()
 {
-       GuiPainter pain(screen_);
+       GuiPainter pain(screen_, p->pixelRatio());
        buffer_view_->draw(pain);
 }
 
@@ -1200,6 +1252,8 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                stopBlinkingCursor();
 
        // last_width : for checking if last preedit string was/wasn't empty.
+       // FIXME THREAD && FIXME
+       // We could have more than one work area, right?
        static bool last_width = false;
        if (!last_width && preedit_string.empty()) {
                // if last_width is last length of preedit string.
@@ -1207,9 +1261,10 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e)
                return;
        }
 
-       GuiPainter pain(d->screen_);
+       GuiPainter pain(d->screen_, pixelRatio());
        d->buffer_view_->updateMetrics();
        d->buffer_view_->draw(pain);
+       // FIXME: shall we use real_current_font here? (see #10478)
        FontInfo font = d->buffer_view_->cursor().getFont().fontInfo();
        FontMetrics const & fm = theFontMetrics(font);
        int height = fm.maxHeight();
@@ -1334,33 +1389,14 @@ QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
 
 void GuiWorkArea::updateWindowTitle()
 {
-       docstring maximize_title;
-       docstring minimize_title;
-
-       Buffer const & buf = d->buffer_view_->buffer();
-       FileName const file_name = buf.fileName();
-       if (!file_name.empty()) {
-               maximize_title = file_name.displayName(130);
-               minimize_title = from_utf8(file_name.onlyFileName());
-               if (buf.lyxvc().inUse()) {
-                       if (buf.lyxvc().locking())
-                               maximize_title +=  _(" (version control, locking)");
-                       else
-                               maximize_title +=  _(" (version control)");
-               }
-               if (!buf.isClean()) {
-                       maximize_title += _(" (changed)");
-                       minimize_title += char_type('*');
-               }
-               if (buf.isReadonly())
-                       maximize_title += _(" (read only)");
-       }
-
-       QString const new_title = toqstr(maximize_title);
-       if (new_title != windowTitle()) {
-               QWidget::setWindowTitle(new_title);
-               QWidget::setWindowIconText(toqstr(minimize_title));
-               titleChanged(this);
+       Buffer const & buf = bufferView().buffer();
+       if (buf.fileName() != d->file_name_ || buf.isReadonly() != d->read_only_
+           || buf.lyxvc().vcstatus() != d->vc_status_ || buf.isClean() != d->clean_) {
+               d->file_name_ = buf.fileName();
+               d->read_only_ = buf.isReadonly();
+               d->vc_status_ = buf.lyxvc().vcstatus();
+               d->clean_ = buf.isClean();
+               Q_EMIT titleChanged(this);
        }
 }
 
@@ -1414,9 +1450,9 @@ GuiView & GuiWorkArea::view()
 
 EmbeddedWorkArea::EmbeddedWorkArea(QWidget * w): GuiWorkArea(w)
 {
-       buffer_ = theBufferList().newBuffer(
-               support::FileName::tempName("embedded.internal").absFileName());
-       buffer_->setInternal(true);
+       support::TempFile tempfile("embedded.internal");
+       tempfile.setAutoRemove(false);
+       buffer_ = theBufferList().newInternalBuffer(tempfile.name().absFileName());
        buffer_->setUnnamed(true);
        buffer_->setFullyLoaded(true);
        setBuffer(*buffer_);
@@ -1474,14 +1510,14 @@ void EmbeddedWorkArea::disable()
 //
 ////////////////////////////////////////////////////////////////////
 
-#ifdef Q_WS_MACX
-class NoTabFrameMacStyle : public QMacStyle {
+#ifdef Q_OS_MAC
+class NoTabFrameMacStyle : public QProxyStyle {
 public:
        ///
        QRect subElementRect(SubElement element, const QStyleOption * option,
                             const QWidget * widget = 0) const
        {
-               QRect rect = QMacStyle::subElementRect(element, option, widget);
+               QRect rect = QProxyStyle::subElementRect(element, option, widget);
                bool noBar = static_cast<QTabWidget const *>(widget)->count() <= 1;
 
                // The Qt Mac style puts the contents into a 3 pixel wide box
@@ -1503,14 +1539,11 @@ NoTabFrameMacStyle noTabFrameMacStyle;
 
 
 TabWorkArea::TabWorkArea(QWidget * parent)
-       : QTabWidget(parent), clicked_tab_(-1)
+       : QTabWidget(parent), clicked_tab_(-1), midpressed_tab_(-1)
 {
-#ifdef Q_WS_MACX
+#ifdef Q_OS_MAC
        setStyle(&noTabFrameMacStyle);
 #endif
-#if QT_VERSION < 0x040500
-       lyxrc.single_close_tab_button = true;
-#endif
 
        QPalette pal = palette();
        pal.setColor(QPalette::Active, QPalette::Button,
@@ -1526,7 +1559,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);
@@ -1547,24 +1580,77 @@ TabWorkArea::TabWorkArea(QWidget * parent)
        tb->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
                this, SLOT(showContextMenu(const QPoint &)));
-#if QT_VERSION >= 0x040500
        connect(tb, SIGNAL(tabCloseRequested(int)),
                this, SLOT(closeTab(int)));
-#endif
 
        setUsesScrollButtons(true);
 }
 
 
+void TabWorkArea::mousePressEvent(QMouseEvent *me)
+{
+       if (me->button() == Qt::MidButton)
+               midpressed_tab_ = tabBar()->tabAt(me->pos());
+       else
+               QTabWidget::mousePressEvent(me);
+}
+
+
+void TabWorkArea::mouseReleaseEvent(QMouseEvent *me)
+{
+       if (me->button() == Qt::MidButton) {
+               int const midreleased_tab = tabBar()->tabAt(me->pos());
+               if (midpressed_tab_ == midreleased_tab && posIsTab(me->pos()))
+                       closeTab(midreleased_tab);
+       } else
+               QTabWidget::mouseReleaseEvent(me);
+}
+
+
+void TabWorkArea::paintEvent(QPaintEvent * event)
+{
+       if (tabBar()->isVisible()) {
+               QTabWidget::paintEvent(event);
+       } else {
+               // Prevent the selected tab to influence the 
+               // painting of the frame of the tab widget.
+               // This is needed for gtk style in Qt.
+               QStylePainter p(this);
+#if QT_VERSION < 0x050000
+               QStyleOptionTabWidgetFrameV2 opt;
+#else
+               QStyleOptionTabWidgetFrame opt;
+#endif
+               initStyleOption(&opt);
+               opt.rect = style()->subElementRect(QStyle::SE_TabWidgetTabPane,
+                       &opt, this);
+               opt.selectedTabRect = QRect();
+               p.drawPrimitive(QStyle::PE_FrameTabWidget, opt);
+       }
+}
+
+
+bool TabWorkArea::posIsTab(QPoint position)
+{
+       // tabAt returns -1 if tab does not covers position
+       return tabBar()->tabAt(position) > -1;
+}
+
+
 void TabWorkArea::mouseDoubleClickEvent(QMouseEvent * event)
 {
        if (event->button() != Qt::LeftButton)
                return;
 
+       // this code chunk is unnecessary because it seems the event only makes
+       // it this far if it is not on a tab. I'm not sure why this is (maybe
+       // it is handled and ended in DragTabBar?), and thus I'm not sure if
+       // this is true in all cases and if it will be true in the future so I
+       // leave this code for now. (skostysh, 2016-07-21)
+       //
        // return early if double click on existing tabs
-       for (int i = 0; i < count(); ++i)
-               if (tabBar()->tabRect(i).contains(event->pos()))
-                       return;
+       if (posIsTab(event->pos()))
+               return;
 
        dispatch(FuncRequest(LFUN_BUFFER_NEW));
 }
@@ -1589,9 +1675,7 @@ void TabWorkArea::showBar(bool show)
        tabBar()->setEnabled(show);
        tabBar()->setVisible(show);
        closeBufferButton->setVisible(show && lyxrc.single_close_tab_button);
-#if QT_VERSION >= 0x040500
        setTabsClosable(!lyxrc.single_close_tab_button);
-#endif
 }
 
 
@@ -1601,7 +1685,7 @@ GuiWorkArea * TabWorkArea::currentWorkArea()
                return 0;
 
        GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(currentWidget());
-       LASSERT(wa, /**/);
+       LATTEST(wa);
        return wa;
 }
 
@@ -1630,7 +1714,7 @@ void TabWorkArea::closeAll()
 {
        while (count()) {
                GuiWorkArea * wa = workArea(0);
-               LASSERT(wa, /**/);
+               LASSERT(wa, return);
                removeTab(0);
                delete wa;
        }
@@ -1639,7 +1723,7 @@ void TabWorkArea::closeAll()
 
 bool TabWorkArea::setCurrentWorkArea(GuiWorkArea * work_area)
 {
-       LASSERT(work_area, /**/);
+       LASSERT(work_area, return false);
        int index = indexOf(work_area);
        if (index == -1)
                return false;
@@ -1732,7 +1816,7 @@ void TabWorkArea::closeCurrentBuffer()
                wa = currentWorkArea();
        else {
                wa = workArea(clicked_tab_);
-               LASSERT(wa, /**/);
+               LASSERT(wa, return);
        }
        wa->view().closeWorkArea(wa);
 }
@@ -1745,7 +1829,7 @@ void TabWorkArea::hideCurrentTab()
                wa = currentWorkArea();
        else {
                wa = workArea(clicked_tab_);
-               LASSERT(wa, /**/);
+               LASSERT(wa, return);
        }
        wa->view().hideWorkArea(wa);
 }
@@ -1759,7 +1843,7 @@ void TabWorkArea::closeTab(int index)
                wa = currentWorkArea();
        else {
                wa = workArea(index);
-               LASSERT(wa, /**/);
+               LASSERT(wa, return);
        }
        wa->view().closeWorkArea(wa);
 }
@@ -1769,6 +1853,7 @@ void TabWorkArea::closeTab(int index)
 class DisplayPath {
 public:
        /// make vector happy
+       // coverity[UNINIT_CTOR]
        DisplayPath() {}
        ///
        DisplayPath(int tab, FileName const & filename)
@@ -1799,7 +1884,7 @@ public:
 
                if (!dotted) {
                        if (dottedPrefix_ && !prefix_.isEmpty())
-                               prefix_ += ".../";
+                               prefix_ += ellipsisSlash_;
                        prefix_ += postfix_.front() + "/";
                }
                dottedPrefix_ = dotted && !prefix_.isEmpty();
@@ -1812,7 +1897,7 @@ public:
                        return filename_;
 
                bool dots = dottedPrefix_ || !postfix_.isEmpty();
-               return prefix_ + (dots ? ".../" : "") + filename_;
+               return prefix_ + (dots ? ellipsisSlash_ : "") + filename_;
        }
        ///
        QString forecastPathString() const
@@ -1821,7 +1906,7 @@ public:
                        return displayString();
 
                return prefix_
-                       + (dottedPrefix_ ? ".../" : "")
+                       + (dottedPrefix_ ? ellipsisSlash_ : "")
                        + postfix_.front() + "/";
        }
        ///
@@ -1830,6 +1915,8 @@ public:
        int tab() const { return tab_; }
 
 private:
+       /// ".../"
+       static QString const ellipsisSlash_;
        ///
        QString prefix_;
        ///
@@ -1845,6 +1932,9 @@ private:
 };
 
 
+QString const DisplayPath::ellipsisSlash_ = QString(QChar(0x2026)) + "/";
+
+
 ///
 bool operator<(DisplayPath const & a, DisplayPath const & b)
 {
@@ -1920,6 +2010,8 @@ void TabWorkArea::updateTabTexts()
                        // that it makes the path more unique.
                        somethingChanged = true;
                        It sit = segStart;
+                       // this is ok for the reason mentioned  in the previous comment.
+                       // coverity[INVALIDATE_ITERATOR]
                        QString dspString = sit->forecastPathString();
                        LYXERR(Debug::GUI, "first forecast found for "
                               << sit->abs() << " => " << dspString);
@@ -1955,11 +2047,17 @@ void TabWorkArea::updateTabTexts()
        for (It it = paths.begin(); it != paths.end(); ++it) {
                int const tab_index = it->tab();
                Buffer const & buf = workArea(tab_index)->bufferView().buffer();
-               QString tab_text = it->displayString();
+               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);
        }
 }
 
@@ -1973,9 +2071,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));
 
@@ -2000,25 +2098,10 @@ DragTabBar::DragTabBar(QWidget* parent)
        : QTabBar(parent)
 {
        setAcceptDrops(true);
-#if QT_VERSION >= 0x040500
        setTabsClosable(!lyxrc.single_close_tab_button);
-#endif
 }
 
 
-#if QT_VERSION < 0x040300
-int DragTabBar::tabAt(QPoint const & position) const
-{
-       const int max = count();
-       for (int i = 0; i < max; ++i) {
-               if (tabRect(i).contains(position))
-                       return i;
-       }
-       return -1;
-}
-#endif
-
-
 void DragTabBar::mousePressEvent(QMouseEvent * event)
 {
        if (event->button() == Qt::LeftButton)
@@ -2057,17 +2140,12 @@ void DragTabBar::mouseMoveEvent(QMouseEvent * event)
        mimeData->setData("action", "tab-reordering") ;
        drag->setMimeData(mimeData);
 
-#if QT_VERSION >= 0x040300
        // get tab pixmap as cursor
        QRect r = tabRect(tab);
        QPixmap pixmap(r.size());
        render(&pixmap, - r.topLeft());
        drag->setPixmap(pixmap);
        drag->exec();
-#else
-       drag->start(Qt::MoveAction);
-#endif
-
 }