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 ***************************************************************************/
26 #include "actioncollection.h"
27 #include "bufferwidget.h"
29 #include "chatviewsearchbar.h"
30 #include "chatviewsearchcontroller.h"
32 #include "iconloader.h"
33 #include "inputline.h"
38 BufferWidget::BufferWidget(QWidget *parent)
39 : AbstractBufferContainer(parent),
40 _chatViewSearchController(new ChatViewSearchController(this))
43 layout()->setContentsMargins(0, 0, 0, 0);
44 layout()->setSpacing(0);
45 // ui.searchBar->hide();
47 _chatViewSearchController->setCaseSensitive(ui.searchBar->caseSensitiveBox()->isChecked());
48 _chatViewSearchController->setSearchSenders(ui.searchBar->searchSendersBox()->isChecked());
49 _chatViewSearchController->setSearchMsgs(ui.searchBar->searchMsgsBox()->isChecked());
50 _chatViewSearchController->setSearchOnlyRegularMsgs(ui.searchBar->searchOnlyRegularMsgsBox()->isChecked());
52 connect(ui.searchBar->searchEditLine(), SIGNAL(textChanged(const QString &)),
53 _chatViewSearchController, SLOT(setSearchString(const QString &)));
54 connect(ui.searchBar->caseSensitiveBox(), SIGNAL(toggled(bool)),
55 _chatViewSearchController, SLOT(setCaseSensitive(bool)));
56 connect(ui.searchBar->searchSendersBox(), SIGNAL(toggled(bool)),
57 _chatViewSearchController, SLOT(setSearchSenders(bool)));
58 connect(ui.searchBar->searchMsgsBox(), SIGNAL(toggled(bool)),
59 _chatViewSearchController, SLOT(setSearchMsgs(bool)));
60 connect(ui.searchBar->searchOnlyRegularMsgsBox(), SIGNAL(toggled(bool)),
61 _chatViewSearchController, SLOT(setSearchOnlyRegularMsgs(bool)));
62 connect(ui.searchBar->searchUpButton(), SIGNAL(clicked()),
63 _chatViewSearchController, SLOT(highlightPrev()));
64 connect(ui.searchBar->searchDownButton(), SIGNAL(clicked()),
65 _chatViewSearchController, SLOT(highlightNext()));
67 connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)),
68 this, SLOT(scrollToHighlight(QGraphicsItem *)));
70 ActionCollection *coll = QtUi::actionCollection();
72 Action *zoomInChatview = coll->add<Action>("ZoomInChatView", this, SLOT(zoomIn()));
73 zoomInChatview->setText(tr("Zoom In"));
74 zoomInChatview->setIcon(SmallIcon("zoom-in"));
75 zoomInChatview->setShortcut(QKeySequence::ZoomIn);
77 Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView", this, SLOT(zoomOut()));
78 zoomOutChatview->setIcon(SmallIcon("zoom-out"));
79 zoomOutChatview->setText(tr("Zoom Out"));
80 zoomOutChatview->setShortcut(QKeySequence::ZoomOut);
82 Action *zoomOriginalChatview = coll->add<Action>("ZoomOriginalChatView", this, SLOT(zoomOriginal()));
83 zoomOriginalChatview->setIcon(SmallIcon("zoom-original"));
84 zoomOriginalChatview->setText(tr("Actual Size"));
85 //zoomOriginalChatview->setShortcut(tr("Ctrl+0")); // used for RTS switching
88 BufferWidget::~BufferWidget() {
89 delete _chatViewSearchController;
90 _chatViewSearchController = 0;
93 AbstractChatView *BufferWidget::createChatView(BufferId id) {
95 chatView = new ChatView(id, this);
96 chatView->setBufferContainer(this);
97 _chatViews[id] = chatView;
98 ui.stackedWidget->addWidget(chatView);
99 chatView->setFocusProxy(this);
103 void BufferWidget::removeChatView(BufferId id) {
104 QWidget *view = _chatViews.value(id, 0);
106 ui.stackedWidget->removeWidget(view);
111 void BufferWidget::showChatView(BufferId id) {
113 ui.stackedWidget->setCurrentWidget(ui.page);
115 ChatView *view = qobject_cast<ChatView *>(_chatViews.value(id));
117 ui.stackedWidget->setCurrentWidget(view);
118 _chatViewSearchController->setScene(view->scene());
122 void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) {
123 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
125 view->centerOn(highlightItem);
130 void BufferWidget::zoomIn() {
131 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
136 void BufferWidget::zoomOut() {
137 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
142 void BufferWidget::zoomOriginal() {
143 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
145 view->zoomOriginal();
148 void BufferWidget::addActionsToMenu(QMenu *menu, const QPointF &pos) {
150 ActionCollection *coll = QtUi::actionCollection();
151 menu->addSeparator();
152 menu->addAction(coll->action("ZoomInChatView"));
153 menu->addAction(coll->action("ZoomOutChatView"));
154 menu->addAction(coll->action("ZoomOriginalChatView"));
157 bool BufferWidget::eventFilter(QObject *watched, QEvent *event) {
158 if(event->type() != QEvent::KeyPress)
161 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
163 // Intercept copy key presses
164 if(keyEvent == QKeySequence::Copy) {
165 InputLine *inputLine = qobject_cast<InputLine *>(watched);
168 if(inputLine->hasSelectedText())
170 ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
172 view->scene()->selectionToClipboard();
176 switch(keyEvent->key()) {
179 if(!(keyEvent->modifiers() & Qt::ShiftModifier))
182 case Qt::Key_PageDown:
183 // static cast to access public qobject::event
184 return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);