1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
* sk_factory.h - Classical Three-Dimensional Artwork for Qt 4
*
* Copyright (c) 2008 Christoph Feck <christoph@maxiom.de>
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef SKULPTURE_FACTORY_H
#define SKULPTURE_FACTORY_H 1
/*-----------------------------------------------------------------------*/
#include <QtGui/QPainterPath>
#include <QtGui/QLinearGradient>
#include <QtGui/QColor>
class AbstractFactory
{
public:
typedef qint8 Code;
typedef const Code *Description;
static const int MinVar = 1;
static const int MaxVar = 9;
public:
enum OpCode
{
/* Values */
MinVal = -100, MaxVal = 100,
GetVar = 100,
Add = 110, Sub, Mul, Div, Min, Max, Mix, Cond,
/* Colors */
RGB = 0, RGBA, RGBAf, Blend, Palette, Shade, Darker, Lighter,
/* Conditions */
EQ = 0, NE, LT, GE, GT, LE, Or, And, Not, FactoryVersion,
OptionVersion, OptionType, OptionComplex, OptionState, OptionRTL,
/* Instructions */
SetVar = 100,
/* Shape */ Move = 121, Line, Quad, Cubic, Close,
/* Gradient */ ColorAt = 121,
/* Frame */
/* Panel */
/* Primitive */
/* Control */
Begin = 118, Else = 119, End = 120, If = 126, While = 127, Nop = 0
};
protected:
AbstractFactory() : p(0), opt(0) { }
virtual ~AbstractFactory() { }
protected:
void setDescription(Description description) { p = description; }
void setOption(const QStyleOption *option) { opt = option; }
void setVar(int n, qreal value) { var[n] = value; }
qreal getVar(int n) const { return var[n]; }
void create();
protected:
virtual void executeCode(Code code) QT_FASTCALL;
virtual void skipCode(Code code) QT_FASTCALL;
virtual int version() QT_FASTCALL { return 0; }
protected:
qreal evalValue() QT_FASTCALL;
QColor evalColor() QT_FASTCALL;
void skipValue() QT_FASTCALL;
void skipColor() QT_FASTCALL;
private:
bool evalCondition() QT_FASTCALL;
void skipCondition() QT_FASTCALL;
private:
Description p;
const QStyleOption *opt;
qreal var[MaxVar + 1];
};
/*-----------------------------------------------------------------------*/
class ShapeFactory : public AbstractFactory
{
public:
static QPainterPath createShape(Description description, qreal var[]);
static QPainterPath createShape(Description description);
protected:
ShapeFactory() : AbstractFactory() { }
virtual ~ShapeFactory() { }
void clear() { path = QPainterPath(); }
const QPainterPath &getPath() const { return path; }
protected:
virtual void executeCode(Code code) QT_FASTCALL;
virtual void skipCode(Code code) QT_FASTCALL;
private:
QPainterPath path;
};
#define Pvalue(v) int(100 * (v) + 0.5)
#define Pmove(x,y) ShapeFactory::Move, Pvalue(x), Pvalue(y)
#define Pline(x,y) ShapeFactory::Line, Pvalue(x), Pvalue(y)
#define Pquad(x,y,a,b) ShapeFactory::Quad, Pvalue(x), Pvalue(y), Pvalue(a), Pvalue(b)
#define Pcubic(x,y,a,b,c,d) ShapeFactory::Cubic, Pvalue(x), Pvalue(y), Pvalue(a), Pvalue(b), Pvalue(c), Pvalue(d)
#define Pend ShapeFactory::Close, ShapeFactory::End
#define Pclose ShapeFactory::Close
/*-----------------------------------------------------------------------*/
class GradientFactory : public AbstractFactory
{
public:
static QGradient createGradient(Description description, qreal var[]);
static QGradient createGradient(Description description);
protected:
GradientFactory() : AbstractFactory() { }
virtual ~GradientFactory() { }
protected:
void clear() { gradient.setStops(QGradientStops()); }
const QGradient &getGradient() const { return gradient; }
protected:
virtual void executeCode(Code code) QT_FASTCALL;
virtual void skipCode(Code code) QT_FASTCALL;
private:
QGradient gradient;
};
/*-----------------------------------------------------------------------*/
#endif
|