not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kcontrol / kfontinst / kcmfontinst / ActionDialog.cpp
bloba439df1866fba1b272f7bafa1e3b9470415fdf1e
1 /*
2 * KFontInst - KDE Font Installer
4 * Copyright 2003-2007 Craig Drummond <craig@kde.org>
6 * ----
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 "ActionDialog.h"
25 #include <KDE/KIconLoader>
26 #include <QtGui/QLabel>
27 #include <QtCore/QTimer>
28 #include <QtGui/QPixmap>
29 #include <QtGui/QMatrix>
31 namespace KFI
34 // Borrowed from kolourpaint...
35 static QMatrix matrixWithZeroOrigin(const QMatrix &matrix, int width, int height)
37 QRect newRect(matrix.mapRect(QRect(0, 0, width, height)));
39 return QMatrix(matrix.m11(), matrix.m12(), matrix.m21(), matrix.m22(),
40 matrix.dx() - newRect.left(), matrix.dy() - newRect.top());
43 static QMatrix rotateMatrix(int width, int height, double angle)
45 QMatrix matrix;
46 matrix.translate(width/2, height/2);
47 matrix.rotate(angle);
49 return matrixWithZeroOrigin(matrix, width, height);
52 static const int constNumIcons=8;
53 static int theUsageCount;
54 static QPixmap *theIcons[constNumIcons];
56 CActionDialog::CActionDialog(QWidget *parent)
57 : KDialog(parent)
59 static const int constIconSize(48);
61 setModal(true);
62 itsPixmapLabel=new QLabel(this);
63 itsPixmapLabel->setMinimumSize(constIconSize, constIconSize);
64 itsPixmapLabel->setMaximumSize(constIconSize, constIconSize);
65 itsPixmapLabel->setAlignment(Qt::AlignCenter);
67 if(0==theUsageCount++)
69 QImage img(KIconLoader::global()->loadIcon("application-x-font-ttf", KIconLoader::NoGroup, 32).toImage());
70 double increment=360.0/constNumIcons;
72 for(int i=0; i<constNumIcons; ++i)
73 theIcons[i]=new QPixmap(QPixmap::fromImage(0==i ? img : img.transformed(rotateMatrix(img.width(), img.height(), increment*i))));
76 itsPixmapLabel->setPixmap(*theIcons[0]);
77 itsTimer=new QTimer(this);
78 connect(itsTimer, SIGNAL(timeout()), SLOT(rotateIcon()));
81 CActionDialog::~CActionDialog()
83 if(0==--theUsageCount)
84 for(int i=0; i<constNumIcons; ++i)
86 delete theIcons[i];
87 theIcons[i]=NULL;
91 int CActionDialog::exec()
93 startAnimation();
94 return KDialog::exec();
97 void CActionDialog::startAnimation()
99 itsCount=0;
100 itsPixmapLabel->setPixmap(*theIcons[0]);
101 itsTimer->start(1000/constNumIcons);
104 void CActionDialog::stopAnimation()
106 itsTimer->stop();
107 itsCount=0;
108 itsPixmapLabel->setPixmap(*theIcons[itsCount]);
111 void CActionDialog::rotateIcon()
113 if(++itsCount==constNumIcons)
114 itsCount=0;
116 itsPixmapLabel->setPixmap(*theIcons[itsCount]);
121 #include "ActionDialog.moc"