summaryrefslogtreecommitdiffstats
path: root/kbarcode/barkodeengine.h
blob: 0975bafb46aa6b1da3c515d499ba91a080c8e0ee (plain)
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
/***************************************************************************
                          barkodeengine.h  -  description
                             -------------------
    begin                : Fri Nov 05 2004
    copyright            : (C) 2002 by Dominik Seichter
    email                : domseichter@web.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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef BARKODEENGINE_H
#define BARKODEENGINE_H

/**
 * The different generator backends / engines
 */
typedef enum { GNU_BARCODE, PDF417, TBARCODE, TBARCODE2, PIXMAP, PURE_POSTSCRIPT, NONE } EEngine;

class Barkode;
class TQDomElement;
class TQPainter;

/** An interface for additional special options
 *  supported by a BarkodeEngine
 */
class BarkodeEngineOptions {
 public:
    BarkodeEngineOptions() {};
    virtual ~BarkodeEngineOptions() {};

    virtual void defaults() = 0;

    virtual void load( const TQDomElement* tag ) = 0;
    virtual void save( TQDomElement* tag ) = 0;
};

#include <tqsize.h>

/**
  * Inherit from this class if you want to create a
  * (barkode engine) for use with KBarcode.
  * @author Dominik Seichter
  */
class BarkodeEngine{
    public:
        BarkodeEngine();
        virtual ~BarkodeEngine();

        virtual const BarkodeEngine & operator=( const BarkodeEngine & rhs ) = 0;

        virtual EEngine engine() const = 0;
        virtual void update( const TQPaintDevice* device ) = 0;
        virtual const TQSize size() const = 0;

        void setBarkode( Barkode* b ) { barkode = b; }
        virtual void drawBarcode(  TQPainter & painter, int x, int y ) = 0;

        /** @returns a pointer to a BarkodeEngineOptions object
         *  if this BarkodeEngine has one. Otherwise null is returned.
         *  The returned object has to be casted down to the concrete object
         *  you want to use, before setting any of the options.
         */
        virtual BarkodeEngineOptions* options();

    protected:
        Barkode* barkode;
        TQSize m_size;
        
        bool m_valid;
};

/** A barcode engine with implemented empty and does
  * nothing
  */
class EmptyEngine : public BarkodeEngine {
    public:
        EmptyEngine();

        virtual inline const BarkodeEngine & operator=( const BarkodeEngine & rhs );
        virtual inline EEngine engine() const;
        virtual void update( const TQPaintDevice* device );
        virtual const TQSize size() const;
        virtual void drawBarcode(  TQPainter & painter, int x, int y );
};

const BarkodeEngine & EmptyEngine::operator=( const BarkodeEngine & )
{
    return *this;
}

EEngine EmptyEngine::engine() const
{
    return NONE;
}

#endif