[kde-doc-english] [kdevplatform] /: Double click in tab bar creates new file

Kevin Funk kfunk at kde.org
Tue Feb 10 21:06:34 UTC 2015


Git commit 2d4ce96f5dfda983b1ad600a2abb3e207a77759d by Kevin Funk.
Committed on 10/02/2015 at 21:04.
Pushed by kfunk into branch 'master'.

Double click in tab bar creates new file

GUI: Clicking on an empty space in the document tab bar now creates an
new file

M  +7    -0    shell/mainwindow.cpp
M  +1    -0    shell/mainwindow.h
M  +18   -5    sublime/container.cpp
M  +6    -0    sublime/container.h
M  +4    -0    sublime/mainwindow.cpp
M  +1    -0    sublime/mainwindow.h
M  +2    -0    sublime/mainwindow_p.cpp

http://commits.kde.org/kdevplatform/2d4ce96f5dfda983b1ad600a2abb3e207a77759d

diff --git a/shell/mainwindow.cpp b/shell/mainwindow.cpp
index f923571..8757942 100644
--- a/shell/mainwindow.cpp
+++ b/shell/mainwindow.cpp
@@ -376,5 +376,12 @@ void MainWindow::dockBarContextMenuRequested(Qt::DockWidgetArea area, const QPoi
     d->dockBarContextMenuRequested(area, position);
 }
 
+void MainWindow::newTabRequested()
+{
+    Sublime::MainWindow::newTabRequested();
+
+    d->fileNew();
+}
+
 }
 
diff --git a/shell/mainwindow.h b/shell/mainwindow.h
index 29a9e8e..1a3871d 100644
--- a/shell/mainwindow.h
+++ b/shell/mainwindow.h
@@ -88,6 +88,7 @@ protected Q_SLOTS:
     virtual void tabContextMenuRequested(Sublime::View* , QMenu* );
     virtual void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int tab);
     virtual void dockBarContextMenuRequested(Qt::DockWidgetArea, const QPoint&);
+    virtual void newTabRequested() override;
 
 private Q_SLOTS:
     void updateCaption();
diff --git a/sublime/container.cpp b/sublime/container.cpp
index 0b73bd3..75d84db 100644
--- a/sublime/container.cpp
+++ b/sublime/container.cpp
@@ -47,8 +47,11 @@ namespace Sublime {
 
 // struct ContainerPrivate
 
-class ContainerTabBar : public QTabBar {
-    public:
+class ContainerTabBar : public QTabBar
+{
+    Q_OBJECT
+
+public:
     ContainerTabBar(Container* container) : QTabBar(container), m_container(container) {
     }
     
@@ -72,7 +75,7 @@ class ContainerTabBar : public QTabBar {
     virtual void mousePressEvent(QMouseEvent* event) {
         if (event->button() == Qt::MidButton) {
             // just close on midbutton, drag can still be done with left mouse button
-            
+
             int tab = tabAt(mapFromGlobal(QCursor::pos()));
             if (tab != -1) {
                 emit tabCloseRequested(tab);
@@ -81,6 +84,11 @@ class ContainerTabBar : public QTabBar {
         }
         QTabBar::mousePressEvent(event);
     }
+
+Q_SIGNALS:
+    void newTabRequested();
+
+private:
     Container* m_container;
 };
 
@@ -236,6 +244,7 @@ Container::Container(QWidget *parent)
 
     connect(d->tabBar, &ContainerTabBar::currentChanged, this, &Container::widgetActivated);
     connect(d->tabBar, &ContainerTabBar::tabCloseRequested, this, static_cast<void(Container::*)(int)>(&Container::requestClose));
+    connect(d->tabBar, &ContainerTabBar::newTabRequested, this, &Container::newTabRequested);
     connect(d->tabBar, &ContainerTabBar::tabMoved, this, &Container::tabMoved);
     connect(d->tabBar, &ContainerTabBar::customContextMenuRequested, this, &Container::contextMenu);
     connect(d->tabBar, &ContainerTabBar::tabBarDoubleClicked, this, &Container::doubleClickTriggered);
@@ -547,7 +556,11 @@ QRect Container::tabRect(int tab) const
 
 void Container::doubleClickTriggered(int tab)
 {
-    emit tabDoubleClicked(viewForWidget(widget(tab)));
+    if (tab == -1) {
+        emit newTabRequested();
+    } else {
+        emit tabDoubleClicked(viewForWidget(widget(tab)));
+    }
 }
 
 void Container::documentListActionTriggered(QAction* action)
@@ -562,4 +575,4 @@ void Container::documentListActionTriggered(QAction* action)
 
 }
 
-
+#include "container.moc"
diff --git a/sublime/container.h b/sublime/container.h
index f023c31..9049f55 100644
--- a/sublime/container.h
+++ b/sublime/container.h
@@ -73,6 +73,12 @@ public:
 Q_SIGNALS:
     void activateView(Sublime::View* view);
     void requestClose(QWidget *w);
+    /**
+     * This signal is emitted whenever the users double clicks on the free
+     * space next to the tab bar. Typically, a new document should be
+     * created.
+     */
+    void newTabRequested();
     void tabContextMenuRequested(Sublime::View* view, QMenu* menu);
     /**
      * @p view The view represented by the tab that was hovered
diff --git a/sublime/mainwindow.cpp b/sublime/mainwindow.cpp
index 39809d4..32ef797 100644
--- a/sublime/mainwindow.cpp
+++ b/sublime/mainwindow.cpp
@@ -399,6 +399,10 @@ void MainWindow::tabToolTipRequested(View*, Container*, int)
     // do nothing
 }
 
+void MainWindow::newTabRequested()
+{
+}
+
 void MainWindow::dockBarContextMenuRequested(Qt::DockWidgetArea , const QPoint& )
 {
     // do nothing
diff --git a/sublime/mainwindow.h b/sublime/mainwindow.h
index e187cfb..25bc46d 100644
--- a/sublime/mainwindow.h
+++ b/sublime/mainwindow.h
@@ -134,6 +134,7 @@ protected Q_SLOTS:
     virtual void tabDoubleClicked(Sublime::View* view);
     virtual void tabContextMenuRequested(Sublime::View*, QMenu*);
     virtual void tabToolTipRequested(Sublime::View* view, Sublime::Container* container, int tab);
+    virtual void newTabRequested();
     /**Called whenever the user requests a context menu on a dockwidget bar.
        You can then e.g. add actions to add dockwidgets.
        Default implementation does nothing.**/
diff --git a/sublime/mainwindow_p.cpp b/sublime/mainwindow_p.cpp
index ab99ac3..2a6ab7d 100644
--- a/sublime/mainwindow_p.cpp
+++ b/sublime/mainwindow_p.cpp
@@ -314,6 +314,8 @@ Area::WalkerMode MainWindowPrivate::ViewCreator::operator() (AreaIndex *index)
                     d->m_mainWindow, &MainWindow::tabToolTipRequested);
             connect(container, static_cast<void(Container::*)(QWidget*)>(&Container::requestClose),
                     d, &MainWindowPrivate::widgetCloseRequest, Qt::QueuedConnection);
+            connect(container, &Container::newTabRequested,
+                    d->m_mainWindow, &MainWindow::newTabRequested);
             splitter->addWidget(container);
         }
         else


More information about the kde-doc-english mailing list