e16735e53ea45da58158184c7511f150107e9aa9
[quassel.git] / src / qtui / bufferwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-08 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #include "bufferwidget.h"
22 #include "chatview.h"
23 #include "chatviewsearchbar.h"
24 #include "chatviewsearchcontroller.h"
25 #include "settings.h"
26 #include "client.h"
27
28 #include "global.h"
29
30 #include <QLayout>
31
32 BufferWidget::BufferWidget(QWidget *parent)
33   : AbstractBufferContainer(parent),
34     _chatViewSearchController(new ChatViewSearchController(this))
35 {
36   ui.setupUi(this);
37   layout()->setContentsMargins(0, 0, 0, 0);
38   layout()->setSpacing(0);
39   // ui.searchBar->hide();
40
41   _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
42   _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
43   _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
44   _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
45   
46   connect(ui.searchBar->searchEditLine(), SIGNAL(textChanged(const QString &)),
47           _chatViewSearchController, SLOT(setSearchString(const QString &)));
48   connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
49           _chatViewSearchController, SLOT(setCaseSensitive(bool)));
50   connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
51           _chatViewSearchController, SLOT(setSearchSenders(bool)));
52   connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
53           _chatViewSearchController, SLOT(setSearchMsgs(bool)));
54   connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
55           _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
56 }
57
58 BufferWidget::~BufferWidget() {
59   delete _chatViewSearchController;
60   _chatViewSearchController = 0;
61 }
62
63 AbstractChatView *BufferWidget::createChatView(BufferId id) {
64   ChatView *chatView;
65   chatView = new ChatView(id, this);
66   _chatViews[id] = chatView;
67   ui.stackedWidget->addWidget(chatView);
68   chatView->setFocusProxy(this);
69   return chatView;
70 }
71
72 void BufferWidget::removeChatView(BufferId id) {
73   QWidget *view = _chatViews.value(id, 0);
74   if(!view) return;
75   ui.stackedWidget->removeWidget(view);
76   view->deleteLater();
77   _chatViews.take(id);
78 }
79
80 void BufferWidget::showChatView(BufferId id) {
81   if(!id.isValid()) {
82     ui.stackedWidget->setCurrentWidget(ui.page);
83   } else {
84     ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
85     Q_ASSERT(view);
86     ui.stackedWidget->setCurrentWidget(view);
87     _chatViewSearchController->setScene(view->scene());
88   }
89 }
90