QTfrontend/ui/widget/flowlayout.cpp
author sheepluva
Fri, 25 Jan 2013 13:59:27 +0100
changeset 8434 4821897a0f10
parent 8386 2aaa2995a32e
permissions -rw-r--r--
big indentation/whitespaces cleanup
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     1
 /****************************************************************************
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     2
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     3
 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     4
 ** All rights reserved.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     5
 ** Contact: Nokia Corporation (qt-info@nokia.com)
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     6
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     7
 ** This file is part of the examples of the Qt Toolkit.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     8
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
     9
 ** $QT_BEGIN_LICENSE:BSD$
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    10
 ** You may use this file under the terms of the BSD license as follows:
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    11
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    12
 ** "Redistribution and use in source and binary forms, with or without
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    13
 ** modification, are permitted provided that the following conditions are
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    14
 ** met:
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    15
 **   * Redistributions of source code must retain the above copyright
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    16
 **     notice, this list of conditions and the following disclaimer.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    17
 **   * Redistributions in binary form must reproduce the above copyright
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    18
 **     notice, this list of conditions and the following disclaimer in
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    19
 **     the documentation and/or other materials provided with the
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    20
 **     distribution.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    21
 **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    22
 **     the names of its contributors may be used to endorse or promote
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    23
 **     products derived from this software without specific prior written
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    24
 **     permission.
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    25
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    26
 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    27
 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    28
 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    29
 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    30
 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    31
 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    32
 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    33
 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    34
 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    35
 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    36
 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    37
 ** $QT_END_LICENSE$
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    38
 **
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    39
 ****************************************************************************/
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    40
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    41
 #include <QtGui>
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    42
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    43
 #include "flowlayout.h"
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    44
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    45
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    46
    : QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    47
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    48
    setContentsMargins(margin, margin, margin, margin);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    49
}
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    50
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    51
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    52
    : m_hSpace(hSpacing), m_vSpace(vSpacing)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    53
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    54
    setContentsMargins(margin, margin, margin, margin);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    55
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    56
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    57
FlowLayout::~FlowLayout()
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    58
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    59
    QLayoutItem *item;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    60
    while ((item = takeAt(0)))
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    61
        delete item;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    62
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    63
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    64
void FlowLayout::addItem(QLayoutItem *item)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    65
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    66
    itemList.append(item);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    67
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    68
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    69
int FlowLayout::horizontalSpacing() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    70
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    71
    if (m_hSpace >= 0) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    72
        return m_hSpace;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    73
    } else {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    74
        return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    75
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    76
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    77
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    78
int FlowLayout::verticalSpacing() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    79
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    80
    if (m_vSpace >= 0) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    81
        return m_vSpace;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    82
    } else {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    83
        return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    84
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    85
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    86
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    87
int FlowLayout::count() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    88
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    89
    return itemList.size();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    90
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    91
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    92
QLayoutItem *FlowLayout::itemAt(int index) const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    93
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    94
    return itemList.value(index);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    95
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
    96
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    97
QLayoutItem *FlowLayout::takeAt(int index)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    98
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
    99
    if (index >= 0 && index < itemList.size())
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   100
        return itemList.takeAt(index);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   101
    else
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   102
        return 0;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   103
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   104
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   105
Qt::Orientations FlowLayout::expandingDirections() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   106
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   107
    return 0;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   108
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   109
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   110
bool FlowLayout::hasHeightForWidth() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   111
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   112
    return true;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   113
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   114
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   115
int FlowLayout::heightForWidth(int width) const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   116
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   117
    int height = doLayout(QRect(0, 0, width, 0), true);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   118
    return height;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   119
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   120
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   121
void FlowLayout::setGeometry(const QRect &rect)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   122
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   123
    QLayout::setGeometry(rect);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   124
    doLayout(rect, false);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   125
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   126
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   127
QSize FlowLayout::sizeHint() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   128
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   129
    return minimumSize();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   130
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   131
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   132
QSize FlowLayout::minimumSize() const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   133
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   134
    QSize size;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   135
    QLayoutItem *item;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   136
    foreach (item, itemList)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   137
        size = size.expandedTo(item->minimumSize());
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   138
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   139
    size += QSize(2*margin(), 2*margin());
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   140
    return size;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   141
}
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   142
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   143
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   144
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   145
    int left, top, right, bottom;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   146
    getContentsMargins(&left, &top, &right, &bottom);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   147
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   148
    int x = effectiveRect.x();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   149
    int y = effectiveRect.y();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   150
    int lineHeight = 0;
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   151
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   152
    QLayoutItem *item;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   153
    foreach (item, itemList) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   154
        QWidget *wid = item->widget();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   155
        int spaceX = horizontalSpacing();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   156
        if (spaceX == -1)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   157
            spaceX = wid->style()->layoutSpacing(
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   158
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   159
        int spaceY = verticalSpacing();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   160
        if (spaceY == -1)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   161
            spaceY = wid->style()->layoutSpacing(
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   162
                QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   163
        int nextX = x + item->sizeHint().width() + spaceX;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   164
        if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   165
            x = effectiveRect.x();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   166
            y = y + lineHeight + spaceY;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   167
            nextX = x + item->sizeHint().width() + spaceX;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   168
            lineHeight = 0;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   169
        }
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   170
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   171
        if (!testOnly)
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   172
            item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
8377
869f80966a77 GCI2012: Improve Game Configuration Widget
dag10
parents:
diff changeset
   173
8434
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   174
        x = nextX;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   175
        lineHeight = qMax(lineHeight, item->sizeHint().height());
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   176
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   177
    return y + lineHeight - rect.y() + bottom;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   178
}
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   179
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   180
{
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   181
    QObject *parent = this->parent();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   182
    if (!parent) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   183
        return -1;
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   184
    } else if (parent->isWidgetType()) {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   185
        QWidget *pw = static_cast<QWidget *>(parent);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   186
        return pw->style()->pixelMetric(pm, 0, pw);
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   187
    } else {
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   188
        return static_cast<QLayout *>(parent)->spacing();
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   189
    }
4821897a0f10 big indentation/whitespaces cleanup
sheepluva
parents: 8386
diff changeset
   190
}