Warning, file /office/calligra/gemini/TouchDeclarativeView.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2013 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "TouchDeclarativeView.h" 0007 0008 #include <QWidget> 0009 #include <QSurfaceFormat> 0010 #include <QResizeEvent> 0011 #include <QApplication> 0012 #include <QQuickItem> 0013 0014 #include <gemini/ViewModeSwitchEvent.h> 0015 0016 TouchDeclarativeView::TouchDeclarativeView(QWindow *parent) 0017 : QQuickView(parent) 0018 , m_drawCanvas(false) 0019 , m_canvasWidget(0) 0020 , m_GLInitialized(false) 0021 { 0022 // setCacheMode(QQuickView::CacheNone); 0023 // setViewportUpdateMode(QQuickView::FullViewportUpdate); 0024 0025 // setFlag(Qt::WA_AcceptTouchEvents); 0026 // setAttribute(Qt::WA_OpaquePaintEvent); 0027 // setAttribute(Qt::WA_NoSystemBackground); 0028 // viewport()->setAttribute(Qt::WA_OpaquePaintEvent); 0029 // viewport()->setAttribute(Qt::WA_NoSystemBackground); 0030 // installEventFilter(this); 0031 } 0032 0033 TouchDeclarativeView::TouchDeclarativeView(const QUrl &url, QWindow *parent) 0034 : QQuickView(url, parent) 0035 , m_drawCanvas(false) 0036 , m_canvasWidget(0) 0037 , m_GLInitialized(false) 0038 { 0039 // setCacheMode(QQuickView::CacheNone); 0040 // setViewportUpdateMode(QQuickView::FullViewportUpdate); 0041 0042 // QSurfaceFormat format; 0043 // format.setSampleBuffers(true); 0044 // setFormat(format); 0045 0046 // setAttribute(Qt::WA_AcceptTouchEvents); 0047 // setAttribute(Qt::WA_OpaquePaintEvent); 0048 // setAttribute(Qt::WA_NoSystemBackground); 0049 // viewport()->setAttribute(Qt::WA_OpaquePaintEvent); 0050 // viewport()->setAttribute(Qt::WA_NoSystemBackground); 0051 // installEventFilter(this); 0052 } 0053 0054 TouchDeclarativeView::~TouchDeclarativeView() 0055 { 0056 m_canvasWidget = 0; 0057 } 0058 0059 QWidget* TouchDeclarativeView::canvasWidget() const 0060 { 0061 return m_canvasWidget.data(); 0062 } 0063 0064 void TouchDeclarativeView::setCanvasWidget(QWidget *canvasWidget) 0065 { 0066 m_canvasWidget = canvasWidget;// qobject_cast<KisOpenGLCanvas2*>(canvasWidget); 0067 connect(m_canvasWidget, SIGNAL(destroyed(QObject*)), this, SLOT(resetInitialized())); 0068 emit canvasWidgetChanged(); 0069 } 0070 0071 void TouchDeclarativeView::resetInitialized() 0072 { 0073 m_GLInitialized = false; 0074 } 0075 0076 bool TouchDeclarativeView::drawCanvas() const 0077 { 0078 return m_drawCanvas; 0079 } 0080 0081 void TouchDeclarativeView::setDrawCanvas(bool drawCanvas) 0082 { 0083 if (m_drawCanvas != drawCanvas) { 0084 m_drawCanvas = drawCanvas; 0085 emit drawCanvasChanged(); 0086 } 0087 } 0088 0089 // void TouchDeclarativeView::drawBackground(QPainter *painter, const QRectF &rect) 0090 // { 0091 // 0092 // if (painter->paintEngine()->type() != QPaintEngine::OpenGL2) { 0093 // qWarning("OpenGLScene: drawBackground needs a " 0094 // "QGLWidget to be set as viewport on the " 0095 // "graphics view"); 0096 // return; 0097 // } 0098 // 0099 // if (m_drawCanvas && m_canvasWidget) { 0100 // if (!m_GLInitialized) { 0101 // //m_canvasWidget->initializeCheckerShader(); 0102 // //m_canvasWidget->initializeDisplayShader(); 0103 // m_GLInitialized = true; 0104 // } 0105 // //m_canvasWidget->renderCanvasGL(); 0106 // //m_canvasWidget->renderDecorations(painter); 0107 // } 0108 // else { 0109 // QQuickView::drawBackground(painter, rect); 0110 // } 0111 // 0112 // } 0113 0114 0115 // void TouchDeclarativeView::resizeEvent(QResizeEvent *event) 0116 // { 0117 // if (m_canvasWidget) { 0118 // //m_canvasWidget->coordinatesConverter()->setCanvasWidgetSize(event->size()); 0119 // } 0120 // 0121 // QQuickView::resizeEvent(event); 0122 // } 0123 // 0124 // bool TouchDeclarativeView::event( QEvent* event ) 0125 // { 0126 // switch(static_cast<int>(event->type())) { 0127 // case QEvent::TabletPress: 0128 // case QEvent::TabletMove: 0129 // case QEvent::TabletRelease: 0130 // break; 0131 // case ViewModeSwitchEvent::AboutToSwitchViewModeEvent: 0132 // case ViewModeSwitchEvent::SwitchedToTouchModeEvent: { 0133 // // If we don't have a canvas widget yet, we don't really have anywhere to send those events 0134 // // so... let's just not 0135 // //if (m_canvasWidget.data()) 0136 // // { 0137 // //QGraphicsScene is silly and will not forward unknown events to its items, so emulate that 0138 // //functionality. 0139 // // QList<QGraphicsItem*> items = scene()->items(); 0140 // // Q_FOREACH(QGraphicsItem* item, items) { 0141 // // if (item == m_sketchView || qobject_cast<TouchView*>((item))) { 0142 // // if (item != m_sketchView) 0143 // // m_sketchView = item; 0144 // // scene()->sendEvent(item, event); 0145 // // break; 0146 // // } 0147 // // } 0148 // // } 0149 // sendEvent(contentItem(), event); 0150 // break; 0151 // } 0152 // default: 0153 // break; 0154 // } 0155 // return QQuickView::event( event ); 0156 // } 0157 // 0158 // bool TouchDeclarativeView::eventFilter(QObject* watched, QEvent* e) 0159 // { 0160 // switch(static_cast<int>(e->type())) { 0161 // // case KisTabletEvent::TabletMoveEx: 0162 // // case KisTabletEvent::TabletPressEx: 0163 // // case KisTabletEvent::TabletReleaseEx: { 0164 // // if (m_canvasWidget.data()) 0165 // // { 0166 // // //QGraphicsScene is silly and will not forward unknown events to its items, so emulate that 0167 // // //functionality.s 0168 // // KisTabletEvent* ev = static_cast<KisTabletEvent*>(e); 0169 // // QList<QGraphicsItem*> items = scene()->items(ev->pos()); 0170 // // Q_FOREACH(QGraphicsItem* item, items) 0171 // // { 0172 // // if(scene()->sendEvent(item, e)) 0173 // // return true; 0174 // // } 0175 // // } 0176 // // break; 0177 // // } 0178 // default: 0179 // break; 0180 // } 0181 // 0182 // 0183 // return QQuickView::eventFilter(watched, e); 0184 // }