diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 48 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 9 |
2 files changed, 56 insertions, 1 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 32c3067..c7a6fa8 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -24,37 +24,53 @@ #include <QCloseEvent> #include <QComboBox> #include <QFileInfo> #include <QLineEdit> #include <QSplitter> #include <QString> #include <QTextEdit> #include <QTime> #include <QUrl> +#include <QPushButton> namespace Swift { QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventStream* eventStream) : QtTabbable(), contact_(contact), previousMessageWasSelf_(false), previousMessageWasSystem_(false), previousMessageWasPresence_(false), eventStream_(eventStream) { unreadCount_ = 0; inputEnabled_ = true; completer_ = NULL; theme_ = theme; isCorrection_ = false; + correctionEnabled_ = Maybe; updateTitleWithUnreadCount(); QtSettingsProvider settings; QBoxLayout *layout = new QBoxLayout(QBoxLayout::TopToBottom, this); layout->setContentsMargins(0,0,0,0); layout->setSpacing(2); + alertWidget_ = new QWidget(this); + QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget_); + layout->addWidget(alertWidget_); + alertLabel_ = new QLabel(this); + alertLayout->addWidget(alertLabel_); + alertButton_ = new QPushButton(this); + connect (alertButton_, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked())); + alertLayout->addWidget(alertButton_); + QPalette palette = alertWidget_->palette(); + palette.setColor(QPalette::Window, QColor(Qt::yellow)); + palette.setColor(QPalette::WindowText, QColor(Qt::black)); + alertWidget_->setPalette(palette); + alertLabel_->setPalette(palette); + alertWidget_->hide(); + logRosterSplitter_ = new QSplitter(this); logRosterSplitter_->setAutoFillBackground(true); layout->addWidget(logRosterSplitter_); - messageLog_ = new QtChatView(theme, this); logRosterSplitter_->addWidget(messageLog_); treeWidget_ = new QtTreeWidget(eventStream_); treeWidget_->setEditable(false); treeWidget_->hide(); logRosterSplitter_->addWidget(treeWidget_); logRosterSplitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); connect(logRosterSplitter_, SIGNAL(splitterMoved(int, int)), this, SLOT(handleSplitterMoved(int, int))); @@ -98,22 +114,42 @@ QtChatWindow::QtChatWindow(const QString &contact, QtChatTheme* theme, UIEventSt connect(messageLog_, SIGNAL(gotFocus()), input_, SLOT(setFocus())); resize(400,300); connect(messageLog_, SIGNAL(fontResized(int)), this, SIGNAL(fontResized(int))); } QtChatWindow::~QtChatWindow() { } + void QtChatWindow::handleFontResized(int fontSizeSteps) { messageLog_->resizeFont(fontSizeSteps); } +void QtChatWindow::handleAlertButtonClicked() { + onAlertButtonClicked(); +} + +void QtChatWindow::setAlert(const std::string& alertText, const std::string& buttonText) { + alertLabel_->setText(alertText.c_str()); + if (buttonText.empty()) { + alertButton_->hide(); + } else { + alertButton_->setText(buttonText.c_str()); + alertButton_->show(); + } + alertWidget_->show(); +} + +void QtChatWindow::cancelAlert() { + alertWidget_->hide(); +} + void QtChatWindow::setTabComplete(TabComplete* completer) { completer_ = completer; } void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { int key = event->key(); Qt::KeyboardModifiers modifiers = event->modifiers(); if (key == Qt::Key_W && modifiers == Qt::ControlModifier) { close(); @@ -140,28 +176,34 @@ void QtChatWindow::handleKeyPressEvent(QKeyEvent* event) { cancelCorrection(); } else if (key == Qt::Key_Down || key == Qt::Key_Up) { /* Drop */ } else { messageLog_->handleKeyPressEvent(event); } } void QtChatWindow::beginCorrection() { + if (correctionEnabled_ == ChatWindow::Maybe) { + setAlert(Q2PSTRING(tr("This chat may not support message correction. If you send a correction anyway, it may appear as a duplicate message"))); + } else if (correctionEnabled_ == ChatWindow::No) { + setAlert(Q2PSTRING(tr("This chat does not support message correction. If you send a correction anyway, it will appear as a duplicate message"))); + } QTextCursor cursor = input_->textCursor(); cursor.select(QTextCursor::Document); cursor.beginEditBlock(); cursor.insertText(QString(lastSentMessage_)); cursor.endEditBlock(); isCorrection_ = true; correctingLabel_->show(); } void QtChatWindow::cancelCorrection() { + cancelAlert(); QTextCursor cursor = input_->textCursor(); cursor.select(QTextCursor::Document); cursor.removeSelectedText(); isCorrection_ = false; correctingLabel_->hide(); } QByteArray QtChatWindow::getSplitterState() { return logRosterSplitter_->saveState(); @@ -231,18 +273,22 @@ void QtChatWindow::setSecurityLabelsError() { void QtChatWindow::setSecurityLabelsEnabled(bool enabled) { if (enabled) { labelsWidget_->setEnabled(true); labelsWidget_->show(); } else { labelsWidget_->hide(); } } +void QtChatWindow::setCorrectionEnabled(Tristate enabled) { + correctionEnabled_ = enabled; +} + SecurityLabelsCatalog::Item QtChatWindow::getSelectedSecurityLabel() { assert(labelsWidget_->isEnabled()); return availableLabels_[labelsWidget_->currentIndex()]; } void QtChatWindow::closeEvent(QCloseEvent* event) { event->accept(); emit windowClosing(); onClosed(); diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 78d8f91..bc2d821 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -13,18 +13,19 @@ #include "SwifTools/LastLineTracker.h" #include "Swiften/Base/IDGenerator.h" class QTextEdit; class QLineEdit; class QComboBox; class QLabel; class QSplitter; +class QPushButton; namespace Swift { class QtChatView; class QtTreeWidget; class QtTreeWidgetFactory; class QtChatTheme; class TreeWidget; class QtTextEdit; class UIEventStream; @@ -57,18 +58,21 @@ namespace Swift { int getCount(); void replaceLastMessage(const std::string& message); void setAckState(const std::string& id, AckState state); void flash(); QByteArray getSplitterState(); public slots: void handleChangeSplitterState(QByteArray state); void handleFontResized(int fontSizeSteps); + void setAlert(const std::string& alertText, const std::string& buttonText = ""); + void cancelAlert(); + void setCorrectionEnabled(Tristate enabled); signals: void geometryChanged(); void splitterMoved(); void fontResized(int); protected slots: void qAppFocusChanged(QWidget* old, QWidget* now); void closeEvent(QCloseEvent* event); @@ -77,18 +81,19 @@ namespace Swift { protected: void showEvent(QShowEvent* event); private slots: void returnPressed(); void handleInputChanged(); void handleKeyPressEvent(QKeyEvent* event); void handleSplitterMoved(int pos, int index); + void handleAlertButtonClicked(); private: void updateTitleWithUnreadCount(); void tabComplete(); void beginCorrection(); void cancelCorrection(); std::string addMessage(const std::string &message, const std::string &senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const QString& style, const boost::posix_time::ptime& time); int unreadCount_; @@ -96,23 +101,27 @@ namespace Swift { LastLineTracker lastLineTracker_; QString contact_; QString lastSentMessage_; QtChatView* messageLog_; QtChatTheme* theme_; QtTextEdit* input_; QComboBox* labelsWidget_; QtTreeWidget* treeWidget_; QLabel* correctingLabel_; + QLabel* alertLabel_; + QWidget* alertWidget_; + QPushButton* alertButton_; TabComplete* completer_; std::vector<SecurityLabelsCatalog::Item> availableLabels_; bool isCorrection_; bool previousMessageWasSelf_; bool previousMessageWasSystem_; bool previousMessageWasPresence_; QString previousSenderName_; bool inputClearing_; UIEventStream* eventStream_; bool inputEnabled_; IDGenerator id_; QSplitter *logRosterSplitter_; + Tristate correctionEnabled_; }; } |