/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /*************************************************************************** * widget.cc * * Tue Jul 17 12:15:59 CEST 2007 * Copyright 2007 Bent Bisballe Nyeng and Lars Bisballe Jensen * deva@aasimon.org and elsenator@gmail.com ****************************************************************************/ /* * This file is part of Pracro. * * Pracro 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. * * Pracro is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Pracro; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "widget.h" Widget::Widget(QDomNode &node, MacroWindow *macrowindow) { QDomElement elem = node.toElement(); this->macrowindow = macrowindow; if(elem.hasAttribute("name")) { widget_name = elem.attribute("name"); } else { if(elem.tagName() != "frame" && elem.tagName() != "label" && elem.tagName() != "button" && elem.tagName() != "widgets") printf("XML ERROR!! Unnamed widget of type: %s\n", elem.tagName().toStdString().c_str()); } if(elem.hasAttribute("script")) { luaprogram = elem.attribute("script"); hasluaprogram = true; } else { hasluaprogram = false; } if(elem.hasAttribute("regexp")) { rx = QRegExp(elem.attribute("regexp")); hasregexpvalidator = true; } else { hasregexpvalidator = false; } has_initial_value = false; initial_value = ""; } QString Widget::getName() { return widget_name; } void Widget::setValue(QString, QString) { } bool Widget::isValid() { return regexpValidator() && luaValidator(); } bool Widget::regexpValidator() { return !hasregexpvalidator || rx.exactMatch(getValue()); } bool Widget::luaValidator() { if(!hasluaprogram) return true; if(macrowindow->luaprograms.contains(luaprogram) == false) return false; QString program = macrowindow->luaprograms.value(luaprogram); return macrowindow->lua->runValidator(program, getName(), getValue()); } void Widget::setInitialValue(QString value) { if(!has_initial_value) { initial_value = value; has_initial_value = true; } } void Widget::reset() { setValue(initial_value); }