chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -6,63 +6,49 @@
|
||||
#include "ElaSuggestBoxPrivate.h"
|
||||
#include "ElaSuggestModel.h"
|
||||
#include "ElaTheme.h"
|
||||
ElaSuggestDelegate::ElaSuggestDelegate(QObject* parent)
|
||||
: QStyledItemDelegate{parent}
|
||||
{
|
||||
ElaSuggestDelegate::ElaSuggestDelegate(QObject *parent) : QStyledItemDelegate{parent} {
|
||||
_themeMode = eTheme->getThemeMode();
|
||||
connect(eTheme, &ElaTheme::themeModeChanged, this, [=](ElaThemeType::ThemeMode themeMode) { _themeMode = themeMode; });
|
||||
}
|
||||
|
||||
ElaSuggestDelegate::~ElaSuggestDelegate()
|
||||
{
|
||||
}
|
||||
ElaSuggestDelegate::~ElaSuggestDelegate() {}
|
||||
|
||||
void ElaSuggestDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
int margin = 2;
|
||||
void ElaSuggestDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
int margin = 2;
|
||||
QStyleOptionViewItem viewOption(option);
|
||||
initStyleOption(&viewOption, index);
|
||||
|
||||
ElaSuggestModel* model = dynamic_cast<ElaSuggestModel*>(const_cast<QAbstractItemModel*>(index.model()));
|
||||
ElaSuggestion* suggest = model->getSearchSuggestion(index.row());
|
||||
if (option.state.testFlag(QStyle::State_HasFocus))
|
||||
{
|
||||
ElaSuggestModel *model = dynamic_cast<ElaSuggestModel *>(const_cast<QAbstractItemModel *>(index.model()));
|
||||
ElaSuggestion *suggest = model->getSearchSuggestion(index.row());
|
||||
if (option.state.testFlag(QStyle::State_HasFocus)) {
|
||||
viewOption.state &= ~QStyle::State_HasFocus;
|
||||
}
|
||||
painter->save();
|
||||
painter->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
|
||||
QPainterPath path;
|
||||
QRect optionRect = option.rect;
|
||||
QRect optionRect = option.rect;
|
||||
optionRect.adjust(margin * 2, margin, -margin * 2, -margin);
|
||||
path.addRoundedRect(optionRect, 8, 8);
|
||||
if (option.state & QStyle::State_Selected)
|
||||
{
|
||||
if (option.state & QStyle::State_MouseOver)
|
||||
{
|
||||
//选中时覆盖
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
// 选中时覆盖
|
||||
painter->fillPath(path, ElaThemeColor(_themeMode, BasicSelectedHoverAlpha));
|
||||
}
|
||||
else
|
||||
{
|
||||
//选中
|
||||
} else {
|
||||
// 选中
|
||||
painter->fillPath(path, ElaThemeColor(_themeMode, BasicSelectedAlpha));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (option.state & QStyle::State_MouseOver)
|
||||
{
|
||||
//覆盖时颜色
|
||||
} else {
|
||||
if (option.state & QStyle::State_MouseOver) {
|
||||
// 覆盖时颜色
|
||||
painter->fillPath(path, ElaThemeColor(_themeMode, BasicHoverAlpha));
|
||||
}
|
||||
}
|
||||
//文字绘制
|
||||
// 文字绘制
|
||||
painter->setPen(ElaThemeColor(_themeMode, BasicText));
|
||||
painter->drawText(option.rect.x() + 37, option.rect.y() + 25, suggest->getSuggestText());
|
||||
|
||||
//图标绘制
|
||||
if (suggest->getElaIcon() != ElaIconType::None)
|
||||
{
|
||||
// 图标绘制
|
||||
if (suggest->getElaIcon() != ElaIconType::None) {
|
||||
QFont iconFont = QFont("ElaAwesome");
|
||||
iconFont.setPixelSize(17);
|
||||
painter->setFont(iconFont);
|
||||
@@ -71,8 +57,7 @@ void ElaSuggestDelegate::paint(QPainter* painter, const QStyleOptionViewItem& op
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
QSize ElaSuggestDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
|
||||
{
|
||||
QSize ElaSuggestDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||
QSize size = QStyledItemDelegate::sizeHint(option, index);
|
||||
size.setHeight(40);
|
||||
return size;
|
||||
|
||||
Reference in New Issue
Block a user