Changeset View
Changeset View
Standalone View
Standalone View
krusader/paneltabbar.cpp
Context not available. | |||||
197 | 197 | | |||
---|---|---|---|---|---|
198 | // set the real max length | 198 | // set the real max length | ||
199 | QFontMetrics fm(fontMetrics()); | 199 | QFontMetrics fm(fontMetrics()); | ||
200 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
201 | _maxTabLength = (dynamic_cast<QWidget*>(parent())->width() - (6 * fm.horizontalAdvance("W"))) / fm.horizontalAdvance("W"); | ||||
202 | #else | ||||
200 | _maxTabLength = (dynamic_cast<QWidget*>(parent())->width() - (6 * fm.width("W"))) / fm.width("W"); | 203 | _maxTabLength = (dynamic_cast<QWidget*>(parent())->width() - (6 * fm.width("W"))) / fm.width("W"); | ||
204 | #endif | ||||
201 | // each tab gets a fair share of the max tab length | 205 | // each tab gets a fair share of the max tab length | ||
202 | const int effectiveTabLength = _maxTabLength / (count() == 0 ? 1 : count()); | 206 | const int effectiveTabLength = _maxTabLength / (count() == 0 ? 1 : count()); | ||
207 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
208 | const int labelWidth = fm.horizontalAdvance("W") * effectiveTabLength; | ||||
209 | const int textWidth = fm.horizontalAdvance(text); | ||||
210 | #else | ||||
203 | const int labelWidth = fm.width("W") * effectiveTabLength; | 211 | const int labelWidth = fm.width("W") * effectiveTabLength; | ||
204 | const int textWidth = fm.width(text); | 212 | const int textWidth = fm.width(text); | ||
213 | #endif | ||||
205 | if (textWidth <= labelWidth) | 214 | if (textWidth <= labelWidth) | ||
206 | return text; | 215 | return text; | ||
207 | 216 | | |||
208 | // squeeze text - start with the dots only | 217 | // squeeze text - start with the dots only | ||
209 | QString squeezedText = "..."; | 218 | QString squeezedText = "..."; | ||
219 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
220 | int squeezedWidth = fm.horizontalAdvance(squeezedText); | ||||
221 | #else | ||||
210 | int squeezedWidth = fm.width(squeezedText); | 222 | int squeezedWidth = fm.width(squeezedText); | ||
223 | #endif | ||||
211 | 224 | | |||
212 | int letters = text.length() * (labelWidth - squeezedWidth) / textWidth / 2; | 225 | int letters = text.length() * (labelWidth - squeezedWidth) / textWidth / 2; | ||
213 | if (labelWidth < squeezedWidth) | 226 | if (labelWidth < squeezedWidth) | ||
214 | letters = 1; | 227 | letters = 1; | ||
215 | squeezedText = text.left(letters) + "..." + text.right(letters); | 228 | squeezedText = text.left(letters) + "..." + text.right(letters); | ||
229 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
230 | squeezedWidth = fm.horizontalAdvance(squeezedText); | ||||
231 | #else | ||||
216 | squeezedWidth = fm.width(squeezedText); | 232 | squeezedWidth = fm.width(squeezedText); | ||
233 | #endif | ||||
217 | 234 | | |||
218 | if (squeezedWidth < labelWidth) { | 235 | if (squeezedWidth < labelWidth) { | ||
219 | // we estimated too short | 236 | // we estimated too short | ||
Context not available. | |||||
221 | do { | 238 | do { | ||
222 | letters++; | 239 | letters++; | ||
223 | squeezedText = text.left(letters) + "..." + text.right(letters); | 240 | squeezedText = text.left(letters) + "..." + text.right(letters); | ||
241 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
242 | squeezedWidth = fm.horizontalAdvance(squeezedText); | ||||
243 | #else | ||||
224 | squeezedWidth = fm.width(squeezedText); | 244 | squeezedWidth = fm.width(squeezedText); | ||
245 | #endif | ||||
225 | } while (squeezedWidth < labelWidth); | 246 | } while (squeezedWidth < labelWidth); | ||
226 | letters--; | 247 | letters--; | ||
227 | squeezedText = text.left(letters) + "..." + text.right(letters); | 248 | squeezedText = text.left(letters) + "..." + text.right(letters); | ||
Context not available. | |||||
231 | do { | 252 | do { | ||
232 | letters--; | 253 | letters--; | ||
233 | squeezedText = text.left(letters) + "..." + text.right(letters); | 254 | squeezedText = text.left(letters) + "..." + text.right(letters); | ||
255 | #if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) | ||||
256 | squeezedWidth = fm.horizontalAdvance(squeezedText); | ||||
257 | #else | ||||
234 | squeezedWidth = fm.width(squeezedText); | 258 | squeezedWidth = fm.width(squeezedText); | ||
259 | #endif | ||||
235 | } while (letters && squeezedWidth > labelWidth); | 260 | } while (letters && squeezedWidth > labelWidth); | ||
236 | } | 261 | } | ||
237 | 262 | | |||
Context not available. |