chalk

kis_text_brush.cpp
1/*
2 * Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program 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
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include <tqfontmetrics.h>
20#include <tqpainter.h>
21#include <tqspinbox.h>
22#include <tqcheckbox.h>
23#include <tqlabel.h>
24
25#include <tdefontdialog.h>
26
27#include <klineedit.h>
28#include "kis_text_brush.h"
29
30void KisTextBrushResource::updateBrush()
31{
32 TQFontMetrics metric(m_font);
33 int w = metric.width(m_txt);
34 int h = metric.height();
35 TQPixmap px(w,h);
36 TQPainter p;
37 p.begin(&px);
38 p.setFont( m_font );
39 p.fillRect(0,0, w, h, TQt::white);
40 p.setPen(TQt::black);
41 p.drawText(0, metric.ascent(), m_txt );
42 p.end();
43 setImage(px.convertToImage ());
44}
45
46KisTextBrush::KisTextBrush(TQWidget *parent, const char* name, const TQString& caption)
47 : KisWdgTextBrush(parent, name),
48 m_textBrushResource(new KisTextBrushResource())
49{
50 setCaption(caption);
51 connect((TQObject*)lineEdit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rebuildTextBrush()));
52 connect((TQObject*)bnFont, TQ_SIGNAL(clicked()), this, TQ_SLOT(getFont()));
53 m_font = font();
54 rebuildTextBrush();
55}
56
57
58void KisTextBrush::getFont()
59{
60 TDEFontDialog::getFont( m_font, false/*, TQWidget* parent! */ );
61 rebuildTextBrush();
62}
63
64void KisTextBrush::rebuildTextBrush()
65{
66 lblFont->setText(TQString(m_font.family() + ", %1").arg(m_font.pointSize()));
67 lblFont->setFont(m_font);
68 m_textBrushResource->setFont(m_font);
69 m_textBrushResource->setText(lineEdit->text());
70 m_textBrushResource->updateBrush();
71 emit(activatedResource(m_textBrushResource));
72}
73
74#include "kis_text_brush.moc"