RioEngine  0.1
My first attempt to create a 3D WYSIWYG Game Engine
colorcombo.cpp
Go to the documentation of this file.
1 // *************************************************************************************************
2 //
3 // QPropertyEditor v 0.3
4 //
5 // --------------------------------------
6 // Copyright (C) 2007 Volker Wiendl
7 // Acknowledgements to Roman alias banal from qt-apps.org for the Enum enhancement
8 //
9 //
10 // The QPropertyEditor Library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation version 3 of the License
13 //
14 // The Horde3D Scene Editor is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 //
22 // *************************************************************************************************
23 
24 #include "ColorCombo.h"
25 
26 #include <QtWidgets/QColorDialog>
27 
28 ColorCombo::ColorCombo(QWidget* parent /*= 0*/) : QComboBox(parent)
29 {
30  QStringList colorNames = QColor::colorNames();
31  for (int i = 0; i < colorNames.size(); ++i) {
32  QColor color(colorNames[i]);
33  insertItem(i, colorNames[i]);
34  setItemData(i, color, Qt::DecorationRole);
35  }
36  addItem(tr("Custom"), QVariant((int)QVariant::UserType));
37  connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(currentChanged(int)));
38 }
39 
40 
42 {
43 }
44 
45 
46 QColor ColorCombo::color() const
47 {
48  return QColor();
49  //return qVariantValue<QColor>(itemData(currentIndex(), Qt::DecorationRole));
50  //return currentIndex().
51 }
52 
53 void ColorCombo::setColor(QColor color)
54 {
55  m_init = color;
56  setCurrentIndex(findData(color, int(Qt::DecorationRole)));
57  if (currentIndex() == -1)
58  {
59  addItem(color.name());
60  setItemData(count()-1, color, Qt::DecorationRole);
61  setCurrentIndex(count()-1);
62  }
63 }
64 
65 void ColorCombo::currentChanged(int index)
66 {
67  if (itemData(index).isValid() && itemData(index) == QVariant((int)QVariant::UserType))
68  {
69  QColor color = QColorDialog::getColor(m_init, this);
70  if (color.isValid())
71  {
72  if (findData(color, int(Qt::DecorationRole)) == -1)
73  {
74  addItem(color.name());
75  setItemData(count()-1, color, Qt::DecorationRole);
76  }
77  setCurrentIndex(findData(color, int(Qt::DecorationRole)));
78  }
79  else
80  setCurrentIndex(findData(m_init));
81  }
82 }
virtual ~ColorCombo()
Definition: colorcombo.cpp:41
QColor color() const
Definition: colorcombo.cpp:46
void setColor(QColor c)
Definition: colorcombo.cpp:53
ColorCombo(QWidget *parent=0)
Definition: colorcombo.cpp:28