summaryrefslogtreecommitdiff
path: root/client/widgets/lineedit.cc
diff options
context:
space:
mode:
authordeva <deva>2010-08-12 10:57:04 +0000
committerdeva <deva>2010-08-12 10:57:04 +0000
commitd9338083192084613e5530b02710b796252d342b (patch)
treee0ec2b36e0de62328e5fd5d3b597f6ee71d1b18f /client/widgets/lineedit.cc
parentdbab8458dcce186e7eb7a114a83f759d7db5445a (diff)
New scripting system part2.
Diffstat (limited to 'client/widgets/lineedit.cc')
-rw-r--r--client/widgets/lineedit.cc126
1 files changed, 50 insertions, 76 deletions
diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc
index c3a799a..918f152 100644
--- a/client/widgets/lineedit.cc
+++ b/client/widgets/lineedit.cc
@@ -27,119 +27,78 @@
#include "lineedit.h"
#include <stdio.h>
+#include <QCoreApplication>
+#include <QLineEdit>
+#include <QEvent>
+#include <QKeyEvent>
+
#include "common.h"
LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow)
- : QLineEdit(), Widget(node, macrowindow)
+ : Widget(node, macrowindow)
{
- setCommonAttributes(this, node);
+ lineedit = new QLineEdit();
+ widget = lineedit;
+
+ setCommonAttributes(lineedit, node);
QDomElement elem = node.toElement();
if(elem.hasAttribute("readonly")) {
- if(elem.attribute("readonly") == "true" || elem.attribute("readonly") == "1") {
- setReadOnly(true);
- } else if(elem.attribute("readonly") == "false" || elem.attribute("readonly") == "0") {
- setReadOnly(false);
+ if(elem.attribute("readonly") == "true" ||
+ elem.attribute("readonly") == "1") {
+ lineedit->setReadOnly(true);
+ } else if(elem.attribute("readonly") == "false" ||
+ elem.attribute("readonly") == "0") {
+ lineedit->setReadOnly(false);
} else {
- printf("Unknown value of readonly: %s\n", elem.attribute("readonly").toStdString().c_str());
+ printf("Unknown value of readonly: %s\n",
+ elem.attribute("readonly").toStdString().c_str());
}
}
- connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed()));
- connect(this, SIGNAL(textEdited(QString)), this, SLOT(user_changed()));
+ connect(lineedit, SIGNAL(textChanged(QString)), this, SLOT(changed()));
+ connect(lineedit, SIGNAL(textEdited(QString)), this, SLOT(user_changed()));
- installEventFilter(this); // Detect keyboard input.
+ installEventFilter(lineedit); // Detect keyboard input.
}
-void LineEdit::changed()
+LineEdit::~LineEdit()
{
- QPalette palette;
-
- if(isEnabled()) {
- if(regexpValidator()) {
- if(luaValidator()) {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(200, 230, 200)));
- }
- } else {
- // invalid string
- palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
- }
- } else {
- // valid string
- palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
- }
+ printf("Delete (LineEdit) %p\n", this); fflush(stdout);
+ // delete lineedit;
+}
- setPalette(palette);
+void LineEdit::changed()
+{
+ eventOnChange();
}
void LineEdit::user_changed()
{
emit wasChanged();
+ eventOnChange();
}
-QString LineEdit::getValue()
+QString LineEdit::value()
{
- return text();
+ return lineedit->text();
}
void LineEdit::setValue(QString value, QString source)
{
if(isUserSource(source)) emit wasChanged();
- if(text() == value) setText(value + " "); // Hack to make sure the textChanged signal is emitted.
- setText(value);
+ if(lineedit->text() == value)
+ lineedit->setText(value + " "); // Hack to make sure the textChanged signal is emitted.
+ lineedit->setText(value);
setInitialValue(value);
}
-void LineEdit::enable()
-{
- setEnabled(true);
-}
-
-void LineEdit::disable()
-{
- setEnabled(false);
-}
-
-bool LineEdit::isDisabled()
-{
- return isEnabled() == false;
-}
-
-void LineEdit::connectFrom(const char *signal,
- const QObject *receiver, const char *method)
-{
- connect(this, signal, receiver, method);
-}
-
-void LineEdit::connectTo(const QObject *sender, const char *signal,
- const char *method)
-{
- connect(sender, signal, this, method);
-}
-
-bool LineEdit::setKeyboardFocus()
-{
- setFocus();
- return true;
-}
-
-void LineEdit::setVisibility(bool visible)
-{
- setVisible(visible);
-}
-
-
-#include <QCoreApplication>
bool LineEdit::eventFilter(QObject *, QEvent *event)
{
- if (event->type() == QEvent::KeyPress) {
+ if(event->type() == QEvent::KeyPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if(keyEvent->key() == Qt::Key_Return ||
keyEvent->key() == Qt::Key_Enter) {
@@ -156,3 +115,18 @@ void LineEdit::changeEvent(QEvent *event)
changed();
}
}
+
+void LineEdit::setWdgValid(bool valid)
+{
+ QPalette palette;
+
+ if(valid) {
+ // valid string
+ palette.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255)));
+ } else {
+ // invalid string
+ palette.setBrush(QPalette::Base, QBrush(QColor(230, 200, 200)));
+ }
+
+ lineedit->setPalette(palette);
+}