Modified the license text comment type.
[emufront] / src / delegates / stringlistdelegate.cpp
1 /*
2 ** EmuFront
3 ** Copyright 2010 Mikko Keinänen
4 **
5 ** This file is part of EmuFront.
6 **
7 **
8 ** EmuFront is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License version 2 as published by
10 ** the Free Software Foundation and appearing in the file gpl.txt included in the
11 ** packaging of this file.
12 **
13 ** EmuFront 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
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with EmuFront.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 #include "stringlistdelegate.h"
22 #include "fileextensionwidget.h"
23
24 StringListDelegate::StringListDelegate(QString separator, QObject *parent) :
25     QStyledItemDelegate(parent), separator(separator)
26 {
27 }
28
29 /*void StringListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
30 {
31     QString str = index.model()->data(index, Qt::DisplayRole).toString();
32     // TODO:...
33 }*/
34
35 QWidget* StringListDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
36 {
37     StringListWidget *editor = new StringListWidget(parent);
38     QString str = index.model()->data(index, Qt::DisplayRole).toString();
39     editor->setItems(str.split(separator, QString::SkipEmptyParts));
40     connect(editor, SIGNAL(stringListUpdated()), this, SLOT(commitAndCloseEditor()));
41     return editor;
42 }
43
44 void StringListDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
45 {
46     QString str = index.model()->data(index, Qt::DisplayRole).toString();
47     StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
48     strListWdg->setItems(str.split(separator, QString::SkipEmptyParts));
49 }
50
51 void StringListDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
52 {
53     StringListWidget *strListWdg = qobject_cast<StringListWidget *>(editor);
54     QStringList ls = strListWdg->getItems();
55     model->setData(index, ls.empty() ? "" : ls.join(separator));
56 }
57
58 void StringListDelegate::commitAndCloseEditor()
59 {
60     StringListWidget *editor = qobject_cast<StringListWidget *>(sender());
61     emit commitData(editor);
62     emit closeEditor(editor);
63 }
64
65 QSize StringListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
66 {
67     QSize sz(300,300);
68     return sz;
69 }