27 #include <QApplication>
37 QCopyListView::~QCopyListView() {
41 QStringList linesT,linesH;
42 QModelIndexList selection = selectedIndexes();
43 QListIterator<QModelIndex> selIter(selection);
44 while (selIter.hasNext()) {
45 QModelIndex curIdx = selIter.next();
46 QVariant curData; QString colStyle;
47 curData = model()->data(curIdx,Qt::ForegroundRole);
48 if (curData.type() == QVariant::Brush) {
49 QBrush brush = qvariant_cast<QBrush>(curData);
50 QString color = brush.color().name();
51 if (!color.isEmpty()) {
52 colStyle += QString(
"color:%1;").arg(color);
55 curData = model()->data(curIdx,Qt::BackgroundRole);
56 if (curData.type() == QVariant::Brush) {
57 QBrush brush = qvariant_cast<QBrush>(curData);
58 QString color = brush.color().name();
59 if (!color.isEmpty()) {
60 colStyle += QString(
"background-color:%1;").arg(color);
63 curData = model()->data(curIdx,Qt::DisplayRole);
64 if (curData.type() == QVariant::String) {
65 QString curLine = curData.toString();
68 curLine.replace(
"&",
"&");
69 curLine.replace(
"\"",
""");
70 curLine.replace(
"<",
"<");
71 curLine.replace(
">",
">");
73 QString(
"<span class=\"logLine\" style=\"%1\">%2</span>")
74 .arg(colStyle).arg(curLine);
78 QMimeData* clipData =
new QMimeData;
79 clipData->setText(linesT.join(
"\n").toLocal8Bit());
80 QString htmlCont = QString(
81 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "
82 "\"http://www.w3.org/TR/html4/strict.dtd\">\n"
83 "<html>\n<head>\n<title>Tuchulcha Log</title>\n"
84 "<meta http-equiv=\"content-type\" "
85 "content=\"text/html; charset=UTF-8\">\n"
86 "<style type=\"text/css\">"
87 "span.logLine{font-family:monospace;white-space:pre-wrap;"
88 "-moz-tab-size:4;-o-tab-size:4;tab-size:4;}"
90 "<body>\n<div>\n%1\n</div>\n</body>\n</html>")
91 .arg(linesH.join(
"<br>\n"));
92 clipData->setHtml(htmlCont);
98 #if !defined(QT_NO_CLIPBOARD) && !defined(QT_NO_SHORTCUT)
99 if (ev == QKeySequence::Copy) {
104 QListView::keyPressEvent(ev);
107 QListView::keyPressEvent(ev);
QMimeData * getSelectedContent() const
get mime-data representation of selected indices
Declaration of class QCopyListView.
QCopyListView(QWidget *parent=0)
default constructor
virtual void keyPressEvent(QKeyEvent *event)
reworked key press event handler able to copy multipe lines into the clipboard