QFontDialog重写

KFontDialog是一个自定义的对话框类,继承自QDialog,用于选择字体。类中包含初始化字体、设置对话框的方法,以及处理鼠标事件的保护函数。此外,还实现了信号和槽函数来更新字体样本和大小。
摘要由CSDN通过智能技术生成

#ifndef KFONTDIALOG_H
#define KFONTDIALOG_H

#include <QDialog>
#include <qfontdatabase.h>
#include <QModelIndex>
#include <QStringListModel>
class QSettings;
namespace Ui {
class KFontDialog;
}

class KFontDialog : public QDialog
{
    Q_OBJECT
    
public:
    explicit KFontDialog(QSettings *mSettings = 0, QString flag = "", QWidget *parent = 0);
    ~KFontDialog();
    void getInitFont();
    void initDialog();
    
private:
    Ui::KFontDialog *ui;
    QSettings *pSettings;
    QFontDatabase fdb;
//    QString initfont;
//    QString initstyle;
//    QString initsize;
//    QStringList families;//所有字体名字
//    QStringList styles;//所有字体风格列表
//    QStringList sizes;//所有字体大小
    QString fontFlag;//字体标记
    void updateSampleFont();
//    void updateSampleFont(const QFont &newFont);

    QStringListModel *familymodel;
    QStringListModel *stylemodel;
    QStringListModel *sizemodel;
    QPoint dragPos;

protected:
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    bool eventFilter(QObject *obj, QEvent *event);

protected slots:
    void updateAll(QModelIndex index);
    void updateStyleandSize(QModelIndex index);
    void updateSize(QModelIndex index);

signals:
    void updateSizeList();
private slots:
    void on_quitBtn_clicked();
    void on_okBtn_clicked();
};

#endif // KFONTDIALOG_H




#include "kfontdialog.h"

#include "ui_kfontdialog.h"
#include <QMouseEvent>
#include <QListView>
#include <QStringListModel>
#include <QDebug>
#include <QSettings>
#include <QMessageBox>

extern QString selectedFont;
/*
 *http://www.vision.ee.ethz.ch/computing/sepp-irix/qt-3.0-mo/qfontdatabase.html
 *https://qt.gitorious.org/qt/qt/source/c48eb6d5d0a299449330dea8a6a59514942c8781:src/gui/dialogs/qfontdialog_p.h#L73
 *http://blog.163.com/shaohj_1999@126/blog/static/63406851201252043139502/
 *http://www.cnblogs.com/venow/archive/2012/10/17/2728299.html
 *
 *
 *
 *families:
 ("Abyssinica SIL", "AR PL UKai CN", "AR PL UKai HK", "AR PL UKai TW", "AR PL UKai TW MBE", "AR PL UMing CN",
"AR PL UMing HK", "AR PL UMing TW", "AR PL UMing TW MBE", "Bitstream Charter", "Century Schoolbook L",
"Courier 10 Pitch", "DejaVu Sans", "DejaVu Sans Mono", "DejaVu Serif", "Dingbats", "gargi", "Garuda", "Kedage",
"Khmer OS", "Khmer OS System", "Liberation Mono", "Liberation Sans", "Liberation Sans Narrow", "Liberation Serif",
"LKLUG", "Lohit Bengali", "Lohit Gujarati", "Lohit Hindi", "Lohit Punjabi", "Lohit Tamil", "Mallige", "Meera",
"Monospace", "Mukti Narrow", "Nimbus Mono L", "Nimbus Roman No9 L", "Nimbus Sans L", "OpenSymbol", "ori1Uni",
"Padauk", "Padauk Book", "Pothana2000", "Rachana", "Rekha", "Saab", "Sans Serif", "Serif", "Standard Symbols L",
"Symbol", "Tibetan Machine Uni", "Ubuntu", "Ubuntu Condensed", "Ubuntu Mono", "URW Bookman L", "URW Chancery L",
"URW Gothic L", "URW Palladio L", "Vemana2000", "文泉驿微米黑", "文泉驿正黑", "文泉驿点阵正黑", "文泉驿等宽微米黑",
"文泉驿等宽正黑")

 *styles:
"Regular","Roman", "Light", "Bold","Medium", "Book", "BoldOblique","Oblique","Normal", "Regular Oblique",
"斜体", "半粗体 斜体", "轻体 斜体", "粗体 斜体", "意大利体", "普通", "粗体 意大利体", "粗体"
"Bold Italic",  "Italic", "Regular Italic", "Medium Italic","Light Italic",
"Bold Condensed", "Regular Condensed Italic", "Bold Condensed Italic", "Regular Condensed",
"Demi Bold", "Demi Bold Italic","Demi", "Demi Oblique", Book Oblique"
sizes:
("6", "7", "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48", "72")
*/

KFontDialog::KFontDialog(QSettings *mSettings, QString flag, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::KFontDialog)
{
    ui->setupUi(this);

    this->setAttribute(Qt::WA_DeleteOnClose);//防止内存泄漏
    this->setWindowFlags(Qt::FramelessWindowHint);
    this->setAttribute(Qt::WA_TranslucentBackground);
    ui->btn_close->installEventFilter(this);
    ui->okBtn->installEventFilter(this);
    ui->quitBtn->installEventFilter(this);
    ui->btn_close->setStyleSheet("border-image:url(:/pixmap/image/closeBtn.png)");
    ui->okBtn->setStyleSheet("QPushButton {border-image:url(:/pixmap/image/ok.png);}"
                "QPushButton:hover{border-image:url(:/pixmap/image/ok-hover.png);}");
    ui->quitBtn->setStyleSheet("QPushButton {border-image:url(:/pixmap/image/quit.png);}"
                "QPushButton:hover{border-image:url(:/pixmap/image/quit-hover.png);}");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值