-
Notifications
You must be signed in to change notification settings - Fork 1
/
filethumlabel.cpp
65 lines (61 loc) · 2.16 KB
/
filethumlabel.cpp
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
#include "filethumlabel.h"
FileThumLabel::FileThumLabel(QString filepath, int height, int width, QWidget *parent):
QWidget(parent),
m_filepath(filepath)
{
QFont ft;
ft.setPointSize(10);
this->setMouseTracking(true);
if(filepath == "default") {
this->m_filename = "返回上层";
this->isPDF = 0;
} else if(filepath == "add_collection") {
this->m_filename = "添加收藏";
this->isPDF = 0;
} else {
QFileInfo filei(filepath);
this->m_filename = filei.fileName();
this->isPDF = filei.isFile();
}
FileImageBuffer filebuff;
this->m_image_cache_path = filebuff.get_image_path(this->m_filepath, this->isPDF);
this->m_image = new QLabel;
qDebug() << this->m_image_cache_path;
this->m_image->setPixmap(QPixmap(this->m_image_cache_path).scaled(width * 0.7, width * 0.7 * 1.414));
this->m_title = new QLabel;
this->m_image->setAlignment(Qt::AlignCenter);
if(this->m_filename.size() > 20) {
this->m_title->setText(this->m_filename.mid(0, 20));
} else {
this->m_title->setText(this->m_filename);
}
this->m_title->setFont(ft);
this->m_title->setAlignment(Qt::AlignCenter);
auto _layout = new QVBoxLayout(this);
_layout->addWidget(this->m_image);
_layout->addWidget(this->m_title);
QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this->m_image);
shadow->setOffset(0, 0);
shadow->setColor(QColor("#555555"));
shadow->setBlurRadius(20);
this->m_image->setGraphicsEffect(shadow);
}
void FileThumLabel::mouseMoveEvent(QMouseEvent *event)
{
QPoint mousepos = event->pos();
//在坐标(0 ~ width,0 ~ height)范围内改变鼠标形状
if(mousepos.rx() > 0
&& mousepos.rx() < this->width()
&& mousepos.ry() > 0
&& mousepos.ry() < this->height())
{
this->setCursor(Qt::PointingHandCursor);
} else {
this->setCursor(Qt::ArrowCursor); //范围之外变回原来形状
}
}
void FileThumLabel::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) emit click_left(this);
else emit click_right(this, event->globalPos());
}