QtAwesome/QtAwesomeSample/mainwindow.cpp

87 lines
2.8 KiB
C++
Raw Permalink Normal View History

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QtAwesome.h"
#include <QStandardItemModel>
#include <QMap>
2022-12-27 23:01:09 +08:00
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
2022-12-27 23:01:09 +08:00
awesome = new fa::QtAwesome(this);
awesome->initFontAwesome();
2022-12-27 23:01:09 +08:00
ui->comboBox->addItem("Solid", fa::fa_solid);
ui->comboBox->addItem("Brands", fa::fa_brands);
ui->comboBox->addItem("Regular", fa::fa_regular);
#ifdef FONT_AWESOME_PRO
2022-12-27 23:01:09 +08:00
ui->comboBox->addItem("Light", fa::fa_light);
ui->comboBox->addItem("Thin", fa::fa_thin);
ui->comboBox->addItem("Duotone", fa::fa_duotone);
ui->comboBox->addItem("Sharp Solid", fa::fa_sharp_solid);
ui->comboBox->addItem("Sharp Regular", fa::fa_sharp_regular);
2023-03-29 02:33:33 +08:00
ui->comboBox->addItem("Sharp Light", fa::fa_sharp_light);
2023-12-08 00:05:11 +08:00
ui->comboBox->addItem("Sharp Thin", fa::fa_sharp_thin);
#endif
// a simple beer button
//=====================
{
QPushButton* beerButton = ui->beerButton;
QVariantMap options;
2022-12-27 23:01:09 +08:00
options.insert("anim", QVariant::fromValue(new fa::QtAwesomeAnimation(beerButton)));
// below are the possible variation to show thi icon
beerButton->setIcon(awesome->icon(fa::fa_solid, fa::fa_beer_mug_empty, options));
// beerButton->setIcon(awesome->icon("fa-solid fa-beer-mug-empty", options));
// beerButton->setIcon(awesome->icon("beer-mug-empty", options));
// beerButton->setIcon(awesome->icon("solid beer-mug-empty", options));
}
2022-12-27 23:01:09 +08:00
// a simple checkbox button
//=========================
{
QPushButton* toggleButton = ui->toggleButton;
toggleButton->setCheckable(true);
QVariantMap options;
2022-12-27 23:01:09 +08:00
options.insert("color", QColor(Qt::yellow));
options.insert("text-off", QString(fa::fa_square));
options.insert("color-off", QColor(Qt::darkBlue));
toggleButton->setIcon( awesome->icon("fa_solid square-check", options));
}
2022-12-27 23:01:09 +08:00
QStandardItemModel* model = new QStandardItemModel(this);
ui->listView->setModel(model);
connect(ui->comboBox, SIGNAL(activated(int)), this, SLOT(styleChanged(int)));
2022-12-27 23:01:09 +08:00
styleChanged(fa::fa_solid);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::styleChanged(int index)
{
2022-12-27 23:01:09 +08:00
Q_UNUSED(index)
QVariant styleValue = ui->comboBox->currentData();
int style = styleValue.toInt();
2022-12-27 23:01:09 +08:00
QHash<QString, int> iconset = awesome->namedCodePoints(style);
QStandardItemModel *model = dynamic_cast<QStandardItemModel*>(ui->listView->model());
model->clear();
2022-12-27 23:01:09 +08:00
for (QHash<QString, int>::iterator i=iconset.begin(); i != iconset.end(); ++i) {
QString name = i.key();
int ic = i.value();
2022-12-27 23:01:09 +08:00
model->appendRow(new QStandardItem(awesome->icon(style, ic), name));
}
model->sort(0);
}