git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
130 lines
3.6 KiB
C++
130 lines
3.6 KiB
C++
#ifndef DRAWTOOLS_H
|
|
#define DRAWTOOLS_H
|
|
|
|
#include <QObject>
|
|
#include <QAction>
|
|
#include <QFontDialog>
|
|
#include <QToolButton>
|
|
#include <QPlainTextEdit>
|
|
#include <QMenu>
|
|
#include "blockview.h"
|
|
|
|
class QComboBox;
|
|
|
|
class _DTSizeItem: public QGraphicsObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
_DTSizeItem();
|
|
~_DTSizeItem();
|
|
|
|
void assignObject(QGraphicsItem * item);
|
|
|
|
protected:
|
|
void moveRects();
|
|
void applyRect();
|
|
void doubleClick();
|
|
QRectF itemRect(const QGraphicsItem * item) const;
|
|
QRectF boundingRect() const;
|
|
void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0) {}
|
|
bool sceneEventFilter(QGraphicsItem * watched, QEvent * event);
|
|
|
|
QGraphicsItem * cur_item;
|
|
QGraphicsView * view_;
|
|
QGraphicsRectItem rects[8];
|
|
QPointF pp, sp;
|
|
QRectF nrect;
|
|
qreal grid;
|
|
bool in_process, can_drag, is_line;
|
|
|
|
signals:
|
|
void sizeChanged();
|
|
void textEditRequest();
|
|
void pixmapEditRequest();
|
|
|
|
};
|
|
|
|
namespace Ui {
|
|
class DrawTools;
|
|
};
|
|
|
|
class DrawTools: public QObject
|
|
{
|
|
Q_OBJECT
|
|
Q_PROPERTY(bool resizeHandlesEnabled READ isResizeHandlesEnabled WRITE setResizeHandlesEnabled)
|
|
public:
|
|
explicit DrawTools(BlockView * parent = 0);
|
|
~DrawTools();
|
|
|
|
void setBlockView(BlockView * v);
|
|
void resetSizeTool() {size_item.assignObject(0);}
|
|
bool isResizeHandlesEnabled() const {return resize_enabled;}
|
|
void setAlignCompact(bool yes);
|
|
|
|
QComboBox * textEditCombo() const;
|
|
QList<QAction * > actionsForAdd() const {return actions_add;}
|
|
QList<QAction * > actionsForZ() const {return QList<QAction * >() << &actions_Z_bottom << &actions_Z_down << &actions_Z_up << &actions_Z_top;}
|
|
QWidget * propertyWidget() const {return widget_props;}
|
|
|
|
protected:
|
|
bool eventFilter(QObject * o, QEvent * e);
|
|
|
|
QAction * newAction(const QString & text, const QIcon & icon, int type);
|
|
void setPenBrushEnabled(bool pen, bool brush);
|
|
void blockPropSignals(bool block_);
|
|
void actionAlignTrigger(bool vert, Qt::AlignmentFlag value);
|
|
void emitZAvailabe(QGraphicsItem * item = 0);
|
|
|
|
QWidget * widget_props;
|
|
Ui::DrawTools * ui;
|
|
BlockView * view_;
|
|
QList<QAction * > actions_add;
|
|
mutable QAction actions_Z_up, actions_Z_top, actions_Z_down, actions_Z_bottom;
|
|
QList<QToolButton * > buttons_align;
|
|
QGraphicsItem * new_item, * cur_item;
|
|
QFontDialog font_dlg;
|
|
QPointF pp;
|
|
QDialog text_dlg;
|
|
QPlainTextEdit text_edit;
|
|
QMenu menu_hor, menu_ver;
|
|
_DTSizeItem size_item;
|
|
Qt::Alignment align;
|
|
int new_type;
|
|
bool resize_enabled;
|
|
|
|
private slots:
|
|
void toggleNewItem(bool on);
|
|
void alignClicked();
|
|
void selectionChanged();
|
|
void sizeChanged();
|
|
void propertyChanged();
|
|
void changeFinished() {if (cur_item) emit itemEdited(cur_item);}
|
|
void moveZUpAvailable(bool yes) {actions_Z_up.setEnabled(yes); actions_Z_top.setEnabled(yes);}
|
|
void moveZDownAvailable(bool yes) {actions_Z_down.setEnabled(yes); actions_Z_bottom.setEnabled(yes);}
|
|
|
|
void buttonImage_clicked();
|
|
void buttonFont_clicked();
|
|
void buttonTextEdit_clicked();
|
|
|
|
void actionTop_triggered(bool on) {actionAlignTrigger(true, Qt::AlignTop);}
|
|
void actionVCenter_triggered(bool on) {actionAlignTrigger(true, Qt::AlignVCenter);}
|
|
void actionBottom_triggered(bool on) {actionAlignTrigger(true, Qt::AlignBottom);}
|
|
void actionLeft_triggered(bool on) {actionAlignTrigger(false, Qt::AlignLeft);}
|
|
void actionHCenter_triggered(bool on) {actionAlignTrigger(false, Qt::AlignHCenter);}
|
|
void actionRight_triggered(bool on) {actionAlignTrigger(false, Qt::AlignRight);}
|
|
void actionZ_triggered();
|
|
|
|
public slots:
|
|
void setResizeHandlesEnabled(bool on);
|
|
|
|
signals:
|
|
void itemCreated(QGraphicsItem * item);
|
|
void itemAddConfirm(QGraphicsItem * item);
|
|
void itemEdited(QGraphicsItem * item);
|
|
void itemZChanged(QGraphicsItem * item);
|
|
|
|
};
|
|
|
|
|
|
#endif // DRAWTOOLS_H
|