-
Notifications
You must be signed in to change notification settings - Fork 0
/
pix.h
60 lines (55 loc) · 1.58 KB
/
pix.h
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
#ifndef ROUNDPIX_H
#define ROUNDPIX_H
#include <QPixmap>
#include <QImage>
#include <QBitmap>
#include <QPainter>
#include <QDebug>
class Pix
{
public:
QPixmap round(QImage image){
QPixmap img = rect(image);
QBitmap mask(img.size());
QPainter painter(&mask);
mask.fill(Qt::white);
painter.setBrush(Qt::black);
painter.drawEllipse(QPoint(mask.width()/2, mask.height()/2), img.width()/2, img.height()/2);
img.setMask(mask);
return img;
}
QPixmap rect(QImage image){
QImage copy;
if(image.height() > image.width()){
copy = image.copy( 0, (image.height()-image.width())/2, image.width(), image.width());
}
else{
copy = image.copy( (image.width()-image.height())/2, 0, image.height(), image.height());
}
QPixmap img = QPixmap::fromImage(copy);
return img;
}
QPixmap borderRadius(QImage image,int radius){
QPixmap img = rect(image);
QBitmap mask(img.size());
QPainter painter(&mask);
mask.fill(Qt::white);
painter.setBrush(Qt::black);
painter.drawRoundRect(0,0,mask.width(),mask.height(),radius,radius);
img.setMask(mask);
return img;
}
QString timeFromSecconds(int secs){
int mins = secs/60;
int sec = secs%60;
QString segundos;
if(sec<10){
segundos = "0" + QString::number(sec);
}
else{
segundos = QString::number(sec);
}
return QString::number(mins)+":"+segundos;
}
};
#endif // ROUNDPIX_H