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"
29 #include "actioncollection.h"
35 BufferWidget::BufferWidget(QWidget *parent)
36 : AbstractBufferContainer(parent),
37 _chatViewSearchController(new ChatViewSearchController(this))
40 layout()->setContentsMargins(0, 0, 0, 0);
41 layout()->setSpacing(0);
42 // ui.searchBar->hide();
44 _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
45 _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
46 _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
47 _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
49 connect(ui.searchBar->searchEditLine(), SIGNAL(textChanged(const QString &)),
50 _chatViewSearchController, SLOT(setSearchString(const QString &)));
51 connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
52 _chatViewSearchController, SLOT(setCaseSensitive(bool)));
53 connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
54 _chatViewSearchController, SLOT(setSearchSenders(bool)));
55 connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
56 _chatViewSearchController, SLOT(setSearchMsgs(bool)));
57 connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
58 _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
59 connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
60 _chatViewSearchController, SLOT(highlightPrev()));
61 connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
62 _chatViewSearchController, SLOT(highlightNext()));
64 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
65 this, SLOT(scrollToHighlight(QGraphicsItem *)));
67 ActionCollection *coll = QtUi::actionCollection();
69 Action *zoomChatview = coll->add<Action>("ZoomChatView");
70 connect(zoomChatview, SIGNAL(triggered()), SLOT(zoomIn()));
71 zoomChatview->setText(tr("Enlarge Chat View"));
72 zoomChatview->setShortcut(tr("Ctrl++"));
74 Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView");
75 connect(zoomOutChatview, SIGNAL(triggered()), SLOT(zoomOut()));
76 zoomOutChatview->setText(tr("Demagnify Chat View"));
77 zoomOutChatview->setShortcut(tr("Ctrl+-"));
79 Action *zoomNormalChatview = coll->add<Action>("ZoomNormalChatView");
80 connect(zoomNormalChatview, SIGNAL(triggered()), SLOT(zoomNormal()));
81 zoomNormalChatview->setText(tr("Normalize zoom of Chat View"));
82 zoomNormalChatview->setShortcut(tr("Ctrl+0"));
85 BufferWidget::~BufferWidget() {
86 delete _chatViewSearchController;
87 _chatViewSearchController = 0;
90 AbstractChatView *BufferWidget::createChatView(BufferId id) {
92 chatView = new ChatView(id, this);
93 _chatViews[id] = chatView;
94 ui.stackedWidget->addWidget(chatView);
95 chatView->setFocusProxy(this);
99 void BufferWidget::removeChatView(BufferId id) {
100 QWidget *view = _chatViews.value(id, 0);
102 ui.stackedWidget->removeWidget(view);
107 void BufferWidget::showChatView(BufferId id) {
109 ui.stackedWidget->setCurrentWidget(ui.page);
111 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
113 ui.stackedWidget->setCurrentWidget(view);
114 _chatViewSearchController->setScene(view->scene());
118 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
119 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
121 view->centerOn(highlightItem);
126 void BufferWidget::zoomIn() {
127 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
132 void BufferWidget::zoomOut() {
133 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
138 void BufferWidget::zoomNormal() {
139 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
144 bool BufferWidget::eventFilter(QObject *watched, QEvent *event) {
146 if(event->type() != QEvent::KeyPress)
149 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
150 switch(keyEvent->key()) {
152 case Qt::Key_PageDown:
153 // static cast to access public qobject::event
154 return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);