Changeset View
Changeset View
Standalone View
Standalone View
src/mode/katemodemenulist.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
60 | #else | 60 | #else | ||
61 | return true; | 61 | return true; | ||
62 | #endif | 62 | #endif | ||
63 | } | 63 | } | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | void KateModeMenuList::init(const SearchBarPosition searchBarPos) | 66 | void KateModeMenuList::init(const SearchBarPosition searchBarPos) | ||
67 | { | 67 | { | ||
68 | /* | ||||
69 | * Fix font size & font style: display the font correctly when changing it from the | ||||
70 | * KDE Plasma preferences. For example, the font type "Menu" is displayed, but "font()" | ||||
71 | * and "fontMetrics()" return the font type "General". Therefore, this overwrites the | ||||
72 | * "General" font. This makes it possible to correctly apply word wrapping on items, | ||||
73 | * when changing the font or its size. | ||||
74 | */ | ||||
75 | QFont font = this->font(); | ||||
76 | font.setFamily(font.family()); | ||||
77 | font.setStyle(font.style()); | ||||
78 | font.setStyleName(font.styleName()); | ||||
79 | font.setBold(font.bold()); | ||||
80 | font.setItalic(font.italic()); | ||||
81 | font.setUnderline(font.underline()); | ||||
82 | font.setStrikeOut(font.strikeOut()); | ||||
83 | font.setPointSize(font.pointSize()); | ||||
84 | setFont(font); | ||||
85 | | ||||
86 | // Create list and search bar | ||||
68 | m_list = KateModeMenuListData::Factory::createListView(this); | 87 | m_list = KateModeMenuListData::Factory::createListView(this); | ||
69 | m_searchBar = KateModeMenuListData::Factory::createSearchLine(this); | 88 | m_searchBar = KateModeMenuListData::Factory::createSearchLine(this); | ||
70 | 89 | | |||
71 | // Empty icon for items. | 90 | // Empty icon for items. | ||
72 | QPixmap emptyIconPixmap(m_iconSize, m_iconSize); | 91 | QPixmap emptyIconPixmap(m_iconSize, m_iconSize); | ||
73 | emptyIconPixmap.fill(Qt::transparent); | 92 | emptyIconPixmap.fill(Qt::transparent); | ||
74 | m_emptyIcon = QIcon(emptyIconPixmap); | 93 | m_emptyIcon = QIcon(emptyIconPixmap); | ||
75 | 94 | | |||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
119 | 138 | | |||
120 | m_layoutList->addWidget(m_list, 0, 0, Qt::AlignLeft); | 139 | m_layoutList->addWidget(m_list, 0, 0, Qt::AlignLeft); | ||
121 | 140 | | |||
122 | // Add scroll bar and set margin. | 141 | // Add scroll bar and set margin. | ||
123 | // Overlap scroll bar above the list widget. | 142 | // Overlap scroll bar above the list widget. | ||
124 | if (overlapScrollBar()) { | 143 | if (overlapScrollBar()) { | ||
125 | QHBoxLayout *layoutScrollBar = new QHBoxLayout(); | 144 | QHBoxLayout *layoutScrollBar = new QHBoxLayout(); | ||
126 | layoutScrollBar->addWidget(m_scroll); | 145 | layoutScrollBar->addWidget(m_scroll); | ||
127 | layoutScrollBar->setContentsMargins(2, 2, 2, 2); | 146 | layoutScrollBar->setContentsMargins(1, 2, 2, 2); | ||
128 | m_layoutList->addLayout(layoutScrollBar, 0, 0, Qt::AlignRight); | 147 | m_layoutList->addLayout(layoutScrollBar, 0, 0, Qt::AlignRight); | ||
129 | } | 148 | } | ||
130 | 149 | | |||
131 | layoutSearchBar->addWidget(m_searchBar); | 150 | layoutSearchBar->addWidget(m_searchBar); | ||
132 | if (searchBarPos == Top) { | 151 | if (searchBarPos == Top) { | ||
133 | layoutContainer->addLayout(layoutSearchBar); | 152 | layoutContainer->addLayout(layoutSearchBar); | ||
134 | } | 153 | } | ||
135 | layoutContainer->addLayout(m_layoutList); | 154 | layoutContainer->addLayout(m_layoutList); | ||
136 | if (searchBarPos == Bottom) { | 155 | if (searchBarPos == Bottom) { | ||
137 | layoutContainer->addLayout(layoutSearchBar); | 156 | layoutContainer->addLayout(layoutSearchBar); | ||
138 | } | 157 | } | ||
139 | 158 | | |||
140 | // In the Windows OS, decrease menu margins. | 159 | // In the Windows OS, decrease menu margins. | ||
141 | #ifdef Q_OS_WIN | 160 | #ifdef Q_OS_WIN | ||
142 | layoutContainer->setContentsMargins(3, 3, 3, 3); | 161 | layoutContainer->setContentsMargins(3, 3, 2, 3); | ||
143 | layoutContainer->setSpacing(0); | 162 | layoutContainer->setSpacing(0); | ||
144 | layoutSearchBar->setContentsMargins(2, 2, 2, 2); | 163 | if (searchBarPos == Bottom) { | ||
164 | layoutSearchBar->setContentsMargins(2, 5, 2, 2); | ||||
165 | } else if (searchBarPos == Top) { | ||||
166 | layoutSearchBar->setContentsMargins(2, 2, 2, 5); | ||||
167 | } | ||||
145 | layoutSearchBar->setSpacing(0); | 168 | layoutSearchBar->setSpacing(0); | ||
146 | m_layoutList->setContentsMargins(2, 2, 2, 2); | 169 | m_layoutList->setContentsMargins(2, 2, 2, 2); | ||
147 | m_layoutList->setSpacing(0); | 170 | m_layoutList->setSpacing(0); | ||
148 | #endif | 171 | #endif | ||
149 | 172 | | |||
150 | container->setLayout(layoutContainer); | 173 | container->setLayout(layoutContainer); | ||
151 | 174 | | |||
152 | QWidgetAction *widAct = new QWidgetAction(this); | 175 | QWidgetAction *widAct = new QWidgetAction(this); | ||
Show All 12 Lines | 187 | { | |||
165 | // couple model to view to let it be deleted with the view | 188 | // couple model to view to let it be deleted with the view | ||
166 | m_model = new QStandardItemModel(0, 0, m_list); | 189 | m_model = new QStandardItemModel(0, 0, m_list); | ||
167 | m_list->setModel(m_model); | 190 | m_list->setModel(m_model); | ||
168 | 191 | | |||
169 | QString *prevHlSection = nullptr; | 192 | QString *prevHlSection = nullptr; | ||
170 | /* | 193 | /* | ||
171 | * The width of the text container in the item, in pixels. This is used to make | 194 | * The width of the text container in the item, in pixels. This is used to make | ||
172 | * a custom word wrap and prevent the item's text from passing under the scroll bar. | 195 | * a custom word wrap and prevent the item's text from passing under the scroll bar. | ||
173 | * NOTE: 12 = the edges | 196 | * NOTE: 11 = Icon margin (8px) + Scroll bar margin (1px + 2px) | ||
174 | */ | 197 | */ | ||
175 | int maxWidthText; | 198 | int maxWidthText; | ||
176 | if (overlapScrollBar()) { | 199 | if (overlapScrollBar()) { | ||
177 | maxWidthText = m_list->sizeHint().width() - m_scroll->sizeHint().width() - m_iconSize - 12; | 200 | maxWidthText = m_list->sizeHint().width() - m_scroll->sizeHint().width() - m_iconSize - 11; | ||
178 | } else { | 201 | } else { | ||
179 | maxWidthText = m_list->sizeHint().width() - m_list->verticalScrollBar()->sizeHint().width() - m_iconSize - 19; | 202 | maxWidthText = m_list->sizeHint().width() - m_list->verticalScrollBar()->sizeHint().width() - m_iconSize - 12; | ||
180 | } | 203 | } | ||
181 | 204 | | |||
182 | // Transparent color used as background in the sections. | 205 | // Transparent color used as background in the sections. | ||
183 | QPixmap transparentPixmap = QPixmap(m_iconSize / 2, m_iconSize / 2); | 206 | QPixmap transparentPixmap = QPixmap(m_iconSize / 2, m_iconSize / 2); | ||
184 | transparentPixmap.fill(Qt::transparent); | 207 | transparentPixmap.fill(Qt::transparent); | ||
185 | QBrush transparentBrush(transparentPixmap); | 208 | QBrush transparentBrush(transparentPixmap); | ||
186 | 209 | | |||
187 | /* | 210 | /* | ||
188 | * The first item on the list is the "Best Search Matches" section, | 211 | * The first item on the list is the "Best Search Matches" section, | ||
189 | * which will remain hidden and will only be shown when necessary. | 212 | * which will remain hidden and will only be shown when necessary. | ||
190 | */ | 213 | */ | ||
191 | createSectionList(QString(), transparentBrush, false); | 214 | createSectionList(QString(), transparentBrush, false); | ||
215 | m_defaultHeightItemSection = m_list->visualRect(m_model->index(0, 0)).height(); | ||||
192 | m_list->setRowHidden(0, true); | 216 | m_list->setRowHidden(0, true); | ||
193 | 217 | | |||
194 | /* | 218 | /* | ||
195 | * Get list of modes from KateModeManager::list(). | 219 | * Get list of modes from KateModeManager::list(). | ||
196 | * We assume that the modes are arranged according to sections, alphabetically; | 220 | * We assume that the modes are arranged according to sections, alphabetically; | ||
197 | * and the attribute "translatedSection" isn't empty if "section" has a value. | 221 | * and the attribute "translatedSection" isn't empty if "section" has a value. | ||
198 | */ | 222 | */ | ||
199 | for (auto *hl : KTextEditor::EditorPrivate::self()->modeManager()->list()) { | 223 | for (auto *hl : KTextEditor::EditorPrivate::self()->modeManager()->list()) { | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 264 | #endif | |||
256 | section->setEnabled(false); | 280 | section->setEnabled(false); | ||
257 | section->setEditable(false); | 281 | section->setEditable(false); | ||
258 | section->setSelectable(false); | 282 | section->setSelectable(false); | ||
259 | 283 | | |||
260 | QLabel *label = new QLabel(sectionName, m_list); | 284 | QLabel *label = new QLabel(sectionName, m_list); | ||
261 | if (m_list->layoutDirection() == Qt::RightToLeft) { | 285 | if (m_list->layoutDirection() == Qt::RightToLeft) { | ||
262 | label->setAlignment(Qt::AlignRight); | 286 | label->setAlignment(Qt::AlignRight); | ||
263 | } | 287 | } | ||
264 | label->setTextFormat(Qt::RichText); | 288 | label->setTextFormat(Qt::PlainText); | ||
265 | label->setIndent(6); | 289 | label->setIndent(6); | ||
266 | 290 | | |||
267 | /* | 291 | /* | ||
268 | * NOTE: Names of sections in bold. The font color | 292 | * NOTE: Names of sections in bold. The font color | ||
269 | * should change according to Kate's color theme. | 293 | * should change according to Kate's color theme. | ||
270 | */ | 294 | */ | ||
271 | QFont font = label->font(); | 295 | QFont font = label->font(); | ||
272 | font.setWeight(QFont::Bold); | 296 | font.setWeight(QFont::Bold); | ||
273 | label->setFont(font); | 297 | label->setFont(font); | ||
274 | 298 | | |||
275 | section->setBackground(background); | 299 | section->setBackground(background); | ||
276 | 300 | | |||
277 | if (modelPosition < 0) { | 301 | if (modelPosition < 0) { | ||
278 | m_model->appendRow(section); | 302 | m_model->appendRow(section); | ||
279 | } else { | 303 | } else { | ||
280 | m_model->insertRow(modelPosition + 1, section); | 304 | m_model->insertRow(modelPosition + 1, section); | ||
281 | } | 305 | } | ||
282 | m_list->setIndexWidget(m_model->index(section->row(), 0), label); | 306 | m_list->setIndexWidget(m_model->index(section->row(), 0), label); | ||
283 | m_list->selectionModel()->select(section->index(), QItemSelectionModel::Deselect); | 307 | m_list->selectionModel()->select(section->index(), QItemSelectionModel::Deselect); | ||
284 | 308 | | |||
309 | // Apply word wrap in sections, for long labels. | ||||
310 | // NOTE: 3 = Scroll bar margin | ||||
311 | int containerTextWidth; | ||||
312 | if (overlapScrollBar()) { | ||||
313 | containerTextWidth = m_list->sizeHint().width() - m_scroll->sizeHint().width() - 3; | ||||
314 | } else { | ||||
315 | containerTextWidth = m_list->sizeHint().width() - m_list->verticalScrollBar()->sizeHint().width() - 2; | ||||
316 | } | ||||
317 | int heightSectionMargin = m_list->visualRect(m_model->index(section->row(), 0)).height() - label->sizeHint().height(); | ||||
318 | | ||||
319 | if (label->sizeHint().width() > containerTextWidth) { | ||||
320 | label->setText(setWordWrap(label->text(), containerTextWidth - label->indent(), label->fontMetrics())); | ||||
321 | if (heightSectionMargin < 2) { | ||||
322 | heightSectionMargin = 2; | ||||
323 | } | ||||
324 | section->setSizeHint(QSize(section->sizeHint().width(), label->sizeHint().height() + heightSectionMargin)); | ||||
325 | } else if (heightSectionMargin < 2) { | ||||
326 | section->setSizeHint(QSize(section->sizeHint().width(), label->sizeHint().height() + 2)); | ||||
327 | } | ||||
328 | | ||||
285 | return section; | 329 | return section; | ||
286 | } | 330 | } | ||
287 | 331 | | |||
288 | void KateModeMenuList::setButton(QPushButton *button, AlignmentHButton positionX, AlignmentVButton positionY, AutoUpdateTextButton autoUpdateTextButton) | 332 | void KateModeMenuList::setButton(QPushButton *button, AlignmentHButton positionX, AlignmentVButton positionY, AutoUpdateTextButton autoUpdateTextButton) | ||
289 | { | 333 | { | ||
290 | if (positionX == AlignHInverse) { | 334 | if (positionX == AlignHInverse) { | ||
291 | if (layoutDirection() == Qt::RightToLeft) { | 335 | if (layoutDirection() == Qt::RightToLeft) { | ||
292 | m_positionX = KateModeMenuList::AlignLeft; | 336 | m_positionX = KateModeMenuList::AlignLeft; | ||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Line(s) | 524 | { | |||
488 | 532 | | |||
489 | m_emptyListMsg->setAlignment(Qt::AlignCenter); | 533 | m_emptyListMsg->setAlignment(Qt::AlignCenter); | ||
490 | m_layoutList->addWidget(m_emptyListMsg, 0, 0, Qt::AlignCenter); | 534 | m_layoutList->addWidget(m_emptyListMsg, 0, 0, Qt::AlignCenter); | ||
491 | } | 535 | } | ||
492 | 536 | | |||
493 | QString KateModeMenuList::setWordWrap(const QString &text, const int maxWidth, const QFontMetrics &fontMetrics) const | 537 | QString KateModeMenuList::setWordWrap(const QString &text, const int maxWidth, const QFontMetrics &fontMetrics) const | ||
494 | { | 538 | { | ||
495 | // Get the length of the text, in pixels, and compare it with the container | 539 | // Get the length of the text, in pixels, and compare it with the container | ||
496 | if (fontMetrics.boundingRect(text).width() <= maxWidth) { | 540 | if (fontMetrics.horizontalAdvance(text) <= maxWidth) { | ||
497 | return text; | 541 | return text; | ||
498 | } | 542 | } | ||
499 | 543 | | |||
500 | // Add line breaks in the text to fit in the container | 544 | // Add line breaks in the text to fit in the container | ||
501 | QStringList words = text.split(QLatin1Char(' ')); | 545 | QStringList words = text.split(QLatin1Char(' ')); | ||
502 | if (words.count() < 1) { | 546 | if (words.count() < 1) { | ||
503 | return text; | 547 | return text; | ||
504 | } | 548 | } | ||
505 | QString newText = QString(); | 549 | QString newText = QString(); | ||
506 | QString tmpLineText = QString(); | 550 | QString tmpLineText = QString(); | ||
507 | 551 | | |||
508 | for (int i = 0; i < words.count() - 1; ++i) { | 552 | for (int i = 0; i < words.count() - 1; ++i) { | ||
553 | // Elide mode in long words | ||||
554 | if (fontMetrics.horizontalAdvance(words[i]) > maxWidth) { | ||||
555 | if (!tmpLineText.isEmpty()) { | ||||
556 | newText += tmpLineText + QLatin1Char('\n'); | ||||
557 | tmpLineText.clear(); | ||||
558 | } | ||||
559 | newText += fontMetrics.elidedText(words[i], m_list->layoutDirection() == Qt::RightToLeft ? Qt::ElideLeft : Qt::ElideRight, maxWidth) + QLatin1Char('\n'); | ||||
560 | continue; | ||||
561 | } else { | ||||
509 | tmpLineText += words[i]; | 562 | tmpLineText += words[i]; | ||
563 | } | ||||
510 | 564 | | |||
511 | // This prevents the last line of text from having only one word with 1 or 2 chars | 565 | // This prevents the last line of text from having only one word with 1 or 2 chars | ||
512 | if (i == words.count() - 3 && words[i + 2].length() <= 2 && fontMetrics.boundingRect(tmpLineText + QLatin1Char(' ') + words[i + 1] + QLatin1Char(' ') + words[i + 2]).width() > maxWidth) { | 566 | if (i == words.count() - 3 && words[i + 2].length() <= 2 && fontMetrics.horizontalAdvance(tmpLineText + QLatin1Char(' ') + words[i + 1] + QLatin1Char(' ') + words[i + 2]) > maxWidth) { | ||
513 | newText += tmpLineText + QLatin1Char('\n'); | 567 | newText += tmpLineText + QLatin1Char('\n'); | ||
514 | tmpLineText.clear(); | 568 | tmpLineText.clear(); | ||
515 | } | 569 | } | ||
516 | // Add line break if the maxWidth is exceeded with the next word | 570 | // Add line break if the maxWidth is exceeded with the next word | ||
517 | else if (fontMetrics.boundingRect(tmpLineText + QLatin1Char(' ') + words[i + 1]).width() > maxWidth) { | 571 | else if (fontMetrics.horizontalAdvance(tmpLineText + QLatin1Char(' ') + words[i + 1]) > maxWidth) { | ||
518 | newText += tmpLineText + QLatin1Char('\n'); | 572 | newText += tmpLineText + QLatin1Char('\n'); | ||
519 | tmpLineText.clear(); | 573 | tmpLineText.clear(); | ||
520 | } else { | 574 | } else { | ||
521 | tmpLineText.append(QLatin1Char(' ')); | 575 | tmpLineText.append(QLatin1Char(' ')); | ||
522 | } | 576 | } | ||
523 | } | 577 | } | ||
524 | 578 | | |||
525 | // Add line breaks in delimiters, if the last word is greater than the container | 579 | // Add line breaks in delimiters, if the last word is greater than the container | ||
526 | if (fontMetrics.boundingRect(words[words.count() - 1]).width() > maxWidth) { | 580 | bool bElidedLastWord = false; | ||
581 | if (fontMetrics.horizontalAdvance(words[words.count() - 1]) > maxWidth) { | ||||
582 | bElidedLastWord = true; | ||||
527 | const int lastw = words.count() - 1; | 583 | const int lastw = words.count() - 1; | ||
528 | for (int c = words[lastw].length() - 1; c >= 0; --c) { | 584 | for (int c = words[lastw].length() - 1; c >= 0; --c) { | ||
529 | if (isDelimiter(words[lastw][c].unicode()) && fontMetrics.boundingRect(words[lastw].mid(0, c + 1)).width() <= maxWidth) { | 585 | if (isDelimiter(words[lastw][c].unicode()) && fontMetrics.horizontalAdvance(words[lastw].mid(0, c + 1)) <= maxWidth) { | ||
586 | bElidedLastWord = false; | ||||
587 | if (fontMetrics.horizontalAdvance(words[lastw].mid(c + 1)) > maxWidth) { | ||||
588 | words[lastw] = words[lastw].mid(0, c + 1) + QLatin1Char('\n') + fontMetrics.elidedText(words[lastw].mid(c + 1), m_list->layoutDirection() == Qt::RightToLeft ? Qt::ElideLeft : Qt::ElideRight, maxWidth); | ||||
589 | } else { | ||||
530 | words[lastw].insert(c + 1, QLatin1Char('\n')); | 590 | words[lastw].insert(c + 1, QLatin1Char('\n')); | ||
591 | } | ||||
531 | break; | 592 | break; | ||
532 | } | 593 | } | ||
533 | } | 594 | } | ||
534 | } | 595 | } | ||
535 | 596 | | |||
536 | if (!tmpLineText.isEmpty()) { | 597 | if (!tmpLineText.isEmpty()) { | ||
537 | newText += tmpLineText; | 598 | newText += tmpLineText; | ||
538 | } | 599 | } | ||
600 | if (bElidedLastWord) { | ||||
601 | newText += fontMetrics.elidedText(words[words.count() - 1], m_list->layoutDirection() == Qt::RightToLeft ? Qt::ElideLeft : Qt::ElideRight, maxWidth); | ||||
602 | } else { | ||||
539 | newText += words[words.count() - 1]; | 603 | newText += words[words.count() - 1]; | ||
604 | } | ||||
540 | return newText; | 605 | return newText; | ||
541 | } | 606 | } | ||
542 | 607 | | |||
543 | void KateModeMenuListData::ListView::setSizeList(const int height, const int width) | 608 | void KateModeMenuListData::ListView::setSizeList(const int height, const int width) | ||
544 | { | 609 | { | ||
545 | setMinimumWidth(width); | 610 | setMinimumWidth(width); | ||
546 | setMaximumWidth(width); | 611 | setMaximumWidth(width); | ||
547 | setMinimumHeight(height); | 612 | setMinimumHeight(height); | ||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Line(s) | 989 | if (bEmptySection && lastSection > 0 && !listModel->item(listModel->rowCount() - 1, 0)->text().isEmpty()) { | |||
925 | listView->setRowHidden(lastSection, true); | 990 | listView->setRowHidden(lastSection, true); | ||
926 | listView->setRowHidden(lastSection - 1, true); | 991 | listView->setRowHidden(lastSection - 1, true); | ||
927 | } | 992 | } | ||
928 | 993 | | |||
929 | // Hide the separator line in the name of the first section. | 994 | // Hide the separator line in the name of the first section. | ||
930 | if (m_bestResults.isEmpty()) { | 995 | if (m_bestResults.isEmpty()) { | ||
931 | listView->setRowHidden(0, true); | 996 | listView->setRowHidden(0, true); | ||
932 | if (firstSection > 0) { | 997 | if (firstSection > 0) { | ||
933 | m_parentMenu->m_list->setRowHidden(firstSection - 1, true); | 998 | listView->setRowHidden(firstSection - 1, true); | ||
934 | } | | |||
935 | } | 999 | } | ||
936 | // Show "Best Search Matches" section, if there are items. | 1000 | } else { | ||
937 | else { | 1001 | /* | ||
938 | // Show title in singular or plural, depending on the number of items | 1002 | * Show "Best Search Matches" section, if there are items. | ||
939 | QLabel *labelSection = static_cast<QLabel *>(listView->indexWidget(m_parentMenu->m_model->index(0, 0))); | 1003 | */ | ||
1004 | | ||||
1005 | // Show title in singular or plural, depending on the number of items. | ||||
1006 | QLabel *labelSection = static_cast<QLabel *>(listView->indexWidget(listModel->index(0, 0))); | ||||
940 | if (m_bestResults.size() == 1) { | 1007 | if (m_bestResults.size() == 1) { | ||
941 | labelSection->setText( | 1008 | labelSection->setText(i18nc("Title (in singular) of the best result in an item search. Please, that the translation doesn't have more than 34 characters, since the menu where it's displayed is small and fixed.", "Best Search Match")); | ||
942 | i18nc("Title (in singular) of the best result in an item search. Please, that the translation doesn't have more than 34 characters, since the menu where it's displayed is small and fixed.", "Best Search Match")); | 1009 | } else { | ||
1010 | labelSection->setText(i18nc("Title (in plural) of the best results in an item search. Please, that the translation doesn't have more than 34 characters, since the menu where it's displayed is small and fixed.", "Best Search Matches")); | ||||
1011 | } | ||||
1012 | | ||||
1013 | int heightSectionMargin = m_parentMenu->m_defaultHeightItemSection - labelSection->sizeHint().height(); | ||||
1014 | if (heightSectionMargin < 2) { | ||||
1015 | heightSectionMargin = 2; | ||||
1016 | } | ||||
1017 | const int listWidth = listView->sizeHint().width() - 1; | ||||
1018 | int maxWidthText; | ||||
1019 | if (overlapScrollBar()) { | ||||
1020 | maxWidthText = listWidth - m_parentMenu->m_scroll->sizeHint().width() - 1; | ||||
943 | } else { | 1021 | } else { | ||
944 | labelSection->setText( | 1022 | maxWidthText = listWidth - listView->verticalScrollBar()->sizeHint().width(); | ||
945 | i18nc("Title (in plural) of the best results in an item search. Please, that the translation doesn't have more than 34 characters, since the menu where it's displayed is small and fixed.", "Best Search Matches")); | | |||
946 | } | 1023 | } | ||
1024 | // NOTE: labelSection->sizeHint().width() == labelSection->indent() + labelSection->fontMetrics().horizontalAdvance(labelSection->text()) | ||||
1025 | const bool bSectionMultiline = labelSection->sizeHint().width() > maxWidthText; | ||||
1026 | maxWidthText -= labelSection->indent(); | ||||
1027 | if (!bSectionMultiline) { | ||||
1028 | listModel->item(0, 0)->setSizeHint(QSize(listModel->item(0, 0)->sizeHint().width(), labelSection->sizeHint().height() + heightSectionMargin)); | ||||
947 | listView->setRowHidden(0, false); | 1029 | listView->setRowHidden(0, false); | ||
1030 | } | ||||
948 | 1031 | | |||
1032 | /* | ||||
1033 | * Show items in "Best Search Matches" section. | ||||
1034 | */ | ||||
949 | int rowModelBestResults = 0; // New position in the model | 1035 | int rowModelBestResults = 0; // New position in the model | ||
950 | 1036 | | |||
951 | // Special Case: always show the "R Script" mode first by typing "r" in the search box | 1037 | // Special Case: always show the "R Script" mode first by typing "r" in the search box | ||
952 | if (searchText.length() == 1 && searchText.compare(QLatin1String("r"), m_caseSensitivity) == 0) { | 1038 | if (searchText.length() == 1 && searchText.compare(QLatin1String("r"), m_caseSensitivity) == 0) { | ||
953 | for (QPair<ListItem *, int> itemBestResults : m_bestResults) { | 1039 | for (QPair<ListItem *, int> itemBestResults : m_bestResults) { | ||
954 | listModel->takeRow(itemBestResults.second); | 1040 | listModel->takeRow(itemBestResults.second); | ||
955 | ++rowModelBestResults; | 1041 | ++rowModelBestResults; | ||
956 | if (itemBestResults.first->getMode()->name == QLatin1String("R Script")) { | 1042 | if (itemBestResults.first->getMode()->name == QLatin1String("R Script")) { | ||
Show All 11 Lines | 1052 | for (QPair<ListItem *, int> itemBestResults : m_bestResults) { | |||
968 | listModel->insertRow(++rowModelBestResults, itemBestResults.first); | 1054 | listModel->insertRow(++rowModelBestResults, itemBestResults.first); | ||
969 | listView->setRowHidden(rowModelBestResults, false); | 1055 | listView->setRowHidden(rowModelBestResults, false); | ||
970 | } | 1056 | } | ||
971 | } | 1057 | } | ||
972 | if (lastItem == -1) { | 1058 | if (lastItem == -1) { | ||
973 | lastItem = rowModelBestResults; | 1059 | lastItem = rowModelBestResults; | ||
974 | } | 1060 | } | ||
975 | 1061 | | |||
1062 | // Add word wrap in long section titles. | ||||
1063 | if (bSectionMultiline) { | ||||
1064 | if (listView->visualRect(listModel->index(lastItem, 0)).bottom() + labelSection->sizeHint().height() + heightSectionMargin > listView->geometry().height() || labelSection->sizeHint().width() > listWidth) { | ||||
1065 | labelSection->setText(m_parentMenu->setWordWrap(labelSection->text(), maxWidthText, labelSection->fontMetrics())); | ||||
1066 | } | ||||
1067 | listModel->item(0, 0)->setSizeHint(QSize(listModel->item(0, 0)->sizeHint().width(), labelSection->sizeHint().height() + heightSectionMargin)); | ||||
1068 | listView->setRowHidden(0, false); | ||||
1069 | } | ||||
1070 | | ||||
976 | m_parentMenu->m_list->setCurrentItem(1); | 1071 | m_parentMenu->m_list->setCurrentItem(1); | ||
977 | } | 1072 | } | ||
978 | 1073 | | |||
979 | listView->scrollToTop(); | 1074 | listView->scrollToTop(); | ||
980 | 1075 | | |||
981 | // Show message of empty list | 1076 | // Show message of empty list | ||
982 | if (lastItem == -1) { | 1077 | if (lastItem == -1) { | ||
983 | if (m_parentMenu->m_emptyListMsg == nullptr) { | 1078 | if (m_parentMenu->m_emptyListMsg == nullptr) { | ||
▲ Show 20 Lines • Show All 44 Lines • Show Last 20 Lines |