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"
36 BufferWidget::BufferWidget(QWidget *parent)
37 : AbstractBufferContainer(parent),
38 _chatViewSearchController(new ChatViewSearchController(this))
41 layout()->setContentsMargins(0, 0, 0, 0);
42 layout()->setSpacing(0);
43 // ui.searchBar->hide();
45 _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
46 _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
47 _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
48 _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
50 connect(ui.searchBar->searchEditLine(), SIGNAL(textChanged(const QString &)),
51 _chatViewSearchController, SLOT(setSearchString(const QString &)));
52 connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
53 _chatViewSearchController, SLOT(setCaseSensitive(bool)));
54 connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
55 _chatViewSearchController, SLOT(setSearchSenders(bool)));
56 connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
57 _chatViewSearchController, SLOT(setSearchMsgs(bool)));
58 connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
59 _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
60 connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
61 _chatViewSearchController, SLOT(highlightPrev()));
62 connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
63 _chatViewSearchController, SLOT(highlightNext()));
65 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
66 this, SLOT(scrollToHighlight(QGraphicsItem *)));
68 ActionCollection *coll = QtUi::actionCollection();
70 Action *zoomChatview = coll->add<Action>("ZoomChatView");
71 connect(zoomChatview, SIGNAL(triggered()), SLOT(zoomIn()));
72 zoomChatview->setText(tr("Enlarge Chat View"));
73 zoomChatview->setShortcut(tr("Ctrl++"));
75 Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView");
76 connect(zoomOutChatview, SIGNAL(triggered()), SLOT(zoomOut()));
77 zoomOutChatview->setText(tr("Demagnify Chat View"));
78 zoomOutChatview->setShortcut(tr("Ctrl+-"));
80 Action *zoomNormalChatview = coll->add<Action>("ZoomNormalChatView");
81 connect(zoomNormalChatview, SIGNAL(triggered()), SLOT(zoomNormal()));
82 zoomNormalChatview->setText(tr("Normalize zoom of Chat View"));
83 zoomNormalChatview->setShortcut(tr("Ctrl+0"));
86 BufferWidget::~BufferWidget() {
87 delete _chatViewSearchController;
88 _chatViewSearchController = 0;
91 AbstractChatView *BufferWidget::createChatView(BufferId id) {
93 chatView = new ChatView(id, this);
94 _chatViews[id] = chatView;
95 ui.stackedWidget->addWidget(chatView);
96 chatView->setFocusProxy(this);
100 void BufferWidget::removeChatView(BufferId id) {
101 QWidget *view = _chatViews.value(id, 0);
103 ui.stackedWidget->removeWidget(view);
108 void BufferWidget::showChatView(BufferId id) {
110 ui.stackedWidget->setCurrentWidget(ui.page);
112 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
114 ui.stackedWidget->setCurrentWidget(view);
115 _chatViewSearchController->setScene(view->scene());
119 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
120 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
122 view->centerOn(highlightItem);
127 void BufferWidget::zoomIn() {
128 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
133 void BufferWidget::zoomOut() {
134 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
139 void BufferWidget::zoomNormal() {
140 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
145 bool BufferWidget::eventFilter(QObject *watched, QEvent *event) {
147 if(event->type() != QEvent::KeyPress)
150 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
153 switch(keyEvent->key()) {
155 case Qt::Key_PageDown:
156 // static cast to access public qobject::event
157 return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);
162 if(keyEvent->modifiers() == Qt::ShiftModifier) {
163 QAbstractScrollArea *scrollArea = qobject_cast<QAbstractScrollArea*>(ui.stackedWidget->currentWidget());
166 int sliderPosition = scrollArea->verticalScrollBar()->value();
167 scrollArea->verticalScrollBar()->setValue(sliderPosition + (direction * 12));