Changeset View
Changeset View
Standalone View
Standalone View
src/dolphintabbar.cpp
Show All 14 Lines | |||||
15 | * along with this program; if not, write to the * | 15 | * along with this program; if not, write to the * | ||
16 | * Free Software Foundation, Inc., * | 16 | * Free Software Foundation, Inc., * | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | ||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "dolphintabbar.h" | 20 | #include "dolphintabbar.h" | ||
21 | 21 | | |||
22 | #include <KLocalizedString> | 22 | #include <KLocalizedString> | ||
23 | 23 | | |||
elvisangelaccio: Unused, please remove it. | |||||
24 | #include <QDragEnterEvent> | 24 | #include <QDragEnterEvent> | ||
25 | #include <QMenu> | 25 | #include <QMenu> | ||
26 | #include <QMimeData> | 26 | #include <QMimeData> | ||
27 | #include <QTimer> | 27 | #include <QTimer> | ||
28 | #include <QInputDialog> | ||||
28 | 29 | | |||
29 | DolphinTabBar::DolphinTabBar(QWidget* parent) : | 30 | DolphinTabBar::DolphinTabBar(QWidget* parent) : | ||
30 | QTabBar(parent), | 31 | QTabBar(parent), | ||
31 | m_autoActivationIndex(-1), | 32 | m_autoActivationIndex(-1), | ||
32 | m_tabToBeClosedOnMiddleMouseButtonRelease(-1) | 33 | m_tabToBeClosedOnMiddleMouseButtonRelease(-1) | ||
33 | { | 34 | { | ||
34 | setAcceptDrops(true); | 35 | setAcceptDrops(true); | ||
35 | setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); | 36 | setSelectionBehaviorOnRemove(QTabBar::SelectPreviousTab); | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | |||||
133 | void DolphinTabBar::contextMenuEvent(QContextMenuEvent* event) | 134 | void DolphinTabBar::contextMenuEvent(QContextMenuEvent* event) | ||
134 | { | 135 | { | ||
135 | const int index = tabAt(event->pos()); | 136 | const int index = tabAt(event->pos()); | ||
136 | 137 | | |||
137 | if (index >= 0) { | 138 | if (index >= 0) { | ||
138 | // Tab context menu | 139 | // Tab context menu | ||
139 | QMenu menu(this); | 140 | QMenu menu(this); | ||
140 | 141 | | |||
142 | QAction* renameTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-rename")), i18nc("@action:inmenu", "Rename Tab")); | ||||
141 | QAction* newTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "New Tab")); | 143 | QAction* newTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-new")), i18nc("@action:inmenu", "New Tab")); | ||
142 | QAction* detachTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-detach")), i18nc("@action:inmenu", "Detach Tab")); | 144 | QAction* detachTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-detach")), i18nc("@action:inmenu", "Detach Tab")); | ||
143 | QAction* closeOtherTabsAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18nc("@action:inmenu", "Close Other Tabs")); | 145 | QAction* closeOtherTabsAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close-other")), i18nc("@action:inmenu", "Close Other Tabs")); | ||
144 | QAction* closeTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18nc("@action:inmenu", "Close Tab")); | 146 | QAction* closeTabAction = menu.addAction(QIcon::fromTheme(QStringLiteral("tab-close")), i18nc("@action:inmenu", "Close Tab")); | ||
145 | 147 | | |||
146 | QAction* selectedAction = menu.exec(event->globalPos()); | 148 | QAction* selectedAction = menu.exec(event->globalPos()); | ||
147 | if (selectedAction == newTabAction) { | 149 | if (selectedAction == newTabAction) { | ||
148 | emit openNewActivatedTab(index); | 150 | emit openNewActivatedTab(index); | ||
149 | } else if (selectedAction == detachTabAction) { | 151 | } else if (selectedAction == detachTabAction) { | ||
150 | emit tabDetachRequested(index); | 152 | emit tabDetachRequested(index); | ||
151 | } else if (selectedAction == closeOtherTabsAction) { | 153 | } else if (selectedAction == closeOtherTabsAction) { | ||
152 | const int tabCount = count(); | 154 | const int tabCount = count(); | ||
153 | for (int i = 0; i < index; i++) { | 155 | for (int i = 0; i < index; i++) { | ||
154 | emit tabCloseRequested(0); | 156 | emit tabCloseRequested(0); | ||
155 | } | 157 | } | ||
156 | for (int i = index + 1; i < tabCount; i++) { | 158 | for (int i = index + 1; i < tabCount; i++) { | ||
157 | emit tabCloseRequested(1); | 159 | emit tabCloseRequested(1); | ||
158 | } | 160 | } | ||
159 | } else if (selectedAction == closeTabAction) { | 161 | } else if (selectedAction == closeTabAction) { | ||
160 | emit tabCloseRequested(index); | 162 | emit tabCloseRequested(index); | ||
163 | } else if (selectedAction == renameTabAction) { | ||||
164 | bool renamed = false; | ||||
ngraham: Spaces around the equals sign | |||||
We could use a more descriptive variable name here, for example renamed or similar. elvisangelaccio: We could use a more descriptive variable name here, for example `renamed` or similar. | |||||
165 | const QString newTabName = QInputDialog::getText(this, | ||||
elvisangelaccio: Please add `const` | |||||
166 | i18n("Rename Tab"), i18n("New tab name:"), QLineEdit::Normal, tabText(index), &renamed | ||||
ngraham: "Rename Tab" (use title case for window titles) | |||||
elvisangelaccio: Maybe we can add a colon at the end of "New tab name" ? | |||||
167 | ); | ||||
168 | if (renamed) { | ||||
169 | emit tabRenamed(index, newTabName); | ||||
170 | } | ||||
161 | } | 171 | } | ||
162 | 172 | | |||
163 | return; | 173 | return; | ||
164 | } | 174 | } | ||
165 | 175 | | |||
166 | QTabBar::contextMenuEvent(event); | 176 | QTabBar::contextMenuEvent(event); | ||
167 | } | 177 | } | ||
168 | 178 | | |||
Show All 20 Lines |
Unused, please remove it.