Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kcontrol / kfontinst / kcmfontinst / GroupList.h
blobb46ab9fb07070a1339b15176682bdd5f9623eb36
1 #ifndef __GROUP_LIST_H__
2 #define __GROUP_LIST_H__
4 /*
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
9 * ----
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; see the file COPYING. If not, write to
23 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
27 #include <KDE/KUrl>
28 #include <KDE/KFileItem>
29 #include <KDE/KIO/Job>
30 #include <KDE/KDirLister>
31 #include <QtCore/QList>
32 #include <QtGui/QTreeView>
33 #include <QtCore/QAbstractItemModel>
34 #include <QtCore/QModelIndex>
35 #include <QtCore/QVariant>
36 #include "FontList.h"
38 class QDragEnterEvent;
39 class QDragLeaveEvent;
40 class QDropEvent;
41 class QTextStream;
42 class QDomElement;
44 namespace KFI
47 class CGroupList;
48 class CFontItem;
50 class CGroupListItem
52 public:
54 enum EType
56 STANDARD_TITLE,
57 ALL,
58 PERSONAL,
59 SYSTEM,
60 UNCLASSIFIED,
61 GROUPS_TITLE,
62 CUSTOM
65 union Data
67 bool validated; //CUSTOM
68 CGroupList *parent; //UNCLASSIFIED
71 CGroupListItem(const QString &name);
72 CGroupListItem(EType type, CGroupList *p);
74 const QString & name() const { return itsName; }
75 void setName(const QString &n) { itsName=n; }
76 QSet<QString> & families() { return itsFamilies; }
77 const EType type() const { return itsType; }
78 bool isCustom() const { return CUSTOM==itsType; }
79 bool isAll() const { return ALL==itsType; }
80 bool isUnclassified() const { return UNCLASSIFIED==itsType; }
81 bool isPersonal() const { return PERSONAL==itsType; }
82 bool isSystem() const { return SYSTEM==itsType; }
83 bool validated() const { return isCustom() ? itsData.validated : true; }
84 void setValidated() { if(isCustom()) itsData.validated=true; }
85 bool highlighted() const { return itsHighlighted; }
86 void setHighlighted(bool b) { itsHighlighted=b; }
87 bool hasFont(const CFontItem *fnt) const;
88 CFamilyItem::EStatus status() const { return itsStatus; }
89 void updateStatus(QSet<QString> &enabled, QSet<QString> &disabled,
90 QSet<QString> &partial);
91 bool load(QDomElement &elem);
92 bool addFamilies(QDomElement &elem);
93 void save(QTextStream &str);
94 void addFamily(const QString &family) { itsFamilies.insert(family); }
95 void removeFamily(const QString &family) { itsFamilies.remove(family); }
96 bool hasFamily(const QString &family) { return itsFamilies.contains(family); }
98 private:
100 QSet<QString> itsFamilies;
101 QString itsName;
102 EType itsType;
103 Data itsData;
104 bool itsHighlighted;
105 CFamilyItem::EStatus itsStatus;
108 class CGroupList : public QAbstractItemModel
110 Q_OBJECT
112 public:
114 CGroupList(QWidget *parent = 0);
115 ~CGroupList();
117 QVariant data(const QModelIndex &index, int role) const;
118 Qt::ItemFlags flags(const QModelIndex &index) const;
119 QVariant headerData(int section, Qt::Orientation orientation,
120 int role = Qt::DisplayRole) const;
121 QModelIndex index(int row, int column,
122 const QModelIndex &parent = QModelIndex()) const;
123 QModelIndex parent(const QModelIndex &index) const;
124 int rowCount(const QModelIndex &parent = QModelIndex()) const;
125 int columnCount(const QModelIndex &parent = QModelIndex()) const;
126 void update(const QModelIndex &unHighlight, const QModelIndex &highlight);
127 void updateStatus(QSet<QString> &enabled, QSet<QString> &disabled,
128 QSet<QString> &partial);
129 void setSysMode(bool sys);
130 void rescan();
131 void load();
132 bool load(const QString &file);
133 bool save();
134 bool save(const QString &fileName, CGroupListItem *grp);
135 void merge(const QString &file);
136 void clear();
137 QModelIndex index(CGroupListItem::EType t);
138 void createGroup(const QString &name);
139 void renameGroup(const QModelIndex &idx, const QString &name);
140 bool removeGroup(const QModelIndex &idx);
141 void removeFamily(const QString &family);
142 bool removeFromGroup(CGroupListItem *grp, const QString &family);
143 QString whatsThis() const;
145 CGroupListItem * group(CGroupListItem::EType t)
146 { return itsSpecialGroups[t]; }
148 public Q_SLOTS:
150 void addToGroup(const QModelIndex &group, const QSet<QString> &families);
151 void removeFromGroup(const QModelIndex &group, const QSet<QString> &families);
153 Q_SIGNALS:
155 void refresh();
157 private:
159 void readGroupsFile();
160 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
161 Qt::DropActions supportedDropActions() const;
162 QStringList mimeTypes() const;
163 CGroupListItem * find(const QString &name);
164 bool exists(const QString &name);
165 QModelIndex createIdx(int r, int c, void *p) { return createIndex(r, c, p); }
167 private:
169 QString itsFileName;
170 time_t itsTimeStamp;
171 bool itsModified;
172 QWidget *itsParent;
173 QList<CGroupListItem *> itsGroups;
174 QMap<CGroupListItem::EType, CGroupListItem *> itsSpecialGroups;
175 Qt::SortOrder itsSortOrder;
177 friend class CGroupListItem;
178 friend class CGroupListView;
181 class CGroupListView : public QTreeView
183 Q_OBJECT
185 public:
187 CGroupListView(QWidget *parent, CGroupList *model);
188 virtual ~CGroupListView() { }
190 QSize sizeHint() const { return QSize(32, 32); }
192 bool isCustom() { return CGroupListItem::CUSTOM==getType(); }
193 bool isUnclassified() { return CGroupListItem::UNCLASSIFIED==getType(); }
194 bool isSystem() { return CGroupListItem::SYSTEM==getType(); }
195 bool isPersonal() { return CGroupListItem::PERSONAL==getType(); }
196 CGroupListItem::EType getType();
197 void controlMenu(bool del, bool en, bool dis, bool p);
199 Q_SIGNALS:
201 void del();
202 void print();
203 void enable();
204 void disable();
205 void copyFonts();
206 void moveFonts();
207 void info(const QString &str);
208 void addFamilies(const QModelIndex &group, const QSet<QString> &);
209 void removeFamilies(const QModelIndex &group, const QSet<QString> &);
210 void itemSelected(const QModelIndex &);
211 void unclassifiedChanged();
213 private Q_SLOTS:
215 void selectionChanged(const QItemSelection &selected,
216 const QItemSelection &deselected);
217 void rename();
219 private:
221 void contextMenuEvent(QContextMenuEvent *ev);
222 void dragEnterEvent(QDragEnterEvent *event);
223 void dragMoveEvent(QDragMoveEvent *event);
224 void dragLeaveEvent(QDragLeaveEvent *event);
225 void dropEvent(QDropEvent *event);
226 void drawHighlighter(const QModelIndex &idx);
228 private:
230 QMenu *itsMenu,
231 *itsActionMenu;
232 QAction *itsDeleteAct,
233 *itsEnableAct,
234 *itsDisableAct,
235 *itsPrintAct,
236 *itsRenameAct;
237 QModelIndex itsCurrentDropItem;
241 #endif