+void TopicWidget::setTopic(const QString &newtopic) {
+ if(_topic == newtopic)
+ return;
+
+ _topic = newtopic;
+ ui.topicButton->setAndStyleText(newtopic);
+ ui.topicLineEdit->setText(newtopic);
+ switchPlain();
+}
+
+void TopicWidget::on_topicLineEdit_returnPressed() {
+ switchPlain();
+ emit topicChanged(topic());
+}
+
+void TopicWidget::on_topicButton_clicked() {
+ switchEditable();
+}
+
+void TopicWidget::switchEditable() {
+ ui.topicButton->hide();
+ ui.topicLineEdit->show();
+ ui.topicLineEdit->setFocus();
+}
+
+void TopicWidget::switchPlain() {
+ ui.topicLineEdit->hide();
+ ui.topicButton->show();
+}
+
+bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
+ if(event->type() != QEvent::KeyPress)
+ return QObject::eventFilter(obj, event);
+
+ QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
+
+ if(keyEvent->key() == Qt::Key_Escape) {
+ switchPlain();
+ ui.topicLineEdit->setText(_topic);
+ return true;
+ }
+
+ return false;