Changeset View
Changeset View
Standalone View
Standalone View
src/dolphintabwidget.cpp
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | 160 | { | |||
---|---|---|---|---|---|
165 | connect(tabPage, &DolphinTabPage::activeViewChanged, | 165 | connect(tabPage, &DolphinTabPage::activeViewChanged, | ||
166 | this, &DolphinTabWidget::activeViewChanged); | 166 | this, &DolphinTabWidget::activeViewChanged); | ||
167 | connect(tabPage, &DolphinTabPage::activeViewUrlChanged, | 167 | connect(tabPage, &DolphinTabPage::activeViewUrlChanged, | ||
168 | this, &DolphinTabWidget::tabUrlChanged); | 168 | this, &DolphinTabWidget::tabUrlChanged); | ||
169 | int newTabIndex = -1; | 169 | int newTabIndex = -1; | ||
170 | if (tabPlacement == AfterCurrentTab) { | 170 | if (tabPlacement == AfterCurrentTab) { | ||
171 | newTabIndex = currentIndex() + 1; | 171 | newTabIndex = currentIndex() + 1; | ||
172 | } | 172 | } | ||
173 | insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage)); | 173 | insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage)); | ||
174 | 174 | | |||
175 | if (focusWidget) { | 175 | if (focusWidget) { | ||
176 | // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened | 176 | // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened | ||
177 | // in background, assure that the previous focused widget gets the focus back. | 177 | // in background, assure that the previous focused widget gets the focus back. | ||
178 | focusWidget->setFocus(); | 178 | focusWidget->setFocus(); | ||
179 | } | 179 | } | ||
180 | } | 180 | } | ||
181 | 181 | | |||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | 315 | if (index >= 0) { | |||
317 | view->dropUrls(view->url(), event, view); | 317 | view->dropUrls(view->url(), event, view); | ||
318 | } | 318 | } | ||
319 | } | 319 | } | ||
320 | 320 | | |||
321 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | 321 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | ||
322 | { | 322 | { | ||
323 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | 323 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | ||
324 | if (index >= 0) { | 324 | if (index >= 0) { | ||
325 | tabBar()->setTabText(index, tabName(tabPageAt(index))); | 325 | DolphinTabPage *tabPage = tabPageAt(index); | ||
326 | tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); | 326 | tabBar()->setTabText(index, tabName(tabPage)); | ||
327 | if (tabBar()->isVisible()) { | ||||
328 | tabBar()->setTabIcon(index, tabIcon(tabPage)); | ||||
329 | } else { | ||||
330 | // Mark as dirty, actually load once the tab bar actually gets shown | ||||
331 | tabBar()->setTabIcon(index, QIcon()); | ||||
332 | } | ||||
327 | 333 | | |||
328 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | 334 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | ||
329 | if (index == currentIndex()) { | 335 | if (index == currentIndex()) { | ||
330 | emit currentUrlChanged(url); | 336 | emit currentUrlChanged(url); | ||
331 | } | 337 | } | ||
332 | } | 338 | } | ||
333 | } | 339 | } | ||
334 | 340 | | |||
Show All 11 Lines | 342 | { | |||
346 | m_lastViewedTab = index; | 352 | m_lastViewedTab = index; | ||
347 | } | 353 | } | ||
348 | 354 | | |||
349 | void DolphinTabWidget::tabInserted(int index) | 355 | void DolphinTabWidget::tabInserted(int index) | ||
350 | { | 356 | { | ||
351 | QTabWidget::tabInserted(index); | 357 | QTabWidget::tabInserted(index); | ||
352 | 358 | | |||
353 | if (count() > 1) { | 359 | if (count() > 1) { | ||
360 | // Resolve all pending tab icons | ||||
361 | for (int i = 0; i < count(); ++i) { | ||||
362 | if (tabBar()->tabIcon(i).isNull()) { | ||||
363 | tabBar()->setTabIcon(i, tabIcon(tabPageAt(i))); | ||||
364 | } | ||||
365 | } | ||||
366 | | ||||
354 | tabBar()->show(); | 367 | tabBar()->show(); | ||
355 | } | 368 | } | ||
356 | 369 | | |||
357 | emit tabCountChanged(count()); | 370 | emit tabCountChanged(count()); | ||
358 | } | 371 | } | ||
359 | 372 | | |||
360 | void DolphinTabWidget::tabRemoved(int index) | 373 | void DolphinTabWidget::tabRemoved(int index) | ||
361 | { | 374 | { | ||
Show All 14 Lines | 388 | if (!tabPage) { | |||
376 | return QString(); | 389 | return QString(); | ||
377 | } | 390 | } | ||
378 | QString name = tabPage->activeViewContainer()->caption(); | 391 | QString name = tabPage->activeViewContainer()->caption(); | ||
379 | // Make sure that a '&' inside the directory name is displayed correctly | 392 | // Make sure that a '&' inside the directory name is displayed correctly | ||
380 | // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() | 393 | // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() | ||
381 | return name.replace('&', QLatin1String("&&")); | 394 | return name.replace('&', QLatin1String("&&")); | ||
382 | } | 395 | } | ||
383 | 396 | | |||
397 | QIcon DolphinTabWidget::tabIcon(DolphinTabPage *tabPage) const | ||||
398 | { | ||||
399 | if (!tabPage) { | ||||
400 | return QIcon(); | ||||
401 | } | ||||
402 | return QIcon::fromTheme(KIO::iconNameForUrl(tabPage->activeViewContainer()->url())); | ||||
403 | } | ||||
404 | | ||||
384 | int DolphinTabWidget::getIndexByUrl(const QUrl& url) const | 405 | int DolphinTabWidget::getIndexByUrl(const QUrl& url) const | ||
385 | { | 406 | { | ||
386 | for (int i = 0; i < count(); i++) { | 407 | for (int i = 0; i < count(); i++) { | ||
387 | // Conversion to display string is necessary to deal with the '~' alias. | 408 | // Conversion to display string is necessary to deal with the '~' alias. | ||
388 | // i.e. to acknowledge that ~/ is equivalent to /home/user/ | 409 | // i.e. to acknowledge that ~/ is equivalent to /home/user/ | ||
389 | const QUrl tabUrl = tabPageAt(i)->activeViewContainer()->url(); | 410 | const QUrl tabUrl = tabPageAt(i)->activeViewContainer()->url(); | ||
390 | if (url == tabUrl || | 411 | if (url == tabUrl || | ||
391 | url.toDisplayString(QUrl::StripTrailingSlash) == tabUrl.toDisplayString(QUrl::StripTrailingSlash)) { | 412 | url.toDisplayString(QUrl::StripTrailingSlash) == tabUrl.toDisplayString(QUrl::StripTrailingSlash)) { | ||
392 | return i; | 413 | return i; | ||
393 | } | 414 | } | ||
394 | } | 415 | } | ||
395 | return -1; | 416 | return -1; | ||
396 | } | 417 | } |