[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfenumlistwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * file klfenumlistwidget.cpp
3 * This file is part of the KLatexFormula Project.
4 * Copyright (C) 2011 by Philippe Faist
5 * philippe.faist at bluewin.ch
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22/* $Id$ */
23
24#include <QUrl>
25#include <QUrlQuery>
26
27#include "klfenumlistwidget.h"
28
29
31 : QLabel(QString(), parent)
32{
33 setTextFormat(Qt::RichText);
34 setWordWrap(true);
35
36 connect(this, SIGNAL(linkActivated(const QString&)), this, SLOT(labelActionLink(const QString&)));
37}
38
42
44{
45 if (i >= 0 && i < pItems.size())
46 return pItems[i].s;
47 return QString();
48}
49
51{
52 if (i >= 0 && i < pItems.size())
53 return pItems[i].data;
54 return QVariant();
55}
56
58{
60 int k;
61 for (k = 0; k < pItems.size(); ++k)
62 l << pItems[k].s;
63 return l;
64}
66{
67 QVariantList l;
68 int k;
69 for (k = 0; k < pItems.size(); ++k)
70 l << pItems[k].data;
71 return l;
72}
73
74
76{
77 i = simple_wrapped_item_index(i);
78 if (i < 0 || i >= pItems.size())
79 return;
80
81 pItems.removeAt(i);
82
84}
85void KLFEnumListWidget::insertItem(int i, const QString& s, const QVariant& data)
86{
87 i = simple_wrapped_item_index(i);
88 pItems.insert(i, Item(s, data));
89
91}
92
93void KLFEnumListWidget::setItems(const QStringList& slist, const QVariantList& datalist)
94{
95 pItems.clear();
96 int k;
97 for (k = 0; k < slist.size(); ++k) {
98 QVariant d;
99 if (k < datalist.size())
100 d = datalist[k];
101 pItems << Item(slist[k], d);
102 }
103 if (k < datalist.size()) {
104 qWarning()<<KLF_FUNC_NAME<<": Ignoring superfluous elements in data QVariantList";
105 }
106
108}
109
111{
112 QString t;
113 t = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
114 "<html><head><meta name=\"qrichtext\" content=\"1\" />\n"
115 "<style type=\"text/css\">\n"
116 ".item { white-space: nowrap }\n"
117 "a.itemtext { color: black; text-decoration: underline; }\n"
118 "a.actionlink { color: blue; text-decoration: none; font-weight: bold; }\n"
119 "</style></head><body>\n"
120 "<p>";
121 int k;
122 for (k = 0; k < pItems.size(); ++k) {
123 t += "<span class=\"item\"><a class=\"itemtext\" href=\"klfenumlistwidgetaction:/itemClick?i="
124 +QString::number(k)+"\">" + (pItems[k].s).toHtmlEscaped() + "</a>&nbsp;";
125 t += "<a class=\"actionlink\" href=\"klfenumlistwidgetaction:/removeAt?i="+QString::number(k)+"\">[-]</a>"
126 + "&nbsp;&nbsp;</span> ";
127 }
128 t += "</p>" "</body></html>";
129
130 setText(t);
131}
132
133void KLFEnumListWidget::labelActionLink(const QString& link)
134{
135 QUrl url = QUrl::fromEncoded(link.toLatin1());
136
137 klfDbg("link clicked="<<link<<" scheme="<<url.scheme()<<", path="<<url.path()) ;
138
139 if (url.scheme() == "klfenumlistwidgetaction") {
140 QUrlQuery q(url);
141 if (url.path() == "/removeAt") {
142 int i = q.queryItemValue("i").toInt();
143 removeItem(i);
144 return;
145 }
146 if (url.path() == "/itemClick") {
147 int i = q.queryItemValue("i").toInt();
148 emit itemActivated(i, itemAt(i), itemDataAt(i));
149 emit itemActivated(itemAt(i), itemDataAt(i));
150 return;
151 }
152 }
153
154 klfDbg("don't know what to do with link: "<<link<<" ...") ;
155}
156
157
158
void setItems(const QStringList &slist, const QVariantList &datalist=QVariantList())
QVariant itemDataAt(int i) const
virtual void updateLabelText()
QString itemAt(int i) const
void insertItem(int i, const QString &s, const QVariant &data=QVariant())
QStringList itemList() const
void itemActivated(const QString &s, const QVariant &data)
KLFEnumListWidget(QWidget *parent)
QVariantList itemDataList() const
#define klfDbg(streamableItems)
print debug stream items
Definition klfdebug.h:158
int size() const
QString number(int n, int base)
QByteArray toLatin1() const
QUrl fromEncoded(const QByteArray &input, ParsingMode parsingMode)
QString path(ComponentFormattingOptions options) const
QString scheme() const

Generated by doxygen 1.10.0