summaryrefslogtreecommitdiffstats
path: root/kbarcode/smalldialogs.cpp
blob: 6c1a8738f09c72fe850f22ac302b3dd2f5f0521f (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
/***************************************************************************
                          smalldialogs.cpp  -  description
                             -------------------
    begin                : Son Jul 20 2003
    copyright            : (C) 2003 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 "smalldialogs.h"
#include "sqltables.h"

// TQt includes
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqsqlcursor.h>

// KDE includes
#include <knuminput.h>
#include <klineedit.h>
#include <klocale.h>


using namespace DSSmallDialogs;

AddAllDialog::AddAllDialog(TQWidget *parent, const char *name )
    : KDialogBase( KDialogBase::Plain, i18n("Add Barcode_basic"),
      KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, parent,name)
{
    TQVBoxLayout* tqlayout = new TQVBoxLayout( plainPage(), 6, 6 );

    group = new KLineEdit( plainPage() );
    number = new KIntNumInput( plainPage() );
    number->setLabel( i18n( "Number of labels:" ) );
    number->setRange( 1, 10000, 1, false );

    tqlayout->addWidget( new TQLabel( i18n("Group:"), plainPage() ) );
    tqlayout->addWidget( group );
    tqlayout->addWidget( number );
}

TQString AddAllDialog::groupName() const
{
    return group->text();
}

int AddAllDialog::numberLabels() const
{
    return number->value();
}

AddItemsDialog::AddItemsDialog(TQWidget *parent, const char *name )
    : KDialogBase( KDialogBase::Plain, i18n("Add Items"),
      KDialogBase::User1 | KDialogBase::Close, KDialogBase::User1, parent,name)
{
    init();
}

AddItemsDialog::AddItemsDialog( const TQString & a, const TQString & g, int c, TQWidget* parent, const char* name )
    : KDialogBase( KDialogBase::Plain, i18n("Edit Item"),
      KDialogBase::Ok| KDialogBase::Close, KDialogBase::Ok, parent,name)
{
    init();
    article->setText( a );
    group->setText( g );
    number->setValue( c );
}

void AddItemsDialog::init()
{
    plainPage()->setFrameStyle( TQFrame::GroupBoxPanel | TQFrame::Sunken );
    plainPage()->setLineWidth( 2 );

    TQHBoxLayout* tqlayout = new TQHBoxLayout( plainPage(), 6, 6 );

    group = new KLineEdit( plainPage() );
    article = new KLineEdit( plainPage() );

    number = new KIntNumInput( plainPage() );
    number->setLabel( i18n( "Number of labels:" ), KNumInput::AlignLeft | KNumInput::AlignVCenter );
    number->setRange( 1, 10000, 1, false );

    tqlayout->addWidget( number );
    tqlayout->addWidget( new TQLabel( i18n("Article:" ), plainPage() ) );
    tqlayout->addWidget( article );
    tqlayout->addWidget( new TQLabel( i18n("Group:"), plainPage() ) );
    tqlayout->addWidget( group );

    setButtonText( KDialogBase::User1, i18n("&Add") );

    setupSql();

    connect( SqlTables::getInstance(), TQT_SIGNAL( tablesChanged() ), this, TQT_SLOT( setupSql() ) );
    connect( SqlTables::getInstance(), TQT_SIGNAL( connectedSQL() ), this, TQT_SLOT( setupSql() ) );
}

void AddItemsDialog::slotUser1()
{
    emit add( article->text(), group->text(), number->value() );

    number->setValue( 1 );
    article->setText( "" );
    group->setText( "" );
    article->setFocus();
}

void AddItemsDialog::setupSql()
{
    SqlTables* tables = SqlTables::getInstance();
    if( !tables->isConnected() )
        return;

    KCompletion* comp = article->completionObject();
    comp->clear();
    TQSqlQuery query( "select article_no from " TABLE_BASIC " order by article_no" );
    TQStringList slist;
    while ( query.next() )
        slist.append( query.value(0).toString() );

    comp->setItems( slist );
}

void AddItemsDialog::setGroupCompletion( KCompletion* c )
{
    group->setCompletionObject( c );
}

int AddItemsDialog::count() const
{
    return number->value();
}

const TQString AddItemsDialog::articleNo() const
{
    return article->text();
}

const TQString AddItemsDialog::groupName() const
{
    return group->text();
}

#include "smalldialogs.moc"