summaryrefslogtreecommitdiffstats
path: root/kbarcode/batchprinter.h
blob: c18918332efd004cf249ae01c38290938eeed59b (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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/***************************************************************************
                          batchprinter.h  -  description
                             -------------------
    begin                : Sat Jan 10 2004
    copyright            : (C) 2004 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 BATCHPRINTER_H
#define BATCHPRINTER_H

#include "measurements.h"

#include <qmap.h>
#include <qvaluelist.h>

namespace KABC {
    class AddresseeList;
}

class Definition;
class Label;
class KPrinter;
class Measurements;
class QBuffer;
class QPainter;
class QProgressDialog;
class QWidget;
class QPaintDevice;

typedef QValueList< QMap<QString,QString> > TVariableList;
/**
    This class is responsible for batch printing of articles.
    It is also responsible for creating images of all articles.
    @author Dominik Seichter
*/
class BatchPrinter
{
    public:
        typedef enum EOutputFormat { POSTSCRIPT = 0, IMAGE, BCP };
        enum EImageFileName { E_ARTICLE, E_BARCODE, E_CUSTOM };

        struct data {
            int number;
            QString article_no;
            QString group;
        };

        /** Use this constructor if you want to print to
          * a printer.
          */
        BatchPrinter( KPrinter* p, QWidget* _parent );
        /** This constructor is used in image gernaration mode.
          * @p path is the path to an existing directory where
          * the images are saved.
          */
        BatchPrinter( const QString & path, QWidget* p );
        
        /** Use this constructor to print to a barcode printer @p path
          * with format @p format
          */
        BatchPrinter( const QString & path, int format, QWidget* _parent );
        
        ~BatchPrinter();

        inline void setBuffer( QBuffer* b ) { buffer = b; }
        void setCustomer( const QString & s ) { m_customer = s; }

        /** Specify the label on which is printed first on the page.
         *  The first label on the page (top/left) has the index 1, 
         *  the second label is index 2 ...
         */
        inline void setMove( int m ) { 
            m_move = m > 0 ? --m : 0;
        }

        /** set the sql data for the batchprinter
         *  @p list will be deleted by the batchprinter
         */
        void setData( QValueList<data>* list );

        /** set the variable data for the batchprinter
         *  @p list will be deleted by the batchprinter
         */
        void setData( TVariableList* list );

        /** set the address data for the batchprinter
         *  @p list will be deleted by the batchprinter
         */
        void setData( KABC::AddresseeList* list );

	inline void setImageFilename( const EImageFileName e ) { m_image_filename = e; }
	inline void setImageCustomFilename( const QString & name ) { m_image_custom_filename = name; };
	inline void setImageFormat( const QString & f ) { m_image_format = f; }
        inline void setSerial( const QString & s, unsigned int inc ) { m_serial = s; m_increment = inc; }
        inline void setName( const QString & s ) { m_name = s; }
        inline void setDefinition( Definition* d ) { def = d; }
        inline void setLabels( int l ) { m_labels = l; }
        inline void setEvents( bool b ) { m_events = b; }

        /** start the batch printing on a printer
          */
        void start();
        /** start image generation
          */
        void startImages();
        /** start printing to a barcode printer
          */
        void startBCP();
    private:
	/** create a label which gets intialized either with m_vardata or m_data
	 *  @p number is set to the number of times this label should be printed.
	 */
	Label* initLabel( int* number = NULL );

        /** starts a new page on the printer, if the
          * current label does not fit anymore on the current pageh
          */
        void checkForNewPage( Label* label );
        /** draw a border around the current label using QPainter @p painter
          */
        void drawBorders();
        /** start a "new line" on the printer,
          * i.e. beginn the second row of labels
          * on the page.
          */
        void changeLine();
        void proccessEvents( int lb, QString value = QString::null, Label* label = 0 );
        void printXLabel( int lb, Label* label, const QString & value );
        void moveLabels();

	/** print the labels using data from the m_data structure
	  */
	void startPrintData( QProgressDialog* progress );
	/** print the labels using data from the m_vardata or m_addrdata structure
	  */
	void startPrintVarData( QProgressDialog* progress );

        /** Create and return a progressdialog
          */
        QProgressDialog* createProgressDialog( const QString & caption );
        bool checkProgressDialog( QProgressDialog* progress );

        Definition* def;
        Measurements m_measure;
        QValueList<data>* m_data;
	TVariableList* m_vardata;
        KABC::AddresseeList* m_addrdata;

        QString m_serial;
        QString m_name;
        QString m_customer;
        /** Path for image output
          * or device for bcp output
          */
        QString m_path;
        /** defines the image format to be used
          */
	QString m_image_format;

        unsigned int m_cur_data_count;

        /** format for bcp output
          */
        int m_bcp_format;

        /** defines the format of the filename for images
         */
	EImageFileName m_image_filename;

	/** prefix for custom filenames if m_image_filename = E_CUSTOM
	 */
	QString m_image_custom_filename;

        /** enable/disable events
          */
        bool m_events;

        unsigned int m_increment;
        unsigned int m_move;
        /** number of labels to print for the progress dialog
          */
        unsigned int m_labels;

        /** height of the current page in pixel.
          */
        double pageh;
        double curw;
        double curh;
        int c_h;
        int c_w;

	QPaintDevice* m_paintDevice;

        QBuffer* buffer;
        KPrinter* printer;
        QPainter* painter;
        /** parent for dialogs
          */
        QWidget* parent;
};

#endif