inputint.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  *
4  *
5  * Copyright (C) 1997-2015 by Dimitri van Heesch.
6  *
7  * Permission to use, copy, modify, and distribute this software and its
8  * documentation under the terms of the GNU General Public License is hereby
9  * granted. No representations are made about the suitability of this software
10  * for any purpose. It is provided "as is" without express or implied warranty.
11  * See the GNU General Public License for more details.
12  *
13  */
14 
15 #include "inputint.h"
16 #include "helplabel.h"
17 
18 #include <QSpinBox>
19 #include <QGridLayout>
20 #include <QWheelEvent>
21 #include <QTextStream>
22 
23 class NoWheelSpinBox : public QSpinBox
24 {
25  protected:
26  void wheelEvent(QWheelEvent *e)
27  {
28  e->ignore();
29  }
30 };
31 
32 InputInt::InputInt( QGridLayout *layout,int &row,
33  const QString & id,
34  int defVal, int minVal,int maxVal,
35  const QString & docs )
36  : m_default(defVal), m_minVal(minVal), m_maxVal(maxVal), m_docs(docs), m_id(id)
37 {
38  m_lab = new HelpLabel(id);
39  m_sp = new NoWheelSpinBox;
40  m_sp->setMinimum(minVal);
41  m_sp->setMaximum(maxVal);
42  m_sp->setSingleStep(1);
43  m_val=defVal-1; // force update
44  setValue(defVal);
45 
46  layout->addWidget( m_lab, row, 0 );
47  layout->addWidget( m_sp, row, 1 );
48 
49  connect(m_sp, SIGNAL(valueChanged(int)),
50  this, SLOT(setValue(int)) );
51  connect( m_lab, SIGNAL(enter()), SLOT(help()) );
52  connect( m_lab, SIGNAL(reset()), SLOT(reset()) );
53  row++;
54 }
55 
57 {
58  showHelp(this);
59 }
60 
61 
63 {
64  val = qMax(m_minVal,val);
65  val = qMin(m_maxVal,val);
66  if (val!=m_val)
67  {
68  m_val = val;
69  m_sp->setValue(val);
70  m_value = m_val;
71  updateDefault();
72  }
73 }
74 
76 {
77  {
78  if (m_val==m_default || !m_lab->isEnabled())
79  {
80  m_lab->setText(QString::fromLatin1("<qt>")+m_id+QString::fromLatin1("</qt"));
81  }
82  else
83  {
84  m_lab->setText(QString::fromLatin1("<qt><font color='red'>")+m_id+QString::fromLatin1("</font></qt>"));
85  }
86  emit changed();
87  }
88 }
89 
90 void InputInt::setEnabled(bool state)
91 {
92  m_lab->setEnabled(state);
93  m_sp->setEnabled(state);
94  updateDefault();
95 }
96 
97 QVariant &InputInt::value()
98 {
99  return m_value;
100 }
101 
103 {
104  setValue(m_value.toInt());
105 }
106 
108 {
110 }
111 
113 {
114  t << m_val;
115 }
116 
int m_maxVal
Definition: inputint.h:67
void writeValue(QTextStream &t, QTextCodec *codec)
Definition: inputint.cpp:112
QVariant & value()
Definition: inputint.cpp:97
void reset()
Definition: inputint.cpp:107
void setEnabled(bool)
Definition: inputint.cpp:90
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
static QString fromLatin1(const char *, int len=-1)
Definition: qstring.cpp:14539
QVariant m_value
Definition: inputint.h:68
QSpinBox * m_sp
Definition: inputint.h:63
def connect(nxgraph, k1, k2, p1=0, p2=0, kwds)
Definition: graph.py:30
void showHelp(Input *)
const double e
void updateDefault()
Definition: inputint.cpp:75
QString m_id
Definition: inputint.h:70
int m_minVal
Definition: inputint.h:66
int m_default
Definition: inputint.h:65
The QTextStream class provides basic functions for reading and writing text using a QIODevice...
Definition: qtextstream.h:53
void changed()
QLabel * m_lab
Definition: inputint.h:62
int m_val
Definition: inputint.h:64
void wheelEvent(QWheelEvent *e)
Definition: inputint.cpp:26
void help()
Definition: inputint.cpp:56
Provides conversion between text encodings.
Definition: qtextcodec.h:62
void update()
Definition: inputint.cpp:102
InputInt(QGridLayout *layout, int &row, const QString &id, int defVal, int minVal, int maxVal, const QString &docs)
Definition: inputint.cpp:32
void setValue(int val)
Definition: inputint.cpp:62