コード例 #1
0
ファイル: Burning.java プロジェクト: ibre5041/PBM
  protected void drawWidget(QPainter painter) {

    BurningApp burn = (BurningApp) parent;

    float width = size().width();
    float slid_width = burn.getCurrentWidth();
    float step = width / DIVISIONS;

    float till = (width / MAX_CAPACITY) * slid_width;
    float full = (width / MAX_CAPACITY) * FULL_CAPACITY;

    if (slid_width > FULL_CAPACITY) {

      painter.setPen(yellowColor);
      painter.setBrush(yellowColor);
      painter.drawRect(new QRectF(0, 0, full, PANEL_HEIGHT));
      painter.setPen(redColor);
      painter.setBrush(redColor);
      painter.drawRect(new QRectF(full + 1, 0, till - full, PANEL_HEIGHT));

    } else {
      if (slid_width > 0) {
        painter.setPen(yellowColor);
        painter.setBrush(yellowColor);
        painter.drawRect(new QRectF(0, 0, till, PANEL_HEIGHT));
      }
    }

    painter.setPen(new QColor(90, 90, 90));
    painter.setBrush(QBrush.NoBrush);
    painter.drawRect(0, 0, size().width() - 1, PANEL_HEIGHT - 1);

    QFont newFont = font();
    newFont.setPointSize(7);
    painter.setFont(newFont);

    for (int i = 1; i <= num.length; i++) {
      painter.drawLine(new QLineF(i * step, 1, i * step, LINE_WIDTH));

      QFontMetrics metrics = new QFontMetrics(newFont);

      int w = metrics.width(num[i - 1]);
      painter.drawText(new QPointF(i * step - w / 2, DISTANCE), num[i - 1]);
    }
  }
コード例 #2
0
    private void drawLineTo(QPoint endPoint) {
      QPainter painter = new QPainter(image);
      painter.setPen(
          new QPen(
              myPenColor,
              myPenWidth,
              Qt.PenStyle.SolidLine,
              Qt.PenCapStyle.RoundCap,
              Qt.PenJoinStyle.RoundJoin));
      painter.drawLine(lastPoint, endPoint);
      modified = true;

      int rad = (myPenWidth / 2) + 2;
      update(new QRect(lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad));
      lastPoint = endPoint;

      painter.end();
    }