superkaramba
clickmap.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "clickmap.h"
00012 #include "clickmap.moc"
00013
00014 #include "karamba.h"
00015
00016 #include <QPainter>
00017 #include <QGraphicsSceneMouseEvent>
00018
00019 #include <KRun>
00020
00021 ClickMap::ClickMap(Karamba* k, int x, int y, int w, int h)
00022 : Meter(k, x, y, w, h)
00023 {
00024
00025
00026
00027
00028
00029
00030
00031 if (h == 0 || w == 0) {
00032 setWidth(-1);
00033 setHeight(-1);
00034 }
00035 }
00036
00037 ClickMap::~ClickMap()
00038 {}
00039
00040 void ClickMap::setTextProps(TextField *t)
00041 {
00042 text = *t;
00043 }
00044
00045 void ClickMap::mousePressEvent(QGraphicsSceneMouseEvent *e)
00046 {
00047 int index = (int)((e->pos().y() - getY()) / text.getLineHeight()) + 1;
00048 if (index >= 1 && index <= (int)displays.count()) {
00049
00050
00051 KRun::runCommand("konqueror " + links[index - 1],0L);
00052 }
00053
00054 return;
00055 }
00056
00057 void ClickMap::paint(QPainter *p, const QStyleOptionGraphicsItem *option,
00058 QWidget *widget)
00059 {
00060 Q_UNUSED(option);
00061 Q_UNUSED(widget);
00062
00063 int i = 0;
00064 int row = 1;
00065
00066 p->setFont(text.getFont());
00067
00068 QStringList::Iterator it = displays.begin();
00069 while (it != displays.end() && (row <= getHeight() || getHeight() == -1)) {
00070 p->setPen(text.getColor());
00071
00072 p->drawText(getX(), getY() + i + text.getLineHeight(), *it);
00073 i += text.getLineHeight();
00074 it++;
00075 row++;
00076 }
00077 }
00078
00079 void ClickMap::setValue(const QString &v)
00080 {
00081 QRegExp rx("^http://", Qt::CaseInsensitive);
00082 if (rx.indexIn(v) == -1)
00083 displays.append(v);
00084 else
00085 links.append(v);
00086 }
00087
00088 void ClickMap::setValue(int v)
00089 {
00090 if (v == 0) {
00091 links.clear();
00092 displays.clear();
00093 }
00094 }
00095