COPASI API  4.16.103
MyLineEdit.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2014 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include "MyLineEdit.h"
16 #include <QtGui/QValidator>
17 
18 MyLineEdit::MyLineEdit(QWidget * parent, const char * name)
19  : QLineEdit(parent)
20 {
21  setObjectName(name);
22  setupWidget();
23 }
24 
25 MyLineEdit::MyLineEdit(const QString & contents, QWidget * parent, const char * name)
26  : QLineEdit(contents, parent)
27 {
28  setObjectName(name);
29  setupWidget();
30 }
31 
33 {
34  connect(this, SIGNAL(editingFinished()), this, SLOT(slotLostFocus()));
35  connect(this, SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
36  connect(this, SIGNAL(textChanged(const QString &)), this, SLOT(slotTextChanged(const QString &)));
37 
38  mOldColor = palette().color(backgroundRole());
39  int h, s, v;
40  mOldColor.getHsv(&h, &s, &v);
41 
42  if (s < 20) s = 20;
43 
44  mNewColor.setHsv(240, s, v);
45 
46  mErrorColor.setHsv(0, s, v);
47 }
48 
50 {
51  if (isModified())
52  {
53  setModified(false);
54  updateColor();
55  emit edited();
56  }
57 }
58 
60 {process();}
61 
63 {process();}
64 
66 {process();}
67 
68 void MyLineEdit::slotTextChanged(const QString & /* text */)
69 {
70  updateColor();
71 }
72 
74 {
75  if (isModified())
76  {
77  setStyleSheet("background-color:" + mNewColor.name() + ";");
78  }
79  else
80  {
81  setStyleSheet("background-color:" + mOldColor.name() + ";");
82  }
83 
84  const QValidator * val = validator();
85 
86  int dummy = 0;
87 
88  QString ttt = text();
89 
90  if (val)
91  if (val->validate(ttt, dummy) == QValidator::Intermediate)
92  {
93  setStyleSheet("background-color:" + mErrorColor.name() + ";");
94  }
95 }
96 
97 void MyLineEdit::setText(const QString & text)
98 {
99  QLineEdit::setText(text);
100  updateColor();
101 }
102 
104 {return (palette().color(backgroundRole()) != mErrorColor);}
void process()
Definition: MyLineEdit.cpp:49
void slotTextChanged(const QString &text)
Definition: MyLineEdit.cpp:68
virtual void updateColor()
Definition: MyLineEdit.cpp:73
void edited()
void slotForceUpdate()
Definition: MyLineEdit.cpp:65
void slotReturnPressed()
Definition: MyLineEdit.cpp:62
QColor mOldColor
Definition: MyLineEdit.h:29
virtual void setText(const QString &text)
Definition: MyLineEdit.cpp:97
void setupWidget()
Definition: MyLineEdit.cpp:32
void slotLostFocus()
Definition: MyLineEdit.cpp:59
MyLineEdit(QWidget *parent=0, const char *name=0)
Definition: MyLineEdit.cpp:18
QColor mErrorColor
Definition: MyLineEdit.h:31
QColor mNewColor
Definition: MyLineEdit.h:30
bool isValid()
Definition: MyLineEdit.cpp:103