-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patharticlebutton.cpp
More file actions
84 lines (69 loc) · 2.05 KB
/
articlebutton.cpp
File metadata and controls
84 lines (69 loc) · 2.05 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "articlebutton.h"
#include "ui_articlebutton.h"
#include <QMenu>
#include <QMouseEvent>
ArticleButton::ArticleButton(
const Article &article,
QWidget *parent
) :
QWidget(parent),
ui(new Ui::ArticleButton),
article(article), checked_(false)
{
ui->setupUi(this);
ui->articleTitle->setTextColor(QColor("black"));
ui->articleContent->setTextColor(QColor("black"));
ui->articleTitle->setAlignment(Qt::AlignLeft);
ui->articleContent->setAlignment(Qt::AlignLeft);
ui->articleTitle->setText(article.title);
ui->articleContent->setText(article.abstractContent);
ui->selectedBar->setStyleSheet("background-color: white");
bColor = BackGroundColor::White;
}
void ArticleButton::paintEvent(QPaintEvent *event) {
if(checked_ && bColor != BackGroundColor::Blue) {
ui->selectedBar->setStyleSheet("background-color: blue");
bColor = BackGroundColor::Blue;
} else if(!checked_ && bColor != BackGroundColor::White) {
ui->selectedBar->setStyleSheet("background-color: white");
bColor = BackGroundColor::White;
}
}
void ArticleButton::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::RightButton)
{
QWidget::mousePressEvent(event);
return;
}
//ignore if alreay selected
if(checked_) {
return;
}
checked_ = !checked_;
emit clicked(article.idx);
update();
}
int ArticleButton::getIdx() const {
return article.idx;
}
bool ArticleButton::isChecked() const {
return checked_;
}
void ArticleButton::setChecked(bool flag) {
checked_ = flag;
}
void ArticleButton::setTitle(const QString &title) {
ui->articleTitle->setText(title);
article.modifiedTime = QDateTime::currentDateTime();
}
void ArticleButton::setContent(const QString &content) {
ui->articleContent->setText(content);
article.modifiedTime = QDateTime::currentDateTime();
}
qint64 ArticleButton::getModifiedTime() const {
return article.modifiedTime.toMSecsSinceEpoch();
}
ArticleButton::~ArticleButton()
{
delete ui;
}