Monolithic build features now zero setup configuration: click and run
[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   connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
55           _chatViewSearchController, SLOT(highlightPrev()));
56   connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
57           _chatViewSearchController, SLOT(highlightNext()));
58
59   connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
60           this, SLOT(scrollToHighlight(QGraphicsItem *)));
61 }
62
63 BufferWidget::~BufferWidget() {
64   delete _chatViewSearchController;
65   _chatViewSearchController = 0;
66 }
67
68 AbstractChatView *BufferWidget::createChatView(BufferId id) {
69   ChatView *chatView;
70   chatView = new ChatView(id, this);
71   _chatViews[id] = chatView;
72   ui.stackedWidget->addWidget(chatView);
73   chatView->setFocusProxy(this);
74   return chatView;
75 }
76
77 void BufferWidget::removeChatView(BufferId id) {
78   QWidget *view = _chatViews.value(id, 0);
79   if(!view) return;
80   ui.stackedWidget->removeWidget(view);
81   view->deleteLater();
82   _chatViews.take(id);
83 }
84
85 void BufferWidget::showChatView(BufferId id) {
86   if(!id.isValid()) {
87     ui.stackedWidget->setCurrentWidget(ui.page);
88   } else {
89     ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
90     Q_ASSERT(view);
91     ui.stackedWidget->setCurrentWidget(view);
92     _chatViewSearchController->setScene(view->scene());
93   }
94 }
95
96 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
97   ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
98   if(view) {
99     view->centerOn(highlightItem);
100   }
101 }