]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
Fix indentation
[dolphin.git] / src / dolphintabwidget.cpp
index edb7247cc611d2edd556d797643b553128136283..3d03b3284334997b9336792c650447b787df6c4f 100644 (file)
@@ -37,13 +37,13 @@ DolphinTabWidget::DolphinTabWidget(QWidget* parent) :
     m_lastViewedTab(0)
 {
     connect(this, &DolphinTabWidget::tabCloseRequested,
-            this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::closeTab));
+            this, QOverload<int>::of(&DolphinTabWidget::closeTab));
     connect(this, &DolphinTabWidget::currentChanged,
             this, &DolphinTabWidget::currentTabChanged);
 
     DolphinTabBar* tabBar = new DolphinTabBar(this);
     connect(tabBar, &DolphinTabBar::openNewActivatedTab,
-            this,  static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::openNewActivatedTab));
+            this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
     connect(tabBar, &DolphinTabBar::tabDropEvent,
             this, &DolphinTabWidget::tabDropEvent);
     connect(tabBar, &DolphinTabBar::tabDetachRequested,
@@ -135,14 +135,10 @@ void DolphinTabWidget::openNewActivatedTab()
 
     // The URL navigator of the new tab should have the same editable state
     // as the current tab
-    KUrlNavigator* navigator = newActiveViewContainer->urlNavigator();
-    navigator->setUrlEditable(isUrlEditable);
+    newActiveViewContainer->urlNavigator()->setUrlEditable(isUrlEditable);
 
-    if (isUrlEditable) {
-        // If a new tab is opened and the URL is editable, assure that
-        // the user can edit the URL without manually setting the focus
-        navigator->setFocus();
-    }
+    // Always focus the new tab's view
+    newActiveViewContainer->view()->setFocus();
 }
 
 void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
@@ -151,7 +147,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& s
     setCurrentIndex(count() - 1);
 }
 
-void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
+void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement)
 {
     QWidget* focusWidget = QApplication::focusWidget();
 
@@ -161,7 +157,11 @@ void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryU
             this, &DolphinTabWidget::activeViewChanged);
     connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
             this, &DolphinTabWidget::tabUrlChanged);
-    addTab(tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
+    int newTabIndex = -1;
+    if (tabPlacement == AfterCurrentTab) {
+        newTabIndex = currentIndex() + 1;
+    }
+    insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
 
     if (focusWidget) {
         // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
@@ -226,7 +226,8 @@ void DolphinTabWidget::closeTab(const int index)
     Q_ASSERT(index < count());
 
     if (count() < 2) {
-        // Never close the last tab.
+        // Close Dolphin when closing the last tab.
+        parentWidget()->close();
         return;
     }