X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Ftopicwidget.cpp;h=f5e6c9e1ae93ed2c853aa659f3d5b1c67c1d92f7;hp=511d27522520e6730079cab26afbef1a9fbaa3d9;hb=1b2d3ea62867220d7bffc3b23dda1dc14d429007;hpb=08cf52eafbd690bbaa3c86e57cb02e7e82dc3159 diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index 511d2752..f5e6c9e1 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -23,7 +23,7 @@ #include TopicWidget::TopicWidget(QWidget *parent) - : QWidget(parent) + : AbstractItemView(parent) { ui.setupUi(this); ui.topicLineEdit->hide(); @@ -31,6 +31,23 @@ TopicWidget::TopicWidget(QWidget *parent) ui.topicButton->show(); } +void TopicWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { + Q_UNUSED(previous); + setTopicForIndex(current); +} + +void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { + QItemSelectionRange changedArea(topLeft, bottomRight); + QModelIndex currentIndex = selectionModel()->currentIndex(); + if(changedArea.contains(currentIndex)) + setTopicForIndex(currentIndex); +}; + +void TopicWidget::setTopicForIndex(const QModelIndex &index) { + QModelIndex topicIndex = index.sibling(index.row(), 1); + setTopic(topicIndex.data().toString()); +} + void TopicWidget::setTopic(const QString &newtopic) { if(_topic == newtopic) return; @@ -42,8 +59,8 @@ void TopicWidget::setTopic(const QString &newtopic) { } void TopicWidget::on_topicLineEdit_returnPressed() { + emit topicChanged(ui.topicLineEdit->text()); switchPlain(); - emit topicChanged(topic()); } void TopicWidget::on_topicButton_clicked() { @@ -59,9 +76,16 @@ void TopicWidget::switchEditable() { void TopicWidget::switchPlain() { ui.topicLineEdit->hide(); ui.topicButton->show(); + ui.topicLineEdit->setText(_topic); } +// filter for the input widget to switch back to normal mode bool TopicWidget::eventFilter(QObject *obj, QEvent *event) { + if(event->type() == QEvent::FocusOut) { + switchPlain(); + return true; + } + if(event->type() != QEvent::KeyPress) return QObject::eventFilter(obj, event); @@ -69,7 +93,6 @@ bool TopicWidget::eventFilter(QObject *obj, QEvent *event) { if(keyEvent->key() == Qt::Key_Escape) { switchPlain(); - ui.topicLineEdit->setText(_topic); return true; }