Chris@1196: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1196: Chris@1196: /* Chris@1196: Sonic Visualiser Chris@1196: An audio file viewer and annotation editor. Chris@1196: Centre for Digital Music, Queen Mary, University of London. Chris@1196: This file copyright 2007-2016 QMUL. Chris@1196: Chris@1196: This program is free software; you can redistribute it and/or Chris@1196: modify it under the terms of the GNU General Public License as Chris@1196: published by the Free Software Foundation; either version 2 of the Chris@1196: License, or (at your option) any later version. See the file Chris@1196: COPYING included with this distribution for more information. Chris@1196: */ Chris@1196: Chris@1196: #ifndef SV_COLOUR_COMBO_BOX_H Chris@1196: #define SV_COLOUR_COMBO_BOX_H Chris@1196: Chris@1196: #include "NotifyingComboBox.h" Chris@1196: Chris@1196: /** Chris@1196: * Colour-picker combo box with swatches, optionally including "Add Chris@1196: * New Colour..." entry to invoke a QColorDialog/ColourNameDialog Chris@1196: */ Chris@1196: class ColourComboBox : public NotifyingComboBox Chris@1196: { Chris@1196: Q_OBJECT Chris@1196: Chris@1196: public: Chris@1196: ColourComboBox(bool withAddNewColourEntry, QWidget *parent = 0); Chris@1196: Chris@1579: /** Chris@1579: * Add an entry at the top of the combo for "no colour selected", Chris@1579: * with the given label. Chris@1579: */ Chris@1579: void includeUnsetEntry(QString label); Chris@1579: Chris@1579: /** Chris@1579: * Get the current colour index. This is the same as Chris@1579: * QComboBox::currentIndex() if there is no unset entry, or 1 less Chris@1579: * than it if includeUnsetEntry() has been used. So if there is an Chris@1579: * unset entry, and it is selected, this returns -1. Chris@1579: */ Chris@1579: int getCurrentColourIndex() const { Chris@1579: int index = currentIndex(); Chris@1579: if (m_unsetEntry == "") { Chris@1579: return index; Chris@1579: } else { Chris@1579: return index - 1; Chris@1579: } Chris@1579: } Chris@1579: Chris@1196: signals: Chris@1579: /** Chris@1579: * Emitted when the current index is changed. The argument is the Chris@1579: * value returned by getCurrentColourIndex() Chris@1579: */ Chris@1196: void colourChanged(int colourIndex); Chris@1196: Chris@1196: private slots: Chris@1196: void rebuild(); Chris@1196: void comboActivated(int); Chris@1196: Chris@1196: private: Chris@1196: bool m_withAddNewColourEntry; Chris@1579: QString m_unsetEntry; Chris@1196: }; Chris@1196: Chris@1196: #endif Chris@1196: