+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+ReAnnouncer* ReIntComboBox::m_defaultAnnouncer = NULL;
+
+/**
+ * Constructor.
+ * @param parent
+ */
+ReIntComboBox::ReIntComboBox(QWidget *parent) :
+ ReComboBox(parent),
+ m_minValue(0),
+ m_maxValue(0x7ffffff),
+ m_defaultValue(0),
+ m_announcer(m_defaultAnnouncer),
+ m_emptyAllowed(false)
+{
+ connect(this, SIGNAL(textEdited(const QString&, const QString&)),
+ this, SLOT(textEdited(const QString&, const QString&)));
+}
+
+/**
+ * Returns the current value.
+ *
+ * @return the current value
+ */
+int ReIntComboBox::currentValue() const
+{
+ QString value = currentText();
+ int rc = m_defaultValue;
+ if (! value.isEmpty())
+ rc = value.toInt();
+ return rc;
+}
+
+/**
+ * Returns the current announcer (logger for error messages).
+ * @return the current announcer
+ */
+ReAnnouncer* ReIntComboBox::announcer() const
+{
+ return m_announcer;
+}
+
+/**
+ * Returns the flag "empty allowed".
+ *
+ * @return the flag "empty allowed"
+ */
+bool ReIntComboBox::emptyAllowed() const
+{
+ return m_emptyAllowed;
+}
+
+/**
+ * Prints an error message with the stored announcer.
+ *
+ * @param message the error message
+ */
+void ReIntComboBox::error(const QString& message, const QString* defaultValue)
+{
+ if (m_announcer != NULL)
+ m_announcer->say(LOG_ERROR, message);
+ if (defaultValue == NULL){
+ setCurrentText(QString::number(m_defaultValue));
+ } else {
+ if (ReQStringUtils::isAnInteger(*defaultValue))
+ setCurrentText(*defaultValue);
+ else
+ setCurrentText(QString::number(m_defaultValue));
+ }
+}
+/**
+ * Returns the current default value (uses for errors).
+ *
+ * @return the current default value
+ */
+int ReIntComboBox::defaultValue() const
+{
+ return m_defaultValue;
+}
+
+/**
+ * Gets the maximal allowed value.
+ *
+ * @return the maximal allowed value
+ */
+int ReIntComboBox::maxValue() const
+{
+ return m_maxValue;
+}
+
+/**
+ * Gets the maximal allowed value.
+ *
+ * @return the maximal allowed value
+ */
+int ReIntComboBox::minValue() const
+{
+ return m_minValue;
+}
+
+/**
+ * Handles the event "changed text".
+ *
+ * @param oldValue value before editing
+ * @param newValue value after editing
+ */
+void ReIntComboBox::textEdited(const QString& oldValue, const QString& newValue)
+{
+ int value;
+ if (newValue.isEmpty()){
+ if (! m_emptyAllowed)
+ error(tr("integer expected, not an empty string"), &oldValue);
+ } else if (! ReQStringUtils::isAnInteger(newValue, &value)){
+ error(tr("not a number:") + " " + newValue, &oldValue);
+ } else if (value < m_minValue) {
+ error(tr("value to small: %1 < %2").arg(value).arg(m_minValue), &oldValue);
+ } else if (value > m_maxValue) {
+ error(tr("value to large: %1 > %2").arg(value).arg(m_maxValue), &oldValue);
+ }
+}
+
+/**
+ * Sets the flag "empty allowed".
+ *
+ * @param emptyAllowed <i>true</i>: the field may be empty.<br>
+ * <i>false</i>: the field must not be empty
+ */
+void ReIntComboBox::setEmptyAllowed(bool emptyAllowed)
+{
+ m_emptyAllowed = emptyAllowed;
+}
+
+/**
+ * Sets the maximal value.
+ *
+ * @param maxValue the maximal allowed value
+ */
+void ReIntComboBox::setMaxValue(int maxValue)
+{
+ m_maxValue = maxValue;
+}
+
+/**
+ * Sets the minimal value.
+ *
+ * @param minValue the minimal allowed value
+ */
+void ReIntComboBox::setMinValue(int minValue)
+{
+ m_minValue = minValue;
+}
+
+/**
+ * Sets the maximal value.
+ *
+ * @param maxValue the maximal allowed value
+ */
+void ReIntComboBox::setDefaultValue(int defaultValue)
+{
+ m_defaultValue = defaultValue;
+}
+
+/**
+ * Sets the announcer (to log errors).
+ *
+ * @param announcer the new announcer (or NULL)
+ */
+void ReIntComboBox::setAnnouncer(ReAnnouncer* announcer)
+{
+ m_announcer = announcer;
+}
+