tools/shared/deviceskin/deviceskin.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the tools applications of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef SKIN_H
       
    43 #define SKIN_H
       
    44 
       
    45 #include <QtGui/QWidget>
       
    46 #include <QtGui/QPolygon>
       
    47 #include <QtGui/QRegion>
       
    48 #include <QtGui/QPixmap>
       
    49 #include <QtCore/QVector>
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 namespace qvfb_internal {
       
    54     class CursorWindow;
       
    55 }
       
    56 
       
    57 class QTextStream;
       
    58 
       
    59 // ------- Button Area
       
    60 struct DeviceSkinButtonArea {
       
    61     DeviceSkinButtonArea();
       
    62     QString name;
       
    63     int	keyCode;
       
    64     QPolygon area;
       
    65     QString text;
       
    66     bool activeWhenClosed;
       
    67     bool toggleArea;
       
    68     bool toggleActiveArea;
       
    69 };
       
    70 
       
    71 // -------- Parameters
       
    72 struct DeviceSkinParameters {
       
    73     enum ReadMode { ReadAll, ReadSizeOnly };
       
    74     bool read(const QString &skinDirectory,  ReadMode rm,  QString *errorMessage);
       
    75     bool read(QTextStream &ts, ReadMode rm, QString *errorMessage);
       
    76 
       
    77     QSize screenSize() const { return screenRect.size(); }
       
    78     QSize secondaryScreenSize() const;
       
    79     bool hasSecondaryScreen() const;
       
    80 
       
    81     QString skinImageUpFileName;
       
    82     QString skinImageDownFileName;
       
    83     QString skinImageClosedFileName;
       
    84     QString skinCursorFileName;
       
    85 
       
    86     QImage skinImageUp;
       
    87     QImage skinImageDown;
       
    88     QImage skinImageClosed;
       
    89     QImage skinCursor;
       
    90 
       
    91     QRect screenRect;
       
    92     QRect backScreenRect;
       
    93     QRect closedScreenRect;
       
    94     int screenDepth;
       
    95     QPoint cursorHot;
       
    96     QVector<DeviceSkinButtonArea> buttonAreas;
       
    97     QList<int> toggleAreaList;
       
    98 
       
    99     int joystick;
       
   100     QString prefix;
       
   101     bool hasMouseHover;
       
   102 };
       
   103 
       
   104 // --------- Skin Widget
       
   105 class DeviceSkin : public QWidget
       
   106 {
       
   107     Q_OBJECT
       
   108 public:
       
   109     explicit DeviceSkin(const DeviceSkinParameters &parameters,  QWidget *p );
       
   110     ~DeviceSkin( );
       
   111 
       
   112     QWidget *view() const { return m_view; }
       
   113     void setView( QWidget *v );
       
   114 
       
   115     QWidget *secondaryView() const { return m_secondaryView; }
       
   116     void setSecondaryView( QWidget *v );
       
   117 
       
   118     void setZoom( double );
       
   119     void setTransform( const QMatrix& );
       
   120 
       
   121     bool hasCursor() const;
       
   122 
       
   123     QString prefix() const  {return m_parameters.prefix;}
       
   124 
       
   125 signals:
       
   126     void popupMenu();
       
   127     void skinKeyPressEvent(int code, const QString& text, bool autorep);
       
   128     void skinKeyReleaseEvent(int code, const QString& text, bool autorep);
       
   129 
       
   130 protected slots:
       
   131     void skinKeyRepeat();
       
   132     void moveParent();
       
   133 
       
   134 protected:
       
   135     virtual void paintEvent( QPaintEvent * );
       
   136     virtual void mousePressEvent( QMouseEvent *e );
       
   137     virtual void mouseMoveEvent( QMouseEvent *e );
       
   138     virtual void mouseReleaseEvent( QMouseEvent * );
       
   139 
       
   140 private:
       
   141     void calcRegions();
       
   142     void flip(bool open);
       
   143     void updateSecondaryScreen();
       
   144     void loadImages();
       
   145     void startPress(int);
       
   146     void endPress();
       
   147 
       
   148     const DeviceSkinParameters m_parameters;
       
   149     QVector<QRegion> buttonRegions;
       
   150     QPixmap skinImageUp;
       
   151     QPixmap skinImageDown;
       
   152     QPixmap skinImageClosed;
       
   153     QPixmap skinCursor;
       
   154     QWidget *parent;
       
   155     QWidget  *m_view;
       
   156     QWidget *m_secondaryView;
       
   157     QPoint parentpos;
       
   158     QPoint clickPos;
       
   159     bool buttonPressed;
       
   160     int buttonIndex;
       
   161     QMatrix transform;
       
   162     qvfb_internal::CursorWindow *cursorw;
       
   163 
       
   164     bool joydown;
       
   165     QTimer *t_skinkey;
       
   166     QTimer *t_parentmove;
       
   167     int onjoyrelease;
       
   168 
       
   169     bool flipped_open;
       
   170 };
       
   171 
       
   172 QT_END_NAMESPACE
       
   173 
       
   174 #endif