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, sales@eyeos.com
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 "editor/widgets/preferredlineeditwidget.h"
12#include "webselecttypecombobox.h"
13#include <KLocalizedString>
14#include <QHBoxLayout>
15#include <QToolButton>
16#include <QUrl>
17using namespace Akonadi;
18
19WebWidget::WebWidget(QWidget *parent)
20 : QWidget(parent)
21 , mWebSiteEdit(new PreferredLineEditWidget(this))
22 , mAddButton(new QToolButton(this))
23 , mRemoveButton(new QToolButton(this))
24 , mWebType(new Akonadi::WebSelectTypeCombobox(this))
25{
26 auto layout = new QHBoxLayout(this);
27 layout->setSpacing(0);
28 layout->setContentsMargins({});
29
30 mWebSiteEdit->setTrapReturnKey(true);
31 mWebSiteEdit->setPlaceholderText(i18nc("@info:placeholder", "Add a Web Site"));
32 mWebSiteEdit->setObjectName(QLatin1StringView("website"));
33 layout->addWidget(mWebSiteEdit);
34 connect(mWebSiteEdit, &PreferredLineEditWidget::preferredChanged, this, &WebWidget::slotPreferredChanged);
35
36 mWebType->setObjectName(QLatin1StringView("webtype"));
37 layout->addWidget(mWebType);
38
39 mAddButton->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
40 mAddButton->setObjectName(QLatin1StringView("addbutton"));
41 mAddButton->setToolTip(i18nc("@info:tooltip", "Add a Web Site"));
42 connect(mAddButton, &QToolButton::clicked, this, &WebWidget::slotAddWeb);
43 layout->addWidget(mAddButton);
44
45 mRemoveButton->setObjectName(QLatin1StringView("removebutton"));
46 mRemoveButton->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
47 mRemoveButton->setToolTip(i18nc("@info:tooltip", "Remove Web Site"));
48 connect(mRemoveButton, &QToolButton::clicked, this, &WebWidget::slotRemoveWeb);
49 layout->addWidget(mRemoveButton);
50}
51
52WebWidget::~WebWidget() = default;
53
54void WebWidget::clearWidget()
55{
56 mWebSiteEdit->clear();
57 mWebType->setCurrentIndex(0);
58}
59
60void WebWidget::updateAddRemoveButton(bool addButtonEnabled)
61{
62 mAddButton->setEnabled(addButtonEnabled);
63}
64
65void WebWidget::slotAddWeb()
66{
67 Q_EMIT addWidget(this);
68}
69
70void WebWidget::slotRemoveWeb()
71{
72 Q_EMIT removeWidget(this);
73}
74
75void WebWidget::setPreferred(bool b)
76{
77 mWebSiteEdit->setPreferred(b);
78}
79
80KContacts::ResourceLocatorUrl WebWidget::url()
81{
82 mUrl.setUrl(QUrl(mWebSiteEdit->text().trimmed()));
83 mUrl.setPreferred(mWebSiteEdit->preferred());
85 return mUrl;
86}
87
88void WebWidget::loadWebSite(const KContacts::ResourceLocatorUrl &url)
89{
90 mUrl = url;
91 setPreferred(url.isPreferred());
92 mWebType->setCurrentIndex(mWebType->findData((int)url.type()));
93 mWebSiteEdit->setText(mUrl.url().toDisplayString());
94}
95
96void WebWidget::setReadOnly(bool readOnly)
97{
98 mWebSiteEdit->setReadOnly(readOnly);
99 mAddButton->setEnabled(!readOnly);
100 mRemoveButton->setEnabled(!readOnly);
101 mWebType->setEnabled(!readOnly);
102}
103
104void WebWidget::slotPreferredChanged()
105{
106 Q_EMIT preferredChanged(this);
107}
108
109#include "moc_webwidget.cpp"
void setPreferred(bool preferred)
virtual void setReadOnly(bool)
virtual void setText(const QString &)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void clicked(bool checked)
void setCurrentIndex(int index)
int findData(const QVariant &data, int role, Qt::MatchFlags flags) const const
QIcon fromTheme(const QString &name)
void clear()
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.