Akonadi Contacts

preferredlineeditwidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "preferredlineeditwidget.h"
10#include <KLocalizedString>
11#include <QAction>
12
13using namespace Akonadi;
14
15PreferredLineEditWidget::PreferredLineEditWidget(QWidget *parent)
16 : KLineEdit(parent)
17{
18 mIconEnabled = QIcon::fromTheme(QStringLiteral("rating"));
19 mIconDisabled = QIcon::fromTheme(QStringLiteral("rating-unrated"));
20 mPreferredAction = addAction(mIconDisabled, QLineEdit::TrailingPosition);
21 mPreferredAction->setObjectName(QLatin1StringView("preferredaction"));
22 mPreferredAction->setToolTip(i18nc("@info:tooltip", "Set as Preferred"));
23 connect(mPreferredAction, &QAction::triggered, this, &PreferredLineEditWidget::slotPreferredStatusChanged);
24}
25
26PreferredLineEditWidget::~PreferredLineEditWidget() = default;
27
28void PreferredLineEditWidget::slotPreferredStatusChanged()
29{
30 if (isReadOnly()) {
31 return;
32 }
33 mPreferred = !mPreferred;
34 updatePreferredIcon();
35 Q_EMIT preferredChanged(this);
36}
37
38void PreferredLineEditWidget::updatePreferredIcon()
39{
40 mPreferredAction->setIcon(mPreferred ? mIconEnabled : mIconDisabled);
41}
42
43void PreferredLineEditWidget::setPreferred(bool preferred)
44{
45 if (mPreferred != preferred) {
46 mPreferred = preferred;
47 updatePreferredIcon();
48 }
49}
50
51bool PreferredLineEditWidget::preferred() const
52{
53 return mPreferred;
54}
55
56#include "moc_preferredlineeditwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
void setIcon(const QIcon &icon)
void triggered(bool checked)
QIcon fromTheme(const QString &name)
bool isReadOnly() const const
Q_EMITQ_EMIT
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.