Use QColor in ColorNode.

This commit is contained in:
Jim Evins
2013-10-17 22:47:08 -04:00
parent 27e791212d
commit e7cbf8d8a3
6 changed files with 16 additions and 192 deletions
-1
View File
@@ -5,7 +5,6 @@ project (app CXX)
set (qtlabels_sources set (qtlabels_sources
qtlabels_main.cpp qtlabels_main.cpp
BarcodeStyle.cpp BarcodeStyle.cpp
Color.cpp
ColorNode.cpp ColorNode.cpp
LabelModel.cpp LabelModel.cpp
LabelModelItem.cpp LabelModelItem.cpp
-21
View File
@@ -1,21 +0,0 @@
/* Color.cpp
*
* Copyright (C) 2011 Jim Evins <evins@snaught.com>
*
* This file is part of qtLabels.
*
* qtLabels is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qtLabels is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qtLabels. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Color.h"
-153
View File
@@ -1,153 +0,0 @@
/* Color.h
*
* Copyright (C) 2011 Jim Evins <evins@snaught.com>
*
* This file is part of qtLabels.
*
* qtLabels is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* qtLabels is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with qtLabels. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef qtlabels_Color_h
#define qtlabels_Color_h
#include <stdint.h>
namespace qtLabels
{
class Color
{
public:
/* double RGBA Constructor */
Color( double r = 0, double g = 0, double b = 0, double a = 1 )
: m_r(r), m_g(g), m_b(b), m_a(a)
{
}
static Color from_byte_rgba( uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255 )
{
return Color( r/255.0, g/255.0, b/255.0, a/255.0 );
}
static Color from_legacy_color( uint32_t c )
{
return Color( ((c>>24) & 0xff) / 255.0,
((c>>16) & 0xff) / 255.0,
((c>>8) & 0xff) / 255.0,
((c) & 0xff) / 255.0 );
}
static Color none()
{
return Color( 0, 0, 0, 0 );
}
static Color black()
{
return Color( 0, 0, 0, 1 );
}
static Color white()
{
return Color( 1, 1, 1, 1 );
}
/* Muliply by opacity. Create new color by applying opacity. */
Color operator*( double opacity ) const
{
return Color( m_r, m_g, m_b, m_a * opacity );
}
uint32_t to_legacy_color()
{
uint32_t c = (((uint32_t)(m_r*255) & 0xff) << 24) |
(((uint32_t)(m_g*255) & 0xff) << 16) |
(((uint32_t)(m_b*255) & 0xff) << 8) |
(((uint32_t)(m_a*255) & 0xff));
return c;
}
bool operator==( const Color &c )
{
return ( (m_r == c.m_r) &&
(m_g == c.m_g) &&
(m_b == c.m_b) &&
(m_a == c.m_a) );
}
bool operator!=( const Color &c )
{
return ( (m_r != c.m_r) ||
(m_g != c.m_g) ||
(m_b != c.m_b) ||
(m_a != c.m_a) );
}
bool has_alpha()
{
return ( m_a != 0 );
}
/*
* Red (r) Property
*/
double r( void ) { return m_r; }
void r( double value ) { m_r = value; }
/*
* Green (g) Property
*/
double g( void ) { return m_g; }
void g( double value ) { m_g = value; }
/*
* Blue (b) Property
*/
double b( void ) { return m_b; }
void b( double value ) { m_b = value; }
/*
* Alpha (a) Property
*/
double a( void ) { return m_a; }
void a( double value ) { m_a = value; }
private:
double m_r;
double m_g;
double m_b;
double m_a;
};
}
#endif // qtlabels_Color_h
+11 -12
View File
@@ -22,8 +22,7 @@
#define qtlabels_ColorNode_h #define qtlabels_ColorNode_h
#include <QString> #include <QString>
#include <QColor>
#include "Color.h"
namespace qtLabels namespace qtLabels
@@ -34,25 +33,25 @@ namespace qtLabels
public: public:
ColorNode() ColorNode()
: m_field_flag(false), m_color(Color::none()), m_key("") : m_field_flag(false), m_color(QColor::fromRgba(0x00000000)), m_key("")
{ {
} }
ColorNode( bool field_flag, Color &color, QString &key ) ColorNode( bool field_flag, QColor &color, QString &key )
: m_field_flag(field_flag), m_color(color), m_key(key) : m_field_flag(field_flag), m_color(color), m_key(key)
{ {
} }
ColorNode( const Color &color ) ColorNode( const QColor &color )
: m_field_flag(false), m_color(color), m_key("") : m_field_flag(false), m_color(color), m_key("")
{ {
} }
ColorNode( QString &key ) ColorNode( QString &key )
: m_field_flag(true), m_color(Color::none()), m_key(key) : m_field_flag(true), m_color(QColor::fromRgba(0x00000000)), m_key(key)
{ {
} }
@@ -74,13 +73,13 @@ namespace qtLabels
#if TODO #if TODO
Color expand( MergeRecord? record ) QColor expand( MergeRecord? record )
{ {
if ( field_flag ) if ( field_flag )
{ {
if ( record == null ) if ( record == null )
{ {
return Color.none(); return QColor.fromRgba(0x00000000);
} }
else else
{ {
@@ -95,12 +94,12 @@ namespace qtLabels
} }
else else
{ {
return Color.none(); return Color.fromRgba(0x00000000);
} }
} }
else else
{ {
return Color.none(); return Color.fromRgba(0x00000000);
} }
} }
} }
@@ -121,7 +120,7 @@ namespace qtLabels
/* /*
* color property * color property
*/ */
Color color( void ) { return m_color; } QColor color( void ) { return m_color; }
/* /*
@@ -132,7 +131,7 @@ namespace qtLabels
private: private:
bool m_field_flag; bool m_field_flag;
Color m_color; QColor m_color;
QString m_key; QString m_key;
}; };
+1 -1
View File
@@ -38,7 +38,7 @@ namespace qtLabels
m_shadow_state = false; m_shadow_state = false;
m_shadow_x = 1.3; m_shadow_x = 1.3;
m_shadow_y = 1.3; m_shadow_y = 1.3;
m_shadow_color_node = ColorNode( Color::black() ); m_shadow_color_node = ColorNode( QColor::fromRgb(0x000000) );
m_shadow_opacity = 0.5; m_shadow_opacity = 0.5;
m_selected_flag = false; m_selected_flag = false;
+4 -4
View File
@@ -244,7 +244,7 @@ namespace qtLabels
*/ */
Q_PROPERTY( ColorNode font_color_node READ font_color_node WRITE font_color_node ); Q_PROPERTY( ColorNode font_color_node READ font_color_node WRITE font_color_node );
virtual ColorNode font_color_node( void ) { return ColorNode( Color::none() ); } virtual ColorNode font_color_node( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
virtual void font_color_node( const ColorNode &value ) { } virtual void font_color_node( const ColorNode &value ) { }
@@ -306,7 +306,7 @@ namespace qtLabels
*/ */
Q_PROPERTY( ColorNode line_color_node READ line_color_node WRITE line_color_node ); Q_PROPERTY( ColorNode line_color_node READ line_color_node WRITE line_color_node );
virtual ColorNode line_color_node( void ) { return ColorNode( Color::none() ); } virtual ColorNode line_color_node( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
virtual void line_color_node( const ColorNode &value ) { } virtual void line_color_node( const ColorNode &value ) { }
@@ -315,7 +315,7 @@ namespace qtLabels
*/ */
Q_PROPERTY( ColorNode fill_color_node READ fill_color_node WRITE fill_color_node ); Q_PROPERTY( ColorNode fill_color_node READ fill_color_node WRITE fill_color_node );
virtual ColorNode fill_color_node( void ) { return ColorNode( Color::none() ); } virtual ColorNode fill_color_node( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
virtual void fill_color_node( const ColorNode &value ) { } virtual void fill_color_node( const ColorNode &value ) { }
@@ -355,7 +355,7 @@ namespace qtLabels
*/ */
Q_PROPERTY( ColorNode bc_color_node READ bc_color_node WRITE bc_color_node ); Q_PROPERTY( ColorNode bc_color_node READ bc_color_node WRITE bc_color_node );
virtual ColorNode bc_color_node( void ) { return ColorNode( Color::none() ); } virtual ColorNode bc_color_node( void ) { return ColorNode( QColor::fromRgba(0x00000000) ); }
virtual void bc_color_node( const ColorNode &value ) { } virtual void bc_color_node( const ColorNode &value ) { }