PSQt/src/puff.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------------------------
00002 // File and Version Information:
00003 //   $Id: puff.cpp 9841 2015-03-26 18:35:44Z dubrovin@SLAC.STANFORD.EDU $
00004 //
00005 // Author: Mikhail S. Dubrovin
00006 //---------------------------------------------------------------------
00007 
00008 #include "PSQt/puff.h"
00009 #include <QApplication>
00010 #include <QPainter>
00011 #include <QPainterPath>
00012 #include <QTimer>
00013 #include <iostream>
00014 
00015 namespace PSQt {
00016 
00017 Puff::Puff(QWidget *parent)
00018     : QWidget(parent)
00019 {
00020   x = 1;
00021   opacity = 1.0;
00022   timerId = startTimer(15);
00023 }
00024 
00025 void Puff::paintEvent(QPaintEvent *event)
00026 {
00027   QPainter painter(this);
00028 
00029   QString text = "ZetCode";
00030 
00031   painter.setPen(QPen(QBrush("#575555"), 1));
00032 
00033   QFont font("Courier", x, QFont::DemiBold);
00034   QFontMetrics fm(font);
00035   int textWidth = fm.width(text);
00036 
00037   painter.setFont(font);
00038 
00039 
00040   if (x > 10) {
00041     opacity -= 0.01;
00042     painter.setOpacity(opacity);
00043   }
00044 
00045   if (opacity <= 0) {
00046     killTimer(timerId);
00047     std::cout << "timer stopped" << std::endl;
00048   }
00049 
00050   int h = height();
00051   int w = width();
00052 
00053   painter.translate(QPoint(w/2, h/2));
00054   painter.drawText(-textWidth/2, 0, text);
00055 
00056 }
00057 
00058 
00059 void Puff::timerEvent(QTimerEvent *event)
00060 {
00061   x += 1;
00062   repaint();
00063 }
00064 
00065 } // namespace PSQt

Generated on 19 Dec 2016 for PSANAmodules by  doxygen 1.4.7