From 309ee636b3939771777969dffa01aaf8aca216f8 Mon Sep 17 00:00:00 2001 From: con Date: Tue, 14 Jul 2009 18:01:25 +0200 Subject: [PATCH] Styled two-row find tool bar with better resizing behavior. For this we needed to get rid of using QToolBar. --- src/plugins/coreplugin/manhattanstyle.cpp | 2 + src/plugins/find/findtoolbar.cpp | 90 ++++++++++++--- src/plugins/find/findtoolbar.h | 4 +- src/plugins/find/findwidget.ui | 132 ++++++++++++---------- 4 files changed, 151 insertions(+), 77 deletions(-) diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 4370ab49d59..171dac813f2 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -86,6 +86,8 @@ bool panelWidget(const QWidget *widget) return true; else if (qobject_cast(p) && styleEnabled(p)) return true; + else if (p->property("panelwidget").toBool()) + return true; p = p->parentWidget(); } return false; diff --git a/src/plugins/find/findtoolbar.cpp b/src/plugins/find/findtoolbar.cpp index 8b7a4bb6af0..0ddd2d259e6 100644 --- a/src/plugins/find/findtoolbar.cpp +++ b/src/plugins/find/findtoolbar.cpp @@ -32,6 +32,7 @@ #include "textfindconstants.h" #include +#include #include #include #include @@ -49,9 +50,10 @@ #include #include #include -#include #include #include +#include +#include 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(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; } diff --git a/src/plugins/find/findtoolbar.h b/src/plugins/find/findtoolbar.h index 4b85c1a9e83..ca1b1ba5268 100644 --- a/src/plugins/find/findtoolbar.h +++ b/src/plugins/find/findtoolbar.h @@ -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; diff --git a/src/plugins/find/findwidget.ui b/src/plugins/find/findwidget.ui index b11792768d0..8fb5973c130 100644 --- a/src/plugins/find/findwidget.ui +++ b/src/plugins/find/findwidget.ui @@ -6,57 +6,47 @@ 0 0 - 600 - 71 + 603 + 90 Find - - - 15 - + 5 - 1 + 2 - 5 + 0 1 - + + 5 + + + 0 + + + + + Find: + + + + + + + - 2 + 3 - - - - Find: - - - - - - - - 160 - 0 - - - - - 160 - 16777215 - - - - @@ -80,36 +70,43 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ... + + + - + + + + Replace with: + + + + + + + - 2 + 3 - - - - Replace with: - - - - - - - - 150 - 0 - - - - - 150 - 16777215 - - - - @@ -146,6 +143,19 @@ + + + + Qt::Horizontal + + + + 40 + 0 + + + + @@ -157,6 +167,12 @@
utils/fancylineedit.h
+ + findEdit + replaceEdit + close + replaceAllButton +