1 /* This file is part of the KDE project
2  * Copyright (C) 2007 Thomas Zander <zander@kde.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public 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
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #include "InsertCharacter.h"
20 
21 #include <klocalizedstring.h>
22 #include <kcharselect.h>
23 
24 #include <QMainWindow>
25 #include <QGridLayout>
26 #include <QPushButton>
27 
InsertCharacter(QWidget * parent)28 InsertCharacter::InsertCharacter(QWidget *parent)
29     : QDockWidget(i18n("Special Characters"))
30 {
31     QWidget *specialCharacterWidget = new QWidget();
32     QGridLayout *lay = new QGridLayout(specialCharacterWidget);
33     lay->setMargin(6);
34     m_charSelector = new KCharSelect(specialCharacterWidget,
35                                      0,
36                                      KCharSelect::SearchLine | KCharSelect::FontCombo | KCharSelect::BlockCombos |
37                                      KCharSelect::CharacterTable | KCharSelect::DetailBrowser);
38     lay->addWidget(m_charSelector, 0, 0, 1, 3);
39     QPushButton *insert = new QPushButton(i18n("Insert"), specialCharacterWidget);
40     lay->addWidget(insert, 1, 1);
41     QPushButton *close = new QPushButton(i18nc("Close dialog", "Close"), specialCharacterWidget);
42     lay->addWidget(close, 1, 2);
43     lay->setColumnStretch(0, 9);
44 
45     setObjectName("insertSpecialCharacter");
46     setWidget(specialCharacterWidget);
47     while (parent->parentWidget()) {
48         parent = parent->parentWidget();
49     }
50     QMainWindow *mw = dynamic_cast<QMainWindow *>(parent);
51     if (mw) {
52         mw->addDockWidget(Qt::TopDockWidgetArea, this);
53     }
54     setFloating(true);
55 
56     connect(close, SIGNAL(released()), this, SLOT(hide()));
57     connect(insert, SIGNAL(released()), this, SLOT(insertCharacter()));
58     connect(m_charSelector, SIGNAL(charSelected(QChar)), this, SLOT(insertCharacter()));
59 }
60 
insertCharacter()61 void InsertCharacter::insertCharacter()
62 {
63     emit insertCharacter(QString(m_charSelector->currentChar()));
64 }
65