KoCharSelectDia.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@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
20#include "KoCharSelectDia.h"
21#include "KoCharSelectDia.moc"
22
23#include <tqlayout.h>
24
25#include <tdelocale.h>
26#include <kcharselect.h>
27#include <kdebug.h>
28/******************************************************************/
29/* class KoCharSelectDia */
30/******************************************************************/
31
32KoCharSelectDia::KoCharSelectDia( TQWidget *parent, const char *name, const TQChar &_chr, const TQString &_font, bool _enableFont , bool _modal)
33 : KDialogBase( Plain, i18n("Select Character"), Ok | Cancel, Ok , parent, name, _modal )
34{
35 initDialog(_chr,_font,_enableFont);
36
37 KGuiItem okItem = KStdGuiItem::ok(); // start from std item to keep the OK icon...
38 okItem.setText( i18n("&Insert") );
39 okItem.setWhatsThis( i18n("Insert the selected character in the text") );
40 setButtonOK( okItem );
41}
42
43KoCharSelectDia::KoCharSelectDia( TQWidget *parent, const char *name, const TQString &_font, const TQChar &_chr, bool _modal )
44 : KDialogBase( Plain, i18n("Select Character"), User1 | Close, User1 , parent, name, _modal )
45{
46 initDialog(_chr,_font,true);
47
48 setButtonText( User1, i18n("&Insert") );
49 setButtonTip( User1, i18n("Insert the selected character in the text") );
50
51}
52
53void KoCharSelectDia::initDialog(const TQChar &_chr, const TQString &_font, bool /*_enableFont*/)
54{
55 TQWidget *page = plainPage();
56
57 grid = new TQGridLayout( page, 1, 1, 0, KDialog::spacingHint() );
58
59 charSelect = new KCharSelect( page, "", _font, _chr );
60 connect(charSelect, TQ_SIGNAL(doubleClicked()),this, TQ_SLOT(slotDoubleClicked()));
61 charSelect->resize( charSelect->sizeHint() );
62 charSelect->enableFontCombo( true );
63 grid->addWidget( charSelect, 0, 0 );
64
65 grid->addColSpacing( 0, charSelect->width() );
66 grid->addRowSpacing( 0, charSelect->height() );
67 grid->setRowStretch( 0, 0 );
68 charSelect->setFocus();
69}
70
71KoCharSelectDia::~KoCharSelectDia()
72{
73}
74
75void KoCharSelectDia::closeDialog()
76{
77 KDialogBase::close();
78}
79
80bool KoCharSelectDia::selectChar( TQString &_font, TQChar &_chr, bool _enableFont, TQWidget* parent, const char* name )
81{
82 bool res = false;
83
84 KoCharSelectDia *dlg = new KoCharSelectDia( parent, name, _chr, _font, _enableFont );
85 dlg->setFocus();
86 if ( dlg->exec() == Accepted )
87 {
88 _font = dlg->font();
89 _chr = dlg->chr();
90 res = true;
91 }
92
93 delete dlg;
94
95 return res;
96}
97
98TQChar KoCharSelectDia::chr() const
99{
100 return charSelect->chr();
101}
102
103TQString KoCharSelectDia::font() const
104{
105 return charSelect->font();
106}
107
108void KoCharSelectDia::slotUser1()
109{
110 emit insertChar(chr(),font());
111}
112
113void KoCharSelectDia::slotDoubleClicked()
114{
115 emit insertChar(chr(),font());
116}
static int spacingHint()
const char * name(StdAction id)