clickmap.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by Ralph M. Churchill                              *
00003  *   mrchucho@yahoo.com                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
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     if( h != 0 || w != 0)
00020         clip = 0;
00021     else
00022         clip = Qt::DontClip;
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   //Don't load the web page if the click isn't for us
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       // qDebug( "You clicked item " + QString::number( index ) + ", " +
00049       //  displays[index - 1] + " " + links[index - 1] );
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; //text.getLineHeight();
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         // p->drawText(x,y+i,width,height,  Qt::AlignCenter | Qt::ExpandTabs, *it);
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( long v )
00088 {
00089     if ( v == 0 )
00090     {
00091         links.clear();
00092         displays.clear();
00093     }
00094 }
00095 
00096 #include "clickmap.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys