Revision: e68a2e506cb6
Author: Devin Anderson <
surface...@gmail.com>
Date: Mon Dec 31 13:11:12 2012
Log: Make text in table selectable so that bytes can be copied/pasted
to the message editor. Top align data in rows.
http://code.google.com/p/midisnoop/source/detail?r=e68a2e506cb6
Added:
/src/messagetabledelegate.cpp
/src/messagetabledelegate.h
Modified:
/src/mainview.cpp
/src/mainview.h
/src/mainview.ui
/src/
src.pro
=======================================
--- /dev/null
+++ /src/messagetabledelegate.cpp Mon Dec 31 13:11:12 2012
@@ -0,0 +1,87 @@
+/*
+ * midisnoop - MIDI monitor and prober
+ * Copyright (C) 2012 Devin Anderson
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
Free
+ * Software Foundation; either version 2 of the License, or (at your
option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
with
+ * this program; if not, write to the Free Software Foundation, Inc., 675
Mass
+ * Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <QtGui/QApplication>
+#include <QtGui/QTextEdit>
+#include <QtGui/QTextFrame>
+
+#include "messagetabledelegate.h"
+
+MessageTableDelegate::MessageTableDelegate(QObject *parent):
+ QStyledItemDelegate(parent)
+{
+ // Empty
+}
+
+MessageTableDelegate::~MessageTableDelegate()
+{
+ // Empty
+}
+
+QWidget *
+MessageTableDelegate::createEditor(QWidget *parent,
+ const QStyleOptionViewItem &/*option*/,
+ const QModelIndex &/*index*/) const
+{
+ QTextEdit *editor = new QTextEdit(parent);
+
+ editor->setFrameShadow(QTextEdit::Plain);
+ editor->setFrameShape(QTextEdit::NoFrame);
+ editor->setLineWidth(0);
+ editor->setMidLineWidth(0);
+
+ editor->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ editor->setReadOnly(true);
+ editor->setTextInteractionFlags(Qt::TextSelectableByKeyboard |
+ Qt::TextSelectableByMouse);
+ return editor;
+}
+
+void
+MessageTableDelegate::setEditorData(QWidget *editor,
+ const QModelIndex &index) const
+{
+ QTextEdit *textEditor = qobject_cast<QTextEdit *>(editor);
+ textEditor->setPlainText(index.data(Qt::EditRole).toString());
+ QTextDocument *document = textEditor->document();
+ document->setDocumentMargin(0);
+ QTextFrame *rootFrame = document->rootFrame();
+ QTextFrameFormat frameFormat = rootFrame->frameFormat();
+ frameFormat.setBottomMargin(0);
+ frameFormat.setLeftMargin(3);
+ frameFormat.setRightMargin(3);
+ frameFormat.setTopMargin(0);
+ rootFrame->setFrameFormat(frameFormat);
+}
+
+void
+MessageTableDelegate::setModelData(QWidget */*editor*/,
+ QAbstractItemModel */*model*/,
+ const QModelIndex &/*index*/) const
+{
+ // Empty
+}
+
+void
+MessageTableDelegate::updateEditorGeometry(QWidget *editor,
+ const QStyleOptionViewItem
&option,
+ const QModelIndex &/*index*/)
const
+{
+ editor->setGeometry(option.rect);
+}
=======================================
--- /dev/null
+++ /src/messagetabledelegate.h Mon Dec 31 13:11:12 2012
@@ -0,0 +1,53 @@
+/*
+ * midisnoop - MIDI monitor and prober
+ * Copyright (C) 2012 Devin Anderson
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
Free
+ * Software Foundation; either version 2 of the License, or (at your
option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
with
+ * this program; if not, write to the Free Software Foundation, Inc., 675
Mass
+ * Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __MESSAGETABLEDELEGATE_H__
+#define __MESSAGETABLEDELEGATE_H__
+
+#include <QtGui/QStyledItemDelegate>
+
+class MessageTableDelegate: public QStyledItemDelegate {
+
+ Q_OBJECT
+
+public:
+
+ explicit
+ MessageTableDelegate(QObject *parent=0);
+
+ ~MessageTableDelegate();
+
+ QWidget *
+ createEditor(QWidget *parent, const QStyleOptionViewItem &option,
+ const QModelIndex &index) const;
+
+ void
+ setEditorData(QWidget *editor, const QModelIndex &index) const;
+
+ void
+ setModelData(QWidget *editor, QAbstractItemModel *model,
+ const QModelIndex &index) const;
+
+ void
+ updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem
&option,
+ const QModelIndex &index) const;
+
+};
+
+#endif
=======================================
--- /src/mainview.cpp Sun Dec 30 19:37:38 2012
+++ /src/mainview.cpp Mon Dec 31 13:11:12 2012
@@ -59,6 +59,7 @@
tr("Timestamp"), Qt::DisplayRole);
tableView = getChild<QTableView>(widget, "centralWidget");
+ tableView->setItemDelegate(&tableDelegate);
tableView->setModel(&tableModel);
}
@@ -74,9 +75,16 @@
int count = tableModel.rowCount();
bool inserted = tableModel.insertRow(count);
assert(inserted);
+ Qt::AlignmentFlag alignment = Qt::AlignTop;
setModelData(count, MESSAGETABLECOLUMN_DATA, dataDescription);
+ setModelData(count, MESSAGETABLECOLUMN_DATA, alignment,
+ Qt::TextAlignmentRole);
setModelData(count, MESSAGETABLECOLUMN_STATUS, statusDescription);
+ setModelData(count, MESSAGETABLECOLUMN_STATUS, alignment,
+ Qt::TextAlignmentRole);
setModelData(count, MESSAGETABLECOLUMN_TIMESTAMP, timeStamp);
+ setModelData(count, MESSAGETABLECOLUMN_TIMESTAMP, alignment,
+ Qt::TextAlignmentRole);
if (! valid) {
setModelData(count, MESSAGETABLECOLUMN_STATUS,
QIcon(":/midisnoop/images/16x16/error.png"),
=======================================
--- /src/mainview.h Sun Dec 30 01:18:51 2012
+++ /src/mainview.h Mon Dec 31 13:11:12 2012
@@ -26,6 +26,7 @@
#include <QtGui/QTableView>
#include "designerview.h"
+#include "messagetabledelegate.h"
class MainView: public DesignerView {
@@ -90,6 +91,7 @@
QAction *addAction;
QAction *clearAction;
QAction *configureAction;
+ MessageTableDelegate tableDelegate;
QAction *quitAction;
QStandardItemModel tableModel;
QTableView *tableView;
=======================================
--- /src/mainview.ui Mon Dec 31 08:40:11 2012
+++ /src/mainview.ui Mon Dec 31 13:11:12 2012
@@ -14,12 +14,18 @@
<string>midisnoop</string>
</property>
<widget class="QTableView" name="centralWidget">
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAsNeeded</enum>
+ </property>
<property name="editTriggers">
- <set>QAbstractItemView::NoEditTriggers</set>
+ <set>QAbstractItemView::CurrentChanged|
QAbstractItemView::SelectedClicked</set>
</property>
<property name="alternatingRowColors">
<bool>false</bool>
</property>
+ <property name="selectionMode">
+ <enum>QAbstractItemView::SingleSelection</enum>
+ </property>
<property name="verticalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
=======================================
--- /src/
src.pro Sun Dec 30 01:18:51 2012
+++ /src/
src.pro Mon Dec 31 13:11:12 2012
@@ -79,6 +79,7 @@
error.h \
errorview.h \
mainview.h \
+ messagetabledelegate.h \
messageview.h \
util.h \
view.h
@@ -99,6 +100,7 @@
errorview.cpp \
main.cpp \
mainview.cpp \
+ messagetabledelegate.cpp \
messageview.cpp \
util.cpp \
view.cpp