File indexing completed on 2024-05-12 05:44:24
0001 /*************************************************************************** 0002 * Copyright (C) 2005-2009 by Rajko Albrecht * 0003 * ral@alwins-world.de * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0019 ***************************************************************************/ 0020 #include "kmultilinedelegate.h" 0021 0022 #include <ktextedit.h> 0023 0024 KMultilineDelegate::KMultilineDelegate(QObject *parent) 0025 : QItemDelegate(parent) 0026 { 0027 } 0028 0029 QWidget *KMultilineDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex & /* index */) const 0030 { 0031 KTextEdit *editor = new KTextEdit(parent); 0032 // editor->setMinimumHeight(35); 0033 return editor; 0034 } 0035 0036 void KMultilineDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const 0037 { 0038 QString value = index.model()->data(index, Qt::EditRole).toString(); 0039 0040 KTextEdit *editBox = static_cast<KTextEdit *>(editor); 0041 editBox->setText(value); 0042 } 0043 0044 void KMultilineDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const 0045 { 0046 KTextEdit *editBox = static_cast<KTextEdit *>(editor); 0047 model->setData(index, editBox->toPlainText(), Qt::EditRole); 0048 } 0049 0050 void KMultilineDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /* index */) const 0051 { 0052 editor->setGeometry(option.rect); 0053 } 0054 0055 QSize KMultilineDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const 0056 { 0057 QSize s = QItemDelegate::sizeHint(option, index); 0058 if (s.height() < 35) { 0059 s.setHeight(35); 0060 } 0061 return s; 0062 } 0063 0064 #include "moc_kmultilinedelegate.cpp"