ginebra2/ContentViews/ViewportMetaData.h
changeset 3 0954f5dd2cd0
child 16 3c88a81ff781
equal deleted inserted replaced
1:b0dd75e285d2 3:0954f5dd2cd0
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 *
       
     5 * This program is free software: you can redistribute it and/or modify
       
     6 * it under the terms of the GNU Lesser General Public License as published by
       
     7 * the Free Software Foundation, version 2.1 of the License.
       
     8 *
       
     9 * This program is distributed in the hope that it will be useful,
       
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12 * GNU Lesser General Public License for more details.
       
    13 *
       
    14 * You should have received a copy of the GNU Lesser General Public License
       
    15 * along with this program.  If not,
       
    16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
       
    17 *
       
    18 * Description:
       
    19 *
       
    20 */
       
    21 
       
    22 #ifndef ViewportMetaData_h
       
    23 #define ViewportMetaData_h
       
    24 
       
    25 #include <QFlags>
       
    26 #include <QObject>
       
    27 #include <QRect>
       
    28 
       
    29 namespace GVA {
       
    30 
       
    31 struct ParsedViewportData{
       
    32     QString m_width;
       
    33     QString m_height;
       
    34     qreal m_minScale;
       
    35 };
       
    36 
       
    37 class ViewportMetaData {
       
    38 public:
       
    39     enum {
       
    40         ValueUndefined = -1
       
    41     };
       
    42 
       
    43     enum ScaleLimit {
       
    44         UserDefinedMinumumScale = 0x1,
       
    45         UserDefinedMaximumScale = 0x2,
       
    46         UserDefinedInitialScale = 0x4,
       
    47     };
       
    48     Q_DECLARE_FLAGS(ScaleLimits, ScaleLimit)
       
    49 
       
    50     ViewportMetaData();
       
    51     ViewportMetaData(const ViewportMetaData&);
       
    52     ViewportMetaData& operator=(const ViewportMetaData&);
       
    53     ~ViewportMetaData();
       
    54 
       
    55     void adjustViewportData(const QRect& clientRect);
       
    56     void updateViewportData(const QSize& size, const QRect& clientRect);
       
    57     void orientationChanged(const QRect& newClientRect);
       
    58     bool isLayoutNeeded();
       
    59     void reset() {initialize();}
       
    60 
       
    61     void setFlag(ScaleLimit scaleLimit, bool enable)
       
    62     {
       
    63         if (enable)
       
    64             m_scaleLimits |= scaleLimit;
       
    65         else
       
    66             m_scaleLimits &= !scaleLimit;
       
    67     }
       
    68 
       
    69     bool getFlag(ScaleLimit scaleLimit)
       
    70     {
       
    71         return m_scaleLimits.testFlag(scaleLimit);
       
    72     }
       
    73 
       
    74 protected:
       
    75     void initialize();
       
    76     void adjustZoomValues(const QRect& clientRect);
       
    77     bool isUserSpecifiedWidth();
       
    78     bool isUserSpecifiedHeight();
       
    79 
       
    80 public:
       
    81     qreal m_initialScale;
       
    82     qreal m_minimumScale;
       
    83     qreal m_maximumScale;
       
    84     int m_width;
       
    85     int m_height;
       
    86     bool m_userScalable;
       
    87     ScaleLimits m_scaleLimits;
       
    88     bool m_isValid;
       
    89     ParsedViewportData m_specifiedData;
       
    90 };//ViewportMetaData
       
    91 
       
    92 Q_DECLARE_OPERATORS_FOR_FLAGS(ViewportMetaData::ScaleLimits)
       
    93 
       
    94 } //namespace GVA
       
    95 
       
    96 #endif //ViewportMetaData_h