UniversalIndentGUI 1.2.0
AboutDialogGraphicsView.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
00003 *   thomas-schweitzer(at)arcor.de                                         *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU General Public License version 2.0 as   *
00007 *   published by the Free Software Foundation.                            *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU General Public License     *
00015 *   along with this program in the file LICENSE.GPL; if not, write to the *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018 ***************************************************************************/
00019 
00020 #include "AboutDialogGraphicsView.h"
00021 
00022 #include "AboutDialog.h"
00023 
00024 #include <QtGui>
00025 #include <QDesktopWidget>
00026 #include <QDate>
00027 #include <QTimeLine>
00028 #include <QSplashScreen>
00029 
00042 AboutDialogGraphicsView::AboutDialogGraphicsView(AboutDialog *aboutDialog, QWidget *parentWindow) : QGraphicsView(parentWindow)
00043     , _aboutDialog(NULL)
00044     , _graphicsProxyWidget(NULL)
00045     , _parentWindow(NULL)
00046     , _timeLine(NULL)
00047     , _aboutDialogAsSplashScreen(NULL)
00048 {
00049     _parentWindow = parentWindow;
00050     setWindowFlags(Qt::SplashScreen);
00051 
00052 #ifdef Q_OS_LINUX
00053     QRect availableGeometry = QApplication::desktop()->availableGeometry();
00054     QRect newGeometry = QRect( availableGeometry.x(), availableGeometry.y(), availableGeometry.width(), availableGeometry.height() );
00055 #else
00056     QRect newGeometry = QRect( -1,-1, QApplication::desktop()->rect().width()+2, QApplication::desktop()->rect().height()+2 );
00057 #endif
00058     setGeometry( newGeometry );
00059 
00060     _aboutDialog = aboutDialog;
00061 
00062     _windowTitleBarWidth = 0;
00063     _windowPosOffset = 0;
00064 
00065     QGraphicsScene *scene = new QGraphicsScene(this);
00066     setSceneRect( newGeometry );
00067     _aboutDialogAsSplashScreen = new QSplashScreen(this);
00068     _graphicsProxyWidget = scene->addWidget(_aboutDialogAsSplashScreen);
00069     _graphicsProxyWidget->setWindowFlags( Qt::ToolTip );
00070 
00071     setScene( scene );
00072     setRenderHint(QPainter::Antialiasing);
00073 
00074     setCacheMode(QGraphicsView::CacheBackground);
00075     setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
00076 
00077     connect(_aboutDialog, SIGNAL(finished(int)), this, SLOT(hide()));
00078 
00079     //setWindowOpacity(0.9);
00080 
00081     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00082     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00083     setStyleSheet("AboutDialogGraphicsView { border: 0px; }");
00084 
00085     _timeLine = new QTimeLine(1000, this);
00086     _timeLine->setFrameRange(270, 0);
00087     //_timeLine->setUpdateInterval(10);
00088     //_timeLine->setCurveShape(QTimeLine::EaseInCurve);
00089     connect(_timeLine, SIGNAL(frameChanged(int)), this, SLOT(updateStep(int)));
00090 }
00091 
00092 
00093 AboutDialogGraphicsView::~AboutDialogGraphicsView(void) {
00094 }
00095 
00096 
00101 void AboutDialogGraphicsView::show() {
00102     // Because on X11 system the window decoration is only available after a widget has been shown once,
00103     // we can detect _windowTitleBarWidth here for the first time.
00104     _windowTitleBarWidth = _parentWindow->geometry().y() - _parentWindow->y();
00105     // If the _windowTitleBarWidth could not be determined, try it a second way. Even the chances are low to get good results.
00106     if ( _windowTitleBarWidth == 0 )
00107         _windowTitleBarWidth = _parentWindow->frameGeometry().height() - _parentWindow->geometry().height();
00108 #ifdef Q_OS_LINUX
00109     if ( _windowTitleBarWidth == 0 ) {
00110         //TODO: 27 pixel is a fix value for the Ubuntu 10.4 default window theme and so just a workaround for that specific case.
00111         _windowPosOffset = 27;
00112         _windowTitleBarWidth = 27;
00113     }
00114 #endif
00115     QPixmap originalPixmap = QPixmap::grabWindow(QApplication::desktop()->winId(), QApplication::desktop()->availableGeometry().x(), QApplication::desktop()->availableGeometry().y(), geometry().width(), geometry().height() );
00116     QBrush brush(originalPixmap);
00117     QTransform transform;
00118     transform.translate(0, QApplication::desktop()->availableGeometry().y());
00119     brush.setTransform(transform);
00120 
00121     setBackgroundBrush(brush);
00122 
00123     _aboutDialogAsSplashScreen->setPixmap( QPixmap::grabWidget(_aboutDialog) );
00124     _graphicsProxyWidget->setGeometry( _aboutDialog->geometry() );
00125     _aboutDialog->hide();
00126     _graphicsProxyWidget->setPos( _parentWindow->geometry().x()+(_parentWindow->geometry().width()-_graphicsProxyWidget->geometry().width()) / 2, _parentWindow->y()+_windowTitleBarWidth-_windowPosOffset);
00127 
00128     QRectF r = _graphicsProxyWidget->boundingRect();
00129     _graphicsProxyWidget->setTransform(QTransform()
00130         .translate(r.width() / 2, -_windowTitleBarWidth)
00131         .rotate(270, Qt::XAxis)
00132         //.rotate(90, Qt::YAxis)
00133         //.rotate(5, Qt::ZAxis)
00134         //.scale(1 + 1.5 * step, 1 + 1.5 * step)
00135         .translate(-r.width() / 2, _windowTitleBarWidth));
00136 
00137     _graphicsProxyWidget->show();
00138     //_aboutDialogAsSplashScreen->show();
00139     QGraphicsView::show();
00140 
00141     connect(_timeLine, SIGNAL(finished()), this, SLOT(showAboutDialog()));
00142     _timeLine->setDirection(QTimeLine::Forward);
00143     _timeLine->start();
00144 }
00145 
00146 
00150 void AboutDialogGraphicsView::updateStep(int step) {
00151     QRectF r = _graphicsProxyWidget->boundingRect();
00152     _graphicsProxyWidget->setTransform(QTransform()
00153         .translate(r.width() / 2, -_windowTitleBarWidth)
00154         .rotate(step, Qt::XAxis)
00155         //.rotate(step, Qt::YAxis)
00156         //.rotate(step * 5, Qt::ZAxis)
00157         //.scale(1 + 1.5 * step, 1 + 1.5 * step)
00158         .translate(-r.width() / 2, _windowTitleBarWidth));
00159     //update();
00160 }
00161 
00162 
00166 void AboutDialogGraphicsView::showAboutDialog() {
00167     //hide();
00168     disconnect(_timeLine, SIGNAL(finished()), this, SLOT(showAboutDialog()));
00169     _aboutDialog->move( int(_parentWindow->geometry().x()+(_parentWindow->geometry().width()-_graphicsProxyWidget->geometry().width()) / 2), _parentWindow->y()+_windowTitleBarWidth-_windowPosOffset );
00170     _aboutDialog->exec();
00171 }
00172 
00173 
00177 void AboutDialogGraphicsView::hide() {
00178     _graphicsProxyWidget->setPos( _parentWindow->geometry().x()+(_parentWindow->geometry().width()-_graphicsProxyWidget->geometry().width()) / 2, _parentWindow->y()+_windowTitleBarWidth-_windowPosOffset);
00179 
00180     QRectF r = _graphicsProxyWidget->boundingRect();
00181     _graphicsProxyWidget->setTransform(QTransform()
00182         .translate(r.width() / 2, -_windowTitleBarWidth)
00183         .rotate(0, Qt::XAxis)
00184         //.rotate(90, Qt::YAxis)
00185         //.rotate(5, Qt::ZAxis)
00186         //.scale(1 + 1.5 * step, 1 + 1.5 * step)
00187         .translate(-r.width() / 2, _windowTitleBarWidth));
00188 
00189     _graphicsProxyWidget->show();
00190     //_aboutDialogAsSplashScreen->show();
00191     QGraphicsView::show();
00192 
00193     connect(_timeLine, SIGNAL(finished()), this, SLOT(hideReally()));
00194     _timeLine->setDirection(QTimeLine::Backward);
00195     _timeLine->start();
00196 }
00197 
00198 
00202 void AboutDialogGraphicsView::hideReally() {
00203     disconnect(_timeLine, SIGNAL(finished()), this, SLOT(hideReally()));
00204     QGraphicsView::hide();
00205     _parentWindow->activateWindow();
00206 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines