]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.cpp
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiWorkArea.cpp
index 11f8da81fd3415e8fa20d942dfd49545b629610a..001056df72abb1bdd551b007ae039982d010c59a 100644 (file)
@@ -639,7 +639,7 @@ void GuiWorkArea::Private::showCaret()
                return;
 
        updateCaretGeometry();
-       p->viewport()->update(caret_->rect());
+       p->viewport()->update();
 }
 
 
@@ -650,7 +650,7 @@ void GuiWorkArea::Private::hideCaret()
 
        caret_visible_ = false;
        //if (!qApp->focusWidget())
-               p->viewport()->update(caret_->rect());
+               p->viewport()->update();
 }
 
 
@@ -1556,19 +1556,19 @@ TabWorkArea::TabWorkArea(QWidget * parent)
                this, SLOT(closeCurrentBuffer()));
        setCornerWidget(closeBufferButton, Qt::TopRightCorner);
 
-       // setup drag'n'drop
-       QTabBar* tb = new DragTabBar;
-       connect(tb, SIGNAL(tabMoveRequested(int, int)),
-               this, SLOT(moveTab(int, int)));
+       // set TabBar behaviour
+       QTabBar * tb = tabBar();
+       tb->setTabsClosable(!lyxrc.single_close_tab_button);
+       tb->setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab);
        tb->setElideMode(Qt::ElideNone);
-       setTabBar(tb);
-
+       // allow dragging tabs
+       tb->setMovable(true);
        // make us responsible for the context menu of the tabbar
        tb->setContextMenuPolicy(Qt::CustomContextMenu);
        connect(tb, SIGNAL(customContextMenuRequested(const QPoint &)),
-               this, SLOT(showContextMenu(const QPoint &)));
+               this, SLOT(showContextMenu(const QPoint &)));
        connect(tb, SIGNAL(tabCloseRequested(int)),
-               this, SLOT(closeTab(int)));
+               this, SLOT(closeTab(int)));
 
        setUsesScrollButtons(true);
 }
@@ -1871,9 +1871,12 @@ public:
        DisplayPath(int tab, FileName const & filename)
                : tab_(tab)
        {
+               // Recode URL encoded chars via fromPercentEncoding()
                filename_ = (filename.extension() == "lyx") ?
-                       toqstr(filename.onlyFileNameWithoutExt())
-                       : toqstr(filename.onlyFileName());
+                       QString(QByteArray::fromPercentEncoding(
+                                       toqstr(filename.onlyFileNameWithoutExt()).toUtf8()))
+                       : QString(QByteArray::fromPercentEncoding(
+                                         toqstr(filename.onlyFileName()).toUtf8()));
                postfix_ = toqstr(filename.absoluteFilePath()).
                        split("/", QString::SkipEmptyParts);
                postfix_.pop_back();
@@ -2083,16 +2086,23 @@ void TabWorkArea::updateTabTexts()
 void TabWorkArea::showContextMenu(const QPoint & pos)
 {
        // which tab?
-       clicked_tab_ = static_cast<DragTabBar *>(tabBar())->tabAt(pos);
+       clicked_tab_ = tabBar()->tabAt(pos);
        if (clicked_tab_ == -1)
                return;
 
+       GuiWorkArea * wa = workArea(clicked_tab_);
+       LASSERT(wa, return);
+
        // show tab popup
        QMenu popup;
        popup.addAction(QIcon(getPixmap("images/", "hidetab", "svgz,png")),
                qt_("Hide tab"), this, SLOT(hideCurrentTab()));
-       popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")),
-               qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
+
+       // we want to show the 'close' option only if this is not a child buffer.
+       Buffer const & buf = wa->bufferView().buffer();
+       if (!buf.parent())
+               popup.addAction(QIcon(getPixmap("images/", "closetab", "svgz,png")),
+                       qt_("Close tab"), this, SLOT(closeCurrentBuffer()));
        popup.exec(tabBar()->mapToGlobal(pos));
 
        clicked_tab_ = -1;
@@ -2112,84 +2122,6 @@ void TabWorkArea::moveTab(int fromIndex, int toIndex)
 }
 
 
-DragTabBar::DragTabBar(QWidget* parent)
-       : QTabBar(parent)
-{
-       setAcceptDrops(true);
-       setTabsClosable(!lyxrc.single_close_tab_button);
-}
-
-
-void DragTabBar::mousePressEvent(QMouseEvent * event)
-{
-       if (event->button() == Qt::LeftButton)
-               dragStartPos_ = event->pos();
-       QTabBar::mousePressEvent(event);
-}
-
-
-void DragTabBar::mouseMoveEvent(QMouseEvent * event)
-{
-       // If the left button isn't pressed anymore then return
-       if (!(event->buttons() & Qt::LeftButton))
-               return;
-
-       // If the distance is too small then return
-       if ((event->pos() - dragStartPos_).manhattanLength()
-           < QApplication::startDragDistance())
-               return;
-
-       // did we hit something after all?
-       int tab = tabAt(dragStartPos_);
-       if (tab == -1)
-               return;
-
-       // simulate button release to remove highlight from button
-       int i = currentIndex();
-       QMouseEvent me(QEvent::MouseButtonRelease, dragStartPos_,
-               event->button(), event->buttons(), 0);
-       QTabBar::mouseReleaseEvent(&me);
-       setCurrentIndex(i);
-
-       // initiate Drag
-       QDrag * drag = new QDrag(this);
-       QMimeData * mimeData = new QMimeData;
-       // a crude way to distinguish tab-reodering drops from other ones
-       mimeData->setData("action", "tab-reordering") ;
-       drag->setMimeData(mimeData);
-
-       // get tab pixmap as cursor
-       QRect r = tabRect(tab);
-       QPixmap pixmap(r.size());
-       render(&pixmap, - r.topLeft());
-       drag->setPixmap(pixmap);
-       drag->exec();
-}
-
-
-void DragTabBar::dragEnterEvent(QDragEnterEvent * event)
-{
-       // Only accept if it's an tab-reordering request
-       QMimeData const * m = event->mimeData();
-       QStringList formats = m->formats();
-       if (formats.contains("action")
-           && m->data("action") == "tab-reordering")
-               event->acceptProposedAction();
-}
-
-
-void DragTabBar::dropEvent(QDropEvent * event)
-{
-       int fromIndex = tabAt(dragStartPos_);
-       int toIndex = tabAt(event->pos());
-
-       // Tell interested objects that
-       if (fromIndex != toIndex)
-               tabMoveRequested(fromIndex, toIndex);
-       event->acceptProposedAction();
-}
-
-
 GuiWorkAreaContainer::GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent)
        : QWidget(parent), wa_(wa)
 {