Make the newly arrived topicbutton display background colors and font styles.
[quassel.git] / src / qtui / topicwidget.cpp
index 40e7ae8..ede4a71 100644 (file)
@@ -26,14 +26,47 @@ TopicWidget::TopicWidget(QWidget *parent)
   : QWidget(parent)
 {
   ui.setupUi(this);
+  ui.topicLineEdit->hide();
+  ui.topicLineEdit->installEventFilter(this);
+  ui.topicButton->show();
 }
 
 void TopicWidget::setTopic(const QString &newtopic) {
+  ui.topicButton->setAndStyleText(newtopic);
   ui.topicLineEdit->setText(newtopic);
-  ui.topicLineEdit->setCursorPosition(0);
+  switchPlain();
 }
 
 void TopicWidget::on_topicLineEdit_returnPressed() {
-  ui.topicLineEdit->setCursorPosition(0);
+  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();
+    return true;
+  }
+  
+  return false;
+}