1 /***************************************************************************
2 * Copyright (C) 2005-08 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 "bufferwidget.h"
23 #include "chatviewsearchbar.h"
24 #include "chatviewsearchcontroller.h"
30 BufferWidget::BufferWidget(QWidget *parent)
31 : AbstractBufferContainer(parent),
32 _chatViewSearchController(new ChatViewSearchController(this))
35 layout()->setContentsMargins(0, 0, 0, 0);
36 layout()->setSpacing(0);
37 // ui.searchBar->hide();
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());
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 connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
55 _chatViewSearchController, SLOT(highlightPrev()));
56 connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
57 _chatViewSearchController, SLOT(highlightNext()));
59 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
60 this, SLOT(scrollToHighlight(QGraphicsItem *)));
63 BufferWidget::~BufferWidget() {
64 delete _chatViewSearchController;
65 _chatViewSearchController = 0;
68 AbstractChatView *BufferWidget::createChatView(BufferId id) {
70 chatView = new ChatView(id, this);
71 _chatViews[id] = chatView;
72 ui.stackedWidget->addWidget(chatView);
73 chatView->setFocusProxy(this);
77 void BufferWidget::removeChatView(BufferId id) {
78 QWidget *view = _chatViews.value(id, 0);
80 ui.stackedWidget->removeWidget(view);
85 void BufferWidget::showChatView(BufferId id) {
87 ui.stackedWidget->setCurrentWidget(ui.page);
89 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
91 ui.stackedWidget->setCurrentWidget(view);
92 _chatViewSearchController->setScene(view->scene());
96 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
97 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
99 view->centerOn(highlightItem);