1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Helge Deller <deller@gmx.de>
4 2002 Lubos Lunak <llunak@suse.cz>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21
22#ifndef KABC_ADDRESSLINEEDIT_H
23#define KABC_ADDRESSLINEEDIT_H
24
25#include "kabc_export.h"
26#include <kcompletion.h>
27#include <klineedit.h>
28#include <QtCore/QObject>
29
30namespace KABC {
31
32/**
33 * A lineedit with kabc completion
34 *
35 * This lineedit is supposed to be used wherever the user types email addresses
36 * and might want a completion. You can simply use it as a replacement for
37 * KLineEdit or QLineEdit.
38 *
39 * You can enable or disable the lineedit at any time.
40 *
41 * @see AddressLineEdit::enableCompletion()
42 */
43class KABC_DEPRECATED_EXPORT AddressLineEdit : public KLineEdit
44{
45 Q_OBJECT
46
47 public:
48 /**
49 * Creates the line edit instance.
50 *
51 * @param parent The QWidget parent
52 * @param useCompletion Whether to use address completion.
53 * See enableCompletion()
54 */
55 explicit AddressLineEdit( QWidget *parent, bool useCompletion = true );
56
57 /**
58 * Destroys the instance.
59 */
60 virtual ~AddressLineEdit();
61
62 /**
63 * Reimplemented for internal reasons.
64 * @param font The font to use
65 * @see KLineEdit::setFont()
66 */
67 virtual void setFont( const QFont &font );
68
69 public Q_SLOTS:
70 /**
71 * Set cursor to end of line.
72 */
73 void cursorAtEnd();
74
75 /**
76 * Toggle completion.
77 *
78 * @param enable When @c true address completion will be enabled, when
79 * @c false it will be disabled
80 */
81 void enableCompletion( bool enable );
82
83 protected:
84 /**
85 * Always call AddressLineEdit::loadAddresses() as the first thing.
86 * Use addAddress() to add addresses.
87 */
88 virtual void loadAddresses();
89
90 /**
91 * Adds a new address to the line edit.
92 *
93 * Adds the given string to the completion handler and additionally the
94 * email part if the string contains name + address in the angle bracket
95 * notation.
96 *
97 * @param addr The address to add
98 */
99 void addAddress( const QString &addr );
100
101 /**
102 * Handles KDE completion short cuts
103 *
104 * @param e The key event to check
105 *
106 * @see KStandardShortcut::SubstringCompletion
107 * @see KStandardShortcut::TextCompletion
108 */
109 virtual void keyPressEvent( QKeyEvent *e );
110
111 /**
112 * Handles drop events.
113 *
114 * Creates a list of addresses separated by @c ',' from a "URI List" drop.
115 * Enables smart paste for anything else before relaying the event to
116 * the base class.
117 * See insert() for information on smart paste.
118 *
119 * @param e The drop event
120 *
121 * @see enableCompletion()
122 */
123 virtual void dropEvent( QDropEvent *e );
124
125 /**
126 * Pastes the clipboard content.
127 *
128 * Enables smart paste if completion is enabled.
129 * See insert() for information on smart paste.
130 *
131 * @see enableCompletion()
132 */
133 virtual void paste();
134
135 /**
136 * Inserts the given string.
137 *
138 * If smart paste is enabled, the text will be parsed for possible
139 * email address parts, i.e.
140 * either a mailto: URI or "spam protected" like "developer at kde dot org"
141 *
142 * @param addr The string to insert
143 */
144 virtual void insert( const QString &addr );
145
146 /**
147 * Enables smart paste for X11 middle mouse text paste if completion is
148 * enabled.
149 *
150 * See insert() for information about smart paste.
151 *
152 * @param e The mouse release event
153 *
154 * @see enableCompletion()
155 */
156 virtual void mouseReleaseEvent( QMouseEvent *e );
157
158 /**
159 * Triggers looking for a completion of the address or the last
160 * address if there are already more than one separated by @c ','
161 */
162 void doCompletion( bool );
163
164 private:
165 class Private;
166 Private *const d;
167
168 Q_PRIVATE_SLOT( d, void slotCompletion() )
169 Q_PRIVATE_SLOT( d, void slotPopupCompletion( const QString &completion ) )
170};
171
172}
173
174#endif
175