summaryrefslogtreecommitdiffstats
path: root/kbarcode/smalldialogs.cpp
blob: 232e2f047219b93cc870204cfd727d1ccce76e07 (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"

// Qt includes
#include <qlabel.h>
#include <qlayout.h>
#include <qsqlcursor.h>

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


using namespace DSSmallDialogs;

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

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

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

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

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

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

AddItemsDialog::AddItemsDialog( const QString & a, const QString & g, int c, QWidget* 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( QFrame::GroupBoxPanel | QFrame::Sunken );
    plainPage()->setLineWidth( 2 );

    QHBoxLayout* layout = new QHBoxLayout( 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 );

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

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

    setupSql();

    connect( SqlTables::getInstance(), SIGNAL( tablesChanged() ), this, SLOT( setupSql() ) );
    connect( SqlTables::getInstance(), SIGNAL( connectedSQL() ), this, 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();
    QSqlQuery query( "select article_no from " TABLE_BASIC " order by article_no" );
    QStringList 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 QString AddItemsDialog::articleNo() const
{
    return article->text();
}

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

#include "smalldialogs.moc"