2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; see the file COPYING. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 #include "FontPreview.h"
27 #include <KDE/KApplication>
28 #include <KDE/KLocale>
29 #include <QtGui/QPainter>
30 #include <QtGui/QPaintEvent>
31 #include <QtGui/QMouseEvent>
32 #include <QtGui/QWheelEvent>
38 static const int constBorder
=4;
39 static const int constStepSize
=16;
41 CFontPreview::CFontPreview(QWidget
*parent
)
46 itsStyleInfo(KFI_NO_STYLE_INFO
),
49 itsEngine
=new CFcEngine
;
52 CFontPreview::~CFontPreview()
57 void CFontPreview::showFont(const KUrl
&url
, const QString
&name
, unsigned long styleInfo
,
62 itsStyleInfo
=styleInfo
;
66 void CFontPreview::showFace(int face
)
72 void CFontPreview::showFont()
74 itsLastWidth
=width()+constStepSize
;
75 itsLastHeight
=height()+constStepSize
;
77 if(!itsCurrentUrl
.isEmpty() &&
78 itsEngine
->draw(itsCurrentUrl
, itsLastWidth
, itsLastHeight
, itsPixmap
,
79 itsCurrentFace
, false, itsRange
, &itsChars
, itsFontName
,
82 itsLastChar
=CFcEngine::TChar();
83 setMouseTracking(itsChars
.count()>0);
92 itsLastChar
=CFcEngine::TChar();
93 setMouseTracking(false);
99 void CFontPreview::zoomIn()
105 void CFontPreview::zoomOut()
107 itsEngine
->zoomOut();
111 void CFontPreview::setUnicodeRange(const QList
<CFcEngine::TRange
> &r
)
117 void CFontPreview::paintEvent(QPaintEvent
*)
119 QPainter
paint(this);
121 paint
.fillRect(rect(), palette().base());
122 if(!itsPixmap
.isNull())
125 if(abs(width()-itsLastWidth
)>constStepSize
|| abs(height()-itsLastHeight
)>constStepSize
)
128 paint
.drawPixmap(QPoint(constBorder
, constBorder
), itsPixmap
,
129 QRect(0, 0, width()-(constBorder
*2), height()-(constBorder
*2)));
133 void CFontPreview::mouseMoveEvent(QMouseEvent
*event
)
137 QList
<CFcEngine::TChar
>::ConstIterator
end(itsChars
.end());
139 if(itsLastChar
.isNull() || !itsLastChar
.contains(event
->pos()))
140 for(QList
<CFcEngine::TChar
>::ConstIterator
it(itsChars
.begin()); it
!=end
; ++it
)
141 if((*it
).contains(event
->pos()))
144 itsTip
=new CCharTip(this);
146 itsTip
->setItem(*it
);
153 void CFontPreview::wheelEvent(QWheelEvent
*e
)
157 else if(e
->delta()<0)
163 QSize
CFontPreview::sizeHint() const
165 return QSize(132, 132);
168 QSize
CFontPreview::minimumSizeHint() const
170 return QSize(32, 32);
175 #include "FontPreview.moc"