From 253bcd613e1935c5f93df581e3499e7d3f787208 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Mon, 24 May 2010 22:21:46 +0100 Subject: Allow setting status messages again. This is not a nice solution to an unpleasant problem - Qt is telling us we've lost focus, so we cancel ... while we're in the middle of completing a successful status set. So we need to keep track and make sure we don't clear out the status on cancel if we're also accepting. diff --git a/Swift/QtUI/QtStatusWidget.cpp b/Swift/QtUI/QtStatusWidget.cpp index e909f5c..ab2e854 100644 --- a/Swift/QtUI/QtStatusWidget.cpp +++ b/Swift/QtUI/QtStatusWidget.cpp @@ -90,7 +90,7 @@ QtStatusWidget::~QtStatusWidget() { } void QtStatusWidget::handleApplicationFocusChanged(QWidget* /*old*/, QWidget* now) { - if (stack_->currentIndex() == 0) { + if (!editing_ || stack_->currentIndex() == 0) { return; } if (!now || (now != menu_ && now != statusEdit_ && !now->isAncestorOf(statusEdit_) && !now->isAncestorOf(menu_) && !statusEdit_->isAncestorOf(now) && !menu_->isAncestorOf(now))) { @@ -106,7 +106,11 @@ void QtStatusWidget::mousePressEvent(QMouseEvent*) { } void QtStatusWidget::generateList() { + if (!editing_) { + return; + } QString text = statusEdit_->text(); + newStatusText_ = text; menu_->clear(); foreach (StatusShow::Type type, icons_.keys()) { QListWidgetItem* item = new QListWidgetItem(text, menu_); @@ -117,6 +121,7 @@ void QtStatusWidget::generateList() { void QtStatusWidget::handleClicked() { + editing_ = true; QPoint point = mapToGlobal(QPoint(0, height())); int x = point.x(); int y = point.y(); @@ -143,17 +148,20 @@ void QtStatusWidget::handleClicked() { } void QtStatusWidget::viewMode() { + editing_ = false; menu_->hide(); stack_->setCurrentIndex(0); } void QtStatusWidget::handleEditComplete() { - statusText_ = statusEdit_->text(); + editing_ = false; + statusText_ = newStatusText_; viewMode(); emit onChangeStatusRequest(selectedStatusType_, statusText_); } void QtStatusWidget::handleEditCancelled() { + editing_ = false; setStatusText(statusText_); viewMode(); } @@ -163,6 +171,7 @@ StatusShow::Type QtStatusWidget::getSelectedStatusShow() { } void QtStatusWidget::handleItemClicked(QListWidgetItem* item) { + editing_ = false; selectedStatusType_ = (StatusShow::Type)(item->data(Qt::UserRole).toInt()); handleEditComplete(); } diff --git a/Swift/QtUI/QtStatusWidget.h b/Swift/QtUI/QtStatusWidget.h index ef8b397..111bc84 100644 --- a/Swift/QtUI/QtStatusWidget.h +++ b/Swift/QtUI/QtStatusWidget.h @@ -48,12 +48,14 @@ namespace Swift { QLabel* statusTextLabel_; QtLineEdit* statusEdit_; QString statusText_; + QString newStatusText_; QMap icons_; StatusShow::Type selectedStatusType_; bool isClicking_; QListWidget* menu_; QCursor editCursor_; QCursor viewCursor_; + bool editing_; }; } -- cgit v0.10.2-6-g49f6