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"
24 #include "iconloader.h"
25 #include "networkmodel.h"
27 TopicWidget::TopicWidget(QWidget *parent)
28 : AbstractItemView(parent)
31 ui.topicEditButton->setIcon(SmallIcon("edit-rename"));
32 ui.topicLineEdit->setWordWrapEnabled(true);
33 ui.topicLineEdit->installEventFilter(this);
35 connect(ui.topicLabel, SIGNAL(clickableActivated(Clickable)), SLOT(clickableActivated(Clickable)));
38 void TopicWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) {
40 setTopic(current.sibling(current.row(), 1).data().toString());
43 void TopicWidget::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) {
44 QItemSelectionRange changedArea(topLeft, bottomRight);
45 QModelIndex currentTopicIndex = selectionModel()->currentIndex().sibling(selectionModel()->currentIndex().row(), 1);
46 if(changedArea.contains(currentTopicIndex))
47 setTopic(currentTopicIndex.data().toString());
50 void TopicWidget::setTopic(const QString &newtopic) {
51 if(_topic == newtopic)
55 ui.topicLabel->setText(newtopic);
56 ui.topicLineEdit->setText(newtopic);
60 void TopicWidget::clickableActivated(const Clickable &click) {
61 NetworkId networkId = selectionModel()->currentIndex().data(NetworkModel::NetworkIdRole).value<NetworkId>();
62 click.activate(networkId, _topic);
65 void TopicWidget::on_topicLineEdit_textEntered() {
66 QModelIndex currentIdx = currentIndex();
67 if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
68 BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
69 if(ui.topicLineEdit->text().isEmpty())
70 Client::userInput(bufferInfo, QString("/quote TOPIC %1 :").arg(bufferInfo.bufferName()));
72 Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text()));
77 void TopicWidget::on_topicEditButton_clicked() {
81 void TopicWidget::switchEditable() {
82 ui.stackedWidget->setCurrentIndex(1);
83 ui.topicLineEdit->setFocus();
87 void TopicWidget::switchPlain() {
88 ui.stackedWidget->setCurrentIndex(0);
89 ui.topicLineEdit->setText(_topic);
93 // filter for the input widget to switch back to normal mode
94 bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
95 if(event->type() == QEvent::FocusOut) {
100 if(event->type() != QEvent::KeyPress)
101 return QObject::eventFilter(obj, event);
103 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
105 if(keyEvent->key() == Qt::Key_Escape) {