X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Ftopicwidget.cpp;h=8adb0b6b46b3f4cba2ea5e0c222518fe5a400ef5;hp=40e7ae8e21c747634a96f133f5d92d02f45d6f1c;hb=a23256347cc47605dd0660127052846427bc998d;hpb=826409f0fdf8027b615a2f382398f100f36e7392 diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index 40e7ae8e..8adb0b6b 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -26,14 +26,46 @@ 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(); +} + +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; +}