summaryrefslogtreecommitdiffstats
path: root/src/gui/linefieldwidget.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/gui/linefieldwidget.cpp
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/linefieldwidget.cpp')
-rw-r--r--src/gui/linefieldwidget.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/gui/linefieldwidget.cpp b/src/gui/linefieldwidget.cpp
new file mode 100644
index 0000000..1535832
--- /dev/null
+++ b/src/gui/linefieldwidget.cpp
@@ -0,0 +1,90 @@
+/***************************************************************************
+ copyright : (C) 2005-2006 by Robby Stephenson
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#include "linefieldwidget.h"
+#include "../field.h"
+#include "../isbnvalidator.h"
+#include "../fieldcompletion.h"
+#include "../latin1literal.h"
+#include "../tellico_kernel.h"
+#include "../gui/lineedit.h"
+
+using Tellico::GUI::LineFieldWidget;
+
+LineFieldWidget::LineFieldWidget(Data::FieldPtr field_, QWidget* parent_, const char* name_/*=0*/)
+ : FieldWidget(field_, parent_, name_) {
+
+ m_lineEdit = new GUI::LineEdit(this);
+ m_lineEdit->setAllowSpellCheck(true);
+ m_lineEdit->setEnableSpellCheck(field_->formatFlag() != Data::Field::FormatName);
+ connect(m_lineEdit, SIGNAL(textChanged(const QString&)), SIGNAL(modified()));
+
+ registerWidget();
+
+ if(field_->flags() & Data::Field::AllowCompletion) {
+ FieldCompletion* completion = new FieldCompletion(field_->flags() & Data::Field::AllowMultiple);
+ completion->setItems(Kernel::self()->valuesByFieldName(field_->name()));
+ completion->setIgnoreCase(true);
+ m_lineEdit->setCompletionObject(completion);
+ m_lineEdit->setAutoDeleteCompletionObject(true);
+ }
+
+ if(field_->name() == Latin1Literal("isbn")) {
+ m_lineEdit->setValidator(new ISBNValidator(this));
+ }
+}
+
+QString LineFieldWidget::text() const {
+ QString text = m_lineEdit->text();
+ if(field()->flags() & Data::Field::AllowMultiple) {
+ text.replace(s_semiColon, QString::fromLatin1("; "));
+ }
+ return text.stripWhiteSpace();
+}
+
+void LineFieldWidget::setText(const QString& text_) {
+ blockSignals(true);
+ m_lineEdit->blockSignals(true);
+ m_lineEdit->setText(text_);
+ m_lineEdit->blockSignals(false);
+ blockSignals(false);
+}
+
+void LineFieldWidget::clear() {
+ m_lineEdit->clear();
+ editMultiple(false);
+}
+
+void LineFieldWidget::addCompletionObjectItem(const QString& text_) {
+ m_lineEdit->completionObject()->addItem(text_);
+}
+
+void LineFieldWidget::updateFieldHook(Data::FieldPtr oldField_, Data::FieldPtr newField_) {
+ bool wasComplete = (oldField_->flags() & Data::Field::AllowCompletion);
+ bool isComplete = (newField_->flags() & Data::Field::AllowCompletion);
+ if(!wasComplete && isComplete) {
+ FieldCompletion* completion = new FieldCompletion(isComplete);
+ completion->setItems(Kernel::self()->valuesByFieldName(newField_->name()));
+ completion->setIgnoreCase(true);
+ m_lineEdit->setCompletionObject(completion);
+ m_lineEdit->setAutoDeleteCompletionObject(true);
+ } else if(wasComplete && !isComplete) {
+ m_lineEdit->completionObject()->clear();
+ }
+}
+
+QWidget* LineFieldWidget::widget() {
+ return m_lineEdit;
+}
+
+#include "linefieldwidget.moc"