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);
34 ui.topicLineEdit->installEventFilter(this);
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_textEntered() {
60 QModelIndex currentIdx = currentIndex();
61 if(currentIdx.isValid() && currentIdx.data(NetworkModel::BufferTypeRole) == BufferInfo::ChannelBuffer) {
62 BufferInfo bufferInfo = currentIdx.data(NetworkModel::BufferInfoRole).value<BufferInfo>();
63 if(ui.topicLineEdit->text().isEmpty())
64 Client::userInput(bufferInfo, QString("/quote TOPIC %1 :").arg(bufferInfo.bufferName()));
66 Client::userInput(bufferInfo, QString("/topic %1").arg(ui.topicLineEdit->text()));
71 void TopicWidget::on_topicEditButton_clicked() {
75 void TopicWidget::switchEditable() {
76 ui.stackedWidget->setCurrentIndex(1);
77 ui.topicLineEdit->setFocus();
81 void TopicWidget::switchPlain() {
82 ui.stackedWidget->setCurrentIndex(0);
83 ui.topicLineEdit->setText(_topic);
87 // filter for the input widget to switch back to normal mode
88 bool TopicWidget::eventFilter(QObject *obj, QEvent *event) {
89 if(event->type() == QEvent::FocusOut) {
94 if(event->type() != QEvent::KeyPress)
95 return QObject::eventFilter(obj, event);
97 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
99 if(keyEvent->key() == Qt::Key_Escape) {