forked from qt-creator/qt-creator
Styled two-row find tool bar with better resizing behavior.
For this we needed to get rid of using QToolBar.
This commit is contained in:
@@ -86,6 +86,8 @@ bool panelWidget(const QWidget *widget)
|
|||||||
return true;
|
return true;
|
||||||
else if (qobject_cast<const QMenuBar *>(p) && styleEnabled(p))
|
else if (qobject_cast<const QMenuBar *>(p) && styleEnabled(p))
|
||||||
return true;
|
return true;
|
||||||
|
else if (p->property("panelwidget").toBool())
|
||||||
|
return true;
|
||||||
p = p->parentWidget();
|
p = p->parentWidget();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "textfindconstants.h"
|
#include "textfindconstants.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
|
#include <coreplugin/stylehelper.h>
|
||||||
#include <coreplugin/findplaceholder.h>
|
#include <coreplugin/findplaceholder.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
#include <coreplugin/stylehelper.h>
|
#include <coreplugin/stylehelper.h>
|
||||||
@@ -49,9 +50,10 @@
|
|||||||
#include <QtGui/QKeyEvent>
|
#include <QtGui/QKeyEvent>
|
||||||
#include <QtGui/QLineEdit>
|
#include <QtGui/QLineEdit>
|
||||||
#include <QtGui/QMenu>
|
#include <QtGui/QMenu>
|
||||||
#include <QtGui/QPainter>
|
|
||||||
#include <QtGui/QPushButton>
|
#include <QtGui/QPushButton>
|
||||||
#include <QtGui/QToolButton>
|
#include <QtGui/QToolButton>
|
||||||
|
#include <QtGui/QPainter>
|
||||||
|
#include <QtGui/QPixmapCache>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QStringList)
|
Q_DECLARE_METATYPE(QStringList)
|
||||||
Q_DECLARE_METATYPE(Find::IFindFilter*)
|
Q_DECLARE_METATYPE(Find::IFindFilter*)
|
||||||
@@ -68,14 +70,13 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
m_findNextAction(0),
|
m_findNextAction(0),
|
||||||
m_findPreviousAction(0),
|
m_findPreviousAction(0),
|
||||||
m_replaceNextAction(0),
|
m_replaceNextAction(0),
|
||||||
m_widget(new QWidget),
|
|
||||||
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
||||||
m_regexpIcon(":/find/images/regexp.png"),
|
m_regexpIcon(":/find/images/regexp.png"),
|
||||||
m_wholewordsIcon(":/find/images/wholewords.png")
|
m_wholewordsIcon(":/find/images/wholewords.png")
|
||||||
{
|
{
|
||||||
//setup ui
|
//setup ui
|
||||||
m_ui.setupUi(m_widget);
|
m_ui.setupUi(this);
|
||||||
addWidget(m_widget);
|
setProperty("panelwidget", true);
|
||||||
setFocusProxy(m_ui.findEdit);
|
setFocusProxy(m_ui.findEdit);
|
||||||
setProperty("topBorder", true);
|
setProperty("topBorder", true);
|
||||||
m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
m_ui.findEdit->setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||||
@@ -83,14 +84,9 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
|
|
||||||
connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch()));
|
connect(m_ui.findEdit, SIGNAL(editingFinished()), this, SLOT(invokeResetIncrementalSearch()));
|
||||||
|
|
||||||
QWidget *spacerItem = new QWidget;
|
m_ui.close->setProperty("type", QLatin1String("dockbutton"));
|
||||||
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
m_ui.close->setIcon(QIcon(":/core/images/closebutton.png"));
|
||||||
addWidget(spacerItem);
|
connect(m_ui.close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus()));
|
||||||
QToolButton *close = new QToolButton;
|
|
||||||
close->setProperty("type", QLatin1String("dockbutton"));
|
|
||||||
close->setIcon(QIcon(":/core/images/closebutton.png"));
|
|
||||||
connect(close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus()));
|
|
||||||
addWidget(close);
|
|
||||||
|
|
||||||
m_ui.findPreviousButton->setProperty("type", QLatin1String("dockbutton"));
|
m_ui.findPreviousButton->setProperty("type", QLatin1String("dockbutton"));
|
||||||
m_ui.findNextButton->setProperty("type", QLatin1String("dockbutton"));
|
m_ui.findNextButton->setProperty("type", QLatin1String("dockbutton"));
|
||||||
@@ -110,7 +106,7 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
|||||||
|
|
||||||
m_ui.findEdit->installEventFilter(this);
|
m_ui.findEdit->installEventFilter(this);
|
||||||
m_ui.replaceEdit->installEventFilter(this);
|
m_ui.replaceEdit->installEventFilter(this);
|
||||||
m_widget->installEventFilter(this);
|
this->installEventFilter(this);
|
||||||
|
|
||||||
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
|
connect(m_ui.findEdit, SIGNAL(textChanged(const QString&)), this, SLOT(invokeFindIncremental()));
|
||||||
connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()));
|
connect(m_ui.findEdit, SIGNAL(returnPressed()), this, SLOT(invokeFindEnter()));
|
||||||
@@ -234,6 +230,56 @@ FindToolBar::~FindToolBar()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FindToolBar::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
// Currently from the style
|
||||||
|
// Goal should be to migrate that into a Utils::StyledWidget class
|
||||||
|
Q_UNUSED(event)
|
||||||
|
QPainter painter(this);
|
||||||
|
|
||||||
|
QRect selfRect = rect();
|
||||||
|
QString key;
|
||||||
|
key.sprintf("mh_toolbar %d %d %d", selfRect.width(), selfRect.height(), StyleHelper::baseColor().rgb());;
|
||||||
|
|
||||||
|
QPixmap pixmap;
|
||||||
|
QPainter *p = &painter;
|
||||||
|
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
|
||||||
|
pixmap = QPixmap(selfRect.size());
|
||||||
|
p = new QPainter(&pixmap);
|
||||||
|
selfRect = QRect(0, 0, selfRect.width(), selfRect.height());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Map offset for global window gradient
|
||||||
|
QPoint offset = window()->mapToGlobal(selfRect.topLeft()) -
|
||||||
|
mapToGlobal(selfRect.topLeft());
|
||||||
|
QRect gradientSpan;
|
||||||
|
gradientSpan = QRect(offset, window()->size());
|
||||||
|
StyleHelper::horizontalGradient(p, gradientSpan, selfRect);
|
||||||
|
|
||||||
|
p->setPen(StyleHelper::borderColor());
|
||||||
|
|
||||||
|
// Note: This is a hack to determine if the
|
||||||
|
// toolbar should draw the top or bottom outline
|
||||||
|
// (needed for the find toolbar for instance)
|
||||||
|
QColor lighter(255, 255, 255, 40);
|
||||||
|
if (property("topBorder").toBool()) {
|
||||||
|
p->drawLine(selfRect.topLeft(), selfRect.topRight());
|
||||||
|
p->setPen(lighter);
|
||||||
|
p->drawLine(selfRect.topLeft() + QPoint(0, 1), selfRect.topRight() + QPoint(0, 1));
|
||||||
|
} else {
|
||||||
|
p->drawLine(selfRect.bottomLeft(), selfRect.bottomRight());
|
||||||
|
p->setPen(lighter);
|
||||||
|
p->drawLine(selfRect.topLeft(), selfRect.topRight());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StyleHelper::usePixmapCache() && !QPixmapCache::find(key, pixmap)) {
|
||||||
|
painter.drawPixmap(selfRect.topLeft(), pixmap);
|
||||||
|
p->end();
|
||||||
|
delete p;
|
||||||
|
QPixmapCache::insert(key, pixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
|
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
|
||||||
@@ -251,7 +297,7 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (obj == m_widget && event->type() == QEvent::ShortcutOverride) {
|
} else if (obj == this && event->type() == QEvent::ShortcutOverride) {
|
||||||
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
|
||||||
if (ke->key() == Qt::Key_Escape && !ke->modifiers()
|
if (ke->key() == Qt::Key_Escape && !ke->modifiers()
|
||||||
&& !m_findCompleter->popup()->isVisible()
|
&& !m_findCompleter->popup()->isVisible()
|
||||||
@@ -268,13 +314,13 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
|||||||
event->accept();
|
event->accept();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (obj == m_widget && event->type() == QEvent::Hide) {
|
} else if (obj == this && event->type() == QEvent::Hide) {
|
||||||
invokeClearResults();
|
invokeClearResults();
|
||||||
if (m_currentDocumentFind->isEnabled()) {
|
if (m_currentDocumentFind->isEnabled()) {
|
||||||
m_currentDocumentFind->clearFindScope();
|
m_currentDocumentFind->clearFindScope();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QToolBar::eventFilter(obj, event);
|
return QWidget::eventFilter(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindToolBar::updateActions()
|
void FindToolBar::updateActions()
|
||||||
@@ -284,9 +330,11 @@ void FindToolBar::updateActions()
|
|||||||
m_findInDocumentAction->setEnabled(enabled);
|
m_findInDocumentAction->setEnabled(enabled);
|
||||||
m_findNextAction->setEnabled(enabled);
|
m_findNextAction->setEnabled(enabled);
|
||||||
m_findPreviousAction->setEnabled(enabled);
|
m_findPreviousAction->setEnabled(enabled);
|
||||||
|
|
||||||
m_replaceNextAction->setEnabled(replaceEnabled);
|
m_replaceNextAction->setEnabled(replaceEnabled);
|
||||||
m_replacePreviousAction->setEnabled(replaceEnabled);
|
m_replacePreviousAction->setEnabled(replaceEnabled);
|
||||||
m_replaceAllAction->setEnabled(replaceEnabled);
|
m_replaceAllAction->setEnabled(replaceEnabled);
|
||||||
|
|
||||||
m_caseSensitiveAction->setEnabled(enabled);
|
m_caseSensitiveAction->setEnabled(enabled);
|
||||||
m_wholeWordAction->setEnabled(enabled);
|
m_wholeWordAction->setEnabled(enabled);
|
||||||
m_regularExpressionAction->setEnabled(enabled);
|
m_regularExpressionAction->setEnabled(enabled);
|
||||||
@@ -295,8 +343,16 @@ void FindToolBar::updateActions()
|
|||||||
bool replaceFocus = m_ui.replaceEdit->hasFocus();
|
bool replaceFocus = m_ui.replaceEdit->hasFocus();
|
||||||
m_ui.findEdit->setEnabled(enabled);
|
m_ui.findEdit->setEnabled(enabled);
|
||||||
m_ui.findLabel->setEnabled(enabled);
|
m_ui.findLabel->setEnabled(enabled);
|
||||||
|
|
||||||
m_ui.replaceEdit->setEnabled(replaceEnabled);
|
m_ui.replaceEdit->setEnabled(replaceEnabled);
|
||||||
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
m_ui.replaceLabel->setEnabled(replaceEnabled);
|
||||||
|
m_ui.replaceEdit->setVisible(replaceEnabled);
|
||||||
|
m_ui.replaceLabel->setVisible(replaceEnabled);
|
||||||
|
m_ui.replacePreviousButton->setVisible(replaceEnabled);
|
||||||
|
m_ui.replaceNextButton->setVisible(replaceEnabled);
|
||||||
|
m_ui.replaceAllButton->setVisible(replaceEnabled);
|
||||||
|
layout()->invalidate();
|
||||||
|
|
||||||
if (!replaceEnabled && enabled && replaceFocus)
|
if (!replaceEnabled && enabled && replaceFocus)
|
||||||
m_ui.findEdit->setFocus();
|
m_ui.findEdit->setFocus();
|
||||||
updateIcons();
|
updateIcons();
|
||||||
@@ -540,7 +596,7 @@ bool FindToolBar::focusNextPrevChild(bool next)
|
|||||||
else if (!next && m_ui.findEdit->hasFocus())
|
else if (!next && m_ui.findEdit->hasFocus())
|
||||||
m_ui.replaceAllButton->setFocus(Qt::TabFocusReason);
|
m_ui.replaceAllButton->setFocus(Qt::TabFocusReason);
|
||||||
else
|
else
|
||||||
return QToolBar::focusNextPrevChild(next);
|
return QWidget::focusNextPrevChild(next);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,14 @@ namespace Internal {
|
|||||||
|
|
||||||
class FindPlugin;
|
class FindPlugin;
|
||||||
|
|
||||||
class FindToolBar : public QToolBar
|
class FindToolBar : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind);
|
FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind);
|
||||||
~FindToolBar();
|
~FindToolBar();
|
||||||
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
void readSettings();
|
void readSettings();
|
||||||
void writeSettings();
|
void writeSettings();
|
||||||
@@ -113,7 +114,6 @@ private:
|
|||||||
QAction *m_caseSensitiveAction;
|
QAction *m_caseSensitiveAction;
|
||||||
QAction *m_wholeWordAction;
|
QAction *m_wholeWordAction;
|
||||||
QAction *m_regularExpressionAction;
|
QAction *m_regularExpressionAction;
|
||||||
QWidget *m_widget;
|
|
||||||
IFindSupport::FindFlags m_findFlags;
|
IFindSupport::FindFlags m_findFlags;
|
||||||
|
|
||||||
QPixmap m_casesensitiveIcon;
|
QPixmap m_casesensitiveIcon;
|
||||||
|
|||||||
@@ -6,57 +6,47 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>600</width>
|
<width>603</width>
|
||||||
<height>71</height>
|
<height>90</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Find</string>
|
<string>Find</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="spacing">
|
|
||||||
<number>15</number>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="rightMargin">
|
<property name="rightMargin">
|
||||||
<number>5</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<property name="horizontalSpacing">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<number>5</number>
|
||||||
<property name="spacing">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<property name="verticalSpacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="findLabel">
|
<widget class="QLabel" name="findLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Find:</string>
|
<string>Find:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="0" column="1">
|
||||||
<widget class="Core::Utils::FancyLineEdit" name="findEdit">
|
<widget class="Core::Utils::FancyLineEdit" name="findEdit"/>
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>160</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>160</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="findPreviousButton">
|
<widget class="QToolButton" name="findPreviousButton">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
@@ -80,36 +70,43 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<widget class="QToolButton" name="close">
|
||||||
<property name="spacing">
|
<property name="text">
|
||||||
<number>2</number>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="replaceLabel">
|
<widget class="QLabel" name="replaceLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Replace with:</string>
|
<string>Replace with:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item row="1" column="1">
|
||||||
<widget class="QLineEdit" name="replaceEdit">
|
<widget class="QLineEdit" name="replaceEdit"/>
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>150</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>150</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>3</number>
|
||||||
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="replacePreviousButton">
|
<widget class="QToolButton" name="replacePreviousButton">
|
||||||
<property name="focusPolicy">
|
<property name="focusPolicy">
|
||||||
@@ -146,6 +143,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="replaceSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -157,6 +167,12 @@
|
|||||||
<header location="global">utils/fancylineedit.h</header>
|
<header location="global">utils/fancylineedit.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>findEdit</tabstop>
|
||||||
|
<tabstop>replaceEdit</tabstop>
|
||||||
|
<tabstop>close</tabstop>
|
||||||
|
<tabstop>replaceAllButton</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user