1 | /* |
2 | Copyright (c) 2012-2013 Montel Laurent <montel@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "selectspecialchar.h" |
21 | #include <KCharSelect> |
22 | #include <KLocalizedString> |
23 | #include <QHBoxLayout> |
24 | |
25 | namespace KPIMTextEdit { |
26 | |
27 | class SelectSpecialCharPrivate |
28 | { |
29 | public: |
30 | SelectSpecialCharPrivate( SelectSpecialChar *qq ) |
31 | : q( qq ) |
32 | { |
33 | q->setCaption( i18n( "Select Special Characters" ) ); |
34 | q->setButtons( KDialog::Ok|KDialog::Cancel|KDialog::User1 ); |
35 | q->setButtonText( KDialog::User1, i18n( "Select" ) ); |
36 | QWidget *page = new QWidget( q ); |
37 | q->setMainWidget( page ); |
38 | QHBoxLayout *lay = new QHBoxLayout( page ); |
39 | mCharSelect = new KCharSelect( q, 0, KCharSelect::CharacterTable|KCharSelect::BlockCombos ); |
40 | q->connect( mCharSelect, SIGNAL(charSelected(QChar)), |
41 | q, SIGNAL(charSelected(QChar)) ); |
42 | lay->addWidget( mCharSelect ); |
43 | q->connect( q, SIGNAL(user1Clicked()), |
44 | q, SLOT(_k_slotInsertChar()) ); |
45 | q->connect( q, SIGNAL(okClicked()), |
46 | q, SLOT(_k_slotInsertChar()) ); |
47 | } |
48 | |
49 | void _k_slotInsertChar(); |
50 | |
51 | KCharSelect *mCharSelect; |
52 | SelectSpecialChar *q; |
53 | }; |
54 | |
55 | void SelectSpecialCharPrivate::_k_slotInsertChar() |
56 | { |
57 | Q_EMIT q->charSelected( mCharSelect->currentChar() ); |
58 | } |
59 | |
60 | SelectSpecialChar::SelectSpecialChar( QWidget *parent ) |
61 | : KDialog( parent ), d( new SelectSpecialCharPrivate( this ) ) |
62 | { |
63 | } |
64 | |
65 | SelectSpecialChar::~SelectSpecialChar() |
66 | { |
67 | delete d; |
68 | } |
69 | |
70 | void SelectSpecialChar::showSelectButton( bool show ) |
71 | { |
72 | if ( show ) { |
73 | setButtons( Ok|Cancel|User1 ); |
74 | } else { |
75 | setButtons( Ok|Cancel ); |
76 | } |
77 | } |
78 | |
79 | void SelectSpecialChar::setCurrentChar( const QChar &c ) |
80 | { |
81 | d->mCharSelect->setCurrentChar(c); |
82 | } |
83 | |
84 | QChar SelectSpecialChar::currentChar() const |
85 | { |
86 | return d->mCharSelect->currentChar(); |
87 | } |
88 | |
89 | void SelectSpecialChar::autoInsertChar() |
90 | { |
91 | connect( d->mCharSelect, SIGNAL(charSelected(QChar)), SLOT(accept()) ); |
92 | } |
93 | |
94 | void SelectSpecialChar::setOkButtonText( const QString &text ) |
95 | { |
96 | setButtonText( KDialog::User1, text ); |
97 | } |
98 | |
99 | } |
100 | |
101 | #include "moc_selectspecialchar.cpp" |
102 | |