1 #ifndef __GROUP_LIST_H__
2 #define __GROUP_LIST_H__
5 * KFontInst - KDE Font Installer
7 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
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.
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>
38 class QDragEnterEvent
;
39 class QDragLeaveEvent
;
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
); }
100 QSet
<QString
> itsFamilies
;
105 CFamilyItem::EStatus itsStatus
;
108 class CGroupList
: public QAbstractItemModel
114 CGroupList(QWidget
*parent
= 0);
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
);
132 bool load(const QString
&file
);
134 bool save(const QString
&fileName
, CGroupListItem
*grp
);
135 void merge(const QString
&file
);
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
]; }
150 void addToGroup(const QModelIndex
&group
, const QSet
<QString
> &families
);
151 void removeFromGroup(const QModelIndex
&group
, const QSet
<QString
> &families
);
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
); }
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
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
);
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();
215 void selectionChanged(const QItemSelection
&selected
,
216 const QItemSelection
&deselected
);
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
);
227 virtual bool viewportEvent(QEvent
*event
);
233 QAction
*itsDeleteAct
,
238 QModelIndex itsCurrentDropItem
;