diff options
Diffstat (limited to 'Swift/QtUI/UserSearch/UserSearchDelegate.cpp')
-rw-r--r-- | Swift/QtUI/UserSearch/UserSearchDelegate.cpp | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp index 1ac9eb3..8c7ca9a 100644 --- a/Swift/QtUI/UserSearch/UserSearchDelegate.cpp +++ b/Swift/QtUI/UserSearch/UserSearchDelegate.cpp @@ -27,44 +27,44 @@ UserSearchDelegate::~UserSearchDelegate() { } QSize UserSearchDelegate::sizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const { - //UserSearchItem* item = static_cast<UserSearchItem*>(index.internalPointer()); - QFontMetrics nameMetrics(common_.nameFont); - QFontMetrics statusMetrics(common_.detailFont); - int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); - return QSize(150, sizeByText); + //UserSearchItem* item = static_cast<UserSearchItem*>(index.internalPointer()); + QFontMetrics nameMetrics(common_.nameFont); + QFontMetrics statusMetrics(common_.detailFont); + int sizeByText = 2 * common_.verticalMargin + nameMetrics.height() + statusMetrics.height(); + return QSize(150, sizeByText); } -void UserSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { - UserSearchResult* item = static_cast<UserSearchResult*>(index.internalPointer()); - painter->save(); - QRect fullRegion(option.rect); - if (option.state & QStyle::State_Selected) { - painter->fillRect(fullRegion, option.palette.highlight()); - painter->setPen(option.palette.highlightedText().color()); - } - else { - QColor nameColor = UserSearchModel::data(item, Qt::TextColorRole).value<QColor> (); - painter->setPen(QPen(nameColor)); - } - - QFontMetrics nameMetrics(common_.nameFont); - painter->setFont(common_.nameFont); - int extraFontWidth = nameMetrics.width("H"); - int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; - QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); - - int nameHeight = nameMetrics.height() + common_.verticalMargin; - QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); - - painter->drawText(nameRegion, Qt::AlignTop, UserSearchModel::data(item, Qt::DisplayRole).toString()); - - painter->setFont(common_.detailFont); - painter->setPen(QPen(QColor(160, 160, 160))); - - QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); - painter->drawText(detailRegion, Qt::AlignTop, UserSearchModel::data(item, UserSearchModel::DetailTextRole).toString()); - - painter->restore(); +void UserSearchDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + UserSearchResult* item = static_cast<UserSearchResult*>(index.internalPointer()); + painter->save(); + QRect fullRegion(option.rect); + if (option.state & QStyle::State_Selected) { + painter->fillRect(fullRegion, option.palette.highlight()); + painter->setPen(option.palette.highlightedText().color()); + } + else { + QColor nameColor = UserSearchModel::data(item, Qt::TextColorRole).value<QColor> (); + painter->setPen(QPen(nameColor)); + } + + QFontMetrics nameMetrics(common_.nameFont); + painter->setFont(common_.nameFont); + int extraFontWidth = nameMetrics.width("H"); + int leftOffset = common_.horizontalMargin * 2 + extraFontWidth / 2; + QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0, 0)); + + int nameHeight = nameMetrics.height() + common_.verticalMargin; + QRect nameRegion(textRegion.adjusted(0, common_.verticalMargin, 0, 0)); + + painter->drawText(nameRegion, Qt::AlignTop, UserSearchModel::data(item, Qt::DisplayRole).toString()); + + painter->setFont(common_.detailFont); + painter->setPen(QPen(QColor(160, 160, 160))); + + QRect detailRegion(textRegion.adjusted(0, nameHeight, 0, 0)); + painter->drawText(detailRegion, Qt::AlignTop, UserSearchModel::data(item, UserSearchModel::DetailTextRole).toString()); + + painter->restore(); } } |