]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
SVN_SILENT made messages (.desktop file) - always resolve ours
[dolphin.git] / src / dolphintabwidget.cpp
index edc1cb7d84f87f12f1d2c03998db3a51c6a119fd..b2f838a40ab7e44b4a4241fd893407c344d8cf56 100644 (file)
@@ -9,6 +9,7 @@
 #include "dolphin_generalsettings.h"
 #include "dolphintabbar.h"
 #include "dolphinviewcontainer.h"
+#include "views/draganddrophelper.h"
 
 #include <KAcceleratorManager>
 #include <KConfigGroup>
@@ -20,6 +21,7 @@
 
 #include <QApplication>
 #include <QDropEvent>
+#include <QStackedWidget>
 
 DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidget, QWidget *parent)
     : QTabWidget(parent)
@@ -33,14 +35,23 @@ DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidg
 
     DolphinTabBar *tabBar = new DolphinTabBar(this);
     connect(tabBar, &DolphinTabBar::openNewActivatedTab, this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
+    connect(tabBar, &DolphinTabBar::tabDragMoveEvent, this, &DolphinTabWidget::tabDragMoveEvent);
     connect(tabBar, &DolphinTabBar::tabDropEvent, this, &DolphinTabWidget::tabDropEvent);
     connect(tabBar, &DolphinTabBar::tabDetachRequested, this, &DolphinTabWidget::detachTab);
-    tabBar->hide();
+    connect(tabBar, &DolphinTabBar::tabRenamed, this, &DolphinTabWidget::renameTab);
 
     setTabBar(tabBar);
     setDocumentMode(true);
     setElideMode(Qt::ElideRight);
     setUsesScrollButtons(true);
+    setTabBarAutoHide(true);
+
+    auto stackWidget{findChild<QStackedWidget *>()};
+    // i18n: This accessible name will be announced any time the user moves keyboard focus e.g. from the toolbar or the places panel towards the main working
+    // area of Dolphin. It gives structure. This container does not only contain the main view but also the status bar, the search panel, filter, and selection
+    // mode bars, so calling it just a "View" is a bit wrong, but hopefully still gets the point across.
+    stackWidget->setAccessibleName(i18nc("accessible name of Dolphin's view container", "Location View")); // Without this call, the non-descript Qt provided
+                                                                                                           // "Layered Pane" role is announced.
 }
 
 DolphinTabPage *DolphinTabWidget::currentTabPage() const
@@ -104,11 +115,24 @@ void DolphinTabWidget::refreshViews()
 
     const int tabCount = count();
     for (int i = 0; i < tabCount; ++i) {
-        tabBar()->setTabText(i, tabName(tabPageAt(i)));
+        updateTabName(i);
         tabPageAt(i)->refreshViews();
     }
 }
 
+void DolphinTabWidget::updateTabName(int index)
+{
+    Q_ASSERT(index >= 0);
+
+    if (!tabPageAt(index)->customLabel().isEmpty()) {
+        QString name = tabPageAt(index)->customLabel();
+        tabBar()->setTabText(index, name);
+        return;
+    }
+
+    tabBar()->setTabText(index, tabName(tabPageAt(index)));
+}
+
 bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
 {
     return viewOpenAtDirectory(url).has_value();
@@ -154,7 +178,7 @@ void DolphinTabWidget::openNewActivatedTab(const QUrl &primaryUrl, const QUrl &s
     }
 }
 
-void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl, DolphinTabWidget::NewTabPosition position)
+DolphinTabPage *DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryUrl, DolphinTabWidget::NewTabPosition position)
 {
     QWidget *focusWidget = QApplication::focusWidget();
 
@@ -163,9 +187,7 @@ void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryU
     connect(tabPage, &DolphinTabPage::activeViewChanged, this, &DolphinTabWidget::activeViewChanged);
     connect(tabPage, &DolphinTabPage::activeViewUrlChanged, this, &DolphinTabWidget::tabUrlChanged);
     connect(tabPage->activeViewContainer(), &DolphinViewContainer::captionChanged, this, [this, tabPage]() {
-        const int tabIndex = indexOf(tabPage);
-        Q_ASSERT(tabIndex >= 0);
-        tabBar()->setTabText(tabIndex, tabName(tabPage));
+        updateTabName(indexOf(tabPage));
     });
 
     if (position == NewTabPosition::FollowSetting) {
@@ -188,6 +210,7 @@ void DolphinTabWidget::openNewTab(const QUrl &primaryUrl, const QUrl &secondaryU
         // in background, assure that the previous focused widget gets the focus back.
         focusWidget->setFocus();
     }
+    return tabPage;
 }
 
 void DolphinTabWidget::openDirectories(const QList<QUrl> &dirs, bool splitView)
@@ -384,6 +407,14 @@ void DolphinTabWidget::openNewActivatedTab(int index)
     openNewActivatedTab(tabPage->activeViewContainer()->url());
 }
 
+void DolphinTabWidget::tabDragMoveEvent(int index, QDragMoveEvent *event)
+{
+    if (index >= 0) {
+        DolphinView *view = tabPageAt(index)->activeViewContainer()->view();
+        DragAndDropHelper::updateDropAction(event, view->url());
+    }
+}
+
 void DolphinTabWidget::tabDropEvent(int index, QDropEvent *event)
 {
     if (index >= 0) {
@@ -407,7 +438,7 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url)
 {
     const int index = indexOf(qobject_cast<QWidget *>(sender()));
     if (index >= 0) {
-        tabBar()->setTabText(index, tabName(tabPageAt(index)));
+        updateTabName(index);
         tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
         if (tabBar()->isVisible()) {
             // ensure the path url ends with a slash to have proper folder icon for remote folders
@@ -422,6 +453,8 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url)
         if (index == currentIndex()) {
             Q_EMIT currentUrlChanged(url);
         }
+
+        Q_EMIT urlChanged(url);
     }
 }
 
@@ -447,11 +480,17 @@ void DolphinTabWidget::currentTabChanged(int index)
     m_lastViewedTab = tabPage;
 }
 
+void DolphinTabWidget::renameTab(int index, const QString &name)
+{
+    tabPageAt(index)->setCustomLabel(name);
+    updateTabName(index);
+}
+
 void DolphinTabWidget::tabInserted(int index)
 {
     QTabWidget::tabInserted(index);
 
-    if (count() > 1) {
+    if (tabBar()->isVisible()) {
         // Resolve all pending tab icons
         for (int i = 0; i < count(); ++i) {
             const QUrl url = tabPageAt(i)->activeViewContainer()->url();
@@ -464,8 +503,6 @@ void DolphinTabWidget::tabInserted(int index)
                 tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
             }
         }
-
-        tabBar()->show();
     }
 
     Q_EMIT tabCountChanged(count());
@@ -475,12 +512,6 @@ void DolphinTabWidget::tabRemoved(int index)
 {
     QTabWidget::tabRemoved(index);
 
-    // If only one tab is left, then remove the tab entry so that
-    // closing the last tab is not possible.
-    if (count() < 2) {
-        tabBar()->hide();
-    }
-
     Q_EMIT tabCountChanged(count());
 }