[Pkg-owncloud-commits] [owncloud-client] 319/470: Make postfixlineedit more userfriendly, rename email id string to "Email".
Sandro Knauß
hefee-guest at moszumanska.debian.org
Thu May 12 16:25:19 UTC 2016
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 9cc981c8c76553029cc7b6d67a20308c44101537
Author: Daniel Molkentin <danimo at owncloud.com>
Date: Tue Apr 12 16:24:06 2016 +0200
Make postfixlineedit more userfriendly, rename email id string to "Email".
---
src/gui/wizard/owncloudhttpcredspage.cpp | 2 +-
src/gui/wizard/owncloudsetuppage.cpp | 12 ++--
src/gui/wizard/postfixlineedit.cpp | 120 +++++++++----------------------
src/gui/wizard/postfixlineedit.h | 32 ++++-----
src/libsync/owncloudtheme.cpp | 1 +
src/libsync/owncloudtheme.h | 1 +
src/libsync/theme.cpp | 5 ++
src/libsync/theme.h | 3 +
8 files changed, 68 insertions(+), 108 deletions(-)
diff --git a/src/gui/wizard/owncloudhttpcredspage.cpp b/src/gui/wizard/owncloudhttpcredspage.cpp
index 046c1fe..a3c1cef 100644
--- a/src/gui/wizard/owncloudhttpcredspage.cpp
+++ b/src/gui/wizard/owncloudhttpcredspage.cpp
@@ -48,7 +48,7 @@ OwncloudHttpCredsPage::OwncloudHttpCredsPage(QWidget* parent)
// default, handled in ui file
break;
case Theme::UserIDEmail:
- _ui.usernameLabel->setText(tr("&E-mail address"));
+ _ui.usernameLabel->setText(tr("&Email"));
break;
case Theme::UserIDCustom:
_ui.usernameLabel->setText(theme->customUserID());
diff --git a/src/gui/wizard/owncloudsetuppage.cpp b/src/gui/wizard/owncloudsetuppage.cpp
index f6186e5..95ea565 100644
--- a/src/gui/wizard/owncloudsetuppage.cpp
+++ b/src/gui/wizard/owncloudsetuppage.cpp
@@ -53,10 +53,12 @@ OwncloudSetupPage::OwncloudSetupPage(QWidget *parent)
if (theme->overrideServerUrl().isEmpty()) {
_ui.leUrl->setPostfix(theme->wizardUrlPostfix());
+ _ui.leUrl->setPlaceholderText(theme->wizardUrlHint());
} else {
_ui.leUrl->setEnabled(false);
}
+
registerField( QLatin1String("OCUrl*"), _ui.leUrl );
_ui.resultLayout->addWidget( _progressIndi );
@@ -136,12 +138,12 @@ void OwncloudSetupPage::slotUrlChanged(const QString& url)
void OwncloudSetupPage::slotUrlEditFinished()
{
- QString url = _ui.leUrl->text();
+ QString url = _ui.leUrl->fullText();
if (QUrl(url).isRelative()) {
// no scheme defined, set one
url.prepend("https://");
}
- _ui.leUrl->setText(url);
+ _ui.leUrl->setFullText(url);
}
bool OwncloudSetupPage::isComplete() const
@@ -210,7 +212,7 @@ int OwncloudSetupPage::nextId() const
QString OwncloudSetupPage::url() const
{
- QString url = _ui.leUrl->text().simplified();
+ QString url = _ui.leUrl->fullText().simplified();
return url;
}
@@ -246,7 +248,7 @@ void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly )
_ui.errorLabel->setVisible(false);
} else {
if (retryHTTPonly) {
- QUrl url(_ui.leUrl->text());
+ QUrl url(_ui.leUrl->fullText());
if (url.scheme() == "https") {
// Ask the user how to proceed when connecting to a https:// URL fails.
// It is possible that the server is secured with client-side TLS certificates,
@@ -260,7 +262,7 @@ void OwncloudSetupPage::setErrorString( const QString& err, bool retryHTTPonly )
case OwncloudConnectionMethodDialog::No_TLS:
{
url.setScheme("http");
- _ui.leUrl->setText(url.toString());
+ _ui.leUrl->setFullText(url.toString());
// skip ahead to next page, since the user would expect us to retry automatically
wizard()->next();
}
diff --git a/src/gui/wizard/postfixlineedit.cpp b/src/gui/wizard/postfixlineedit.cpp
index bf8bef9..6ed14ec 100644
--- a/src/gui/wizard/postfixlineedit.cpp
+++ b/src/gui/wizard/postfixlineedit.cpp
@@ -12,51 +12,30 @@
* for more details.
*/
-#include <QRegExpValidator>
-#include <QRegExp>
+#include <QStyle>
+#include <QStyleOptionFrame>
+
#include <QDebug>
#include "postfixlineedit.h"
namespace OCC {
-// Helper class
-
-/**
- * @brief A QRegExValidator with no Intermediate validation state.
- *
- * Along with a pre-set text in a lineedit, this enforces a certain text
- * to always be present.
- */
-class StrictRegExpValidator : public QRegExpValidator
-{
-public:
- explicit StrictRegExpValidator(const QRegExp& rx, QObject *parent = 0) :
- QRegExpValidator(rx, parent) {}
-
- virtual QValidator::State validate(QString& input, int& pos) const Q_DECL_OVERRIDE;
-};
-
-
-QValidator::State StrictRegExpValidator::validate(QString &input, int &pos) const
-{
- QValidator::State state = QRegExpValidator::validate(input, pos);
- if (state == QValidator::Intermediate)
- state = QValidator::Invalid;
- return state;
-}
-
-// Begin of URLLineEdit impl
+const int horizontalMargin(4);
+const int verticalMargin(4);
PostfixLineEdit::PostfixLineEdit(QWidget *parent)
- : QLineEdit(parent)
+ : QLineEdit(parent)
{
- connect(this, SIGNAL(textChanged(const QString&)), SLOT(slotTextChanged(const QString&)));
}
void PostfixLineEdit::setPostfix(const QString &postfix)
{
_postfix = postfix;
+ QFontMetricsF fm(font());
+ QMargins tm = textMargins();
+ tm.setRight(tm.right()+fm.width(_postfix)+verticalMargin);
+ setTextMargins(tm);
}
QString PostfixLineEdit::postfix() const
@@ -64,70 +43,39 @@ QString PostfixLineEdit::postfix() const
return _postfix;
}
-void PostfixLineEdit::focusInEvent(QFocusEvent *ev)
-{
- QLineEdit::focusInEvent(ev);
- ensureValidationEngaged();
- setSelection(0 , maxUserInputLength());
-}
-
-void PostfixLineEdit::focusOutEvent(QFocusEvent *ev)
-{
- QLineEdit::focusOutEvent(ev);
- showPlaceholder();
-}
-
-void PostfixLineEdit::slotTextChanged(const QString &)
+QString PostfixLineEdit::fullText() const
{
- ensureValidationEngaged();
+ return text() + _postfix;
}
-void PostfixLineEdit::mouseReleaseEvent(QMouseEvent *ev)
+void PostfixLineEdit::setFullText(const QString &text)
{
- QLineEdit::mouseReleaseEvent(ev);
- // ensure selections still work
- if (selectedText().isEmpty()) {
- limitCursorPlacement();
+ QString prefixString = text;
+ if (prefixString.endsWith(postfix())) {
+ prefixString.chop(postfix().length());
}
+ qDebug() << prefixString;
+ setText(prefixString);
}
-void PostfixLineEdit::ensureValidationEngaged()
+void PostfixLineEdit::paintEvent(QPaintEvent *pe)
{
- if (_postfix.isEmpty())
- return;
-
- if (text().isEmpty()) {
- // also called from setText via slotTextChanged
- bool old = blockSignals(true);
- setText(_postfix);
- blockSignals(old);
- }
- if (!validator()) {
- QRegExp rx(QString("*%1").arg(_postfix));
- rx.setPatternSyntax(QRegExp::Wildcard);
- QRegExpValidator *val = new StrictRegExpValidator(rx);
- setValidator(val);
- }
-}
-void PostfixLineEdit::showPlaceholder()
-{
- if (text() == _postfix && !placeholderText().isNull()) {
- setValidator(0);
- setText(QString());
- }
-}
-
-int PostfixLineEdit::maxUserInputLength() const
-{
- return text().length() - _postfix.length();
-}
-
-void PostfixLineEdit::limitCursorPlacement()
-{
- if (cursorPosition() > maxUserInputLength()) {
- setCursorPosition(maxUserInputLength());
- }
+ QLineEdit::paintEvent(pe);
+ QPainter p(this);
+
+ //
+ p.setPen(palette().color(QPalette::Disabled, QPalette::Text));
+ QFontMetricsF fm(font());
+ int start = rect().right()-fm.width(_postfix);
+ QStyleOptionFrame panel;
+ initStyleOption(&panel);
+ QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this);
+ r.setTop(r.top()+horizontalMargin-1);
+ QRect postfixRect(r);
+
+ postfixRect.setLeft(start-verticalMargin);
+ p.drawText(postfixRect, _postfix);
}
} // namespace OCC
diff --git a/src/gui/wizard/postfixlineedit.h b/src/gui/wizard/postfixlineedit.h
index 636cc1f..2d0d297 100644
--- a/src/gui/wizard/postfixlineedit.h
+++ b/src/gui/wizard/postfixlineedit.h
@@ -16,40 +16,40 @@
#define OCC_POSTFIXLINEEDIT_H
#include <QLineEdit>
+#include <QPaintEvent>
+#include <QPainter>
namespace OCC {
/**
- * @brief A class with a non-removable postfix string.
+ * @brief A lineedit class with a pre-set postfix.
*
* Useful e.g. for setting a fixed domain name.
*/
+
class PostfixLineEdit : public QLineEdit
{
Q_OBJECT
public:
- PostfixLineEdit(QWidget *parent = 0);
- /// Sets a non-removeable postfix string
- void setPostfix(const QString &postfix);
- /// @return the currently set postfix. Use @ref text() to retrieve the full text.
- QString postfix() const;
+ PostfixLineEdit(QWidget *parent);
-protected:
- void mouseReleaseEvent(QMouseEvent*) Q_DECL_OVERRIDE;
- void focusInEvent(QFocusEvent *) Q_DECL_OVERRIDE;
- void focusOutEvent(QFocusEvent *) Q_DECL_OVERRIDE;
+ /** @brief sets an optional postfix shown greyed out */
+ void setPostfix(const QString& postfix);
+ /** @brief retrives the postfix */
+ QString postfix() const;
+ /** @brief retrieves combined text() and postfix() */
+ QString fullText() const;
-private slots:
- void slotTextChanged(const QString&);
+ /** @brief sets text() from full text, discarding prefix() */
+ void setFullText(const QString &text);
+protected:
+ void paintEvent(QPaintEvent *pe);
private:
- void ensureValidationEngaged();
- void showPlaceholder();
- int maxUserInputLength() const;
- void limitCursorPlacement();
QString _postfix;
};
+
} // namespace OCC
#endif // OCC_POSTFIXLINEEDIT_H
diff --git a/src/libsync/owncloudtheme.cpp b/src/libsync/owncloudtheme.cpp
index 81b682b..0916fa8 100644
--- a/src/libsync/owncloudtheme.cpp
+++ b/src/libsync/owncloudtheme.cpp
@@ -109,6 +109,7 @@ QPixmap ownCloudTheme::wizardHeaderLogo() const
{
return QPixmap(hidpiFileName(":/client/theme/colored/wizard_logo.png"));
}
+
#endif
QString ownCloudTheme::appName() const
diff --git a/src/libsync/owncloudtheme.h b/src/libsync/owncloudtheme.h
index 8eade6a..0ad7f46 100644
--- a/src/libsync/owncloudtheme.h
+++ b/src/libsync/owncloudtheme.h
@@ -47,6 +47,7 @@ public:
QColor wizardHeaderTitleColor() const Q_DECL_OVERRIDE;
QPixmap wizardHeaderLogo() const Q_DECL_OVERRIDE;
#endif
+
private:
diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp
index e2f673b..1bc3477 100644
--- a/src/libsync/theme.cpp
+++ b/src/libsync/theme.cpp
@@ -453,6 +453,11 @@ QString Theme::wizardUrlPostfix() const
return QString();
}
+QString Theme::wizardUrlHint() const
+{
+ return QString();
+}
+
} // end namespace client
diff --git a/src/libsync/theme.h b/src/libsync/theme.h
index c9df014..4e60a11 100644
--- a/src/libsync/theme.h
+++ b/src/libsync/theme.h
@@ -286,6 +286,9 @@ public:
virtual QString wizardUrlPostfix() const;
+ virtual QString wizardUrlHint() const;
+
+
protected:
#ifndef TOKEN_AUTH_ONLY
QIcon themeIcon(const QString& name, bool sysTray = false) const;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list