QTfrontend/qaspectratiolayout.h
changeset 4520 e7882bd1a894
parent 4477 63a21fac8bf7
equal deleted inserted replaced
4519:aee36896d46b 4520:e7882bd1a894
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation.
       
     3  */
       
     4 
       
     5 #ifndef QASPECTRATIOLAYOUT_H_
       
     6 #define QASPECTRATIOLAYOUT_H_
       
     7 
       
     8 #include <QLayout>
       
     9 #include <QPointer>
       
    10 #include <QRect>
       
    11 #include <QWidgetItem>
       
    12 #include <QLayoutItem>
       
    13 
       
    14 
       
    15 class QAspectRatioLayout : public QLayout
       
    16 {
       
    17         Q_OBJECT
       
    18 
       
    19 public:
       
    20         QAspectRatioLayout(QWidget* parent, int spacing =-1);
       
    21         QAspectRatioLayout(int spacing = -1);
       
    22         ~QAspectRatioLayout();
       
    23 
       
    24         /* Convenience method */
       
    25         virtual void add(QLayoutItem* item);
       
    26 
       
    27 /* http://doc.trolltech.com/qlayout.html#addItem */
       
    28         virtual void addItem(QLayoutItem* item);
       
    29         /* http://doc.trolltech.com/qlayout.html#addWidget */
       
    30         virtual void addWidget(QWidget* widget);
       
    31         /* http://doc.trolltech.com/qlayout.html#takeAt */
       
    32         virtual QLayoutItem* takeAt(int index);
       
    33         /* http://doc.trolltech.com/qlayout.html#itemAt */
       
    34         virtual QLayoutItem* itemAt(int index) const;
       
    35         /* http://doc.trolltech.com/qlayout.html#count */
       
    36         virtual int count() const;
       
    37 
       
    38         /*
       
    39          * These are ours since we do have only one item.
       
    40          */
       
    41         virtual QLayoutItem* replaceItem(QLayoutItem* item);
       
    42         virtual QLayoutItem* take();
       
    43         virtual bool hasItem() const;
       
    44 
       
    45 /* http://doc.trolltech.com/qlayout.html#expandingDirections */
       
    46         virtual Qt::Orientations expandingDirections() const;
       
    47 
       
    48         /*
       
    49          * This method contains most of the juice of this article.
       
    50          * http://doc.trolltech.com/qlayoutitem.html#setGeometry
       
    51          */
       
    52         virtual void setGeometry(const QRect& rect);
       
    53         /* http://doc.trolltech.com/qlayoutitem.html#geometry */
       
    54         virtual QRect geometry();
       
    55 
       
    56         /* http://doc.trolltech.com/qlayoutitem.html#sizeHint */
       
    57         virtual QSize sizeHint() const;
       
    58         /* http://doc.trolltech.com/qlayout.html#minimumSize */
       
    59         virtual QSize minimumSize() const;
       
    60         /* http://doc.trolltech.com/qlayoutitem.html#hasHeightForWidth */
       
    61         virtual bool hasHeightForWidth() const;
       
    62 
       
    63 private:
       
    64         /* Saves the last received rect. */
       
    65         void setLastReceivedRect(const QRect& rect);
       
    66         /* Used to initialize the object. */
       
    67         void init(int spacing);
       
    68         /* Calculates the maximum size for the item from the assigned size. */
       
    69         QSize calculateProperSize(QSize from) const;
       
    70         /* Calculates the center location from the assigned size and
       
    71          * the items size. */
       
    72         QPoint calculateCenterLocation(QSize from, QSize itemSize) const;
       
    73         /* Check if two QRects are equal */
       
    74         bool areRectsEqual(const QRect& a, const QRect& b) const;
       
    75         /* Contains item reference */
       
    76         QLayoutItem* item;
       
    77         /*
       
    78          * Used for caching so we won't do calculations every time
       
    79          * setGeometry is called.
       
    80          */
       
    81         QRect* lastReceivedRect;
       
    82         /* Contains geometry */
       
    83         QRect* _geometry;
       
    84 
       
    85 };
       
    86 
       
    87 #endif /* QASPECTRATIOLAYOUT_H_ */