Attached a small patch and a png for a button
to close the current tab, see screen shot.
closetab.png have to go into lib/images.

Jose, please tell me when I could put it in.

Peter



Index: src/frontends/qt4/GuiView.h
===================================================================
--- src/frontends/qt4/GuiView.h (revision 18720)
+++ src/frontends/qt4/GuiView.h (working copy)
@@ -98,7 +98,8 @@
        /// populate a toplevel menu and all its children on demand
        void updateMenu(QAction *);
 
-       void currentTabChanged (int index);
+       void currentTabChanged(int index);
+       void closeCurrentTab();
 
        /// slots to change the icon size
        void smallSizedIcons();
Index: src/frontends/qt4/GuiView.cpp
===================================================================
--- src/frontends/qt4/GuiView.cpp       (revision 18720)
+++ src/frontends/qt4/GuiView.cpp       (working copy)
@@ -53,7 +53,10 @@
 #include <QTabBar>
 #include <QDesktopWidget>
 #include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QToolButton>
 
+
 #include <boost/bind.hpp>
 #include <boost/shared_ptr.hpp>
 
@@ -75,23 +78,54 @@
 
 class TabWidget : public QWidget
 {
+       QHBoxLayout* hlayout;
 public:
        QTabBar* tabbar;
+       QToolButton* closeTabButton;
 
+       void hideTabsIfNecessary()
+       {
+               if (tabbar->count() > 1) {
+                       tabbar->show();
+                       closeTabButton->show();
+               } else {
+                       tabbar->hide();
+                       closeTabButton->hide();
+               }
+       }
+
        TabWidget(QWidget* w, bool topTabBar)
        {
+           closeTabButton = new QToolButton(this);
+               FileName const file = support::libFileSearch("images", 
"closetab", "png");
+               if (!file.empty()) {
+                       QPixmap pm(toqstr(file.absFilename()));
+                       closeTabButton->setIcon(QIcon(pm));
+               } else {
+                       closeTabButton->setText("Close");
+               }
+               closeTabButton->setCursor(Qt::ArrowCursor);
+               closeTabButton->setAutoRaise(true);
+               closeTabButton->setToolTip(tr("Close tab"));
+               closeTabButton->setEnabled(true);
+
                tabbar = new QTabBar;
-               QVBoxLayout* layout = new QVBoxLayout;
+               hlayout = new QHBoxLayout;
+               QVBoxLayout* vlayout = new QVBoxLayout;
+               hlayout->addWidget(tabbar);
+               hlayout->addWidget(closeTabButton);
                if (topTabBar) {
-                       layout->addWidget(tabbar);
-                       layout->addWidget(w);
+                       vlayout->addLayout(hlayout);
+                       vlayout->addWidget(w);
                } else {
                        tabbar->setShape(QTabBar::RoundedSouth);
-                       layout->addWidget(w);
-                       layout->addWidget(tabbar);
+                       vlayout->addWidget(w);
+                       vlayout->addLayout(hlayout);
                }
-               layout->setMargin(0);
-               setLayout(layout);
+               vlayout->setMargin(0);
+               hlayout->setMargin(0);
+               setLayout(vlayout);
+               hideTabsIfNecessary();
        }
 
        void clearTabbar()
@@ -141,7 +175,6 @@
                QObject::connect(normalIcons, SIGNAL(triggered()), parent, 
SLOT(normalSizedIcons()));
                menu->addAction(normalIcons);
 
-
                QAction *bigIcons = new QAction(iconSizeGroup);
                bigIcons->setText(qt_("Big-sized icons"));
                bigIcons->setCheckable(true);
@@ -534,6 +567,8 @@
        setCentralWidget(d.tabWidget);
        QObject::connect(d.tabWidget->tabbar, SIGNAL(currentChanged(int)),
                        this, SLOT(currentTabChanged(int)));
+       QObject::connect(d.tabWidget->closeTabButton, SIGNAL(clicked()),
+                       this, SLOT(closeCurrentTab()));
 }
 
 
@@ -571,9 +606,16 @@
                }
        }
        tabbar.blockSignals(false);
+       d.tabWidget->hideTabsIfNecessary();
 }
 
 
+void GuiView::closeCurrentTab()
+{
+       dispatch(FuncRequest(LFUN_BUFFER_CLOSE));
+}
+
+
 void GuiView::currentTabChanged(int i)
 {
        BOOST_ASSERT(i >= 0 && size_type(i) < d.tabnames.size());

<<inline: closetab.png>>

<<inline: close_tab_screen_shot.png>>

Reply via email to