mirror of
https://github.com/gamecreature/QtAwesome.git
synced 2024-11-15 13:35:44 +08:00
updated font awesome to v5.10.2, added support to pro icons (pro fonts not included)
This commit is contained in:
parent
86f3bb8abb
commit
902790e03e
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,10 @@
|
||||
defineReplace( resourcesForConfig ){
|
||||
return($$PWD/QtAwesome$$eval($$1).qrc)
|
||||
}
|
||||
|
||||
options = $$find(CONFIG, fontAwesomePro) $$find(CONFIG, fontAwesomeFree)
|
||||
count(options, 0) { error("fontAwesomePro or fontAwesomeFree should be defined") }
|
||||
count(options, 2) { error("fontAwesomePro and fontAwesomeFree were defined, only one config is accepted") }
|
||||
|
||||
INCLUDEPATH += $$PWD
|
||||
|
||||
@ -6,7 +13,18 @@ SOURCES += $$PWD/QtAwesome.cpp \
|
||||
|
||||
HEADERS += $$PWD/QtAwesome.h \
|
||||
$$PWD/QtAwesomeAnim.h
|
||||
|
||||
RESOURCES += $$PWD/QtAwesome.qrc
|
||||
|
||||
CONFIG( fontAwesomePro ){
|
||||
config = Pro
|
||||
RESOURCES += $$resourcesForConfig(config)
|
||||
DEFINES += FONT_AWESOME_PRO=1
|
||||
!build_pass:message(using font awesome pro)
|
||||
}
|
||||
|
||||
CONFIG( fontAwesomeFree ){
|
||||
config = Free
|
||||
RESOURCES += $$resourcesForConfig(config)
|
||||
!build_pass:message(using font awesome free)
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,8 +9,10 @@ TEMPLATE = lib
|
||||
CONFIG += staticlib c++11
|
||||
QT += widgets
|
||||
|
||||
SOURCES += QtAwesome.cpp QtAwesomeAnim.cpp
|
||||
HEADERS += QtAwesome.h QtAwesomeAnim.h
|
||||
# only one option must be enabled
|
||||
#CONFIG += fontAwesomePro
|
||||
CONFIG += fontAwesomeFree
|
||||
include(QtAwesome.pri)
|
||||
|
||||
isEmpty(PREFIX) {
|
||||
unix {
|
||||
@ -24,6 +26,3 @@ install_headers.files = QtAwesome.h QtAwesomeAnim.h
|
||||
install_headers.path = $$PREFIX/include
|
||||
target.path = $$PREFIX/lib
|
||||
INSTALLS += install_headers target
|
||||
|
||||
RESOURCES += \
|
||||
QtAwesome.qrc
|
||||
|
@ -1,5 +0,0 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>fonts/fontawesome-4.7.0.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -9,7 +9,7 @@
|
||||
|
||||
QtAwesomeAnimation::QtAwesomeAnimation(QWidget *parentWidget, int interval, int step)
|
||||
: parentWidgetRef_( parentWidget )
|
||||
, timer_( 0 )
|
||||
, timer_( nullptr )
|
||||
, interval_( interval )
|
||||
, step_( step )
|
||||
, angle_( 0.0f )
|
||||
@ -29,11 +29,11 @@ void QtAwesomeAnimation::setup( QPainter &painter, const QRect &rect)
|
||||
else
|
||||
{
|
||||
//timer, angle, self.step = self.info[self.parent_widget]
|
||||
float x_center = rect.width() * 0.5;
|
||||
float y_center = rect.height() * 0.5;
|
||||
painter.translate(x_center, y_center);
|
||||
painter.rotate(angle_);
|
||||
painter.translate(-x_center, -y_center);
|
||||
float x_center = rect.width() * 0.5f;
|
||||
float y_center = rect.height() * 0.5f;
|
||||
painter.translate(static_cast<qreal>(x_center), static_cast<qreal>(y_center));
|
||||
painter.rotate(static_cast<qreal>(angle_));
|
||||
painter.translate(static_cast<qreal>(-x_center), -static_cast<qreal>(y_center));
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,6 @@ void QtAwesomeAnimation::setup( QPainter &painter, const QRect &rect)
|
||||
void QtAwesomeAnimation::update()
|
||||
{
|
||||
angle_ += step_;
|
||||
angle_ = std::fmod( angle_, 360);
|
||||
angle_ = std::fmod( static_cast<float>(angle_), 360.0f);
|
||||
parentWidgetRef_->update();
|
||||
}
|
||||
|
7
QtAwesome/QtAwesomeFree.qrc
Normal file
7
QtAwesome/QtAwesomeFree.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>fonts/Font Awesome 5 Brands-Regular-400.otf</file>
|
||||
<file>fonts/Font Awesome 5 Free-Regular-400.otf</file>
|
||||
<file>fonts/Font Awesome 5 Free-Solid-900.otf</file>
|
||||
</qresource>
|
||||
</RCC>
|
9
QtAwesome/QtAwesomePro.qrc
Normal file
9
QtAwesome/QtAwesomePro.qrc
Normal file
@ -0,0 +1,9 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>fonts/Font Awesome 5 Brands-Regular-400.otf</file>
|
||||
<file>fonts/Font Awesome 5 Duotone-Solid-900.otf</file>
|
||||
<file>fonts/Font Awesome 5 Pro-Light-300.otf</file>
|
||||
<file>fonts/Font Awesome 5 Pro-Regular-400.otf</file>
|
||||
<file>fonts/Font Awesome 5 Pro-Solid-900.otf</file>
|
||||
</qresource>
|
||||
</RCC>
|
BIN
QtAwesome/fonts/Font Awesome 5 Brands-Regular-400.otf
Normal file
BIN
QtAwesome/fonts/Font Awesome 5 Brands-Regular-400.otf
Normal file
Binary file not shown.
BIN
QtAwesome/fonts/Font Awesome 5 Free-Regular-400.otf
Normal file
BIN
QtAwesome/fonts/Font Awesome 5 Free-Regular-400.otf
Normal file
Binary file not shown.
BIN
QtAwesome/fonts/Font Awesome 5 Free-Solid-900.otf
Normal file
BIN
QtAwesome/fonts/Font Awesome 5 Free-Solid-900.otf
Normal file
Binary file not shown.
Binary file not shown.
@ -11,10 +11,17 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
||||
TARGET = QtAwesomeSample
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
HEADERS +=
|
||||
HEADERS += \
|
||||
mainwindow.h
|
||||
|
||||
|
||||
# only one option must be enabled
|
||||
#CONFIG += fontAwesomePro
|
||||
CONFIG += fontAwesomeFree
|
||||
include(../QtAwesome/QtAwesome.pri)
|
||||
|
||||
FORMS += \
|
||||
mainwindow.ui
|
||||
|
@ -12,52 +12,13 @@
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
QMainWindow w;
|
||||
MainWindow w;
|
||||
|
||||
QtAwesome* awesome = new QtAwesome(&w);
|
||||
awesome->initFontAwesome();
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout();
|
||||
|
||||
// a simple beer button
|
||||
//=====================
|
||||
{
|
||||
QPushButton* beerButton = new QPushButton( "Cheers!");
|
||||
|
||||
QVariantMap options;
|
||||
options.insert("anim", qVariantFromValue( new QtAwesomeAnimation(beerButton) ) );
|
||||
beerButton->setIcon( awesome->icon( fa::beer, options ) );
|
||||
|
||||
layout->addWidget(beerButton);
|
||||
}
|
||||
|
||||
// a simple beer checkbox button
|
||||
//==============================
|
||||
{
|
||||
QPushButton* toggleButton = new QPushButton("Toggle Me");
|
||||
toggleButton->setCheckable(true);
|
||||
|
||||
QVariantMap options;
|
||||
options.insert("color", QColor(Qt::green) );
|
||||
options.insert("text-off", QString(fa::squareo) );
|
||||
options.insert("color-off", QColor(Qt::red) );
|
||||
toggleButton->setIcon( awesome->icon( fa::checksquareo, options ));
|
||||
|
||||
|
||||
layout->addWidget(toggleButton);
|
||||
}
|
||||
|
||||
|
||||
// add the samples
|
||||
QWidget* samples = new QWidget();
|
||||
samples->setLayout(layout);
|
||||
w.setCentralWidget(samples);
|
||||
|
||||
w.show();
|
||||
|
||||
w.show();
|
||||
return app.exec();
|
||||
}
|
||||
|
89
QtAwesomeSample/mainwindow.cpp
Normal file
89
QtAwesomeSample/mainwindow.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
#include "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "QtAwesome.h"
|
||||
#include <QStandardItemModel>
|
||||
#include <QMap>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
awesome = new QtAwesome(this);
|
||||
awesome->initFontAwesome();
|
||||
|
||||
for(int st=style::fas; st<=style::fab; st++){
|
||||
switch(st){
|
||||
case style::fab:
|
||||
ui->comboBox->insertItem(style::fab, "Brands", style::fab);
|
||||
break;
|
||||
case style::far:
|
||||
ui->comboBox->insertItem(style::far, "Regular", style::far);
|
||||
break;
|
||||
case style::fas:
|
||||
ui->comboBox->insertItem(style::fas, "Solid", style::fas);
|
||||
break;
|
||||
#ifdef FONT_AWESOME_PRO
|
||||
case style::fal:
|
||||
ui->comboBox->insertItem(style::fal, "Light", style::fal);
|
||||
break;
|
||||
case style::fad:
|
||||
ui->comboBox->insertItem(style::fad, "Duotone", style::fad);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// a simple beer button
|
||||
//=====================
|
||||
{
|
||||
QPushButton* beerButton = ui->beerButton;
|
||||
|
||||
QVariantMap options;
|
||||
options.insert("anim", qVariantFromValue( new QtAwesomeAnimation(beerButton) ) );
|
||||
beerButton->setIcon( awesome->icon( "fas beer", options ) );
|
||||
}
|
||||
|
||||
// a simple beer checkbox button
|
||||
//==============================
|
||||
{
|
||||
QPushButton* toggleButton = ui->toggleButton;
|
||||
toggleButton->setCheckable(true);
|
||||
|
||||
QVariantMap options;
|
||||
options.insert("color", QColor(Qt::green) );
|
||||
options.insert("text-off", QString(fa::square) );
|
||||
options.insert("color-off", QColor(Qt::red) );
|
||||
toggleButton->setIcon( awesome->icon( "far check-square", options ));
|
||||
}
|
||||
|
||||
QStandardItemModel *model = new QStandardItemModel(this);
|
||||
ui->listView->setModel(model);
|
||||
|
||||
connect(ui->comboBox, SIGNAL(activated(int)), this, SLOT(styleChanged(int)));
|
||||
ui->comboBox->setCurrentIndex(style::fab);
|
||||
styleChanged(style::fab);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void MainWindow::styleChanged(int index)
|
||||
{
|
||||
|
||||
QHash<QString, int> iconset = awesome->namedCodePoints(static_cast<style::styles>(index));
|
||||
|
||||
QStandardItemModel *model = dynamic_cast<QStandardItemModel*>(ui->listView->model());
|
||||
model->clear();
|
||||
|
||||
for(QHash<QString, int>::iterator i=iconset.begin();i!=iconset.end();++i)
|
||||
{
|
||||
QString name = i.key();
|
||||
int ic = i.value();
|
||||
|
||||
model->appendRow(new QStandardItem(awesome->icon(index, ic), name));
|
||||
}
|
||||
model->sort(0);
|
||||
}
|
27
QtAwesomeSample/mainwindow.h
Normal file
27
QtAwesomeSample/mainwindow.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "QtAwesome.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
void styleChanged(int index);
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
QtAwesome* awesome;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
86
QtAwesomeSample/mainwindow.ui
Normal file
86
QtAwesomeSample/mainwindow.ui
Normal file
@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>750</width>
|
||||
<height>433</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QFrame" name="verticalFrame">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="listView">
|
||||
<property name="viewMode">
|
||||
<enum>QListView::IconMode</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="gridFrame">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="beerButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cheers!</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="toggleButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>30</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Toggle Me!</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
Reference in New Issue
Block a user