コード例 #1
0
  @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);
  }