#include #include #include #include #include #include #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); } }