Exemplo n.º 1
0
  private static QImage makeShade(QImage image, boolean highlight, boolean darker) {
    double shade_alpha = 0.8;
    double shade_size = 0.2;
    double hl_pos = GOLDEN_MEAN;

    QColor shade_color = QColor.fromRgbF(0, 0, 0, shade_alpha);
    QColor transparent = darker ? QColor.fromRgbF(0, 0, 0, 0.25) : QColor.fromRgbF(0, 0, 0, 0);
    QColor hl_color = QColor.fromRgbF(1, 1, 1, 0.7);

    image = image.copy();
    QPainter p = new QPainter();
    p.begin(image);
    p.scale(image.width(), image.height());

    QLinearGradient lg = new QLinearGradient(0, 0, 1, 0);
    lg.setColorAt(0, shade_color);
    lg.setColorAt(shade_size, transparent);
    if (highlight) lg.setColorAt(hl_pos, hl_color);
    lg.setColorAt(1 - shade_size, transparent);
    lg.setColorAt(1, shade_color);
    p.fillRect(0, 0, 1, 1, new QBrush(lg));

    if (highlight) {
      QRadialGradient rg = new QRadialGradient(hl_pos, 1 - hl_pos, 0.4, hl_pos, 1 - hl_pos);
      rg.setColorAt(0, hl_color);
      rg.setColorAt(1, transparent);
      p.fillRect(0, 0, 1, 1, new QBrush(rg));
    }

    p.end();

    return image;
  }
