diff options
-rw-r--r-- | Swift/Controllers/UIInterfaces/ChatWindow.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/UnitTest/MockChatWindow.h | 2 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.cpp | 32 | ||||
-rw-r--r-- | Swift/QtUI/QtChatWindow.h | 3 |
4 files changed, 22 insertions, 17 deletions
diff --git a/Swift/Controllers/UIInterfaces/ChatWindow.h b/Swift/Controllers/UIInterfaces/ChatWindow.h index f2f5f76..6b2799b 100644 --- a/Swift/Controllers/UIInterfaces/ChatWindow.h +++ b/Swift/Controllers/UIInterfaces/ChatWindow.h @@ -164,7 +164,7 @@ namespace Swift { * @param buttonText Button text to use (optional, no button is shown if empty). * @return A handle to the alert message. */ - virtual AlertID addAlert(const std::string& alertText, const std::string& buttonText = "") = 0; + virtual AlertID addAlert(const std::string& alertText) = 0; /** * Removes an alert. * @param id An alert ID previously returned from setAlert diff --git a/Swift/Controllers/UnitTest/MockChatWindow.h b/Swift/Controllers/UnitTest/MockChatWindow.h index ef7216b..774bdd9 100644 --- a/Swift/Controllers/UnitTest/MockChatWindow.h +++ b/Swift/Controllers/UnitTest/MockChatWindow.h @@ -56,7 +56,7 @@ namespace Swift { void setAckState(const std::string& /*id*/, AckState /*state*/) {} virtual void flash() {} - virtual AlertID addAlert(const std::string& /*alertText*/, const std::string& /*buttonText*/) { return 0; } + virtual AlertID addAlert(const std::string& /*alertText*/) { return 0; } virtual void removeAlert(const AlertID /*id*/) {} virtual void setCorrectionEnabled(Tristate /*enabled*/) {} virtual void setFileTransferEnabled(Tristate /*enabled*/) {} diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 574a0a2..3491d3c 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -199,32 +199,38 @@ void QtChatWindow::handleFontResized(int fontSizeSteps) { } void QtChatWindow::handleAlertButtonClicked() { - onAlertButtonClicked(); + const QObject* alertWidget = QObject::sender()->parent(); + std::map<AlertID, QWidget*>::const_iterator i = alertWidgets_.begin(); + for ( ; i != alertWidgets_.end(); ++i) { + if (i->second == alertWidget) { + removeAlert(i->first); + break; + } + } } -QtChatWindow::AlertID QtChatWindow::addAlert(const std::string& alertText, const std::string& buttonText) { +QtChatWindow::AlertID QtChatWindow::addAlert(const std::string& alertText) { QWidget* alertWidget = new QWidget(this); QHBoxLayout* alertLayout = new QHBoxLayout(alertWidget); alertLayout_->addWidget(alertWidget); QLabel* alertLabel = new QLabel(this); + alertLabel->setText(alertText.c_str()); alertLayout->addWidget(alertLabel); - alertButton_ = new QPushButton(this); - connect (alertButton_, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked())); - alertLayout->addWidget(alertButton_); + + QToolButton* closeButton = new QToolButton(alertWidget); + closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton)); + closeButton->setIconSize(QSize(16,16)); + closeButton->setCursor(Qt::ArrowCursor); + closeButton->setStyleSheet("QToolButton { border: none; padding: 0px; }"); + connect (closeButton, SIGNAL(clicked()), this, SLOT(handleAlertButtonClicked())); + + alertLayout->addWidget(closeButton); QPalette palette = alertWidget->palette(); palette.setColor(QPalette::Window, QColor(Qt::yellow)); palette.setColor(QPalette::WindowText, QColor(Qt::black)); alertWidget->setStyleSheet(alertStyleSheet_); alertLabel->setStyleSheet(alertStyleSheet_); - alertLabel->setText(alertText.c_str()); - if (buttonText.empty()) { - alertButton_->hide(); - } else { - alertButton_->setText(buttonText.c_str()); - alertButton_->show(); - } - AlertID id = nextAlertId_++; alertWidgets_[id] = alertWidget; return id; diff --git a/Swift/QtUI/QtChatWindow.h b/Swift/QtUI/QtChatWindow.h index 45eaa6f..bf37557 100644 --- a/Swift/QtUI/QtChatWindow.h +++ b/Swift/QtUI/QtChatWindow.h @@ -134,7 +134,7 @@ namespace Swift { public slots: void handleChangeSplitterState(QByteArray state); void handleFontResized(int fontSizeSteps); - AlertID addAlert(const std::string& alertText, const std::string& buttonText = ""); + AlertID addAlert(const std::string& alertText); void removeAlert(const AlertID id); void setCorrectionEnabled(Tristate enabled); void setFileTransferEnabled(Tristate enabled); @@ -197,7 +197,6 @@ namespace Swift { QVBoxLayout* alertLayout_; std::map<AlertID, QWidget*> alertWidgets_; AlertID nextAlertId_; - QPushButton* alertButton_; TabComplete* completer_; QLineEdit* subject_; bool isCorrection_; |