summaryrefslogtreecommitdiffstats
path: root/quanta/components/csseditor/specialsb.cpp
blob: e59fca51c19f621a968441939d91d5b80d355dac (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
/***************************************************************************
                          specialsb.cpp  -  description
                             -------------------
    begin                : dom ago 3 2003
    copyright            : (C) 2003 by gulmini luciano
    email                : gulmini.luciano@student.unife.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 "specialsb.h"
#include "propertysetter.h"
#include "csseditor_globals.h"

#include <klineedit.h>

specialSB::specialSB(TQWidget *tqparent, const char *name, bool useLineEdit ) : miniEditor(tqparent,name) {
  if (useLineEdit)
  {
    m_lineEdit = new KLineEdit(this);
    m_sb = 0L;
    connect(m_lineEdit, TQT_SIGNAL(textChanged ( const TQString & )), this, TQT_SLOT(lineEditValueSlot ( const TQString & )));
  }
  else
  {
    m_sb=new mySpinBox(this);
    connect(m_sb, TQT_SIGNAL(valueChanged ( const TQString & )), this, TQT_SLOT(sbValueSlot(const TQString&)));
    m_lineEdit = 0L;
  }
  m_cb = new TQComboBox(this);
  connect(m_cb, TQT_SIGNAL(activated ( const TQString & )), this, TQT_SLOT(cbValueSlot(const TQString&)));
}

specialSB::~specialSB(){
  delete m_cb;
  delete m_sb;
  delete m_lineEdit;
}

void specialSB::connectToPropertySetter(propertySetter* p){
  connect(this, TQT_SIGNAL(valueChanged(const TQString&)), p,TQT_SIGNAL(valueChanged(const TQString&)));
}


void specialSB::cbValueSlot(const TQString& s){
  if (m_sb)
    emit valueChanged( m_sb->text() +s );
  else
    emit valueChanged( m_lineEdit->text() +s );
}

void specialSB::sbValueSlot(const TQString& s){
  emit valueChanged( s + m_cb->currentText());
}

void specialSB::lineEditValueSlot(const TQString& s){
  emit valueChanged( s + m_cb->currentText());
}

void specialSB::setInitialValue(const TQString& s){

  TQRegExp pattern("\\d("+ cbValueList().join("|")+")");

  if (pattern.search(s) != -1) {
    TQString temp(s.stripWhiteSpace());
    TQString cbValue = pattern.cap(1);

    if (m_sb)
      m_sb->setValue(temp.remove(cbValue).toInt());
    else
      m_lineEdit->setText(temp.remove(cbValue));
    m_cb->setCurrentText(cbValue);
  }
  else return;
}

TQStringList specialSB::cbValueList(){
  TQStringList l;
  for(int i=0; i<m_cb->count();i++) l.append(m_cb->text(i));
  return l;
}

frequencyEditor::frequencyEditor(TQWidget *tqparent, const char *name ) : specialSB(tqparent,name) {
  m_cb->insertItem("Hz");
  m_cb->insertItem("kHz");
  m_sb->setMaxValue(9999);
}

angleEditor::angleEditor(TQWidget *tqparent, const char *name) : specialSB(tqparent,name){
  m_cb->insertItem("deg");
  m_cb->insertItem("grad");
  m_cb->insertItem("rad");
  m_sb->setMaxValue(-400);
  m_sb->setMaxValue(400);
}

timeEditor::timeEditor(TQWidget *tqparent, const char *name ) : specialSB(tqparent,name) {
  m_cb->insertItem("ms");
  m_cb->insertItem("s");
  m_sb->setMaxValue(99999);
}

lengthEditor::lengthEditor(TQWidget *tqparent, const char *name ) : specialSB(tqparent,name, true) {
  m_cb->insertItem("px");
  m_cb->insertItem("em");
  m_cb->insertItem("ex");
  m_cb->insertItem("in");
  m_cb->insertItem("cm");
  m_cb->insertItem("mm");
  m_cb->insertItem("pt");
  m_cb->insertItem("pc");
  if (m_sb)
    m_sb->setMaxValue(99999);
}





#include "specialsb.moc"