Akonadi Contacts

preferredlineeditwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2016-2021 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "preferredlineeditwidget.h"
10 #include <KLocalizedString>
11 #include <QAction>
12 
13 using namespace ContactEditor;
14 
15 PreferredLineEditWidget::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(QStringLiteral("preferredaction"));
22  mPreferredAction->setToolTip(i18n("Set as Preferred"));
23  connect(mPreferredAction, &QAction::triggered, this, &PreferredLineEditWidget::slotPreferredStatusChanged);
24 }
25 
26 PreferredLineEditWidget::~PreferredLineEditWidget()
27 {
28 }
29 
30 void PreferredLineEditWidget::slotPreferredStatusChanged()
31 {
32  if (isReadOnly()) {
33  return;
34  }
35  mPreferred = !mPreferred;
36  updatePreferredIcon();
37  Q_EMIT preferredChanged(this);
38 }
39 
40 void PreferredLineEditWidget::updatePreferredIcon()
41 {
42  mPreferredAction->setIcon(mPreferred ? mIconEnabled : mIconDisabled);
43 }
44 
45 void PreferredLineEditWidget::setPreferred(bool preferred)
46 {
47  if (mPreferred != preferred) {
48  mPreferred = preferred;
49  updatePreferredIcon();
50  }
51 }
52 
53 bool PreferredLineEditWidget::preferred() const
54 {
55  return mPreferred;
56 }
void triggered(bool checked)
void addAction(QAction *action)
QString i18n(const char *text, const TYPE &arg...)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.