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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user