Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

celsplashscreen.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           celsplashscreen.cpp  -  description
00003                              -------------------
00004     begin                : Tue Jan 03 23:27:30 CET 2006
00005     copyright            : (C) 2006 by Christophe Teyssier
00006     email                : chris@teyssier.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include <qapplication.h>
00018 #include <qpainter.h>
00019 #include <qrect.h>
00020 #include <klocale.h>
00021 #include <kglobal.h>
00022 #include <kglobalsettings.h>
00023 #include <celsplashscreen.h>
00024 #include <X11/Xlib.h>
00025 
00026 CelSplashScreen::CelSplashScreen(const QString& filename, QWidget* _parent):
00027     QWidget(0, 0, WStyle_Customize | WX11BypassWM), 
00028     parent(_parent)
00029 {
00030     setPixmap(filename);
00031     show();
00032 }
00033 
00034 void CelSplashScreen::mousePressEvent( QMouseEvent * )
00035 {
00036     hide();
00037 }
00038 
00039 void CelSplashScreen::repaint()
00040 {
00041     drawContents();
00042     QWidget::repaint();
00043     QApplication::flush();
00044 }
00045 
00046 void CelSplashScreen::drawContents()
00047 {
00048     QPixmap textPix = pixmap;
00049     QPainter painter( &textPix, this );
00050     drawContents( &painter );
00051     setErasePixmap( textPix );
00052 }
00053 
00054 void CelSplashScreen::drawContents(QPainter *painter) {
00055     status.draw(painter);
00056 }
00057 
00058 void CelSplashScreen::update(const string& _message) {
00059     status.setContent(_message);
00060     repaint();
00061 }
00062 
00063 void CelSplashScreen::finish( QWidget *mainWin )
00064 {
00065     if ( mainWin ) {
00066         extern void qt_wait_for_window_manager( QWidget *mainWin );
00067         qt_wait_for_window_manager( mainWin );
00068     }
00069     close();
00070 }
00071 
00072 void CelSplashScreen::setPixmap( const QString &filename )
00073 {
00074     QPixmap _pixmap(filename);
00075     resize( _pixmap.size() );
00076 
00077     //  Set default values for status and version fields
00078     status.getRect().setX(20);
00079     status.getRect().setY(height() - 40);
00080     status.getRect().setWidth(width() - 200);
00081     status.getRect().setHeight(20);
00082     status.setFlags(Qt::AlignLeft | Qt::AlignTop);
00083 
00084     version.getRect().setX(width() - 180);
00085     version.getRect().setY(height() - 40);
00086     version.getRect().setWidth(150);
00087     version.getRect().setHeight(20);
00088     version.setFlags(Qt::AlignRight | Qt::AlignTop);
00089     version.setContent(VERSION);
00090 
00091     KFileMetaInfo info(filename);
00092     KFileMetaInfoGroup comments = info.group("Comment");
00093 
00094     if (comments.isValid()) {
00095         status.set("status", comments);
00096         version.set("version", comments);
00097         int i = 0;
00098         char extraName[10];
00099         sprintf(extraName, "extra%02d", i);
00100         while (i< 100 && comments.item(QString(extraName) + "_insert_before").isValid()) {
00101             TextItem extra;
00102             extra.set(extraName, comments);
00103             extraText.push_back(extra);
00104             i++;
00105             sprintf(extraName, "extra%02d", i);
00106         }
00107     }
00108 
00109     QRect desk = KGlobalSettings::splashScreenDesktopGeometry();
00110     setGeometry( ( desk.width() / 2 ) - ( width() / 2 ) + desk.left(),
00111        ( desk.height() / 2 ) - ( height() / 2 ) + desk.top(),
00112          width(), height() );
00113     if (_pixmap.hasAlphaChannel()) {
00114         QPixmap bg = QPixmap::grabWindow( qt_xrootwin(), x(), y(), width(), height() );
00115         QPainter painter(&bg);
00116         painter.drawPixmap(0, 0, _pixmap);
00117         pixmap = bg;
00118     } else {
00119         pixmap = _pixmap;
00120     }
00121     
00122     QPainter painter( &pixmap, this );
00123     version.draw(&painter);
00124     for(std::vector<TextItem>::const_iterator i = extraText.begin(); i != extraText.end();  ++i)
00125         (*i).draw(&painter);
00126 
00127     repaint();
00128 }
00129 
00130 TextItem::TextItem():
00131     disable(false),
00132     color(QColor("white")),
00133     font(QFont("Arial")),
00134     showBox(false)
00135  {
00136     font.setPixelSize(11);
00137 }
00138 
00139 void TextItem::draw(QPainter *painter) const {
00140     if (disable) return;
00141     painter->setPen(color);
00142     painter->setFont(font);
00143     painter->drawText(rect, flags, insertBefore + content);
00144     if (showBox) painter->drawRect(rect);
00145 }
00146 
00147 void TextItem::setColor(const QString& rgb) {
00148     bool okr, okg, okb;
00149     int r, g, b;
00150     r = rgb.mid(0, 2).toInt(&okr, 16);
00151     g = rgb.mid(2, 2).toInt(&okg, 16);
00152     b = rgb.mid(4, 2).toInt(&okb, 16);
00153     if (okr && okg && okb) color.setRgb(r, g, b);
00154 }
00155 
00156 void TextItem::set(const QString& prefix, const KFileMetaInfoGroup& comments) {
00157     bool ok;
00158     int intVal;
00159     intVal = comments.value(prefix + "_disable").toInt(&ok);
00160     if (ok) disable = intVal;
00161     intVal = comments.value(prefix + "_x").toInt(&ok);
00162     if (ok) rect.setX(intVal);
00163     intVal = comments.value(prefix + "_y").toInt(&ok);
00164     if (ok) rect.setY(intVal);
00165     intVal = comments.value(prefix + "_width").toInt(&ok);
00166     if (ok) rect.setWidth(intVal);
00167     intVal = comments.value(prefix+ "_height").toInt(&ok);
00168     if (ok) rect.setHeight(intVal);
00169     QString sVal = comments.value(prefix + "_halign").toString();
00170     int _flags = -1;
00171     if (sVal == "left") {
00172         _flags = Qt::AlignLeft;
00173     } else if (sVal == "center") {
00174         _flags = Qt::AlignHCenter;
00175     } else if (sVal == "right") {
00176         _flags = Qt::AlignRight;
00177     }
00178     sVal = comments.value(prefix + "_valign").toString();
00179     if (sVal == "top") {
00180         if (_flags < 0) _flags = Qt::AlignTop;
00181         else _flags |= Qt::AlignTop;
00182     } else if (sVal == "center") {
00183         if (_flags < 0) _flags = Qt::AlignVCenter;
00184         else _flags |= Qt::AlignVCenter;
00185     } else if (sVal == "bottom") {
00186         if (_flags < 0) _flags = Qt::AlignBottom;
00187         else _flags |= Qt::AlignBottom;
00188     }
00189     if (_flags >= 0) flags = _flags;
00190     sVal = comments.value(prefix + "_font_family").toString();
00191     if (sVal != "") font.setFamily(sVal);
00192     intVal = comments.value(prefix + "_font_size").toInt(&ok);
00193     if (ok) font.setPixelSize(intVal);
00194     intVal = comments.value(prefix + "_font_is_bold").toInt(&ok);
00195     if (ok) font.setBold(intVal);
00196     sVal = comments.value(prefix + "_color").toString();
00197     if (sVal != "") setColor(sVal);
00198     intVal = comments.value(prefix + "_show_box").toInt(&ok);
00199     if (ok) showBox = intVal;
00200     sVal = comments.value(prefix + "_insert_before").toString();
00201     if (sVal != "") insertBefore = sVal;
00202 }

Generated on Sat Jan 14 22:30:30 2006 for Celestia by  doxygen 1.4.1