]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphintabwidget.cpp
fix information panel icon
[dolphin.git] / src / dolphintabwidget.cpp
index ff2f246aeda85846127d77fef7dccaef08efc6d3..9bfd6076ae132bfac209988235f1831c2146a055 100644 (file)
@@ -15,6 +15,7 @@
 #include <KIO/CommandLauncherJob>
 #include <KLocalizedString>
 #include <KShell>
+#include <KStringHandler>
 #include <kio/global.h>
 
 #include <QApplication>
@@ -22,6 +23,7 @@
 
 DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidget, QWidget *parent)
     : QTabWidget(parent)
+    , m_dragAndDropHelper{this}
     , m_lastViewedTab(nullptr)
     , m_navigatorsWidget{navigatorsWidget}
 {
@@ -32,14 +34,15 @@ 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();
 
     setTabBar(tabBar);
     setDocumentMode(true);
     setElideMode(Qt::ElideRight);
     setUsesScrollButtons(true);
+    setTabBarAutoHide(true);
 }
 
 DolphinTabPage *DolphinTabWidget::currentTabPage() const
@@ -103,11 +106,17 @@ 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);
+    tabBar()->setTabText(index, tabName(tabPageAt(index)));
+}
+
 bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
 {
     return viewOpenAtDirectory(url).has_value();
@@ -162,9 +171,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) {
@@ -383,6 +390,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();
+        m_dragAndDropHelper.updateDropAction(event, view->url());
+    }
+}
+
 void DolphinTabWidget::tabDropEvent(int index, QDropEvent *event)
 {
     if (index >= 0) {
@@ -406,7 +421,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
@@ -421,6 +436,8 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url)
         if (index == currentIndex()) {
             Q_EMIT currentUrlChanged(url);
         }
+
+        Q_EMIT urlChanged(url);
     }
 }
 
@@ -450,7 +467,7 @@ 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();
@@ -463,8 +480,6 @@ void DolphinTabWidget::tabInserted(int index)
                 tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
             }
         }
-
-        tabBar()->show();
     }
 
     Q_EMIT tabCountChanged(count());
@@ -474,12 +489,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());
 }
 
@@ -507,7 +516,7 @@ QString DolphinTabWidget::tabName(DolphinTabPage *tabPage) const
 
     // Make sure that a '&' inside the directory name is displayed correctly
     // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
-    return name.replace('&', QLatin1String("&&"));
+    return KStringHandler::rsqueeze(name.replace('&', QLatin1String("&&")), 40 /* default maximum visible folder name visible */);
 }
 
 DolphinViewContainer *DolphinTabWidget::viewContainerAt(DolphinTabWidget::ViewIndex viewIndex) const