void Text::draw (QPixmap &buffer, Scaler &scaler, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; painter.setFont(font); painter.setPen(color); int y = scaler.convertToY(getValue()); painter.drawText(x, y, label); QFontMetrics fm = painter.fontMetrics(); clearSelectionArea(); setSelectionArea(new QRegion(x, y - fm.height(), fm.width(label, -1), fm.height(), QRegion::Rectangle)); if (getStatus() == COBase::Selected) { clearGrabHandles(); setGrabHandle(new QRegion(x - HANDLE_WIDTH - 1, y - (fm.height() / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - HANDLE_WIDTH - 1, y - (fm.height() / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void SellArrow::draw (QPixmap &buffer, Scaler &scaler, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; int y = scaler.convertToY(getValue()); 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); painter.setBrush(getColor()); painter.drawPolygon(arrow, TRUE, 0, -1); clearSelectionArea(); setSelectionArea(new QRegion(arrow)); if (getStatus() == COBase::Selected) { clearGrabHandles(); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), y + 1, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), y + 1, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void VerticalLine::draw (QPixmap &buffer, Scaler &, int startIndex, int pixelspace, int startX) { QPainter painter; painter.begin(&buffer); int x2 = data->getX(date); if (x2 == -1) return; int x = startX + (x2 * pixelspace) - (startIndex * pixelspace); if (x == -1) return; painter.setPen(getColor()); painter.drawLine (x, 0, x, buffer.height()); clearSelectionArea(); Q3PointArray array; array.putPoints(0, 4, x - (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), 0, x + (HANDLE_WIDTH / 2), buffer.height(), x - (HANDLE_WIDTH / 2), buffer.height()); setSelectionArea(new QRegion(array)); if (getStatus() == COBase::Selected) { clearGrabHandles(); int t = (int) buffer.height() / 4; setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), 0, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 2, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 3, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(x - (HANDLE_WIDTH / 2), t * 4, HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }
void HorizontalLine::draw (QPixmap &buffer, Scaler &scaler, int, int, int) { QPainter painter; painter.begin(&buffer); painter.setFont(font); int y = scaler.convertToY(getValue()); // if value is off chart then don't draw it if (getValue() < scaler.getLow()) return; painter.setPen(getColor()); QFontMetrics fm(font); QString s; getText(s); int pixelsWide = fm.width(s); painter.drawLine (0, y, buffer.width(), y); painter.drawText(0, y - 1, s, -1); painter.drawText(0 + pixelsWide + 1, y - 1, QString::number(getValue()), -1); clearSelectionArea(); QPointArray array; array.putPoints(0, 4, 0, y - 4, 0, y + 4, buffer.width(), y + 4, buffer.width(), y - 4); setSelectionArea(new QRegion(array)); if (getStatus() == COBase::Selected) { clearGrabHandles(); int t = (int) buffer.width() / 4; setGrabHandle(new QRegion(0, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(0, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 2, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 2, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 3, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 3, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); setGrabHandle(new QRegion(t * 4, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, QRegion::Rectangle)); painter.fillRect(t * 4, y - (HANDLE_WIDTH / 2), HANDLE_WIDTH, HANDLE_WIDTH, getColor()); } painter.end(); }