[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:59:35 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-accounts-kcm.git;a=commitdiff;h=5f72f24
The following commit has been merged in the master branch:
commit 5f72f24780a1389465a74162913a857d4509a537
Author: David Edmundson <kde at davidedmundson.co.uk>
Date: Sun Apr 24 15:09:36 2011 +0100
Add missing files from last commit that I forgot to git add.
---
src/KCMTelepathyAccounts/validated-line-edit.cpp | 187 +++++++++++++++++++++
...ofile-select-widget.h => validated-line-edit.h} | 59 ++++---
2 files changed, 219 insertions(+), 27 deletions(-)
diff --git a/src/KCMTelepathyAccounts/validated-line-edit.cpp b/src/KCMTelepathyAccounts/validated-line-edit.cpp
new file mode 100644
index 0000000..35e46b1
--- /dev/null
+++ b/src/KCMTelepathyAccounts/validated-line-edit.cpp
@@ -0,0 +1,187 @@
+/*
+ * This file is part of telepathy-accounts-kcm
+ *
+ * Copyright (C) 2011 Thomas Richard <thomas.richard at proan.be>
+ *
+ * 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 "validated-line-edit.h"
+
+#include "parameter-edit-model.h"
+
+#include <KIcon>
+#include <KLineEdit>
+#include <KDebug>
+#include <KLocale>
+#include <KIconLoader>
+
+#include <QtGui/QWidget>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QPaintEvent>
+#include <QtGui/QPainter>
+#include <QtCore/QAbstractItemModel>
+#include <QtCore/QPersistentModelIndex>
+
+class ValidationIconWidget : public QWidget
+{
+public:
+ enum Icon {
+ InvalidIcon = 0,
+ ValidIcon = 1
+ };
+
+ ValidationIconWidget(QWidget *parent);
+
+ void setPixmap(const QPixmap &pixmap);
+
+protected:
+ void paintEvent(QPaintEvent *event);
+
+private:
+ QPixmap m_pixmap;
+};
+
+ValidationIconWidget::ValidationIconWidget(QWidget *parent)
+ : QWidget(parent)
+{
+ this->setCursor(Qt::ArrowCursor);
+}
+
+void ValidationIconWidget::setPixmap(const QPixmap &pixmap)
+{
+ m_pixmap = pixmap;
+ update();
+}
+
+void ValidationIconWidget::paintEvent(QPaintEvent *event)
+{
+ Q_UNUSED(event);
+
+ QPainter p(this);
+ p.drawPixmap(0, 0, width(), height(), m_pixmap);
+}
+
+//////////////////////////////////////////////////////////////////////
+
+class ValidatedLineEdit::Private
+{
+ public:
+ Private()
+ : validationIcon(0)
+ {
+
+ }
+
+ ValidationIconWidget *validationIcon;
+ QRegExpValidator validator;
+ QValidator::State currentState;
+ ValidationIconWidget::Icon currentIcon;
+ QString errorMessage;
+};
+
+ValidatedLineEdit::ValidatedLineEdit(QWidget *parent)
+ : KLineEdit(parent),
+ d(new Private())
+{
+ d->validationIcon = new ValidationIconWidget(this);
+ setToolTip(i18n("This field is required"));
+ updateIcon();
+ setStyleSheet(QLatin1String("QLineEdit { margin-right: 17px;} "));
+ validate();
+
+ connect(this,
+ SIGNAL(textChanged(QString)),
+ this,
+ SLOT(onTextChanged(QString)));
+}
+
+ValidatedLineEdit::~ValidatedLineEdit()
+{
+ delete d;
+}
+
+void ValidatedLineEdit::setValidator(PredefinedValidator validator)
+{
+ switch(validator)
+ {
+ case NotEmptyValidator:
+ setValidator(".+", i18n("This field should not be empty"));
+ break;
+ case EmailValidator:
+ setValidator("[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}", i18n("This field should contain an email address"));
+ break;
+ case HostnameValidator:
+ setValidator(".+\..+", i18n("This field should contain a hostname"));
+ break;
+ case IPAddressValidator:
+ setValidator("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", i18n("This field should contain an IP address"));
+ break;
+ }
+}
+
+void ValidatedLineEdit::setValidator(const QString ®exp, const QString &errorMessage)
+{
+ QRegExp regexpression(regexp, Qt::CaseInsensitive);
+ d->validator.setRegExp(regexpression);
+ d->errorMessage = errorMessage;
+ validate();
+}
+
+QValidator::State ValidatedLineEdit::validationState()
+{
+ return d->currentState;
+}
+
+void ValidatedLineEdit::onTextChanged(const QString &text)
+{
+ Q_UNUSED(text);
+ validate();
+}
+
+void ValidatedLineEdit::resizeEvent(QResizeEvent *event)
+{
+ updateIcon();
+ KLineEdit::resizeEvent(event);
+}
+
+void ValidatedLineEdit::updateIcon()
+{
+ d->validationIcon->resize(height()-6, height()-6);
+ d->validationIcon->move(width() - d->validationIcon->width(), 3);
+ d->validationIcon->update();
+}
+
+void ValidatedLineEdit::validate()
+{
+ int pos;
+ QString validatedText(text());
+
+ if(d->validator.validate(validatedText, pos) == QValidator::Acceptable) {
+ if(d->currentIcon != ValidationIconWidget::ValidIcon) {
+ d->validationIcon->setPixmap(SmallIcon("dialog-ok-apply", 0));
+ setToolTip(i18n("This field is valid"));
+ d->currentIcon = ValidationIconWidget::ValidIcon;
+ d->currentState = QValidator::Acceptable;
+ }
+ }
+ else if(d->currentIcon != ValidationIconWidget::InvalidIcon) {
+ d->validationIcon->setPixmap(SmallIcon("dialog-error", 0));
+ this->setToolTip(d->errorMessage);
+ d->currentIcon = ValidationIconWidget::InvalidIcon;
+ d->currentState = QValidator::Invalid;
+ }
+}
diff --git a/src/KCMTelepathyAccounts/profile-select-widget.h b/src/KCMTelepathyAccounts/validated-line-edit.h
similarity index 51%
copy from src/KCMTelepathyAccounts/profile-select-widget.h
copy to src/KCMTelepathyAccounts/validated-line-edit.h
index 4bb92a1..16f4e5d 100644
--- a/src/KCMTelepathyAccounts/profile-select-widget.h
+++ b/src/KCMTelepathyAccounts/validated-line-edit.h
@@ -1,7 +1,6 @@
/*
* This file is part of telepathy-accounts-kcm
*
- * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
* Copyright (C) 2011 Thomas Richard <thomas.richard at proan.be>
*
* This library is free software; you can redistribute it and/or
@@ -19,45 +18,51 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef TELEPATHY_ACCOUNTS_KCM_PROFILE_SELECT_WIDGET_H
-#define TELEPATHY_ACCOUNTS_KCM_PROFILE_SELECT_WIDGET_H
+#ifndef VALIDATEDLINEEDIT_H
+#define VALIDATEDLINEEDIT_H
-#include "kcm_telepathy_accounts_export.h"
-
-#include <QtGui/QWidget>
-
-namespace Tp {
- class PendingOperation;
-}
-
-class ProfileItem;
-class QItemSelection;
+#include <KLineEdit>
+#include <kdemacros.h>
+#include <QtGui/QValidator>
+class QLabel;
+class QHBoxLayout;
+class QToolButton;
+class ValidationIconWidget;
+class QAbstractItemModel;
class QModelIndex;
-class KCM_TELEPATHY_ACCOUNTS_EXPORT ProfileSelectWidget : public QWidget
+class KDE_EXPORT ValidatedLineEdit : public KLineEdit
{
Q_OBJECT
public:
- explicit ProfileSelectWidget(QWidget *parent = 0);
- ~ProfileSelectWidget();
+ enum PredefinedValidator {
+ NotEmptyValidator,
+ EmailValidator,
+ HostnameValidator,
+ IPAddressValidator
+ };
+
+ ValidatedLineEdit(QWidget *parent = 0);
+ virtual ~ValidatedLineEdit();
- ProfileItem *selectedProfile();
+ void setValidator(PredefinedValidator validator);
+ void setValidator(const QString ®exp, const QString &errorMessage);
-private Q_SLOTS:
- void onProfileManagerReady(Tp::PendingOperation *op);
- void onSelectionChanged(const QItemSelection &selected);
+ QValidator::State validationState();
-Q_SIGNALS:
- void profileGotSelected(bool selected);
- void profileDoubleClicked();
+protected Q_SLOTS:
+ void onTextChanged(const QString &text);
+
+protected:
+ virtual void resizeEvent(QResizeEvent *event);
+ void updateIcon();
+ void validate();
private:
class Private;
- Private * const d;
+ Private *d;
};
-
-#endif // Header guard
-
+#endif // VALIDATEDLINEEDIT_H
--
ktp-accounts-kcm packaging
More information about the pkg-kde-commits
mailing list