Changeset View
Changeset View
Standalone View
Standalone View
src/dolphintabwidget.cpp
Show All 24 Lines | |||||
25 | 25 | | |||
26 | #include <KConfigGroup> | 26 | #include <KConfigGroup> | ||
27 | #include <KRun> | 27 | #include <KRun> | ||
28 | #include <KShell> | 28 | #include <KShell> | ||
29 | #include <kio/global.h> | 29 | #include <kio/global.h> | ||
30 | 30 | | |||
31 | #include <QApplication> | 31 | #include <QApplication> | ||
32 | #include <QDropEvent> | 32 | #include <QDropEvent> | ||
33 | #include <QDebug> | ||||
ngraham: Don't want this in production code | |||||
33 | 34 | | |||
34 | DolphinTabWidget::DolphinTabWidget(QWidget* parent) : | 35 | DolphinTabWidget::DolphinTabWidget(QWidget* parent) : | ||
35 | QTabWidget(parent), | 36 | QTabWidget(parent), | ||
36 | m_placesSelectorVisible(true), | 37 | m_placesSelectorVisible(true), | ||
37 | m_lastViewedTab(0) | 38 | m_lastViewedTab(0), | ||
39 | m_tabNames() | ||||
elvisangelaccio: Not needed, the constructor is implicitly called for QMap objects. | |||||
38 | { | 40 | { | ||
39 | connect(this, &DolphinTabWidget::tabCloseRequested, | 41 | connect(this, &DolphinTabWidget::tabCloseRequested, | ||
40 | this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::closeTab)); | 42 | this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::closeTab)); | ||
41 | connect(this, &DolphinTabWidget::currentChanged, | 43 | connect(this, &DolphinTabWidget::currentChanged, | ||
42 | this, &DolphinTabWidget::currentTabChanged); | 44 | this, &DolphinTabWidget::currentTabChanged); | ||
43 | 45 | | |||
44 | DolphinTabBar* tabBar = new DolphinTabBar(this); | 46 | DolphinTabBar* tabBar = new DolphinTabBar(this); | ||
45 | connect(tabBar, &DolphinTabBar::openNewActivatedTab, | 47 | connect(tabBar, &DolphinTabBar::openNewActivatedTab, | ||
46 | this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::openNewActivatedTab)); | 48 | this, static_cast<void (DolphinTabWidget::*)(int)>(&DolphinTabWidget::openNewActivatedTab)); | ||
47 | connect(tabBar, &DolphinTabBar::tabDropEvent, | 49 | connect(tabBar, &DolphinTabBar::tabDropEvent, | ||
48 | this, &DolphinTabWidget::tabDropEvent); | 50 | this, &DolphinTabWidget::tabDropEvent); | ||
49 | connect(tabBar, &DolphinTabBar::tabDetachRequested, | 51 | connect(tabBar, &DolphinTabBar::tabDetachRequested, | ||
50 | this, &DolphinTabWidget::detachTab); | 52 | this, &DolphinTabWidget::detachTab); | ||
53 | connect(tabBar, &DolphinTabBar::tabRenamed, this, &DolphinTabWidget::renameTab); | ||||
51 | tabBar->hide(); | 54 | tabBar->hide(); | ||
52 | 55 | | |||
53 | setTabBar(tabBar); | 56 | setTabBar(tabBar); | ||
54 | setDocumentMode(true); | 57 | setDocumentMode(true); | ||
55 | setElideMode(Qt::ElideRight); | 58 | setElideMode(Qt::ElideRight); | ||
56 | setUsesScrollButtons(true); | 59 | setUsesScrollButtons(true); | ||
57 | } | 60 | } | ||
58 | 61 | | |||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 97 | { | |||
111 | const int index = group.readEntry("Active Tab Index", 0); | 114 | const int index = group.readEntry("Active Tab Index", 0); | ||
112 | setCurrentIndex(index); | 115 | setCurrentIndex(index); | ||
113 | } | 116 | } | ||
114 | 117 | | |||
115 | void DolphinTabWidget::refreshViews() | 118 | void DolphinTabWidget::refreshViews() | ||
116 | { | 119 | { | ||
117 | const int tabCount = count(); | 120 | const int tabCount = count(); | ||
118 | for (int i = 0; i < tabCount; ++i) { | 121 | for (int i = 0; i < tabCount; ++i) { | ||
122 | if (m_tabNames.contains(i)) { | ||||
123 | tabBar()->setTabText(i, m_tabNames.value(i)); | ||||
124 | } else { | ||||
119 | tabBar()->setTabText(i, tabName(tabPageAt(i))); | 125 | tabBar()->setTabText(i, tabName(tabPageAt(i))); | ||
126 | } | ||||
hallas: Maybe this logic should be moved to the `tabName` function instead? | |||||
120 | tabPageAt(i)->refreshViews(); | 127 | tabPageAt(i)->refreshViews(); | ||
121 | } | 128 | } | ||
122 | } | 129 | } | ||
123 | 130 | | |||
124 | void DolphinTabWidget::openNewActivatedTab() | 131 | void DolphinTabWidget::openNewActivatedTab() | ||
125 | { | 132 | { | ||
126 | const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer(); | 133 | const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer(); | ||
127 | Q_ASSERT(oldActiveViewContainer); | 134 | Q_ASSERT(oldActiveViewContainer); | ||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | |||||
264 | } | 271 | } | ||
265 | 272 | | |||
266 | void DolphinTabWidget::restoreClosedTab(const QByteArray& state) | 273 | void DolphinTabWidget::restoreClosedTab(const QByteArray& state) | ||
267 | { | 274 | { | ||
268 | openNewActivatedTab(); | 275 | openNewActivatedTab(); | ||
269 | currentTabPage()->restoreState(state); | 276 | currentTabPage()->restoreState(state); | ||
270 | } | 277 | } | ||
271 | 278 | | |||
279 | void DolphinTabWidget::renameTab(int index, QString& name) { | ||||
elvisangelaccio: Coding style: brace should go to next line for functions. | |||||
280 | if (name.isEmpty()) { | ||||
281 | m_tabNames.remove(index); | ||||
282 | tabBar()->setTabText(index, tabName(tabPageAt(index))); | ||||
283 | } | ||||
284 | else { | ||||
285 | tabBar()->setTabText(index, name); | ||||
elvisangelaccio: Coding style: else starts at the end of previous line. | |||||
286 | m_tabNames.insert(index, name); | ||||
287 | } | ||||
288 | } | ||||
289 | | ||||
272 | void DolphinTabWidget::detachTab(int index) | 290 | void DolphinTabWidget::detachTab(int index) | ||
273 | { | 291 | { | ||
274 | Q_ASSERT(index >= 0); | 292 | Q_ASSERT(index >= 0); | ||
275 | 293 | | |||
276 | QStringList args; | 294 | QStringList args; | ||
277 | 295 | | |||
278 | const DolphinTabPage* tabPage = tabPageAt(index); | 296 | const DolphinTabPage* tabPage = tabPageAt(index); | ||
279 | args << tabPage->primaryViewContainer()->url().url(); | 297 | args << tabPage->primaryViewContainer()->url().url(); | ||
Show All 22 Lines | 318 | if (index >= 0) { | |||
302 | view->dropUrls(view->url(), event, view); | 320 | view->dropUrls(view->url(), event, view); | ||
303 | } | 321 | } | ||
304 | } | 322 | } | ||
305 | 323 | | |||
306 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | 324 | void DolphinTabWidget::tabUrlChanged(const QUrl& url) | ||
307 | { | 325 | { | ||
308 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | 326 | const int index = indexOf(qobject_cast<QWidget*>(sender())); | ||
309 | if (index >= 0) { | 327 | if (index >= 0) { | ||
328 | if (!m_tabNames.contains(index)) { | ||||
310 | tabBar()->setTabText(index, tabName(tabPageAt(index))); | 329 | tabBar()->setTabText(index, tabName(tabPageAt(index))); | ||
330 | } | ||||
311 | tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); | 331 | tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url))); | ||
312 | 332 | | |||
313 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | 333 | // Emit the currentUrlChanged signal if the url of the current tab has been changed. | ||
314 | if (index == currentIndex()) { | 334 | if (index == currentIndex()) { | ||
315 | emit currentUrlChanged(url); | 335 | emit currentUrlChanged(url); | ||
316 | } | 336 | } | ||
317 | } | 337 | } | ||
318 | } | 338 | } | ||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Don't want this in production code