1 /***************************************************************************
2 * Copyright (C) 2005/06 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "topicwidget.h"
26 #include "networkmodel.h"
28 TopicWidget::TopicWidget(QWidget *parent)
29 : AbstractItemView(parent)
32 ui.topicLineEdit->hide();
33 ui.topicLineEdit->installEventFilter(this);
34 ui.topicLabel->show();
37 void TopicWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
39 setTopic(current.sibling(current.row(), 1).data().toString());
42 void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
43 QItemSelectionRange changedArea(topLeft, bottomRight);
44 QModelIndex currentTopicIndex = selectionModel()->currentIndex().sibling(selectionModel()->currentIndex().row(), 1);
45 if(changedArea.contains(currentTopicIndex))
46 setTopic(currentTopicIndex.data().toString());
49 void TopicWidget::setTopic(const QString &newtopic) {
50 if(_topic == newtopic)
54 ui.topicLabel->setText(newtopic);
55 ui.topicLineEdit->setText(newtopic);
59 void TopicWidget::on_topicLineEdit_returnPressed() {
60 QModelIndex currentIdx = currentIndex();
61 if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
62 BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
63 Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text()));
68 void TopicWidget::on_topicEditButton_clicked() {
72 void TopicWidget::switchEditable() {
73 ui.topicLabel->hide();
74 ui.topicEditButton->hide();
75 ui.topicLineEdit->show();
76 ui.topicLineEdit->setFocus();
79 void TopicWidget::switchPlain() {
80 ui.topicLineEdit->hide();
81 ui.topicLabel->show();
82 ui.topicEditButton->show();
83 ui.topicLineEdit->setText(_topic);
86 // filter for the input widget to switch back to normal mode
87 bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
88 if(event->type() == QEvent::FocusOut) {
93 if(event->type() != QEvent::KeyPress)
94 return QObject::eventFilter(obj, event);
96 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
98 if(keyEvent->key() == Qt::Key_Escape) {