krita

kis_text_brush.cc

00001 /*
00002  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018  
00019 #include <qfontmetrics.h>
00020 #include <qpainter.h>
00021 #include <qspinbox.h>
00022 #include <qcheckbox.h> 
00023 #include <qlabel.h>
00024 
00025 #include <kfontdialog.h>
00026 
00027 #include <klineedit.h>
00028 #include "kis_text_brush.h"
00029 
00030 void KisTextBrushResource::updateBrush()
00031 {
00032     QFontMetrics metric(m_font);
00033     int w = metric.width(m_txt);
00034     int h = metric.height();
00035     QPixmap px(w,h);
00036     QPainter p;
00037     p.begin(&px);
00038     p.setFont( m_font );
00039     p.fillRect(0,0, w, h, Qt::white);
00040     p.setPen(Qt::black);
00041     p.drawText(0, metric.ascent(), m_txt );
00042     p.end();
00043     setImage(px.convertToImage ());
00044 }
00045 
00046 KisTextBrush::KisTextBrush(QWidget *parent, const char* name, const QString& caption) 
00047     : KisWdgTextBrush(parent, name), 
00048       m_textBrushResource(new KisTextBrushResource())
00049 {
00050     setCaption(caption);
00051     connect((QObject*)lineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(rebuildTextBrush()));
00052     connect((QObject*)bnFont, SIGNAL(clicked()), this, SLOT(getFont()));
00053     m_font = font();
00054     rebuildTextBrush();
00055 }
00056 
00057 
00058 void KisTextBrush::getFont()
00059 {
00060     KFontDialog::getFont( m_font, false/*, QWidget* parent! */ );
00061     rebuildTextBrush();
00062 }
00063 
00064 void KisTextBrush::rebuildTextBrush()
00065 {
00066     lblFont->setText(QString(m_font.family() + ", %1").arg(m_font.pointSize()));
00067     lblFont->setFont(m_font);
00068     m_textBrushResource->setFont(m_font);
00069     m_textBrushResource->setText(lineEdit->text());
00070     m_textBrushResource->updateBrush();
00071     emit(activatedResource(m_textBrushResource));
00072 }
00073 
00074 #include "kis_text_brush.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys