diff --git a/src/plugins/coreplugin/flowlayout.cpp b/src/libs/utils/flowlayout.cpp similarity index 55% rename from src/plugins/coreplugin/flowlayout.cpp rename to src/libs/utils/flowlayout.cpp index 9c1b8419c7d..6cc6974a78f 100644 --- a/src/plugins/coreplugin/flowlayout.cpp +++ b/src/libs/utils/flowlayout.cpp @@ -35,18 +35,18 @@ #include #include -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(parent); + return pw->style()->pixelMetric(pm, 0, pw); + } else { + return static_cast(parent)->spacing(); + } } diff --git a/src/plugins/coreplugin/flowlayout.h b/src/libs/utils/flowlayout.h similarity index 79% rename from src/plugins/coreplugin/flowlayout.h rename to src/libs/utils/flowlayout.h index 14432ba77b8..d75f4072174 100644 --- a/src/plugins/coreplugin/flowlayout.h +++ b/src/libs/utils/flowlayout.h @@ -33,19 +33,24 @@ #ifndef FLOWLAYOUT_H #define FLOWLAYOUT_H +#include "utils_global.h" + #include +#include +#include -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 itemList; + int m_hSpace; + int m_vSpace; }; -} // namespace Internal -} // namespace Core +} // namespace Utils #endif // FLOWLAYOUT_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index 822873317ad..ac6ffa5cf21 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -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 \ diff --git a/src/plugins/coreplugin/coreplugin.pro b/src/plugins/coreplugin/coreplugin.pro index 8bab66a249d..0547ad61de1 100644 --- a/src/plugins/coreplugin/coreplugin.pro +++ b/src/plugins/coreplugin/coreplugin.pro @@ -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 \ diff --git a/src/plugins/find/findtoolbar.cpp b/src/plugins/find/findtoolbar.cpp index a244e7eefbc..7e88eccadb6 100644 --- a/src/plugins/find/findtoolbar.cpp +++ b/src/plugins/find/findtoolbar.cpp @@ -46,6 +46,7 @@ #include #include +#include #include #include @@ -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(); diff --git a/src/plugins/find/findwidget.ui b/src/plugins/find/findwidget.ui index 2457dbc6989..7ff9c28f0f2 100644 --- a/src/plugins/find/findwidget.ui +++ b/src/plugins/find/findwidget.ui @@ -6,14 +6,14 @@ 0 0 - 603 - 90 + 681 + 88 Find - + 5 @@ -27,7 +27,7 @@ 2 - 5 + 3 0 @@ -40,152 +40,244 @@ - - - - - - 3 - - - - - Qt::NoFocus - - - Qt::LeftArrow - - - - - - - - - - Qt::NoFocus - - - Qt::RightArrow - - - - - - - Qt::Horizontal - - - - 40 - 0 - - - - - - - - ... - - - - - - - - - Replace with: + + + + 100 + 0 + - - + + + + + 3 + + + 0 + + + + + Qt::NoFocus + + + Qt::LeftArrow + + + + + + + + + + Qt::NoFocus + + + Qt::RightArrow + + + + + + + Qt::Horizontal + + + + 40 + 0 + + + + + + + + ... + + + + + - - + + - 3 + 0 - - - Qt::NoFocus - + - Replace - - - Qt::ToolButtonTextOnly - - - Qt::LeftArrow + Replace with: - - - - - - Qt::NoFocus - - - Replace && Find - - - Qt::ToolButtonTextOnly - - - Qt::RightArrow - - - - - - - - - - Replace All - - - Qt::ToolButtonTextOnly - - - - - + - Qt::Horizontal + Qt::Vertical - 40 + 0 0 + + + + + + 0 + - - - Advanced... - - - Qt::ToolButtonTextOnly + + + + 100 + 0 + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + 3 + + + 0 + + + + + + 0 + 0 + + + + + 3 + + + 0 + + + + + Qt::NoFocus + + + Replace + + + Qt::ToolButtonTextOnly + + + Qt::LeftArrow + + + + + + + + + + Qt::NoFocus + + + Replace && Find + + + Qt::ToolButtonTextOnly + + + Qt::RightArrow + + + + + + + + + + Replace All + + + Qt::ToolButtonTextOnly + + + + + + + + + + 0 + + + + + Advanced... + + + Qt::ToolButtonTextOnly + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + - Utils::FilterLineEdit + Utils::FancyLineEdit QLineEdit +
utils/fancylineedit.h
+
+ + Utils::FilterLineEdit + Utils::FancyLineEdit
utils/filterlineedit.h