2 * Copyright (C) 2006 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2006 George Staikos <staikos@kde.org>
4 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
5 * Copyright (C) 2006 Simon Hausmann <hausmann@kde.org>
6 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "ScrollViewCanvasQt.h"
35 #include "ScrollViewCanvasQt.moc"
38 #include "FrameView.h"
39 #include "TypingCommand.h"
40 #include "KeyboardCodes.h"
41 #include "GraphicsContext.h"
42 #include "SelectionController.h"
43 #include "PlatformMouseEvent.h"
44 #include "PlatformKeyboardEvent.h"
47 #include <QPaintEvent>
48 #include <QMouseEvent>
52 ScrollViewCanvasQt::ScrollViewCanvasQt(ScrollView* frameView, QWidget* parent)
54 , m_frameView(frameView)
56 setMouseTracking(true);
57 setFocusPolicy(Qt::StrongFocus);
60 void ScrollViewCanvasQt::paintEvent(QPaintEvent* ev)
62 FrameView* fv = static_cast<FrameView*>(m_frameView);
63 if (!fv || !fv->frame())
66 QRect clip = ev->rect();
69 GraphicsContext ctx(&p);
72 fv->frame()->paint(&ctx, clip);
75 QSize ScrollViewCanvasQt::sizeHint() const
77 return QSize(1024, 768);
80 void ScrollViewCanvasQt::mouseMoveEvent(QMouseEvent* ev)
82 FrameView* fv = static_cast<FrameView*>(m_frameView);
83 if (!fv || !fv->frame())
86 fv->handleMouseMoveEvent(PlatformMouseEvent(ev, 0));
89 void ScrollViewCanvasQt::mousePressEvent(QMouseEvent* ev)
91 FrameView* fv = static_cast<FrameView*>(m_frameView);
92 if (!fv || !fv->frame())
95 fv->handleMousePressEvent(PlatformMouseEvent(ev, 1));
98 void ScrollViewCanvasQt::mouseReleaseEvent(QMouseEvent* ev)
100 FrameView* fv = static_cast<FrameView*>(m_frameView);
101 if (!fv || !fv->frame())
104 fv->handleMouseReleaseEvent(PlatformMouseEvent(ev, 0));
107 void ScrollViewCanvasQt::keyPressEvent(QKeyEvent* ev)
109 handleKeyEvent(ev, false);
112 void ScrollViewCanvasQt::keyReleaseEvent(QKeyEvent* ev)
114 handleKeyEvent(ev, true);
117 void ScrollViewCanvasQt::handleKeyEvent(QKeyEvent* ev, bool isKeyUp)
119 PlatformKeyboardEvent kevent(ev, isKeyUp);
121 FrameView* fv = static_cast<FrameView*>(m_frameView);
122 FrameQt* frame = (fv ? static_cast<FrameQt*>(fv->frame()) : 0);
126 bool handled = frame->keyEvent(kevent);
128 if (!handled && !kevent.isKeyUp()) {
129 Node* start = frame->selectionController()->start().node();
130 if (start && start->isContentEditable()) {
131 switch(kevent.WindowsKeyCode()) {
133 TypingCommand::deleteKeyPressed(frame->document());
136 TypingCommand::forwardDeleteKeyPressed(frame->document());
139 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity);
142 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity);
145 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, ParagraphGranularity);
148 frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, ParagraphGranularity);
151 TypingCommand::insertText(frame->document(), kevent.text(), false);
158 // FIXME: doScroll stuff()!