Debian Codegraph @

src/messagetabledelegate.cpp

raw symbols SCIP
1 /*
2 * midisnoop - MIDI monitor and prober
3 * Copyright (C) 2012 Devin Anderson
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
17 * Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <QtGui/QTextFrame>
21 #include <QtWidgets/QApplication>
22 #include <QtWidgets/QTextEdit>
23
24 #include "messagetabledelegate.h"
25
26 MessageTableDelegate::MessageTableDelegate(QObject *parent):
27 QStyledItemDelegate(parent)
28 {
29 // Empty
30 }
31
32 MessageTableDelegate::~MessageTableDelegate()
33 {
34 // Empty
35 }
36
37 QWidget *
38 MessageTableDelegate::createEditor(QWidget *parent,
39 const QStyleOptionViewItem &/*option*/,
40 const QModelIndex &/*index*/) const
41 {
42 QTextEdit *editor = new QTextEdit(parent);
43
44 editor->setFrameShadow(QTextEdit::Plain);
45 editor->setFrameShape(QTextEdit::NoFrame);
46 editor->setLineWidth(0);
47 editor->setMidLineWidth(0);
48
49 editor->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
50 editor->setReadOnly(true);
51 editor->setTextInteractionFlags(Qt::TextSelectableByKeyboard |
52 Qt::TextSelectableByMouse);
53 return editor;
54 }
55
56 void
57 MessageTableDelegate::setEditorData(QWidget *editor,
58 const QModelIndex &index) const
59 {
60 QTextEdit *textEditor = qobject_cast<QTextEdit *>(editor);
61 textEditor->setPlainText(index.data(Qt::EditRole).toString());
62 QTextDocument *document = textEditor->document();
63 document->setDocumentMargin(0);
64 QTextFrame *rootFrame = document->rootFrame();
65 QTextFrameFormat frameFormat = rootFrame->frameFormat();
66 frameFormat.setBottomMargin(0);
67 frameFormat.setLeftMargin(3);
68 frameFormat.setRightMargin(3);
69 frameFormat.setTopMargin(0);
70 rootFrame->setFrameFormat(frameFormat);
71 }
72
73 void
74 MessageTableDelegate::setModelData(QWidget */*editor*/,
75 QAbstractItemModel */*model*/,
76 const QModelIndex &/*index*/) const
77 {
78 // Empty
79 }
80
81 void
82 MessageTableDelegate::updateEditorGeometry(QWidget *editor,
83 const QStyleOptionViewItem &option,
84 const QModelIndex &/*index*/) const
85 {
86 editor->setGeometry(option.rect);
87 }