/***************************************************************************
- * 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 *
: 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) {
+ ui.topicButton->setAndStyleText(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;
}