Skip to content

Commit

Permalink
Do not use custom delegate when no search term is set (#211)
Browse files Browse the repository at this point in the history
This avoids additional rendering in SearchItemDelegate when there is
nothing to highlight.
  • Loading branch information
trollixx committed May 28, 2015
1 parent 6d21a78 commit 097bf24
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ui/searchitemdelegate.cpp
Expand Up @@ -17,6 +17,11 @@ SearchItemDelegate::SearchItemDelegate(QLineEdit *lineEdit, QWidget *view) :
void SearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option_,
const QModelIndex &index) const
{
if (!m_lineEdit || m_lineEdit->text().isEmpty()) {
QStyledItemDelegate::paint(painter, option_, index);
return;
}

painter->save();

QStyleOptionViewItem option(option_);
Expand Down Expand Up @@ -50,10 +55,7 @@ void SearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
const QFontMetrics metrics(painter->font());
QString elided = metrics.elidedText(index.data().toString(), option.textElideMode, rect.width());

QString highlight;
if (m_lineEdit)
highlight = Zeal::SearchQuery::fromString(m_lineEdit->text()).query();

const QString highlight = Zeal::SearchQuery::fromString(m_lineEdit->text()).query();
int from = 0;
while (from < elided.size()) {
const int until = highlight.isEmpty() ? -1 : elided.toLower().indexOf(highlight.toLower(), from);
Expand Down

0 comments on commit 097bf24

Please sign in to comment.