* Improve transfer history dialog
[kdenetwork.git] / kget / conf / selectdirectoryitemdelegate.cpp
blob0f9085549a845c0e23fdacd044d0a792a89d5a3b
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
25 Q_UNUSED(option)
26 Q_UNUSED(index)
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());
32 return widget;
35 void SelectDirectoryItemDelegate::updateEditorGeometry(QWidget *editor,
36 const QStyleOptionViewItem &option, const QModelIndex &index) const
38 Q_UNUSED(index)
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);