annotate layer/ColourMapper.h @ 1413:0930a27ebea2

Support changing the separator (if more than one plausible one is found) and repopulating the dialog
author Chris Cannam
date Wed, 09 Jan 2019 14:41:52 +0000
parents d79e21855aef
children
rev   line source
Chris@376 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@376 2
Chris@376 3 /*
Chris@376 4 Sonic Visualiser
Chris@376 5 An audio file viewer and annotation editor.
Chris@376 6 Centre for Digital Music, Queen Mary, University of London.
Chris@376 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@376 8
Chris@376 9 This program is free software; you can redistribute it and/or
Chris@376 10 modify it under the terms of the GNU General Public License as
Chris@376 11 published by the Free Software Foundation; either version 2 of the
Chris@376 12 License, or (at your option) any later version. See the file
Chris@376 13 COPYING included with this distribution for more information.
Chris@376 14 */
Chris@376 15
Chris@1199 16 #ifndef SV_COLOUR_MAPPER_H
Chris@1199 17 #define SV_COLOUR_MAPPER_H
Chris@376 18
Chris@376 19 #include <QObject>
Chris@376 20 #include <QColor>
Chris@376 21 #include <QString>
Chris@1199 22 #include <QPixmap>
Chris@376 23
Chris@376 24 /**
Chris@376 25 * A class for mapping intensity values onto various colour maps.
Chris@376 26 */
Chris@1071 27 class ColourMapper
Chris@376 28 {
Chris@376 29 public:
Chris@1362 30 ColourMapper(int map,
Chris@1362 31 bool inverted,
Chris@1362 32 double minValue,
Chris@1362 33 double maxValue);
Chris@1071 34 ~ColourMapper();
Chris@1071 35
Chris@1362 36 ColourMapper(const ColourMapper &) =default;
Chris@1362 37 ColourMapper &operator=(const ColourMapper &) =default;
Chris@376 38
Chris@1362 39 enum ColourMap {
Chris@1017 40 Green,
Chris@376 41 Sunset,
Chris@376 42 WhiteOnBlack,
Chris@376 43 BlackOnWhite,
Chris@1017 44 Cherry,
Chris@1017 45 Wasp,
Chris@1017 46 Ice,
Chris@376 47 FruitSalad,
Chris@376 48 Banded,
Chris@376 49 Highlight,
Chris@536 50 Printer,
Chris@1362 51 HighGain,
Chris@1362 52 BlueOnBlack,
Chris@1362 53 Cividis,
Chris@1362 54 Magma
Chris@376 55 };
Chris@376 56
Chris@376 57 int getMap() const { return m_map; }
Chris@1362 58 bool isInverted() const { return m_inverted; }
Chris@902 59 double getMinValue() const { return m_min; }
Chris@902 60 double getMaxValue() const { return m_max; }
Chris@376 61
Chris@1362 62 /**
Chris@1362 63 * Return the number of known colour maps.
Chris@1362 64 */
Chris@376 65 static int getColourMapCount();
Chris@376 66
Chris@1362 67 /**
Chris@1362 68 * Return a human-readable label for the colour map with the given
Chris@1362 69 * index. This may have been subject to translation.
Chris@1362 70 */
Chris@1362 71 static QString getColourMapLabel(int n);
Chris@1362 72
Chris@1362 73 /**
Chris@1362 74 * Return a machine-readable id string for the colour map with the
Chris@1362 75 * given index. This is not translated and is intended for use in
Chris@1362 76 * file I/O.
Chris@1362 77 */
Chris@1362 78 static QString getColourMapId(int n);
Chris@1362 79
Chris@1362 80 /**
Chris@1362 81 * Return the index for the colour map with the given
Chris@1362 82 * machine-readable id string, or -1 if the id is not recognised.
Chris@1362 83 */
Chris@1362 84 static int getColourMapById(QString id);
Chris@1362 85
Chris@1362 86 /**
Chris@1362 87 * Older versions of colour-handling code save and reload colour
Chris@1362 88 * maps by numerical index and can't properly handle situations in
Chris@1362 89 * which the index order changes between releases, or new indices
Chris@1362 90 * are added. So when we save a colour map by id, we should also
Chris@1362 91 * save a compatibility value that can be re-read by such
Chris@1362 92 * code. This value is an index into the series of colours used by
Chris@1362 93 * pre-3.2 SV code, namely (Default/Green, Sunset, WhiteOnBlack,
Chris@1362 94 * BlackOnWhite, RedOnBlue, YellowOnBlack, BlueOnBlack,
Chris@1362 95 * FruitSalad, Banded, Highlight, Printer, HighGain). It should
Chris@1362 96 * represent the closest equivalent to the current colour scheme
Chris@1362 97 * available in that set. This function returns that index.
Chris@1362 98 */
Chris@1362 99 static int getBackwardCompatibilityColourMap(int n);
Chris@1362 100
Chris@1362 101 /**
Chris@1362 102 * Map the given value to a colour. The value will be clamped to
Chris@1362 103 * the range minValue to maxValue (where both are drawn from the
Chris@1362 104 * constructor arguments).
Chris@1362 105 */
Chris@902 106 QColor map(double value) const;
Chris@376 107
Chris@1362 108 /**
Chris@1362 109 * Return a colour that contrasts somewhat with the colours in the
Chris@1362 110 * map, so as to be used for cursors etc.
Chris@1362 111 */
Chris@1362 112 QColor getContrastingColour() const;
Chris@1362 113
Chris@1362 114 /**
Chris@1362 115 * Return true if the colour map is intended to be placed over a
Chris@1362 116 * light background, false otherwise. This is typically true if
Chris@1362 117 * the colours corresponding to higher values are darker than
Chris@1362 118 * those corresponding to lower values.
Chris@1362 119 */
Chris@376 120 bool hasLightBackground() const;
Chris@376 121
Chris@1362 122 /**
Chris@1362 123 * Return a pixmap of the given size containing a preview swatch
Chris@1362 124 * for the colour map.
Chris@1362 125 */
Chris@1199 126 QPixmap getExamplePixmap(QSize size) const;
Chris@1199 127
Chris@376 128 protected:
Chris@376 129 int m_map;
Chris@1362 130 bool m_inverted;
Chris@902 131 double m_min;
Chris@902 132 double m_max;
Chris@376 133 };
Chris@376 134
Chris@376 135 #endif
Chris@376 136