Example #1
0
const QVector<int> Q3PlotAxis::tickPositions() const
{
    QVector<int> tickPositions(ticks_.count());
    for (int i = 0; i < ticks_.count(); ++i) {
        tickPositions[i] = coordinateToPixel(ticks_[i]);
    }
    return tickPositions;
}
Example #2
0
void Q3PlotAxis::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);

    QPainter painter;
    painter.begin(this);
    painter.setPen(Qt::white);

    QFontMetrics fm(font());
    QVector<int> tp = tickPositions();
    int margin = Q3PlotFrameContainer::Margin;

    switch (position_) {
    case Q3PlotFrame::PositionLeft:
        if (labelsVisible_) {
            for (int i = 0; i < ticks_.count(); ++i) {
                if (tp[i] + margin - fm.height() / 3. < 0
                        || tp[i] + margin + fm.height() / 3. > height()) {
                    continue;
                }
                painter.drawText(QPointF(width() - margin - fm.width(labels_[i]) - 1,
                                         tp[i] + margin + fm.height() / 3),
                                 labels_[i]);
            }
        }
        break;
    case Q3PlotFrame::PositionTop:
        if (labelsVisible_) {
            for (int i = 0; i < ticks_.count(); ++i) {
                if (tp[i] + margin - fm.width(labels_[i]) / 2 < 0
                        || tp[i] + margin + fm.width(labels_[i]) / 2 > width()) {
                    continue;
                }
                painter.drawText(QPointF(tp[i] + margin - fm.width(labels_[i]) / 2,
                                         height() - margin - 1), labels_[i]);
            }
        }
        break;
    case Q3PlotFrame::PositionRight:
        if (labelsVisible_) {
            for (int i = 0; i < ticks_.count(); ++i) {
                if (tp[i] + margin - fm.height() / 3. < 0
                        || tp[i] + margin + fm.height() / 3. > height()) {
                    continue;
                }
                painter.drawText(QPointF(margin, tp[i] + margin + fm.height() / 3),
                                 labels_[i]);
            }
        }
        break;
    case Q3PlotFrame::PositionBottom:
        if (labelsVisible_) {
            for (int i = 0; i < ticks_.count(); ++i) {
                if (tp[i] + margin - fm.width(labels_[i]) / 2 < 0
                        || tp[i] + margin + fm.width(labels_[i]) / 2 > width()) {
                    continue;
                }
                painter.drawText(QPointF(tp[i] + margin - fm.width(labels_[i]) / 2,
                                         margin + 2. / 3. * fm.height()), labels_[i]);
            }
        }
        break;
    }

    painter.end();
}
Example #3
0
double MSLabelOut::tickPosition(unsigned index_) const
{
  int len=tickPositions().length();
  return tickPositions()(index_<len?index_:index_%len);
}