1 /*************************************************************************** 2 * * 3 * This program is free software; you can redistribute it and/or modify * 4 * it under the terms of the GNU General Public License as published by * 5 * the Free Software Foundation; either version 3 of the License, or * 6 * (at your option) any later version. * 7 * * 8 ***************************************************************************/ 9 10 #pragma once 11 12 #include <QAbstractItemModel> 13 14 #define COLUMN_CUSTOM_FONT_DESC 0 15 #define COLUMN_CUSTOM_FONT_DISP 1 16 17 class CustomFontItem{ 18 public: 19 CustomFontItem(const QList<QVariant> &data, CustomFontItem *parent = 0); 20 virtual ~CustomFontItem(); 21 22 void appendChild(CustomFontItem *child); 23 24 CustomFontItem *child(int row); 25 int childCount() const; 26 int columnCount() const; 27 QVariant data(int column) const; 28 int row() const; 29 CustomFontItem *parent(); 30 void updateColumn(int column, QVariant var); 31 32 QList<CustomFontItem*> childItems; 33 34 QString key; 35 QString custom_font; 36 private: 37 38 QList<QVariant> itemData; 39 CustomFontItem *parentItem; 40 }; 41 42 class CustomFontModel : public QAbstractItemModel 43 { 44 Q_OBJECT 45 public: 46 explicit CustomFontModel(QObject *parent = 0); 47 virtual ~CustomFontModel(); 48 49 /** */ 50 QVariant data(const QModelIndex &, int) const; 51 /** */ 52 QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const; 53 /** */ 54 QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const; 55 /** */ 56 QModelIndex parent(const QModelIndex &index) const; 57 /** */ 58 int rowCount(const QModelIndex &parent = QModelIndex()) const; 59 /** */ 60 int columnCount(const QModelIndex &parent = QModelIndex()) const; 61 62 signals: 63 void fontChanged(const QString &key, const QString &value); 64 65 public slots: 66 void itemDoubleClicked(const QModelIndex&); 67 void ok(); 68 69 private: 70 void addNewFont(const QString &wkey, const QString &desc); 71 72 CustomFontItem *rootItem; 73 }; 74