1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 /*
3     Rosegarden
4     A MIDI and audio sequencer and musical notation editor.
5     Copyright 2000-2021 the Rosegarden development team.
6 
7     Other copyrights also apply to some parts of this work.  Please
8     see the AUTHORS file and individual file headers for details.
9 
10     This program is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License as
12     published by the Free Software Foundation; either version 2 of the
13     License, or (at your option) any later version.  See the file
14     COPYING included with this distribution for more information.
15 */
16 
17 #define RG_MODULE_STRING "[ColorCombo]"
18 
19 #include "ColorCombo.h"
20 
21 #include "base/ColourMap.h"
22 #include "base/Composition.h"
23 #include "gui/general/GUIPalette.h"
24 #include "document/RosegardenDocument.h"
25 #include "gui/application/RosegardenMainWindow.h"
26 
27 #include "misc/Debug.h"
28 
29 #include <QPixmap>
30 #include <QString>
31 
32 namespace Rosegarden
33 {
34 
35 
36 ColorCombo::ColorCombo(QWidget *parent) :
37     QComboBox(parent)
38 {
39     setEditable(false);
40     setMaxVisibleItems(20);
41 }
42 
43 void
44 ColorCombo::updateColors()
45 {
46     // The color combobox is handled differently from the others.  Since
47     // there are 420 strings of up to 25 chars in here, it would be
48     // expensive to detect changes by comparing vectors of strings.
49 
50     // For now, we'll handle the document colors changed notification
51     // and reload the combobox then.
52 
53     // See the comments on RosegardenDocument::docColoursChanged()
54     // in RosegardenDocument.h.
55 
56     // Note that as of this writing (June 2019) there is no way
57     // to modify the document colors.  See ColourConfigurationPage
58     // which was probably meant to be used by DocumentConfigureDialog.
59     // See TrackParameterBox::slotDocColoursChanged().
60 
61     clear();
62 
63     RosegardenDocument *doc = RosegardenMainWindow::self()->getDocument();
64     if (!doc)
65         return;
66 
67     // Populate it from Composition::m_segmentColourMap
68     ColourMap temp = doc->getComposition().getSegmentColourMap();
69 
70     // For each color in the segment color map
71     for (ColourMap::MapType::const_iterator colourIter = temp.colours.begin();
72          colourIter != temp.colours.end();
73          ++colourIter) {
74         // Wrap in a tr() call in case the color is on the list of translated
75         // color names we're including since 09.10.
76         QString colourName(QObject::tr(colourIter->second.name.c_str()));
77 
78         QPixmap colourIcon(15, 15);
79         colourIcon.fill(colourIter->second.colour);
80 
81         if (colourName == "") {
82             addItem(colourIcon, tr("Default"));
83         } else {
84             // truncate name to 25 characters to avoid the combo forcing the
85             // whole kit and kaboodle too wide (This expands from 15 because the
86             // translators wrote books instead of copying the style of
87             // TheShortEnglishNames, and because we have that much room to
88             // spare.)
89             if (colourName.length() > 25)
90                 colourName = colourName.left(22) + "...";
91 
92             addItem(colourIcon, colourName);
93         }
94     }
95 
96 #if 0
97 // Removing this since it has never been in there.
98     m_color->addItem(tr("Add New Color"));
99     m_addColourPos = m_color->count() - 1;
100 #endif
101 
102 }
103 
104 
105 }
106