1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4     Rosegarden
5     A MIDI and audio sequencer and musical notation editor.
6     Copyright 2000-2021 the Rosegarden development team.
7 
8     This file is Copyright 2003
9         Mark Hymers         <markh@linuxfromscratch.org>
10 
11     This program is free software; you can redistribute it and/or
12     modify it under the terms of the GNU General Public License as
13     published by the Free Software Foundation; either version 2 of the
14     License, or (at your option) any later version.  See the file
15     COPYING included with this distribution for more information.
16 */
17 
18 #ifndef RG_COLOURMAP_H
19 #define RG_COLOURMAP_H
20 
21 #include <QColor>
22 
23 #include <map>
24 #include <string>
25 
26 namespace Rosegarden
27 {
28 
29 
30 /// Maps a colour ID to a QColor and a name.
31 /**
32  * ??? Quite a bit of this is actually unused as there is no way to launch
33  *     the color table editor (ColourConfigurationPage).
34  */
35 class ColourMap
36 {
37 public:
38     /// Create a ColourMap with only the default segment colour.
39     ColourMap();
40 
41     static const QColor defaultSegmentColour;
42 
43     /**
44      * If the colourID isn't in the map, the routine returns the value of
45      * the default colour (at ID 0 in the table).  This means that if
46      * somehow some of the Segments get out of sync with the ColourMap and
47      * have invalid colour values, they'll be set to the Composition default
48      * colour.
49      */
50     QColor getColour(unsigned colourID) const;
51 
52     /**
53      * If the colourID isn't in the map, the name of the entry at ID 0 is
54      * returned.  Usually this is "", for internationalization reasons.
55      */
56     std::string getName(unsigned colourID) const;
57 
58     /// For RosegardenDocument.
59     std::string toXmlString(std::string name) const;
60 
61 
62     // *** Data
63 
64     struct Entry
65     {
EntryEntry66         Entry() :
67             colour(defaultSegmentColour),
68             name()
69         {
70         }
71 
EntryEntry72         Entry(const QColor &i_colour, const std::string &i_name) :
73             colour(i_colour),
74             name(i_name)
75         {
76         }
77 
78         QColor colour;
79         std::string name;
80     };
81 
82     typedef std::map<unsigned /* colourID */, Entry> MapType;
83     // Note: Use the helper functions above (and below) if possible.
84     MapType colours;
85 
86 
87     // *** Interface for ColourConfigurationPage.
88 
89     // These functions are essentially unused as there is no way to
90     // launch the ColourConfigurationPage.
91 
92     /// Add a colour entry using the lowest available ID.
93     void addEntry(QColor colour, std::string name);
94     void modifyName(unsigned colourID, std::string name);
95     void modifyColour(unsigned colourID, QColor colour);
96     void deleteEntry(unsigned colourID);
97 
98 };
99 
100 
101 }
102 
103 #endif
104