comparison widgets/ColourComboBox.cpp @ 1580:a2ff9c01889e

Merge from branch background-mode
author Chris Cannam
date Fri, 24 Jan 2020 15:11:08 +0000
parents 85f04c956f03
children
comparison
equal deleted inserted replaced
1572:5f6fdd525158 1580:a2ff9c01889e
36 rebuild(); 36 rebuild();
37 37
38 connect(this, SIGNAL(activated(int)), this, SLOT(comboActivated(int))); 38 connect(this, SIGNAL(activated(int)), this, SLOT(comboActivated(int)));
39 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()), 39 connect(ColourDatabase::getInstance(), SIGNAL(colourDatabaseChanged()),
40 this, SLOT(rebuild())); 40 this, SLOT(rebuild()));
41
42 if (count() < 20 && count() > maxVisibleItems()) {
43 setMaxVisibleItems(count());
44 }
45 } 41 }
46 42
47 void 43 void
48 ColourComboBox::comboActivated(int index) 44 ColourComboBox::includeUnsetEntry(QString entry)
49 { 45 {
46 m_unsetEntry = entry;
47
48 rebuild();
49
50 blockSignals(true);
51 int ix = currentIndex();
52 setCurrentIndex(ix + 1);
53 blockSignals(false);
54 }
55
56 void
57 ColourComboBox::comboActivated(int comboIndex)
58 {
59 int index = comboIndex;
60 if (m_unsetEntry != "") {
61 index = comboIndex - 1; // so index is the colour index
62 }
63
50 if (!m_withAddNewColourEntry || 64 if (!m_withAddNewColourEntry ||
51 index < int(ColourDatabase::getInstance()->getColourCount())) { 65 index < int(ColourDatabase::getInstance()->getColourCount())) {
52 emit colourChanged(index); 66 emit colourChanged(index);
53 return; 67 return;
54 } 68 }
79 93
80 int ix = currentIndex(); 94 int ix = currentIndex();
81 95
82 clear(); 96 clear();
83 97
98 if (m_unsetEntry != "") {
99 addItem(m_unsetEntry);
100 }
101
84 int size = (QFontMetrics(QFont()).height() * 2) / 3; 102 int size = (QFontMetrics(QFont()).height() * 2) / 3;
85 if (size < 12) size = 12; 103 if (size < 12) size = 12;
86 104
87 ColourDatabase *db = ColourDatabase::getInstance(); 105 ColourDatabase *db = ColourDatabase::getInstance();
88 for (int i = 0; i < db->getColourCount(); ++i) { 106 for (int i = 0; i < db->getColourCount(); ++i) {
93 if (m_withAddNewColourEntry) { 111 if (m_withAddNewColourEntry) {
94 addItem(tr("Add New Colour...")); 112 addItem(tr("Add New Colour..."));
95 } 113 }
96 114
97 setCurrentIndex(ix); 115 setCurrentIndex(ix);
116
117 if (count() < 18) {
118 setMaxVisibleItems(count());
119 } else {
120 setMaxVisibleItems(10);
121 }
98 122
99 blockSignals(false); 123 blockSignals(false);
100 } 124 }
101 125