diff options
Diffstat (limited to 'Swift/QtUI')
| -rw-r--r-- | Swift/QtUI/QtInviteToChatWindow.cpp | 22 | ||||
| -rw-r--r-- | Swift/QtUI/QtInviteToChatWindow.h | 5 |
2 files changed, 22 insertions, 5 deletions
diff --git a/Swift/QtUI/QtInviteToChatWindow.cpp b/Swift/QtUI/QtInviteToChatWindow.cpp index d53c493..3b8f1fc 100644 --- a/Swift/QtUI/QtInviteToChatWindow.cpp +++ b/Swift/QtUI/QtInviteToChatWindow.cpp @@ -13,20 +13,20 @@ #include <QPushButton> #include <QDialogButtonBox> #include <Swift/QtUI/QtSwiftUtil.h> namespace Swift { QtInviteToChatWindow::QtInviteToChatWindow(QWidget* parent) : QDialog(parent) { QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); - layout->setContentsMargins(0,0,0,0); - layout->setSpacing(2); + //layout->setContentsMargins(0,0,0,0); + //layout->setSpacing(2); QLabel* description = new QLabel(tr("Users to invite to this chat (one per line):")); layout->addWidget(description); jidsLayout_ = new QBoxLayout(QBoxLayout::TopToBottom); layout->addLayout(jidsLayout_); QLabel* reasonLabel = new QLabel(tr("If you want to provide a reason for the invitation, enter it here")); layout->addWidget(reasonLabel); @@ -39,18 +39,20 @@ QtInviteToChatWindow::QtInviteToChatWindow(QWidget* parent) : QDialog(parent) { QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); layout->addWidget(buttonBox); + jids_[0]->setFocus(); + setModal(false); show(); } QtInviteToChatWindow::~QtInviteToChatWindow() { } void QtInviteToChatWindow::handleAccepting() { @@ -75,19 +77,19 @@ std::vector<JID> QtInviteToChatWindow::getJIDs() const { results.push_back(jid); } } } return results; } void QtInviteToChatWindow::addJIDLine() { QLineEdit* jid = new QLineEdit(this); - QCompleter* completer = new QCompleter(completions_, this); + QCompleter* completer = new QCompleter(&completions_, this); completer->setCaseSensitivity(Qt::CaseInsensitive); jid->setCompleter(completer); jids_.push_back(jid); jidsLayout_->addWidget(jid); connect(jid, SIGNAL(textChanged(const QString&)), this, SLOT(handleJIDTextChanged())); } void QtInviteToChatWindow::handleJIDTextChanged() { bool gotEmpty = false; @@ -95,13 +97,27 @@ void QtInviteToChatWindow::handleJIDTextChanged() { if (edit->text().isEmpty()) { gotEmpty = true; } } if (!gotEmpty) { addJIDLine(); } } +typedef std::pair<JID, std::string> JIDString; + +void QtInviteToChatWindow::setAutoCompletions(std::vector<std::pair<JID, std::string> > completions) { + QStringList list; + foreach (JIDString jidPair, completions) { + QString line = P2QSTRING(jidPair.first.toString()); + if (jidPair.second != jidPair.first.toString() && !jidPair.second.empty()) { + line = P2QSTRING(jidPair.second) + " - " + line; + } + list.append(line); + } + completions_.setStringList(list); +} + } diff --git a/Swift/QtUI/QtInviteToChatWindow.h b/Swift/QtUI/QtInviteToChatWindow.h index c009861..a0167db 100644 --- a/Swift/QtUI/QtInviteToChatWindow.h +++ b/Swift/QtUI/QtInviteToChatWindow.h @@ -3,39 +3,40 @@ * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #pragma once #include <Swift/Controllers/UIInterfaces/InviteToChatWindow.h> #include <QDialog> -#include <QStringList> +#include <QStringListModel> class QLineEdit; class QBoxLayout; namespace Swift { class QtInviteToChatWindow : public QDialog, public InviteToChatWindow { Q_OBJECT public: QtInviteToChatWindow(QWidget* parent = NULL); virtual ~QtInviteToChatWindow(); virtual std::string getReason() const; virtual std::vector<JID> getJIDs() const; + virtual void setAutoCompletions(std::vector<std::pair<JID, std::string> > completions); private: void addJIDLine(); private slots: void handleJIDTextChanged(); void handleAccepting(); void handleRejecting(); private: - QStringList completions_; + QStringListModel completions_; QLineEdit* reason_; QBoxLayout* jidsLayout_; std::vector<QLineEdit*> jids_; }; } |
Swift