1#include "JobButton.h"
2
3#include <JenkinsJobInfo.h>
4
5#include <QLabel>
6#include <QIcon>
7#include <QHBoxLayout>
8#include <QMouseEvent>
9
10namespace Jenkins
11{
12JobButton::JobButton(const JenkinsJobInfo &job, QWidget *parent)
13 : QFrame(parent)
14 , mJob(job)
15{
16 mJob.name.replace("%2F", "/");
17 mJob.color.remove("_anime");
18
19 if (mJob.color.contains("blue"))
20 mJob.color = "green";
21 else if (mJob.color.contains("disabled") || mJob.color.contains("grey") || mJob.color.contains("notbuilt"))
22 mJob.color = "grey";
23 else if (mJob.color.contains("aborted"))
24 mJob.color = "dark_grey";
25
26 const auto icon = new QLabel();
27 icon->setPixmap(QIcon(QString(":/icons/%1").arg(mJob.color)).pixmap(22, 22));
28
29 const auto layout = new QHBoxLayout(this);
30 layout->setContentsMargins(QMargins());
31 layout->setSpacing(20);
32 layout->addWidget(icon);
33 layout->addWidget(new QLabel(mJob.name));
34 layout->addStretch();
35}
36
37void JobButton::mousePressEvent(QMouseEvent *e)
38{
39 mPressed = rect().contains(e->pos()) && e->button() == Qt::LeftButton;
40}
41
42void JobButton::mouseReleaseEvent(QMouseEvent *e)
43{
44 if (mPressed && rect().contains(e->pos()) && e->button() == Qt::LeftButton)
45 emit clicked();
46}
47
48}
49