X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Ftopicwidget.cpp;h=2f8f5fa4e29c62f75f4c8813c2dfbd987db4993f;hb=09d19fe065125ccc6e406fa325d675387788ab3c;hp=ea319bef36aca15b7425990294c3d459638fa655;hpb=d6b056e936ec441258d291b7a8af7b83f9f53016;p=quassel.git diff --git a/src/qtui/topicwidget.cpp b/src/qtui/topicwidget.cpp index ea319bef..2f8f5fa4 100644 --- a/src/qtui/topicwidget.cpp +++ b/src/qtui/topicwidget.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * 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 * @@ -20,21 +20,92 @@ #include "topicwidget.h" -#include +#include "client.h" +#include "iconloader.h" +#include "networkmodel.h" TopicWidget::TopicWidget(QWidget *parent) - : QWidget(parent) + : AbstractItemView(parent) { ui.setupUi(this); + ui.topicEditButton->setIcon(SmallIcon("edit-rename")); + ui.topicLineEdit->setWordWrapEnabled(true); + ui.topicLineEdit->installEventFilter(this); + + connect(ui.topicLabel, SIGNAL(clickableActivated(Clickable)), SLOT(clickableActivated(Clickable))); } -QString TopicWidget::topic() const { - return ui.topicLineEdit->text(); +void TopicWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { + Q_UNUSED(previous); + setTopic(current.sibling(current.row(), 1).data().toString()); } +void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { + QItemSelectionRange changedArea(topLeft, bottomRight); + QModelIndex currentTopicIndex = selectionModel()->currentIndex().sibling(selectionModel()->currentIndex().row(), 1); + if(changedArea.contains(currentTopicIndex)) + setTopic(currentTopicIndex.data().toString()); +}; + void TopicWidget::setTopic(const QString &newtopic) { + if(_topic == newtopic) + return; + + _topic = newtopic; + ui.topicLabel->setText(newtopic); ui.topicLineEdit->setText(newtopic); + switchPlain(); +} + +void TopicWidget::clickableActivated(const Clickable &click) { + NetworkId networkId = selectionModel()->currentIndex().data(NetworkModel::NetworkIdRole).value(); + click.activate(networkId, _topic); +} + +void TopicWidget::on_topicLineEdit_textEntered() { + QModelIndex currentIdx = currentIndex(); + if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) { + BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value(); + if(ui.topicLineEdit->text().isEmpty()) + Client::userInput(bufferInfo, QString("/quote TOPIC %1 :").arg(bufferInfo.bufferName())); + else + Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text())); + } + switchPlain(); +} + +void TopicWidget::on_topicEditButton_clicked() { + switchEditable(); } -TopicWidget::~TopicWidget() { +void TopicWidget::switchEditable() { + ui.stackedWidget->setCurrentIndex(1); + ui.topicLineEdit->setFocus(); + updateGeometry(); +} + +void TopicWidget::switchPlain() { + ui.stackedWidget->setCurrentIndex(0); + ui.topicLineEdit->setText(_topic); + updateGeometry(); +} + +// 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); + + QKeyEvent *keyEvent = static_cast(event); + + if(keyEvent->key() == Qt::Key_Escape) { + switchPlain(); + return true; + } + + return false; }