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 "ActionDialog.h"
25 #include <KDE/KIconLoader>
26 #include <QtGui/QLabel>
27 #include <QtCore/QTimer>
28 #include <QtGui/QPixmap>
29 #include <QtGui/QMatrix>
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
)
46 matrix
.translate(width
/2, height
/2);
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
)
59 static const int constIconSize(48);
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
)
91 int CActionDialog::exec()
94 return KDialog::exec();
97 void CActionDialog::startAnimation()
100 itsPixmapLabel
->setPixmap(*theIcons
[0]);
101 itsTimer
->start(1000/constNumIcons
);
104 void CActionDialog::stopAnimation()
108 itsPixmapLabel
->setPixmap(*theIcons
[itsCount
]);
111 void CActionDialog::rotateIcon()
113 if(++itsCount
==constNumIcons
)
116 itsPixmapLabel
->setPixmap(*theIcons
[itsCount
]);
121 #include "ActionDialog.moc"