use system palete colors
[makneto-zunavac1.git] / src / ui-mobile / view-graber.cpp
bloba32fffc92c0ccafdf5001d6965df3def502feae6
1 /*
2 * Copyright (C) 2011 Lukáš Karas <lukas.karas@centrum.cz>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <qt4/QtOpenGL/qgl.h>
21 #include <QGraphicsScene>
22 #include <qt4/QtDeclarative/qdeclarativeitem.h>
24 #include "view-graber.h"
26 ViewGraber::ViewGraber(QDeclarativeItem *parent) :
27 QDeclarativeItem(parent),
28 scheduledSnapshot(false),
29 paintSnapshot(false) {
33 ViewGraber::~ViewGraber() {
36 void ViewGraber::takeSnapshot() {
37 //QDeclarativeItem *parent = parentItem();
38 if (!_delegate)
39 return;
41 scheduledSnapshot = true;
42 paintSnapshot = true;
44 setFlag(QGraphicsItem::ItemHasNoContents, false);
45 update(_delegate->boundingRect());
48 void ViewGraber::releaseSnapshot() {
49 paintSnapshot = false;
52 void ViewGraber::paint(QPainter *painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0) {
53 Q_UNUSED(option);
55 if (!_delegate)
56 return;
58 if (scheduledSnapshot) {
59 QGLWidget *qgl = reinterpret_cast<QGLWidget *> (widget);
60 if (!qgl) {
61 qWarning() << "ViewGraber: cast" << widget << "to QGLWidget failed";
62 return;
65 _delegate->paint(painter, option, widget);
66 scheduledSnapshot = false;
67 snapshot = qgl->grabFrameBuffer(false);
68 qDebug() << "MyWebView: take snapshot ";
69 emit snapshotTaken();
72 if (!paintSnapshot)
73 return;
75 QPointF sceneMapRect = _delegate->mapToScene(0, 0);
76 QPointF selfMapRect = ((QGraphicsItem*) _delegate)->mapToItem((QGraphicsItem*) this, QPointF(0, 0));
77 //rect = this->scene()->mapToItem(this, rect);
78 //qDebug() << "MyWebView: paint" << sceneMapRect << selfMapRect;
79 painter->drawImage((sceneMapRect.x() - selfMapRect.x()) *-1, (sceneMapRect.y() - selfMapRect.y()) *-1, snapshot);
82 #include "view-graber.moc"