fixing speed up aftermath
[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 <QLayout>
29
30 BufferWidget::BufferWidget(QWidget *parent)
31   : AbstractBufferContainer(parent),
32     _chatViewSearchController(new ChatViewSearchController(this))
33 {
34   ui.setupUi(this);
35   layout()->setContentsMargins(0, 0, 0, 0);
36   layout()->setSpacing(0);
37   // ui.searchBar->hide();
38
39   _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
40   _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
41   _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
42   _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
43
44   connect(ui.searchBar->searchEditLine(), SIGNAL(textChanged(const QString &)),
45           _chatViewSearchController, SLOT(setSearchString(const QString &)));
46   connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
47           _chatViewSearchController, SLOT(setCaseSensitive(bool)));
48   connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
49           _chatViewSearchController, SLOT(setSearchSenders(bool)));
50   connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
51           _chatViewSearchController, SLOT(setSearchMsgs(bool)));
52   connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
53           _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
54 }
55
56 BufferWidget::~BufferWidget() {
57   delete _chatViewSearchController;
58   _chatViewSearchController = 0;
59 }
60
61 AbstractChatView *BufferWidget::createChatView(BufferId id) {
62   ChatView *chatView;
63   chatView = new ChatView(id, this);
64   _chatViews[id] = chatView;
65   ui.stackedWidget->addWidget(chatView);
66   chatView->setFocusProxy(this);
67   return chatView;
68 }
69
70 void BufferWidget::removeChatView(BufferId id) {
71   QWidget *view = _chatViews.value(id, 0);
72   if(!view) return;
73   ui.stackedWidget->removeWidget(view);
74   view->deleteLater();
75   _chatViews.take(id);
76 }
77
78 void BufferWidget::showChatView(BufferId id) {
79   if(!id.isValid()) {
80     ui.stackedWidget->setCurrentWidget(ui.page);
81   } else {
82     ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
83     Q_ASSERT(view);
84     ui.stackedWidget->setCurrentWidget(view);
85     _chatViewSearchController->setScene(view->scene());
86   }
87 }
88