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(ui.searchBar, SIGNAL(hidden()), this, SLOT(setFocus()));
70 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
71 this, SLOT(scrollToHighlight(QGraphicsItem *)));
73 ActionCollection *coll = QtUi::actionCollection();
75 Action *zoomInChatview = coll->add<Action>("ZoomInChatView", this, SLOT(zoomIn()));
76 zoomInChatview->setText(tr("Zoom In"));
77 zoomInChatview->setIcon(SmallIcon("zoom-in"));
78 zoomInChatview->setShortcut(QKeySequence::ZoomIn);
80 Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView", this, SLOT(zoomOut()));
81 zoomOutChatview->setIcon(SmallIcon("zoom-out"));
82 zoomOutChatview->setText(tr("Zoom Out"));
83 zoomOutChatview->setShortcut(QKeySequence::ZoomOut);
85 Action *zoomOriginalChatview = coll->add<Action>("ZoomOriginalChatView", this, SLOT(zoomOriginal()));
86 zoomOriginalChatview->setIcon(SmallIcon("zoom-original"));
87 zoomOriginalChatview->setText(tr("Actual Size"));
88 //zoomOriginalChatview->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_0)); // used for RTS switching
91 BufferWidget::~BufferWidget() {
92 delete _chatViewSearchController;
93 _chatViewSearchController = 0;
96 AbstractChatView *BufferWidget::createChatView(BufferId id) {
98 chatView = new ChatView(id, this);
99 chatView->setBufferContainer(this);
100 _chatViews[id] = chatView;
101 ui.stackedWidget->addWidget(chatView);
102 chatView->setFocusProxy(this);
106 void BufferWidget::removeChatView(BufferId id) {
107 QWidget *view = _chatViews.value(id, 0);
109 ui.stackedWidget->removeWidget(view);
114 void BufferWidget::showChatView(BufferId id) {
116 ui.stackedWidget->setCurrentWidget(ui.page);
118 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
120 ui.stackedWidget->setCurrentWidget(view);
121 _chatViewSearchController->setScene(view->scene());
125 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
126 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
128 view->centerOn(highlightItem);
133 void BufferWidget::zoomIn() {
134 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
139 void BufferWidget::zoomOut() {
140 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
145 void BufferWidget::zoomOriginal() {
146 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
148 view->zoomOriginal();
151 void BufferWidget::addActionsToMenu(QMenu *menu, const QPointF &pos) {
153 ActionCollection *coll = QtUi::actionCollection();
154 menu->addSeparator();
155 menu->addAction(coll->action("ZoomInChatView"));
156 menu->addAction(coll->action("ZoomOutChatView"));
157 menu->addAction(coll->action("ZoomOriginalChatView"));
160 bool BufferWidget::eventFilter(QObject *watched, QEvent *event) {
161 if(event->type() != QEvent::KeyPress)
164 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
166 MultiLineEdit *inputLine = qobject_cast<MultiLineEdit *>(watched);
170 // Intercept copy key presses
171 if(keyEvent == QKeySequence::Copy) {
172 if(inputLine->hasSelectedText())
174 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
176 view->scene()->selectionToClipboard();
180 // We don't want to steal cursor movement keys if the input line is in multiline mode
181 if(!inputLine->isSingleLine())
184 switch(keyEvent->key()) {
187 if(!(keyEvent->modifiers() & Qt::ShiftModifier))
190 case Qt::Key_PageDown:
191 // static cast to access public qobject::event
192 return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);