void KstBindLine::setCapStyle(KJS::ExecState *exec, const KJS::Value& value) { unsigned w = 0; if (value.type() != KJS::NumberType || !value.toUInt32(w)) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return; } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); switch (w) { case 0: d->setCapStyle(Qt::FlatCap); break; case 1: d->setCapStyle(Qt::SquareCap); break; case 2: d->setCapStyle(Qt::RoundCap); break; default: return; } KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
KJS::Value KstBindLine::to(KJS::ExecState *exec) const { KstViewLinePtr d = makeLine(_d); if (d) { KstReadLocker rl(d); return KJS::Object(new KstBindPoint(exec, d->to().x(), d->to().y())); } return KJS::Null(); }
KstGfxLineMouseHandler::KstGfxLineMouseHandler() : KstGfxMouseHandler() { // initial default settings before any sticky settings KstViewLinePtr defaultLine = new KstViewLine; defaultLine->setWidth(2); defaultLine->setPenStyle(Qt::SolidLine); defaultLine->setForegroundColor(Qt::black); _defaultObject = KstViewObjectPtr(defaultLine); }
KJS::Value KstBindLine::width(KJS::ExecState *exec) const { Q_UNUSED(exec) KstViewLinePtr d = makeLine(_d); if (d) { KstReadLocker rl(d); return KJS::Number(d->width()); } return KJS::Number(0); }
void KstBindLine::setTo(KJS::ExecState *exec, const KJS::Value& value) { KstBindPoint *imp = 0L; if (value.type() != KJS::ObjectType || !(imp = dynamic_cast<KstBindPoint*>(value.toObject(exec).imp()))) { return createPropertyTypeError(exec); } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); d->setTo(QPoint(int(imp->_x), int(imp->_y))); KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
void KstBindLine::setWidth(KJS::ExecState *exec, const KJS::Value& value) { unsigned w = 0; if (value.type() != KJS::NumberType || !value.toUInt32(w)) { return createPropertyTypeError(exec); } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); d->setWidth(w); KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
void KstBindLine::setWidth(KJS::ExecState *exec, const KJS::Value& value) { unsigned w = 0; if (value.type() != KJS::NumberType || !value.toUInt32(w)) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return; } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); d->setWidth(w); KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
void KstBindLine::setTo(KJS::ExecState *exec, const KJS::Value& value) { KstBindPoint *imp = 0L; if (value.type() != KJS::ObjectType || !(imp = dynamic_cast<KstBindPoint*>(value.toObject(exec).imp()))) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return; } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); d->setTo(QPoint(int(imp->_x), int(imp->_y))); // FIXME: Point is the wrong // type to use here. It's // a double, for one... KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
KJS::Value KstBindLine::capStyle(KJS::ExecState *exec) const { Q_UNUSED(exec) KstViewLinePtr d = makeLine(_d); if (d) { KstReadLocker rl(d); switch (d->capStyle()) { case Qt::FlatCap: return KJS::Number(0); case Qt::SquareCap: return KJS::Number(1); case Qt::RoundCap: return KJS::Number(2); default: break; } } return KJS::Number(0); }
KJS::Object KstBindLine::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() != 1) { return createSyntaxError(exec); } KstViewObjectPtr view = extractViewObject(exec, args[0]); if (!view) { KstViewWindow *w = extractWindow(exec, args[0]); if (w) { view = w->view(); } else { return createTypeError(exec, 0); } } KstViewLinePtr b = new KstViewLine; view->appendChild(b.data()); KstApp::inst()->paintAll(KstPainter::P_PAINT); return KJS::Object(new KstBindLine(exec, b)); }
void KstBindLine::setLineStyle(KJS::ExecState *exec, const KJS::Value& value) { unsigned w = 0; if (value.type() != KJS::NumberType || !value.toUInt32(w)) { return createPropertyTypeError(exec); } KstViewLinePtr d = makeLine(_d); if (d) { KstWriteLocker wl(d); switch (w) { case 0: d->setPenStyle(Qt::SolidLine); break; case 1: d->setPenStyle(Qt::DashLine); break; case 2: d->setPenStyle(Qt::DotLine); break; case 3: d->setPenStyle(Qt::DashDotLine); break; case 4: d->setPenStyle(Qt::DashDotDotLine); break; default: return createPropertyRangeError(exec); } KstApp::inst()->paintAll(KstPainter::P_PAINT); } }
KJS::Value KstBindLine::lineStyle(KJS::ExecState *exec) const { Q_UNUSED(exec) KstViewLinePtr d = makeLine(_d); if (d) { KstReadLocker rl(d); switch (d->penStyle()) { case Qt::SolidLine: return KJS::Number(0); case Qt::DashLine: return KJS::Number(1); case Qt::DotLine: return KJS::Number(2); case Qt::DashDotLine: return KJS::Number(3); case Qt::DashDotDotLine: return KJS::Number(4); default: break; } } return KJS::Number(0); }
KstBindLine::KstBindLine(KJS::ExecState *exec, KstViewLinePtr d, const char *name) : KstBindViewObject(exec, d.data(), name ? name : "Line") { KJS::Object o(this); addBindings(exec, o); }