summaryrefslogtreecommitdiffstats
path: root/quanta/dialogs/tagdialogs/tagwidget.cpp
blob: 014549bc14edd8b901fb8281f95e5497b8d8ef2e (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
/***************************************************************************
                          tagwidget.cpp  -  description
                             -------------------
    begin                : Sat Apr 1 2000
    copyright            : (C) 2000 by Yacovlev Alexander & Dmitry Poplavsky <pdima@mail.univ.kiev.ua>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

// QT files
#include <tqcombobox.h>
#include <klineedit.h>
#include <tqstring.h>
#include <tqspinbox.h>
#include <tqcheckbox.h>

// KDE files
#include <kcolorbutton.h>
#include <kurl.h>

// application's headers
#include "tagwidget.h"
#include "tagdialog.h"
#include "resource.h"

TagWidget::TagWidget(TQObject *parent, const char *)
{
  baseURL = ((TagDialog *)parent)->baseURL();
}

TagWidget::~TagWidget(){
}

void TagWidget::updateDict(const TQString &attr, TQComboBox *combo )
{
  TQString *s = new TQString(combo->currentText());
  if (s->isEmpty())
  {
    dict->remove(attr);
    delete s;
  }
  else
    dict->replace(attr, s);
}

void TagWidget::setValue(const TQString &val, TQComboBox *combo)
{
  bool found = false;
  int num = combo->count();

  for ( int i = 0; i < num; i++)
  {
    if (val == combo->text(i))
    {
      combo->setCurrentItem(i);
      found = true;
    }
  }

  if (!found)
    combo->setEditText(val);
}

void TagWidget::setValue(const TQString &val, TQLineEdit *line)
{
  line->setText(val);
}

void TagWidget::setValue(const TQString &val, TQSpinBox *spin)
{
  spin->setValue(val.toInt());
}

void TagWidget::setValue(const TQString &val, KColorButton *button)
{
  button->setColor(val);
}

void TagWidget::updateDict(const TQString &attr, TQLineEdit *line )
{
  TQString *s = new TQString(line->text());
  if (s->isEmpty())
  {
    dict->remove(attr);
    delete s;
  }
  else
    dict->replace(attr, s);
}

void TagWidget::updateDict(const TQString &attr, TQSpinBox *spin )
{
  TQString *s = new TQString(spin->text());
  if (s->isEmpty())
  {
    dict->remove(attr);
    delete s;
  } 
  else
    dict->replace(attr, s);
}

void TagWidget::updateDict(const TQString &attr, TQCheckBox *check )
{
  if (!check->isChecked())
    dict->remove(attr);
  else
  {
    if (!dict->find(attr))
      dict->insert(attr, new TQString(""));
  }
}