blob: 306a2d17ececb5ffd2abffcd23370667cfe4f75a (
plain)
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
|
#include <QPainter>
#include <QAction>
#include <QLabel>
#include <QApplication>
#include <taglib/fileref.h>
#include <taglib/audioproperties.h>
#include "helper.h"
namespace Helper {
QIcon iconFromQChar(const QChar &c, int pixelSize){
QImage img(32, 32, QImage::Format_ARGB32);
img.fill(QColor(0, 0, 0, 0));
QPainter p(&img);
p.setRenderHint(QPainter::Antialiasing);
p.setRenderHint(QPainter::TextAntialiasing);
p.setRenderHint(QPainter::SmoothPixmapTransform);
p.setPen(qApp->palette().color(QPalette::Text));
QFont f(qApp->font());
f.setPixelSize(pixelSize);
f.setBold(true);
p.setFont(f);
p.drawText(img.rect(), Qt::AlignCenter, c);
return QIcon(QPixmap::fromImage(img));
}
QAction* createSeparator(QObject *parent){
QAction *a = new QAction(parent);
a->setSeparator(true);
return a;
}
quint64 lengthInSeconds(const QString &file){
TagLib::FileRef f(QString(file).toUtf8());
if(f.isNull()){
return 0;
}
TagLib::AudioProperties *props = f.audioProperties();
return props->lengthInSeconds();
}
QColor colorFromLabel(QLabel *l){
QColor retval;
const QPixmap *pm = l->pixmap();
if(pm){
QImage img = pm->toImage();
retval = img.pixelColor(0, 0);
}
return retval;
}
void fillLabel(QLabel *l, QColor c){
QPixmap newPm(l->sizeHint());
newPm.fill(c);
l->setPixmap(newPm);
}
}
|