Make the newly arrived topicbutton display background colors and font styles.
[quassel.git] / src / qtui / topicwidget.cpp
index ea319be..ede4a71 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
 /***************************************************************************
- *   Copyright (C) 2005/06 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005/06 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -26,15 +26,47 @@ TopicWidget::TopicWidget(QWidget *parent)
   : QWidget(parent)
 {
   ui.setupUi(this);
   : QWidget(parent)
 {
   ui.setupUi(this);
-}
-
-QString TopicWidget::topic() const {
-  return ui.topicLineEdit->text();
+  ui.topicLineEdit->hide();
+  ui.topicLineEdit->installEventFilter(this);
+  ui.topicButton->show();
 }
 
 void TopicWidget::setTopic(const QString &newtopic) {
 }
 
 void TopicWidget::setTopic(const QString &newtopic) {
+  ui.topicButton->setAndStyleText(newtopic);
   ui.topicLineEdit->setText(newtopic);
   ui.topicLineEdit->setText(newtopic);
+  switchPlain();
+}
+
+void TopicWidget::on_topicLineEdit_returnPressed() {
+  switchPlain();
+  emit topicChanged(topic());
+}
+
+void TopicWidget::on_topicButton_clicked() {
+  switchEditable();
 }
 
 }
 
-TopicWidget::~TopicWidget() {
+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;
 }
 }