compile with Exiv2 < 0.18
[kdegraphics.git] / kgamma / kcmkgamma / displaynumber.cpp
blob1a5da4a5cae31d6e613eae986a2a9709c515dcd7
1 /***************************************************************************
2 displaynumber.cpp - description
3 -------------------
4 begin : Sun Feb 23 2003
5 copyright : (C) 2003 by Michael v.Ostheim
6 email : ostheimm@users.berlios.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include <qstring.h>
19 #include <qfontmetrics.h>
20 //Added by qt3to4:
21 #include <QLabel>
22 #include <QFrame>
24 #include "displaynumber.h"
26 DisplayNumber::DisplayNumber(QWidget *parent, int digits, int prec)
27 : QLabel(parent) {
29 setPrecision(prec);
30 setWidth(digits);
32 setFrameStyle(QFrame::Panel | QFrame::Sunken);
33 setBackgroundRole(QPalette::Base);
34 setAlignment(Qt::AlignCenter);
35 setFocusPolicy(Qt::NoFocus);
38 DisplayNumber::~DisplayNumber(){
41 void DisplayNumber::setFont( const QFont & f ) {
42 QLabel::setFont(f);
43 setWidth(dg);
46 void DisplayNumber::setWidth(int digits) {
47 QFontMetrics fm(font());
48 QString s("0123456789.+-");
49 int width = 0, charWidth=0;
51 for (int i = 0; i < 11; i++, width = fm.width(s[i]))
52 charWidth = (width > charWidth) ? width : charWidth;
54 dg = digits;
55 setMinimumWidth( dg * charWidth + charWidth/2 );
58 void DisplayNumber::setNum(double num) {
59 QString text;
60 setText(text.setNum(num, 'f', precision));
64 #include "displaynumber.moc"