summaryrefslogtreecommitdiffstats
path: root/parts/doxygen/input.cpp
blob: d5745badcb30f6ed6f642ce38e106fe0bd839182 (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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
/***************************************************************************
 *   Copyright (C) 1997-2000 by Dimitri van Heesch                         *
 *   dimitri@stack.nl                                                      *
 *   Copyright (C) 2001 by Bernd Gehrmann                                  *
 *   bernd@kdevelop.org                                                    *
 *                                                                         *
 *   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 <qlabel.h>
#include <qlayout.h>
#include <qcombobox.h>
#include <klineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qtooltip.h>
#include <klocale.h>
#include <kfiledialog.h>
#include <kglobal.h>
#include <kiconloader.h>

#include "input.h"


static const char * const add_xpm_data[] =
{
  "16 16 5 1",
  ". c None",
  "* c #0328f9",
  "# c #354396",
  "a c #353740",
  "c c #999999",
  "................",
  "......###.......",
  "......#*ac......",
  "......#*ac......",
  "......#*ac......",
  "......#*ac......",
  ".######*a#####..",
  ".#***********ac.",
  ".#aaaaa*aaaaaac.",
  "..cccc#*acccccc.",
  "......#*ac......",
  "......#*ac......",
  "......#*ac......",
  "......#aac......",
  ".......ccc......",
  "................"
};
const char **add_xpm = (const char **)add_xpm_data;

static const char * const del_xpm_data[] =
{
  "16 16 5 1",
  ". c None",
  "* c #0328f9",
  "# c #354396",
  "a c #353740",
  "c c #999999",
  "................",
  "................",
  "................",
  "................",
  "................",
  "................",
  ".#############..",
  ".#***********ac.",
  ".aaaaaaaaaaaaac.",
  "..ccccccccccccc.",
  "................",
  "................",
  "................",
  "................",
  "................",
  "................"
};
const char **del_xpm = (const char **)del_xpm_data;

static const char* const update_xpm_data[] =
{
  "16 16 5 1",
  /* colors */
  ". c #0328f9",
  "# c #354396",
  "a c #353740",
  "b c None",
  "c c #999999",
  /* pixels */
  "bbbbbbbbbbbbbbbb",
  "bbbbbbbb#####acb",
  "bbbbbbbb#....abb",
  "bbc##cbb#...acbb",
  "bb#..abb#....abb",
  "bc#..abb#.a..acb",
  "b#..acbbaac#..ab",
  "b#..abbbcbb#..ab",
  "b#..abbbbbb#..ab",
  "b#..acbbbbc#..ab",
  "bc#..#cbbc#..acb",
  "bb#...####...acb",
  "bbca........acbb",
  "bbbbaa....aaccbb",
  "bbbbbcaaaaccbbbb",
  "bbbbbbbbbbbbbbbb"
};
const char **update_xpm = (const char **)update_xpm_data;


InputBool::InputBool(const QCString &k, const QString &text, QWidget * parent, bool &flag)
    : QWidget(parent), state(flag), key(k)
{
    QHBoxLayout *layout = new QHBoxLayout(this);
    cb = new QCheckBox(text,this);

    init();

    layout->addWidget(cb);
    layout->addStretch(1);
    
    connect( cb, SIGNAL(toggled(bool)), this, SLOT(valueChanged(bool)));
}


InputBool::~InputBool()
{}


void InputBool::init()
{
    cb->setChecked(state);
}


void InputBool::valueChanged(bool s)
{
    if (s != state) {
        emit changed();
        emit toggle(key, s);
    }
    state = s;
}


void InputBool::setEnabled(bool b)
{
    cb->setEnabled(b);
}


