Incidenceeditor

attendeelineeditdelegate.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
5 */
6
7#include "attendeelineeditdelegate.h"
8
9#include "attendeeline.h"
10
11#include <KLocalizedString>
12
13#include <QAbstractItemView>
14#include <QHelpEvent>
15#include <QToolTip>
16#include <QWhatsThis>
17
18using namespace IncidenceEditorNG;
19
20AttendeeLineEditDelegate::AttendeeLineEditDelegate(QObject *parent)
21 : QStyledItemDelegate(parent)
22 , mToolTip(i18nc("@info:tooltip", "Enter the name or email address of the attendee."))
23 , mWhatsThis(i18nc("@info:whatsthis",
24 "The email address or name of the attendee. An invitation "
25 "can be sent to the user if an email address is provided."))
26{
27}
28
29QWidget *AttendeeLineEditDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
30{
31 Q_UNUSED(option)
32 Q_UNUSED(index)
33 auto editor = new AttendeeLineEdit(parent);
34 connect(editor, &AttendeeLineEdit::leftPressed, this, &AttendeeLineEditDelegate::leftPressed);
35 connect(editor, &AttendeeLineEdit::rightPressed, this, &AttendeeLineEditDelegate::rightPressed);
36 editor->setToolTip(mToolTip);
37 editor->setWhatsThis(mWhatsThis);
38 editor->setCompletionMode(mCompletionMode);
39 editor->setClearButtonEnabled(true);
40
41 return editor;
42}
43
44void AttendeeLineEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
45{
46 auto lineedit = static_cast<AttendeeLineEdit *>(editor);
47 lineedit->setText(index.model()->data(index, Qt::EditRole).toString());
48}
49
50void AttendeeLineEditDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
51{
52 auto lineedit = static_cast<AttendeeLineEdit *>(editor);
53 model->setData(index, lineedit->text(), Qt::EditRole);
54}
55
56void AttendeeLineEditDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
57{
58 Q_UNUSED(index)
59 editor->setGeometry(option.rect);
60}
61
62void AttendeeLineEditDelegate::leftPressed()
63{
65}
66
67void AttendeeLineEditDelegate::rightPressed()
68{
70}
71
72void AttendeeLineEditDelegate::setCompletionMode(KCompletion::CompletionMode mode)
73{
74 mCompletionMode = mode;
75}
76
77bool AttendeeLineEditDelegate::helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
78{
79 if (!event || !view) {
80 return false;
81 }
82 switch (event->type()) {
83#ifndef QT_NO_TOOLTIP
84 case QEvent::ToolTip:
85 QToolTip::showText(event->globalPos(), mToolTip, view);
86 return true;
87#endif
88#ifndef QT_NO_WHATSTHIS
90 return true;
92 QWhatsThis::showText(event->globalPos(), mWhatsThis, view);
93 return true;
94#endif
95 default:
96 break;
97 }
98 return QStyledItemDelegate::helpEvent(event, view, option, index);
99}
100
101#include "moc_attendeelineeditdelegate.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHint hint)
virtual bool helpEvent(QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index)
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
const QAbstractItemModel * model() const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
virtual bool event(QEvent *e)
QObject * parent() const const
T qobject_cast(QObject *object)
QObject * sender() const const
EditRole
void showText(const QPoint &pos, const QString &text, QWidget *w, const QRect &rect, int msecDisplayTime)
QString toString() const const
void showText(const QPoint &pos, const QString &text, QWidget *w)
void setGeometry(const QRect &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.