2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "GroupList.h"
26 #include <KDE/KGlobal>
27 #include <KDE/KStandardDirs>
28 #include <KDE/KLocale>
29 #include <KDE/KMimeType>
30 #include <KDE/KIconLoader>
32 #include <KDE/KMessageBox>
33 #include <KDE/KInputDialog>
34 #include <KDE/KSaveFile>
35 #include <QtGui/QFont>
36 #include <QtGui/QFontDatabase>
37 #include <QtGui/QDropEvent>
38 #include <QtGui/QHeaderView>
39 #include <QtGui/QMenu>
40 #include <QtGui/QApplication>
41 #include <QtXml/QDomElement>
42 #include <QtCore/QTextStream>
43 #include <QtCore/QDir>
44 #include <QtGui/QPainter>
50 #include "KfiConstants.h"
51 #include <config-workspace.h>
56 #define GROUPS_DOC "groups"
57 #define GROUP_TAG "group"
58 #define NAME_ATTR "name"
59 #define FAMILY_TAG "family"
66 CGroupListItem::CGroupListItem(const QString
&name
)
69 itsHighlighted(false),
70 itsStatus(CFamilyItem::ENABLED
)
72 itsData
.validated
=false;
75 CGroupListItem::CGroupListItem(EType type
, CGroupList
*p
)
77 itsHighlighted(false),
78 itsStatus(CFamilyItem::ENABLED
)
83 itsName
=i18n("All Fonts");
86 itsName
=i18n("Personal Fonts");
89 itsName
=i18n("System Fonts");
92 itsName
=i18nc("Title for a group that contains \"All Fonts\", \"Personal Fonts\", \"System Fonts\" and \"Unclassified\"", "Standard:");
95 itsName
=i18n("Custom:");
98 itsName
=i18n("Unclassified");
103 bool CGroupListItem::hasFont(const CFontItem
*fnt
) const
108 return itsFamilies
.contains(fnt
->family());
110 return !fnt
->isSystem();
112 return fnt
->isSystem();
117 QList
<CGroupListItem
*>::ConstIterator
it(itsData
.parent
->itsGroups
.begin()),
118 end(itsData
.parent
->itsGroups
.end());
121 if((*it
)->isCustom() && (*it
)->families().contains(fnt
->family()))
131 void CGroupListItem::updateStatus(QSet
<QString
> &enabled
, QSet
<QString
> &disabled
, QSet
<QString
> &partial
)
133 QSet
<QString
> families(itsFamilies
);
135 if(0!=families
.intersect(partial
).count())
136 itsStatus
=CFamilyItem::PARTIAL
;
139 families
=itsFamilies
;
141 bool haveEnabled(0!=families
.intersect(enabled
).count());
143 families
=itsFamilies
;
145 bool haveDisabled(0!=families
.intersect(disabled
).count());
147 if(haveEnabled
&& haveDisabled
)
148 itsStatus
=CFamilyItem::PARTIAL
;
149 else if(haveEnabled
&& !haveDisabled
)
150 itsStatus
=CFamilyItem::ENABLED
;
152 itsStatus
=CFamilyItem::DISABLED
;
156 bool CGroupListItem::load(QDomElement
&elem
)
158 if(elem
.hasAttribute(NAME_ATTR
))
160 itsName
=elem
.attribute(NAME_ATTR
);
167 bool CGroupListItem::addFamilies(QDomElement
&elem
)
169 int b4(itsFamilies
.count());
171 for(QDomNode n
=elem
.firstChild(); !n
.isNull(); n
=n
.nextSibling())
173 QDomElement ent
=n
.toElement();
175 if(FAMILY_TAG
==ent
.tagName())
176 itsFamilies
.insert(ent
.text());
178 return b4
!=itsFamilies
.count();
181 void CGroupListItem::save(QTextStream
&str
)
183 str
<< " <"GROUP_TAG
" "NAME_ATTR
"=\"" << Misc::encodeText(itsName, str) << "\">" << endl;
184 if(itsFamilies.count())
186 QSet<QString>::ConstIterator it(itsFamilies.begin()),
187 end(itsFamilies.end());
190 str << " <"FAMILY_TAG">" << Misc::encodeText(*it, str) << "</"FAMILY_TAG">" << endl;
192 str << " </"GROUP_TAG">" << endl;
195 CGroupList::CGroupList(QWidget *parent)
196 : QAbstractItemModel(parent),
200 itsSortOrder(Qt::AscendingOrder)
202 itsSpecialGroups[CGroupListItem::STANDARD_TITLE]=new CGroupListItem(CGroupListItem::STANDARD_TITLE, this);
203 itsGroups.append(itsSpecialGroups[CGroupListItem::STANDARD_TITLE]);
204 itsSpecialGroups[CGroupListItem::ALL]=new CGroupListItem(CGroupListItem::ALL, this);
205 itsGroups.append(itsSpecialGroups[CGroupListItem::ALL]);
207 itsSpecialGroups[CGroupListItem::PERSONAL]=
208 itsSpecialGroups[CGroupListItem::SYSTEM]=NULL;
211 itsSpecialGroups[CGroupListItem::PERSONAL]=new CGroupListItem(CGroupListItem::PERSONAL, this);
212 itsGroups.append(itsSpecialGroups[CGroupListItem::PERSONAL]);
213 itsSpecialGroups[CGroupListItem::SYSTEM]=new CGroupListItem(CGroupListItem::SYSTEM, this);
214 itsGroups.append(itsSpecialGroups[CGroupListItem::SYSTEM]);
216 itsSpecialGroups[CGroupListItem::UNCLASSIFIED]=
217 new CGroupListItem(CGroupListItem::UNCLASSIFIED, this);
218 itsGroups.append(itsSpecialGroups[CGroupListItem::UNCLASSIFIED]);
219 itsSpecialGroups[CGroupListItem::GROUPS_TITLE]=new CGroupListItem(CGroupListItem::GROUPS_TITLE, this);
220 itsGroups.append(itsSpecialGroups[CGroupListItem::GROUPS_TITLE]);
221 // Locate groups.xml file - normall will be ~/.config/fontgroups.xml
222 QString path(KGlobal::dirs()->localxdgconfdir());
224 if(!Misc::dExists(path))
225 Misc::createDir(path);
227 itsFileName=path+'/'+KFI_GROUPS_FILE;
232 CGroupList::~CGroupList()
235 qDeleteAll(itsGroups);
239 int CGroupList::columnCount(const QModelIndex &) const
244 void CGroupList::update(const QModelIndex &unHighlight, const QModelIndex &highlight)
246 if(unHighlight.isValid())
248 CGroupListItem *grp=static_cast<CGroupListItem *>(unHighlight.internalPointer());
250 grp->setHighlighted(false);
251 emit dataChanged(unHighlight, unHighlight);
253 if(highlight.isValid())
255 CGroupListItem *grp=static_cast<CGroupListItem *>(highlight.internalPointer());
257 grp->setHighlighted(true);
258 emit dataChanged(highlight, highlight);
262 void CGroupList::updateStatus(QSet<QString> &enabled, QSet<QString> &disabled,
263 QSet<QString> &partial)
265 QList<CGroupListItem *>::Iterator it(itsGroups.begin()),
266 end(itsGroups.end());
269 if((*it)->isCustom())
270 (*it)->updateStatus(enabled, disabled, partial);
272 emit layoutChanged();
275 inline QColor midColour(const QColor &a, const QColor &b)
277 return QColor((a.red()+b.red())>>1, (a.green()+b.green())>>1, (a.blue()+b.blue())>>1);
280 QVariant CGroupList::data(const QModelIndex &index, int role) const
282 if (!index.isValid())
285 CGroupListItem *grp=static_cast<CGroupListItem *>(index.internalPointer());
288 switch(index.column())
293 case Qt::BackgroundRole:
296 case CGroupListItem::STANDARD_TITLE:
297 case CGroupListItem::GROUPS_TITLE:
299 QPalette pal(QApplication::palette());
301 return midColour(pal.color(QPalette::Active, QPalette::Base),
302 pal.color(QPalette::Active, QPalette::Highlight));
311 case CGroupListItem::STANDARD_TITLE:
312 case CGroupListItem::GROUPS_TITLE:
315 font.setPointSizeF(font.pointSizeF()*0.75);
323 case Qt::DisplayRole:
325 if(CFamilyItem::DISABLED==grp->status())
326 if(grp->families().count())
327 return i18n("%1 (Disabled
)", grp->name());
329 return i18n("%1 (Empty
)", grp->name());
330 else if(CFamilyItem::PARTIAL==grp->status())
331 return i18n("%1 (Partial
)", grp->name());
333 case Qt::DecorationRole:
334 if(grp->highlighted())
337 case CGroupListItem::ALL: // Removing from a group
338 return SmallIcon("list
-remove
");
339 case CGroupListItem::PERSONAL: // Copying/moving
340 case CGroupListItem::SYSTEM: // Copying/moving
341 return SmallIcon(Qt::LeftToRight==QApplication::layoutDirection()
342 ? "go
-next
" : "go
-previous
");
343 case CGroupListItem::CUSTOM: // Adding to a group
344 return SmallIcon("list
-add
");
356 Qt::ItemFlags CGroupList::flags(const QModelIndex &index) const
358 if (!index.isValid())
359 return Qt::ItemIsEnabled;
361 CGroupListItem *grp=static_cast<CGroupListItem *>(index.internalPointer());
366 case CGroupListItem::STANDARD_TITLE:
367 case CGroupListItem::GROUPS_TITLE:
368 return Qt::ItemIsEnabled;
372 return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled;
375 QVariant CGroupList::headerData(int section, Qt::Orientation orientation, int role) const
377 if (Qt::Horizontal==orientation && COL_GROUP_NAME==section)
380 case Qt::DisplayRole:
381 return i18n("Group
");
382 case Qt::TextAlignmentRole:
383 return Qt::AlignLeft;
384 case Qt::WhatsThisRole:
393 QModelIndex CGroupList::index(int row, int column, const QModelIndex &parent) const
395 if(!parent.isValid())
397 CGroupListItem *grp=itsGroups.value(row);
400 return createIndex(row, column, grp);
403 return QModelIndex();
406 QModelIndex CGroupList::parent(const QModelIndex &) const
408 return QModelIndex();
411 int CGroupList::rowCount(const QModelIndex &) const
413 return itsGroups.count();
416 void CGroupList::rescan()
420 sort(0, itsSortOrder);
423 void CGroupList::load()
425 time_t ts=Misc::getTimeStamp(itsFileName);
427 if(!ts || ts!=itsTimeStamp)
431 if(load(itsFileName))
436 bool CGroupList::load(const QString &file)
441 if(f.open(QIODevice::ReadOnly))
445 if(doc.setContent(&f))
446 for(QDomNode n=doc.documentElement().firstChild(); !n.isNull(); n=n.nextSibling())
448 QDomElement e=n.toElement();
450 if(GROUP_TAG==e.tagName() && e.hasAttribute(NAME_ATTR))
452 QString name(e.attribute(NAME_ATTR));
454 CGroupListItem *item=find(name);
458 item=new CGroupListItem(name);
459 itsGroups.append(item);
463 if(item->addFamilies(e))
471 bool CGroupList::save()
473 if(itsModified && save(itsFileName, NULL))
475 itsTimeStamp=Misc::getTimeStamp(itsFileName);
481 bool CGroupList::save(const QString &fileName, CGroupListItem *grp)
483 KSaveFile file(fileName);
487 QTextStream str(&file);
489 str << "<"GROUPS_DOC">" << endl;
495 QList<CGroupListItem *>::Iterator it(itsGroups.begin()),
496 end(itsGroups.end());
499 if((*it)->isCustom())
502 str << "</"GROUPS_DOC">" << endl;
504 return file.finalize();
510 void CGroupList::merge(const QString &file)
515 sort(0, itsSortOrder);
519 void CGroupList::clear()
521 beginRemoveRows(QModelIndex(), 0, itsGroups.count());
523 itsGroups.removeFirst(); // Remove STANDARD_TITLE
524 itsGroups.removeFirst(); // Remove all
525 if(itsSpecialGroups[CGroupListItem::SYSTEM])
527 itsGroups.removeFirst(); // Remove personal
528 itsGroups.removeFirst(); // Remove system
530 itsGroups.removeFirst(); // Remove unclassif...
531 itsGroups.removeFirst(); // Remove GROUPS_TITLE
532 qDeleteAll(itsGroups);
534 itsGroups.append(itsSpecialGroups[CGroupListItem::STANDARD_TITLE]);
535 itsGroups.append(itsSpecialGroups[CGroupListItem::ALL]);
536 if(itsSpecialGroups[CGroupListItem::SYSTEM])
538 itsGroups.append(itsSpecialGroups[CGroupListItem::PERSONAL]);
539 itsGroups.append(itsSpecialGroups[CGroupListItem::SYSTEM]);
541 itsGroups.append(itsSpecialGroups[CGroupListItem::UNCLASSIFIED]);
542 itsGroups.append(itsSpecialGroups[CGroupListItem::GROUPS_TITLE]);
545 QModelIndex CGroupList::index(CGroupListItem::EType t)
547 return createIndex(t, 0, itsSpecialGroups[t]);
550 void CGroupList::createGroup(const QString &name)
554 itsGroups.append(new CGroupListItem(name));
557 sort(0, itsSortOrder);
561 void CGroupList::renameGroup(const QModelIndex &idx, const QString &name)
565 CGroupListItem *grp=static_cast<CGroupListItem *>(idx.internalPointer());
567 if(grp && grp->isCustom() && grp->name()!=name && !exists(name))
572 sort(0, itsSortOrder);
577 bool CGroupList::removeGroup(const QModelIndex &idx)
581 CGroupListItem *grp=static_cast<CGroupListItem *>(idx.internalPointer());
583 if(grp && grp->isCustom() &&
584 KMessageBox::Yes==KMessageBox::warningYesNo(itsParent,
585 i18n("<p
>Do you really want to remove
\'<b
>%1</b
>\'?</p
>"
586 "<p
><i
>This will only remove the group
, and not "
587 "the actual fonts
.</i
></p
>", grp->name()),
588 i18n("Remove Group
"), KGuiItem(i18n("Remove
"), "list
-remove
",
589 i18n("Remove group
"))))
592 itsGroups.removeAll(grp);
595 sort(0, itsSortOrder);
603 void CGroupList::removeFromGroup(const QModelIndex &group, const QSet<QString> &families)
607 CGroupListItem *grp=static_cast<CGroupListItem *>(group.internalPointer());
609 if(grp && grp->isCustom())
611 QSet<QString>::ConstIterator it(families.begin()),
616 if(removeFromGroup(grp, *it))
625 QString CGroupList::whatsThis() const
627 return i18n("<h3
>Font Groups
</h3
><p
>This list displays the font groups available on your system
. "
628 "There are
2 main types of font groups
:"
629 "<ul
><li
><b
>Standard
</b
> are special groups used by the font manager
.<ul
>%1</ul
></li
>"
630 "<li
><b
>Custom
</b
> are groups created by you
. To add a font family to one of
"
631 "these groups simply drag it from the list of fonts
, and drop
"
632 "onto the desired group
. To remove a family from the group
, drag
"
633 "the font onto the
\"All Fonts
\" group
.</li
>"
636 ? i18n("<li
><i
>All Fonts
</i
> contains all the fonts installed on your system
.</li
>"
637 "<li
><i
>Unclassified
</i
> contains all fonts that have
not yet been placed
"
638 "within a
\"Custom
\" group
.</li
>")
639 : i18n("<li
><i
>All Fonts
</i
> contains all the fonts installed on your system
- "
640 "both
\"System
\" and \"Personal
\".</li
>"
641 "<li
><i
>System
</i
> contains all fonts that are installed system
-wide (i
.e
. "
642 "available to all users
).</li
>"
643 "<li
><i
>Personal
</i
> contains your personal fonts
.</li
>"
644 "<li
><i
>Unclassified
</i
> contains all fonts that have
not yet been placed
"
645 "within a
\"Custom
\" group
.</li
>"));
648 void CGroupList::addToGroup(const QModelIndex &group, const QSet<QString> &families)
652 CGroupListItem *grp=static_cast<CGroupListItem *>(group.internalPointer());
654 if(grp && grp->isCustom())
656 QSet<QString>::ConstIterator it(families.begin()),
661 if(!grp->hasFamily(*it))
674 void CGroupList::removeFamily(const QString &family)
676 QList<CGroupListItem *>::ConstIterator it(itsGroups.begin()),
677 end(itsGroups.end());
680 removeFromGroup(*it, family);
683 bool CGroupList::removeFromGroup(CGroupListItem *grp, const QString &family)
685 if(grp && grp->isCustom() && grp->hasFamily(family))
687 grp->removeFamily(family);
695 static bool groupNameLessThan(const CGroupListItem *f1, const CGroupListItem *f2)
697 return f1 && f2 && (f1->type()<f2->type() ||
698 (f1->type()==f2->type() && QString::localeAwareCompare(f1->name(), f2->name())<0));
701 static bool groupNameGreaterThan(const CGroupListItem *f1, const CGroupListItem *f2)
703 return f1 && f2 && (f1->type()<f2->type() ||
704 (f1->type()==f2->type() && QString::localeAwareCompare(f1->name(), f2->name())>0));
707 void CGroupList::sort(int, Qt::SortOrder order)
711 qSort(itsGroups.begin(), itsGroups.end(),
712 Qt::AscendingOrder==order ? groupNameLessThan : groupNameGreaterThan);
714 emit layoutChanged();
717 Qt::DropActions CGroupList::supportedDropActions() const
719 return Qt::CopyAction | Qt::MoveAction;
722 QStringList CGroupList::mimeTypes() const
725 types << KFI_FONT_DRAG_MIME;
729 CGroupListItem * CGroupList::find(const QString &name)
731 QList<CGroupListItem *>::ConstIterator it(itsGroups.begin()),
732 end(itsGroups.end());
735 if((*it)->name()==name)
741 bool CGroupList::exists(const QString &name)
745 KMessageBox::error(itsParent, i18n("<qt
>A group named
<b
>\'%1\'</b
> already
"
746 "exists
.</qt
>", name));
753 CGroupListView::CGroupListView(QWidget *parent, CGroupList *model)
757 sortByColumn(COL_GROUP_NAME, Qt::AscendingOrder);
758 setSelectionMode(QAbstractItemView::SingleSelection);
759 resizeColumnToContents(COL_GROUP_NAME);
760 setSortingEnabled(true);
761 setAllColumnsShowFocus(true);
762 setAlternatingRowColors(true);
763 setAcceptDrops(true);
764 setDragDropMode(QAbstractItemView::DropOnly);
765 setDropIndicatorShown(true);
766 setDragEnabled(false);
767 header()->setSortIndicatorShown(true);
768 setRootIsDecorated(false);
769 itsMenu=new QMenu(this);
771 itsDeleteAct=itsMenu->addAction(KIcon("list
-remove
"), i18n("Remove
"),
772 this, SIGNAL(del()));
773 itsEnableAct=itsMenu->addAction(KIcon("enablefont
"), i18n("Enable
"),
774 this, SIGNAL(enable()));
775 itsDisableAct=itsMenu->addAction(KIcon("disablefont
"), i18n("Disable
"),
776 this, SIGNAL(disable()));
777 itsMenu->addSeparator();
778 itsRenameAct=itsMenu->addAction(i18n("Rename
..."), this, SLOT(rename()));
779 itsMenu->addSeparator();
780 itsPrintAct=itsMenu->addAction(KIcon("document
-print
"), i18n("Print
..."),
781 this, SIGNAL(print()));
783 itsActionMenu=new QMenu(this);
784 itsActionMenu->addAction(KIcon("goto-page
"), i18n("Move Here
"), this, SIGNAL(moveFonts()));
785 itsActionMenu->addAction(KIcon("edit
-copy
"), i18n("Copy Here
"), this, SIGNAL(copyFonts()));
786 itsActionMenu->addSeparator();
787 itsActionMenu->addAction(KIcon("process
-stop
"), i18n("Cancel
"));
789 setWhatsThis(model->whatsThis());
790 header()->setWhatsThis(whatsThis());
791 connect(this, SIGNAL(addFamilies(const QModelIndex &, const QSet<QString> &)),
792 model, SLOT(addToGroup(const QModelIndex &, const QSet<QString> &)));
793 connect(this, SIGNAL(removeFamilies(const QModelIndex &, const QSet<QString> &)),
794 model, SLOT(removeFromGroup(const QModelIndex &, const QSet<QString> &)));
797 CGroupListItem::EType CGroupListView::getType()
799 QModelIndexList selectedItems(selectedIndexes());
801 if(selectedItems.count() && selectedItems.last().isValid())
803 CGroupListItem *grp=static_cast<CGroupListItem *>(selectedItems.last().internalPointer());
808 return CGroupListItem::ALL;
811 void CGroupListView::controlMenu(bool del, bool en, bool dis, bool p)
813 itsDeleteAct->setEnabled(del);
814 itsRenameAct->setEnabled(del);
815 itsEnableAct->setEnabled(en);
816 itsDisableAct->setEnabled(dis);
817 itsPrintAct->setEnabled(p);
820 void CGroupListView::selectionChanged(const QItemSelection &selected,
821 const QItemSelection &deselected)
823 QModelIndexList deselectedItems(deselected.indexes());
825 QAbstractItemView::selectionChanged(selected, deselected);
827 QModelIndexList selectedItems(selectedIndexes());
829 if(0==selectedItems.count() && 1==deselectedItems.count())
830 selectionModel()->select(deselectedItems.last(), QItemSelectionModel::Select);
832 emit itemSelected(selectedItems.count()
833 ? selectedItems.last()
837 void CGroupListView::rename()
839 QModelIndex index(currentIndex());
843 CGroupListItem *grp=static_cast<CGroupListItem *>(index.internalPointer());
845 if(grp && grp->isCustom())
848 QString name(KInputDialog::getText(i18n("Rename Group
"),
849 i18n("Please enter a
new name
for group
:"),
850 grp->name(), &ok, this));
852 if(ok && !name.isEmpty() && name!=grp->name())
853 ((CGroupList *)model())->renameGroup(index, name);
858 void CGroupListView::contextMenuEvent(QContextMenuEvent *ev)
860 if(indexAt(ev->pos()).isValid())
861 itsMenu->popup(ev->globalPos());
864 void CGroupListView::dragEnterEvent(QDragEnterEvent *event)
866 if(event->provides(KFI_FONT_DRAG_MIME))
867 event->acceptProposedAction();
870 void CGroupListView::dragMoveEvent(QDragMoveEvent *event)
872 if(event->provides(KFI_FONT_DRAG_MIME))
874 QModelIndex index(indexAt(event->pos()));
878 if(COL_GROUP_NAME!=index.column())
879 index=((CGroupList *)model())->createIdx(index.row(), COL_GROUP_NAME, index.internalPointer());
881 CGroupListItem *dest=static_cast<CGroupListItem *>(index.internalPointer());
882 CGroupListItem::EType type=getType();
885 if(!selectedIndexes().contains(index))
890 emit info(i18n("Drop here to add the selected fonts to
\"%1\".", dest->name()));
891 else if(CGroupListItem::CUSTOM==type && dest->isAll())
892 emit info(i18n("Drop here to remove the selected fonts from the current group
."));
893 else if(!Misc::root() && dest->isPersonal() && CGroupListItem::SYSTEM==type)
894 emit info(i18n("Drop here to copy
, or move
, the selected fonts to your personal folder
."));
895 else if(!Misc::root() && dest->isSystem() && CGroupListItem::PERSONAL==type)
896 emit info(i18n("Drop here to copy
, or move
, the selected fonts to the system folder
."));
902 drawHighlighter(index);
903 event->acceptProposedAction();
909 drawHighlighter(QModelIndex());
910 emit info(QString());
914 void CGroupListView::dragLeaveEvent(QDragLeaveEvent *)
916 drawHighlighter(QModelIndex());
917 emit info(QString());
920 void CGroupListView::dropEvent(QDropEvent *event)
922 emit info(QString());
923 drawHighlighter(QModelIndex());
924 if(event->provides(KFI_FONT_DRAG_MIME))
926 event->acceptProposedAction();
928 QSet<QString> families;
929 QByteArray encodedData(event->mimeData()->data(KFI_FONT_DRAG_MIME));
930 QDataStream ds(&encodedData, QIODevice::ReadOnly);
931 QModelIndex from(selectedIndexes().last()),
932 to(indexAt(event->pos()));
935 // Are we mvoeing/copying, removing a font from the current group?
936 if(to.isValid() && from.isValid())
937 if( ((static_cast<CGroupListItem *>(from.internalPointer()))->isSystem() &&
938 (static_cast<CGroupListItem *>(to.internalPointer()))->isPersonal()) ||
939 ((static_cast<CGroupListItem *>(from.internalPointer()))->isPersonal() &&
940 (static_cast<CGroupListItem *>(to.internalPointer()))->isSystem()))
941 itsActionMenu->popup(QCursor::pos());
942 else if((static_cast<CGroupListItem *>(from.internalPointer()))->isCustom() &&
943 !(static_cast<CGroupListItem *>(to.internalPointer()))->isCustom())
944 emit removeFamilies(from, families);
946 emit addFamilies(to, families);
949 emit unclassifiedChanged();
953 void CGroupListView::drawHighlighter(const QModelIndex &idx)
955 if(itsCurrentDropItem!=idx)
957 ((CGroupList *)model())->update(itsCurrentDropItem, idx);
958 itsCurrentDropItem=idx;
962 bool CGroupListView::viewportEvent(QEvent *event)
964 executeDelayedItemsLayout();
965 return QTreeView::viewportEvent(event);
970 #include "GroupList
.moc
"