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;
|
||||
else if (qobject_cast<const QMenuBar *>(p) && styleEnabled(p))
|
||||
return true;
|
||||
else if (p->property("panelwidget").toBool())
|
||||
return true;
|
||||
p = p->parentWidget();
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "textfindconstants.h"
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
#include <coreplugin/stylehelper.h>
|
||||
#include <coreplugin/findplaceholder.h>
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/stylehelper.h>
|
||||
@@ -49,9 +50,10 @@
|
||||
#include <QtGui/QKeyEvent>
|
||||
#include <QtGui/QLineEdit>
|
||||
#include <QtGui/QMenu>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPushButton>
|
||||
#include <QtGui/QToolButton>
|
||||
#include <QtGui/QPainter>
|
||||
#include <QtGui/QPixmapCache>
|
||||
|
||||
Q_DECLARE_METATYPE(QStringList)
|
||||
Q_DECLARE_METATYPE(Find::IFindFilter*)
|
||||
@@ -68,14 +70,13 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
|
||||
m_findNextAction(0),
|
||||
m_findPreviousAction(0),
|
||||
m_replaceNextAction(0),
|
||||
m_widget(new QWidget),
|
||||
m_casesensitiveIcon(":/find/images/casesensitively.png"),
|
||||
m_regexpIcon(":/find/images/regexp.png"),
|
||||
m_wholewordsIcon(":/find/images/wholewords.png")
|
||||
{
|
||||
//setup ui
|
||||
m_ui.setupUi(m_widget);
|
||||
addWidget(m_widget);
|
||||
m_ui.setupUi(this);
|
||||
setProperty("panelwidget", true);
|
||||
setFocusProxy(m_ui.findEdit);
|
||||
setProperty("topBorder", true);
|
||||
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()));
|
||||
|
||||
QWidget *spacerItem = new QWidget;
|
||||
spacerItem->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
addWidget(spacerItem);
|
||||
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.close->setProperty("type", QLatin1String("dockbutton"));
|
||||
m_ui.close->setIcon(QIcon(":/core/images/closebutton.png"));
|
||||
connect(m_ui.close, SIGNAL(clicked()), this, SLOT(hideAndResetFocus()));
|
||||
|
||||
m_ui.findPreviousButton->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.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(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)
|
||||
{
|
||||
if ((obj == m_ui.findEdit || obj == m_findCompleter->popup())
|
||||
@@ -251,7 +297,7 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
||||
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);
|
||||
if (ke->key() == Qt::Key_Escape && !ke->modifiers()
|
||||
&& !m_findCompleter->popup()->isVisible()
|
||||
@@ -268,13 +314,13 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
|
||||
event->accept();
|
||||
return true;
|
||||
}
|
||||
} else if (obj == m_widget && event->type() == QEvent::Hide) {
|
||||
} else if (obj == this && event->type() == QEvent::Hide) {
|
||||
invokeClearResults();
|
||||
if (m_currentDocumentFind->isEnabled()) {
|
||||
m_currentDocumentFind->clearFindScope();
|
||||
}
|
||||
}
|
||||
return QToolBar::eventFilter(obj, event);
|
||||
return QWidget::eventFilter(obj, event);
|
||||
}
|
||||
|
||||
void FindToolBar::updateActions()
|
||||
@@ -284,9 +330,11 @@ void FindToolBar::updateActions()
|
||||
m_findInDocumentAction->setEnabled(enabled);
|
||||
m_findNextAction->setEnabled(enabled);
|
||||
m_findPreviousAction->setEnabled(enabled);
|
||||
|
||||
m_replaceNextAction->setEnabled(replaceEnabled);
|
||||
m_replacePreviousAction->setEnabled(replaceEnabled);
|
||||
m_replaceAllAction->setEnabled(replaceEnabled);
|
||||
|
||||
m_caseSensitiveAction->setEnabled(enabled);
|
||||
m_wholeWordAction->setEnabled(enabled);
|
||||
m_regularExpressionAction->setEnabled(enabled);
|
||||
@@ -295,8 +343,16 @@ void FindToolBar::updateActions()
|
||||
bool replaceFocus = m_ui.replaceEdit->hasFocus();
|
||||
m_ui.findEdit->setEnabled(enabled);
|
||||
m_ui.findLabel->setEnabled(enabled);
|
||||
|
||||
m_ui.replaceEdit->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)
|
||||
m_ui.findEdit->setFocus();
|
||||
updateIcons();
|
||||
@@ -540,7 +596,7 @@ bool FindToolBar::focusNextPrevChild(bool next)
|
||||
else if (!next && m_ui.findEdit->hasFocus())
|
||||
m_ui.replaceAllButton->setFocus(Qt::TabFocusReason);
|
||||
else
|
||||
return QToolBar::focusNextPrevChild(next);
|
||||
return QWidget::focusNextPrevChild(next);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,13 +44,14 @@ namespace Internal {
|
||||
|
||||
class FindPlugin;
|
||||
|
||||
class FindToolBar : public QToolBar
|
||||
class FindToolBar : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumentFind);
|
||||
~FindToolBar();
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
void readSettings();
|
||||
void writeSettings();
|
||||
@@ -113,7 +114,6 @@ private:
|
||||
QAction *m_caseSensitiveAction;
|
||||
QAction *m_wholeWordAction;
|
||||
QAction *m_regularExpressionAction;
|
||||
QWidget *m_widget;
|
||||
IFindSupport::FindFlags m_findFlags;
|
||||
|
||||
QPixmap m_casesensitiveIcon;
|
||||
|
||||
@@ -6,57 +6,47 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>71</height>
|
||||
<width>603</width>
|
||||
<height>90</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Find</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
<property name="horizontalSpacing">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<property name="verticalSpacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="findLabel">
|
||||
<property name="text">
|
||||
<string>Find:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<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 row="0" column="1">
|
||||
<widget class="Core::Utils::FancyLineEdit" name="findEdit"/>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="findPreviousButton">
|
||||
<property name="focusPolicy">
|
||||
@@ -80,36 +70,43 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>2</number>
|
||||
<widget class="QToolButton" name="close">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<item>
|
||||
</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>
|
||||
<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 row="1" column="1">
|
||||
<widget class="QLineEdit" name="replaceEdit"/>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QToolButton" name="replacePreviousButton">
|
||||
<property name="focusPolicy">
|
||||
@@ -146,6 +143,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -157,6 +167,12 @@
|
||||
<header location="global">utils/fancylineedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>findEdit</tabstop>
|
||||
<tabstop>replaceEdit</tabstop>
|
||||
<tabstop>close</tabstop>
|
||||
<tabstop>replaceAllButton</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user