parent
878714bc12
commit
e21b74ac25
@ -0,0 +1,5 @@
|
||||
HEADERS += \
|
||||
$$PWD/iconhelper.h
|
||||
|
||||
SOURCES += \
|
||||
$$PWD/iconhelper.cpp
|
||||
@ -0,0 +1,24 @@
|
||||
#include "iconhelper.h"
|
||||
|
||||
IconHelper* IconHelper::_instance = 0;
|
||||
IconHelper::IconHelper(QObject*):
|
||||
QObject(qApp)
|
||||
{
|
||||
int fontId = QFontDatabase::addApplicationFont(":/res/fontawesome-webfont.ttf");
|
||||
QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0);
|
||||
iconFont = QFont(fontName);
|
||||
}
|
||||
|
||||
void IconHelper::SetIcon(QLabel* lab, QChar c, int size)
|
||||
{
|
||||
iconFont.setPointSize(size);
|
||||
lab->setFont(iconFont);
|
||||
lab->setText(c);
|
||||
}
|
||||
|
||||
void IconHelper::SetIcon(QPushButton* btn, QChar c, int size)
|
||||
{
|
||||
iconFont.setPointSize(size);
|
||||
btn->setFont(iconFont);
|
||||
btn->setText(c);
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
#ifndef ICONHELPER_H
|
||||
#define ICONHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QFont>
|
||||
#include <QFontDatabase>
|
||||
#include <QMutex>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QApplication>
|
||||
|
||||
class IconHelper : public QObject
|
||||
{
|
||||
private:
|
||||
explicit IconHelper(QObject *parent = 0);
|
||||
QFont iconFont;
|
||||
static IconHelper* _instance;
|
||||
|
||||
public:
|
||||
static IconHelper* Instance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (!_instance) {
|
||||
QMutexLocker locker(&mutex);
|
||||
if (!_instance) {
|
||||
_instance = new IconHelper;
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void SetIcon(QLabel* lab, QChar c, int size = 10);
|
||||
void SetIcon(QPushButton* btn, QChar c, int size = 10);
|
||||
|
||||
};
|
||||
|
||||
#endif // ICONHELPER_H
|
||||
@ -1,5 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>res/psblack.css</file>
|
||||
<file>res/fontawesome-webfont.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue