X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Ftopicwidget.cpp;h=ede4a71e6529a102cdc12cbfc58bdbc64289578d;hp=40e7ae8e21c747634a96f133f5d92d02f45d6f1c;hb=87828aeae2510b29619aa79a3bd76885e2c1ebd4;hpb=dcba0652ac1275877b98b06d6482924ee6df0cd1;ds=sidebyside diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index 40e7ae8e..ede4a71e 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -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(event); + + if(keyEvent->key() == Qt::Key_Escape) { + switchPlain(); + return true; + } + + return false; +}