2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "flowlayout.h"
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QWidget>
|
2010-03-18 10:59:06 +01:00
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
using namespace Utils;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
|
|
|
|
|
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-06-23 14:35:45 +02:00
|
|
|
setContentsMargins(margin, margin, margin, margin);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
|
|
|
|
|
: m_hSpace(hSpacing), m_vSpace(vSpacing)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-06-23 14:35:45 +02:00
|
|
|
setContentsMargins(margin, margin, margin, margin);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FlowLayout::~FlowLayout()
|
|
|
|
|
{
|
|
|
|
|
QLayoutItem *item;
|
|
|
|
|
while ((item = takeAt(0)))
|
|
|
|
|
delete item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlowLayout::addItem(QLayoutItem *item)
|
|
|
|
|
{
|
|
|
|
|
itemList.append(item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
int FlowLayout::horizontalSpacing() const
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_hSpace >= 0)
|
2011-06-23 14:35:45 +02:00
|
|
|
return m_hSpace;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-06-23 14:35:45 +02:00
|
|
|
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FlowLayout::verticalSpacing() const
|
|
|
|
|
{
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_vSpace >= 0)
|
2011-06-23 14:35:45 +02:00
|
|
|
return m_vSpace;
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-06-23 14:35:45 +02:00
|
|
|
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
int FlowLayout::count() const
|
|
|
|
|
{
|
|
|
|
|
return itemList.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLayoutItem *FlowLayout::itemAt(int index) const
|
|
|
|
|
{
|
|
|
|
|
return itemList.value(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QLayoutItem *FlowLayout::takeAt(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index >= 0 && index < itemList.size())
|
|
|
|
|
return itemList.takeAt(index);
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::Orientations FlowLayout::expandingDirections() const
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FlowLayout::hasHeightForWidth() const
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FlowLayout::heightForWidth(int width) const
|
|
|
|
|
{
|
|
|
|
|
int height = doLayout(QRect(0, 0, width, 0), true);
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlowLayout::setGeometry(const QRect &rect)
|
|
|
|
|
{
|
|
|
|
|
QLayout::setGeometry(rect);
|
|
|
|
|
doLayout(rect, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize FlowLayout::sizeHint() const
|
|
|
|
|
{
|
|
|
|
|
return minimumSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize FlowLayout::minimumSize() const
|
|
|
|
|
{
|
|
|
|
|
QSize size;
|
2011-06-23 14:35:45 +02:00
|
|
|
QLayoutItem *item;
|
|
|
|
|
foreach (item, itemList)
|
2008-12-02 12:01:29 +01:00
|
|
|
size = size.expandedTo(item->minimumSize());
|
|
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
size += QSize(2*margin(), 2*margin());
|
2008-12-02 12:01:29 +01:00
|
|
|
return size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
|
|
|
|
|
{
|
2011-06-23 14:35:45 +02:00
|
|
|
int left, top, right, bottom;
|
|
|
|
|
getContentsMargins(&left, &top, &right, &bottom);
|
|
|
|
|
QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
|
|
|
|
|
int x = effectiveRect.x();
|
|
|
|
|
int y = effectiveRect.y();
|
2008-12-02 12:01:29 +01:00
|
|
|
int lineHeight = 0;
|
|
|
|
|
|
2011-06-23 14:35:45 +02:00
|
|
|
QLayoutItem *item;
|
|
|
|
|
foreach (item, itemList) {
|
|
|
|
|
QWidget *wid = item->widget();
|
|
|
|
|
int spaceX = horizontalSpacing();
|
|
|
|
|
if (spaceX == -1)
|
|
|
|
|
spaceX = wid->style()->layoutSpacing(
|
|
|
|
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
|
|
|
|
|
int spaceY = verticalSpacing();
|
|
|
|
|
if (spaceY == -1)
|
|
|
|
|
spaceY = wid->style()->layoutSpacing(
|
|
|
|
|
QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
|
|
|
|
|
int nextX = x + item->sizeHint().width() + spaceX;
|
|
|
|
|
if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
|
|
|
|
|
x = effectiveRect.x();
|
|
|
|
|
y = y + lineHeight + spaceY;
|
|
|
|
|
nextX = x + item->sizeHint().width() + spaceX;
|
2008-12-02 12:01:29 +01:00
|
|
|
lineHeight = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!testOnly)
|
|
|
|
|
item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));
|
|
|
|
|
|
|
|
|
|
x = nextX;
|
|
|
|
|
lineHeight = qMax(lineHeight, item->sizeHint().height());
|
|
|
|
|
}
|
2011-06-23 14:35:45 +02:00
|
|
|
return y + lineHeight - rect.y() + bottom;
|
|
|
|
|
}
|
|
|
|
|
int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
|
|
|
|
|
{
|
|
|
|
|
QObject *parent = this->parent();
|
|
|
|
|
if (!parent) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else if (parent->isWidgetType()) {
|
|
|
|
|
QWidget *pw = static_cast<QWidget *>(parent);
|
|
|
|
|
return pw->style()->pixelMetric(pm, 0, pw);
|
|
|
|
|
} else {
|
|
|
|
|
return static_cast<QLayout *>(parent)->spacing();
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|