/****************************************************************************
** This file is part of the taborca project hosted at
** sf.net/projects/taborca
** Copyright (C) 2013 Shawn Rutledge
** Contact: s@ecloud.org
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called LICENSE; if not, write to the
** Free Software Foundation, Inc.,
** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
****************************************************************************/
#ifndef RECTANGLE_H
#define RECTANGLE_H
#include <QGraphicsRectItem>
/**
\brief A type of PDF annotation: a rectangular region selected
for further processing (for example, OCR).
It can be dragged to size, moved around, selected,
and later resized by dragging the corner handles.
*/
class Rectangle : public QGraphicsRectItem
{
public:
Rectangle(qreal x, qreal y, qreal width, qreal height,
QGraphicsItem * parent = 0);
enum { Type = UserType + 1 };
int type() const { return Type; }
enum ResizeHandleIdx {
RH_NONE,
RH_TOP_LEFT,
RH_TOP_RIGHT,
RH_BOTTOM_RIGHT,
RH_BOTTOM_LEFT };
ResizeHandleIdx handleAt(QPointF pos);
void startResize();
void resize(ResizeHandleIdx hidx, QPointF pos);
void rotate(bool clockwise);
int handleWidth();
double actualWidth();
double actualHeight();
QRectF boundingRect () const;
void resizeDone();
/**
Inform this item that the mouse was clicked at the given position.
Will remember buttonDownPos in its own coord system for later use
while dragging.
*/
void buttonDown(QPointF scenePos);
QPointF buttonDownPos() { return m_buttonDownPos; };
/**
If selected, overlay the resize handle images.
*/
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option,
QWidget * widget = 0 );
protected:
virtual QRectF innerBoundingRect () const;
protected:
/**
Last position given to buttonDown(), mapped to item coord system.
*/
QPointF m_buttonDownPos;
static QPixmap* resizeHandle;
};
#endif // RECTANGLE_H