mysocials-core 1.0

src/utils/fullscreenexitbutton.h

00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the examples of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** No Commercial Usage
00011 ** This file contains pre-release code and may not be distributed.
00012 ** You may use this file in accordance with the terms and conditions
00013 ** contained in the Technology Preview License Agreement accompanying
00014 ** this package.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
00027 **
00028 ** If you have questions regarding the use of this file, please contact
00029 ** Nokia at qt-info@nokia.com.
00030 **
00031 **
00032 **
00033 **
00034 **
00035 **
00036 **
00037 **
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef FULLSCREENEXITBUTTON_H
00043 #define FULLSCREENEXITBUTTON_H
00044 
00045 #include <QtGui/qtoolbutton.h>
00046 #include <QtGui/qevent.h>
00047 
00048 class FullScreenExitButton : public QToolButton
00049 {
00050     Q_OBJECT
00051 public:
00052     inline explicit FullScreenExitButton(QWidget *parent);
00053 
00054 protected:
00055     inline bool eventFilter(QObject *obj, QEvent *ev);
00056 };
00057 
00058 
00059 FullScreenExitButton::FullScreenExitButton(QWidget *parent)
00060         : QToolButton(parent)
00061 {
00062     Q_ASSERT(parent);
00063 
00064     // set the fullsize icon from Maemo's theme
00065     setIcon(QIcon::fromTheme(QLatin1String("general_fullsize")));
00066 
00067     // ensure that our size is fixed to our ideal size
00068     setFixedSize(sizeHint());
00069 
00070     // set the background to 0.5 alpha
00071     QPalette pal = palette();
00072     QColor backgroundColor = pal.color(backgroundRole());
00073     backgroundColor.setAlpha(128);
00074     pal.setColor(backgroundRole(), backgroundColor);
00075     setPalette(pal);
00076 
00077     // ensure that we're painting our background
00078     setAutoFillBackground(true);
00079 
00080     // when we're clicked, tell the parent to exit fullscreen
00081     connect(this, SIGNAL(clicked()), parent, SLOT(showNormal()));
00082 
00083     // install an event filter to listen for the parent's events
00084     parent->installEventFilter(this);
00085 }
00086 
00087 bool FullScreenExitButton::eventFilter(QObject *obj, QEvent *ev)
00088 {
00089     if (obj != parent())
00090         return QToolButton::eventFilter(obj, ev);
00091 
00092     QWidget *parent = parentWidget();
00093     bool isFullScreen = parent->windowState() & Qt::WindowFullScreen;
00094 
00095     switch (ev->type()) {
00096     case QEvent::WindowStateChange:
00097         setVisible(isFullScreen);
00098         if (isFullScreen)
00099             raise();
00100         // fall through
00101     case QEvent::Resize:
00102         if (isVisible())
00103             move(parent->width() - width(),
00104                  parent->height() - height());
00105         break;
00106     default:
00107         break;
00108     }
00109 
00110     return QToolButton::eventFilter(obj, ev);
00111 }
00112 
00113 #endif