diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-02 10:40:38 (GMT) | 
|---|---|---|
| committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-07-08 09:11:59 (GMT) | 
| commit | 8ab7ca17fdde8f8fb62a0c574478aa2c4c01a9bc (patch) | |
| tree | 26a3b88639149370fcd231bd102bc37e039b07d3 /Swift | |
| parent | b4fe7ad5c1036b1d24470d9f8e0888faf582530a (diff) | |
| download | swift-contrib-8ab7ca17fdde8f8fb62a0c574478aa2c4c01a9bc.zip swift-contrib-8ab7ca17fdde8f8fb62a0c574478aa2c4c01a9bc.tar.bz2 | |
Added close/clear button to roster filter search term box.
Test-Information:
Verify that the clear button resets the roster filter and hides the search box. Verify that the roster filter continues to behave as normal.
Change-Id: Ifa5de1e611334b83634ac31d30bf912fd5c4da87
Diffstat (limited to 'Swift')
| -rw-r--r-- | Swift/QtUI/QtClosableLineEdit.cpp | 59 | ||||
| -rw-r--r-- | Swift/QtUI/QtClosableLineEdit.h | 43 | ||||
| -rw-r--r-- | Swift/QtUI/Roster/QtFilterWidget.cpp | 17 | ||||
| -rw-r--r-- | Swift/QtUI/Roster/QtFilterWidget.h | 6 | ||||
| -rw-r--r-- | Swift/QtUI/SConscript | 1 | 
5 files changed, 117 insertions, 9 deletions
| diff --git a/Swift/QtUI/QtClosableLineEdit.cpp b/Swift/QtUI/QtClosableLineEdit.cpp new file mode 100644 index 0000000..512194b --- /dev/null +++ b/Swift/QtUI/QtClosableLineEdit.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +/* Contains demo Trolltech code from http://git.forwardbias.in/?p=lineeditclearbutton.git with license: */ +/**************************************************************************** +** +** Copyright (c) 2007 Trolltech ASA <info@trolltech.com> +** +** Use, modification and distribution is allowed without limitation, +** warranty, liability or support of any kind. +** +****************************************************************************/ + +#include <Swift/QtUI/QtClosableLineEdit.h> +#include <QApplication> +#include <QToolButton> +#include <QStyle> +#include <QKeyEvent> + +namespace Swift { + +const int QtClosableLineEdit::clearButtonPadding = 2; + +QtClosableLineEdit::QtClosableLineEdit(QWidget *parent) : QLineEdit(parent) { +	clearButton = new QToolButton(this); +	clearButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); +	clearButton->setIconSize(QSize(16,16)); +	clearButton->setCursor(Qt::ArrowCursor); +	clearButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); +	clearButton->hide(); +	connect(clearButton, SIGNAL(clicked()), this, SLOT(handleCloseButtonClicked())); +	connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateCloseButton(const QString&))); +	int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); +	setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(clearButton->sizeHint().width() + frameWidth + 1)); +	QSize minimumSize = minimumSizeHint(); +	setMinimumSize(qMax(minimumSize.width(), clearButton->sizeHint().width() + frameWidth * 2 + clearButtonPadding), +								qMax(minimumSize.height(), clearButton->sizeHint().height() + frameWidth * 2 + clearButtonPadding)); +} + +void QtClosableLineEdit::resizeEvent(QResizeEvent *) { +	QSize size = clearButton->sizeHint(); +	int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); +	clearButton->move(rect().right() - frameWidth - size.width(), (rect().bottom() + 1 - size.height())/2); +} + +void QtClosableLineEdit::updateCloseButton(const QString& text) { +	clearButton->setVisible(!text.isEmpty()); +} + +void QtClosableLineEdit::handleCloseButtonClicked() { +	clear(); +	QApplication::postEvent(this, new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier)); +	QApplication::postEvent(this, new QKeyEvent(QEvent::KeyRelease, Qt::Key_Escape, Qt::NoModifier)); +} + +} diff --git a/Swift/QtUI/QtClosableLineEdit.h b/Swift/QtUI/QtClosableLineEdit.h new file mode 100644 index 0000000..91b4f0e --- /dev/null +++ b/Swift/QtUI/QtClosableLineEdit.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +/* Contains demo Trolltech code from http://git.forwardbias.in/?p=lineeditclearbutton.git with license: */ +/**************************************************************************** +** +** Copyright (c) 2007 Trolltech ASA <info@trolltech.com> +** +** Use, modification and distribution is allowed without limitation, +** warranty, liability or support of any kind. +** +****************************************************************************/ + +#pragma once + +#include <QLineEdit> + +class QToolButton; + +namespace Swift { + +class QtClosableLineEdit : public QLineEdit +{ +	Q_OBJECT +	public: +		QtClosableLineEdit(QWidget *parent = 0); + +	protected: +		void resizeEvent(QResizeEvent *); + +	private slots: +		void updateCloseButton(const QString &text); +		void handleCloseButtonClicked(); + +	private: +		static const int clearButtonPadding; +		QToolButton *clearButton; +}; + +} diff --git a/Swift/QtUI/Roster/QtFilterWidget.cpp b/Swift/QtUI/Roster/QtFilterWidget.cpp index 2f08981..a4c9449 100644 --- a/Swift/QtUI/Roster/QtFilterWidget.cpp +++ b/Swift/QtUI/Roster/QtFilterWidget.cpp @@ -1,62 +1,69 @@  /* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +/*   * Copyright (c) 2013 Tobias Markmann   * Licensed under the simplified BSD license.   * See Documentation/Licenses/BSD-simplified.txt for more information.   */ -#include <QLayout> -#include <QVBoxLayout> -#include <QKeyEvent>  #include <QEvent> +#include <QKeyEvent> +#include <QLayout>  #include <QString> -#include <QEvent> +#include <QVBoxLayout> +  #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h>  #include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/QtUI/QtClosableLineEdit.h>  #include <Swift/QtUI/QtSwiftUtil.h>  #include <Swift/QtUI/Roster/QtFilterWidget.h>  namespace Swift {  QtFilterWidget::QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout) : QWidget(parent), treeView_(treeView), eventStream_(eventStream), fuzzyRosterFilter_(0), isModifierSinglePressed_(false) {  	int targetIndex = layout->indexOf(treeView);  	QVBoxLayout* vboxLayout = new QVBoxLayout(this);  	vboxLayout->setSpacing(0);  	vboxLayout->setContentsMargins(0,0,0,0); -	filterLineEdit_ = new QLineEdit(this); +	filterLineEdit_ = new QtClosableLineEdit(this);  	filterLineEdit_->hide();  	vboxLayout->addWidget(filterLineEdit_);  	vboxLayout->addWidget(treeView);  	setLayout(vboxLayout);  	layout->insertWidget(targetIndex, this);  	filterLineEdit_->installEventFilter(this);  	treeView->installEventFilter(this);  	sourceModel_ = treeView_->model();  }  QtFilterWidget::~QtFilterWidget() {  }  bool QtFilterWidget::eventFilter(QObject*, QEvent* event) {  	if (event->type() == QEvent::KeyPress ||  		event->type() == QEvent::KeyRelease ||  		// InputMethodQuery got introduced in Qt 5.  #if QT_VERSION >= 0x050000  		event->type() == QEvent::InputMethodQuery ||  #endif  		event->type() == QEvent::InputMethod) {  		event->ignore();  		QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);  		if (keyEvent) {  			if (keyEvent->key() == Qt::Key_Up || keyEvent->key() == Qt::Key_Down) {  				return false;  			} else if ((keyEvent->key() == Qt::Key_Left || keyEvent->key() == Qt::Key_Right) && filterLineEdit_->text().isEmpty()) {  				return false;  			} else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyPress) {  				isModifierSinglePressed_ = true;  			} else if (keyEvent->key() == Qt::Key_Alt && event->type() == QEvent::KeyRelease && isModifierSinglePressed_) { diff --git a/Swift/QtUI/Roster/QtFilterWidget.h b/Swift/QtUI/Roster/QtFilterWidget.h index 94ebc2a..3e17566 100644 --- a/Swift/QtUI/Roster/QtFilterWidget.h +++ b/Swift/QtUI/Roster/QtFilterWidget.h @@ -1,50 +1,48 @@  /*   * Copyright (c) 2013 Tobias Markmann   * Licensed under the simplified BSD license.   * See Documentation/Licenses/BSD-simplified.txt for more information.   */  #pragma once  #include <vector>  #include <QBoxLayout> -#include <QLineEdit>  #include <QWidget>  #include <Swift/Controllers/Roster/RosterFilter.h>  #include <Swift/Controllers/Roster/FuzzyRosterFilter.h>  #include <Swift/QtUI/Roster/QtTreeWidget.h>  namespace Swift { -  class UIEventStream; - +class QtClosableLineEdit;  class QtFilterWidget : public QWidget {  	Q_OBJECT  	public:  		QtFilterWidget(QWidget* parent, QtTreeWidget* treeView, UIEventStream* eventStream, QBoxLayout* layout = 0);  		virtual ~QtFilterWidget();  	protected:  		bool eventFilter(QObject*, QEvent* event);  	private:  		void popAllFilters();  		void pushAllFilters();  		void updateRosterFilters();  		void updateSearchFilter();  	private: -		QLineEdit* filterLineEdit_; +		QtClosableLineEdit* filterLineEdit_;  		QtTreeWidget* treeView_;  		UIEventStream* eventStream_;  		std::vector<RosterFilter*> filters_;  		QAbstractItemModel* sourceModel_;  		FuzzyRosterFilter* fuzzyRosterFilter_;  		bool isModifierSinglePressed_;  };  } diff --git a/Swift/QtUI/SConscript b/Swift/QtUI/SConscript index 06b04fa..53dbea9 100644 --- a/Swift/QtUI/SConscript +++ b/Swift/QtUI/SConscript @@ -98,70 +98,71 @@ sources = [      "QtBlockListEditorWindow.cpp",      "QtNameWidget.cpp",      "QtSettingsProvider.cpp",      "QtStatusWidget.cpp",      "QtScaledAvatarCache.cpp",      "QtSwift.cpp",      "QtURIHandler.cpp",      "QtChatWindow.cpp",      "QtChatView.cpp",      "QtWebKitChatView.cpp",      "QtPlainChatView.cpp",      "QtChatTheme.cpp",      "QtChatTabs.cpp",      "QtSoundPlayer.cpp",      "QtSystemTray.cpp",      "QtCachedImageScaler.cpp",      "QtTabbable.cpp",      "QtTabWidget.cpp",      "QtTextEdit.cpp",      "QtXMLConsoleWidget.cpp",      "QtHistoryWindow.cpp",      "QtFileTransferListWidget.cpp",      "QtFileTransferListItemModel.cpp",      "QtAdHocCommandWindow.cpp",      "QtUtilities.cpp",      "QtBookmarkDetailWindow.cpp",      "QtAddBookmarkWindow.cpp",      "QtEditBookmarkWindow.cpp",      "QtContactEditWindow.cpp",      "QtContactEditWidget.cpp",      "QtSingleWindow.cpp",      "QtHighlightEditorWidget.cpp",      "QtHighlightRulesItemModel.cpp",      "QtHighlightRuleWidget.cpp",      "QtColorToolButton.cpp", +    "QtClosableLineEdit.cpp",      "ChatSnippet.cpp",      "MessageSnippet.cpp",      "SystemMessageSnippet.cpp",      "QtElidingLabel.cpp",      "QtFormWidget.cpp",      "QtFormResultItemModel.cpp",      "QtLineEdit.cpp",      "QtJoinMUCWindow.cpp",      "QtConnectionSettingsWindow.cpp",      "Roster/RosterModel.cpp",      "Roster/QtTreeWidget.cpp",  #    "Roster/QtTreeWidgetItem.cpp",      "Roster/RosterDelegate.cpp",      "Roster/GroupItemDelegate.cpp",      "Roster/DelegateCommons.cpp",      "Roster/QtFilterWidget.cpp",      "Roster/QtRosterWidget.cpp",      "Roster/QtOccupantListWidget.cpp",      "Roster/RosterTooltip.cpp",      "EventViewer/EventModel.cpp",      "EventViewer/EventDelegate.cpp",      "EventViewer/TwoLineDelegate.cpp",      "EventViewer/QtEventWindow.cpp",      "EventViewer/QtEvent.cpp",      "ChatList/QtChatListWindow.cpp",      "ChatList/ChatListModel.cpp",      "ChatList/ChatListDelegate.cpp",      "ChatList/ChatListMUCItem.cpp",      "ChatList/ChatListRecentItem.cpp",      "ChatList/ChatListWhiteboardItem.cpp",      "MUCSearch/QtMUCSearchWindow.cpp",      "MUCSearch/MUCSearchModel.cpp",      "MUCSearch/MUCSearchRoomItem.cpp",      "MUCSearch/MUCSearchEmptyItem.cpp",      "MUCSearch/MUCSearchDelegate.cpp", | 
 Swift
 Swift