{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = zone->zoneColor;
zone->setPen(myPenColor);
}
foreach(QGraphicsItem *item, items())
{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = zone->zoneColor;
zone->setPen(myPenColor);
}
To copy to clipboard, switch view to plain text mode
#include <QtGui>
#include <sstream>
#include <QGraphicsItem>
#include "scribblearea.h"
#include "diagramitem.h"
{
return polygon;
}
//! [0]
ScribbleArea
::ScribbleArea(QWidget *parent
){
//setAttribute(Qt::WA_StaticContents);
modified = false;
scribbling = false;
myPenWidth = 1;
myPenColor = Qt::blue;
newZone = false;
polyIndex = 0;
zoneCount = 0;
if (!pix.load( ":/images/iterislogo.jpg" ))
{
qWarning("Failed to load iterislogo.png");
}
else
{
item->setPos(0,500);
}
}
//! [0]
//! [1]
bool ScribbleArea
::openImage(const QString &fileName
) //! [1] //! [2]
{
return true;
}
//! [2]
//! [3]
bool ScribbleArea
::saveImage(const QString &fileName,
const char *fileFormat
) //! [3] //! [4]
{
return false;
}
//! [4]
//! [5]
void ScribbleArea
::setPenColor(const QColor &newColor
) //! [5] //! [6]
{
myPenColor = newColor;
}
//! [6]
//! [7]
void ScribbleArea::setPenWidth(int newWidth)
//! [7] //! [8]
{
myPenWidth = newWidth;
}
//! [8]
void ScribbleArea::timesUp()
{
//DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(all);
for (int i = 0; i < zoneCount; i++)
{
{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = zone->zoneColor;
zone->setPen(myPenColor);
}
}
}
void ScribbleArea::activateImage()
//! [9] //! [10]
{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor= Qt::red;
zone->setPen(myPenColor);
zone->toggleState();
}
}
void ScribbleArea::deactivateImage()
//! [9] //! [10]
{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = Qt::blue;
zone->setPen(myPenColor);
zone->toggleState();
}
}
//! [9]
void ScribbleArea::clearImage()
//! [9] //! [10]
{
delete item;
zoneCount--;
}
}
//! [10]
void ScribbleArea::drawZone()
{
newZone = true;
}
//! [11]
//! [11] //! [12]
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->scenePos();
scribbling = true;
if( newZone ) // If drawing a new zone
{
polygon.setPoint(polyIndex++, event->scenePos().x(), event->scenePos().y());
if( polyIndex > 3)
{
newZone = false;
DiagramItem *item;
item = new DiagramItem(this);
item->setPen(myPenColor);
addItem(item);
QPointF details
= event
->scenePos
();
// debug purposes only
polyIndex = 0;
zoneCount++;
}
}
}
}
{
}
//! [14]
//! [15]
//! [18]
//! [19]
void ScribbleArea
::resizeImage(QImage *image,
const QSize &newSize
) //! [19] //! [20]
{
if (image->size() == newSize)
return;
newImage.fill(qRgb(255, 255, 255));
painter.
drawImage(QPoint(0,
0),
*image
);
*image = newImage;
}
//! [20]
//! [22]
#include <QtGui>
#include <sstream>
#include <QGraphicsItem>
#include "scribblearea.h"
#include "diagramitem.h"
QVector <QPoint> polygonPoints(4);
QPolygon polygon(4);
QPolygon ScribbleArea::getPoly()
{
return polygon;
}
//! [0]
ScribbleArea::ScribbleArea(QWidget *parent)
: QGraphicsScene(parent)
{
//setAttribute(Qt::WA_StaticContents);
modified = false;
scribbling = false;
myPenWidth = 1;
myPenColor = Qt::blue;
newZone = false;
polyIndex = 0;
zoneCount = 0;
QPixmap pix;
if (!pix.load( ":/images/iterislogo.jpg" ))
{
qWarning("Failed to load iterislogo.png");
}
else
{
QGraphicsPixmapItem *item = this->addPixmap(pix);
item->setPos(0,500);
}
}
//! [0]
//! [1]
bool ScribbleArea::openImage(const QString &fileName)
//! [1] //! [2]
{
return true;
}
//! [2]
//! [3]
bool ScribbleArea::saveImage(const QString &fileName, const char *fileFormat)
//! [3] //! [4]
{
return false;
}
//! [4]
//! [5]
void ScribbleArea::setPenColor(const QColor &newColor)
//! [5] //! [6]
{
myPenColor = newColor;
}
//! [6]
//! [7]
void ScribbleArea::setPenWidth(int newWidth)
//! [7] //! [8]
{
myPenWidth = newWidth;
}
//! [8]
void ScribbleArea::timesUp()
{
//DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(all);
for (int i = 0; i < zoneCount; i++)
{
foreach(QGraphicsItem *item, items())
{
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = zone->zoneColor;
zone->setPen(myPenColor);
}
}
}
void ScribbleArea::activateImage()
//! [9] //! [10]
{
foreach (QGraphicsItem *item, selectedItems()) {
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor= Qt::red;
zone->setPen(myPenColor);
zone->toggleState();
}
}
void ScribbleArea::deactivateImage()
//! [9] //! [10]
{
foreach (QGraphicsItem *item, selectedItems()) {
DiagramItem *zone = qgraphicsitem_cast<DiagramItem *>(item);
myPenColor = Qt::blue;
zone->setPen(myPenColor);
zone->toggleState();
}
}
//! [9]
void ScribbleArea::clearImage()
//! [9] //! [10]
{
foreach (QGraphicsItem *item, selectedItems()) {
delete item;
zoneCount--;
}
}
//! [10]
void ScribbleArea::drawZone()
{
newZone = true;
}
//! [11]
void ScribbleArea::mousePressEvent(QGraphicsSceneMouseEvent *event)
//! [11] //! [12]
{
if (event->button() == Qt::LeftButton) {
lastPoint = event->scenePos();
scribbling = true;
if( newZone ) // If drawing a new zone
{
polygon.setPoint(polyIndex++, event->scenePos().x(), event->scenePos().y());
if( polyIndex > 3)
{
newZone = false;
DiagramItem *item;
item = new DiagramItem(this);
item->setPen(myPenColor);
addItem(item);
QPointF details = event->scenePos(); // debug purposes only
polyIndex = 0;
zoneCount++;
}
}
}
QGraphicsScene::mousePressEvent(event);
}
void ScribbleArea::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mouseMoveEvent(event);
}
//! [14]
//! [15]
//! [18]
//! [19]
void ScribbleArea::resizeImage(QImage *image, const QSize &newSize)
//! [19] //! [20]
{
if (image->size() == newSize)
return;
QImage newImage(newSize, QImage::Format_RGB32);
newImage.fill(qRgb(255, 255, 255));
QPainter painter(&newImage);
painter.drawImage(QPoint(0, 0), *image);
*image = newImage;
}
//! [20]
//! [22]
To copy to clipboard, switch view to plain text mode
Bookmarks