Commit 78fa1bb0 authored by con's avatar con Committed by Eike Ziller
Browse files

Find/replace tool bar wasn't usable in very small width editors.

E.g. in split editors with small main window. We now have line edits
with a minimum size and use a flow layout for the replace buttons (which
will reduce width when necessary by laying out vertically).

Flow layout is taken from the Qt examples.

Task-number: QTCREATORBUG-3279
Change-Id: Ic07d4d3e75e3d928d6b53534adb42481ce26256b
Reviewed-on: http://codereview.qt.nokia.com/666

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarLeandro T. C. Melo <leandro.melo@nokia.com>
parent fbce58bf
......@@ -35,18 +35,18 @@
#include <QtCore/QRect>
#include <QtGui/QWidgetItem>
using namespace Core::Internal;
using namespace Utils;
FlowLayout::FlowLayout(QWidget *parent, int margin, int spacing)
: QLayout(parent)
FlowLayout::FlowLayout(QWidget *parent, int margin, int hSpacing, int vSpacing)
: QLayout(parent), m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setMargin(margin);
setSpacing(spacing);
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::FlowLayout(int spacing)
FlowLayout::FlowLayout(int margin, int hSpacing, int vSpacing)
: m_hSpace(hSpacing), m_vSpace(vSpacing)
{
setSpacing(spacing);
setContentsMargins(margin, margin, margin, margin);
}
FlowLayout::~FlowLayout()
......@@ -61,6 +61,24 @@ void FlowLayout::addItem(QLayoutItem *item)
itemList.append(item);
}
int FlowLayout::horizontalSpacing() const
{
if (m_hSpace >= 0) {
return m_hSpace;
} else {
return smartSpacing(QStyle::PM_LayoutHorizontalSpacing);
}
}
int FlowLayout::verticalSpacing() const
{
if (m_vSpace >= 0) {
return m_vSpace;
} else {
return smartSpacing(QStyle::PM_LayoutVerticalSpacing);
}
}
int FlowLayout::count() const
{
return itemList.size();
......@@ -109,25 +127,39 @@ QSize FlowLayout::sizeHint() const
QSize FlowLayout::minimumSize() const
{
QSize size;
foreach (QLayoutItem *item, itemList)
QLayoutItem *item;
foreach (item, itemList)
size = size.expandedTo(item->minimumSize());
size += QSize(2 * margin(), 2 * margin());
size += QSize(2*margin(), 2*margin());
return size;
}
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
int x = rect.x();
int y = rect.y();
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();
int lineHeight = 0;
foreach (QLayoutItem *item, itemList) {
int nextX = x + item->sizeHint().width() + spacing();
if (nextX - spacing() > rect.right() && lineHeight > 0) {
x = rect.x();
y = y + lineHeight + spacing();
nextX = x + item->sizeHint().width() + spacing();
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;
lineHeight = 0;
}
......@@ -137,5 +169,17 @@ int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
x = nextX;
lineHeight = qMax(lineHeight, item->sizeHint().height());
}
return y + lineHeight - rect.y() + margin();
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();
}
}
......@@ -33,19 +33,24 @@
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include "utils_global.h"
#include <QtGui/QLayout>
#include <QtGui/QWidget>
#include <QtGui/QStyle>
namespace Core {
namespace Internal {
namespace Utils {
class FlowLayout : public QLayout
class QTCREATOR_UTILS_EXPORT FlowLayout : public QLayout
{
public:
explicit FlowLayout(QWidget *parent, int margin = 0, int spacing = -1);
FlowLayout(int spacing = -1);
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item);
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const;
bool hasHeightForWidth() const;
int heightForWidth(int) const;
......@@ -58,11 +63,13 @@ public:
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
int m_hSpace;
int m_vSpace;
};
} // namespace Internal
} // namespace Core
} // namespace Utils
#endif // FLOWLAYOUT_H
......@@ -87,7 +87,8 @@ SOURCES += $$PWD/environment.cpp \
$$PWD/ssh/sftpchannel.cpp \
$$PWD/ssh/sshremoteprocessrunner.cpp \
$$PWD/ssh/sshconnectionmanager.cpp \
$$PWD/outputformatter.cpp
$$PWD/outputformatter.cpp \
$$PWD/flowlayout.cpp
win32 {
SOURCES += \
......@@ -187,7 +188,8 @@ HEADERS += $$PWD/environment.h \
$$PWD/ssh/sshpseudoterminal.h \
$$PWD/statuslabel.h \
$$PWD/outputformatter.h \
$$PWD/outputformat.h
$$PWD/outputformat.h \
$$PWD/flowlayout.h
FORMS += $$PWD/filewizardpage.ui \
$$PWD/projectintropage.ui \
......
......@@ -20,7 +20,6 @@ SOURCES += mainwindow.cpp \
tabpositionindicator.cpp \
fancyactionbar.cpp \
fancytabwidget.cpp \
flowlayout.cpp \
generalsettings.cpp \
filemanager.cpp \
uniqueidmanager.cpp \
......@@ -99,7 +98,6 @@ HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
fancytabwidget.h \
flowlayout.h \
generalsettings.h \
filemanager.h \
uniqueidmanager.h \
......
......@@ -46,6 +46,7 @@
#include <extensionsystem/pluginmanager.h>
#include <utils/stylehelper.h>
#include <utils/flowlayout.h>
#include <QtCore/QDebug>
#include <QtCore/QSettings>
......@@ -87,6 +88,14 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
{
//setup ui
m_ui.setupUi(this);
// compensate for a vertically expanding spacer below the label
m_ui.replaceLabel->setMinimumHeight(m_ui.replaceEdit->sizeHint().height());
delete m_ui.replaceButtonsWidget->layout();
Utils::FlowLayout *flowlayout = new Utils::FlowLayout(m_ui.replaceButtonsWidget, 0, 3, 3);
flowlayout->addWidget(m_ui.replaceButton);
flowlayout->addWidget(m_ui.replaceNextButton);
flowlayout->addWidget(m_ui.replaceAllButton);
m_ui.replaceButtonsWidget->setLayout(flowlayout);
setFocusProxy(m_ui.findEdit);
setProperty("topBorder", true);
setSingleRow(false);
......@@ -348,9 +357,7 @@ void FindToolBar::updateToolBar()
m_ui.replaceLabel->setEnabled(replaceEnabled);
m_ui.replaceEdit->setVisible(replaceEnabled);
m_ui.replaceLabel->setVisible(replaceEnabled);
m_ui.replaceButton->setVisible(replaceEnabled);
m_ui.replaceNextButton->setVisible(replaceEnabled);
m_ui.replaceAllButton->setVisible(replaceEnabled);
m_ui.replaceButtonsWidget->setVisible(replaceEnabled);
m_ui.advancedButton->setVisible(replaceEnabled);
layout()->invalidate();
......
......@@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>90</height>
<width>681</width>
<height>88</height>
</rect>
</property>
<property name="windowTitle">
<string>Find</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>5</number>
</property>
......@@ -27,7 +27,7 @@
<number>2</number>
</property>
<property name="horizontalSpacing">
<number>5</number>
<number>3</number>
</property>
<property name="verticalSpacing">
<number>0</number>
......@@ -40,152 +40,244 @@
</widget>
</item>
<item row="0" column="1">
<widget class="Utils::FilterLineEdit" name="findEdit"/>
<widget class="Utils::FilterLineEdit" name="findEdit">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<widget class="QWidget" name="findButtonsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="findPreviousButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="findNextButton">
<property name="font">
<font/>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="close">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>3</number>
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="findPreviousButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="findNextButton">
<property name="font">
<font/>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
<widget class="QLabel" name="replaceLabel">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="close">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QLabel" name="replaceLabel">
<property name="text">
<string>Replace with:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::FilterLineEdit" name="replaceEdit"/>
</item>
<item row="1" column="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="replaceButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Replace</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceNextButton">
<property name="font">
<font/>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Replace &amp;&amp; Find</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceAllButton">
<property name="font">
<font/>
</property>
<property name="text">
<string>Replace All</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
<widget class="Utils::FilterLineEdit" name="replaceEdit">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="replaceSpacer">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="advancedButton">
<property name="text">
<string>Advanced...</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</layout>
</item>
<item row="1" column="2">
<layout class="QGridLayout" name="gridLayout">
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QWidget" name="replaceButtonsWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="replaceButtonsLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="replaceButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Replace</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::LeftArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceNextButton">
<property name="font">
<font/>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Replace &amp;&amp; Find</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
<property name="arrowType">
<enum>Qt::RightArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="replaceAllButton">
<property name="font">
<font/>
</property>
<property name="text">
<string>Replace All</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="advancedButton">
<property name="text">
<string>Advanced...</string>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Utils::FilterLineEdit</class>
<class>Utils::FancyLineEdit</class>
<extends>QLineEdit</extends>
<header location="global">utils/fancylineedit.h</header>
</customwidget>
<customwidget>
<class>Utils::FilterLineEdit</class>
<extends>Utils::FancyLineEdit</extends>
<header location="global">utils/filterlineedit.h</header>
</customwidget>
</customwidgets>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment