[Kst] branches/work/kst/1.6/kst/src

Andrew Walker arwalker at sumusltd.com
Tue Nov 13 19:52:39 CET 2007


SVN commit 736239 by arwalker:

allow user to set arrow end points and scale size via javaScript

 M  +170 -1    extensions/js/bind_arrow.cpp  
 M  +24 -2     extensions/js/bind_arrow.h  
 M  +2 -2      extensions/js/bind_line.cpp  
 M  +0 -2      extensions/js/bind_line.h  
 M  +2 -3      libkstapp/kstviewline.cpp  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_arrow.cpp #736238:736239
@@ -102,6 +102,10 @@
 
 
 static ArrowProperties arrowProperties[] = {
+  { "fromArrow", &KstBindArrow::setFromArrow, &KstBindArrow::fromArrow },
+  { "toArrow", &KstBindArrow::setToArrow, &KstBindArrow::toArrow },
+  { "fromArrowScaling", &KstBindArrow::setFromArrowScaling, &KstBindArrow::fromArrowScaling },
+  { "toArrowScaling", &KstBindArrow::setToArrowScaling, &KstBindArrow::toArrowScaling },
   { 0L, 0L, 0L }
 };
 
@@ -211,4 +215,169 @@
   }
 }
 
-// vim: ts=2 sw=2 et
+#define makeArrow(X) dynamic_cast<KstViewArrow*>(const_cast<KstObject*>(X.data()))
+
+void KstBindArrow::setFromArrow(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+
+  if (value.type() != KJS::BooleanType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+
+    d->setHasFromArrow(value.toBoolean(exec));
+    _d->setDirty();
+    KstApp::inst()->paintAll(KstPainter::P_PAINT);
+  }
+}
+
+
+KJS::Value KstBindArrow::fromArrow(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    return KJS::Boolean(d->hasFromArrow());
+  }
+
+  return KJS::Undefined();
+}
+
+
+void KstBindArrow::setToArrow(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+
+  if (value.type() != KJS::BooleanType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+
+    d->setHasToArrow(value.toBoolean(exec));
+    _d->setDirty();
+    KstApp::inst()->paintAll(KstPainter::P_PAINT);
+  }
+}
+
+
+KJS::Value KstBindArrow::toArrow(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    return KJS::Boolean(d->hasToArrow());
+  }
+
+  return KJS::Undefined();
+}
+
+
+void KstBindArrow::setFromArrowScaling(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+
+  if (value.type() !=  KJS::NumberType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+
+    d->setFromArrowScaling(value.toNumber(exec));
+    _d->setDirty();
+    KstApp::inst()->paintAll(KstPainter::P_PAINT);
+  }
+}
+
+
+KJS::Value KstBindArrow::fromArrowScaling(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    return KJS::Number(d->fromArrowScaling());
+  }
+
+  return KJS::Undefined();
+}
+
+
+void KstBindArrow::setToArrowScaling(KJS::ExecState *exec, const KJS::Value& value) {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return;
+  }
+
+  if (value.type() !=  KJS::NumberType) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError);
+    exec->setException(eobj);
+    return;
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstWriteLocker wl(d);
+
+    d->setToArrowScaling(value.toNumber(exec));
+    _d->setDirty();
+    KstApp::inst()->paintAll(KstPainter::P_PAINT);
+  }
+}
+
+
+KJS::Value KstBindArrow::toArrowScaling(KJS::ExecState *exec) const {
+  if (!_d) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+
+  KstViewArrowPtr d = makeArrow(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    return KJS::Number(d->toArrowScaling());
+  }
+
+  return KJS::Undefined();
+}
+
+#undef makeArrow
--- branches/work/kst/1.6/kst/src/extensions/js/bind_arrow.h #736238:736239
@@ -57,13 +57,35 @@
     int methodCount() const;
     int propertyCount() const;
 
+    /* @property boolean fromArrow
+       @description True if the arrow has an arrow at the start point.
+    */
+    void setFromArrow(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value fromArrow(KJS::ExecState *exec) const;
+
+    /* @property boolean toArrow
+       @description True if the arrow has an arrow at the end point.
+    */
+    void setToArrow(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value toArrow(KJS::ExecState *exec) const;
+
+    /* @property number fromArrowScaling
+       @description Scale size of the arrow at the start point.
+    */
+    void setFromArrowScaling(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value fromArrowScaling(KJS::ExecState *exec) const;
+
+    /* @property number toArrowScaling
+       @description Scale size of the arrow at the end point.
+    */
+    void setToArrowScaling(KJS::ExecState *exec, const KJS::Value& value);
+    KJS::Value toArrowScaling(KJS::ExecState *exec) const;
+
   protected:
     KstBindArrow(int id, const char *name = 0L);
     void addBindings(KJS::ExecState *exec, KJS::Object& obj);
     static KstBindViewObject *bindFactory(KJS::ExecState *exec, KstViewObjectPtr obj);
 };
 
-
 #endif
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_line.cpp #736238:736239
@@ -320,6 +320,8 @@
         d->setCapStyle(Qt::RoundCap);
         break;
       default:
+        KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError, "Value is out of range.");
+        exec->setException(eobj);
         return;
     }
     KstApp::inst()->paintAll(KstPainter::P_PAINT);
@@ -404,7 +406,5 @@
   return KJS::Number(0);
 }
 
-
 #undef makeLine
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_line.h #736238:736239
@@ -101,7 +101,5 @@
     static KstBindViewObject *bindFactory(KJS::ExecState *exec, KstViewObjectPtr obj);
 };
 
-
 #endif
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/libkstapp/kstviewline.cpp #736238:736239
@@ -30,7 +30,7 @@
 #include <math.h>
 
 KstViewLine::KstViewLine(const QString& type)
-: KstViewObject(type), _width(0) {
+: KstViewObject(type), _width(1) {
   _editTitle = i18n("Edit Line");
   setTransparent(true);
   _container = false;
@@ -518,6 +518,5 @@
 KST_REGISTER_VIEW_OBJECT(Line, create_KstViewLine, handler_KstViewLine)
 }
 
-
 #include "kstviewline.moc"
-// vim: ts=2 sw=2 et
+


More information about the Kst mailing list