Changeset View
Changeset View
Standalone View
Standalone View
src/view/katestatusbar.cpp
Show All 37 Lines | |||||
38 | //BEGIN menu | 38 | //BEGIN menu | ||
39 | KateStatusBarOpenUpMenu::KateStatusBarOpenUpMenu(QWidget *parent) : QMenu(parent) {} | 39 | KateStatusBarOpenUpMenu::KateStatusBarOpenUpMenu(QWidget *parent) : QMenu(parent) {} | ||
40 | KateStatusBarOpenUpMenu::~KateStatusBarOpenUpMenu() {} | 40 | KateStatusBarOpenUpMenu::~KateStatusBarOpenUpMenu() {} | ||
41 | 41 | | |||
42 | void KateStatusBarOpenUpMenu::setVisible(bool visibility) | 42 | void KateStatusBarOpenUpMenu::setVisible(bool visibility) | ||
43 | { | 43 | { | ||
44 | if (visibility) { | 44 | if (visibility) { | ||
45 | QRect geo = geometry(); | 45 | QRect geo = geometry(); | ||
46 | QPoint pos = ((QPushButton *)parent())->mapToGlobal(QPoint(0, 0)); | 46 | QPoint pos = parentWidget()->mapToGlobal(QPoint(0, 0)); | ||
47 | geo.moveTopLeft(QPoint(pos.x(), pos.y() - geo.height())); | 47 | geo.moveTopLeft(QPoint(pos.x(), pos.y() - geo.height())); | ||
48 | if (geo.top() < 0) geo.moveTop(0); | 48 | if (geo.top() < 0) geo.moveTop(0); | ||
49 | setGeometry(geo); | 49 | setGeometry(geo); | ||
50 | } | 50 | } | ||
51 | 51 | | |||
52 | QMenu::setVisible(visibility); | 52 | QMenu::setVisible(visibility); | ||
53 | } | 53 | } | ||
54 | //END menu | 54 | //END menu | ||
55 | 55 | | |||
56 | //BEGIN StatusBarButton | ||||
57 | StatusBarButton::StatusBarButton(KateStatusBar *parent, const QString &text /*= QString()*/) | ||||
58 | : QPushButton(text, parent) | ||||
59 | { | ||||
60 | setFlat(true); | ||||
61 | setFocusProxy(parent->m_view); | ||||
62 | setMinimumSize(QSize(1, minimumSizeHint().height())); | ||||
63 | } | ||||
64 | | ||||
65 | StatusBarButton::~StatusBarButton() | ||||
66 | { | ||||
67 | } | ||||
68 | //END StatusBarButton | ||||
69 | | ||||
56 | KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view) | 70 | KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view) | ||
57 | : KateViewBarWidget(false) | 71 | : KateViewBarWidget(false) | ||
58 | , m_view(view) | 72 | , m_view(view) | ||
59 | , m_insertModeLabel(nullptr) | | |||
60 | , m_modifiedStatus(-1) | 73 | , m_modifiedStatus(-1) | ||
61 | , m_selectionMode(-1) | 74 | , m_selectionMode(-1) | ||
62 | , m_wordCounter(nullptr) | 75 | , m_wordCounter(nullptr) | ||
63 | { | 76 | { | ||
64 | KAcceleratorManager::setNoAccel(this); | 77 | KAcceleratorManager::setNoAccel(this); | ||
65 | setFocusProxy(m_view); | 78 | setFocusProxy(m_view); | ||
66 | 79 | | |||
67 | /** | 80 | /** | ||
68 | * just add our status bar to central widget, full sized | 81 | * just add our status bar to central widget, full sized | ||
69 | */ | 82 | */ | ||
70 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | 83 | QHBoxLayout *topLayout = new QHBoxLayout(centralWidget()); | ||
71 | topLayout->setMargin(0); | 84 | topLayout->setMargin(0); | ||
72 | topLayout->setSpacing(4); | 85 | topLayout->setSpacing(4); | ||
73 | 86 | | |||
74 | /** | 87 | /** | ||
75 | * add a bit space | 88 | * show modification state of the document | ||
89 | * TODO Using a (StatusBar)Button is currently pointless but handy due to no "setIcon()" function in QLabel. | ||||
90 | * Add some useful action when button is clicked, e.g. save document or show tool-tip | ||||
91 | * or find a way to not show a "focus frame" when hovered by mouse | ||||
76 | */ | 92 | */ | ||
77 | topLayout->addSpacing(4); | 93 | m_modified = new StatusBarButton(this); | ||
94 | topLayout->addWidget(m_modified); | ||||
78 | 95 | | |||
79 | /** | 96 | /** | ||
80 | * show Line XXX, Column XXX | 97 | * show Line XXX, Column XXX | ||
81 | */ | 98 | */ | ||
82 | m_lineColLabel = new QLabel(this); | 99 | m_cursorPosition = new StatusBarButton(this); | ||
83 | m_lineColLabel->installEventFilter(this); // register for doubleclick | 100 | topLayout->addWidget(m_cursorPosition); | ||
84 | topLayout->addWidget(m_lineColLabel, 0); | 101 | m_cursorPosition->setWhatsThis(i18n("Current cursor position. Click to go to a specific line.")); | ||
85 | m_lineColLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | 102 | connect(m_cursorPosition, &StatusBarButton::clicked, m_view, &KTextEditor::ViewPrivate::gotoLine); | ||
86 | m_lineColLabel->setFocusProxy(m_view); | | |||
87 | m_lineColLabel->setWhatsThis(i18n("Current cursor position. Doubleclick to go to specific line.")); | | |||
88 | 103 | | |||
89 | /** | 104 | // Separate the status line in a left and right part | ||
90 | * show word count | 105 | topLayout->addStretch(1); | ||
91 | */ | | |||
92 | m_wordCountLabel = new QLabel(this); | | |||
93 | topLayout->addWidget(m_wordCountLabel, 0); | | |||
94 | m_wordCountLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); | | |||
95 | m_wordCountLabel->setFocusProxy(m_view); | | |||
96 | m_wordCountLabel->setWhatsThis(i18n("Words and Chars count in document/selection.")); | | |||
97 | m_wordCountLabel->hide(); | | |||
98 | 106 | | |||
99 | /** | 107 | /** | ||
100 | * show the current mode, like INSERT, OVERWRITE, VI + modifiers like [BLOCK] | 108 | * show the current mode, like INSERT, OVERWRITE, VI + modifiers like [BLOCK] | ||
101 | */ | 109 | */ | ||
102 | m_insertModeLabel = new QLabel(this); | 110 | m_inputMode = new StatusBarButton(this); | ||
103 | m_insertModeLabel->installEventFilter(this); // register for doubleclick | 111 | topLayout->addWidget(m_inputMode); | ||
104 | topLayout->addWidget(m_insertModeLabel, 1000 /* this one should stretch */); | 112 | m_inputMode->setWhatsThis(i18n("Insert mode and VI input mode indicator. Click to change the mode.")); | ||
105 | m_insertModeLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight); | 113 | connect(m_inputMode, &StatusBarButton::clicked, [=] { m_view->currentInputMode()->toggleInsert(); }); | ||
106 | m_insertModeLabel->setFocusProxy(m_view); | | |||
107 | m_insertModeLabel->setWhatsThis(i18n("Insert mode and VI input mode indicator")); | | |||
108 | 114 | | |||
109 | /** | 115 | /** | ||
110 | * allow to change indentation configuration | 116 | * allow to change indentation configuration | ||
111 | */ | 117 | */ | ||
112 | m_spacesOnly = ki18n("Soft Tabs: %1"); | | |||
113 | m_spacesOnlyShowTabs = ki18n("Soft Tabs: %1 (%2)"); | | |||
114 | m_tabsOnly = ki18n("Tab Size: %1"); | | |||
115 | m_tabSpacesMixed = ki18n("Indent/Tab: %1/%2"); | | |||
116 | 118 | | |||
117 | QAction *action; | 119 | m_tabsIndent = new StatusBarButton(this); | ||
118 | m_tabGroup = new QActionGroup(this); | 120 | topLayout->addWidget(m_tabsIndent); | ||
119 | m_indentGroup = new QActionGroup(this); | | |||
120 | | ||||
121 | m_tabsIndent = new QPushButton(QString(), this); | | |||
122 | m_tabsIndent->setFlat(true); | | |||
123 | topLayout->addWidget(m_tabsIndent, 0); | | |||
124 | m_tabsIndent->setFocusProxy(m_view); | | |||
125 | 121 | | |||
126 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | 122 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | ||
127 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | 123 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | ||
124 | m_tabGroup = new QActionGroup(this); | ||||
128 | addNumberAction(m_tabGroup, m_indentSettingsMenu, -1); | 125 | addNumberAction(m_tabGroup, m_indentSettingsMenu, -1); | ||
129 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 8); | 126 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 8); | ||
130 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 4); | 127 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 4); | ||
131 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 2); | 128 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 2); | ||
129 | connect(m_tabGroup, &QActionGroup::triggered, this, &KateStatusBar::slotTabGroup); | ||||
130 | | ||||
132 | m_indentSettingsMenu->addSection(i18n("Indentation Width")); | 131 | m_indentSettingsMenu->addSection(i18n("Indentation Width")); | ||
132 | m_indentGroup = new QActionGroup(this); | ||||
133 | addNumberAction(m_indentGroup, m_indentSettingsMenu, -1); | 133 | addNumberAction(m_indentGroup, m_indentSettingsMenu, -1); | ||
134 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 8); | 134 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 8); | ||
135 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 4); | 135 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 4); | ||
136 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 2); | 136 | addNumberAction(m_indentGroup, m_indentSettingsMenu, 2); | ||
137 | connect(m_indentGroup, &QActionGroup::triggered, this, &KateStatusBar::slotIndentGroup); | ||||
137 | 138 | | |||
138 | m_indentSettingsMenu->addSection(i18n("Indentation Mode")); | 139 | m_indentSettingsMenu->addSection(i18n("Indentation Mode")); | ||
139 | QActionGroup *radioGroup = new QActionGroup(m_indentSettingsMenu); | 140 | QActionGroup *radioGroup = new QActionGroup(m_indentSettingsMenu); | ||
140 | action = m_indentSettingsMenu->addAction(i18n("Tabulators && Spaces")); | 141 | m_mixedAction = m_indentSettingsMenu->addAction(i18n("Tabulators && Spaces")); | ||
141 | action->setCheckable(true); | 142 | m_mixedAction->setCheckable(true); | ||
142 | action->setActionGroup(radioGroup); | 143 | m_mixedAction->setActionGroup(radioGroup); | ||
143 | m_mixedAction = action; | 144 | m_hardAction = m_indentSettingsMenu->addAction(i18n("Tabulators")); | ||
144 | action = m_indentSettingsMenu->addAction(i18n("Tabulators")); | 145 | m_hardAction->setCheckable(true); | ||
145 | action->setCheckable(true); | 146 | m_hardAction->setActionGroup(radioGroup); | ||
146 | action->setActionGroup(radioGroup); | 147 | m_softAction = m_indentSettingsMenu->addAction(i18n("Spaces")); | ||
147 | m_hardAction = action; | 148 | m_softAction->setCheckable(true); | ||
148 | action = m_indentSettingsMenu->addAction(i18n("Spaces")); | 149 | m_softAction->setActionGroup(radioGroup); | ||
149 | action->setCheckable(true); | 150 | connect(radioGroup, &QActionGroup::triggered, this, &KateStatusBar::slotIndentTabMode); | ||
150 | action->setActionGroup(radioGroup); | | |||
151 | m_softAction = action; | | |||
152 | 151 | | |||
153 | m_tabsIndent->setMenu(m_indentSettingsMenu); | 152 | m_tabsIndent->setMenu(m_indentSettingsMenu); | ||
154 | 153 | | |||
155 | /** | 154 | /** | ||
156 | * add encoding button which allows user to switch encoding of document | 155 | * add encoding button which allows user to switch encoding of document | ||
157 | * this will reuse the encoding action menu of the view | 156 | * this will reuse the encoding action menu of the view | ||
158 | */ | 157 | */ | ||
159 | m_encoding = new QPushButton(QString(), this); | 158 | m_encoding = new StatusBarButton(this); | ||
160 | m_encoding->setFlat(true); | 159 | topLayout->addWidget(m_encoding); | ||
161 | topLayout->addWidget(m_encoding, 0); | | |||
162 | m_encoding->setMenu(m_view->encodingAction()->menu()); | 160 | m_encoding->setMenu(m_view->encodingAction()->menu()); | ||
163 | m_encoding->setFocusProxy(m_view); | | |||
164 | m_encoding->setWhatsThis(i18n("Encoding")); | 161 | m_encoding->setWhatsThis(i18n("Encoding")); | ||
165 | 162 | | |||
166 | /** | 163 | /** | ||
167 | * add mode button which allows user to switch mode of document | 164 | * add mode button which allows user to switch mode of document | ||
168 | * this will reuse the mode action menu of the view | 165 | * this will reuse the mode action menu of the view | ||
169 | */ | 166 | */ | ||
170 | m_mode = new QPushButton(QString(), this); | 167 | m_mode = new StatusBarButton(this); | ||
171 | m_mode->setFlat(true); | 168 | topLayout->addWidget(m_mode); | ||
172 | topLayout->addWidget(m_mode, 0); | | |||
173 | m_mode->setMenu(m_view->modeAction()->menu()); | 169 | m_mode->setMenu(m_view->modeAction()->menu()); | ||
174 | m_mode->setFocusProxy(m_view); | | |||
175 | m_mode->setWhatsThis(i18n("Syntax highlighting")); | 170 | m_mode->setWhatsThis(i18n("Syntax highlighting")); | ||
176 | 171 | | |||
177 | /** | | |||
178 | * show modification state of the document | | |||
179 | */ | | |||
180 | m_modifiedLabel = new QToolButton(this); | | |||
181 | m_modifiedLabel->setAutoRaise(true); | | |||
182 | m_modifiedLabel->setEnabled(false); | | |||
183 | topLayout->addWidget(m_modifiedLabel, 0); | | |||
184 | m_modifiedLabel->setFocusProxy(m_view); | | |||
185 | | ||||
186 | /** | | |||
187 | * add a bit space | | |||
188 | */ | | |||
189 | topLayout->addSpacing(4); | | |||
190 | | ||||
191 | // signals for the statusbar | 172 | // signals for the statusbar | ||
192 | connect(m_view, SIGNAL(cursorPositionChanged(KTextEditor::View*, KTextEditor::Cursor)), this, SLOT(cursorPositionChanged())); | 173 | connect(m_view, &KTextEditor::View::cursorPositionChanged, this, &KateStatusBar::cursorPositionChanged); | ||
193 | connect(m_view, SIGNAL(viewModeChanged(KTextEditor::View*, KTextEditor::View::ViewMode)), this, SLOT(viewModeChanged())); | 174 | connect(m_view, &KTextEditor::View::viewModeChanged, this, &KateStatusBar::viewModeChanged); | ||
194 | connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(selectionChanged())); | 175 | connect(m_view, &KTextEditor::View::selectionChanged, this, &KateStatusBar::selectionChanged); | ||
195 | connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(modifiedChanged())); | 176 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modifiedChanged, this, &KateStatusBar::modifiedChanged); | ||
196 | connect(m_view->document(), SIGNAL(modifiedOnDisk(KTextEditor::Document*, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason)), this, SLOT(modifiedChanged())); | 177 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::modifiedOnDisk, this, &KateStatusBar::modifiedChanged); | ||
197 | connect(m_view->document(), SIGNAL(configChanged()), this, SLOT(documentConfigChanged())); | 178 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::configChanged, this, &KateStatusBar::documentConfigChanged); | ||
198 | connect(m_view->document(), SIGNAL(modeChanged(KTextEditor::Document*)), this, SLOT(modeChanged())); | 179 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modeChanged, this, &KateStatusBar::modeChanged); | ||
199 | connect(m_view, &KTextEditor::ViewPrivate::configChanged, this, &KateStatusBar::configChanged); | 180 | connect(m_view, &KTextEditor::ViewPrivate::configChanged, this, &KateStatusBar::configChanged); | ||
200 | 181 | | |||
201 | connect(m_tabGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotTabGroup(QAction*))); | | |||
202 | connect(m_indentGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotIndentGroup(QAction*))); | | |||
203 | connect(radioGroup, SIGNAL(triggered(QAction*)), this, SLOT(slotIndentTabMode(QAction*))); | | |||
204 | updateStatus(); | 182 | updateStatus(); | ||
205 | wordCountChanged(0, 0, 0, 0); | 183 | toggleWordCount(KateViewConfig::global()->showWordCount()); | ||
206 | } | 184 | } | ||
207 | 185 | | |||
208 | bool KateStatusBar::eventFilter(QObject *obj, QEvent *event) | 186 | bool KateStatusBar::eventFilter(QObject *obj, QEvent *event) | ||
209 | { | 187 | { | ||
210 | if (obj == m_insertModeLabel) { | | |||
211 | if (event->type() == QEvent::MouseButtonDblClick) { | | |||
212 | m_view->currentInputMode()->toggleInsert(); | | |||
213 | return true; | | |||
214 | } | | |||
215 | } else if (obj == m_lineColLabel) { | | |||
216 | if (event->type() == QEvent::MouseButtonDblClick) { | | |||
217 | m_view->gotoLine(); | | |||
218 | return true; | | |||
219 | } | | |||
220 | } | | |||
221 | | ||||
222 | return KateViewBarWidget::eventFilter(obj, event); | 188 | return KateViewBarWidget::eventFilter(obj, event); | ||
223 | } | 189 | } | ||
224 | 190 | | |||
225 | void KateStatusBar::contextMenuEvent(QContextMenuEvent *event) | 191 | void KateStatusBar::contextMenuEvent(QContextMenuEvent *event) | ||
226 | { | 192 | { | ||
193 | // TODO Add option "Show Statusbar" and options to show/hide buttons of the status bar | ||||
227 | QMenu menu(this); | 194 | QMenu menu(this); | ||
228 | QAction *showLines = menu.addAction(QStringLiteral("Show line count"), this, &KateStatusBar::toggleShowLines); | 195 | QAction *showLines = menu.addAction(QStringLiteral("Show line count"), this, &KateStatusBar::toggleShowLines); | ||
229 | showLines->setCheckable(true); | 196 | showLines->setCheckable(true); | ||
230 | showLines->setChecked(KateViewConfig::global()->showLineCount()); | 197 | showLines->setChecked(KateViewConfig::global()->showLineCount()); | ||
231 | QAction *showWords = menu.addAction(QStringLiteral("Show word count"), this, &KateStatusBar::toggleShowWords); | 198 | QAction *showWords = menu.addAction(QStringLiteral("Show word count"), this, &KateStatusBar::toggleShowWords); | ||
232 | showWords->setCheckable(true); | 199 | showWords->setCheckable(true); | ||
233 | showWords->setChecked(KateViewConfig::global()->showWordCount()); | 200 | showWords->setChecked(KateViewConfig::global()->showWordCount()); | ||
234 | menu.exec(event->globalPos()); | 201 | menu.exec(event->globalPos()); | ||
202 | | ||||
235 | } | 203 | } | ||
236 | 204 | | |||
237 | void KateStatusBar::toggleShowLines(bool checked) | 205 | void KateStatusBar::toggleShowLines(bool checked) | ||
238 | { | 206 | { | ||
239 | KateViewConfig::global()->setShowLineCount(checked); | 207 | KateViewConfig::global()->setShowLineCount(checked); | ||
240 | } | 208 | } | ||
241 | 209 | | |||
242 | void KateStatusBar::toggleShowWords(bool checked) | 210 | void KateStatusBar::toggleShowWords(bool checked) | ||
Show All 23 Lines | 226 | { | |||
266 | viewModeChanged(); | 234 | viewModeChanged(); | ||
267 | } | 235 | } | ||
268 | 236 | | |||
269 | void KateStatusBar::viewModeChanged() | 237 | void KateStatusBar::viewModeChanged() | ||
270 | { | 238 | { | ||
271 | // prepend BLOCK for block selection mode | 239 | // prepend BLOCK for block selection mode | ||
272 | QString text = m_view->viewModeHuman(); | 240 | QString text = m_view->viewModeHuman(); | ||
273 | if (m_view->blockSelection()) | 241 | if (m_view->blockSelection()) | ||
274 | text = i18n("<em>[BLOCK]</em> %1", text); | 242 | text = i18n("[BLOCK] %1", text); | ||
275 | 243 | | |||
276 | m_insertModeLabel->setText(text); | 244 | m_inputMode->setText(text); | ||
277 | } | 245 | } | ||
278 | 246 | | |||
279 | void KateStatusBar::cursorPositionChanged() | 247 | void KateStatusBar::cursorPositionChanged() | ||
280 | { | 248 | { | ||
281 | KTextEditor::Cursor position(m_view->cursorPositionVirtual()); | 249 | KTextEditor::Cursor position(m_view->cursorPositionVirtual()); | ||
282 | 250 | | |||
283 | if (KateViewConfig::global()->showLineCount()) | 251 | QString text; | ||
284 | m_lineColLabel->setText( | 252 | | ||
285 | i18n("Line %1 of %2, Column %3" | 253 | if (KateViewConfig::global()->showLineCount()) { | ||
286 | , QLocale().toString(position.line() + 1) | 254 | text = i18n("Line %1 of %2, Column %3", QLocale().toString(position.line() + 1) | ||
287 | , QLocale().toString(m_view->doc()->lines()) | 255 | , QLocale().toString(m_view->doc()->lines()) | ||
288 | , QLocale().toString(position.column() + 1) | 256 | , QLocale().toString(position.column() + 1) | ||
289 | ) | | |||
290 | ); | 257 | ); | ||
291 | 258 | } else { | |||
292 | else | 259 | text = i18n("Line %1, Column %2", QLocale().toString(position.line() + 1) | ||
293 | m_lineColLabel->setText( | | |||
294 | i18n("Line %1, Column %2" | | |||
295 | , QLocale().toString(position.line() + 1) | | |||
296 | , QLocale().toString(position.column() + 1) | 260 | , QLocale().toString(position.column() + 1) | ||
297 | ) | | |||
298 | ); | 261 | ); | ||
299 | } | 262 | } | ||
300 | 263 | | |||
264 | if (m_wordCounter) { | ||||
265 | text.append(QStringLiteral(", ") + m_wordCount); | ||||
266 | } | ||||
267 | | ||||
268 | m_cursorPosition->setText(text); | ||||
269 | } | ||||
270 | | ||||
301 | void KateStatusBar::modifiedChanged() | 271 | void KateStatusBar::modifiedChanged() | ||
302 | { | 272 | { | ||
303 | const bool mod = m_view->doc()->isModified(); | 273 | const bool mod = m_view->doc()->isModified(); | ||
304 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | 274 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | ||
305 | 275 | | |||
306 | /** | 276 | /** | ||
307 | * combine to modified status, update only if changed | 277 | * combine to modified status, update only if changed | ||
308 | */ | 278 | */ | ||
309 | unsigned int newStatus = (unsigned int)mod | ((unsigned int)modOnHD << 1); | 279 | unsigned int newStatus = (unsigned int)mod | ((unsigned int)modOnHD << 1); | ||
310 | if (m_modifiedStatus == newStatus) | 280 | if (m_modifiedStatus == newStatus) | ||
311 | return; | 281 | return; | ||
312 | 282 | | |||
313 | m_modifiedStatus = newStatus; | 283 | m_modifiedStatus = newStatus; | ||
314 | switch (m_modifiedStatus) { | 284 | switch (m_modifiedStatus) { | ||
315 | case 0x1: | 285 | case 0x1: | ||
316 | m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("document-save"))); | 286 | m_modified->setIcon(QIcon::fromTheme(QStringLiteral("document-save"))); | ||
317 | m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was modified since it was loaded")); | 287 | m_modified->setWhatsThis(i18n("Meaning of current icon: Document was modified since it was loaded")); | ||
318 | break; | 288 | break; | ||
319 | 289 | | |||
320 | case 0x2: | 290 | case 0x2: | ||
321 | m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); | 291 | m_modified->setIcon(QIcon::fromTheme(QStringLiteral("dialog-warning"))); | ||
322 | m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was modified or deleted by another program")); | 292 | m_modified->setWhatsThis(i18n("Meaning of current icon: Document was modified or deleted by another program")); | ||
323 | break; | 293 | break; | ||
324 | 294 | | |||
325 | case 0x3: | 295 | case 0x3: | ||
326 | m_modifiedLabel->setIcon(QIcon(KIconUtils::addOverlay(QIcon::fromTheme(QStringLiteral("document-save")), | 296 | m_modified->setIcon(QIcon(KIconUtils::addOverlay(QIcon::fromTheme(QStringLiteral("document-save")), | ||
327 | QIcon(QStringLiteral("emblem-important")), Qt::TopLeftCorner))); | 297 | QIcon(QStringLiteral("emblem-important")), Qt::TopLeftCorner))); | ||
328 | m_modifiedLabel->setWhatsThis(QString()); | 298 | m_modified->setWhatsThis(QString()); | ||
329 | break; | 299 | break; | ||
330 | 300 | | |||
331 | default: | 301 | default: | ||
332 | m_modifiedLabel->setIcon(QIcon::fromTheme(QStringLiteral("text-plain"))); | 302 | m_modified->setIcon(QIcon::fromTheme(QStringLiteral("text-plain"))); | ||
333 | m_modifiedLabel->setWhatsThis(i18n("Meaning of current icon: Document was not modified since it was loaded")); | 303 | m_modified->setWhatsThis(i18n("Meaning of current icon: Document was not modified since it was loaded")); | ||
334 | break; | 304 | break; | ||
335 | } | 305 | } | ||
336 | } | 306 | } | ||
337 | 307 | | |||
338 | void KateStatusBar::documentConfigChanged() | 308 | void KateStatusBar::documentConfigChanged() | ||
339 | { | 309 | { | ||
340 | m_encoding->setText(m_view->document()->encoding()); | 310 | m_encoding->setText(m_view->document()->encoding()); | ||
341 | KateDocumentConfig *config = ((KTextEditor::DocumentPrivate *)m_view->document())->config(); | 311 | KateDocumentConfig *config = ((KTextEditor::DocumentPrivate *)m_view->document())->config(); | ||
342 | int tabWidth = config->tabWidth(); | 312 | int tabWidth = config->tabWidth(); | ||
343 | int indentationWidth = config->indentationWidth(); | 313 | int indentationWidth = config->indentationWidth(); | ||
344 | bool replaceTabsDyn = config->replaceTabsDyn(); | 314 | bool replaceTabsDyn = config->replaceTabsDyn(); | ||
345 | 315 | | |||
316 | static const KLocalizedString spacesOnly = ki18n("Soft Tabs: %1"); | ||||
317 | static const KLocalizedString spacesOnlyShowTabs = ki18n("Soft Tabs: %1 (%2)"); | ||||
318 | static const KLocalizedString tabsOnly = ki18n("Tab Size: %1"); | ||||
319 | static const KLocalizedString tabSpacesMixed = ki18n("Indent/Tab: %1/%2"); | ||||
320 | | ||||
346 | if (!replaceTabsDyn) { | 321 | if (!replaceTabsDyn) { | ||
347 | if (tabWidth == indentationWidth) { | 322 | if (tabWidth == indentationWidth) { | ||
348 | m_tabsIndent->setText(m_tabsOnly.subs(tabWidth).toString()); | 323 | m_tabsIndent->setText(tabsOnly.subs(tabWidth).toString()); | ||
349 | m_tabGroup->setEnabled(false); | 324 | m_tabGroup->setEnabled(false); | ||
350 | m_hardAction->setChecked(true); | 325 | m_hardAction->setChecked(true); | ||
351 | } else { | 326 | } else { | ||
352 | m_tabsIndent->setText(m_tabSpacesMixed.subs(indentationWidth).subs(tabWidth).toString()); | 327 | m_tabsIndent->setText(tabSpacesMixed.subs(indentationWidth).subs(tabWidth).toString()); | ||
353 | m_tabGroup->setEnabled(true); | 328 | m_tabGroup->setEnabled(true); | ||
354 | m_mixedAction->setChecked(true); | 329 | m_mixedAction->setChecked(true); | ||
355 | } | 330 | } | ||
356 | } else { | 331 | } else { | ||
357 | if (tabWidth == indentationWidth) { | 332 | if (tabWidth == indentationWidth) { | ||
358 | m_tabsIndent->setText(m_spacesOnly.subs(indentationWidth).toString()); | 333 | m_tabsIndent->setText(spacesOnly.subs(indentationWidth).toString()); | ||
359 | m_tabGroup->setEnabled(true); | 334 | m_tabGroup->setEnabled(true); | ||
360 | m_softAction->setChecked(true); | 335 | m_softAction->setChecked(true); | ||
361 | } else { | 336 | } else { | ||
362 | m_tabsIndent->setText(m_spacesOnlyShowTabs.subs(indentationWidth).subs(tabWidth).toString()); | 337 | m_tabsIndent->setText(spacesOnlyShowTabs.subs(indentationWidth).subs(tabWidth).toString()); | ||
363 | m_tabGroup->setEnabled(true); | 338 | m_tabGroup->setEnabled(true); | ||
364 | m_softAction->setChecked(true); | 339 | m_softAction->setChecked(true); | ||
365 | } | 340 | } | ||
366 | } | 341 | } | ||
367 | 342 | | |||
368 | updateGroup(m_tabGroup, tabWidth); | 343 | updateGroup(m_tabGroup, tabWidth); | ||
369 | updateGroup(m_indentGroup, indentationWidth); | 344 | updateGroup(m_indentGroup, indentationWidth); | ||
370 | } | 345 | } | ||
Show All 16 Lines | 353 | { | |||
387 | a->setActionGroup(group); | 362 | a->setActionGroup(group); | ||
388 | } | 363 | } | ||
389 | 364 | | |||
390 | void KateStatusBar::updateGroup(QActionGroup *group, int w) | 365 | void KateStatusBar::updateGroup(QActionGroup *group, int w) | ||
391 | { | 366 | { | ||
392 | QAction *m1 = nullptr; | 367 | QAction *m1 = nullptr; | ||
393 | bool found = false; | 368 | bool found = false; | ||
394 | //linear search should be fast enough here, no additional hash | 369 | //linear search should be fast enough here, no additional hash | ||
395 | Q_FOREACH (QAction *action, group->actions()) { | 370 | for (QAction *action : group->actions()) { | ||
396 | int val = action->data().toInt(); | 371 | int val = action->data().toInt(); | ||
397 | if (val == -1) m1 = action; | 372 | if (val == -1) m1 = action; | ||
398 | if (val == w) { | 373 | if (val == w) { | ||
399 | found = true; | 374 | found = true; | ||
400 | action->setChecked(true); | 375 | action->setChecked(true); | ||
401 | } | 376 | } | ||
402 | } | 377 | } | ||
403 | if (found) { | 378 | if (found) { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 436 | { | |||
464 | } | 439 | } | ||
465 | 440 | | |||
466 | if (on) { | 441 | if (on) { | ||
467 | m_wordCounter = new WordCounter(m_view); | 442 | m_wordCounter = new WordCounter(m_view); | ||
468 | connect(m_wordCounter, &WordCounter::changed, this, &KateStatusBar::wordCountChanged); | 443 | connect(m_wordCounter, &WordCounter::changed, this, &KateStatusBar::wordCountChanged); | ||
469 | } else { | 444 | } else { | ||
470 | delete m_wordCounter; | 445 | delete m_wordCounter; | ||
471 | m_wordCounter = nullptr; | 446 | m_wordCounter = nullptr; | ||
472 | wordCountChanged(0, 0, 0, 0); | | |||
473 | } | 447 | } | ||
474 | 448 | | |||
475 | m_wordCountLabel->setVisible(on); | 449 | wordCountChanged(0, 0, 0, 0); | ||
476 | } | 450 | } | ||
477 | 451 | | |||
478 | void KateStatusBar::wordCountChanged(int wordsInDocument, int wordsInSelection, int charsInDocument, int charsInSelection) | 452 | void KateStatusBar::wordCountChanged(int wordsInDocument, int wordsInSelection, int charsInDocument, int charsInSelection) | ||
479 | { | 453 | { | ||
480 | m_wordCountLabel->setText(i18n("Words %1/%2, Chars %3/%4", | 454 | if (m_wordCounter) { | ||
481 | wordsInDocument, wordsInSelection, | 455 | m_wordCount = i18n("Words %1/%2, Chars %3/%4", wordsInDocument, wordsInSelection, charsInDocument, charsInSelection); | ||
482 | charsInDocument, charsInSelection)); | 456 | } else { | ||
457 | m_wordCount.clear(); | ||||
458 | } | ||||
459 | | ||||
460 | cursorPositionChanged(); | ||||
483 | } | 461 | } | ||
484 | 462 | | |||
485 | void KateStatusBar::configChanged() | 463 | void KateStatusBar::configChanged() | ||
486 | { | 464 | { | ||
487 | toggleWordCount(m_view->config()->showWordCount()); | 465 | toggleWordCount(m_view->config()->showWordCount()); | ||
488 | } | 466 | } |