-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResultItem.cpp
More file actions
66 lines (52 loc) · 1.84 KB
/
ResultItem.cpp
File metadata and controls
66 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "ResultItem.h"
#include "ui_ResultItem.h"
#include <QDesktopWidget>
#include <QFileIconProvider>
#include "ThemeSetting.h"
#include "HelperFunc.h"
ResultItem::ResultItem(QWidget *parent,Result* result) :
QWidget(parent),
m_result(*result),
ui(new Ui::ResultItem)
{
ui->setupUi(this);
int primary = QApplication::desktop()->primaryScreen();
int iwidth = QApplication::desktop()->screen(primary)->width();
setGeometry(0,0,iwidth/5*2 - 20, 60);
setTheme();
ui->labelTitle->setText(m_result.title);
ui->labelSubTitle->setText(m_result.subTitle);
m_uuid = m_result.id;
}
ResultItem::~ResultItem()
{
delete ui;
}
void ResultItem::updateIcon(QPixmap& pixmap)
{
ui->labelAppIcon->setPixmap(pixmap);
ui->labelAppIcon->setScaledContents(true);
}
void ResultItem::update()
{
ui->labelTitle->setText(m_result.title);
ui->labelSubTitle->setText(m_result.subTitle);
m_uuid = m_result.id;
}
void ResultItem::setTheme(QColor mainColorForImage)
{
Theme* theme = GetThemeSetting()->getSelectTheme();
if (!theme) return;
QColor textColor = GetThemeSetting()->resolvedTextColor(mainColorForImage);
// 副标题颜色比标题略淡
QColor subTitleColor = textColor;
subTitleColor.setAlpha(160);
ui->labelTitle->setStyleSheet(QString("color: %1;").arg(textColor.name()));
// 副标题使用 180/255 透明度,确保在复杂背景上也有足够对比度
ui->labelSubTitle->setStyleSheet(QString("color: rgba(%1, %2, %3, 180);")
.arg(textColor.red())
.arg(textColor.green())
.arg(textColor.blue()));
ui->labelTitle->setFont(GetUiFont(theme->title_font_size, QFont::Bold));
ui->labelSubTitle->setFont(GetUiFont(theme->subtitle_font_size, QFont::Normal));
}