1 /***************************************************************************
2 * Copyright (C) 2005-09 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 ***************************************************************************/
27 #include "actioncollection.h"
28 #include "bufferwidget.h"
30 #include "chatviewsearchbar.h"
31 #include "chatviewsearchcontroller.h"
33 #include "iconloader.h"
34 #include "multilineedit.h"
39 BufferWidget::BufferWidget(QWidget *parent)
40 : AbstractBufferContainer(parent),
41 _chatViewSearchController(new ChatViewSearchController(this))
44 layout()->setContentsMargins(0, 0, 0, 0);
45 layout()->setSpacing(0);
46 // ui.searchBar->hide();
48 _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
49 _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
50 _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
51 _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
53 connect(ui.searchBar, SIGNAL(searchChanged(const QString &)),
54 _chatViewSearchController, SLOT(setSearchString(const QString &)));
55 connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
56 _chatViewSearchController, SLOT(setCaseSensitive(bool)));
57 connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
58 _chatViewSearchController, SLOT(setSearchSenders(bool)));
59 connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
60 _chatViewSearchController, SLOT(setSearchMsgs(bool)));
61 connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
62 _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
63 connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
64 _chatViewSearchController, SLOT(highlightPrev()));
65 connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
66 _chatViewSearchController, SLOT(highlightNext()));
68 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
69 this, SLOT(scrollToHighlight(QGraphicsItem *)));
71 ActionCollection *coll = QtUi::actionCollection();
73 Action *zoomInChatview = coll->add<Action>("ZoomInChatView", this, SLOT(zoomIn()));
74 zoomInChatview->setText(tr("Zoom In"));
75 zoomInChatview->setIcon(SmallIcon("zoom-in"));
76 zoomInChatview->setShortcut(QKeySequence::ZoomIn);
78 Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView", this, SLOT(zoomOut()));
79 zoomOutChatview->setIcon(SmallIcon("zoom-out"));
80 zoomOutChatview->setText(tr("Zoom Out"));
81 zoomOutChatview->setShortcut(QKeySequence::ZoomOut);
83 Action *zoomOriginalChatview = coll->add<Action>("ZoomOriginalChatView", this, SLOT(zoomOriginal()));
84 zoomOriginalChatview->setIcon(SmallIcon("zoom-original"));
85 zoomOriginalChatview->setText(tr("Actual Size"));
86 //zoomOriginalChatview->setShortcut(tr("Ctrl+0")); // used for RTS switching
89 BufferWidget::~BufferWidget() {
90 delete _chatViewSearchController;
91 _chatViewSearchController = 0;
94 AbstractChatView *BufferWidget::createChatView(BufferId id) {
96 chatView = new ChatView(id, this);
97 chatView->setBufferContainer(this);
98 _chatViews[id] = chatView;
99 ui.stackedWidget->addWidget(chatView);
100 chatView->setFocusProxy(this);
104 void BufferWidget::removeChatView(BufferId id) {
105 QWidget *view = _chatViews.value(id, 0);
107 ui.stackedWidget->removeWidget(view);
112 void BufferWidget::showChatView(BufferId id) {
114 ui.stackedWidget->setCurrentWidget(ui.page);
116 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
118 ui.stackedWidget->setCurrentWidget(view);
119 _chatViewSearchController->setScene(view->scene());
123 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
124 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
126 view->centerOn(highlightItem);
131 void BufferWidget::zoomIn() {
132 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
137 void BufferWidget::zoomOut() {
138 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
143 void BufferWidget::zoomOriginal() {
144 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
146 view->zoomOriginal();
149 void BufferWidget::addActionsToMenu(QMenu *menu, const QPointF &pos) {
151 ActionCollection *coll = QtUi::actionCollection();
152 menu->addSeparator();
153 menu->addAction(coll->action("ZoomInChatView"));
154 menu->addAction(coll->action("ZoomOutChatView"));
155 menu->addAction(coll->action("ZoomOriginalChatView"));
158 bool BufferWidget::eventFilter(QObject *watched, QEvent *event) {
159 if(event->type() != QEvent::KeyPress)
162 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
164 MultiLineEdit *inputLine = qobject_cast<MultiLineEdit *>(watched);
168 // Intercept copy key presses
169 if(keyEvent == QKeySequence::Copy) {
170 if(inputLine->hasSelectedText())
172 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
174 view->scene()->selectionToClipboard();
178 // We don't want to steal cursor movement keys if the input line is in multiline mode
179 if(!inputLine->isSingleLine())
182 switch(keyEvent->key()) {
185 if(!(keyEvent->modifiers() & Qt::ShiftModifier))
188 case Qt::Key_PageDown:
189 // static cast to access public qobject::event
190 return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);