fixes, cleanup and other improvements... Now I know how a GC feels ;)
[quassel.git] / src / qtui / topicwidget.cpp
index cb646ed..ab901fd 100644 (file)
 
 #include <QDebug>
 
+#include "client.h"
+#include "networkmodel.h"
+
 TopicWidget::TopicWidget(QWidget *parent)
   : AbstractItemView(parent)
 {
   ui.setupUi(this);
   ui.topicLineEdit->hide();
   ui.topicLineEdit->installEventFilter(this);
-  ui.topicButton->show();
+  ui.topicLabel->show();
 }
 
 void TopicWidget::currentChanged(const QModelIndex &current, const QModelIndex &previous) {
@@ -48,29 +51,35 @@ void TopicWidget::setTopic(const QString &newtopic) {
     return;
   
   _topic = newtopic;
-  ui.topicButton->setAndStyleText(newtopic);
+  ui.topicLabel->setText(newtopic);
   ui.topicLineEdit->setText(newtopic);
   switchPlain();
 }
 
 void TopicWidget::on_topicLineEdit_returnPressed() {
-  emit topicChanged(ui.topicLineEdit->text());
+  QModelIndex currentIdx = currentIndex();
+  if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
+    BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
+    Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text()));
+  }
   switchPlain();
 }
 
-void TopicWidget::on_topicButton_clicked() {
+void TopicWidget::on_topicEditButton_clicked() {
   switchEditable();
 }
 
 void TopicWidget::switchEditable() {
-  ui.topicButton->hide();
+  ui.topicLabel->hide();
+  ui.topicEditButton->hide();
   ui.topicLineEdit->show();
   ui.topicLineEdit->setFocus();
 }
 
 void TopicWidget::switchPlain() {
   ui.topicLineEdit->hide();
-  ui.topicButton->show();
+  ui.topicLabel->show();
+  ui.topicEditButton->show();
   ui.topicLineEdit->setText(_topic);
 }
 
@@ -93,3 +102,4 @@ bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
   
   return false;
 }
+