diff options
| author | Richard Maudsley <richard.maudsley@isode.com> | 2014-03-24 09:53:37 (GMT) |
|---|---|---|
| committer | Swift Review <review@swift.im> | 2014-04-02 11:45:22 (GMT) |
| commit | 1a35178bcad7c30e50a19e4017d021fb0485ccf0 (patch) | |
| tree | 3d52cee147d6c3f70866a1b5a4c4ae942bb3d48b /Swift/QtUI/UserSearch | |
| parent | c9275affd040ee1ca7c1d599b28df3b363bef888 (diff) | |
| download | swift-contrib-1a35178bcad7c30e50a19e4017d021fb0485ccf0.zip swift-contrib-1a35178bcad7c30e50a19e4017d021fb0485ccf0.tar.bz2 | |
Automatically moving user into the chat list when you select from the population drop-down.
Change-Id: I69b44e0e1dda2fa513d2d867ed10e5a8046ff0e9
Diffstat (limited to 'Swift/QtUI/UserSearch')
| -rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp | 3 | ||||
| -rw-r--r-- | Swift/QtUI/UserSearch/QtSuggestingJIDInput.h | 4 | ||||
| -rw-r--r-- | Swift/QtUI/UserSearch/QtUserSearchWindow.cpp | 2 |
3 files changed, 7 insertions, 2 deletions
diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp index ca65dca..de935d9 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.cpp @@ -99,71 +99,72 @@ void QtSuggestingJIDInput::keyPressEvent(QKeyEvent* event) { } } else if (event->key() == Qt::Key_Return && treeViewPopup_->isVisible()) { QModelIndex index = treeViewPopup_->currentIndex(); if (!contactListModel_->getList().empty() && index.isValid()) { currentContact_ = &contactListModel_->getList()[index.row()]; setText(P2QSTRING(currentContact_->jid.toString())); hidePopup(); clearFocus(); } else { currentContact_ = NULL; } editingDone(); } else { QLineEdit::keyPressEvent(event); } } void QtSuggestingJIDInput::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* /*now*/) { /* Using the now argument gives use the wrong widget. This is part of the code needed to prevent stealing of focus when opening a the suggestion window. */ QWidget* now = qApp->focusWidget(); if (!now || (now != treeViewPopup_ && now != this && !now->isAncestorOf(this) && !now->isAncestorOf(treeViewPopup_) && !this->isAncestorOf(now) && !treeViewPopup_->isAncestorOf(now))) { hidePopup(); } } void QtSuggestingJIDInput::handleSettingsChanged(const std::string& setting) { if (setting == QtUISettingConstants::COMPACT_ROSTER.getKey()) { contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); } } void QtSuggestingJIDInput::handleClicked(const QModelIndex& index) { if (index.isValid()) { currentContact_ = &contactListModel_->getList()[index.row()]; - setText(P2QSTRING(currentContact_->jid.toString())); + setText(""); + onUserSelected(currentContact_->jid); hidePopup(); } } void QtSuggestingJIDInput::positionPopup() { QDesktopWidget* desktop = QApplication::desktop(); int screen = desktop->screenNumber(this); QPoint point = mapToGlobal(QPoint(0, height())); QRect geometry = desktop->availableGeometry(screen); int x = point.x(); int y = point.y(); int width = this->width(); int height = 80; int screenWidth = geometry.x() + geometry.width(); if (x + width > screenWidth) { x = screenWidth - width; } height = treeViewPopup_->sizeHintForRow(0) * contactListModel_->rowCount(); height = height > 200 ? 200 : height; int marginLeft; int marginTop; int marginRight; int marginBottom; treeViewPopup_->getContentsMargins(&marginLeft, &marginTop, &marginRight, &marginBottom); height += marginTop + marginBottom; width += marginLeft + marginRight; treeViewPopup_->setGeometry(x, y, width, height); treeViewPopup_->move(x, y); treeViewPopup_->setMaximumWidth(width); } diff --git a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h index 673621c..9ec0512 100644 --- a/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h +++ b/Swift/QtUI/UserSearch/QtSuggestingJIDInput.h @@ -1,57 +1,59 @@ /* * Copyright (c) 2013 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #pragma once #include <QLineEdit> #include <QTreeView> - +#include <Swiften/Base/boost_bsignals.h> #include <Swift/Controllers/Contact.h> namespace Swift { class ContactListDelegate; class SettingsProvider; class ContactListModel; class QtSuggestingJIDInput : public QLineEdit { Q_OBJECT public: QtSuggestingJIDInput(QWidget* parent, SettingsProvider* settings); virtual ~QtSuggestingJIDInput(); const Contact* getContact(); void setSuggestions(const std::vector<Contact>& suggestions); + boost::signal<void (const JID&)> onUserSelected; + signals: void editingDone(); protected: virtual void keyPressEvent(QKeyEvent* event); private: void handleSettingsChanged(const std::string& setting); private slots: void handleClicked(const QModelIndex& index); void handleApplicationFocusChanged(QWidget* old, QWidget* now); private: void positionPopup(); void showPopup(); void hidePopup(); private: SettingsProvider* settings_; ContactListModel* contactListModel_; QTreeView* treeViewPopup_; ContactListDelegate* contactListDelegate_; Contact manualContact_; const Contact* currentContact_; }; } diff --git a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp index d06fa19..c0c7972 100644 --- a/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp +++ b/Swift/QtUI/UserSearch/QtUserSearchWindow.cpp @@ -1,47 +1,48 @@ /* * Copyright (c) 2010-2013 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Swift/QtUI/UserSearch/QtUserSearchWindow.h" #include <QItemDelegate> #include <QModelIndex> #include <QWizardPage> #include <QMovie> +#include <boost/bind.hpp> #include <boost/smart_ptr/make_shared.hpp> #include <Swiften/Base/foreach.h> #include <Swift/Controllers/UIEvents/UIEventStream.h> #include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> #include <Swift/Controllers/UIEvents/AddContactUIEvent.h> #include <Swift/Controllers/UIEvents/CreateImpromptuMUCUIEvent.h> #include <Swift/Controllers/UIEvents/InviteToMUCUIEvent.h> #include <Swift/QtUI/UserSearch/UserSearchModel.h> #include <Swift/QtUI/UserSearch/UserSearchDelegate.h> #include <Swift/QtUI/QtSwiftUtil.h> #include <Swift/QtUI/QtFormResultItemModel.h> #include <Swift/QtUI/UserSearch/QtUserSearchFirstPage.h> #include <Swift/QtUI/UserSearch/QtUserSearchFirstMultiJIDPage.h> #include <Swift/QtUI/UserSearch/QtUserSearchFieldsPage.h> #include <Swift/QtUI/UserSearch/QtUserSearchResultsPage.h> #include <Swift/QtUI/UserSearch/QtUserSearchDetailsPage.h> #include <Swift/QtUI/UserSearch/QtContactListWidget.h> #include <Swiften/Base/Log.h> namespace Swift { QtUserSearchWindow::QtUserSearchWindow(UIEventStream* eventStream, UserSearchWindow::Type type, const std::set<std::string>& groups, SettingsProvider* settingsProvider) : eventStream_(eventStream), type_(type), model_(NULL), settings_(settingsProvider), searchNext_(false), supportsImpromptu_(false) { setupUi(this); #ifndef Q_OS_MAC setWindowIcon(QIcon(":/logo-icon-16.png")); #endif QString title; switch(type) { case AddContact: title = tr("Add Contact"); break; case ChatToContact: title = tr("Chat to Users"); @@ -412,70 +413,71 @@ void QtUserSearchWindow::setResultsForm(Form::ref results) { resultsPage_->results_->setHeaderHidden(false); #if QT_VERSION >= 0x050000 resultsPage_->results_->header()->setSectionResizeMode(QHeaderView::ResizeToContents); #else resultsPage_->results_->header()->setResizeMode(QHeaderView::ResizeToContents); #endif delete model_; model_ = newModel; resultsPage_->setNoResults(model_->rowCount() == 0); resultsPage_->emitCompletenessCheck(); } void QtUserSearchWindow::setSelectedService(const JID& jid) { myServer_ = jid; } void QtUserSearchWindow::setFirstPage(QString title) { if (page(1) != 0) { removePage(1); } if (type_ == AddContact) { firstPage_ = new QtUserSearchFirstPage(type_, title.isEmpty() ? firstPage_->title() : title, settings_); connect(firstPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString))); connect(firstPage_->byJID_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange())); connect(firstPage_->byLocalSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange())); connect(firstPage_->byRemoteSearch_, SIGNAL(toggled(bool)), this, SLOT(handleFirstPageRadioChange())); #if QT_VERSION >= 0x040700 firstPage_->jid_->setPlaceholderText(tr("alice@wonderland.lit")); #endif firstPage_->service_->setEnabled(false); setPage(1, firstPage_); } else { firstMultiJIDPage_ = new QtUserSearchFirstMultiJIDPage(type_, title.isEmpty() ? firstMultiJIDPage_->title() : title, settings_); connect(firstMultiJIDPage_->addContactButton_, SIGNAL(clicked()), this, SLOT(addContact())); connect(firstMultiJIDPage_->jid_, SIGNAL(textEdited(QString)), this, SLOT(handleContactSuggestionRequested(QString))); + firstMultiJIDPage_->jid_->onUserSelected.connect(boost::bind(&QtUserSearchWindow::addSearchedJIDToList, this, _1)); connect(firstMultiJIDPage_->addViaSearchButton_, SIGNAL(clicked()), this, SLOT(handleAddViaSearch())); connect(firstMultiJIDPage_->contactList_, SIGNAL(onListChanged(std::vector<Contact>)), this, SLOT(handleListChanged(std::vector<Contact>))); connect(firstMultiJIDPage_->contactList_, SIGNAL(onJIDsAdded(std::vector<JID>)), this, SLOT(handleJIDsAdded(std::vector<JID>))); setPage(1, firstMultiJIDPage_); } } void QtUserSearchWindow::setSecondPage() { if (page(2) != 0) { removePage(2); } fieldsPage_ = new QtUserSearchFieldsPage(); fieldsPage_->fetchingThrobber_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this)); fieldsPage_->fetchingThrobber_->movie()->stop(); setPage(2, fieldsPage_); } void QtUserSearchWindow::setThirdPage() { if (page(3) != 0) { removePage(3); } resultsPage_ = new QtUserSearchResultsPage(); #ifdef SWIFT_PLATFORM_MACOSX resultsPage_->results_->setAlternatingRowColors(true); #endif if (type_ == AddContact) { connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next())); } else { connect(resultsPage_, SIGNAL(onUserTriggersContinue()), this, SLOT(next())); } setPage(3, resultsPage_); } |
Swift