[SCM] ktp-accounts-kcm packaging branch, master, updated. debian/15.12.1-1-1157-gc4589c5

Maximiliano Curia maxy at moszumanska.debian.org
Fri May 27 23:57:29 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-accounts-kcm.git;a=commitdiff;h=64a0e17

The following commit has been merged in the master branch:
commit 64a0e1705d03c3b0fa27a7c08cc35bc1c445d3de
Author: George Goldberg <grundleborg at googlemail.com>
Date:   Fri Jul 24 17:09:27 2009 +0000

    Add an IntegerEdit class which provides a lineEdit field which only allows valid integers to be in it.
    
    svn path=/trunk/playground/network/telepathy-accounts-kcm/; revision=1001971
---
 src/CMakeLists.txt                              |  1 +
 src/integer-edit.cpp                            | 95 +++++++++++++++++++++++++
 src/{add-account-assistant.h => integer-edit.h} | 30 ++++----
 src/parameter-edit-delegate.cpp                 | 28 +++++++-
 src/parameter-edit-delegate.h                   |  1 +
 5 files changed, 137 insertions(+), 18 deletions(-)

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2c5a737..6ecb496 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,6 +17,7 @@ set (telepathy_accounts_kcm_SRCS
      parameter-edit-delegate.cpp
      parameter-edit-model.cpp
      parameter-item.cpp
+     integer-edit.cpp
 )
 
 kde4_add_ui_files (telepathy_accounts_kcm_SRCS
diff --git a/src/integer-edit.cpp b/src/integer-edit.cpp
new file mode 100644
index 0000000..7b5bf08
--- /dev/null
+++ b/src/integer-edit.cpp
@@ -0,0 +1,95 @@
+/*
+ * This file is part of telepathy-accounts-kcm
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "integer-edit.h"
+
+#include <KDebug>
+
+#include <QtGui/QKeyEvent>
+
+IntegerEdit::IntegerEdit(QWidget *parent)
+ : QLineEdit(parent)
+{
+    connect(this, SIGNAL(textChanged(QString)), SLOT(onTextChanged(QString)));
+}
+
+IntegerEdit::~IntegerEdit()
+{
+
+}
+
+void IntegerEdit::setValue(int integer)
+{
+    setText(QString::number(integer));
+}
+
+void IntegerEdit::keyPressEvent(QKeyEvent *event)
+{
+    kDebug() << "Key:" << event->key() << "Text:" << event->text();
+
+    // If the text is empty or a modifier, allow the keypress
+    if ((event->text().isEmpty()) || (event->key() < Qt::Key_Space)) {
+        event->ignore();
+        QLineEdit::keyPressEvent(event);
+        return;
+    }
+
+    // If the key is backspace or delete, allow it
+    if ((event->key() == Qt::Key_Delete) || (event->key() == Qt::Key_Backspace)) {
+        event->ignore();
+        QLineEdit::keyPressEvent(event);
+        return;
+    }
+
+    // Check for numbers (and ensure maximum input length is not expended
+    // FIXME: Have a better check to make sure the user doesn't enter a number too large.
+    QString validKeys("0123456789");
+    if (validKeys.contains(event->text())) {
+        if (((text().contains(QString("-"))) && ((text().length() + 1) <= 5)) ||
+            ((text().length() + 1) <= 4))
+        {
+            kDebug() << "Key is a number.";
+            event->ignore();
+            QLineEdit::keyPressEvent(event);
+            return;
+        }
+    }
+
+    // Check for minus sign as the first character
+    if (event->text() == QString("-")) {
+        if (cursorPosition() == 0) {
+            if (!text().contains(QString("-"))) {
+                kDebug() << "Key is a minus-sign at the start.";
+                event->ignore();
+                QLineEdit::keyPressEvent(event);
+                return;
+            }
+        }
+    }
+
+    // Anything else, reject the keypress.
+    event->accept();
+}
+
+void IntegerEdit::onTextChanged(const QString &text)
+{
+    Q_EMIT integerChanged(text.toInt());
+}
+
diff --git a/src/add-account-assistant.h b/src/integer-edit.h
similarity index 64%
copy from src/add-account-assistant.h
copy to src/integer-edit.h
index 524ab2f..85f5cac 100644
--- a/src/add-account-assistant.h
+++ b/src/integer-edit.h
@@ -18,33 +18,31 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef TELEPATHY_ACCOUNTS_KCM_ADD_ACCOUNT_ASSISTANT_H
-#define TELEPATHY_ACCOUNTS_KCM_ADD_ACCOUNT_ASSISTANT_H
+#ifndef TELEPATHY_ACCOUNTS_KCM_INTEGER_EDIT_H
+#define TELEPATHY_ACCOUNTS_KCM_INTEGER_EDIT_H
 
-#include <KAssistantDialog>
+#include <QtGui/QLineEdit>
 
-class AddAccountAssistant : public KAssistantDialog
+class IntegerEdit : public QLineEdit
 {
     Q_OBJECT
 
 public:
-    explicit AddAccountAssistant(QWidget *parent = 0);
-    ~AddAccountAssistant();
+    explicit IntegerEdit(QWidget *parent = 0);
+    virtual ~IntegerEdit();
 
-protected Q_SLOTS:
-    virtual void back();
-    virtual void next();
-    virtual void accept();
-    virtual void reject();
+    void setValue(int integer);
+
+protected:
+    void keyPressEvent(QKeyEvent *event);
 
 Q_SIGNALS:
-    void cancelled();
+    void integerChanged(int integer);
 
-private:
-    class Private;
-    Private * const d;
+private Q_SLOTS:
+    void onTextChanged(const QString &text);
 };
 
 
-#endif  // Header guard
+#endif // header guard
 
diff --git a/src/parameter-edit-delegate.cpp b/src/parameter-edit-delegate.cpp
index 4894fbc..7f9d5d2 100644
--- a/src/parameter-edit-delegate.cpp
+++ b/src/parameter-edit-delegate.cpp
@@ -20,6 +20,7 @@
 
 #include "parameter-edit-delegate.h"
 
+#include "integer-edit.h"
 #include "parameter-edit-model.h"
 
 #include <KDebug>
@@ -54,12 +55,14 @@ QList<QWidget*> ParameterEditDelegate::createItemWidgets() const
     QLabel *nameLabel = new QLabel();
     QLineEdit *lineEdit = new QLineEdit();
     QCheckBox *checkBox = new QCheckBox();
+    IntegerEdit *integerEdit = new IntegerEdit();
 
     // Connect to the slots from the widgets that we are interested in.
     connect(lineEdit, SIGNAL(textChanged(QString)), SLOT(onLineEditTextChanged(QString)));
     connect(checkBox, SIGNAL(toggled(bool)), SLOT(onCheckBoxToggled(bool)));
+    connect(integerEdit, SIGNAL(integerChanged(int)), SLOT(onIntegerEditIntegerChanged(int)));
 
-    widgets << nameLabel << lineEdit << checkBox;
+    widgets << nameLabel << lineEdit << checkBox << integerEdit;
 
     return widgets;
 }
@@ -82,12 +85,14 @@ void ParameterEditDelegate::updateItemWidgets(const QList<QWidget*> widgets,
     // for every single item in the view.
     QLineEdit *lineEdit = qobject_cast<QLineEdit*>(widgets.at(1));
     QCheckBox *checkBox = qobject_cast<QCheckBox*>(widgets.at(2));
+    IntegerEdit *integerEdit = qobject_cast<IntegerEdit*>(widgets.at(3));
 
     lineEdit->hide();
     checkBox->hide();
+    integerEdit->hide();
 
     // See what type the parameter is, and draw the appropriate widget for it.
-    // FIXME: Support int/uint types with appropriate validation.
+    // FIXME: Support uint types with appropriate validation.
     if (index.model()->data(index, ParameterEditModel::TypeRole).type() == QVariant::Bool) {
         // Bool type. Draw a checkbox.
         checkBox->move((right / 2) + margin, (option.rect.height() - checkBox->size().height()) / 2);
@@ -97,6 +102,16 @@ void ParameterEditDelegate::updateItemWidgets(const QList<QWidget*> widgets,
         // focusedItem() returns the wrong value and we end up setting the data of the wrong item
         // in the model.
         checkBox->setChecked(index.model()->data(index, ParameterEditModel::ValueRole).toBool());
+    } else if (index.model()->data(index, ParameterEditModel::TypeRole).type() == QVariant::Int) {
+        // Integer type. Draw a integer edit.
+        integerEdit->move((right / 2) + margin, (option.rect.height() - integerEdit->size().height()) / 2);
+        integerEdit->resize(QSize(((right - (4 * margin)) / 2), integerEdit->size().height()));
+        integerEdit->show();
+        integerEdit->setFocus(Qt::OtherFocusReason);
+        // NB: We must update the value of the widget AFTER setting it as focused, otherwise
+        // focusedItem() returns the wrong value and we end up setting the data of the wrong item
+        // in the model.
+        integerEdit->setValue(index.model()->data(index, ParameterEditModel::ValueRole).toInt());
     } else {
         // For any other type, treat it as a string type.
         // FIXME: Support asterisking out the entry in secret parameters
@@ -164,6 +179,15 @@ void ParameterEditDelegate::onCheckBoxToggled(bool checked)
     Q_EMIT dataChanged(index, QVariant(checked), ParameterEditModel::ValueRole);
 }
 
+void ParameterEditDelegate::onIntegerEditIntegerChanged(int integer)
+{
+    kDebug();
+
+    QModelIndex index = focusedIndex();
+
+    Q_EMIT dataChanged(index, QVariant(integer), ParameterEditModel::ValueRole);
+}
+
 
 #include "parameter-edit-delegate.moc"
 
diff --git a/src/parameter-edit-delegate.h b/src/parameter-edit-delegate.h
index 523dfec..fd77c2b 100644
--- a/src/parameter-edit-delegate.h
+++ b/src/parameter-edit-delegate.h
@@ -39,6 +39,7 @@ public:
 private Q_SLOTS:
     void onLineEditTextChanged(QString text);
     void onCheckBoxToggled(bool checked);
+    void onIntegerEditIntegerChanged(int integer);
 
 Q_SIGNALS:
     void dataChanged(const QModelIndex &index, const QVariant &value, int role);

-- 
ktp-accounts-kcm packaging



More information about the pkg-kde-commits mailing list