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