int MarkerTLine::highLow (PluginData *pd) { if (! pd->data) return 0; Marker *tline = (Marker *) pd->data; Entity *e = tline->settings(); PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) tline->plot()->axisScaleDraw(QwtPlot::xBottom); if (! dsd) return 1; QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; int x = dsd->dateToX(date->toDateTime()); if (x >= pd->start && x <= pd->end) { pd->high = price->toDouble(); double t = price2->toDouble(); if (t > pd->high) pd->high = t; pd->low = price->toDouble(); if (t < pd->low) pd->low = t; return 1; } int x2 = dsd->dateToX(date2->toDateTime()); if (x2 >= pd->start && x2 <= pd->end) { pd->high = price->toDouble(); double t = price2->toDouble(); if (t > pd->high) pd->high = t; pd->low = price->toDouble(); if (t < pd->low) pd->low = t; return 1; } return 1; }
int MarkerSell::move (PluginData *pd) { if (! pd->data) return 0; Marker *sell = (Marker *) pd->data; switch (pd->status) { case PlotStatus::_MOVE: { Entity *e = sell->settings(); QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *date = e->get(QString("date")); if (! date) return 0; QwtScaleMap map = sell->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); if (! g_symbol) return 0; Bar *tbar = g_symbol->bar(x); if (! tbar) return 0; date->setValue(tbar->date()); map = sell->plot()->canvasMap(QwtPlot::yRight); price->setValue(map.invTransform((double) pd->point.y())); sell->setModified(TRUE); sell->plot()->replot(); break; } default: break; } return 1; }
int MarkerSell::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m) { Marker *sell = (Marker *) m; Entity *e = sell->settings(); PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) sell->plot()->axisScaleDraw(QwtPlot::xBottom); QVariant *date = e->get(QString("date")); if (! date) { qDebug() << "MarkerSell::draw: date missing"; return 0; } int x = xMap.transform(dsd->dateToX(date->toDateTime())); if (x == -1) return 1; QVariant *price = e->get(QString("price")); if (! price) { qDebug() << "MarkerSell::draw: price missing"; return 0; } int y = yMap.transform(price->toDouble()); QVariant *tset = e->get(QString("color")); if (! tset) { qDebug() << "MarkerSell::draw: color missing"; return 0; } QColor color(tset->toString()); p->setBrush(color); QPolygon arrow; arrow.putPoints(0, 7, x, y, x + 5, y - 5, x + 2, y - 5, x + 2, y - 11, x - 2, y - 11, x - 2, y - 5, x - 5, y - 5); p->drawPolygon(arrow, Qt::OddEvenFill); sell->clearSelectionArea(); sell->appendSelectionArea(QRegion(arrow)); int handleWidth = sell->handleWidth(); if (sell->selected()) { sell->clearGrabHandles(); sell->appendGrabHandle(QRegion(x - (handleWidth / 2), y - handleWidth, handleWidth, handleWidth, QRegion::Rectangle)); p->fillRect(x - (handleWidth / 2), y + (handleWidth / 2), handleWidth, handleWidth, color); } return 1; }
int MarkerSell::click (PluginData *pd) { if (! pd->data) return 0; Marker *sell = (Marker *) pd->data; switch ((PlotStatus::Key) pd->status) { case PlotStatus::_SELECTED: { switch (pd->button) { case Qt::LeftButton: if (sell->isGrabSelected(pd->point)) { pd->status = PlotStatus::_MOVE; return 1; } if (! sell->isSelected(pd->point)) { pd->status = PlotStatus::_NONE; sell->setSelected(FALSE); Plot *tplot = (Plot *) sell->plot(); tplot->unselectMarker(); sell->plot()->replot(); return 1; } break; case Qt::RightButton: { Plot *p = (Plot *) sell->plot(); p->showMarkerMenu(); break; } default: break; } break; } case PlotStatus::_MOVE: { switch (pd->button) { case Qt::LeftButton: pd->status = PlotStatus::_SELECTED; return 1; default: break; } break; } default: // _None { switch (pd->button) { case Qt::LeftButton: { if (sell->isSelected(pd->point)) { pd->status = PlotStatus::_SELECTED; sell->setSelected(TRUE); Plot *tplot = (Plot *) sell->plot(); tplot->selectMarker(sell->ID()); sell->plot()->replot(); return 1; } break; } default: break; } break; } } return 1; }
int MarkerRetracement::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m) { Marker *ret = (Marker *) m; Entity *e = ret->settings(); QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *high = e->get(QString("high")); if (! high) return 0; QVariant *low = e->get(QString("low")); if (! low) return 0; QVariant *tset = e->get(QString("color")); if (! tset) return 0; QColor color(tset->toString()); QVariant *extend = e->get(QString("extend")); if (! extend) return 0; QVariant *l1 = e->get(QString("level1")); if (! l1) return 0; QVariant *l2 = e->get(QString("level2")); if (! l2) return 0; QVariant *l3 = e->get(QString("level3")); if (! l3) return 0; QVariant *l4 = e->get(QString("level4")); if (! l4) return 0; QVariant *l5 = e->get(QString("level5")); if (! l5) return 0; QVariant *l6 = e->get(QString("level6")); if (! l6) return 0; PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) ret->plot()->axisScaleDraw(QwtPlot::xBottom); int x = xMap.transform(dsd->dateToX(date->toDateTime())); QDateTime dt = date2->toDateTime(); if (extend->toBool()) { int s, e; g_symbol->startEndRange(s, e); Bar *bar = g_symbol->bar(e); if (! bar) return 0; dt = bar->date(); } int x2 = xMap.transform(dsd->dateToX(dt)); p->setPen(color); ret->clearSelectionArea(); QList<double> lineList; lineList.append(l1->toDouble()); lineList.append(l2->toDouble()); lineList.append(l3->toDouble()); lineList.append(l4->toDouble()); lineList.append(l5->toDouble()); lineList.append(l6->toDouble()); for (int loop = 0; loop < lineList.size(); loop++) { double td = lineList.at(loop); if (td != 0) { double range = high->toDouble() - low->toDouble(); double r = 0; if (td < 0) r = low->toDouble() + (range * td); else { if (td > 0) r = low->toDouble() + (range * td); else { if (td < 0) r = high->toDouble(); else r = low->toDouble(); } } int y = yMap.transform(r); p->drawLine (x, y, x2, y); p->drawText(x, y - 1, QString::number(td * 100) + "% - " + QString::number(r)); QPolygon array; array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4); ret->appendSelectionArea(QRegion(array)); } } // draw the low line int y = yMap.transform(low->toDouble()); p->drawLine (x, y, x2, y); Strip strip; QString ts; strip.strip(low->toDouble(), 4, ts); p->drawText(x, y - 1, "0% - " + ts); // store the selectable area the low line occupies QPolygon array; array.putPoints(0, 4, x, y - 4, x, y + 4, x2, y + 4, x2, y - 4); ret->appendSelectionArea(QRegion(array)); // draw the high line int y2 = yMap.transform(high->toDouble()); p->drawLine (x, y2, x2, y2); strip.strip(high->toDouble(), 4, ts); p->drawText(x, y2 - 1, "100% - " + ts); // store the selectable area the high line occupies array.clear(); array.putPoints(0, 4, x, y2 - 4, x, y2 + 4, x2, y2 + 4, x2, y2 - 4); ret->appendSelectionArea(QRegion(array)); if (ret->selected()) { int handleWidth = ret->handleWidth(); ret->clearGrabHandles(); //top left corner ret->appendGrabHandle(QRegion(x, y2 - (handleWidth / 2), handleWidth, handleWidth, QRegion::Rectangle)); p->fillRect(x, y2 - (handleWidth / 2), handleWidth, handleWidth, color); //bottom right corner ret->appendGrabHandle(QRegion(x2, y - (handleWidth / 2), handleWidth, handleWidth, QRegion::Rectangle)); p->fillRect(x2, y - (handleWidth / 2), handleWidth, handleWidth, color); } return 1; }
int MarkerRetracement::click (PluginData *pd) { if (! pd->data) return 0; Marker *m = (Marker *) pd->data; switch (pd->status) { case PlotStatus::_SELECTED: { switch (pd->button) { case Qt::LeftButton: { int grab = m->isGrabSelected(pd->point); if (grab) { pd->status = PlotStatus::_MOVE; if (grab == 2) pd->status = PlotStatus::_MOVE2; return 1; } if (! m->isSelected(pd->point)) { pd->status = PlotStatus::_NONE; m->setSelected(FALSE); Plot *tplot = (Plot *) m->plot(); tplot->unselectMarker(); m->plot()->replot(); return 1; } break; } case Qt::RightButton: { Plot *p = (Plot *) m->plot(); p->showMarkerMenu(); break; } default: break; } break; } case PlotStatus::_MOVE: case PlotStatus::_CREATE_MOVE: { switch (pd->button) { case Qt::LeftButton: if (pd->status == PlotStatus::_CREATE_MOVE) { pd->status = PlotStatus::_MOVE2; emit signalMessage(tr("Select lowest ending point...")); return 1; } pd->status = PlotStatus::_SELECTED; return 1; default: break; } break; } case PlotStatus::_MOVE2: { switch (pd->button) { case Qt::LeftButton: pd->status = PlotStatus::_SELECTED; return 1; default: break; } break; } default: // _None { switch (pd->button) { case Qt::LeftButton: { if (m->isSelected(pd->point)) { pd->status = PlotStatus::_SELECTED; m->setSelected(TRUE); Plot *tplot = (Plot *) m->plot(); tplot->selectMarker(m->ID()); m->plot()->replot(); return 1; } break; } default: break; } break; } } return 1; }
int MarkerRetracement::move (PluginData *pd) { if (! pd->data) return 0; Marker *m = (Marker *) pd->data; Entity *e = m->settings(); switch (pd->status) { case PlotStatus::_MOVE: case PlotStatus::_CREATE_MOVE: { QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *high = e->get(QString("high")); if (! high) return 0; QVariant *low = e->get(QString("low")); if (! low) return 0; QwtScaleMap map = m->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date->setValue(bar->date()); map = m->plot()->canvasMap(QwtPlot::yRight); high->setValue(map.invTransform((double) pd->point.y())); if (pd->status == PlotStatus::_CREATE_MOVE) { date2->setValue(bar->date()); low->setValue(high->toDouble()); } m->plot()->replot(); m->setModified(TRUE); break; } case PlotStatus::_MOVE2: { QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *low = e->get(QString("low")); if (! low) return 0; QwtScaleMap map = m->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date2->setValue(bar->date()); map = m->plot()->canvasMap(QwtPlot::yRight); low->setValue(map.invTransform((double) pd->point.y())); m->plot()->replot(); m->setModified(TRUE); break; } default: break; } return 1; }
int MarkerTLine::draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &, void *m) { Marker *tline = (Marker *) m; Entity *e = tline->settings(); QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; QVariant *tset = e->get(QString("color")); if (! tset) return 0; QColor color(tset->toString()); QVariant *extend = e->get(QString("extend")); if (! extend) return 0; PlotDateScaleDraw *dsd = (PlotDateScaleDraw *) tline->plot()->axisScaleDraw(QwtPlot::xBottom); int x = xMap.transform(dsd->dateToX(date->toDateTime())); int x2 = xMap.transform(dsd->dateToX(date2->toDateTime())); int y = yMap.transform(price->toDouble()); int y2 = yMap.transform(price2->toDouble()); p->setPen(color); p->drawLine (x, y, x2, y2); // save old values; int tx2 = x2; int ty2 = y2; int tx = x; int ty = y; if (extend->toBool()) { int ydiff = y - y2; int xdiff = x2 - x; if (xdiff > 0) { while (x2 < p->window().width()) { x = x2; y = y2; x2 = x2 + xdiff; y2 = y2 - ydiff; p->drawLine (x, y, x2, y2); } } } // store the selectable area the line occupies tline->clearSelectionArea(); QPolygon array; array.putPoints(0, 4, tx, ty - 4, tx, ty + 4, x2, y2 + 4, x2, y2 - 4); tline->appendSelectionArea(QRegion(array)); if (tline->selected()) { int handleWidth = tline->handleWidth(); tline->clearGrabHandles(); tline->appendGrabHandle(QRegion(tx, ty - (handleWidth / 2), handleWidth, handleWidth, QRegion::Rectangle)); p->fillRect(tx, ty - (handleWidth / 2), handleWidth, handleWidth, color); tline->appendGrabHandle(QRegion(tx2, ty2 - (handleWidth / 2), handleWidth, handleWidth, QRegion::Rectangle)); p->fillRect(tx2, ty2 - (handleWidth / 2), handleWidth, handleWidth, color); } return 1; }
int MarkerTLine::move (PluginData *pd) { if (! pd->data) return 0; Marker *tline = (Marker *) pd->data; Entity *e = tline->settings(); switch (pd->status) { case PlotStatus::_MOVE: case PlotStatus::_CREATE_MOVE: { QVariant *price = e->get(QString("price")); if (! price) return 0; QVariant *date = e->get(QString("date")); if (! date) return 0; QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QwtScaleMap map = tline->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date->setValue(bar->date()); map = tline->plot()->canvasMap(QwtPlot::yRight); price->setValue(map.invTransform((double) pd->point.y())); if (pd->status == PlotStatus::_CREATE_MOVE) { date2->setValue(bar->date()); price2->setValue(price->toDouble()); } tline->plot()->replot(); tline->setModified(TRUE); break; } case PlotStatus::_MOVE2: { QVariant *price2 = e->get(QString("price2")); if (! price2) return 0; QVariant *date2 = e->get(QString("date2")); if (! date2) return 0; QwtScaleMap map = tline->plot()->canvasMap(QwtPlot::xBottom); int x = map.invTransform((double) pd->point.x()); Bar *bar = g_symbol->bar(x); if (! bar) return 0; date2->setValue(bar->date()); map = tline->plot()->canvasMap(QwtPlot::yRight); price2->setValue(map.invTransform((double) pd->point.y())); tline->plot()->replot(); tline->setModified(TRUE); break; } default: break; } return 1; }