-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstareditor.cpp
93 lines (85 loc) · 1.95 KB
/
stareditor.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <QtGui>
#include "stareditor.h"
#include "starrating.h"
/**
* @brief Constructor
* @param parent
*/
StarEditor::StarEditor(QWidget *parent)
: QWidget(parent)
{
setAutoFillBackground(true);
}
/**
* @brief Resize
* @return
*/
QSize StarEditor::sizeHint() const
{
return myStarRating.sizeHint();
}
/**
* @brief Painter
*/
void StarEditor::paintEvent(QPaintEvent *)
{
QPainter painter(this);
myStarRating.paint(&painter, rect(), this->palette(),
StarRating::Editable);
}
/**
* @brief Catch position
* @param event
*/
void StarEditor::mousePressEvent(QMouseEvent *event)
{
this->start = starAtPosition(event->x());
}
/**
* @brief Catch release and edit
* @param event
*/
void StarEditor::mouseReleaseEvent(QMouseEvent *event)
{
int end = starAtPosition(event->x());
if(end<start)
{
int a = start;
this->start = end;
end = a;
}
for(int star = this->start; star<=end; star++)
{
//to activate if 1hour = 1 task
if(alDisp)
{
if(myStarRating.getVect().at(star-1))
myStarRating.setStar(star-1);
else if(myStarRating.db->isAllocated(myStarRating.day, star-1) < alDisp)
myStarRating.setStar(star-1);
}
else
myStarRating.setStar(star-1);
if(myStarRating.getVect().at(star-1))
{
myStarRating.db->addAllocation(myStarRating.task, myStarRating.day, star-1);
}
else
myStarRating.db->deleteAllocation(myStarRating.task, myStarRating.day, star-1);
update();
}
emit editingFinished();
}
/**
* @brief Give item from x position
* @param x
* @return
*/
int StarEditor::starAtPosition(int x)
{
int star = (x / (myStarRating.sizeHint().width()
/ myStarRating.maxStarCount())) + 1;
if (star <= 0 || star > myStarRating.maxStarCount())
return myStarRating.maxStarCount();
return star;
}