Exemplo n.º 2
0
  @Override
  protected void paintEvent(QPaintEvent e) {
    m_smoke_effect.next();

    QPainter p = new QPainter();
    p.begin(this);
    p.fillRect(rect(), new QBrush(QColor.white));
    //  p.fillRect(rect(), new QBrush(Qt.CrossPattern));

    p.drawImage(50, 80, m_logo);

    p.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform);
    QImage im = m_smoke_effect.image();
    p.drawImage(
        new QRect(50, -20, im.width(), im.height()),
        im,
        new QRect(0, (int) (im.height() * 0.60), im.width(), (int) (im.height() * 0.39)));

    p.end();
  }
  @Override
  public void paint(QPainter painter, QStyleOptionViewItem option, QModelIndex index) {
    // if (log.isTraceEnabled())
    // log.trace("paint(): index=" + index + ", option.palette().highlight()=" +
    // option.palette().highlight());
    Object data = index.data();
    QModelIndex sourceIndex = modelManager.getProxyModel().mapToSource(index);
    SongRecord songRecord =
        (SongRecord) ((RecordTableModelManager) modelManager).getRecordForRow(sourceIndex.row());
    if (ProfileWidgetUI.instance.getCurrentProfile() instanceof SongProfile) {
      SongProfile relativeProfile = (SongProfile) ProfileWidgetUI.instance.getCurrentProfile();
      QStyle.State state = option.state();
      if (RE3Properties.getBoolean("highlight_broken_file_links")) {
        if (modelManager instanceof RecordTableModelManager) {
          SearchRecord searchRecord =
              (SearchRecord)
                  ((RecordTableModelManager) modelManager).getRecordForRow(sourceIndex.row());
          if (searchRecord instanceof SongRecord) {
            SongRecord song = (SongRecord) searchRecord;
            if (!song.isExternalItem() && !song.hasValidSongFilename()) {
              if (!state.isSet(QStyle.StateFlag.State_Selected)) {
                state.set(QStyle.StateFlag.State_Selected);
                option.setState(state);
                QPalette p = option.palette();
                p.setColor(QPalette.ColorRole.Highlight, BROKEN_FILELINKS_COLOR.getQColor());
                option.setPalette(p);
              }
            }
          }
        }
      }
      if (relativeProfile != null) {
        boolean isMixout = false;
        float mixoutRating = 0.0f;
        for (MixoutRecord mixout : relativeProfile.getMixouts()) {
          if (mixout.getToSongUniqueId() == songRecord.getUniqueId()) {
            isMixout = true;
            mixoutRating = mixout.getRatingValue().getRatingNormalized();
            break;
          }
        }
        if (isMixout && !(parent instanceof MixoutTableWidget)) {
          if (!option.state().isSet(QStyle.StateFlag.State_Selected)) {
            mixoutRating = 0.75f * mixoutRating + 0.25f;
            Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base));
            painter.fillRect(
                option.rect(), mixoutColor.getLinearGradient(baseColor, mixoutRating).getQColor());
          }
        } else {
          // target bpm/key/time sig
          Bpm targetBpm = ProfileWidgetUI.instance.getStageWidget().getCurrentBpm();
          if (!targetBpm.isValid()) targetBpm = relativeProfile.getBpmEnd();
          if (!targetBpm.isValid()) targetBpm = relativeProfile.getBpmStart();
          Key targetKey = ProfileWidgetUI.instance.getStageWidget().getCurrentKey();
          if (!targetKey.isValid()) targetKey = relativeProfile.getEndKey();
          if (!targetKey.isValid()) targetKey = relativeProfile.getStartKey();

          if (parent instanceof CompatibleSongTableWidget) {
            CompatibleSongTableWidget compatibleWidget = (CompatibleSongTableWidget) parent;
            if ((compatibleWidget.getShowType()
                    == CompatibleSongTableWidget.COMPATIBLE_TYPE_ALL_HARMONIC)
                || (compatibleWidget.getShowType()
                    == CompatibleSongTableWidget.COMPATIBLE_TYPE_BPM_ONLY)) {
              SongKeyRelation keyRelation =
                  SongKeyRelation.getSongKeyRelation(songRecord, targetBpm, targetKey);
              if (keyRelation.isCompatible()) {
                float percentInKey =
                    (0.5f - Math.abs(keyRelation.getBestKeyRelation().getDifference())) * 2.0f;
                if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey);
                if (!option.state().isSet(QStyle.StateFlag.State_Selected)) {
                  Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base));
                  painter.fillRect(
                      option.rect(),
                      harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor());
                }
              }
            } else if (compatibleWidget.getShowType()
                == CompatibleSongTableWidget.COMPATIBLE_TYPE_KEYLOCK_ONLY) {
              KeyRelation keyRelation =
                  Key.getClosestKeyRelation(
                      targetBpm.getBpmValue(),
                      songRecord.getStartKey(),
                      targetBpm.getBpmValue(),
                      targetKey);
              if (keyRelation.isCompatible()) {
                float percentInKey = (0.5f - Math.abs(keyRelation.getDifference())) * 2.0f;
                if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey);
                if (!option.state().isSet(QStyle.StateFlag.State_Selected)) {
                  Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base));
                  painter.fillRect(
                      option.rect(),
                      harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor());
                }
              }
            } else if (compatibleWidget.getShowType()
                == CompatibleSongTableWidget.COMPATIBLE_TYPE_NO_KEYLOCK) {
              KeyRelation keyRelation =
                  Key.getClosestKeyRelation(
                      songRecord.getStartBpm(),
                      songRecord.getStartKey(),
                      targetBpm.getBpmValue(),
                      targetKey);
              if (keyRelation.isCompatible()) {
                float percentInKey = (0.5f - Math.abs(keyRelation.getDifference())) * 2.0f;
                if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey);
                if (!option.state().isSet(QStyle.StateFlag.State_Selected)) {
                  Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base));
                  painter.fillRect(
                      option.rect(),
                      harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor());
                }
              }
            }
          } else {
            if (RE3Properties.getBoolean("enable_harmonic_coloring_in_search_table")
                && CentralWidgetUI.instance.isDetailsTabOpen()) {
              SongKeyRelation keyRelation =
                  SongKeyRelation.getSongKeyRelation(songRecord, targetBpm, targetKey);
              if (keyRelation.isCompatible()) {
                float percentInKey =
                    (0.5f - Math.abs(keyRelation.getBestKeyRelation().getDifference())) * 2.0f;
                if (log.isTraceEnabled()) log.trace("paint(): percentInKey=" + percentInKey);
                if (!option.state().isSet(QStyle.StateFlag.State_Selected)) {
                  Color baseColor = new Color(option.palette().color(QPalette.ColorRole.Base));
                  painter.fillRect(
                      option.rect(),
                      harmonicMatchColor.getLinearGradient(baseColor, percentInKey).getQColor());
                }
              }
            }
          }
        }
      }
    }
    super.paint(painter, option, index);
  }