summaryrefslogtreecommitdiffstats
path: root/quanta/components/csseditor/specialsb.cpp
blob: eb26e05f8ba81f1a3cdf2183ec4f1dce67a2b9f3 (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(QWidget *parent, const char *name, bool useLineEdit ) : miniEditor(parent,name) {
  if (useLineEdit)
  {
    m_lineEdit = new KLineEdit(this);
    m_sb = 0L;
    connect(m_lineEdit, SIGNAL(textChanged ( const QString & )), this, SLOT(lineEditValueSlot ( const QString & )));
  }
  else
  {
    m_sb=new mySpinBox(this);
    connect(m_sb, SIGNAL(valueChanged ( const QString & )), this, SLOT(sbValueSlot(const QString&)));
    m_lineEdit = 0L;
  }
  m_cb = new QComboBox(this);
  connect(m_cb, SIGNAL(activated ( const QString & )), this, SLOT(cbValueSlot(const QString&)));
}

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

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


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

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

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

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

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

  if (pattern.search(s) != -1) {
    QString temp(s.stripWhiteSpace());
    QString 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;
}

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

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

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

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

lengthEditor::lengthEditor(QWidget *parent, const char *name ) : specialSB(parent,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"