Editor: Do int to color conversion in ColorEditor

0.6.1
Rob Cutmore 8 years ago
parent 3fb7c42845
commit c7241c692f

@ -10,9 +10,20 @@
#include "colorpickerpopup.hpp"
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, bool popupOnStart)
CSVWidget::ColorEditor::ColorEditor(const QColor &color, QWidget *parent, const bool popupOnStart)
: ColorEditor(parent, popupOnStart)
{
setColor(color);
}
CSVWidget::ColorEditor::ColorEditor(const int colorInt, QWidget *parent, const bool popupOnStart)
: ColorEditor(parent, popupOnStart)
{
setColor(colorInt);
}
CSVWidget::ColorEditor::ColorEditor(QWidget *parent, const bool popupOnStart)
: QPushButton(parent),
mColor(color),
mColorPicker(new ColorPickerPopup(this)),
mPopupOnStart(popupOnStart)
{
@ -59,6 +70,14 @@ void CSVWidget::ColorEditor::setColor(const QColor &color)
update();
}
void CSVWidget::ColorEditor::setColor(const int colorInt)
{
// Color RGB values are stored in given integer.
// First byte is red, second byte is green, third byte is blue.
QColor color = QColor(colorInt & 0xff, (colorInt >> 8) & 0xff, (colorInt >> 16) & 0xff);
setColor(color);
}
void CSVWidget::ColorEditor::showPicker()
{
if (isChecked())

@ -22,15 +22,23 @@ namespace CSVWidget
QPoint calculatePopupPosition();
public:
ColorEditor(const QColor &color, QWidget *parent = 0, bool popupOnStart = false);
ColorEditor(const QColor &color, QWidget *parent = 0, const bool popupOnStart = false);
ColorEditor(const int colorInt, QWidget *parent = 0, const bool popupOnStart = false);
QColor color() const;
void setColor(const QColor &color);
/// \brief Set color using given int value.
/// \param colorInt RGB color value encoded as an integer.
void setColor(const int colorInt);
protected:
virtual void paintEvent(QPaintEvent *event);
virtual void showEvent(QShowEvent *event);
private:
ColorEditor(QWidget *parent = 0, const bool popupOnStart = false);
private slots:
void showPicker();
void pickerHid();

@ -181,9 +181,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
// (the third parameter of ColorEditor's constructor)
else if (display == CSMWorld::ColumnBase::Display_Colour)
{
int colorInt = index.data().toInt();
QColor color = QColor(colorInt & 0xff, (colorInt >> 8) & 0xff, (colorInt >> 16) & 0xff);
return new CSVWidget::ColorEditor(color, parent, true);
return new CSVWidget::ColorEditor(index.data().toInt(), parent, true);
}
return createEditor (parent, option, index, display);
}
@ -207,9 +205,7 @@ QWidget *CSVWorld::CommandDelegate::createEditor (QWidget *parent, const QStyleO
{
case CSMWorld::ColumnBase::Display_Colour:
{
int colorInt = variant.toInt();
QColor color = QColor(colorInt & 0xff, (colorInt >> 8) & 0xff, (colorInt >> 16) & 0xff);
return new CSVWidget::ColorEditor(color, parent);
return new CSVWidget::ColorEditor(variant.toInt(), parent);
}
case CSMWorld::ColumnBase::Display_Integer:
{
@ -322,9 +318,7 @@ void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelInde
CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor);
if (colorEditor != NULL)
{
int colorInt = variant.toInt();
QColor color = QColor(colorInt & 0xff, (colorInt >> 8) & 0xff, (colorInt >> 16) & 0xff);
colorEditor->setColor(color);
colorEditor->setColor(variant.toInt());
return;
}

Loading…
Cancel
Save