summaryrefslogtreecommitdiffstats
path: root/kbarcode/newlabel.cpp
blob: d97dd4713db14d4566f39418069514eec5c3b939 (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/***************************************************************************
                          newlabel.cpp  -  description
                             -------------------
    begin                : Son Mai 5 2002
    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.                                   *
 *                                                                         *
 ***************************************************************************/

#include "newlabel.h"
#include "definitiondialog.h"
#include "sqltables.h"

// TQt includes
#include <tqcheckbox.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqsqlquery.h>

// KDE includes
#include <klocale.h>
#include <kcombobox.h>
#include <kpushbutton.h>

#ifndef I2S
    #define I2S(x) TQString("%1").tqarg(x)
#endif // I2S

NewLabel::NewLabel( TQWidget* parent,  const char* name, bool change, WFlags fl )
    : TQDialog( parent, name, true, fl )
{
    setCaption( i18n( "New Label" ) );
    curid = 0;
    types = 0;
    
    NewLabelLayout = new TQVBoxLayout( this, 11, 6, "NewLabelLayout"); 

    TextLabel1 = new TQLabel( this, "TextLabel1" );
    if( !change )
        TextLabel1->setText( i18n( "<h1>Create a new Label</h1><br><br>" ) );
    else
        TextLabel1->setText( i18n( "<h1>Change Label Size</h1><br><br>" ) );

    NewLabelLayout->addWidget( TextLabel1 );

    TQGroupBox* group1 = new TQGroupBox( this );
    group1->setTitle( i18n( "Label" ) );
    group1->setColumnLayout(0, Qt::Vertical );
    group1->tqlayout()->setSpacing( 6 );
    group1->tqlayout()->setMargin( 11 );
    TQGridLayout* group1Layout = new TQGridLayout( group1->tqlayout() );
    group1Layout->setAlignment( TQt::AlignTop );
    
    TextLabel2 = new TQLabel( group1, "TextLabel2" );
    TextLabel2->setText( i18n( "Producer:" ) );

    TextLabel3 = new TQLabel( group1, "TextLabel3" );
    TextLabel3->setText( i18n( "Type:" ) );

    comboProducer = new KComboBox( FALSE, group1, "comboProducer" );
    comboType = new KComboBox( FALSE, group1, "comboType" );

    checkEmpty = new TQCheckBox( i18n("&Start with an empty label"), group1 );
    checkEmpty->setEnabled( !change );
    
    group1Layout->addMultiCellWidget( checkEmpty, 0, 0, 0, 1 );
    group1Layout->addWidget( TextLabel2, 1, 0 );
    group1Layout->addWidget( TextLabel3, 2, 0 );
    group1Layout->addWidget( comboProducer, 1, 1 );
    group1Layout->addWidget( comboType, 2, 1 );
    
    NewLabelLayout->addWidget( group1 );

    Layout2 = new TQHBoxLayout( 0, 0, 6, "Layout2"); 

    TQSpacerItem* spacer_2 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    Layout2->addItem( spacer_2 );
    NewLabelLayout->addLayout( Layout2 );

    TextLabel4 = new TQLabel( this, "TextLabel4" );
    preview = new LabelPreview( this, "preview" );

    TQHBoxLayout* htqlayout = new TQHBoxLayout( 0, 6, 6 );    
    htqlayout->addWidget( TextLabel4 );
    htqlayout->addWidget( preview );
    NewLabelLayout->addLayout( htqlayout );
    TQSpacerItem* spacer_3 = new TQSpacerItem( 0, 0, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
    NewLabelLayout->addItem( spacer_3 );

    Layout1 = new TQHBoxLayout( 0, 0, 6, "Layout1"); 

    buttonOwnFormat = new KPushButton( this, "buttonOwnFormat" );
    buttonOwnFormat->setText( i18n( "&Add own Label Definition" ) );
    Layout1->addWidget( buttonOwnFormat );

    TQSpacerItem* spacer_4 = new TQSpacerItem( 0, 0, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
    Layout1->addItem( spacer_4 );

    buttonOk = new KPushButton( this, "buttonOk" );
    buttonOk->setText( i18n( "&OK" ) );
    buttonOk->setDefault( true );
    Layout1->addWidget( buttonOk );

    buttonCancel = new KPushButton( this, "buttonCancel" );
    buttonCancel->setText( i18n( "&Cancel" ) );
    Layout1->addWidget( buttonCancel );
    NewLabelLayout->addLayout( Layout1 );

    connect( comboProducer, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( updateType() ) );
    connect( comboProducer, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( updateText() ) );
    connect( comboType, TQT_SIGNAL( activated(int) ), this, TQT_SLOT( updateText() ) );
    connect( checkEmpty, TQT_SIGNAL( clicked() ), this, TQT_SLOT( updateText() ) );
    
    connect( buttonOk, TQT_SIGNAL( clicked() ), this, TQT_SLOT(accept() ) );
    connect( buttonCancel, TQT_SIGNAL( clicked() ), this, TQT_SLOT(reject() ) );
    connect( buttonOwnFormat, TQT_SIGNAL( clicked() ), this, TQT_SLOT(add() ) );
    fillData();
    updateType();
    updateText();
}

NewLabel::~NewLabel()
{
    if( types )
        delete [] types;
}

void NewLabel::fillData()
{
    comboProducer->clear();
    TQStringList list = Definition::getProducers();
    comboProducer->insertStringList( list );

    if( comboProducer->count() ) {
        types = new TQStringList[comboProducer->count()];
        for( int i = 0; i < comboProducer->count(); i++ )
            types[i] = Definition::getTypes( comboProducer->text( i ) );
    }
}

void NewLabel::updateType()
{
    comboType->clear();
    if( types )
        comboType->insertStringList( types[ comboProducer->currentItem() ] );
}

void NewLabel::updateText()
{
    comboProducer->setEnabled( !checkEmpty->isChecked() );
    comboType->setEnabled( !checkEmpty->isChecked() );
    TextLabel2->setEnabled( !checkEmpty->isChecked() );
    TextLabel3->setEnabled( !checkEmpty->isChecked() );
    
    if(!checkEmpty->isChecked())
    {
        Definition d( comboProducer->currentText(), comboType->currentText() );
        TextLabel4->setText( TQString(i18n(
            "<b>Format:</b><br>\nWidth: ") + I2S(d.getMeasurements().width()) +
            i18n("%1<br>Height: ") + I2S(d.getMeasurements().height()) +
            i18n("%2<br>Horizontal Gap: ") + I2S(d.getMeasurements().gapH()) +
            i18n("%3<br>Vertical Gap: ") + I2S(d.getMeasurements().gapV()) +
            i18n("%4<br>Top Gap: ") + I2S(d.getMeasurements().gapTop()) +
            i18n("%5<br>Left Gap: ") + I2S(d.getMeasurements().gapLeft()) + "%6<br>"
            ).tqarg( Measurements::system() )
            .tqarg( Measurements::system() )
            .tqarg( Measurements::system() )
            .tqarg( Measurements::system() )
            .tqarg( Measurements::system() )
            .tqarg( Measurements::system() ) );
    
        preview->setRect( TQRect( (int)d.getMeasurements().gapLeftMM(), 
                                 (int)d.getMeasurements().gapTopMM(), 
                                 (int)d.getMeasurements().widthMM(), 
                                 (int)d.getMeasurements().heightMM() ) );
        preview->setMeasurements( d.getMeasurements() );
        preview->setPrvEnabled( true );        
        preview->tqrepaint();
        curid = d.getId();
    }
    else
    {
        TextLabel4->setText( i18n("No label selected.") );
        preview->setPrvEnabled( false );
        preview->tqrepaint();
    }
}

bool NewLabel::isInCombo( TQComboBox* combo, TQString text )
{
    if( combo->count() == 0 )
        return false;

    for( int i = 0; i < combo->count(); i++ )
        if( combo->text( i ) == text )
            return true;
    return false;
}

void NewLabel::setLabelId( int id )
{
    TQString name;
    TQSqlQuery query("SELECT type FROM " TABLE_LABEL_DEF " WHERE label_no='" + TQString::number( id ) + "'" );
    while( query.next() )
        name = query.value( 0 ).toString();

    for( int i = 0; i < comboProducer->count(); i++ ) {
        comboProducer->setCurrentItem( i );
        updateType();
        for( int z = 0; z < comboType->count(); z++ )
            if( comboType->text( z ) == name ) {
                comboProducer->setCurrentItem( i );
                comboType->setCurrentItem( z );
                return;
            }
        }

    comboProducer->setCurrentItem( 0 );
    updateType();
}

void NewLabel::add()
{
    DefinitionDialog* d = new DefinitionDialog( this );
    if( d->exec() == TQDialog::Accepted ){
        fillData();
        updateType();
        updateText();
    }
    delete d;
}

bool NewLabel::empty() const
{
    return checkEmpty->isChecked();
}


#include "newlabel.moc"