InputInt::InputInt(const QString &label, QWidget *parent, int &val, int minVal, int maxVal)
    : QWidget(parent), m_val(val), m_minVal(minVal), m_maxVal(maxVal)
{
    QHBoxLayout *layout = new QHBoxLayout(this, 5);
    
    sp = new QSpinBox(minVal, maxVal, 1, this);
    lab = new QLabel(sp, label+":", this);
    
    init();
  
    layout->addWidget(lab);
    layout->addWidget(sp);
    layout->addStretch(1);

    connect(sp, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
}


InputInt::~InputInt()
{}


void InputInt::init()
{
    m_val = QMAX(m_minVal, m_val);
    m_val = QMIN(m_maxVal, m_val);
    sp->setValue(m_val);
}


void InputInt::valueChanged(int val)
{
    if (val != m_val)
        emit changed(); 
    m_val = val;
}


void InputInt::setEnabled(bool state)
{
    lab->setEnabled(state);
    sp->setEnabled(state);
}


InputString::InputString(const QString & label, 
                         QWidget *parent, QCString &s, StringMode m)
    : QWidget(parent), str(s), sm(m), m_values(0), m_index(0)
{
    le = 0; br = 0; com = 0;
    
    if (m == StringFixed) {
        QHBoxLayout *layout = new QHBoxLayout(this, 5);
        com = new QComboBox(this); 
	lab = new QLabel(com,label+":", this);
	layout->addWidget(lab);
        layout->addWidget(com);
        layout->addStretch(1);
    } else {
        QGridLayout *layout = new QGridLayout(this, 1, m==StringFree? 1 : 3, 5);
        le = new KLineEdit(this);
	lab = new QLabel(le,label+":", this);
	layout->addWidget(lab, 0, 0);
        le->setText(s);
        layout->addWidget(le, 0, 1);
        
        if (m == StringFile || m == StringDir) {
            br = new QPushButton(this);
            br->setPixmap(SmallIcon(m==StringFile? "document" : "folder"));
            QToolTip::add(br, m==StringFile? i18n("Browse to a file") : i18n("Browse to a folder"));
            layout->addWidget(br, 0, 2);
        }
    }
    
    if (le)
        connect( le,   SIGNAL(textChanged(const QString&)), 
                 this, SLOT(textChanged(const QString&)) );
    if (br)
        connect( br,   SIGNAL(clicked()), this, SLOT(browse()) );
    if (com)
        connect( com,  SIGNAL(activated(const QString &)), 
                 this, SLOT(textChanged(const QString &)) );
}

InputString::~InputString()
{
    if (m_values)
        delete m_values;
}


void InputString::init()
{
    if (sm == StringFixed) {
        int *itemIndex = m_values->find(str);
        if (itemIndex) 
            com->setCurrentItem(*itemIndex);
        else
            com->setCurrentItem(0);
    } else
        le->setText(str);
}


void InputString::addValue(const char *s)
{
    if (sm == StringFixed) {
        if (!m_values)
            m_values = new QDict<int>;
        m_values->setAutoDelete(true);
        m_values->insert(s, new int(m_index++));
        com->insertItem(s);
    }
}


void InputString::clear()
{
    le->setText("");
    if (!str.isEmpty()) {
        emit changed();
        str = "";
    }
}


void InputString::textChanged(const QString &s)
{
    if (str!=s.latin1()) {
        str = s.latin1();
        emit changed();
    }
}

void InputString::setEnabled(bool state)
{
    lab->setEnabled(state);
    if (le)
        le->setEnabled(state);
    if (br)
        br->setEnabled(state);
    if (com)
        com->setEnabled(state);
}


void InputString::browse()
{
    if (sm == StringFile) {
        QString fileName = KFileDialog::getOpenFileName();
    
        if (!fileName.isNull()) {
            le->setText(fileName);
            if (str != le->text().latin1()) {
                str = le->text().latin1(); 
                emit changed();
            }
        }
    } else { // sm==StringDir
        QString dirName = KFileDialog::getExistingDirectory();

        if (!dirName.isNull()) {
            le->setText( dirName ); 	
            if (str != le->text().latin1()) {
                str = le->text().latin1();
                emit changed();
            }
        }	
    }
}


InputStrList::InputStrList(const QString & label, 
                           QWidget *parent, QStrList &sl, ListMode lm)
    : QWidget(parent), strList(sl)
{
    QGridLayout *layout = new QGridLayout(this, 2, 2, 5);
    
    QWidget *dw = new QWidget(this); /* dummy widget used for layouting */
    QHBoxLayout *boxlayout = new QHBoxLayout(dw, 0, 5);
    le  = new KLineEdit(dw);
    lab = new QLabel(le,label+":", this );
    layout->addWidget(lab, 0, 0);
    boxlayout->addWidget(le, 1);

    add = new QPushButton(dw);
    add->setPixmap(QPixmap( add_xpm ));
    QToolTip::add(add, i18n("Add item"));
    boxlayout->addWidget(add);
    
    del = new QPushButton(dw);
    del->setPixmap(QPixmap( del_xpm ));
    QToolTip::add(del, i18n("Delete selected item"));
    boxlayout->addWidget(del);

    upd = new QPushButton(dw); 
    upd->setPixmap(QPixmap( update_xpm ));
    QToolTip::add(upd, i18n("Update selected item"));
    boxlayout->addWidget(upd);
    
    lb  = new QListBox(this);
    lb->setMinimumSize(400, 100);
    init();
    lb->setVScrollBarMode(QScrollView::Auto);
    lb->setHScrollBarMode(QScrollView::Auto);
    
    brFile = 0;
    brDir = 0;
    if (lm != ListString) {
        if (lm & ListFile) {
            brFile = new QPushButton(dw);
            brFile->setPixmap(SmallIcon("document"));
            QToolTip::add(brFile, i18n("Browse to a file"));
            boxlayout->addWidget(brFile);
        } 
        if (lm & ListDir) {
            brDir = new QPushButton(dw);
            brDir->setPixmap(SmallIcon("folder"));
            QToolTip::add(brDir, i18n("Browse to a folder"));
            boxlayout->addWidget(brDir);
        }
    }
    layout->addWidget(dw, 0, 1);
    layout->addWidget(lb, 1, 1);
    
    connect( le,   SIGNAL(returnPressed()), 
             this, SLOT(addString()) );
    connect( add,  SIGNAL(clicked()), 
             this, SLOT(addString()) );
    connect( del,  SIGNAL(clicked()), 
             this, SLOT(delString()) );
    connect( upd,  SIGNAL(clicked()), 
             this, SLOT(updateString()) );
    if (brFile) 
        connect( brFile, SIGNAL(clicked()),
                 this, SLOT(browseFiles()) );
    if (brDir)
        connect( brDir, SIGNAL(clicked()),
                 this, SLOT(browseDir()) );
    connect( lb,   SIGNAL(selected(const QString &)), 
             this, SLOT(selectText(const QString &)) );
    
    strList = sl;
}


InputStrList::~InputStrList()
{}


void InputStrList::init()
{
    le->clear();
    lb->clear();
    char *s = strList.first();
    while (s) {
        lb->insertItem(s);
        s = strList.next();
    }
}


void InputStrList::addString()
{
    if (!le->text().isEmpty()) {
        lb->insertItem(le->text());
        strList.append(le->text().latin1());
        emit changed();
        le->clear();
    }
}


void InputStrList::delString()
{
    if (lb->currentItem() != -1) {
        int itemIndex = lb->currentItem();
        lb->removeItem(itemIndex);
        strList.remove(itemIndex);
        emit changed();
    }
}


void InputStrList::updateString()
{
    if (lb->currentItem() != -1 && !le->text().isEmpty()) {
        lb->changeItem(le->text(),lb->currentItem());
        strList.insert(lb->currentItem(),le->text().latin1());
        strList.remove(lb->currentItem()+1);
        emit changed();
    }
}


void InputStrList::selectText(const QString &s)
{
    le->setText(s);
}


void InputStrList::setEnabled(bool state)
{
    lab->setEnabled(state);
    le->setEnabled(state);
    add->setEnabled(state);
    del->setEnabled(state);
    upd->setEnabled(state);
    lb->setEnabled(state);
    if (brFile)
        brFile->setEnabled(state);
    if (brDir)
        brDir->setEnabled(state);
}


void InputStrList::browseFiles()
{
    QStringList fileNames = KFileDialog::getOpenFileNames();	
    
    if (!fileNames.isEmpty()) {
        QStringList::Iterator it;
        for (it = fileNames.begin(); it != fileNames.end(); ++it) {
            lb->insertItem(*it);
            strList.append(( *it ).latin1());
            emit changed();
        }
        le->setText(*fileNames.begin());
    }
}


void InputStrList::browseDir()
{	
    QString dirName = KFileDialog::getExistingDirectory();	
    
    if (!dirName.isNull()) {
        lb->insertItem(dirName);
        strList.append(dirName.latin1());
        emit changed();
        le->setText(dirName);
    }
}


#include "input.moc"