diff options
author | Fabian Müller <fmueller@owncloud.com> | 2022-05-27 15:21:52 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2022-05-31 16:02:54 +0300 |
commit | 0d5a064d5b94707cc91c8fb65e3c7173ab31bcba (patch) | |
tree | c64a80e5cd2ef68e52fdc22079b71a4f5d6d840e /src/gui | |
parent | 4f135b49d3d06cb880da601783e9b972805adcad (diff) |
Restore wizard URL postfix branding option
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/newwizard/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/gui/newwizard/pages/serverurlsetupwizardpage.cpp | 12 | ||||
-rw-r--r-- | src/gui/newwizard/pages/serverurlsetupwizardpage.ui | 9 | ||||
-rw-r--r-- | src/gui/newwizard/postfixlineedit.cpp | 77 | ||||
-rw-r--r-- | src/gui/newwizard/postfixlineedit.h | 56 |
5 files changed, 154 insertions, 2 deletions
diff --git a/src/gui/newwizard/CMakeLists.txt b/src/gui/newwizard/CMakeLists.txt index 50de4a71a..5ba480f6b 100644 --- a/src/gui/newwizard/CMakeLists.txt +++ b/src/gui/newwizard/CMakeLists.txt @@ -37,6 +37,8 @@ add_library(newwizard STATIC jobs/checkbasicauthjobfactory.cpp jobs/checkbasicauthjobfactory.h + postfixlineedit.cpp + syncmode.cpp ) target_link_libraries(newwizard PUBLIC Qt5::Widgets libsync) diff --git a/src/gui/newwizard/pages/serverurlsetupwizardpage.cpp b/src/gui/newwizard/pages/serverurlsetupwizardpage.cpp index 9936e565d..04d82cd59 100644 --- a/src/gui/newwizard/pages/serverurlsetupwizardpage.cpp +++ b/src/gui/newwizard/pages/serverurlsetupwizardpage.cpp @@ -32,11 +32,21 @@ ServerUrlSetupWizardPage::ServerUrlSetupWizardPage(const QUrl &serverUrl) if (!Theme::instance()->wizardUrlHint().isEmpty()) { _ui->urlLineEdit->setPlaceholderText(Theme::instance()->wizardUrlHint()); } + + if (!Theme::instance()->wizardUrlPostfix().isEmpty()) { + _ui->urlLineEdit->setPostfix(Theme::instance()->wizardUrlPostfix()); + } } QString ServerUrlSetupWizardPage::userProvidedUrl() const { - return _ui->urlLineEdit->text(); + QString url = _ui->urlLineEdit->text(); + + if (!Theme::instance()->wizardUrlPostfix().isEmpty()) { + url += Theme::instance()->wizardUrlPostfix(); + } + + return url; } ServerUrlSetupWizardPage::~ServerUrlSetupWizardPage() diff --git a/src/gui/newwizard/pages/serverurlsetupwizardpage.ui b/src/gui/newwizard/pages/serverurlsetupwizardpage.ui index 76850ccf0..51930b6c0 100644 --- a/src/gui/newwizard/pages/serverurlsetupwizardpage.ui +++ b/src/gui/newwizard/pages/serverurlsetupwizardpage.ui @@ -127,7 +127,7 @@ </spacer> </item> <item> - <widget class="QLineEdit" name="urlLineEdit"> + <widget class="OCC::PostfixLineEdit" name="urlLineEdit"> <property name="sizePolicy"> <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -184,6 +184,13 @@ </item> </layout> </widget> + <customwidgets> + <customwidget> + <class>OCC::PostfixLineEdit</class> + <extends>QLineEdit</extends> + <header>postfixlineedit.h</header> + </customwidget> + </customwidgets> <resources/> <connections/> </ui> diff --git a/src/gui/newwizard/postfixlineedit.cpp b/src/gui/newwizard/postfixlineedit.cpp new file mode 100644 index 000000000..1cc44a248 --- /dev/null +++ b/src/gui/newwizard/postfixlineedit.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 by Daniel Molkentin <danimo@owncloud.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License + * for more details. + */ + +#include <QStyle> +#include <QStyleOptionFrame> + +#include "postfixlineedit.h" + +namespace OCC { + +const int horizontalMargin(4); +const int verticalMargin(4); + +PostfixLineEdit::PostfixLineEdit(QWidget *parent) + : QLineEdit(parent) +{ +} + +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 +{ + return _postfix; +} + +QString PostfixLineEdit::fullText() const +{ + return text() + _postfix; +} + +void PostfixLineEdit::setFullText(const QString &text) +{ + QString prefixString = text; + if (prefixString.endsWith(postfix())) { + prefixString.chop(postfix().length()); + } + setText(prefixString); +} + +void PostfixLineEdit::paintEvent(QPaintEvent *pe) +{ + 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/newwizard/postfixlineedit.h b/src/gui/newwizard/postfixlineedit.h new file mode 100644 index 000000000..1e8078f05 --- /dev/null +++ b/src/gui/newwizard/postfixlineedit.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2016 by Daniel Molkentin <danimo@owncloud.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License + * for more details. + */ + +#ifndef OCC_POSTFIXLINEEDIT_H +#define OCC_POSTFIXLINEEDIT_H + +#include <QLineEdit> +#include <QPaintEvent> +#include <QPainter> + +namespace OCC { + +/** + * @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); + + /** @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; + + /** @brief sets text() from full text, discarding prefix() */ + void setFullText(const QString &text); + +protected: + void paintEvent(QPaintEvent *pe) override; + +private: + QString _postfix; +}; + + +} // namespace OCC + +#endif // OCC_POSTFIXLINEEDIT_H |