From: Shaun Reich Date: Thu, 9 Jul 2009 04:41:53 +0000 (+0000) Subject: Fixed the annoying bug (for me) that dealt with having a very long folder name. In... X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/70915125f7250ea8eb654ab253db7ed96b14a6bf?ds=inline Fixed the annoying bug (for me) that dealt with having a very long folder name. In this case, the name of the tab could be many more times bigger than the tabBar itself. Now they are ellided, so e.g. "really really long folder name...is" or something. Few more cases left for me to fix(shortly), but those are not quite close to this section. svn path=/trunk/KDE/kdebase/apps/; revision=993618 --- diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 399c662f8..1c310b5b3 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -237,7 +237,7 @@ void DolphinMainWindow::changeUrl(const KUrl& url) updateGoActions(); setUrlAsCaption(url); if (m_viewTab.count() > 1) { - m_tabBar->setTabText(m_tabIndex, tabName(url)); + m_tabBar->setTabText(m_tabIndex, squeezeText(tabName(m_activeViewContainer->url()))); } const QString iconName = KMimeType::iconNameForUrl(url); m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName)); @@ -339,11 +339,11 @@ void DolphinMainWindow::openNewTab(const KUrl& url) if (m_viewTab.count() == 1) { // Only one view is open currently and hence no tab is shown at // all. Before creating a tab for 'url', provide a tab for the current URL. - m_tabBar->addTab(icon, tabName(m_activeViewContainer->url())); + m_tabBar->addTab(icon, squeezeText(tabName(m_activeViewContainer->url()))); m_tabBar->blockSignals(false); } - m_tabBar->addTab(icon, tabName(url)); + m_tabBar->addTab(icon, squeezeText(tabName(url))); ViewTab viewTab; viewTab.splitter = new QSplitter(this); @@ -1434,10 +1434,7 @@ void DolphinMainWindow::rememberClosedTab(int index) const QString primaryPath = m_viewTab[index].primaryView->url().path(); const QString iconName = KMimeType::iconNameForUrl(primaryPath); - const QFontMetrics fm = fontMetrics(); - const QString actionText = fm.elidedText(primaryPath, Qt::ElideMiddle, fm.maxWidth() * 20); - - QAction* action = new QAction(actionText, tabsMenu); + QAction* action = new QAction(squeezeText(primaryPath), tabsMenu); ClosedTab closedTab; closedTab.primaryUrl = m_viewTab[index].primaryView->url(); @@ -1580,6 +1577,13 @@ void DolphinMainWindow::setUrlAsCaption(const KUrl& url) setCaption(caption); } +QString DolphinMainWindow::squeezeText(const QString& text) +{ + const QFontMetrics fm = fontMetrics(); + QString result = fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10); + return result; +} + DolphinMainWindow::UndoUiInterface::UndoUiInterface() : KIO::FileUndoManager::UiInterface() { diff --git a/src/dolphinmainwindow.h b/src/dolphinmainwindow.h index c1e0ffcbd..4d724ad2d 100644 --- a/src/dolphinmainwindow.h +++ b/src/dolphinmainwindow.h @@ -455,6 +455,8 @@ private: virtual void jobError(KIO::Job* job); }; + QString squeezeText(const QString& text); + KNewMenu* m_newMenu; KActionMenu* m_recentTabsMenu; KAction* m_showMenuBar;