superkaramba
clickarea.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "clickarea.h"
00014
00015 #include <QMouseEvent>
00016 #include <QCursor>
00017
00018 #include <KService>
00019
00020
00021 ClickArea::ClickArea(Karamba* k, bool preview, int x, int y, int w, int h)
00022 : Meter(k, x, y, w, h), m_preview(preview)
00023 {
00024 value = "";
00025 setAcceptedMouseButtons(Qt::LeftButton);
00026 setCursor(QCursor(Qt::PointingHandCursor));
00027 }
00028
00029 ClickArea::~ClickArea()
00030 {}
00031
00032 bool ClickArea::mouseEvent(QEvent *e)
00033 {
00034
00035 Q_UNUSED(e);
00036
00037 if (!svc_name.isEmpty()) {
00038 KService sv(svc_name, svc_onClick, svc_icon);
00039 KUrl::List l;
00040 KRun::run(sv, l, 0);
00041 return false;
00042 } else {
00043 QString program;
00044 program = onClick;
00045 program.replace(QRegExp("%v", Qt::CaseInsensitive), value);
00046
00047 if (!program.isEmpty()) {
00048
00049 KRun::runCommand(program,0L);
00050 }
00051 }
00052
00053 return false;
00054 }
00055
00056 void ClickArea::setOnClick(const QString &oc)
00057 {
00058 onClick = oc;
00059 }
00060
00061 void ClickArea::setServiceOnClick(const QString &name, const QString &exec, const QString &icon)
00062 {
00063 svc_name = name;
00064 svc_onClick = exec;
00065 svc_icon = icon;
00066 }
00067
00068 void ClickArea::setOnMiddleClick(const QString &oc)
00069 {
00070 onMiddleClick = oc;
00071 }
00072
00073
00074 QRect ClickArea::getRectangle()
00075 {
00076 return boundingRect().toRect();
00077 }
00078
00079 void ClickArea::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
00080 QWidget *widget)
00081 {
00082 Q_UNUSED(option);
00083 Q_UNUSED(widget);
00084
00085 if (m_preview)
00086 painter->drawRect(boundingRect());
00087 }
00088
00089
00090 void ClickArea::setValue(int v)
00091 {
00092 setValue(QString::number(v));
00093 }
00094
00095
00096 void ClickArea::setValue(const QString &v)
00097 {
00098 value = v;
00099 }
00100
00101 #include "clickarea.moc"