forked from qt-creator/qt-creator
Locator: Show actions shortcuts in locator widget
Change-Id: Ib4d1e55e6335e691ee9ee85735e69a86b9276f15 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -139,8 +139,24 @@ void HighlightingItemDelegate::drawText(QPainter *painter,
|
||||
QVector<int> searchTermLengths =
|
||||
index.model()->data(index, int(HighlightingItemRole::Length)).value<QVector<int>>();
|
||||
|
||||
QVector<QTextLayout::FormatRange> formats;
|
||||
|
||||
const QString extraText
|
||||
= index.model()->data(index, int(HighlightingItemRole::DisplayExtra)).toString();
|
||||
if (!extraText.isEmpty()) {
|
||||
if (!option.state.testFlag(QStyle::State_Selected)) {
|
||||
int start = text.length();
|
||||
auto dataType = int(HighlightingItemRole::DisplayExtraForeground);
|
||||
const QColor highlightForeground = index.model()->data(index, dataType).value<QColor>();
|
||||
QTextCharFormat extraFormat;
|
||||
extraFormat.setForeground(highlightForeground);
|
||||
formats.append({start, int(extraText.length()), extraFormat});
|
||||
}
|
||||
text.append(extraText);
|
||||
}
|
||||
|
||||
if (searchTermStarts.isEmpty()) {
|
||||
drawDisplay(painter, option, rect, text.replace('\t', m_tabString), {});
|
||||
drawDisplay(painter, option, rect, text.replace('\t', m_tabString), formats);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,7 +191,6 @@ void HighlightingItemDelegate::drawText(QPainter *painter,
|
||||
highlightFormat.setForeground(highlightForeground);
|
||||
highlightFormat.setBackground(highlightBackground);
|
||||
|
||||
QVector<QTextLayout::FormatRange> formats;
|
||||
for (int i = 0, size = searchTermStarts.size(); i < size; ++i)
|
||||
formats.append({searchTermStarts.at(i), searchTermLengths.at(i), highlightFormat});
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ enum class HighlightingItemRole {
|
||||
Length,
|
||||
Foreground,
|
||||
Background,
|
||||
User
|
||||
User,
|
||||
DisplayExtra,
|
||||
DisplayExtraForeground
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT HighlightingItemDelegate : public QItemDelegate
|
||||
|
||||
@@ -245,6 +245,7 @@ void ActionsFilter::collectEntriesForCommands()
|
||||
const QStringList path = identifier.split(QLatin1Char('.'));
|
||||
const ActionFilterEntryData data{action, command->id()};
|
||||
LocatorFilterEntry filterEntry(this, text, QVariant::fromValue(data), action->icon());
|
||||
filterEntry.displayExtra = command->keySequence().toString(QKeySequence::NativeText);
|
||||
if (path.size() >= 2)
|
||||
filterEntry.extraInfo = path.mid(0, path.size() - 1).join(" > ");
|
||||
updateEntry(action, filterEntry);
|
||||
|
||||
@@ -79,6 +79,8 @@ struct LocatorFilterEntry
|
||||
ILocatorFilter *filter = nullptr;
|
||||
/* displayed string */
|
||||
QString displayName;
|
||||
/* extra information displayed in parentheses and light-gray next to display name (optional)*/
|
||||
QString displayExtra;
|
||||
/* extra information displayed in light-gray in a second column (optional) */
|
||||
QString extraInfo;
|
||||
/* additional tooltip */
|
||||
|
||||
@@ -213,6 +213,16 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
break;
|
||||
}
|
||||
case int(HighlightingItemRole::DisplayExtra): {
|
||||
if (index.column() == LocatorFilterEntry::HighlightInfo::DisplayName) {
|
||||
LocatorFilterEntry &entry = mEntries[index.row()];
|
||||
if (!entry.displayExtra.isEmpty())
|
||||
return QString(" (" + entry.displayExtra + ')');
|
||||
}
|
||||
break;
|
||||
}
|
||||
case int(HighlightingItemRole::DisplayExtraForeground):
|
||||
return QColor(Qt::darkGray);
|
||||
case int(HighlightingItemRole::Background):
|
||||
return mBackgroundColor;
|
||||
case int(HighlightingItemRole::Foreground):
|
||||
|
||||
Reference in New Issue
Block a user