1 /* This file is part of the KDE project
3 Copyright (C) 2004 - 2007 KGet Developers <kget@kde.org>
4 Copyright (C) 2007 by Javier Goday <jgoday@gmail.com>
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
12 #include "selectdirectoryitemdelegate.h"
15 #include <KUrlRequester>
17 SelectDirectoryItemDelegate::SelectDirectoryItemDelegate(QObject
*parent
)
18 : QItemDelegate(parent
)
22 QWidget
*SelectDirectoryItemDelegate::createEditor(QWidget
*parent
,
23 const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
28 KUrlRequester
*widget
= new KUrlRequester(parent
);
29 widget
->setMode(KFile::Directory
| KFile::ExistingOnly
| KFile::LocalOnly
);
30 widget
->setPath(index
.model()->data(index
, Qt::DisplayRole
).toString());
35 void SelectDirectoryItemDelegate::updateEditorGeometry(QWidget
*editor
,
36 const QStyleOptionViewItem
&option
, const QModelIndex
&index
) const
40 editor
->setGeometry(option
.rect
);
43 void SelectDirectoryItemDelegate::setModelData(QWidget
*editor
, QAbstractItemModel
*model
,
44 const QModelIndex
&index
) const
46 KUrlRequester
*fileWidget
= static_cast<KUrlRequester
*>(editor
);
47 QString path
= fileWidget
->url().pathOrUrl();
49 if (!path
.isEmpty()) {
50 model
->setData(index
, path
);