Akonadi Contacts

webwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016 eyeOS S.L.U., a Telefonica company, [email protected]
5  SPDX-FileCopyrightText: 2016-2020 Laurent Montel <montel.org>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "webwidget.h"
11 #include "webselecttypecombobox.h"
12 #include <QHBoxLayout>
13 #include <QToolButton>
14 #include <QUrl>
15 #include <KLocalizedString>
16 #include <editor/widgets/preferredlineeditwidget.h>
17 using namespace ContactEditor;
18 
19 WebWidget::WebWidget(QWidget *parent)
20  : QWidget(parent)
21 {
22  QHBoxLayout *layout = new QHBoxLayout(this);
23  layout->setSpacing(0);
24  layout->setContentsMargins(0, 0, 0, 0);
25 
26  mWebSiteEdit = new PreferredLineEditWidget(this);
27  mWebSiteEdit->setTrapReturnKey(true);
28  mWebSiteEdit->setPlaceholderText(i18n("Add a Web Site"));
29  mWebSiteEdit->setObjectName(QStringLiteral("website"));
30  layout->addWidget(mWebSiteEdit);
31  connect(mWebSiteEdit, &PreferredLineEditWidget::preferredChanged, this, &WebWidget::slotPreferredChanged);
32 
33  mWebType = new ContactEditor::WebSelectTypeCombobox(this);
34  mWebType->setObjectName(QStringLiteral("webtype"));
35  layout->addWidget(mWebType);
36 
37  mAddButton = new QToolButton(this);
38  mAddButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
39  mAddButton->setObjectName(QStringLiteral("addbutton"));
40  mAddButton->setToolTip(i18n("Add a Web Site"));
41  connect(mAddButton, &QToolButton::clicked, this, &WebWidget::slotAddWeb);
42  layout->addWidget(mAddButton);
43 
44  mRemoveButton = new QToolButton(this);
45  mRemoveButton->setObjectName(QStringLiteral("removebutton"));
46  mRemoveButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
47  mRemoveButton->setToolTip(i18n("Remove Web Site"));
48  connect(mRemoveButton, &QToolButton::clicked, this, &WebWidget::slotRemoveWeb);
49  layout->addWidget(mRemoveButton);
50 }
51 
52 WebWidget::~WebWidget()
53 {
54 }
55 
56 void WebWidget::clearWidget()
57 {
58  mWebSiteEdit->clear();
59  mWebType->setCurrentIndex(0);
60 }
61 
62 void WebWidget::updateAddRemoveButton(bool addButtonEnabled)
63 {
64  mAddButton->setEnabled(addButtonEnabled);
65 }
66 
67 void WebWidget::slotAddWeb()
68 {
69  Q_EMIT addWidget(this);
70 }
71 
72 void WebWidget::slotRemoveWeb()
73 {
74  Q_EMIT removeWidget(this);
75 }
76 
77 void WebWidget::setPreferred(bool b)
78 {
79  mWebSiteEdit->setPreferred(b);
80 }
81 
82 KContacts::ResourceLocatorUrl WebWidget::url()
83 {
84  mUrl.setUrl(QUrl(mWebSiteEdit->text()));
85  mUrl.setPreferred(mWebSiteEdit->preferred());
86  mUrl.setType(KContacts::ResourceLocatorUrl::Type(mWebType->currentData().toInt()));
87  return mUrl;
88 }
89 
90 void WebWidget::loadWebSite(const KContacts::ResourceLocatorUrl &url)
91 {
92  mUrl = url;
93  setPreferred(url.isPreferred());
94  mWebType->setCurrentIndex(mWebType->findData((int)url.type()));
95  mWebSiteEdit->setText(mUrl.url().toDisplayString());
96 }
97 
98 void WebWidget::setReadOnly(bool readOnly)
99 {
100  mWebSiteEdit->setReadOnly(readOnly);
101  mAddButton->setEnabled(!readOnly);
102  mRemoveButton->setEnabled(!readOnly);
103  mWebType->setEnabled(!readOnly);
104 }
105 
106 void WebWidget::slotPreferredChanged()
107 {
108  Q_EMIT preferredChanged(this);
109 }
void setContentsMargins(int left, int top, int right, int bottom)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void clicked(bool checked)
void setPreferred(bool preferred)
QString i18n(const char *text, const TYPE &arg...)
QIcon fromTheme(const QString &name)
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 23:09:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.