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 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 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; }