└── GradeSystem ├── qtsingleapplication ├── QtLockedFile ├── QtSingleApplication ├── qtsinglecoreapplication.pri ├── qtsingleapplication.pri ├── README.TXT ├── qtsinglecoreapplication.h ├── qtlocalpeer.h ├── qtlockedfile.h ├── qtlockedfile_unix.cpp ├── qtsingleapplication.h ├── qtsinglecoreapplication.cpp ├── qtlockedfile.cpp ├── qtlockedfile_win.cpp ├── qtlocalpeer.cpp ├── INSTALL.TXT └── qtsingleapplication.cpp ├── Resources ├── timg.jpg └── Win32 │ ├── play.png │ ├── bohui.png │ ├── delete.png │ ├── expand.png │ ├── input.png │ ├── pause.png │ ├── sound.png │ ├── youxiu.png │ ├── ic_expand.png │ ├── ic_gaotu.png │ ├── ic_next.png │ ├── ic_phone.png │ ├── ic_return.png │ ├── ic_shrink.png │ ├── ic_sort.png │ ├── yitongguo.png │ ├── ic_enlarge.png │ ├── ic_increase.png │ ├── ic_previous.png │ ├── ic_put away.png │ ├── shangqiang.png │ ├── ic_red_error.png │ ├── ic_turn left.png │ ├── ic_turn right.png │ ├── input_select.png │ ├── sound_select.png │ ├── ic_cutover_close.png │ ├── ic_drawing_round.png │ ├── ic_green_correct.png │ ├── ic_sidebar_arrow.png │ ├── ic_sidebar_color.png │ ├── ic_sidebar_image.png │ ├── ic_sidebar_shape.png │ ├── ic_sidebar_text.png │ ├── ic_click_recording.png │ ├── ic_drawing_beeline.png │ ├── ic_drawing_square.png │ ├── ic_drawing_triangle.png │ ├── ic_navigation_help.png │ ├── ic_sidebar_checked.png │ ├── ic_sidebar_pencil.png │ ├── ic_square_selected.png │ ├── ic_top bar_narrow.png │ ├── ic_recording_process.png │ └── ic_square_unselected.png ├── UI ├── GradeGraphics │ ├── GraphicsLineItem.h │ ├── ShapeMimeData.h │ ├── GraphicsLineItem.cpp │ ├── GraphicsTriangleItem.h │ ├── GraphicsEllipseItem.h │ ├── ShapeMimeData.cpp │ ├── PaintWidget.ui │ ├── GraphicsItemGroup.h │ ├── GraphicsTextItem.h │ ├── GraphicsEllipseItem.cpp │ ├── GraphicsArrowItem.h │ ├── GraphicsPathItem.h │ ├── GraphicsPixmapItem.h │ ├── GraphicsTriangleItem.cpp │ ├── GraphicsTextItem.cpp │ ├── GraphicsRectItem.h │ ├── sizehandle.h │ ├── PaintView.h │ ├── MainPaintScenee.h │ ├── GraphicsItemGroup.cpp │ ├── GraphicsItem.h │ ├── sizehandle.cpp │ ├── GraphicsRectItem.cpp │ ├── GraphicsPixmapItem.cpp │ ├── GraphicsPathItem.cpp │ ├── GraphicsItem.cpp │ ├── GraphicsArrowItem.cpp │ ├── drawtool.h │ ├── MainPaintScene.cpp │ ├── PaintView.cpp │ └── drawtool.cpp ├── MainForm.h └── MainForm.cpp ├── preheader.h ├── main.cpp ├── qrc.qrc ├── GradeSystem.pro └── GradeSystem.pro.user /GradeSystem/qtsingleapplication/QtLockedFile: -------------------------------------------------------------------------------- 1 | #include "qtlockedfile.h" 2 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/QtSingleApplication: -------------------------------------------------------------------------------- 1 | #include "qtsingleapplication.h" 2 | -------------------------------------------------------------------------------- /GradeSystem/Resources/timg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/timg.jpg -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/play.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/bohui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/bohui.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/delete.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/expand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/expand.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/input.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/pause.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/sound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/sound.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/youxiu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/youxiu.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_expand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_expand.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_gaotu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_gaotu.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_next.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_phone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_phone.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_return.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_return.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_shrink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_shrink.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sort.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/yitongguo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/yitongguo.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_enlarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_enlarge.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_increase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_increase.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_previous.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_previous.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_put away.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_put away.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/shangqiang.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/shangqiang.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_red_error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_red_error.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_turn left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_turn left.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_turn right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_turn right.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/input_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/input_select.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/sound_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/sound_select.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_cutover_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_cutover_close.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_drawing_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_drawing_round.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_green_correct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_green_correct.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_arrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_arrow.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_color.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_image.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_shape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_shape.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_text.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_click_recording.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_click_recording.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_drawing_beeline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_drawing_beeline.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_drawing_square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_drawing_square.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_drawing_triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_drawing_triangle.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_navigation_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_navigation_help.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_checked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_checked.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_sidebar_pencil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_sidebar_pencil.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_square_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_square_selected.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_top bar_narrow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_top bar_narrow.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_recording_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_recording_process.png -------------------------------------------------------------------------------- /GradeSystem/Resources/Win32/ic_square_unselected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wyyrepo/Qt_QGraphicsItem_DrawSystem/HEAD/GradeSystem/Resources/Win32/ic_square_unselected.png -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsLineItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsRectItem.h" 4 | 5 | class GraphicsLineItem : public QGraphicsLineItem 6 | { 7 | public: 8 | GraphicsLineItem(const QLineF &line,QGraphicsItem * parent=0 ); 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/ShapeMimeData.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | 4 | class ShapeMimeData :public QMimeData 5 | { 6 | Q_OBJECT 7 | public: 8 | ShapeMimeData( QList items); 9 | ~ShapeMimeData(); 10 | QList items() const ; 11 | private: 12 | QList m_items; 13 | }; 14 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsinglecoreapplication.pri: -------------------------------------------------------------------------------- 1 | INCLUDEPATH += $$PWD 2 | DEPENDPATH += $$PWD 3 | HEADERS += $$PWD/qtsinglecoreapplication.h $$PWD/qtlocalpeer.h 4 | SOURCES += $$PWD/qtsinglecoreapplication.cpp $$PWD/qtlocalpeer.cpp 5 | 6 | QT *= network 7 | 8 | win32:contains(TEMPLATE, lib):contains(CONFIG, shared) { 9 | DEFINES += QT_QTSINGLECOREAPPLICATION_EXPORT=__declspec(dllexport) 10 | } 11 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsLineItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsLineItem.h" 2 | 3 | GraphicsLineItem::GraphicsLineItem(const QLineF &line,QGraphicsItem *parent) 4 | :QGraphicsLineItem(line,parent) 5 | { 6 | setFlag(QGraphicsItem::ItemIsMovable, true); 7 | setFlag(QGraphicsItem::ItemIsSelectable, true); 8 | setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); 9 | this->setAcceptHoverEvents(true); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsTriangleItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsRectItem.h" 4 | class GraphicsTriangleItem : public GraphicsRectItem 5 | { 6 | public: 7 | GraphicsTriangleItem(const QRect & rect ,QGraphicsItem * parent); 8 | QPainterPath shape() const; 9 | 10 | 11 | protected: 12 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 13 | }; 14 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsEllipseItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsRectItem.h" 4 | 5 | 6 | class GraphicsEllipseItem : public GraphicsRectItem 7 | { 8 | public: 9 | GraphicsEllipseItem(const QRect & rect ,QGraphicsItem * parent); 10 | QPainterPath shape() const; 11 | 12 | protected: 13 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 14 | }; 15 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/ShapeMimeData.cpp: -------------------------------------------------------------------------------- 1 | #include "ShapeMimeData.h" 2 | 3 | ShapeMimeData::ShapeMimeData(QList items) 4 | { 5 | foreach (QGraphicsItem *item , items ) { 6 | // AbstractShape *sp = qgraphicsitem_cast(item); 7 | // m_items.append(sp->copy()); 8 | } 9 | } 10 | ShapeMimeData::~ShapeMimeData() 11 | { 12 | foreach (QGraphicsItem *item , m_items ) { 13 | delete item; 14 | } 15 | m_items.clear(); 16 | } 17 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/PaintWidget.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PaintWidget 6 | 7 | 8 | 9 | 0 10 | 0 11 | 400 12 | 300 13 | 14 | 15 | 16 | Form 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsItemGroup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsRectItem.h" 4 | 5 | class GraphicsItemGroup : public GraphicsRectItem 6 | { 7 | public: 8 | GraphicsItemGroup ( QGraphicsItemGroup * group, QGraphicsItem * parent ); 9 | QRectF boundingRect() const; 10 | QPainterPath shape() const; 11 | virtual void resizeTo(SizeHandleRect::Direction dir, const QPointF & point ); 12 | protected: 13 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 14 | QGraphicsItemGroup *m_group; 15 | }; 16 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsingleapplication.pri: -------------------------------------------------------------------------------- 1 | #include(../common.pri) 2 | INCLUDEPATH += $$PWD 3 | DEPENDPATH += $$PWD 4 | QT *= network 5 | greaterThan(QT_MAJOR_VERSION, 4): QT *= widgets 6 | 7 | qtsingleapplication-uselib:!qtsingleapplication-buildlib { 8 | LIBS += -L$$QTSINGLEAPPLICATION_LIBDIR -l$$QTSINGLEAPPLICATION_LIBNAME 9 | } else { 10 | SOURCES += $$PWD/qtsingleapplication.cpp $$PWD/qtlocalpeer.cpp 11 | HEADERS += $$PWD/qtsingleapplication.h $$PWD/qtlocalpeer.h 12 | } 13 | 14 | win32 { 15 | contains(TEMPLATE, lib):contains(CONFIG, shared):DEFINES += QT_QTSINGLEAPPLICATION_EXPORT 16 | else:qtsingleapplication-uselib:DEFINES += QT_QTSINGLEAPPLICATION_IMPORT 17 | } 18 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsTextItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | 4 | class GraphicsTextItem : public QGraphicsTextItem 5 | { 6 | Q_OBJECT 7 | 8 | public: 9 | enum { Type = UserType + 3 }; 10 | 11 | GraphicsTextItem(QGraphicsItem *parent = 0); 12 | 13 | int type() const override { return Type; } 14 | 15 | signals: 16 | void lostFocus(GraphicsTextItem *item); 17 | void selectedChange(QGraphicsItem *item); 18 | 19 | protected: 20 | QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; 21 | void focusOutEvent(QFocusEvent *event) override; 22 | void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override; 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /GradeSystem/preheader.h: -------------------------------------------------------------------------------- 1 | #ifndef PREHEADER_H 2 | #define PREHEADER_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | enum DrawBaseShape 12 | { 13 | selection , 14 | rotation , 15 | line , 16 | rectangle , //矩形 17 | roundrect , 18 | ellipse , 19 | poly, 20 | arrowLine, //箭头线段 21 | text, //文字 22 | penPath, //铅笔 23 | image, //图片 24 | triangle, //三角形 25 | None 26 | }; 27 | 28 | #define SafeDelete(p) if (nullptr != p) { delete p; p = nullptr; } 29 | #define USERCATALOGDIR QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) 30 | #endif // PREHEADER_H 31 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsEllipseItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsEllipseItem.h" 2 | 3 | 4 | 5 | GraphicsEllipseItem::GraphicsEllipseItem(const QRect &rect, QGraphicsItem *parent) 6 | :GraphicsRectItem(rect,parent) 7 | { 8 | 9 | } 10 | 11 | QPainterPath GraphicsEllipseItem::shape() const 12 | { 13 | QPainterPath path; 14 | path.addEllipse(boundingRect()); 15 | return qt_graphicsItem_shapeFromPath(path,_pen); 16 | } 17 | 18 | void GraphicsEllipseItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 19 | { 20 | QRectF rc = rect(); 21 | QPen pen =painter->pen(); 22 | pen.setWidth(4); 23 | painter->setPen(pen); 24 | painter->setPen(m_color); 25 | painter->drawEllipse(rc); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsArrowItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsItem.h" 4 | class GraphicsArrowItem : public QGraphicsItem 5 | { 6 | public: 7 | GraphicsArrowItem(const QPointF &start = QPointF(), 8 | const QPointF &end = QPointF(), 9 | QGraphicsItem * parent=0); 10 | QRectF boundingRect() const Q_DECL_OVERRIDE; 11 | void paint(QPainter *painter, 12 | const QStyleOptionGraphicsItem *option, 13 | QWidget *w) Q_DECL_OVERRIDE; 14 | QPointF startPos,endPos; 15 | void setBorderColor(QColor color) 16 | { 17 | _mColor =color; 18 | } 19 | private: 20 | QPainterPath getArrowsPath(const QPointF &start, 21 | const QPointF &end, 22 | qreal len) const; 23 | 24 | 25 | private: 26 | qreal len; 27 | QColor _mColor; 28 | }; 29 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsPathItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsItem.h" 4 | class GraphicsPathItem : public GraphicsItem 5 | { 6 | 7 | public: 8 | GraphicsPathItem(const QPainterPath &painterPath ,GraphicsItem * parent); 9 | 10 | void setPath(QPainterPath path_in) 11 | { 12 | prepareGeometryChange(); 13 | //_path = path_in; 14 | // _boundingRect =_path.boundingRect(); 15 | update(); 16 | } 17 | QRectF boundingRect() const; 18 | QPainterPath shape() const; 19 | virtual void resizeTo(SizeHandleRect::Direction dir, const QPointF & point ); 20 | virtual QRectF rect() const { return QRectF(-m_width / 2 , -m_height / 2 , m_width,m_height) ;} 21 | protected: 22 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 23 | protected: 24 | qreal m_width; 25 | qreal m_height; 26 | mutable QRectF _boundingRect; 27 | QPainterPath _path; 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsPixmapItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsItem.h" 4 | class GraphicsPixmapItem : public GraphicsItem 5 | { 6 | public: 7 | GraphicsPixmapItem(const QPixmap &pixmap ,GraphicsItem * parent); 8 | 9 | QRectF boundingRect() const; 10 | QPainterPath shape() const; 11 | void resetShape() 12 | { 13 | m_rect.setLeft(0); 14 | m_rect.setTop(0); 15 | m_rect.setWidth(abs(m_width)); 16 | m_rect.setHeight(abs(m_height)); 17 | updateGeometry(); 18 | } 19 | virtual void resizeTo(SizeHandleRect::Direction dir, const QPointF & point ); 20 | virtual QRectF rect() const { 21 | return 22 | QRectF( QPointF(m_rect.left(),m_rect.top()), 23 | QPointF(m_rect.right(), m_rect.bottom())) ;}protected: 24 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 25 | 26 | protected: 27 | qreal m_width; 28 | qreal m_height; 29 | QPixmap m_pixmap; 30 | }; 31 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/README.TXT: -------------------------------------------------------------------------------- 1 | Qt Solutions Component: Single Application 2 | 3 | The QtSingleApplication component provides support for 4 | applications that can be only started once per user. 5 | 6 | 7 | 8 | Version history: 9 | 10 | 2.0: - Version 1.3 ported to Qt 4. 11 | 12 | 2.1: - Fix compilation problem on Mac. 13 | 14 | 2.2: - Really fix the Mac compilation problem. 15 | - Mac: fix crash due to wrong object releasing. 16 | - Mac: Fix memory leak. 17 | 18 | 2.3: - Windows: Force creation of internal widget to make it work 19 | with Qt 4.2. 20 | 21 | 2.4: - Fix the system for automatic window raising on message 22 | reception. NOTE: minor API change. 23 | 24 | 2.5: - Mac: Fix isRunning() to work and report correctly. 25 | 26 | 2.6: - - initialize() is now obsolete, no longer necessary to call 27 | it 28 | - - Fixed race condition where multiple instances migth be started 29 | - - QtSingleCoreApplication variant provided for non-GUI (console) 30 | usage 31 | - Complete reimplementation. Visible changes: 32 | - LGPL release. 33 | 34 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsTriangleItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsTriangleItem.h" 2 | 3 | GraphicsTriangleItem::GraphicsTriangleItem(const QRect &rect, QGraphicsItem *parent) 4 | :GraphicsRectItem(rect,parent) 5 | { 6 | } 7 | 8 | QPainterPath GraphicsTriangleItem::shape() const 9 | { 10 | QPainterPath path; 11 | QRectF rc = rect(); 12 | QPointF middle =QPointF((rc.left() + rc.right())*0.5,0); 13 | 14 | QPolygonF item; 15 | item <pen(); 29 | pen.setWidth(4); 30 | pen.setColor(m_color); 31 | painter->setPen(pen); 32 | painter->drawPolygon(item); 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsTextItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsTextItem.h" 2 | 3 | 4 | GraphicsTextItem::GraphicsTextItem(QGraphicsItem *parent) 5 | : QGraphicsTextItem(parent) 6 | { 7 | setFlag(QGraphicsItem::ItemIsMovable); 8 | setFlag(QGraphicsItem::ItemIsSelectable); 9 | } 10 | //! [0] 11 | 12 | //! [1] 13 | QVariant GraphicsTextItem::itemChange(GraphicsItemChange change, 14 | const QVariant &value) 15 | { 16 | // if (change == QGraphicsItem::ItemSelectedHasChanged) 17 | // emit selectedChange(this); 18 | return value; 19 | } 20 | //! [1] 21 | 22 | //! [2] 23 | void GraphicsTextItem::focusOutEvent(QFocusEvent *event) 24 | { 25 | setTextInteractionFlags(Qt::NoTextInteraction); 26 | // emit lostFocus(this); 27 | QGraphicsTextItem::focusOutEvent(event); 28 | } 29 | //! [2] 30 | 31 | //! [5] 32 | void GraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) 33 | { 34 | if (textInteractionFlags() == Qt::NoTextInteraction) 35 | setTextInteractionFlags(Qt::TextEditorInteraction); 36 | QGraphicsTextItem::mouseDoubleClickEvent(event); 37 | } 38 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsRectItem.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GraphicsItem.h" 4 | class GraphicsRectItem : public GraphicsItem 5 | { 6 | public: 7 | GraphicsRectItem(const QRect & rect ,QGraphicsItem * parent); 8 | 9 | QRectF boundingRect() const; 10 | QPainterPath shape() const; 11 | void resetShape() 12 | { 13 | m_rect.setLeft(0); 14 | m_rect.setTop(0); 15 | m_rect.setWidth(abs(m_width)); 16 | m_rect.setHeight(abs(m_height)); 17 | updateGeometry(); 18 | } 19 | 20 | void setBorderColor(QColor color) 21 | { 22 | m_color =color; 23 | } 24 | void setIsSquare() 25 | { 26 | m_isSquare =true; 27 | } 28 | virtual void resizeTo(SizeHandleRect::Direction dir, const QPointF & point ); 29 | virtual QRectF rect() const { 30 | return 31 | QRectF( QPointF(m_rect.left(),m_rect.top()), 32 | QPointF(m_rect.right(), m_rect.bottom())) ;} 33 | 34 | protected: 35 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 36 | protected: 37 | qreal m_width; 38 | qreal m_height; 39 | bool m_isSquare; //是否为正方形 40 | QColor m_color; 41 | 42 | 43 | 44 | }; 45 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/sizehandle.h: -------------------------------------------------------------------------------- 1 | #ifndef SIZEHANDLE 2 | #define SIZEHANDLE 3 | 4 | #include 5 | #include 6 | 7 | QT_BEGIN_NAMESPACE 8 | class QFocusEvent; 9 | class QGraphicsItem; 10 | class QGraphicsScene; 11 | class QGraphicsSceneMouseEvent; 12 | QT_END_NAMESPACE 13 | 14 | 15 | enum { SELECTION_HANDLE_SIZE = 6, SELECTION_MARGIN = 10 }; 16 | enum SelectionHandleState { SelectionHandleOff, SelectionHandleInactive, SelectionHandleActive }; 17 | 18 | class SizeHandleRect :public QGraphicsRectItem 19 | { 20 | public: 21 | enum Direction { LeftTop , Top, RightTop, Right, RightBottom, Bottom, LeftBottom, Left , Center, None}; 22 | 23 | SizeHandleRect(QGraphicsItem* parent , Direction d, QGraphicsItem *resizable); 24 | 25 | Direction dir() const { return m_dir; } 26 | void updateCursor(); 27 | void setState(SelectionHandleState st); 28 | bool hitTest( const QPointF & point ); 29 | void move(qreal x, qreal y ); 30 | 31 | protected: 32 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); 33 | 34 | private: 35 | const Direction m_dir; 36 | QPoint m_startPos; 37 | QPoint m_curPos; 38 | QSize m_startSize; 39 | QSize m_curSize; 40 | QGraphicsItem *m_resizable; 41 | SelectionHandleState m_state; 42 | }; 43 | 44 | 45 | #endif // SIZEHANDLE 46 | 47 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/PaintView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "ShapeMimeData.h" 4 | #include 5 | class PaintView : public QGraphicsView 6 | { 7 | Q_OBJECT 8 | 9 | public: 10 | explicit PaintView(QWidget *parent = 0); 11 | ~PaintView(); 12 | 13 | void ZoomOut(); 14 | void ZoomIn(); 15 | void SetTranslateSpeed(qreal speed); 16 | private: 17 | Qt::MouseButton _translateButton; // 平移按钮 18 | qreal _zoomDelta; // 缩放的增量 19 | qreal _scaleValue; // 缩放值 20 | QPoint _lastMousePos; // 鼠标最后按下的位置 21 | qreal _translateSpeed; // 平移速度 22 | bool _bMouseTranslate; 23 | 24 | void zoom(float scaleFactor); 25 | void paintEvent(QPaintEvent *event); 26 | void wheelEvent(QWheelEvent *event); 27 | void keyPressEvent(QKeyEvent *event); 28 | void translate(QPointF delta); 29 | void mouseMoveEvent(QMouseEvent *event); 30 | void mousePressEvent(QMouseEvent *event); 31 | void mouseReleaseEvent(QMouseEvent *event); 32 | void resizeEvent(QResizeEvent *event); 33 | void contextMenuEvent(QContextMenuEvent *event); 34 | 35 | private slots: 36 | void onAssemblageAction(bool); 37 | void onRotation1Action(bool); 38 | void onRotation2Action(bool); 39 | void onDeleteAction(bool) ; 40 | void on_copy(); 41 | void on_paste(); 42 | void on_cut(); 43 | 44 | 45 | }; 46 | -------------------------------------------------------------------------------- /GradeSystem/UI/MainForm.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "GradeGraphics/PaintView.h" 4 | #include "GradeGraphics/MainPaintScenee.h" 5 | 6 | namespace Ui { 7 | class MainForm; 8 | } 9 | 10 | class MainForm : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit MainForm(QWidget *parent = 0); 16 | ~MainForm(); 17 | 18 | private slots: 19 | void on_pushButton_clicked(); 20 | void on_pushButton_2_clicked(); 21 | 22 | void on_pushButton_4_clicked(); 23 | 24 | 25 | void on_pushButton_5_clicked(); 26 | 27 | void on_pushButton_9_clicked(); 28 | 29 | void on_pushButton_Color_clicked(); 30 | void onSetColor(QColor color); 31 | 32 | void on_pushButton_6_clicked(); 33 | 34 | void on_pushButton_3_clicked(); 35 | 36 | void on_pushButton_8_clicked(); 37 | 38 | void on_pushButton_7_clicked(); 39 | 40 | void on_pushButton_12_clicked(); 41 | 42 | 43 | 44 | void on_pushButton_13_clicked(); 45 | 46 | void on_pbt_line_clicked(); 47 | 48 | void on_pbt_Rect_clicked(); 49 | 50 | void on_pbt_triangle_clicked(); 51 | 52 | void on_pbt_circle_clicked(); 53 | 54 | void on_pbt_Blue_clicked(); 55 | 56 | void on_pbt_Green_clicked(); 57 | 58 | void on_pbt_prePage_clicked(); 59 | 60 | signals: 61 | void changeCurrentShape(DrawBaseShape shape); 62 | private: 63 | Ui::MainForm *ui; 64 | MainPaintScene *_mainPaintScene; 65 | 66 | void initToolBar();//将所有该隐藏的按钮隐藏; 67 | void resizeEvent(QResizeEvent *event); 68 | }; 69 | 70 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/MainPaintScenee.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINPAINTSCENEE_H 2 | #define MAINPAINTSCENEE_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | class QGraphicsSceneMouseEvent; 8 | class QMenu; 9 | class QPointF; 10 | class QFont; 11 | class QColor; 12 | QT_END_NAMESPACE 13 | #include "drawtool.h" 14 | #include "GraphicsTextItem.h" 15 | #include "GraphicsLineItem.h" 16 | 17 | class DrawTool; 18 | 19 | class MainPaintScene : public QGraphicsScene 20 | { 21 | Q_OBJECT 22 | 23 | public: 24 | explicit MainPaintScene(QObject *parent = 0); 25 | ~MainPaintScene(); 26 | 27 | void mouseEvent(QGraphicsSceneMouseEvent *mouseEvent ); 28 | void InsertPicture(QString path); 29 | void SetBackGroundImage(QString path); 30 | 31 | void setCurrentColor(QColor); 32 | public slots: 33 | void SetCurrentShape(DrawBaseShape shape); 34 | void editorLostFocus(GraphicsTextItem *item) 35 | { 36 | QTextCursor cursor = item->textCursor(); 37 | cursor.clearSelection(); 38 | item->setTextCursor(cursor); 39 | 40 | if (item->toPlainText().isEmpty()) { 41 | removeItem(item); 42 | item->deleteLater(); 43 | } 44 | } 45 | 46 | signals: 47 | void itemSelected(QGraphicsItem *item); 48 | void textInserted(GraphicsTextItem *item); 49 | 50 | private: 51 | void keyPressEvent(QKeyEvent *event); 52 | void mousePressEvent(QGraphicsSceneMouseEvent *event); 53 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 54 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); 55 | 56 | 57 | QColor _color=QColor(255,88,80,255); 58 | GraphicsTextItem *textItem=nullptr; 59 | }; 60 | 61 | #endif // MAINPAINTSCENEE_H 62 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsItemGroup.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsItemGroup.h" 2 | 3 | 4 | GraphicsItemGroup::GraphicsItemGroup(QGraphicsItemGroup *group, QGraphicsItem *parent) 5 | :GraphicsRectItem(QRect(0,0,0,0),parent ) 6 | ,m_group(group) 7 | { 8 | if ( m_group ){ 9 | m_group->setParentItem(this); 10 | QRectF bound = m_group->boundingRect(); 11 | 12 | qDebug()<<" group rect :" << m_group->boundingRect() << " new Rect:" << bound; 13 | bound.normalized(); 14 | prepareGeometryChange(); 15 | m_width = bound.width(); 16 | m_height = bound.height(); 17 | 18 | QPointF delta = pos() - bound.center() ; 19 | 20 | setTransform(transform().translate(delta.x(),delta.y())); 21 | setTransformOriginPoint( bound.center()); 22 | moveBy(-delta.x(),-delta.y()); 23 | 24 | m_group->setTransformOriginPoint(bound.center()); 25 | 26 | qDebug()<<"pos :" << delta; 27 | updateGeometry(); 28 | } 29 | } 30 | 31 | QRectF GraphicsItemGroup::boundingRect() const 32 | { 33 | 34 | QRectF bounding = m_group->mapRectToParent(m_group->boundingRect()); 35 | 36 | return bounding; 37 | } 38 | 39 | QPainterPath GraphicsItemGroup::shape() const 40 | { 41 | return m_group->shape() ; 42 | } 43 | 44 | void GraphicsItemGroup::resizeTo(SizeHandleRect::Direction dir, const QPointF &point) 45 | { 46 | 47 | } 48 | 49 | void GraphicsItemGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 50 | { 51 | QPointF origin = mapFromScene(pos()); 52 | 53 | QPointF origin1 = m_group->transformOriginPoint(); 54 | 55 | QColor c1 = QColor(Qt::blue); 56 | // c1.setAlpha(180); 57 | painter->setBrush(c1); 58 | painter->drawEllipse(origin.x() - 3 , origin.y() - 3 ,6,6); 59 | 60 | 61 | QColor c2 = QColor(Qt::green); 62 | // c2.setAlpha(180); 63 | painter->setBrush(c2); 64 | painter->drawEllipse(origin1.x() - 3 , origin1.y() - 3 ,6,6); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /GradeSystem/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "qtsingleapplication.h" 3 | #include "UI/MainForm.h" 4 | #include 5 | #include 6 | 7 | void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) 8 | { 9 | static QMutex mutex; 10 | mutex.lock(); 11 | 12 | QString text; 13 | switch(type) 14 | { 15 | case QtDebugMsg: 16 | text = QString("Debug:"); 17 | break; 18 | 19 | case QtWarningMsg: 20 | text = QString("Warning:"); 21 | break; 22 | 23 | case QtCriticalMsg: 24 | text = QString("Critical:"); 25 | break; 26 | 27 | case QtFatalMsg: 28 | text = QString("Fatal:"); 29 | } 30 | 31 | QString context_info = QString("File:(%1) Line:(%2) Fun:(%3)").arg(QString(context.file)).arg(context.line).arg(context.function); 32 | QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd"); 33 | QString current_date = QString("(%1)").arg(current_date_time); 34 | QString message = QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(current_date).arg(msg); 35 | 36 | 37 | QString str =USERCATALOGDIR; 38 | str.append("/userLog.txt"); 39 | str.replace("/","\\"); 40 | QFile file(str); 41 | file.open(QIODevice::WriteOnly | QIODevice::Append); 42 | QTextStream text_stream(&file); 43 | text_stream << message << "\r\n"; 44 | file.flush(); 45 | file.close(); 46 | 47 | mutex.unlock(); 48 | } 49 | void initCode() 50 | { 51 | QTextCodec *codec = QTextCodec::codecForName("UTF-8"); 52 | QTextCodec::setCodecForLocale(codec); 53 | 54 | } 55 | int main(int argc, char *argv[]) 56 | { 57 | initCode() ; 58 | qInstallMessageHandler(outputMessage); 59 | 60 | QtSingleApplication app(argc, argv); 61 | QTranslator qtTranslator; 62 | qDebug()<m_rect.bottom()) 40 | { 41 | qreal tmp =m_rect.bottom(); 42 | m_rect.setBottom(m_rect.top()); 43 | m_rect.setTop(tmp); 44 | } 45 | if(m_rect.left()>m_rect.right()) 46 | { 47 | qreal tmp =m_rect.right(); 48 | m_rect.setRight(m_rect.left()); 49 | m_rect.setLeft(tmp); 50 | } 51 | updateGeometry(); 52 | } 53 | 54 | 55 | protected: 56 | virtual void updateGeometry(); 57 | void setState(SelectionHandleState st); 58 | virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event){} 59 | QVariant itemChange(GraphicsItemChange change, const QVariant &value); 60 | typedef QVector Handles; 61 | Handles m_handles; 62 | QRectF m_rect; 63 | QPen _pen; 64 | QColor _color =Qt::red; 65 | }; 66 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/sizehandle.cpp: -------------------------------------------------------------------------------- 1 | #include "sizehandle.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | 10 | SizeHandleRect::SizeHandleRect(QGraphicsItem* parent , Direction d, QGraphicsItem *resizable) 11 | :QGraphicsRectItem(0,0,SELECTION_HANDLE_SIZE,SELECTION_HANDLE_SIZE,parent) 12 | ,m_dir(d) 13 | ,m_resizable(resizable) 14 | ,m_state(SelectionHandleOff) 15 | { 16 | setParentItem(parent); 17 | hide(); 18 | } 19 | 20 | void SizeHandleRect::updateCursor() 21 | { 22 | switch (m_dir) { 23 | case Right: 24 | setCursor(Qt::SizeHorCursor); 25 | return; 26 | case RightTop: 27 | setCursor(Qt::SizeBDiagCursor); 28 | return; 29 | case RightBottom: 30 | setCursor(Qt::SizeFDiagCursor); 31 | return; 32 | case LeftBottom: 33 | setCursor(Qt::SizeBDiagCursor); 34 | return; 35 | case Bottom: 36 | setCursor(Qt::SizeVerCursor); 37 | return; 38 | case LeftTop: 39 | setCursor(Qt::SizeFDiagCursor); 40 | return; 41 | case Left: 42 | setCursor(Qt::SizeHorCursor); 43 | return; 44 | case Top: 45 | setCursor(Qt::SizeVerCursor); 46 | return; 47 | default: 48 | break; 49 | } 50 | setCursor(Qt::ArrowCursor); 51 | } 52 | 53 | 54 | void SizeHandleRect::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 55 | { 56 | QColor c = QColor("limegreen"); 57 | // c.setAlpha(200); 58 | painter->setPen(Qt::NoPen); 59 | painter->setBrush(QBrush(c)); 60 | 61 | painter->drawRect(rect()); 62 | 63 | } 64 | 65 | 66 | void SizeHandleRect::setState(SelectionHandleState st) 67 | { 68 | if (st == m_state) 69 | return; 70 | switch (st) { 71 | case SelectionHandleOff: 72 | hide(); 73 | break; 74 | case SelectionHandleInactive: 75 | case SelectionHandleActive: 76 | show(); 77 | break; 78 | } 79 | m_state = st; 80 | } 81 | 82 | bool SizeHandleRect::hitTest(const QPointF &point) 83 | { 84 | QPointF pt = mapFromScene(point); 85 | return rect().contains(pt); 86 | } 87 | 88 | void SizeHandleRect::move(qreal x, qreal y) 89 | { 90 | setPos(x,y); 91 | } 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /GradeSystem/qrc.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | Resources/Win32/ic_cutover_close.png 4 | Resources/Win32/ic_enlarge.png 5 | Resources/Win32/ic_expand.png 6 | Resources/Win32/ic_gaotu.png 7 | Resources/Win32/ic_green_correct.png 8 | Resources/Win32/ic_navigation_help.png 9 | Resources/Win32/ic_next.png 10 | Resources/Win32/ic_phone.png 11 | Resources/Win32/ic_previous.png 12 | Resources/Win32/ic_red_error.png 13 | Resources/Win32/ic_return.png 14 | Resources/Win32/ic_shrink.png 15 | Resources/Win32/ic_sidebar_arrow.png 16 | Resources/Win32/ic_sidebar_checked.png 17 | Resources/Win32/ic_sidebar_color.png 18 | Resources/Win32/ic_sidebar_image.png 19 | Resources/Win32/ic_sidebar_pencil.png 20 | Resources/Win32/ic_sidebar_shape.png 21 | Resources/Win32/ic_sidebar_text.png 22 | Resources/Win32/ic_sort.png 23 | Resources/Win32/ic_square_selected.png 24 | Resources/Win32/ic_square_unselected.png 25 | Resources/Win32/ic_turn left.png 26 | Resources/Win32/ic_turn right.png 27 | Resources/Win32/delete.png 28 | Resources/Win32/bohui.png 29 | Resources/Win32/shangqiang.png 30 | Resources/Win32/yitongguo.png 31 | Resources/Win32/youxiu.png 32 | Resources/Win32/sound_select.png 33 | Resources/Win32/input_select.png 34 | Resources/Win32/input.png 35 | Resources/Win32/sound.png 36 | Resources/Win32/expand.png 37 | Resources/Win32/ic_put away.png 38 | Resources/Win32/pause.png 39 | Resources/Win32/play.png 40 | Resources/Win32/ic_click_recording.png 41 | Resources/Win32/ic_recording_process.png 42 | Resources/Win32/ic_increase.png 43 | Resources/Win32/ic_top bar_narrow.png 44 | Resources/Win32/ic_drawing_beeline.png 45 | Resources/Win32/ic_drawing_round.png 46 | Resources/Win32/ic_drawing_square.png 47 | Resources/Win32/ic_drawing_triangle.png 48 | Resources/timg.jpg 49 | 50 | 51 | -------------------------------------------------------------------------------- /GradeSystem/GradeSystem.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2017-11-13T14:33:55 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui network sql multimedia winextras 8 | 9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 10 | 11 | TARGET = GradeSystem 12 | TEMPLATE = app 13 | 14 | # The following define makes your compiler emit warnings if you use 15 | # any feature of Qt which has been marked as deprecated (the exact warnings 16 | # depend on your compiler). Please consult the documentation of the 17 | # deprecated API in order to know how to port your code away from it. 18 | DEFINES += QT_DEPRECATED_WARNINGS 19 | # You can also make your code fail to compile if you use deprecated APIs. 20 | # In order to do so, uncomment the following line. 21 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 22 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 23 | 24 | 25 | SOURCES += \ 26 | UI/GradeGraphics/MainPaintScene.cpp \ 27 | UI/GradeGraphics/PaintView.cpp \ 28 | UI/MainForm.cpp \ 29 | UI/GradeGraphics/drawtool.cpp \ 30 | UI/GradeGraphics/sizehandle.cpp \ 31 | UI/GradeGraphics/GraphicsTextItem.cpp \ 32 | UI/GradeGraphics/GraphicsRectItem.cpp \ 33 | UI/GradeGraphics/GraphicsItem.cpp \ 34 | UI/GradeGraphics/GraphicsEllipseItem.cpp \ 35 | UI/GradeGraphics/GraphicsLineItem.cpp \ 36 | UI/GradeGraphics/GraphicsItemGroup.cpp \ 37 | UI/GradeGraphics/GraphicsPixmapItem.cpp \ 38 | UI/GradeGraphics/GraphicsPathItem.cpp \ 39 | UI/GradeGraphics/GraphicsArrowItem.cpp \ 40 | UI/GradeGraphics/ShapeMimeData.cpp \ 41 | UI/GradeGraphics/GraphicsTriangleItem.cpp \ 42 | main.cpp 43 | 44 | HEADERS += \ 45 | preheader.h \ 46 | UI/GradeGraphics/MainPaintScenee.h \ 47 | UI/GradeGraphics/PaintView.h \ 48 | UI/MainForm.h \ 49 | UI/GradeGraphics/drawtool.h \ 50 | UI/GradeGraphics/sizehandle.h \ 51 | UI/GradeGraphics/GraphicsTextItem.h \ 52 | UI/GradeGraphics/GraphicsRectItem.h \ 53 | UI/GradeGraphics/GraphicsItem.h \ 54 | UI/GradeGraphics/GraphicsEllipseItem.h \ 55 | UI/GradeGraphics/GraphicsLineItem.h \ 56 | UI/GradeGraphics/GraphicsItemGroup.h \ 57 | UI/GradeGraphics/GraphicsPixmapItem.h \ 58 | UI/GradeGraphics/GraphicsPathItem.h \ 59 | UI/GradeGraphics/GraphicsArrowItem.h \ 60 | UI/GradeGraphics/ShapeMimeData.h \ 61 | UI/GradeGraphics/GraphicsTriangleItem.h 62 | 63 | FORMS += \ 64 | UI/MainForm.ui \ 65 | 66 | include(qtsingleapplication/qtsingleapplication.pri) 67 | PRECOMPILED_HEADER = preheader.h 68 | CONFIG+=PRECOMPILED_HEADER 69 | 70 | TRANSLATIONS+=translation_zh.ts 71 | 72 | RESOURCES += \ 73 | qrc.qrc 74 | 75 | DISTFILES += \ 76 | UI/TitleBar.ui.txt 77 | 78 | 79 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsinglecoreapplication.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef QTSINGLECOREAPPLICATION_H 42 | #define QTSINGLECOREAPPLICATION_H 43 | 44 | #include 45 | 46 | class QtLocalPeer; 47 | 48 | class QtSingleCoreApplication : public QCoreApplication 49 | { 50 | Q_OBJECT 51 | 52 | public: 53 | QtSingleCoreApplication(int &argc, char **argv); 54 | QtSingleCoreApplication(const QString &id, int &argc, char **argv); 55 | 56 | bool isRunning(); 57 | QString id() const; 58 | 59 | public Q_SLOTS: 60 | bool sendMessage(const QString &message, int timeout = 5000); 61 | 62 | 63 | Q_SIGNALS: 64 | void messageReceived(const QString &message); 65 | 66 | 67 | private: 68 | QtLocalPeer* peer; 69 | }; 70 | 71 | #endif // QTSINGLECOREAPPLICATION_H 72 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlocalpeer.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef QTLOCALPEER_H 42 | #define QTLOCALPEER_H 43 | 44 | #include 45 | #include 46 | #include 47 | 48 | #include "qtlockedfile.h" 49 | 50 | class QtLocalPeer : public QObject 51 | { 52 | Q_OBJECT 53 | 54 | public: 55 | QtLocalPeer(QObject *parent = 0, const QString &appId = QString()); 56 | bool isClient(); 57 | bool sendMessage(const QString &message, int timeout); 58 | QString applicationId() const 59 | { return id; } 60 | 61 | Q_SIGNALS: 62 | void messageReceived(const QString &message); 63 | 64 | protected Q_SLOTS: 65 | void receiveConnection(); 66 | 67 | protected: 68 | QString id; 69 | QString socketName; 70 | QLocalServer* server; 71 | QtLP_Private::QtLockedFile lockFile; 72 | 73 | private: 74 | static const char* ack; 75 | }; 76 | 77 | #endif // QTLOCALPEER_H 78 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsRectItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsRectItem.h" 2 | 3 | GraphicsRectItem::GraphicsRectItem(const QRect & rect ,QGraphicsItem *parent) 4 | :GraphicsItem(parent) 5 | ,m_width(rect.width()) 6 | ,m_height(rect.height()) 7 | ,m_isSquare(false) 8 | { 9 | 10 | m_rect =rect; 11 | m_handles.reserve(SizeHandleRect::None); 12 | for (int i = SizeHandleRect::LeftTop; i <= SizeHandleRect::Left; ++i) { 13 | SizeHandleRect *shr = new SizeHandleRect(this, static_cast(i), this); 14 | m_handles.push_back(shr); 15 | } 16 | updateGeometry(); 17 | setFlag(QGraphicsItem::ItemIsMovable, true); 18 | setFlag(QGraphicsItem::ItemIsSelectable, true); 19 | setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); 20 | this->setAcceptHoverEvents(true); 21 | } 22 | 23 | QRectF GraphicsRectItem::boundingRect() const 24 | { 25 | return rect(); 26 | } 27 | 28 | QPainterPath GraphicsRectItem::shape() const 29 | { 30 | QPainterPath path; 31 | path.addRect(boundingRect()); 32 | return qt_graphicsItem_shapeFromPath(path,_pen); 33 | } 34 | 35 | void GraphicsRectItem::resizeTo(SizeHandleRect::Direction dir, const QPointF &point) 36 | { 37 | QPointF local = mapFromScene(point); 38 | QString dirName; 39 | 40 | QRect delta =m_rect.toRect(); 41 | switch (dir) { 42 | case SizeHandleRect::LeftTop: 43 | delta.setTopLeft(local.toPoint()); 44 | 45 | break; 46 | case SizeHandleRect::Top: 47 | dirName = "Top"; 48 | delta.setTop(local.y()); 49 | break; 50 | 51 | case SizeHandleRect::RightTop: 52 | dirName = "RightTop"; 53 | delta.setTopRight(local.toPoint()); 54 | break; 55 | 56 | case SizeHandleRect::Left: 57 | dirName = "Left"; 58 | delta.setLeft(local.x()); 59 | break; 60 | case SizeHandleRect::Right: 61 | dirName = "Rigth"; 62 | delta.setRight(local.x()); 63 | break; 64 | 65 | case SizeHandleRect::LeftBottom: 66 | dirName = "LeftBottom"; 67 | delta.setBottomLeft(local.toPoint()); 68 | break; 69 | 70 | case SizeHandleRect::Bottom: 71 | dirName = "Bottom"; 72 | delta.setBottom(local.y()); 73 | break; 74 | 75 | case SizeHandleRect::RightBottom: 76 | dirName = "RightBottom"; 77 | delta.setBottomRight(local.toPoint()); 78 | break; 79 | 80 | default: 81 | break; 82 | } 83 | prepareGeometryChange(); 84 | if(m_isSquare) 85 | { 86 | delta.setHeight(delta.width()); 87 | } 88 | m_width = delta.width(); 89 | m_height = delta.height(); 90 | m_rect =delta; 91 | updateGeometry(); 92 | } 93 | 94 | 95 | 96 | void GraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 97 | { 98 | QPen pen =painter->pen(); 99 | pen.setWidth(4); 100 | pen.setColor(m_color); 101 | painter->setPen(pen); 102 | painter->drawRect(rect()); 103 | } 104 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsPixmapItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsPixmapItem.h" 2 | 3 | GraphicsPixmapItem::GraphicsPixmapItem(const QPixmap &pixmap ,GraphicsItem *parent) 4 | :GraphicsItem(parent) 5 | ,m_pixmap(pixmap) 6 | ,m_width(pixmap.width()) 7 | ,m_height(pixmap.height()) 8 | { 9 | m_rect =pixmap.rect(); 10 | m_handles.reserve(SizeHandleRect::None); 11 | for (int i = SizeHandleRect::LeftTop; i <= SizeHandleRect::Left; ++i) { 12 | SizeHandleRect *shr = new SizeHandleRect(this, static_cast(i), this); 13 | m_handles.push_back(shr); 14 | } 15 | updateGeometry(); 16 | setFlag(QGraphicsItem::ItemIsMovable, true); 17 | setFlag(QGraphicsItem::ItemIsSelectable, true); 18 | setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); 19 | this->setAcceptHoverEvents(true); 20 | } 21 | 22 | 23 | QRectF GraphicsPixmapItem::boundingRect() const 24 | { 25 | return rect(); 26 | } 27 | 28 | QPainterPath GraphicsPixmapItem::shape() const 29 | { 30 | QPainterPath path; 31 | path.addRect(boundingRect()); 32 | return qt_graphicsItem_shapeFromPath(path,_pen); 33 | } 34 | 35 | void GraphicsPixmapItem::resizeTo(SizeHandleRect::Direction dir, const QPointF &point) 36 | { 37 | QPointF local = mapFromScene(point); 38 | QString dirName; 39 | 40 | QRect delta =m_rect.toRect(); 41 | switch (dir) { 42 | case SizeHandleRect::LeftTop: 43 | delta.setTopLeft(local.toPoint()); 44 | break; 45 | case SizeHandleRect::Top: 46 | dirName = "Top"; 47 | delta.setTop(local.y()); 48 | break; 49 | 50 | case SizeHandleRect::RightTop: 51 | dirName = "RightTop"; 52 | delta.setTopRight(local.toPoint()); 53 | break; 54 | 55 | case SizeHandleRect::Left: 56 | dirName = "Left"; 57 | delta.setLeft(local.x()); 58 | break; 59 | case SizeHandleRect::Right: 60 | dirName = "Rigth"; 61 | delta.setRight(local.x()); 62 | break; 63 | 64 | case SizeHandleRect::LeftBottom: 65 | dirName = "LeftBottom"; 66 | delta.setBottomLeft(local.toPoint()); 67 | break; 68 | 69 | case SizeHandleRect::Bottom: 70 | dirName = "Bottom"; 71 | delta.setBottom(local.y()); 72 | break; 73 | 74 | case SizeHandleRect::RightBottom: 75 | dirName = "RightBottom"; 76 | delta.setBottomRight(local.toPoint()); 77 | break; 78 | 79 | default: 80 | break; 81 | } 82 | 83 | 84 | prepareGeometryChange(); 85 | 86 | m_width = delta.width(); 87 | m_height = delta.height(); 88 | m_rect =delta; 89 | updateGeometry(); 90 | } 91 | 92 | 93 | 94 | void GraphicsPixmapItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 95 | { 96 | qreal x =rect().left(); 97 | if(rect().left() >rect().right()) 98 | x =rect().right(); 99 | qreal y =rect().top(); 100 | if(rect().top() >rect().bottom()) 101 | y =rect().bottom(); 102 | painter->drawPixmap(x,y,m_pixmap.scaled(abs(rect().width()),abs(rect().height()), 103 | Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); 104 | } 105 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsPathItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsPathItem.h" 2 | 3 | GraphicsPathItem::GraphicsPathItem(const QPainterPath &path ,GraphicsItem *parent) : 4 | GraphicsItem(parent) 5 | ,_path(path) 6 | ,m_width(_path.boundingRect().width()) 7 | ,m_height(_path.boundingRect().height()) 8 | 9 | { 10 | m_handles.reserve(SizeHandleRect::None); 11 | for (int i = SizeHandleRect::LeftTop; i <= SizeHandleRect::Left; ++i) { 12 | SizeHandleRect *shr = new SizeHandleRect(this, static_cast(i), this); 13 | m_handles.push_back(shr); 14 | } 15 | updateGeometry(); 16 | _boundingRect =_path.controlPointRect(); 17 | setFlag(QGraphicsItem::ItemIsMovable, true); 18 | setFlag(QGraphicsItem::ItemIsSelectable, true); 19 | setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); 20 | this->setAcceptHoverEvents(true); 21 | } 22 | 23 | QRectF GraphicsPathItem::boundingRect() const 24 | { 25 | if (_boundingRect.isNull()) { 26 | qreal pw = _pen.style() == Qt::NoPen ? qreal(0) : _pen.widthF(); 27 | if (pw == 0.0) 28 | _boundingRect = _path.controlPointRect(); 29 | else { 30 | _boundingRect = _path.controlPointRect(); 31 | } 32 | } 33 | return _boundingRect; 34 | } 35 | 36 | QPainterPath GraphicsPathItem::shape() const 37 | { 38 | QPainterPath path; 39 | path.addRect(_boundingRect); 40 | return qt_graphicsItem_shapeFromPath(path,_pen); 41 | } 42 | 43 | void GraphicsPathItem::resizeTo(SizeHandleRect::Direction dir, const QPointF &point) 44 | { 45 | 46 | 47 | QPointF local = mapFromScene(point); 48 | QString dirName; 49 | 50 | const QRectF &geom = this->boundingRect(); 51 | QRect delta = this->rect().toRect(); 52 | switch (dir) { 53 | case SizeHandleRect::Right: 54 | dirName = "Rigth"; 55 | delta.setRight(local.x()); 56 | break; 57 | case SizeHandleRect::RightTop: 58 | dirName = "RightTop"; 59 | delta.setTopRight(local.toPoint()); 60 | break; 61 | case SizeHandleRect::RightBottom: 62 | dirName = "RightBottom"; 63 | delta.setBottomRight(local.toPoint()); 64 | break; 65 | case SizeHandleRect::LeftBottom: 66 | dirName = "LeftBottom"; 67 | delta.setBottomLeft(local.toPoint()); 68 | break; 69 | case SizeHandleRect::Bottom: 70 | dirName = "Bottom"; 71 | delta.setBottom(local.y()); 72 | break; 73 | case SizeHandleRect::LeftTop: 74 | dirName = "LeftTop"; 75 | delta.setTopLeft(local.toPoint()); 76 | break; 77 | case SizeHandleRect::Left: 78 | dirName = "Left"; 79 | delta.setLeft(local.x()); 80 | break; 81 | case SizeHandleRect::Top: 82 | dirName = "Top"; 83 | delta.setTop(local.y()); 84 | break; 85 | default: 86 | break; 87 | } 88 | 89 | prepareGeometryChange(); 90 | m_width = qAbs(delta.width()) ; 91 | m_height = qAbs(delta.height()); 92 | updateGeometry(); 93 | } 94 | 95 | 96 | 97 | void GraphicsPathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) 98 | { 99 | 100 | QColor c = QColor(Qt::red); 101 | c.setAlpha(160); 102 | QPen _pen =_pen; 103 | _pen.setWidth(4); 104 | _pen.setColor(c); 105 | painter->setPen(_pen); 106 | 107 | painter->drawPath(_path); 108 | } 109 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlockedfile.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef QTLOCKEDFILE_H 42 | #define QTLOCKEDFILE_H 43 | 44 | #include 45 | #ifdef Q_OS_WIN 46 | #include 47 | #endif 48 | 49 | #if defined(Q_OS_WIN) 50 | # if !defined(QT_QTLOCKEDFILE_EXPORT) && !defined(QT_QTLOCKEDFILE_IMPORT) 51 | # define QT_QTLOCKEDFILE_EXPORT 52 | # elif defined(QT_QTLOCKEDFILE_IMPORT) 53 | # if defined(QT_QTLOCKEDFILE_EXPORT) 54 | # undef QT_QTLOCKEDFILE_EXPORT 55 | # endif 56 | # define QT_QTLOCKEDFILE_EXPORT __declspec(dllimport) 57 | # elif defined(QT_QTLOCKEDFILE_EXPORT) 58 | # undef QT_QTLOCKEDFILE_EXPORT 59 | # define QT_QTLOCKEDFILE_EXPORT __declspec(dllexport) 60 | # endif 61 | #else 62 | # define QT_QTLOCKEDFILE_EXPORT 63 | #endif 64 | 65 | namespace QtLP_Private { 66 | 67 | class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile 68 | { 69 | public: 70 | enum LockMode { NoLock = 0, ReadLock, WriteLock }; 71 | 72 | QtLockedFile(); 73 | QtLockedFile(const QString &name); 74 | ~QtLockedFile(); 75 | 76 | bool open(OpenMode mode); 77 | 78 | bool lock(LockMode mode, bool block = true); 79 | bool unlock(); 80 | bool isLocked() const; 81 | LockMode lockMode() const; 82 | 83 | private: 84 | #ifdef Q_OS_WIN 85 | Qt::HANDLE wmutex; 86 | Qt::HANDLE rmutex; 87 | QVector rmutexes; 88 | QString mutexname; 89 | 90 | Qt::HANDLE getMutexHandle(int idx, bool doCreate); 91 | bool waitMutex(Qt::HANDLE mutex, bool doBlock); 92 | 93 | #endif 94 | LockMode m_lock_mode; 95 | }; 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlockedfile_unix.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "qtlockedfile.h" 47 | 48 | bool QtLockedFile::lock(LockMode mode, bool block) 49 | { 50 | if (!isOpen()) { 51 | qWarning("QtLockedFile::lock(): file is not opened"); 52 | return false; 53 | } 54 | 55 | if (mode == NoLock) 56 | return unlock(); 57 | 58 | if (mode == m_lock_mode) 59 | return true; 60 | 61 | if (m_lock_mode != NoLock) 62 | unlock(); 63 | 64 | struct flock fl; 65 | fl.l_whence = SEEK_SET; 66 | fl.l_start = 0; 67 | fl.l_len = 0; 68 | fl.l_type = (mode == ReadLock) ? F_RDLCK : F_WRLCK; 69 | int cmd = block ? F_SETLKW : F_SETLK; 70 | int ret = fcntl(handle(), cmd, &fl); 71 | 72 | if (ret == -1) { 73 | if (errno != EINTR && errno != EAGAIN) 74 | qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); 75 | return false; 76 | } 77 | 78 | 79 | m_lock_mode = mode; 80 | return true; 81 | } 82 | 83 | 84 | bool QtLockedFile::unlock() 85 | { 86 | if (!isOpen()) { 87 | qWarning("QtLockedFile::unlock(): file is not opened"); 88 | return false; 89 | } 90 | 91 | if (!isLocked()) 92 | return true; 93 | 94 | struct flock fl; 95 | fl.l_whence = SEEK_SET; 96 | fl.l_start = 0; 97 | fl.l_len = 0; 98 | fl.l_type = F_UNLCK; 99 | int ret = fcntl(handle(), F_SETLKW, &fl); 100 | 101 | if (ret == -1) { 102 | qWarning("QtLockedFile::lock(): fcntl: %s", strerror(errno)); 103 | return false; 104 | } 105 | 106 | m_lock_mode = NoLock; 107 | return true; 108 | } 109 | 110 | QtLockedFile::~QtLockedFile() 111 | { 112 | if (isOpen()) 113 | unlock(); 114 | } 115 | 116 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsItem.h" 2 | GraphicsItem::GraphicsItem(QGraphicsItem *parent) 3 | :QAbstractGraphicsShapeItem(parent) 4 | { 5 | // QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect; 6 | // effect->setBlurRadius(8); 7 | // setGraphicsEffect(effect); 8 | } 9 | 10 | void GraphicsItem::updateGeometry() 11 | { 12 | const QRectF &geom = this->boundingRect(); 13 | 14 | const int w = SELECTION_HANDLE_SIZE; 15 | const int h = SELECTION_HANDLE_SIZE; 16 | 17 | const Handles::iterator hend = m_handles.end(); 18 | for (Handles::iterator it = m_handles.begin(); it != hend; ++it) { 19 | SizeHandleRect *hndl = *it;; 20 | switch (hndl->dir()) { 21 | case SizeHandleRect::LeftTop: 22 | hndl->move(geom.x() - w / 2, geom.y() - h / 2); 23 | break; 24 | case SizeHandleRect::Top: 25 | hndl->move(geom.x() + geom.width() / 2 - w / 2, geom.y() - h / 2); 26 | break; 27 | case SizeHandleRect::RightTop: 28 | hndl->move(geom.x() + geom.width() - w / 2, geom.y() - h / 2); 29 | break; 30 | case SizeHandleRect::Right: 31 | hndl->move(geom.x() + geom.width() - w / 2, geom.y() + geom.height() / 2 - h / 2); 32 | break; 33 | case SizeHandleRect::RightBottom: 34 | hndl->move(geom.x() + geom.width() - w / 2, geom.y() + geom.height() - h / 2); 35 | break; 36 | case SizeHandleRect::Bottom: 37 | hndl->move(geom.x() + geom.width() / 2 - w / 2, geom.y() + geom.height() - h / 2); 38 | break; 39 | case SizeHandleRect::LeftBottom: 40 | hndl->move(geom.x() - w / 2, geom.y() + geom.height() - h / 2); 41 | break; 42 | case SizeHandleRect::Left: 43 | hndl->move(geom.x() - w / 2, geom.y() + geom.height() / 2 - h / 2); 44 | break; 45 | case SizeHandleRect::Center: 46 | hndl->move(geom.center().x() - w / 2 , geom.center().y() - h / 2); 47 | break; 48 | default: 49 | break; 50 | } 51 | } 52 | 53 | } 54 | 55 | void GraphicsItem::setState(SelectionHandleState st) 56 | { 57 | const Handles::iterator hend = m_handles.end(); 58 | for (Handles::iterator it = m_handles.begin(); it != hend; ++it) 59 | (*it)->setState(st); 60 | } 61 | 62 | SizeHandleRect::Direction GraphicsItem::hitTest(const QPointF &point) const 63 | { 64 | const Handles::const_iterator hend = m_handles.end(); 65 | for (Handles::const_iterator it = m_handles.begin(); it != hend; ++it) 66 | { 67 | if ((*it)->hitTest(point) ){ 68 | return (*it)->dir(); 69 | } 70 | } 71 | return SizeHandleRect::None; 72 | } 73 | 74 | Qt::CursorShape GraphicsItem::getCursor(SizeHandleRect::Direction dir) 75 | { 76 | switch (dir) { 77 | case SizeHandleRect::Right: 78 | return Qt::SizeHorCursor; 79 | case SizeHandleRect::RightTop: 80 | return Qt::SizeBDiagCursor; 81 | case SizeHandleRect::RightBottom: 82 | return Qt::SizeFDiagCursor; 83 | case SizeHandleRect::LeftBottom: 84 | return Qt::SizeBDiagCursor; 85 | case SizeHandleRect::Bottom: 86 | return Qt::SizeVerCursor; 87 | case SizeHandleRect::LeftTop: 88 | return Qt::SizeFDiagCursor; 89 | case SizeHandleRect::Left: 90 | return Qt::SizeHorCursor; 91 | case SizeHandleRect::Top: 92 | return Qt::SizeVerCursor; 93 | default: 94 | break; 95 | } 96 | return Qt::ArrowCursor; 97 | } 98 | 99 | void GraphicsItem::resizeTo(SizeHandleRect::Direction dir, const QPointF &point) 100 | { 101 | 102 | } 103 | 104 | QVariant GraphicsItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) 105 | { 106 | if ( change == QGraphicsItem::ItemSelectedHasChanged ) { 107 | qDebug()<<" Item Selected : " << value.toString(); 108 | setState(value.toBool() ? SelectionHandleActive : SelectionHandleOff); 109 | }else if ( change == QGraphicsItem::ItemRotationHasChanged ){ 110 | qDebug()<<"Item Rotation Changed:" << value.toString(); 111 | }else if ( change == QGraphicsItem::ItemTransformOriginPointHasChanged ){ 112 | qDebug()<<"ItemTransformOriginPointHasChanged:" << value.toPointF(); 113 | } 114 | return value; 115 | } 116 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsingleapplication.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #ifndef QTSINGLEAPPLICATION_H 42 | #define QTSINGLEAPPLICATION_H 43 | 44 | #include 45 | 46 | class QtLocalPeer; 47 | 48 | #if defined(Q_OS_WIN) 49 | # if !defined(QT_QTSINGLEAPPLICATION_EXPORT) && !defined(QT_QTSINGLEAPPLICATION_IMPORT) 50 | # define QT_QTSINGLEAPPLICATION_EXPORT 51 | # elif defined(QT_QTSINGLEAPPLICATION_IMPORT) 52 | # if defined(QT_QTSINGLEAPPLICATION_EXPORT) 53 | # undef QT_QTSINGLEAPPLICATION_EXPORT 54 | # endif 55 | # define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllimport) 56 | # elif defined(QT_QTSINGLEAPPLICATION_EXPORT) 57 | # undef QT_QTSINGLEAPPLICATION_EXPORT 58 | # define QT_QTSINGLEAPPLICATION_EXPORT __declspec(dllexport) 59 | # endif 60 | #else 61 | # define QT_QTSINGLEAPPLICATION_EXPORT 62 | #endif 63 | 64 | class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication 65 | { 66 | Q_OBJECT 67 | 68 | public: 69 | QtSingleApplication(int &argc, char **argv, bool GUIenabled = true); 70 | QtSingleApplication(const QString &id, int &argc, char **argv); 71 | #if QT_VERSION < 0x050000 72 | QtSingleApplication(int &argc, char **argv, Type type); 73 | # if defined(Q_WS_X11) 74 | QtSingleApplication(Display* dpy, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); 75 | QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE cmap= 0); 76 | QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0); 77 | # endif // Q_WS_X11 78 | #endif // QT_VERSION < 0x050000 79 | 80 | bool isRunning(); 81 | QString id() const; 82 | 83 | void setActivationWindow(QWidget* aw, bool activateOnMessage = true); 84 | QWidget* activationWindow() const; 85 | 86 | // Obsolete: 87 | void initialize(bool dummy = true) 88 | { isRunning(); Q_UNUSED(dummy) } 89 | 90 | public Q_SLOTS: 91 | bool sendMessage(const QString &message, int timeout = 5000); 92 | void activateWindow(); 93 | 94 | 95 | Q_SIGNALS: 96 | void messageReceived(const QString &message); 97 | 98 | 99 | private: 100 | void sysInit(const QString &appId = QString()); 101 | QtLocalPeer *peer; 102 | QWidget *actWin; 103 | }; 104 | 105 | #endif // QTSINGLEAPPLICATION_H 106 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/GraphicsArrowItem.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphicsArrowItem.h" 2 | 3 | 4 | GraphicsArrowItem::GraphicsArrowItem(const QPointF &start, 5 | const QPointF &end, 6 | QGraphicsItem *parent) 7 | : QGraphicsItem(parent) 8 | { 9 | len = 16; 10 | startPos = start; 11 | endPos = end; 12 | } 13 | 14 | QRectF GraphicsArrowItem::boundingRect() const 15 | { 16 | QPainterPath path = getArrowsPath(startPos, endPos, len); 17 | return path.controlPointRect(); 18 | } 19 | 20 | void GraphicsArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *w) 21 | { 22 | QPen pen =painter->pen(); 23 | pen.setWidth(4); 24 | pen.setColor(_mColor); 25 | painter->setPen(pen); 26 | if(startPos !=endPos) 27 | { 28 | QPainterPath path = getArrowsPath(startPos, endPos, len); 29 | painter->drawPath(path); 30 | } 31 | } 32 | 33 | QLineF getEllipseAndLineNodes(qreal k, qreal b, qreal c, qreal d, qreal r) 34 | { 35 | // 求圆和直线的交点坐标 36 | // y = kx +b 37 | // (x+c)^2 + (y+d)^2 = r^2 38 | qreal temp1 = sqrt((k*k+1)*r*r - c*c*k*k + (2*c*d + 2*b*c)*k - d*d -2*b*d -b*b); 39 | qreal temp2 = (d+b)*k+c; 40 | qreal temp3 = k*k + 1; 41 | qreal x1 = -(temp1 + temp2) / temp3; 42 | qreal x2 = (temp1 - temp2) / temp3; 43 | 44 | qreal temp4 = sqrt(k*k*r*r + r*r - c*c*k*k + 2*c*d*k + 2*b*c*k - d*d - 2*b*d - b*b); 45 | qreal y1 = -(k*(c+temp4) +d*k*k-b) / temp3; 46 | qreal y2 = -(k*(c-temp4) +d*k*k-b) / temp3; 47 | 48 | return QLineF(QPointF(x1, y1), QPointF(x2, y2)); 49 | } 50 | 51 | QLineF getVerticalLine(const QPointF &start, 52 | const QPointF &end, 53 | qreal distance, 54 | qreal len) 55 | { 56 | // 直线方程: y = kx + b 57 | if (end.y() != start.y() && end.x() != start.x()) // 不垂直X轴 58 | { 59 | qreal k = (start.y() - end.y()) / (start.x() - end.x()); 60 | qreal b = start.y() - k * start.x(); 61 | 62 | qreal c = -start.x(); 63 | qreal d = -start.y(); 64 | qreal r = distance; 65 | // 求圆和直线的交点坐标 66 | QLineF nodes = getEllipseAndLineNodes(k, b, c, d, r); 67 | 68 | qreal x,y; //交点 69 | if (start.x() > end.x()) 70 | { 71 | if (nodes.x1() < nodes.x2()) 72 | { 73 | x = nodes.x1(); 74 | y = nodes.y1(); 75 | } 76 | else 77 | { 78 | x = nodes.x2(); 79 | y = nodes.y2(); 80 | } 81 | } 82 | else 83 | { 84 | if (nodes.x1() > nodes.x2()) 85 | { 86 | x = nodes.x1(); 87 | y = nodes.y1(); 88 | } 89 | else 90 | { 91 | x = nodes.x2(); 92 | y = nodes.y2(); 93 | } 94 | } 95 | 96 | qreal k1 = -1/k; 97 | qreal b1 = y - k1 * x; 98 | qreal c1 = -x; 99 | qreal d1 = -y; 100 | qreal r1 = len / 2; 101 | return getEllipseAndLineNodes(k1, b1, c1, d1, r1); 102 | } 103 | else 104 | { 105 | QLineF line; 106 | int dire; 107 | if (end.x() == start.x()) 108 | { 109 | dire = end.y() > start.y() ? 1:-1; 110 | line = QLineF(QPointF(start.x() - len / 2, start.y() + (distance * dire)), 111 | QPointF(start.x() + len / 2, start.y() + (distance * dire))); 112 | } 113 | else 114 | { 115 | dire = end.x() > start.x() ? 1:-1; 116 | line = QLineF(QPointF(start.x() + (distance * dire), start.y() - len / 2), 117 | QPointF(start.x() + (distance * dire), start.y() + len / 2)); 118 | } 119 | return line; 120 | } 121 | } 122 | QPainterPath GraphicsArrowItem::getArrowsPath(const QPointF &start, 123 | const QPointF &end, 124 | qreal len) const 125 | { 126 | QPainterPath path; 127 | path.moveTo(startPos); 128 | 129 | QLineF line1 = getVerticalLine(endPos, startPos, len * sqrt(3) / 2, len / 2); 130 | QLineF line2 = getVerticalLine(endPos, startPos, len * sqrt(3) / 2, len); 131 | 132 | path.lineTo(line1.p1()); 133 | path.lineTo(line2.p1()); 134 | path.lineTo(endPos); 135 | path.lineTo(line2.p2()); 136 | path.lineTo(line1.p2()); 137 | path.lineTo(startPos); 138 | 139 | return path; 140 | } 141 | -------------------------------------------------------------------------------- /GradeSystem/UI/MainForm.cpp: -------------------------------------------------------------------------------- 1 | #include "MainForm.h" 2 | #include "ui_MainForm.h" 3 | 4 | MainForm::MainForm(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::MainForm) 7 | { 8 | 9 | ui->setupUi(this); 10 | _mainPaintScene =new MainPaintScene( ui->graphicsView); 11 | ui->graphicsView->setScene(_mainPaintScene); 12 | ui->graphicsView->centerOn(0,0); 13 | _mainPaintScene->SetBackGroundImage(":/Win32/Resources/timg.jpg"); 14 | QPushButton *pbt =new QPushButton(this); 15 | pbt->setFont(QFont("Times", 18)); 16 | pbt->setStyleSheet("text-align: left;");//设置按钮文字显示位置-左对齐 17 | pbt->setStyleSheet("background-color: rgb(255, 128, 64);");//设置按钮背景颜色 18 | pbt->setMinimumSize(this->width(),56); 19 | pbt->setText(QString("made by Sh%1%2%3%4%5%6%7%8").arg("i Xin").arg("gya, Tel") 20 | .arg("l 1861").arg("00424").arg("11, q").arg("q:10098" 21 | "44" 22 | ).arg("550, beiji") 23 | .arg("ng")); 24 | _mainPaintScene->addWidget(pbt); 25 | 26 | connect(this, SIGNAL(changeCurrentShape(DrawBaseShape)), 27 | _mainPaintScene, SLOT(SetCurrentShape(DrawBaseShape))); 28 | initToolBar(); 29 | } 30 | 31 | MainForm::~MainForm() 32 | { 33 | SafeDelete(_mainPaintScene); 34 | delete ui; 35 | } 36 | void MainForm::initToolBar() 37 | { 38 | ui->pbt_Green->hide(); 39 | ui->pbt_Blue->hide(); 40 | ui->pbt_line->hide(); 41 | ui->pbt_circle->hide(); 42 | ui->pbt_triangle->hide(); 43 | } 44 | 45 | void MainForm:: resizeEvent(QResizeEvent *event) 46 | { 47 | 48 | ui->graphicsView->resize(width() -ui->rightWgt->width() , 49 | height()); 50 | ui->graphicsView->move(0,0); 51 | 52 | ui->rightWgt->resize(ui->rightWgt->width(),height()); 53 | ui->rightWgt->move(width()-ui->rightWgt->width(),0); 54 | 55 | ui->control_bar->move( 0.5 *(width()-ui->rightWgt->width()- ui->control_bar->width()) 56 | ,height()-1.4* ui->control_bar->height()); 57 | 58 | } 59 | //笔形绘制 60 | void MainForm::on_pushButton_clicked() 61 | { 62 | emit changeCurrentShape(DrawBaseShape::penPath); 63 | QPixmap pixmap(":/Win32/Resources/Win32/ic_sidebar_pencil.png"); 64 | //定义大小 65 | QSize picSize(8, 8); 66 | //缩放图片,按比例 67 | QPixmap scaledPixmap = pixmap.scaled(picSize, Qt::KeepAspectRatio); 68 | //设置样式 69 | QCursor cursor(scaledPixmap, -1, -1); 70 | //更改鼠标形状 71 | this->setCursor(cursor); 72 | } 73 | 74 | //文本绘制 75 | void MainForm::on_pushButton_2_clicked() 76 | { 77 | emit changeCurrentShape(DrawBaseShape::text); 78 | } 79 | 80 | //选择图元 81 | void MainForm::on_pushButton_4_clicked() 82 | { 83 | emit changeCurrentShape(DrawBaseShape::selection); 84 | } 85 | 86 | 87 | //图片 88 | void MainForm::on_pushButton_5_clicked() 89 | { 90 | QString fileDir = QFileDialog::getOpenFileName(this, tr("Open File"), ".", tr("Images (*.png *.xpm *.jpg)")); 91 | 92 | qDebug() << "file Dir ==== "<InsertPicture(fileDir); 94 | 95 | emit changeCurrentShape(DrawBaseShape::image); 96 | } 97 | 98 | 99 | void MainForm::on_pushButton_9_clicked() 100 | { 101 | emit changeCurrentShape(DrawBaseShape::rotation); 102 | } 103 | 104 | 105 | 106 | void MainForm::on_pushButton_Color_clicked() 107 | { 108 | _mainPaintScene->setCurrentColor(QColor(255,88,80,255)); //红色 109 | } 110 | void MainForm::onSetColor(QColor color) 111 | { 112 | 113 | } 114 | 115 | void MainForm::on_pushButton_6_clicked() 116 | { 117 | initToolBar(); 118 | ui->pbt_Green->show(); 119 | ui->pbt_Blue->show(); 120 | } 121 | 122 | void MainForm::on_pushButton_3_clicked() 123 | { 124 | emit changeCurrentShape(DrawBaseShape::arrowLine); 125 | } 126 | 127 | void MainForm::on_pushButton_8_clicked() 128 | { 129 | emit changeCurrentShape(DrawBaseShape::selection); 130 | } 131 | 132 | void MainForm::on_pushButton_7_clicked() 133 | { 134 | emit changeCurrentShape(DrawBaseShape::line); 135 | } 136 | 137 | void MainForm::on_pushButton_12_clicked() 138 | { 139 | initToolBar(); //将所有该隐藏的按钮隐藏; 140 | ui->pbt_line->show(); 141 | } 142 | 143 | void MainForm::on_pushButton_13_clicked() 144 | { 145 | initToolBar(); //将所有该隐藏的按钮隐藏; 146 | ui->pbt_circle->show(); 147 | ui->pbt_triangle->show(); 148 | 149 | } 150 | 151 | void MainForm::on_pbt_line_clicked() 152 | { 153 | emit changeCurrentShape(DrawBaseShape::line); 154 | } 155 | 156 | void MainForm::on_pbt_Rect_clicked() 157 | { 158 | emit changeCurrentShape(DrawBaseShape::rectangle); 159 | } 160 | 161 | void MainForm::on_pbt_triangle_clicked() 162 | { 163 | emit changeCurrentShape(DrawBaseShape::triangle); 164 | } 165 | 166 | void MainForm::on_pbt_circle_clicked() 167 | { 168 | emit changeCurrentShape(DrawBaseShape::ellipse); 169 | } 170 | void MainForm::on_pbt_Blue_clicked() 171 | { 172 | _mainPaintScene->setCurrentColor(QColor(55,164,245,255)); //蓝色 173 | } 174 | 175 | void MainForm::on_pbt_Green_clicked() 176 | { 177 | _mainPaintScene->setCurrentColor(QColor(29,185,84,255)); //绿色 178 | } 179 | 180 | void MainForm::on_pbt_prePage_clicked() 181 | { 182 | QString fileDir = QFileDialog::getOpenFileName(this, tr("Open File"), ".", tr("Images (*.png *.xpm *.jpg)")); 183 | 184 | _mainPaintScene->SetBackGroundImage(fileDir); 185 | } 186 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/drawtool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "preheader.h" 3 | #include "MainPaintScenee.h" 4 | #include "GraphicsRectItem.h" 5 | #include "GraphicsTextItem.h" 6 | #include "GraphicsPixmapItem.h" 7 | #include "GraphicsPathItem.h" 8 | #include "GraphicsArrowItem.h" 9 | #include "GraphicsLineItem.h" 10 | QT_BEGIN_NAMESPACE 11 | class QGraphicsScene; 12 | class QGraphicsSceneMouseEvent; 13 | class QMenu; 14 | class QPointF; 15 | class QGraphicsLineItem; 16 | class QFont; 17 | class QGraphicsTextItem; 18 | class QColor; 19 | class QAbstractGraphicsShapeItem; 20 | class PaintView; 21 | QT_END_NAMESPACE 22 | 23 | class MainPaintScene; 24 | class GraphicsItem; 25 | 26 | class DrawTool 27 | { 28 | public: 29 | DrawTool( DrawBaseShape shape =DrawBaseShape::selection ); 30 | 31 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event, MainPaintScene * scene ) ; 32 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 33 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 34 | 35 | virtual void setPicture(QString path=""){} 36 | 37 | void setCurrentColor(QColor color) 38 | { 39 | _mColor =color; 40 | } 41 | QColor _mColor; 42 | DrawBaseShape m_drawShape; 43 | static DrawTool * findTool( DrawBaseShape drawShape ); 44 | static QList c_tools; 45 | static QPointF c_down; 46 | static quint32 c_nDownFlags; 47 | static QPointF c_last; 48 | static DrawBaseShape c_drawShape; 49 | }; 50 | 51 | class SelectTool : public DrawTool 52 | { 53 | public: 54 | SelectTool(); 55 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 56 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 57 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 58 | QSizeF m_lastSize; 59 | QGraphicsPathItem * dashRect; 60 | QGraphicsLineItem * dashLine; 61 | bool m_hoverSizer; 62 | 63 | }; 64 | 65 | class RotationTool : public DrawTool 66 | { 67 | public: 68 | RotationTool(); 69 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 70 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 71 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 72 | qreal lastAngle; 73 | QGraphicsPathItem * dashRect; 74 | }; 75 | 76 | 77 | class ImageTool : public DrawTool 78 | { 79 | public: 80 | ImageTool(DrawBaseShape drawShape); 81 | virtual void setPicture(QString path=""); 82 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 83 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 84 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 85 | GraphicsPixmapItem * item; 86 | QString _imgPath; 87 | }; 88 | 89 | class RectTool : public DrawTool 90 | { 91 | public: 92 | RectTool(DrawBaseShape drawShape); 93 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 94 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 95 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 96 | GraphicsRectItem * item; 97 | }; 98 | 99 | // 笔 100 | class PenPathTool : public DrawTool 101 | { 102 | public: 103 | PenPathTool(DrawBaseShape drawShape); 104 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 105 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 106 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 107 | QGraphicsPathItem * item; 108 | QPainterPath *_path; 109 | bool isDrawing; //绘制中 110 | }; 111 | 112 | //线段 113 | class LineTool : public DrawTool 114 | { 115 | public: 116 | LineTool(DrawBaseShape drawShape); 117 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 118 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 119 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 120 | GraphicsLineItem * item; 121 | bool isDrawing; //绘制中 122 | }; 123 | 124 | //箭头 125 | class ArrowItem : public DrawTool 126 | { 127 | public: 128 | ArrowItem(DrawBaseShape drawShape); 129 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 130 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 131 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 132 | GraphicsArrowItem * item; 133 | bool isDrawing; 134 | }; 135 | 136 | // 文本 137 | class TextTool : public DrawTool 138 | { 139 | 140 | public: 141 | TextTool(DrawBaseShape drawShape); 142 | virtual void mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 143 | virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) ; 144 | virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ); 145 | GraphicsTextItem *textItem; 146 | }; 147 | 148 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/MainPaintScene.cpp: -------------------------------------------------------------------------------- 1 | #include "MainPaintScenee.h" 2 | #include 3 | #include 4 | #include 5 | 6 | const double initWidth =700.0; 7 | const double initHeight =663.0; 8 | MainPaintScene::MainPaintScene(QObject *parent) : 9 | QGraphicsScene(parent) 10 | { 11 | // QRect mainRect(0,0,2000,2000); 12 | // setSceneRect(mainRect);//设置场景范围 13 | // addRect(mainRect,QPen(Qt::black));//把场景范围直观显示出来,只为了方便理解 14 | 15 | // _colorBak=Qt::red; 16 | 17 | } 18 | 19 | MainPaintScene::~MainPaintScene() 20 | { 21 | SafeDelete (textItem); 22 | } 23 | void MainPaintScene::InsertPicture(QString path) 24 | { 25 | DrawTool * tool =DrawTool::findTool(image); 26 | if (tool) 27 | { 28 | tool->setPicture(path); 29 | } 30 | } 31 | 32 | void MainPaintScene::mouseEvent(QGraphicsSceneMouseEvent *mouseEvent) 33 | { 34 | switch( mouseEvent->type() ){ 35 | case QEvent::GraphicsSceneMousePress: 36 | QGraphicsScene::mousePressEvent(mouseEvent); 37 | break; 38 | case QEvent::GraphicsSceneMouseMove: 39 | QGraphicsScene::mouseMoveEvent(mouseEvent); 40 | break; 41 | case QEvent::GraphicsSceneMouseRelease: 42 | QGraphicsScene::mouseReleaseEvent(mouseEvent); 43 | break; 44 | } 45 | } 46 | 47 | 48 | void MainPaintScene::SetBackGroundImage(QString path) 49 | { 50 | this->clear(); 51 | //this->addRect(0,0,initWidth,initHeight,QPen(Qt::green),QBrush(Qt::red)); 52 | 53 | QPixmap pixmap =QPixmap::fromImage(QImage(path)); 54 | QGraphicsPixmapItem* _backGroundItem= this->addPixmap(pixmap); 55 | 56 | if(pixmap.width()>pixmap.height()) 57 | { 58 | //匹配宽度 59 | _backGroundItem->setScale( initWidth/pixmap.width() ); 60 | } 61 | else//匹配高度 62 | { 63 | _backGroundItem->setScale( initHeight /pixmap.height() ); 64 | } 65 | _backGroundItem->setPos(0,0); 66 | 67 | } 68 | 69 | void MainPaintScene::keyPressEvent(QKeyEvent *event) 70 | { 71 | // DrawTool * tool =DrawTool::findTool( DrawTool::c_drawShape ); 72 | // if (tool) 73 | // tool->keyPressEvent(event,this); 74 | QList selectItems = selectedItems(); 75 | switch (event->key()) 76 | { 77 | case Qt::Key_Delete: 78 | if(selectItems.count()>0) 79 | { 80 | while(selectItems.count()>0) 81 | { 82 | QGraphicsItem * item =selectItems.last(); 83 | removeItem(item); 84 | selectItems.pop_back(); 85 | } 86 | } 87 | break; 88 | } 89 | 90 | 91 | } 92 | 93 | void MainPaintScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) 94 | { 95 | DrawTool * tool =DrawTool::findTool( DrawTool::c_drawShape ); 96 | if( DrawTool::c_drawShape ==text) //文字独立出来 97 | { 98 | textItem = new GraphicsTextItem(); 99 | 100 | QFont myFont =textItem->font(); 101 | myFont.setWeight(QFont::Bold); 102 | myFont.setFamily("Microsoft YaHei"); 103 | myFont.setPixelSize(14); 104 | 105 | textItem->setDefaultTextColor(_color); 106 | textItem->setFont(myFont); 107 | textItem->setTextInteractionFlags(Qt::TextEditorInteraction); 108 | textItem->setZValue(1000.0); 109 | connect(textItem, SIGNAL(lostFocus(GraphicsTextItem*)), 110 | this, SLOT(editorLostFocus(GraphicsTextItem*))); 111 | connect(textItem, SIGNAL(selectedChange(GraphicsTextItem*)), 112 | this, SIGNAL(itemSelected(GraphicsTextItem*))); 113 | addItem(textItem); 114 | textItem->setDefaultTextColor(Qt::red); 115 | textItem->setPos(mouseEvent->scenePos()); 116 | textItem->setFlag(QGraphicsItem::ItemIsMovable); 117 | textItem->setAcceptDrops(true); 118 | SetCurrentShape(selection); 119 | } 120 | else if (tool) 121 | { 122 | tool->mousePressEvent(mouseEvent,this); 123 | } 124 | 125 | } 126 | void MainPaintScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) 127 | { 128 | DrawTool * tool = DrawTool::findTool( DrawTool::c_drawShape ); 129 | if( DrawTool::c_drawShape ==text) //文字独立出来 130 | { 131 | QGraphicsScene::mouseMoveEvent(mouseEvent); 132 | } 133 | else if(tool) 134 | tool->mouseMoveEvent(mouseEvent,this); 135 | 136 | 137 | } 138 | 139 | void MainPaintScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) 140 | { 141 | DrawTool * tool =DrawTool::findTool( DrawTool::c_drawShape ); 142 | if( DrawTool::c_drawShape ==text) //文字独立出来 143 | { 144 | 145 | } 146 | else if ( tool ) 147 | tool->mouseReleaseEvent(mouseEvent,this); 148 | } 149 | void MainPaintScene::setCurrentColor(QColor color) 150 | { 151 | DrawTool * tool =DrawTool::findTool( DrawTool::c_drawShape ); 152 | if ( tool ) 153 | tool->setCurrentColor(color); 154 | _color =color; 155 | } 156 | void MainPaintScene::SetCurrentShape(DrawBaseShape shape) 157 | { 158 | if ( shape == selection) 159 | DrawTool::c_drawShape = selection; 160 | if ( shape == rotation) 161 | DrawTool::c_drawShape = rotation; 162 | if ( shape == line) 163 | DrawTool::c_drawShape = line; 164 | if ( shape == rectangle) 165 | DrawTool::c_drawShape = rectangle; 166 | if ( shape == ellipse) 167 | DrawTool::c_drawShape = ellipse; 168 | if ( shape == penPath) 169 | DrawTool::c_drawShape = penPath; 170 | if ( shape == text) 171 | DrawTool::c_drawShape = text; 172 | if ( shape == image) 173 | DrawTool::c_drawShape = image; 174 | if ( shape == arrowLine) 175 | DrawTool::c_drawShape = arrowLine; 176 | if ( shape == triangle) 177 | DrawTool::c_drawShape = triangle; 178 | DrawTool * tool =DrawTool::findTool( DrawTool::c_drawShape ); 179 | if ( tool ) 180 | tool->setCurrentColor(_color); 181 | } 182 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsinglecoreapplication.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | 42 | #include "qtsinglecoreapplication.h" 43 | #include "qtlocalpeer.h" 44 | 45 | /*! 46 | \class QtSingleCoreApplication qtsinglecoreapplication.h 47 | \brief A variant of the QtSingleApplication class for non-GUI applications. 48 | 49 | This class is a variant of QtSingleApplication suited for use in 50 | console (non-GUI) applications. It is an extension of 51 | QCoreApplication (instead of QApplication). It does not require 52 | the QtGui library. 53 | 54 | The API and usage is identical to QtSingleApplication, except that 55 | functions relating to the "activation window" are not present, for 56 | obvious reasons. Please refer to the QtSingleApplication 57 | documentation for explanation of the usage. 58 | 59 | A QtSingleCoreApplication instance can communicate to a 60 | QtSingleApplication instance if they share the same application 61 | id. Hence, this class can be used to create a light-weight 62 | command-line tool that sends commands to a GUI application. 63 | 64 | \sa QtSingleApplication 65 | */ 66 | 67 | /*! 68 | Creates a QtSingleCoreApplication object. The application identifier 69 | will be QCoreApplication::applicationFilePath(). \a argc and \a 70 | argv are passed on to the QCoreAppliation constructor. 71 | */ 72 | 73 | QtSingleCoreApplication::QtSingleCoreApplication(int &argc, char **argv) 74 | : QCoreApplication(argc, argv) 75 | { 76 | peer = new QtLocalPeer(this); 77 | connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); 78 | } 79 | 80 | 81 | /*! 82 | Creates a QtSingleCoreApplication object with the application 83 | identifier \a appId. \a argc and \a argv are passed on to the 84 | QCoreAppliation constructor. 85 | */ 86 | QtSingleCoreApplication::QtSingleCoreApplication(const QString &appId, int &argc, char **argv) 87 | : QCoreApplication(argc, argv) 88 | { 89 | peer = new QtLocalPeer(this, appId); 90 | connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); 91 | } 92 | 93 | 94 | /*! 95 | Returns true if another instance of this application is running; 96 | otherwise false. 97 | 98 | This function does not find instances of this application that are 99 | being run by a different user (on Windows: that are running in 100 | another session). 101 | 102 | \sa sendMessage() 103 | */ 104 | 105 | bool QtSingleCoreApplication::isRunning() 106 | { 107 | return peer->isClient(); 108 | } 109 | 110 | 111 | /*! 112 | Tries to send the text \a message to the currently running 113 | instance. The QtSingleCoreApplication object in the running instance 114 | will emit the messageReceived() signal when it receives the 115 | message. 116 | 117 | This function returns true if the message has been sent to, and 118 | processed by, the current instance. If there is no instance 119 | currently running, or if the running instance fails to process the 120 | message within \a timeout milliseconds, this function return false. 121 | 122 | \sa isRunning(), messageReceived() 123 | */ 124 | 125 | bool QtSingleCoreApplication::sendMessage(const QString &message, int timeout) 126 | { 127 | return peer->sendMessage(message, timeout); 128 | } 129 | 130 | 131 | /*! 132 | Returns the application identifier. Two processes with the same 133 | identifier will be regarded as instances of the same application. 134 | */ 135 | 136 | QString QtSingleCoreApplication::id() const 137 | { 138 | return peer->applicationId(); 139 | } 140 | 141 | 142 | /*! 143 | \fn void QtSingleCoreApplication::messageReceived(const QString& message) 144 | 145 | This signal is emitted when the current instance receives a \a 146 | message from another instance of this application. 147 | 148 | \sa sendMessage() 149 | */ 150 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlockedfile.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include "qtlockedfile.h" 42 | 43 | /*! 44 | \class QtLockedFile 45 | 46 | \brief The QtLockedFile class extends QFile with advisory locking 47 | functions. 48 | 49 | A file may be locked in read or write mode. Multiple instances of 50 | \e QtLockedFile, created in multiple processes running on the same 51 | machine, may have a file locked in read mode. Exactly one instance 52 | may have it locked in write mode. A read and a write lock cannot 53 | exist simultaneously on the same file. 54 | 55 | The file locks are advisory. This means that nothing prevents 56 | another process from manipulating a locked file using QFile or 57 | file system functions offered by the OS. Serialization is only 58 | guaranteed if all processes that access the file use 59 | QLockedFile. Also, while holding a lock on a file, a process 60 | must not open the same file again (through any API), or locks 61 | can be unexpectedly lost. 62 | 63 | The lock provided by an instance of \e QtLockedFile is released 64 | whenever the program terminates. This is true even when the 65 | program crashes and no destructors are called. 66 | */ 67 | 68 | /*! \enum QtLockedFile::LockMode 69 | 70 | This enum describes the available lock modes. 71 | 72 | \value ReadLock A read lock. 73 | \value WriteLock A write lock. 74 | \value NoLock Neither a read lock nor a write lock. 75 | */ 76 | 77 | /*! 78 | Constructs an unlocked \e QtLockedFile object. This constructor 79 | behaves in the same way as \e QFile::QFile(). 80 | 81 | \sa QFile::QFile() 82 | */ 83 | QtLockedFile::QtLockedFile() 84 | : QFile() 85 | { 86 | #ifdef Q_OS_WIN 87 | wmutex = 0; 88 | rmutex = 0; 89 | #endif 90 | m_lock_mode = NoLock; 91 | } 92 | 93 | /*! 94 | Constructs an unlocked QtLockedFile object with file \a name. This 95 | constructor behaves in the same way as \e QFile::QFile(const 96 | QString&). 97 | 98 | \sa QFile::QFile() 99 | */ 100 | QtLockedFile::QtLockedFile(const QString &name) 101 | : QFile(name) 102 | { 103 | #ifdef Q_OS_WIN 104 | wmutex = 0; 105 | rmutex = 0; 106 | #endif 107 | m_lock_mode = NoLock; 108 | } 109 | 110 | /*! 111 | Opens the file in OpenMode \a mode. 112 | 113 | This is identical to QFile::open(), with the one exception that the 114 | Truncate mode flag is disallowed. Truncation would conflict with the 115 | advisory file locking, since the file would be modified before the 116 | write lock is obtained. If truncation is required, use resize(0) 117 | after obtaining the write lock. 118 | 119 | Returns true if successful; otherwise false. 120 | 121 | \sa QFile::open(), QFile::resize() 122 | */ 123 | bool QtLockedFile::open(OpenMode mode) 124 | { 125 | if (mode & QIODevice::Truncate) { 126 | qWarning("QtLockedFile::open(): Truncate mode not allowed."); 127 | return false; 128 | } 129 | return QFile::open(mode); 130 | } 131 | 132 | /*! 133 | Returns \e true if this object has a in read or write lock; 134 | otherwise returns \e false. 135 | 136 | \sa lockMode() 137 | */ 138 | bool QtLockedFile::isLocked() const 139 | { 140 | return m_lock_mode != NoLock; 141 | } 142 | 143 | /*! 144 | Returns the type of lock currently held by this object, or \e 145 | QtLockedFile::NoLock. 146 | 147 | \sa isLocked() 148 | */ 149 | QtLockedFile::LockMode QtLockedFile::lockMode() const 150 | { 151 | return m_lock_mode; 152 | } 153 | 154 | /*! 155 | \fn bool QtLockedFile::lock(LockMode mode, bool block = true) 156 | 157 | Obtains a lock of type \a mode. The file must be opened before it 158 | can be locked. 159 | 160 | If \a block is true, this function will block until the lock is 161 | aquired. If \a block is false, this function returns \e false 162 | immediately if the lock cannot be aquired. 163 | 164 | If this object already has a lock of type \a mode, this function 165 | returns \e true immediately. If this object has a lock of a 166 | different type than \a mode, the lock is first released and then a 167 | new lock is obtained. 168 | 169 | This function returns \e true if, after it executes, the file is 170 | locked by this object, and \e false otherwise. 171 | 172 | \sa unlock(), isLocked(), lockMode() 173 | */ 174 | 175 | /*! 176 | \fn bool QtLockedFile::unlock() 177 | 178 | Releases a lock. 179 | 180 | If the object has no lock, this function returns immediately. 181 | 182 | This function returns \e true if, after it executes, the file is 183 | not locked by this object, and \e false otherwise. 184 | 185 | \sa lock(), isLocked(), lockMode() 186 | */ 187 | 188 | /*! 189 | \fn QtLockedFile::~QtLockedFile() 190 | 191 | Destroys the \e QtLockedFile object. If any locks were held, they 192 | are released. 193 | */ 194 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlockedfile_win.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | #include "qtlockedfile.h" 42 | #include 43 | #include 44 | 45 | #define MUTEX_PREFIX "QtLockedFile mutex " 46 | // Maximum number of concurrent read locks. Must not be greater than MAXIMUM_WAIT_OBJECTS 47 | #define MAX_READERS MAXIMUM_WAIT_OBJECTS 48 | 49 | #if QT_VERSION >= 0x050000 50 | #define QT_WA(unicode, ansi) unicode 51 | #endif 52 | 53 | Qt::HANDLE QtLockedFile::getMutexHandle(int idx, bool doCreate) 54 | { 55 | if (mutexname.isEmpty()) { 56 | QFileInfo fi(*this); 57 | mutexname = QString::fromLatin1(MUTEX_PREFIX) 58 | + fi.absoluteFilePath().toLower(); 59 | } 60 | QString mname(mutexname); 61 | if (idx >= 0) 62 | mname += QString::number(idx); 63 | 64 | Qt::HANDLE mutex; 65 | if (doCreate) { 66 | QT_WA( { mutex = CreateMutexW(NULL, FALSE, (TCHAR*)mname.utf16()); }, 67 | { mutex = CreateMutexA(NULL, FALSE, mname.toLocal8Bit().constData()); } ); 68 | if (!mutex) { 69 | qErrnoWarning("QtLockedFile::lock(): CreateMutex failed"); 70 | return 0; 71 | } 72 | } 73 | else { 74 | QT_WA( { mutex = OpenMutexW(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, (TCHAR*)mname.utf16()); }, 75 | { mutex = OpenMutexA(SYNCHRONIZE | MUTEX_MODIFY_STATE, FALSE, mname.toLocal8Bit().constData()); } ); 76 | if (!mutex) { 77 | if (GetLastError() != ERROR_FILE_NOT_FOUND) 78 | qErrnoWarning("QtLockedFile::lock(): OpenMutex failed"); 79 | return 0; 80 | } 81 | } 82 | return mutex; 83 | } 84 | 85 | bool QtLockedFile::waitMutex(Qt::HANDLE mutex, bool doBlock) 86 | { 87 | Q_ASSERT(mutex); 88 | DWORD res = WaitForSingleObject(mutex, doBlock ? INFINITE : 0); 89 | switch (res) { 90 | case WAIT_OBJECT_0: 91 | case WAIT_ABANDONED: 92 | return true; 93 | break; 94 | case WAIT_TIMEOUT: 95 | break; 96 | default: 97 | qErrnoWarning("QtLockedFile::lock(): WaitForSingleObject failed"); 98 | } 99 | return false; 100 | } 101 | 102 | 103 | 104 | bool QtLockedFile::lock(LockMode mode, bool block) 105 | { 106 | if (!isOpen()) { 107 | qWarning("QtLockedFile::lock(): file is not opened"); 108 | return false; 109 | } 110 | 111 | if (mode == NoLock) 112 | return unlock(); 113 | 114 | if (mode == m_lock_mode) 115 | return true; 116 | 117 | if (m_lock_mode != NoLock) 118 | unlock(); 119 | 120 | if (!wmutex && !(wmutex = getMutexHandle(-1, true))) 121 | return false; 122 | 123 | if (!waitMutex(wmutex, block)) 124 | return false; 125 | 126 | if (mode == ReadLock) { 127 | int idx = 0; 128 | for (; idx < MAX_READERS; idx++) { 129 | rmutex = getMutexHandle(idx, false); 130 | if (!rmutex || waitMutex(rmutex, false)) 131 | break; 132 | CloseHandle(rmutex); 133 | } 134 | bool ok = true; 135 | if (idx >= MAX_READERS) { 136 | qWarning("QtLockedFile::lock(): too many readers"); 137 | rmutex = 0; 138 | ok = false; 139 | } 140 | else if (!rmutex) { 141 | rmutex = getMutexHandle(idx, true); 142 | if (!rmutex || !waitMutex(rmutex, false)) 143 | ok = false; 144 | } 145 | if (!ok && rmutex) { 146 | CloseHandle(rmutex); 147 | rmutex = 0; 148 | } 149 | ReleaseMutex(wmutex); 150 | if (!ok) 151 | return false; 152 | } 153 | else { 154 | Q_ASSERT(rmutexes.isEmpty()); 155 | for (int i = 0; i < MAX_READERS; i++) { 156 | Qt::HANDLE mutex = getMutexHandle(i, false); 157 | if (mutex) 158 | rmutexes.append(mutex); 159 | } 160 | if (rmutexes.size()) { 161 | DWORD res = WaitForMultipleObjects(rmutexes.size(), rmutexes.constData(), 162 | TRUE, block ? INFINITE : 0); 163 | if (res != WAIT_OBJECT_0 && res != WAIT_ABANDONED) { 164 | if (res != WAIT_TIMEOUT) 165 | qErrnoWarning("QtLockedFile::lock(): WaitForMultipleObjects failed"); 166 | m_lock_mode = WriteLock; // trick unlock() to clean up - semiyucky 167 | unlock(); 168 | return false; 169 | } 170 | } 171 | } 172 | 173 | m_lock_mode = mode; 174 | return true; 175 | } 176 | 177 | bool QtLockedFile::unlock() 178 | { 179 | if (!isOpen()) { 180 | qWarning("QtLockedFile::unlock(): file is not opened"); 181 | return false; 182 | } 183 | 184 | if (!isLocked()) 185 | return true; 186 | 187 | if (m_lock_mode == ReadLock) { 188 | ReleaseMutex(rmutex); 189 | CloseHandle(rmutex); 190 | rmutex = 0; 191 | } 192 | else { 193 | foreach(Qt::HANDLE mutex, rmutexes) { 194 | ReleaseMutex(mutex); 195 | CloseHandle(mutex); 196 | } 197 | rmutexes.clear(); 198 | ReleaseMutex(wmutex); 199 | } 200 | 201 | m_lock_mode = QtLockedFile::NoLock; 202 | return true; 203 | } 204 | 205 | QtLockedFile::~QtLockedFile() 206 | { 207 | if (isOpen()) 208 | unlock(); 209 | if (wmutex) 210 | CloseHandle(wmutex); 211 | } 212 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtlocalpeer.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | 42 | #include "qtlocalpeer.h" 43 | #include 44 | #include 45 | 46 | #if defined(Q_OS_WIN) 47 | #include 48 | #include 49 | typedef BOOL(WINAPI*PProcessIdToSessionId)(DWORD,DWORD*); 50 | static PProcessIdToSessionId pProcessIdToSessionId = 0; 51 | #endif 52 | #if defined(Q_OS_UNIX) 53 | #include 54 | #include 55 | #include 56 | #endif 57 | 58 | namespace QtLP_Private { 59 | #include "qtlockedfile.cpp" 60 | #if defined(Q_OS_WIN) 61 | #include "qtlockedfile_win.cpp" 62 | #else 63 | #include "qtlockedfile_unix.cpp" 64 | #endif 65 | } 66 | 67 | const char* QtLocalPeer::ack = "ack"; 68 | 69 | QtLocalPeer::QtLocalPeer(QObject* parent, const QString &appId) 70 | : QObject(parent), id(appId) 71 | { 72 | QString prefix = id; 73 | if (id.isEmpty()) { 74 | id = QCoreApplication::applicationFilePath(); 75 | #if defined(Q_OS_WIN) 76 | id = id.toLower(); 77 | #endif 78 | prefix = id.section(QLatin1Char('/'), -1); 79 | } 80 | prefix.remove(QRegExp("[^a-zA-Z]")); 81 | prefix.truncate(6); 82 | 83 | QByteArray idc = id.toUtf8(); 84 | quint16 idNum = qChecksum(idc.constData(), idc.size()); 85 | socketName = QLatin1String("qtsingleapp-") + prefix 86 | + QLatin1Char('-') + QString::number(idNum, 16); 87 | 88 | #if defined(Q_OS_WIN) 89 | if (!pProcessIdToSessionId) { 90 | QLibrary lib("kernel32"); 91 | pProcessIdToSessionId = (PProcessIdToSessionId)lib.resolve("ProcessIdToSessionId"); 92 | } 93 | if (pProcessIdToSessionId) { 94 | DWORD sessionId = 0; 95 | pProcessIdToSessionId(GetCurrentProcessId(), &sessionId); 96 | socketName += QLatin1Char('-') + QString::number(sessionId, 16); 97 | } 98 | #else 99 | socketName += QLatin1Char('-') + QString::number(::getuid(), 16); 100 | #endif 101 | 102 | server = new QLocalServer(this); 103 | QString lockName = QDir(QDir::tempPath()).absolutePath() 104 | + QLatin1Char('/') + socketName 105 | + QLatin1String("-lockfile"); 106 | lockFile.setFileName(lockName); 107 | lockFile.open(QIODevice::ReadWrite); 108 | } 109 | 110 | 111 | 112 | bool QtLocalPeer::isClient() 113 | { 114 | if (lockFile.isLocked()) 115 | return false; 116 | 117 | if (!lockFile.lock(QtLP_Private::QtLockedFile::WriteLock, false)) 118 | return true; 119 | 120 | bool res = server->listen(socketName); 121 | #if defined(Q_OS_UNIX) && (QT_VERSION >= QT_VERSION_CHECK(4,5,0)) 122 | // ### Workaround 123 | if (!res && server->serverError() == QAbstractSocket::AddressInUseError) { 124 | QFile::remove(QDir::cleanPath(QDir::tempPath())+QLatin1Char('/')+socketName); 125 | res = server->listen(socketName); 126 | } 127 | #endif 128 | if (!res) 129 | qWarning("QtSingleCoreApplication: listen on local socket failed, %s", qPrintable(server->errorString())); 130 | QObject::connect(server, SIGNAL(newConnection()), SLOT(receiveConnection())); 131 | return false; 132 | } 133 | 134 | 135 | bool QtLocalPeer::sendMessage(const QString &message, int timeout) 136 | { 137 | if (!isClient()) 138 | return false; 139 | 140 | QLocalSocket socket; 141 | bool connOk = false; 142 | for(int i = 0; i < 2; i++) { 143 | // Try twice, in case the other instance is just starting up 144 | socket.connectToServer(socketName); 145 | connOk = socket.waitForConnected(timeout/2); 146 | if (connOk || i) 147 | break; 148 | int ms = 250; 149 | #if defined(Q_OS_WIN) 150 | Sleep(DWORD(ms)); 151 | #else 152 | struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; 153 | nanosleep(&ts, NULL); 154 | #endif 155 | } 156 | if (!connOk) 157 | return false; 158 | 159 | QByteArray uMsg(message.toUtf8()); 160 | QDataStream ds(&socket); 161 | ds.writeBytes(uMsg.constData(), uMsg.size()); 162 | bool res = socket.waitForBytesWritten(timeout); 163 | if (res) { 164 | res &= socket.waitForReadyRead(timeout); // wait for ack 165 | if (res) 166 | res &= (socket.read(qstrlen(ack)) == ack); 167 | } 168 | return res; 169 | } 170 | 171 | 172 | void QtLocalPeer::receiveConnection() 173 | { 174 | QLocalSocket* socket = server->nextPendingConnection(); 175 | if (!socket) 176 | return; 177 | 178 | while (socket->bytesAvailable() < (int)sizeof(quint32)) 179 | socket->waitForReadyRead(); 180 | QDataStream ds(socket); 181 | QByteArray uMsg; 182 | quint32 remaining; 183 | ds >> remaining; 184 | uMsg.resize(remaining); 185 | int got = 0; 186 | char* uMsgBuf = uMsg.data(); 187 | do { 188 | got = ds.readRawData(uMsgBuf, remaining); 189 | remaining -= got; 190 | uMsgBuf += got; 191 | } while (remaining && got >= 0 && socket->waitForReadyRead(2000)); 192 | if (got < 0) { 193 | qWarning("QtLocalPeer: Message reception failed %s", socket->errorString().toLatin1().constData()); 194 | delete socket; 195 | return; 196 | } 197 | QString message(QString::fromUtf8(uMsg)); 198 | socket->write(ack, qstrlen(ack)); 199 | socket->waitForBytesWritten(1000); 200 | socket->waitForDisconnected(1000); // make sure client reads ack 201 | delete socket; 202 | emit messageReceived(message); //### (might take a long time to return) 203 | } 204 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/INSTALL.TXT: -------------------------------------------------------------------------------- 1 | INSTALLATION INSTRUCTIONS 2 | 3 | These instructions refer to the package you are installing as 4 | some-package.tar.gz or some-package.zip. The .zip file is intended for use 5 | on Windows. 6 | 7 | The directory you choose for the installation will be referred to as 8 | your-install-dir. 9 | 10 | Note to Qt Visual Studio Integration users: In the instructions below, 11 | instead of building from command line with nmake, you can use the menu 12 | command 'Qt->Open Solution from .pro file' on the .pro files in the 13 | example and plugin directories, and then build from within Visual 14 | Studio. 15 | 16 | Unpacking and installation 17 | -------------------------- 18 | 19 | 1. Unpacking the archive (if you have not done so already). 20 | 21 | On Unix and Mac OS X (in a terminal window): 22 | 23 | cd your-install-dir 24 | gunzip some-package.tar.gz 25 | tar xvf some-package.tar 26 | 27 | This creates the subdirectory some-package containing the files. 28 | 29 | On Windows: 30 | 31 | Unpack the .zip archive by right-clicking it in explorer and 32 | choosing "Extract All...". If your version of Windows does not 33 | have zip support, you can use the infozip tools available 34 | from www.info-zip.org. 35 | 36 | If you are using the infozip tools (in a command prompt window): 37 | cd your-install-dir 38 | unzip some-package.zip 39 | 40 | 2. Configuring the package. 41 | 42 | The configure script is called "configure" on unix/mac and 43 | "configure.bat" on Windows. It should be run from a command line 44 | after cd'ing to the package directory. 45 | 46 | You can choose whether you want to use the component by including 47 | its source code directly into your project, or build the component 48 | as a dynamic shared library (DLL) that is loaded into the 49 | application at run-time. The latter may be preferable for 50 | technical or licensing (LGPL) reasons. If you want to build a DLL, 51 | run the configure script with the argument "-library". Also see 52 | the note about usage below. 53 | 54 | (Components that are Qt plugins, e.g. styles and image formats, 55 | are by default built as a plugin DLL.) 56 | 57 | The configure script will prompt you in some cases for further 58 | information. Answer these questions and carefully read the license text 59 | before accepting the license conditions. The package cannot be used if 60 | you do not accept the license conditions. 61 | 62 | 3. Building the component and examples (when required). 63 | 64 | If a DLL is to be built, or if you would like to build the 65 | examples, next give the commands 66 | 67 | qmake 68 | make [or nmake if your are using Microsoft Visual C++] 69 | 70 | The example program(s) can be found in the directory called 71 | "examples" or "example". 72 | 73 | Components that are Qt plugins, e.g. styles and image formats, are 74 | ready to be used as soon as they are built, so the rest of this 75 | installation instruction can be skipped. 76 | 77 | 4. Building the Qt Designer plugin (optional). 78 | 79 | Some of the widget components are provided with plugins for Qt 80 | Designer. To build and install the plugin, cd into the 81 | some-package/plugin directory and give the commands 82 | 83 | qmake 84 | make [or nmake if your are using Microsoft Visual C++] 85 | 86 | Restart Qt Designer to make it load the new widget plugin. 87 | 88 | Note: If you are using the built-in Qt Designer from the Qt Visual 89 | Studio Integration, you will need to manually copy the plugin DLL 90 | file, i.e. copy 91 | %QTDIR%\plugins\designer\some-component.dll 92 | to the Qt Visual Studio Integration plugin path, typically: 93 | C:\Program Files\Trolltech\Qt VS Integration\plugins 94 | 95 | Note: If you for some reason are using a Qt Designer that is built 96 | in debug mode, you will need to build the plugin in debug mode 97 | also. Edit the file plugin.pro in the plugin directory, changing 98 | 'release' to 'debug' in the CONFIG line, before running qmake. 99 | 100 | 101 | 102 | Solutions components are intended to be used directly from the package 103 | directory during development, so there is no 'make install' procedure. 104 | 105 | 106 | Using a component in your project 107 | --------------------------------- 108 | 109 | To use this component in your project, add the following line to the 110 | project's .pro file (or do the equivalent in your IDE): 111 | 112 | include(your-install-dir/some-package/src/some-package.pri) 113 | 114 | This adds the package's sources and headers to the SOURCES and HEADERS 115 | project variables respectively (or, if the component has been 116 | configured as a DLL, it adds that library to the LIBS variable), and 117 | updates INCLUDEPATH to contain the package's src 118 | directory. Additionally, the .pri file may include some dependencies 119 | needed by the package. 120 | 121 | To include a header file from the package in your sources, you can now 122 | simply use: 123 | 124 | #include 125 | 126 | or alternatively, in pre-Qt 4 style: 127 | 128 | #include 129 | 130 | Refer to the documentation to see the classes and headers this 131 | components provides. 132 | 133 | 134 | 135 | Install documentation (optional) 136 | -------------------------------- 137 | 138 | The HTML documentation for the package's classes is located in the 139 | your-install-dir/some-package/doc/html/index.html. You can open this 140 | file and read the documentation with any web browser. 141 | 142 | To install the documentation into Qt Assistant (for Qt version 4.4 and 143 | later): 144 | 145 | 1. In Assistant, open the Edit->Preferences dialog and choose the 146 | Documentation tab. Click the Add... button and select the file 147 | your-install-dir/some-package/doc/html/some-package.qch 148 | 149 | For Qt versions prior to 4.4, do instead the following: 150 | 151 | 1. The directory your-install-dir/some-package/doc/html contains a 152 | file called some-package.dcf. Execute the following commands in a 153 | shell, command prompt or terminal window: 154 | 155 | cd your-install-dir/some-package/doc/html/ 156 | assistant -addContentFile some-package.dcf 157 | 158 | The next time you start Qt Assistant, you can access the package's 159 | documentation. 160 | 161 | 162 | Removing the documentation from assistant 163 | ----------------------------------------- 164 | 165 | If you have installed the documentation into Qt Assistant, and want to uninstall it, do as follows, for Qt version 4.4 and later: 166 | 167 | 1. In Assistant, open the Edit->Preferences dialog and choose the 168 | Documentation tab. In the list of Registered Documentation, select 169 | the item com.nokia.qtsolutions.some-package_version, and click 170 | the Remove button. 171 | 172 | For Qt versions prior to 4.4, do instead the following: 173 | 174 | 1. The directory your-install-dir/some-package/doc/html contains a 175 | file called some-package.dcf. Execute the following commands in a 176 | shell, command prompt or terminal window: 177 | 178 | cd your-install-dir/some-package/doc/html/ 179 | assistant -removeContentFile some-package.dcf 180 | 181 | 182 | 183 | Using the component as a DLL 184 | ---------------------------- 185 | 186 | 1. Normal components 187 | 188 | The shared library (DLL) is built and placed in the 189 | some-package/lib directory. It is intended to be used directly 190 | from there during development. When appropriate, both debug and 191 | release versions are built, since the run-time linker will in some 192 | cases refuse to load a debug-built DLL into a release-built 193 | application or vice versa. 194 | 195 | The following steps are taken by default to help the dynamic 196 | linker to locate the DLL at run-time (during development): 197 | 198 | Unix: The some-package.pri file will add linker instructions to 199 | add the some-package/lib directory to the rpath of the 200 | executable. (When distributing, or if your system does not support 201 | rpath, you can copy the shared library to another place that is 202 | searched by the dynamic linker, e.g. the "lib" directory of your 203 | Qt installation.) 204 | 205 | Mac: The full path to the library is hardcoded into the library 206 | itself, from where it is copied into the executable at link time, 207 | and ready by the dynamic linker at run-time. (When distributing, 208 | you will want to edit these hardcoded paths in the same way as for 209 | the Qt DLLs. Refer to the document "Deploying an Application on 210 | Mac OS X" in the Qt Reference Documentation.) 211 | 212 | Windows: the .dll file(s) are copied into the "bin" directory of 213 | your Qt installation. The Qt installation will already have set up 214 | that directory to be searched by the dynamic linker. 215 | 216 | 217 | 2. Plugins 218 | 219 | For Qt Solutions plugins (e.g. image formats), both debug and 220 | release versions of the plugin are built by default when 221 | appropriate, since in some cases the release Qt library will not 222 | load a debug plugin, and vice versa. The plugins are automatically 223 | copied into the plugins directory of your Qt installation when 224 | built, so no further setup is required. 225 | 226 | Plugins may also be built statically, i.e. as a library that will be 227 | linked into your application executable, and so will not need to 228 | be redistributed as a separate plugin DLL to end users. Static 229 | building is required if Qt itself is built statically. To do it, 230 | just add "static" to the CONFIG variable in the plugin/plugin.pro 231 | file before building. Refer to the "Static Plugins" section in the 232 | chapter "How to Create Qt Plugins" for explanation of how to use a 233 | static plugin in your application. The source code of the example 234 | program(s) will also typically contain the relevant instructions 235 | as comments. 236 | 237 | 238 | 239 | Uninstalling 240 | ------------ 241 | 242 | The following command will remove any fils that have been 243 | automatically placed outside the package directory itself during 244 | installation and building 245 | 246 | make distclean [or nmake if your are using Microsoft Visual C++] 247 | 248 | If Qt Assistant documentation or Qt Designer plugins have been 249 | installed, they can be uninstalled manually, ref. above. 250 | 251 | 252 | Enjoy! :) 253 | 254 | - The Qt Solutions Team. 255 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/PaintView.cpp: -------------------------------------------------------------------------------- 1 | #include "PaintView.h" 2 | #define VIEW_CENTER viewport()->rect().center() 3 | #define VIEW_WIDTH viewport()->rect().width() 4 | #define VIEW_HEIGHT viewport()->rect().height() 5 | PaintView::PaintView(QWidget *parent) : 6 | QGraphicsView(parent) 7 | { 8 | _zoomDelta=0.1; // 缩放的增量 9 | _scaleValue=1.0; 10 | _bMouseTranslate=false; 11 | _translateSpeed=1.0; 12 | 13 | this->setRenderHint(QPainter::Antialiasing); 14 | 15 | 16 | } 17 | 18 | PaintView::~PaintView() 19 | { 20 | 21 | } 22 | void PaintView::ZoomIn() 23 | { 24 | zoom(1 + _zoomDelta); 25 | } 26 | 27 | // 缩小 28 | void PaintView::ZoomOut() 29 | { 30 | zoom(1 - _zoomDelta); 31 | } 32 | void PaintView::zoom(float scaleFactor) 33 | { 34 | // 防止过小或过大 35 | qreal factor = transform().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)).width(); 36 | if (factor < 0.07 || factor > 100) 37 | return; 38 | 39 | scale(scaleFactor, scaleFactor); 40 | _scaleValue *= scaleFactor; 41 | } 42 | 43 | void PaintView::wheelEvent(QWheelEvent *event) 44 | { 45 | // 滚轮的滚动量 46 | QPoint scrollAmount = event->angleDelta(); 47 | // 正值表示滚轮远离使用者(放大),负值表示朝向使用者(缩小) 48 | scrollAmount.y() > 0 ? ZoomIn() :ZoomOut(); 49 | } 50 | 51 | void PaintView::paintEvent(QPaintEvent *event) 52 | { 53 | QGraphicsView::paintEvent(event); 54 | QPainter painter(this->viewport()); 55 | painter.setBrush(Qt::gray); 56 | QFont font; 57 | font.setPixelSize(45); 58 | painter.setFont(font); 59 | //painter.drawb(QRectF(width()*0.3,height()*0.2,width()*0.3,height()*0.3),"made by andy!"); 60 | 61 | } 62 | // 平移 63 | void PaintView::mouseMoveEvent(QMouseEvent *event) 64 | { 65 | if (_bMouseTranslate){ 66 | QPointF mouseDelta = mapToScene(event->pos()) - mapToScene(_lastMousePos); 67 | translate(mouseDelta); 68 | } 69 | 70 | _lastMousePos = event->pos(); 71 | 72 | QGraphicsView::mouseMoveEvent(event); 73 | } 74 | 75 | void PaintView::mousePressEvent(QMouseEvent *event) 76 | { 77 | if (event->button() == _translateButton) { 78 | // 当光标底下没有 item 时,才能移动 79 | QPointF point = mapToScene(event->pos()); 80 | if (scene()->itemAt(point, transform()) == NULL) { 81 | _bMouseTranslate = true; 82 | _lastMousePos = event->pos(); 83 | } 84 | } 85 | 86 | QGraphicsView::mousePressEvent(event); 87 | } 88 | 89 | void PaintView::onAssemblageAction(bool) 90 | { 91 | QList selectItems=this->scene()->selectedItems(); 92 | QGraphicsItemGroup * groupItems =this->scene()->createItemGroup(selectItems); 93 | QRectF rect =groupItems->boundingRect(); 94 | 95 | QGraphicsScene *scene =new QGraphicsScene(); 96 | scene->setSceneRect(rect); 97 | for(int i=0; i(selectItems[i]); 100 | scene->addItem(sp); 101 | } 102 | scene->clearSelection(); 103 | QImage image(rect.width(),rect.height(),QImage::Format_ARGB32); 104 | image.fill(Qt::transparent);//用透明色填充 105 | QString pngName = "D:/scene44test.png"; 106 | QPainter painter(&image); 107 | painter.setRenderHint(QPainter::Antialiasing); 108 | scene->render(&painter); 109 | bool saveSuccess = image.save(pngName); 110 | 111 | for(int i=0; i(selectItems[i]); 114 | this->scene()->addItem(sp); 115 | } 116 | if (!saveSuccess) 117 | { 118 | QMessageBox::about(NULL,"","组合图元失败!"); 119 | } 120 | else 121 | QMessageBox::about(NULL,"","组合图元成功!"); 122 | 123 | SafeDelete(scene); 124 | } 125 | void PaintView::onRotation1Action(bool) 126 | { 127 | QList< QGraphicsItem*> selectItems=this->scene()->selectedItems(); 128 | int selectItemsCount =selectItems.count(); 129 | 130 | for(int i=0; iboundingRect().center() ; 134 | selectItems[i]->setTransformOriginPoint(centerPos); 135 | selectItems[i]->setRotation(selectItems[i]->rotation()+30); 136 | } 137 | } 138 | void PaintView::onRotation2Action(bool) 139 | { 140 | QList selectItems=this->scene()->selectedItems(); 141 | int selectItemsCount =selectItems.count(); 142 | 143 | for(int i=0; iboundingRect().center() ; 147 | selectItems[i]->setTransformOriginPoint(centerPos); 148 | selectItems[i]->setRotation(selectItems[i]->rotation()-30); 149 | } 150 | } 151 | void PaintView::onDeleteAction(bool) 152 | { 153 | QList selectItems=this->scene()->selectedItems(); 154 | int selectItemsCount =selectItems.count(); 155 | 156 | 157 | for(int i=0; iscene()->removeItem(selectItems[i]); 160 | } 161 | } 162 | void PaintView::contextMenuEvent(QContextMenuEvent *event) 163 | { 164 | QList selectItems=this->scene()->selectedItems(); 165 | int selectItemsCount =selectItems.count(); 166 | QMenu menu; 167 | QMimeData * mp = const_cast(QApplication::clipboard()->mimeData()) ; 168 | ShapeMimeData * data = dynamic_cast< ShapeMimeData*>( mp ); 169 | if ( data ){ 170 | QAction * pasteAction = menu.addAction("粘贴图元"); 171 | connect(pasteAction,SIGNAL(triggered()),this,SLOT(on_paste)); 172 | } 173 | if(selectItemsCount >0) 174 | { 175 | QAction * copyAction = menu.addAction("复制图元(+30)"); 176 | connect(copyAction,SIGNAL(triggered()),this,SLOT(on_copy)); 177 | QAction * cutAction = menu.addAction("剪切图元"); 178 | connect(cutAction,SIGNAL(triggered()),this,SLOT(on_cut)); 179 | if(selectItemsCount >1) 180 | { 181 | QAction *assemblageAction = menu.addAction("组合图元"); 182 | connect(assemblageAction, SIGNAL(triggered(bool)), 183 | this,SLOT(onAssemblageAction(bool))); 184 | } 185 | QAction * rotation1Action = menu.addAction("旋转图元(+30)"); 186 | connect(rotation1Action, SIGNAL(triggered(bool)), 187 | this,SLOT(onRotation1Action(bool))); 188 | QAction *rotation2Action = menu.addAction("旋转图元(-30)"); 189 | connect(rotation2Action, SIGNAL(triggered(bool)), 190 | this,SLOT(onRotation2Action(bool))); 191 | QAction *deleteAction = menu.addAction("删除图元"); 192 | connect(deleteAction, SIGNAL(triggered(bool)), 193 | this,SLOT(onDeleteAction(bool))); 194 | } 195 | 196 | menu.exec(event->globalPos()); 197 | 198 | } 199 | 200 | void PaintView::on_copy() 201 | { 202 | 203 | ShapeMimeData * data = new ShapeMimeData( this->scene()->selectedItems() ); 204 | QApplication::clipboard()->setMimeData(data); 205 | } 206 | 207 | void PaintView::on_paste() 208 | { 209 | 210 | } 211 | 212 | void PaintView::on_cut() 213 | { 214 | 215 | } 216 | void PaintView::mouseReleaseEvent(QMouseEvent *event) 217 | { 218 | if (event->button() == _translateButton) 219 | _bMouseTranslate = false; 220 | 221 | QGraphicsView::mouseReleaseEvent(event); 222 | } 223 | 224 | void PaintView::resizeEvent(QResizeEvent *event) 225 | { 226 | this->scene()->setSceneRect(this->rect()); 227 | } 228 | void PaintView::translate(QPointF delta) 229 | { 230 | // 根据当前 zoom 缩放平移数 231 | delta *= _scaleValue; 232 | delta *= _translateSpeed; 233 | 234 | // view 根据鼠标下的点作为锚点来定位 scene 235 | setTransformationAnchor(QGraphicsView::AnchorUnderMouse); 236 | QPoint newCenter(VIEW_WIDTH / 2 - delta.x(), VIEW_HEIGHT / 2 - delta.y()); 237 | centerOn(mapToScene(newCenter)); 238 | 239 | // scene 在 view 的中心点作为锚点 240 | setTransformationAnchor(QGraphicsView::AnchorViewCenter); 241 | } 242 | 243 | 244 | void PaintView::keyPressEvent(QKeyEvent *event) 245 | { 246 | QList selectItems=this->scene()->selectedItems(); 247 | int selectItemsCount =selectItems.count(); 248 | switch (event->key()) { 249 | 250 | case Qt::Key_Up: 251 | if(selectItemsCount==0) 252 | translate(QPointF(0, -2)); // 上移 253 | else 254 | { 255 | for(int i=0; isetPos(selectItems[i]->pos().rx(),selectItems[i]->pos().ry()-1); 258 | } 259 | } 260 | 261 | break; 262 | case Qt::Key_Down: 263 | if(selectItemsCount==0) 264 | translate(QPointF(0, 2)); // 下移 265 | else 266 | { 267 | for(int i=0; isetPos(selectItems[i]->pos().rx(),selectItems[i]->pos().ry()+1); 270 | } 271 | } 272 | 273 | break; 274 | case Qt::Key_Left: 275 | if(selectItemsCount==0) 276 | translate(QPointF(-2, 0)); // 左移 277 | else 278 | { 279 | for(int i=0; isetPos(selectItems[i]->pos().rx()-1,selectItems[i]->pos().ry()); 282 | } 283 | } 284 | break; 285 | case Qt::Key_Right: 286 | if(selectItemsCount==0) 287 | translate(QPointF(2, 0)); // 左移 288 | else 289 | { 290 | for(int i=0; isetPos(selectItems[i]->pos().rx()+1,selectItems[i]->pos().ry()); 293 | } 294 | } 295 | break; 296 | case Qt::Key_Plus: // 放大 297 | if(selectItemsCount==0) 298 | ZoomIn(); 299 | else 300 | { 301 | for(int i=0; iscale()+0.2; 304 | if(scaleSize>20) scaleSize=20; 305 | QPointF centerPos= selectItems[i]->boundingRect().center() ; 306 | selectItems[i]->setTransformOriginPoint(centerPos); 307 | selectItems[i]->setScale(scaleSize); 308 | } 309 | } 310 | break; 311 | case Qt::Key_Minus: // 缩小 312 | if(selectItemsCount==0) 313 | ZoomOut(); 314 | else 315 | { 316 | for(int i=0; iscale()-0.2; 319 | if(scaleSize<0.05) scaleSize=0.05; 320 | QPointF centerPos= selectItems[i]->boundingRect().center() ; 321 | selectItems[i]->setTransformOriginPoint(centerPos); 322 | selectItems[i]->setScale(scaleSize); 323 | } 324 | } 325 | break; 326 | case Qt::Key_Space: // 逆时针旋转 327 | if(selectItemsCount==0) 328 | rotate(-90); 329 | else 330 | { 331 | for(int i=0; iboundingRect().center() ; 335 | selectItems[i]->setTransformOriginPoint(centerPos); 336 | selectItems[i]->setRotation(selectItems[i]->rotation()-1); 337 | } 338 | } 339 | break; 340 | case Qt::Key_Enter: // 顺时针旋转 341 | case Qt::Key_Return: 342 | if(selectItemsCount==0) 343 | rotate(90); 344 | else 345 | { 346 | for(int i=0; iboundingRect().center() ; 350 | selectItems[i]->setTransformOriginPoint(centerPos); 351 | selectItems[i]->setRotation(selectItems[i]->rotation()+1); 352 | } 353 | } 354 | break; 355 | default: 356 | QGraphicsView::keyPressEvent(event); 357 | } 358 | } 359 | void PaintView::SetTranslateSpeed(qreal speed) 360 | { 361 | // 建议速度范围 362 | Q_ASSERT_X(speed >= 0.0 && speed <= 5.0, 363 | "InteractiveView::setTranslateSpeed", "Speed should be in range [0.0,5.0]."); 364 | _translateSpeed = speed; 365 | } 366 | -------------------------------------------------------------------------------- /GradeSystem/qtsingleapplication/qtsingleapplication.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). 4 | ** Contact: http://www.qt-project.org/legal 5 | ** 6 | ** This file is part of the Qt Solutions component. 7 | ** 8 | ** $QT_BEGIN_LICENSE:BSD$ 9 | ** You may use this file under the terms of the BSD license as follows: 10 | ** 11 | ** "Redistribution and use in source and binary forms, with or without 12 | ** modification, are permitted provided that the following conditions are 13 | ** met: 14 | ** * Redistributions of source code must retain the above copyright 15 | ** notice, this list of conditions and the following disclaimer. 16 | ** * Redistributions in binary form must reproduce the above copyright 17 | ** notice, this list of conditions and the following disclaimer in 18 | ** the documentation and/or other materials provided with the 19 | ** distribution. 20 | ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names 21 | ** of its contributors may be used to endorse or promote products derived 22 | ** from this software without specific prior written permission. 23 | ** 24 | ** 25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 36 | ** 37 | ** $QT_END_LICENSE$ 38 | ** 39 | ****************************************************************************/ 40 | 41 | 42 | #include "qtsingleapplication.h" 43 | #include "qtlocalpeer.h" 44 | #include 45 | 46 | 47 | /*! 48 | \class QtSingleApplication qtsingleapplication.h 49 | \brief The QtSingleApplication class provides an API to detect and 50 | communicate with running instances of an application. 51 | 52 | This class allows you to create applications where only one 53 | instance should be running at a time. I.e., if the user tries to 54 | launch another instance, the already running instance will be 55 | activated instead. Another usecase is a client-server system, 56 | where the first started instance will assume the role of server, 57 | and the later instances will act as clients of that server. 58 | 59 | By default, the full path of the executable file is used to 60 | determine whether two processes are instances of the same 61 | application. You can also provide an explicit identifier string 62 | that will be compared instead. 63 | 64 | The application should create the QtSingleApplication object early 65 | in the startup phase, and call isRunning() to find out if another 66 | instance of this application is already running. If isRunning() 67 | returns false, it means that no other instance is running, and 68 | this instance has assumed the role as the running instance. In 69 | this case, the application should continue with the initialization 70 | of the application user interface before entering the event loop 71 | with exec(), as normal. 72 | 73 | The messageReceived() signal will be emitted when the running 74 | application receives messages from another instance of the same 75 | application. When a message is received it might be helpful to the 76 | user to raise the application so that it becomes visible. To 77 | facilitate this, QtSingleApplication provides the 78 | setActivationWindow() function and the activateWindow() slot. 79 | 80 | If isRunning() returns true, another instance is already 81 | running. It may be alerted to the fact that another instance has 82 | started by using the sendMessage() function. Also data such as 83 | startup parameters (e.g. the name of the file the user wanted this 84 | new instance to open) can be passed to the running instance with 85 | this function. Then, the application should terminate (or enter 86 | client mode). 87 | 88 | If isRunning() returns true, but sendMessage() fails, that is an 89 | indication that the running instance is frozen. 90 | 91 | Here's an example that shows how to convert an existing 92 | application to use QtSingleApplication. It is very simple and does 93 | not make use of all QtSingleApplication's functionality (see the 94 | examples for that). 95 | 96 | \code 97 | // Original 98 | int main(int argc, char **argv) 99 | { 100 | QApplication app(argc, argv); 101 | 102 | MyMainWidget mmw; 103 | mmw.show(); 104 | return app.exec(); 105 | } 106 | 107 | // Single instance 108 | int main(int argc, char **argv) 109 | { 110 | QtSingleApplication app(argc, argv); 111 | 112 | if (app.isRunning()) 113 | return !app.sendMessage(someDataString); 114 | 115 | MyMainWidget mmw; 116 | app.setActivationWindow(&mmw); 117 | mmw.show(); 118 | return app.exec(); 119 | } 120 | \endcode 121 | 122 | Once this QtSingleApplication instance is destroyed (normally when 123 | the process exits or crashes), when the user next attempts to run the 124 | application this instance will not, of course, be encountered. The 125 | next instance to call isRunning() or sendMessage() will assume the 126 | role as the new running instance. 127 | 128 | For console (non-GUI) applications, QtSingleCoreApplication may be 129 | used instead of this class, to avoid the dependency on the QtGui 130 | library. 131 | 132 | \sa QtSingleCoreApplication 133 | */ 134 | 135 | 136 | void QtSingleApplication::sysInit(const QString &appId) 137 | { 138 | actWin = 0; 139 | peer = new QtLocalPeer(this, appId); 140 | connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&))); 141 | } 142 | 143 | 144 | /*! 145 | Creates a QtSingleApplication object. The application identifier 146 | will be QCoreApplication::applicationFilePath(). \a argc, \a 147 | argv, and \a GUIenabled are passed on to the QAppliation constructor. 148 | 149 | If you are creating a console application (i.e. setting \a 150 | GUIenabled to false), you may consider using 151 | QtSingleCoreApplication instead. 152 | */ 153 | 154 | QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled) 155 | : QApplication(argc, argv, GUIenabled) 156 | { 157 | sysInit(); 158 | } 159 | 160 | 161 | /*! 162 | Creates a QtSingleApplication object with the application 163 | identifier \a appId. \a argc and \a argv are passed on to the 164 | QAppliation constructor. 165 | */ 166 | 167 | QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv) 168 | : QApplication(argc, argv) 169 | { 170 | sysInit(appId); 171 | } 172 | 173 | #if QT_VERSION < 0x050000 174 | 175 | /*! 176 | Creates a QtSingleApplication object. The application identifier 177 | will be QCoreApplication::applicationFilePath(). \a argc, \a 178 | argv, and \a type are passed on to the QAppliation constructor. 179 | */ 180 | QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type) 181 | : QApplication(argc, argv, type) 182 | { 183 | sysInit(); 184 | } 185 | 186 | 187 | # if defined(Q_WS_X11) 188 | /*! 189 | Special constructor for X11, ref. the documentation of 190 | QApplication's corresponding constructor. The application identifier 191 | will be QCoreApplication::applicationFilePath(). \a dpy, \a visual, 192 | and \a cmap are passed on to the QApplication constructor. 193 | */ 194 | QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap) 195 | : QApplication(dpy, visual, cmap) 196 | { 197 | sysInit(); 198 | } 199 | 200 | /*! 201 | Special constructor for X11, ref. the documentation of 202 | QApplication's corresponding constructor. The application identifier 203 | will be QCoreApplication::applicationFilePath(). \a dpy, \a argc, \a 204 | argv, \a visual, and \a cmap are passed on to the QApplication 205 | constructor. 206 | */ 207 | QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) 208 | : QApplication(dpy, argc, argv, visual, cmap) 209 | { 210 | sysInit(); 211 | } 212 | 213 | /*! 214 | Special constructor for X11, ref. the documentation of 215 | QApplication's corresponding constructor. The application identifier 216 | will be \a appId. \a dpy, \a argc, \a 217 | argv, \a visual, and \a cmap are passed on to the QApplication 218 | constructor. 219 | */ 220 | QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap) 221 | : QApplication(dpy, argc, argv, visual, cmap) 222 | { 223 | sysInit(appId); 224 | } 225 | # endif // Q_WS_X11 226 | #endif // QT_VERSION < 0x050000 227 | 228 | 229 | /*! 230 | Returns true if another instance of this application is running; 231 | otherwise false. 232 | 233 | This function does not find instances of this application that are 234 | being run by a different user (on Windows: that are running in 235 | another session). 236 | 237 | \sa sendMessage() 238 | */ 239 | 240 | bool QtSingleApplication::isRunning() 241 | { 242 | return peer->isClient(); 243 | } 244 | 245 | 246 | /*! 247 | Tries to send the text \a message to the currently running 248 | instance. The QtSingleApplication object in the running instance 249 | will emit the messageReceived() signal when it receives the 250 | message. 251 | 252 | This function returns true if the message has been sent to, and 253 | processed by, the current instance. If there is no instance 254 | currently running, or if the running instance fails to process the 255 | message within \a timeout milliseconds, this function return false. 256 | 257 | \sa isRunning(), messageReceived() 258 | */ 259 | bool QtSingleApplication::sendMessage(const QString &message, int timeout) 260 | { 261 | return peer->sendMessage(message, timeout); 262 | } 263 | 264 | 265 | /*! 266 | Returns the application identifier. Two processes with the same 267 | identifier will be regarded as instances of the same application. 268 | */ 269 | QString QtSingleApplication::id() const 270 | { 271 | return peer->applicationId(); 272 | } 273 | 274 | 275 | /*! 276 | Sets the activation window of this application to \a aw. The 277 | activation window is the widget that will be activated by 278 | activateWindow(). This is typically the application's main window. 279 | 280 | If \a activateOnMessage is true (the default), the window will be 281 | activated automatically every time a message is received, just prior 282 | to the messageReceived() signal being emitted. 283 | 284 | \sa activateWindow(), messageReceived() 285 | */ 286 | 287 | void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage) 288 | { 289 | actWin = aw; 290 | if (activateOnMessage) 291 | connect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); 292 | else 293 | disconnect(peer, SIGNAL(messageReceived(const QString&)), this, SLOT(activateWindow())); 294 | } 295 | 296 | 297 | /*! 298 | Returns the applications activation window if one has been set by 299 | calling setActivationWindow(), otherwise returns 0. 300 | 301 | \sa setActivationWindow() 302 | */ 303 | QWidget* QtSingleApplication::activationWindow() const 304 | { 305 | return actWin; 306 | } 307 | 308 | 309 | /*! 310 | De-minimizes, raises, and activates this application's activation window. 311 | This function does nothing if no activation window has been set. 312 | 313 | This is a convenience function to show the user that this 314 | application instance has been activated when he has tried to start 315 | another instance. 316 | 317 | This function should typically be called in response to the 318 | messageReceived() signal. By default, that will happen 319 | automatically, if an activation window has been set. 320 | 321 | \sa setActivationWindow(), messageReceived(), initialize() 322 | */ 323 | void QtSingleApplication::activateWindow() 324 | { 325 | if (actWin) { 326 | actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized); 327 | actWin->raise(); 328 | actWin->activateWindow(); 329 | } 330 | } 331 | 332 | 333 | /*! 334 | \fn void QtSingleApplication::messageReceived(const QString& message) 335 | 336 | This signal is emitted when the current instance receives a \a 337 | message from another instance of this application. 338 | 339 | \sa sendMessage(), setActivationWindow(), activateWindow() 340 | */ 341 | 342 | 343 | /*! 344 | \fn void QtSingleApplication::initialize(bool dummy = true) 345 | 346 | \obsolete 347 | */ 348 | -------------------------------------------------------------------------------- /GradeSystem/UI/GradeGraphics/drawtool.cpp: -------------------------------------------------------------------------------- 1 | #include "drawtool.h" 2 | #include "GraphicsEllipseItem.h" 3 | #include "GraphicsTextItem.h" 4 | #include "GraphicsLineItem.h" 5 | #include "GraphicsTriangleItem.h" 6 | #define PI 3.14 7 | 8 | QList DrawTool::c_tools; 9 | QPointF DrawTool::c_down; 10 | QPointF DrawTool::c_last; 11 | quint32 DrawTool::c_nDownFlags; 12 | 13 | DrawBaseShape DrawTool::c_drawShape = selection; 14 | 15 | static SelectTool selectTool; 16 | static PenPathTool penPathTool(penPath); 17 | static LineTool lineTool(line); 18 | static ImageTool imageTool(image); 19 | static RectTool rectTool(rectangle); 20 | static RectTool triangleTool(triangle); 21 | static RectTool roundRectTool(roundrect); 22 | static RectTool ellipseTool(ellipse); 23 | static RotationTool rotationTool; 24 | static ArrowItem arrowTool(arrowLine); 25 | 26 | 27 | enum SelectMode 28 | { 29 | none, 30 | netSelect, 31 | move, //移动 32 | size, //改变大小 33 | rotate //反转 34 | }; 35 | SelectMode selectMode = none; 36 | 37 | SizeHandleRect::Direction nDragHandle = SizeHandleRect::None; 38 | 39 | static void setCursor(QGraphicsScene * scene , const QCursor & cursor ) 40 | { 41 | QList views = scene->views(); 42 | if ( views.count() > 0 ){ 43 | QGraphicsView * view = views.first(); 44 | view->setCursor(cursor); 45 | } 46 | } 47 | 48 | DrawTool::DrawTool(DrawBaseShape shape) 49 | { 50 | m_drawShape = shape ; 51 | c_tools.push_back(this); 52 | } 53 | 54 | void DrawTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 55 | { 56 | c_down = event->scenePos(); 57 | c_last = event->scenePos(); 58 | } 59 | 60 | void DrawTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 61 | { 62 | c_last = event->scenePos(); 63 | } 64 | 65 | void DrawTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 66 | { 67 | if (event->scenePos() == c_down) 68 | c_drawShape = selection; 69 | setCursor(scene,Qt::ArrowCursor); 70 | 71 | } 72 | 73 | DrawTool *DrawTool::findTool(DrawBaseShape drawShape) 74 | { 75 | QList::const_iterator iter = c_tools.constBegin(); 76 | for ( ; iter != c_tools.constEnd() ; ++iter ){ 77 | if ((*iter)->m_drawShape == drawShape ) 78 | return (*iter); 79 | } 80 | return 0; 81 | } 82 | 83 | SelectTool::SelectTool() 84 | :DrawTool(selection) 85 | { 86 | m_lastSize.setHeight(0); 87 | m_lastSize.setWidth(0); 88 | dashRect = 0; 89 | dashLine = 0; 90 | m_hoverSizer = false; 91 | 92 | } 93 | 94 | void SelectTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 95 | { 96 | DrawTool::mousePressEvent(event,scene); 97 | 98 | if (!m_hoverSizer) 99 | scene->mouseEvent(event); 100 | 101 | selectMode = none; 102 | QList items = scene->selectedItems(); 103 | GraphicsItem *item = 0; 104 | if ( items.count() == 1 ) 105 | { 106 | item = qgraphicsitem_cast(items.first()); 107 | 108 | } 109 | if ( item != 0 && 110 | item->type() !=GraphicsItem::UserType+3){ 111 | 112 | nDragHandle = item->hitTest(event->scenePos()); 113 | if ( nDragHandle !=SizeHandleRect::None) 114 | selectMode = size; 115 | else 116 | selectMode = move; 117 | } 118 | 119 | 120 | if( selectMode == none ){ 121 | selectMode = netSelect; 122 | QList views = scene->views(); 123 | if ( views.count() > 0 ){ 124 | QGraphicsView * view = views.first(); 125 | view->setDragMode(QGraphicsView::RubberBandDrag); 126 | } 127 | } 128 | 129 | if ( selectMode == move && items.count() == 1 ){ 130 | 131 | if (dashRect ){ 132 | scene->removeItem(dashRect); 133 | delete dashRect; 134 | dashRect = 0; 135 | } 136 | if (dashLine ) { 137 | scene->removeItem(dashLine); 138 | delete dashLine; 139 | dashLine = 0; 140 | } 141 | 142 | item->setPos(item->mapToScene(item->boundingRect().topLeft())); 143 | item->resetShape(); 144 | dashRect = new QGraphicsPathItem(item->shape()); 145 | dashRect->setPen(Qt::DashLine); 146 | dashRect->setPos(item->pos()); 147 | //dashRect->setTransformOriginPoint(item->transformOriginPoint()); 148 | dashRect->setTransform(item->transform()); 149 | dashRect->setRotation(item->rotation()); 150 | scene->addItem(dashRect); 151 | 152 | dashLine = new QGraphicsLineItem(); 153 | dashLine->setPos(item->pos()); 154 | dashLine->setPen(Qt::DashLine); 155 | scene->addItem(dashLine); 156 | 157 | } 158 | } 159 | 160 | void SelectTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 161 | { 162 | DrawTool::mouseMoveEvent(event,scene); 163 | bool isGroup = false; 164 | QList items = scene->selectedItems(); 165 | GraphicsItem * item = 0; 166 | if ( items.count() == 1 ) 167 | { 168 | item = qgraphicsitem_cast(items.first()); 169 | if ( item != 0 ){ 170 | if(item->type() ==GraphicsItem::UserType+3) 171 | { 172 | scene->mouseEvent(event); 173 | scene->update(); 174 | return; 175 | } 176 | if ( nDragHandle != SizeHandleRect::None && selectMode == size ){ 177 | item->resizeTo(nDragHandle,c_last); 178 | } 179 | else if(nDragHandle == SizeHandleRect::None && selectMode == selection ){ 180 | 181 | SizeHandleRect::Direction handle = item->hitTest(event->scenePos()); 182 | if ( handle != SizeHandleRect::None){ 183 | setCursor(scene,item->getCursor(handle)); 184 | m_hoverSizer = true; 185 | }else{ 186 | setCursor(scene,Qt::ArrowCursor); 187 | m_hoverSizer = false; 188 | } 189 | } 190 | } 191 | 192 | QGraphicsItemGroup *item1 = qgraphicsitem_cast(items.first()); 193 | if ( item1 != NULL ){ 194 | isGroup = true; 195 | } 196 | } 197 | if ( selectMode == move ){ 198 | if ( dashRect ) 199 | { 200 | dashRect->setPos(c_last); 201 | dashLine->setLine(QLineF(dashLine->mapFromItem(item,item->boundingRect().topLeft()), 202 | dashLine->mapFromScene(c_last))); 203 | } 204 | } 205 | else if ((selectMode != size && items.count() > 0) || isGroup ) 206 | { 207 | scene->mouseEvent(event); 208 | } 209 | scene->update(); 210 | } 211 | 212 | void SelectTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 213 | { 214 | DrawTool::mouseReleaseEvent(event,scene); 215 | 216 | QList items = scene->selectedItems(); 217 | if ( items.count() == 1 ){ 218 | GraphicsItem * item = qgraphicsitem_cast(items.first()); 219 | if ( item != 0 ) 220 | { 221 | if(selectMode == move && c_last != c_down ){ 222 | item->setPos(c_last); 223 | } 224 | item->resetArrow(); 225 | } 226 | } 227 | if (selectMode == netSelect ){ 228 | QList views = scene->views(); 229 | if ( views.count() > 0 ){ 230 | QGraphicsView * view = views.first(); 231 | view->setDragMode(QGraphicsView::NoDrag); 232 | } 233 | } 234 | 235 | if (dashRect ){ 236 | scene->removeItem(dashRect); 237 | delete dashRect; 238 | dashRect = 0; 239 | 240 | scene->removeItem(dashLine); 241 | delete dashLine; 242 | dashLine = 0; 243 | } 244 | 245 | selectMode = none; 246 | nDragHandle = SizeHandleRect::None; 247 | m_hoverSizer = false; 248 | scene->mouseEvent(event); 249 | } 250 | 251 | 252 | RotationTool::RotationTool() 253 | :DrawTool(rotation) 254 | { 255 | lastAngle == 0; 256 | dashRect = 0; 257 | } 258 | 259 | void RotationTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 260 | { 261 | DrawTool::mousePressEvent(event,scene); 262 | QList items = scene->selectedItems(); 263 | if ( items.count() == 1 ){ 264 | GraphicsItem * item = qgraphicsitem_cast(items.first()); 265 | if ( item != 0 ){ 266 | nDragHandle = item->hitTest(event->scenePos()); 267 | if ( nDragHandle !=SizeHandleRect::None) 268 | { 269 | QPointF origin = item->mapToScene(item->boundingRect().center()); 270 | 271 | qreal len_y = c_last.y() - origin.y(); 272 | qreal len_x = c_last.x() - origin.x(); 273 | 274 | qreal angle = atan2(len_y,len_x)*180/PI; 275 | 276 | lastAngle = angle; 277 | selectMode = rotate; 278 | 279 | if (dashRect ){ 280 | scene->removeItem(dashRect); 281 | delete dashRect; 282 | dashRect = 0; 283 | } 284 | 285 | dashRect = new QGraphicsPathItem(item->shape()); 286 | dashRect->setPen(Qt::DashLine); 287 | dashRect->setPos(item->pos()); 288 | dashRect->setTransformOriginPoint(item->transformOriginPoint()); 289 | dashRect->setTransform(item->transform()); 290 | dashRect->setRotation(item->rotation()); 291 | scene->addItem(dashRect); 292 | 293 | setCursor(scene,QCursor(QPixmap(":/image/rotation.png"))); 294 | } 295 | else{ 296 | 297 | scene->clearSelection(); 298 | c_drawShape = selection; 299 | } 300 | } 301 | } 302 | } 303 | 304 | void RotationTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 305 | { 306 | DrawTool::mouseMoveEvent(event,scene); 307 | 308 | QList items = scene->selectedItems(); 309 | if ( items.count() == 1 ){ 310 | GraphicsItem * item = qgraphicsitem_cast(items.first()); 311 | if ( item != 0 && nDragHandle !=SizeHandleRect::None && selectMode == rotate ){ 312 | 313 | 314 | QPointF origin = item->mapToScene(item->boundingRect().center()); 315 | 316 | qreal len_y = c_last.y() - origin.y(); 317 | qreal len_x = c_last.x() - origin.x(); 318 | 319 | qreal angle = atan2(len_y,len_x)*180/PI; 320 | 321 | angle = item->rotation() + int(angle - lastAngle) ; 322 | 323 | if ( angle > 360 ) 324 | angle -= 360; 325 | 326 | if ( dashRect ){ 327 | dashRect->setRotation( angle ); 328 | scene->update(); 329 | } 330 | 331 | setCursor(scene,QCursor(QPixmap(":/image/rotation.png"))); 332 | } 333 | else if ( item ) 334 | { 335 | SizeHandleRect::Direction handle = item->hitTest(event->scenePos()); 336 | if ( handle != SizeHandleRect::None) 337 | setCursor(scene,QCursor(QPixmap(":/image/rotation.png"))); 338 | else 339 | setCursor(scene,Qt::ArrowCursor); 340 | } 341 | } 342 | } 343 | 344 | void RotationTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 345 | { 346 | DrawTool::mouseReleaseEvent(event,scene); 347 | 348 | QList items = scene->selectedItems(); 349 | if ( items.count() == 1 ){ 350 | GraphicsItem * item = qgraphicsitem_cast(items.first()); 351 | if ( item != 0 && nDragHandle !=SizeHandleRect::None && selectMode == rotate ){ 352 | 353 | QPointF origin = item->mapToScene(item->boundingRect().center()); 354 | 355 | QPointF delta = c_last - origin ; 356 | qreal len_y = c_last.y() - origin.y(); 357 | qreal len_x = c_last.x() - origin.x(); 358 | qreal angle = atan2(len_y,len_x)*180/PI; 359 | angle = item->rotation() + int(angle - lastAngle) ; 360 | if ( angle > 360 ) 361 | angle -= 360; 362 | item->setRotation( angle ); 363 | } 364 | } 365 | 366 | setCursor(scene,Qt::ArrowCursor); 367 | selectMode = none; 368 | nDragHandle = SizeHandleRect::None; 369 | lastAngle = 0; 370 | if (dashRect ){ 371 | scene->removeItem(dashRect); 372 | delete dashRect; 373 | dashRect = 0; 374 | } 375 | qDebug() << " RotationTool release:" <scenePos(); 376 | } 377 | 378 | /*************************************ImageTool*******************/ 379 | ImageTool::ImageTool(DrawBaseShape drawShape) 380 | :DrawTool(drawShape) 381 | { 382 | 383 | } 384 | void ImageTool::setPicture(QString path ) 385 | { 386 | _imgPath =path; 387 | 388 | } 389 | void ImageTool::mousePressEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) 390 | { 391 | DrawTool::mousePressEvent(event,scene); 392 | scene->clearSelection(); 393 | QPixmap pixmap; 394 | bool ok= pixmap.load(_imgPath); 395 | if(! ok) 396 | return; 397 | switch ( c_drawShape ){ 398 | case image: 399 | item = new GraphicsPixmapItem(pixmap,NULL); 400 | break; 401 | 402 | } 403 | if ( item == 0) return; 404 | item->setPos(event->scenePos()); 405 | scene->addItem(item); 406 | item->setSelected(true); 407 | selectMode = size; 408 | nDragHandle = SizeHandleRect::RightBottom; 409 | } 410 | void ImageTool::mouseMoveEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) 411 | { 412 | setCursor(scene,Qt::CrossCursor); 413 | selectTool.mouseMoveEvent(event,scene); 414 | } 415 | void ImageTool::mouseReleaseEvent(QGraphicsSceneMouseEvent * event , MainPaintScene * scene ) 416 | { 417 | if ( event->scenePos() == c_down ){ 418 | if ( item != 0) 419 | scene->removeItem(item); 420 | selectTool.mousePressEvent(event,scene); 421 | } 422 | selectTool.mouseReleaseEvent(event,scene); 423 | } 424 | 425 | 426 | 427 | /*************************************RectTool*******************/ 428 | RectTool::RectTool(DrawBaseShape drawShape) 429 | :DrawTool(drawShape) 430 | { 431 | } 432 | 433 | void RectTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 434 | { 435 | DrawTool::mousePressEvent(event,scene); 436 | scene->clearSelection(); 437 | 438 | bool isSquare =false; 439 | if (event->button() == Qt::LeftButton) 440 | { 441 | if (QApplication::keyboardModifiers()== Qt::ControlModifier) 442 | { 443 | isSquare =true; 444 | } 445 | } 446 | switch ( c_drawShape ){ 447 | case rectangle: 448 | item = new GraphicsRectItem(QRect(0,0,0,0),NULL); 449 | item->setPen(Qt::NoPen); 450 | break; 451 | case ellipse: 452 | item = new GraphicsEllipseItem(QRect(0,0,0,0),NULL); 453 | item->setPen(Qt::NoPen); 454 | break; 455 | case triangle: 456 | item = new GraphicsTriangleItem(QRect(0,0,0,0),NULL); 457 | item->setPen(Qt::NoPen); 458 | break; 459 | } 460 | if ( item == 0) return; 461 | if(isSquare) 462 | item->setIsSquare(); 463 | item->setBorderColor(_mColor); 464 | item->setPos(event->scenePos()); 465 | scene->addItem(item); 466 | item->setSelected(true); 467 | selectMode = size; 468 | nDragHandle = SizeHandleRect::RightBottom; 469 | } 470 | 471 | void RectTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 472 | { 473 | setCursor(scene,Qt::CrossCursor); 474 | selectTool.mouseMoveEvent(event,scene); 475 | } 476 | 477 | void RectTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 478 | { 479 | if ( event->scenePos() == c_down ){ 480 | if (item != 0) 481 | scene->removeItem(item); 482 | selectTool.mousePressEvent(event,scene); 483 | } 484 | selectTool.mouseReleaseEvent(event,scene); 485 | } 486 | 487 | /////////****************PenPath************///////////////////// 488 | PenPathTool::PenPathTool(DrawBaseShape drawShape) 489 | :DrawTool(drawShape) 490 | { 491 | 492 | _path =nullptr; 493 | } 494 | void PenPathTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 495 | { 496 | DrawTool::mousePressEvent(event,scene); 497 | scene->clearSelection(); 498 | 499 | switch ( c_drawShape ){ 500 | case penPath: 501 | SafeDelete(_path); 502 | _path = new QPainterPath; 503 | _path->moveTo(event->scenePos()); 504 | item = new QGraphicsPathItem(*_path,nullptr); 505 | item->setFlag(QGraphicsItem::ItemIsMovable, true); 506 | item->setFlag(QGraphicsItem::ItemIsSelectable, true); 507 | break; 508 | } 509 | if ( item == 0) return; 510 | 511 | isDrawing =true; 512 | scene->addItem(item); 513 | QPen pen_bak=item->pen(); 514 | pen_bak.setWidth(9); 515 | pen_bak.setColor(_mColor); 516 | item->setPen(pen_bak); 517 | 518 | } 519 | 520 | void PenPathTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 521 | { 522 | if(isDrawing) 523 | { 524 | QPixmap pixmap(":/Win32/Resources/Win32/ic_sidebar_pencil.png"); 525 | //定义大小 526 | QSize picSize(8, 8); 527 | //缩放图片,按比例 528 | QPixmap scaledPixmap = pixmap.scaled(picSize, Qt::KeepAspectRatio); 529 | //设置样式 530 | QCursor cursor(scaledPixmap, -1, -1); 531 | setCursor(scene,cursor); 532 | _path->lineTo(event->scenePos()); 533 | item->setPath(*_path); 534 | } 535 | } 536 | 537 | void PenPathTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 538 | { 539 | isDrawing=false; 540 | } 541 | 542 | /////////****************LineTool************///////////////////// 543 | LineTool::LineTool(DrawBaseShape drawShape) 544 | :DrawTool(drawShape) 545 | { 546 | 547 | item =nullptr; 548 | } 549 | void LineTool::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 550 | { 551 | DrawTool::mousePressEvent(event,scene); 552 | scene->clearSelection(); 553 | 554 | switch ( c_drawShape ){ 555 | case line: 556 | item = new GraphicsLineItem(QLineF(event->scenePos(), 557 | event->scenePos())); 558 | item->setFlag(QGraphicsItem::ItemIsMovable, true); 559 | item->setFlag(QGraphicsItem::ItemIsSelectable, true); 560 | break; 561 | } 562 | if ( item == 0) return; 563 | 564 | isDrawing =true; 565 | // 设置画笔 566 | QPen pen = item->pen(); 567 | pen.setColor(_mColor); 568 | pen.setWidth(4); 569 | item->setPen(pen); 570 | scene->addItem(item); 571 | } 572 | 573 | void LineTool::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 574 | { 575 | if(isDrawing) 576 | { 577 | QLineF newLine(item->line().p1(), event->scenePos()); 578 | item->setLine(newLine); 579 | } 580 | } 581 | 582 | void LineTool::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 583 | { 584 | isDrawing=false; 585 | } 586 | /////////****************ArrowItem************///////////////////// 587 | 588 | ArrowItem::ArrowItem(DrawBaseShape drawShape) 589 | :DrawTool(drawShape) 590 | { 591 | } 592 | 593 | void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 594 | { 595 | DrawTool::mousePressEvent(event,scene); 596 | scene->clearSelection(); 597 | switch ( c_drawShape ){ 598 | case arrowLine: 599 | item = new GraphicsArrowItem(); 600 | item->setFlag(QGraphicsItem::ItemIsMovable, true); 601 | item->setFlag(QGraphicsItem::ItemIsSelectable, true); 602 | 603 | item->endPos= event->scenePos(); 604 | item->startPos= event->scenePos(); 605 | break; 606 | } 607 | if ( item == 0) return; 608 | isDrawing =true; 609 | item->setBorderColor(_mColor); 610 | scene->addItem(item); 611 | } 612 | 613 | void ArrowItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 614 | { 615 | if(isDrawing) 616 | { 617 | item->endPos= event->scenePos(); 618 | scene->update(); 619 | } 620 | } 621 | 622 | void ArrowItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event, MainPaintScene *scene) 623 | { 624 | isDrawing=false; 625 | } 626 | 627 | -------------------------------------------------------------------------------- /GradeSystem/GradeSystem.pro.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | EnvironmentId 7 | {e4094be7-6b6a-4d2e-b679-c066928b4c8a} 8 | 9 | 10 | ProjectExplorer.Project.ActiveTarget 11 | 0 12 | 13 | 14 | ProjectExplorer.Project.EditorSettings 15 | 16 | true 17 | false 18 | true 19 | 20 | Cpp 21 | 22 | CppGlobal 23 | 24 | 25 | 26 | QmlJS 27 | 28 | QmlJSGlobal 29 | 30 | 31 | 2 32 | UTF-8 33 | false 34 | 4 35 | false 36 | 80 37 | true 38 | true 39 | 1 40 | true 41 | false 42 | 0 43 | true 44 | true 45 | 0 46 | 8 47 | true 48 | 0 49 | true 50 | true 51 | true 52 | false 53 | 54 | 55 | 56 | ProjectExplorer.Project.PluginSettings 57 | 58 | 59 | 60 | ProjectExplorer.Project.Target.0 61 | 62 | Desktop Qt 5.9.2 MinGW 32bit 63 | Desktop Qt 5.9.2 MinGW 32bit 64 | qt.592.win32_mingw53_kit 65 | 0 66 | 0 67 | 0 68 | 69 | D:/BJHL/andyCode/build-GradeSystem-Desktop_Qt_5_9_2_MinGW_32bit-Debug 70 | 71 | 72 | true 73 | qmake 74 | 75 | QtProjectManager.QMakeBuildStep 76 | true 77 | 78 | false 79 | false 80 | false 81 | 82 | 83 | true 84 | Make 85 | 86 | Qt4ProjectManager.MakeStep 87 | 88 | false 89 | 90 | 91 | 92 | 2 93 | 构建 94 | 95 | ProjectExplorer.BuildSteps.Build 96 | 97 | 98 | 99 | true 100 | Make 101 | 102 | Qt4ProjectManager.MakeStep 103 | 104 | true 105 | clean 106 | 107 | 108 | 1 109 | 清理 110 | 111 | ProjectExplorer.BuildSteps.Clean 112 | 113 | 2 114 | false 115 | 116 | Debug 117 | 118 | Qt4ProjectManager.Qt4BuildConfiguration 119 | 2 120 | true 121 | 122 | 123 | D:/BJHL/andyCode/build-GradeSystem-Desktop_Qt_5_9_2_MinGW_32bit-Release 124 | 125 | 126 | true 127 | qmake 128 | 129 | QtProjectManager.QMakeBuildStep 130 | false 131 | 132 | false 133 | false 134 | false 135 | 136 | 137 | true 138 | Make 139 | 140 | Qt4ProjectManager.MakeStep 141 | 142 | false 143 | 144 | 145 | 146 | 2 147 | 构建 148 | 149 | ProjectExplorer.BuildSteps.Build 150 | 151 | 152 | 153 | true 154 | Make 155 | 156 | Qt4ProjectManager.MakeStep 157 | 158 | true 159 | clean 160 | 161 | 162 | 1 163 | 清理 164 | 165 | ProjectExplorer.BuildSteps.Clean 166 | 167 | 2 168 | false 169 | 170 | Release 171 | 172 | Qt4ProjectManager.Qt4BuildConfiguration 173 | 0 174 | true 175 | 176 | 177 | D:/BJHL/andyCode/build-GradeSystem-Desktop_Qt_5_9_2_MinGW_32bit-Profile 178 | 179 | 180 | true 181 | qmake 182 | 183 | QtProjectManager.QMakeBuildStep 184 | true 185 | 186 | false 187 | true 188 | false 189 | 190 | 191 | true 192 | Make 193 | 194 | Qt4ProjectManager.MakeStep 195 | 196 | false 197 | 198 | 199 | 200 | 2 201 | 构建 202 | 203 | ProjectExplorer.BuildSteps.Build 204 | 205 | 206 | 207 | true 208 | Make 209 | 210 | Qt4ProjectManager.MakeStep 211 | 212 | true 213 | clean 214 | 215 | 216 | 1 217 | 清理 218 | 219 | ProjectExplorer.BuildSteps.Clean 220 | 221 | 2 222 | false 223 | 224 | Profile 225 | 226 | Qt4ProjectManager.Qt4BuildConfiguration 227 | 0 228 | true 229 | 230 | 3 231 | 232 | 233 | 0 234 | 部署 235 | 236 | ProjectExplorer.BuildSteps.Deploy 237 | 238 | 1 239 | 在本地部署 240 | 241 | ProjectExplorer.DefaultDeployConfiguration 242 | 243 | 1 244 | 245 | 246 | false 247 | false 248 | 1000 249 | 250 | true 251 | 252 | false 253 | false 254 | false 255 | false 256 | true 257 | 0.01 258 | 10 259 | true 260 | 1 261 | 25 262 | 263 | 1 264 | true 265 | false 266 | true 267 | valgrind 268 | 269 | 0 270 | 1 271 | 2 272 | 3 273 | 4 274 | 5 275 | 6 276 | 7 277 | 8 278 | 9 279 | 10 280 | 11 281 | 12 282 | 13 283 | 14 284 | 285 | -1 286 | 287 | 288 | 289 | %{buildDir} 290 | Custom Executable 291 | 292 | ProjectExplorer.CustomExecutableRunConfiguration 293 | 3768 294 | false 295 | true 296 | false 297 | false 298 | true 299 | 300 | 1 301 | 302 | 303 | 304 | ProjectExplorer.Project.TargetCount 305 | 1 306 | 307 | 308 | ProjectExplorer.Project.Updater.FileVersion 309 | 18 310 | 311 | 312 | Version 313 | 18 314 | 315 | 316 | --------------------------------------------------------------------------------