Changeset View
Changeset View
Standalone View
Standalone View
krusader/paneltabbar.cpp
Show All 31 Lines | |||||
32 | #include <QResizeEvent> | 32 | #include <QResizeEvent> | ||
33 | #include <QMouseEvent> | 33 | #include <QMouseEvent> | ||
34 | // QtWidgets | 34 | // QtWidgets | ||
35 | #include <QAction> | 35 | #include <QAction> | ||
36 | #include <QMenu> | 36 | #include <QMenu> | ||
37 | 37 | | |||
38 | #include <KConfigCore/KSharedConfig> | 38 | #include <KConfigCore/KSharedConfig> | ||
39 | #include <KI18n/KLocalizedString> | 39 | #include <KI18n/KLocalizedString> | ||
40 | #include <KIconThemes/KIconLoader> | ||||
40 | #include <KWidgetsAddons/KActionMenu> | 41 | #include <KWidgetsAddons/KActionMenu> | ||
41 | 42 | | |||
42 | #define DISPLAY(X) (X.isLocalFile() ? X.path() : X.toDisplayString()) | 43 | #define DISPLAY(X) (X.isLocalFile() ? X.path() : X.toDisplayString()) | ||
43 | 44 | | |||
44 | PanelTabBar::PanelTabBar(QWidget *parent, TabActions *actions): QTabBar(parent), | 45 | PanelTabBar::PanelTabBar(QWidget *parent, TabActions *actions): QTabBar(parent), | ||
45 | _maxTabLength(0), _tabClicked(false), _draggingTab(false) | 46 | _maxTabLength(0), _tabClicked(false), _draggingTab(false) | ||
46 | { | 47 | { | ||
47 | _panelActionMenu = new KActionMenu(i18n("Panel"), this); | 48 | _panelActionMenu = new KActionMenu(i18n("Panel"), this); | ||
Show All 17 Lines | |||||
65 | { | 66 | { | ||
66 | _panelActionMenu->addAction(action); | 67 | _panelActionMenu->addAction(action); | ||
67 | } | 68 | } | ||
68 | 69 | | |||
69 | int PanelTabBar::addPanel(ListPanel *panel, bool setCurrent, KrPanel *nextTo) | 70 | int PanelTabBar::addPanel(ListPanel *panel, bool setCurrent, KrPanel *nextTo) | ||
70 | { | 71 | { | ||
71 | int insertIndex = -1; | 72 | int insertIndex = -1; | ||
72 | 73 | | |||
73 | if(nextTo) { | 74 | if (nextTo) { | ||
74 | for(int i = 0; i < count(); i++) { | 75 | for (int i = 0; i < count(); i++) { | ||
75 | if(getPanel(i) == nextTo) { | 76 | if (getPanel(i) == nextTo) { | ||
76 | insertIndex = i + 1; | 77 | insertIndex = i + 1; | ||
77 | break; | 78 | break; | ||
78 | } | 79 | } | ||
79 | } | 80 | } | ||
80 | } | 81 | } | ||
81 | 82 | | |||
82 | int newId; | 83 | const QString text = squeeze(DISPLAY(panel->virtualPath())); | ||
83 | if(insertIndex != -1) { | 84 | const int index = insertIndex != -1 ? insertTab(insertIndex, text) : addTab(text); | ||
84 | newId = insertTab(insertIndex, squeeze(DISPLAY(panel->virtualPath()))); | | |||
85 | } else | | |||
86 | newId = addTab(squeeze(DISPLAY(panel->virtualPath()))); | | |||
87 | 85 | | |||
88 | QVariant v; | 86 | QVariant v; | ||
89 | v.setValue((long long)panel); | 87 | v.setValue((long long)panel); | ||
90 | setTabData(newId, v); | 88 | setTabData(index, v); | ||
89 | | ||||
90 | setIcon(index, panel); | ||||
91 | 91 | | |||
92 | // make sure all tabs lengths are correct | 92 | // make sure all tabs lengths are correct | ||
93 | layoutTabs(); | 93 | layoutTabs(); | ||
94 | 94 | | |||
95 | if (setCurrent) | 95 | if (setCurrent) | ||
96 | setCurrentIndex(newId); | 96 | setCurrentIndex(index); | ||
97 | 97 | | |||
98 | return newId; | 98 | return index; | ||
99 | } | 99 | } | ||
100 | 100 | | |||
101 | ListPanel* PanelTabBar::getPanel(int tabIdx) | 101 | ListPanel* PanelTabBar::getPanel(int tabIdx) | ||
102 | { | 102 | { | ||
103 | QVariant v = tabData(tabIdx); | 103 | QVariant v = tabData(tabIdx); | ||
104 | if (v.isNull()) return 0; | 104 | if (v.isNull()) return 0; | ||
105 | return (ListPanel*)v.toLongLong(); | 105 | return (ListPanel*)v.toLongLong(); | ||
106 | } | 106 | } | ||
Show All 22 Lines | |||||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | void PanelTabBar::updateTab(ListPanel *panel) | 131 | void PanelTabBar::updateTab(ListPanel *panel) | ||
132 | { | 132 | { | ||
133 | // find which is the correct tab | 133 | // find which is the correct tab | ||
134 | for (int i = 0; i < count(); i++) { | 134 | for (int i = 0; i < count(); i++) { | ||
135 | if ((ListPanel*)tabData(i).toLongLong() == panel) { | 135 | if ((ListPanel*)tabData(i).toLongLong() == panel) { | ||
136 | setTabText(i, squeeze(DISPLAY(panel->virtualPath()), i)); | 136 | setTabText(i, squeeze(DISPLAY(panel->virtualPath()), i)); | ||
137 | setIcon(i, panel); | ||||
137 | break; | 138 | break; | ||
138 | } | 139 | } | ||
139 | } | 140 | } | ||
140 | } | 141 | } | ||
141 | 142 | | |||
142 | void PanelTabBar::duplicateTab() | 143 | void PanelTabBar::duplicateTab() | ||
143 | { | 144 | { | ||
144 | int id = currentIndex(); | 145 | int id = currentIndex(); | ||
145 | emit newTab(((ListPanel*)tabData(id).toLongLong())->virtualPath()); | 146 | emit newTab(((ListPanel*)tabData(id).toLongLong())->virtualPath()); | ||
146 | } | 147 | } | ||
147 | 148 | | |||
148 | void PanelTabBar::closeTab() | 149 | void PanelTabBar::setIcon(int index, ListPanel *panel) | ||
149 | { | 150 | { | ||
150 | emit closeCurrentTab(); | 151 | setTabIcon(index, | ||
152 | panel->isLocked() ? krLoader->loadIcon("lock", KIconLoader::Toolbar, 16) : QIcon()); | ||||
151 | } | 153 | } | ||
152 | 154 | | |||
153 | QString PanelTabBar::squeeze(QString text, int index) | 155 | QString PanelTabBar::squeeze(QString text, int index) | ||
154 | { | 156 | { | ||
155 | QString originalText = text; | 157 | QString originalText = text; | ||
156 | 158 | | |||
157 | KConfigGroup group(krConfig, "Look&Feel"); | 159 | KConfigGroup group(krConfig, "Look&Feel"); | ||
158 | bool longNames = group.readEntry("Fullpath Tab Names", _FullPathTabNames); | 160 | bool longNames = group.readEntry("Fullpath Tab Names", _FullPathTabNames); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 261 | if (-1 == clickedTab) { // clicked on nothing ... | |||
260 | QTabBar::mousePressEvent(e); | 262 | QTabBar::mousePressEvent(e); | ||
261 | return; | 263 | return; | ||
262 | } | 264 | } | ||
263 | 265 | | |||
264 | _tabClicked = true; | 266 | _tabClicked = true; | ||
265 | 267 | | |||
266 | setCurrentIndex(clickedTab); | 268 | setCurrentIndex(clickedTab); | ||
267 | 269 | | |||
268 | ListPanel *p = getPanel(clickedTab); | 270 | ListPanel *p = getPanel(clickedTab); | ||
269 | if(p) | 271 | if (p) | ||
270 | p->slotFocusOnMe(); | 272 | p->slotFocusOnMe(); | ||
271 | 273 | | |||
272 | if (e->button() == Qt::RightButton) { | 274 | if (e->button() == Qt::RightButton) { | ||
273 | // show the popup menu | 275 | // show the popup menu | ||
274 | _panelActionMenu->menu()->popup(e->globalPos()); | 276 | _panelActionMenu->menu()->popup(e->globalPos()); | ||
275 | } else { | 277 | } else { | ||
276 | if (e->button() == Qt::MidButton)// close the current tab | 278 | if (e->button() == Qt::MidButton)// close the current tab | ||
277 | emit closeCurrentTab(); | 279 | emit closeCurrentTab(); | ||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |