X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/863ee3a87cee8b1f22a311d6a6a62e56714b5eae..c035e95e1d74fecd8267b08009c616232e2c16b0:/src/dolphintabwidget.cpp diff --git a/src/dolphintabwidget.cpp b/src/dolphintabwidget.cpp index d4271847f..f274ffa2a 100644 --- a/src/dolphintabwidget.cpp +++ b/src/dolphintabwidget.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -34,12 +35,12 @@ DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidg connect(tabBar, &DolphinTabBar::openNewActivatedTab, this, QOverload::of(&DolphinTabWidget::openNewActivatedTab)); 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 +104,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 +169,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) { @@ -392,7 +397,7 @@ void DolphinTabWidget::tabDropEvent(int index, QDropEvent *event) const auto urls = event->mimeData()->urls(); for (const QUrl &url : urls) { - auto *job = KIO::statDetails(url, KIO::StatJob::SourceSide, KIO::StatDetail::StatBasic, KIO::JobFlag::HideProgressInfo); + auto *job = KIO::stat(url, KIO::StatJob::SourceSide, KIO::StatDetail::StatBasic, KIO::JobFlag::HideProgressInfo); connect(job, &KJob::result, this, [this, job]() { if (!job->error() && job->statResult().isDir()) { openNewTab(job->url(), QUrl(), NewTabPosition::AtEnd); @@ -406,7 +411,7 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url) { const int index = indexOf(qobject_cast(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 +426,8 @@ void DolphinTabWidget::tabUrlChanged(const QUrl &url) if (index == currentIndex()) { Q_EMIT currentUrlChanged(url); } + + Q_EMIT urlChanged(url); } } @@ -450,7 +457,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 +470,6 @@ void DolphinTabWidget::tabInserted(int index) tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile)); } } - - tabBar()->show(); } Q_EMIT tabCountChanged(count()); @@ -474,12 +479,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 +506,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 @@ -595,3 +594,5 @@ const std::optional DolphinTabWidget::viewSho return std::nullopt; } + +#include "moc_dolphintabwidget.cpp"