-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,264 additions
and
584 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
FourthOne/vector-editor_changed/vector-editor_changed/VectorEditor.pro.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,012 changes: 751 additions & 261 deletions
1,012
FourthOne/vector-editor_changed/vector-editor_changed/src/Makefile.Debug
Large diffs are not rendered by default.
Oops, something went wrong.
1,014 changes: 752 additions & 262 deletions
1,014
FourthOne/vector-editor_changed/vector-editor_changed/src/Makefile.Release
Large diffs are not rendered by default.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
FourthOne/vector-editor_changed/vector-editor_changed/src/TextItem.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
#include "TextItem.h" | ||
#include <QFont> | ||
#include <QPainter> | ||
#include <QCursor> | ||
#include <QKeyEvent> | ||
#include <QGraphicsSceneHoverEvent> | ||
#include <QGraphicsSceneContextMenuEvent> | ||
#include <QMenu> | ||
#include <QTextBlockFormat> | ||
|
||
TextItem::TextItem(QObject *parent) : | ||
QObject(parent) | ||
{ | ||
setFlag(QGraphicsItem::ItemIsFocusable); | ||
setFlag(QGraphicsItem::ItemIsMovable); | ||
|
||
QTextBlockFormat format; | ||
format.setAlignment(Qt::AlignCenter); | ||
//出现窗口,获得字体 | ||
if(td.exec() == QDialog::Accepted) | ||
{ | ||
tFont = td.getFont(); | ||
tWeight = td.getWidth(); | ||
myWidth = td.getKWidth();//文本框宽度 | ||
} | ||
//尺寸 | ||
adjust = 20; | ||
myFont.setFamily(tFont); | ||
myFont.setPointSize(tWeight); | ||
//文本项 | ||
text_item = new QGraphicsTextItem(this); | ||
text_item->setTextWidth(myWidth); | ||
text_item->setFont(myFont); | ||
text_item->setTextInteractionFlags(Qt::TextEditorInteraction); | ||
text_interaction = true; | ||
text_item->setPlainText("请在这里编辑^_^"); | ||
text_rect = text_item->boundingRect(); | ||
text_item->setPos(520, 520); | ||
//矩形框 | ||
rect_item = new QGraphicsRectItem(this); | ||
QPen *pen = new QPen(Qt::lightGray); | ||
rect_item->setPen(*pen); | ||
rect_item->setRect(500, 500, | ||
text_rect.width() + 3*adjust, | ||
text_rect.height() + 3*adjust); | ||
|
||
|
||
}; | ||
|
||
TextItem::~TextItem() | ||
{ | ||
delete text_item; | ||
delete rect_item; | ||
} | ||
|
||
QRectF TextItem::boundingRect(void) const //初始化长方形的位置,大小 | ||
{ | ||
rect_item->setRect(500, 500, | ||
text_rect.width() + 2*adjust, | ||
text_rect.height() + 2*adjust); | ||
return rect_item->boundingRect(); | ||
} | ||
void TextItem::paint(QPainter *painter, | ||
const QStyleOptionGraphicsItem *option, | ||
QWidget *widget) | ||
{ | ||
Q_UNUSED(painter); | ||
Q_UNUSED(option); | ||
} | ||
|
||
void TextItem::keyPressEvent(QKeyEvent *event) | ||
{ | ||
QGraphicsItem::keyPressEvent(event); | ||
} | ||
void TextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||
//setFocus(); | ||
QGraphicsItem::mousePressEvent(event); | ||
} | ||
void TextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | ||
{ | ||
setCursor(Qt::OpenHandCursor); | ||
} | ||
void TextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | ||
{ | ||
setCursor(Qt::ArrowCursor); | ||
} | ||
void TextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||
QGraphicsItem::mouseMoveEvent(event); | ||
} | ||
|
||
void TextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) | ||
{ | ||
QMenu menu; //显示文本和图标,但是不执行操作 | ||
QAction *edit_action = menu.addAction("编辑开关"); | ||
QAction *selected_action = menu.exec(event->screenPos()); | ||
if(selected_action == edit_action){ | ||
if(text_interaction){ | ||
text_item->setTextInteractionFlags(Qt::NoTextInteraction); | ||
text_interaction = false; | ||
reset_text_rect(); | ||
update(); //每次编辑完都更新 | ||
}else{ | ||
text_item->setTextInteractionFlags(Qt::TextEditorInteraction);//可编辑 | ||
text_interaction = true; | ||
} | ||
} | ||
} | ||
|
||
void TextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) | ||
{ | ||
setFocus(); | ||
QGraphicsItem::mouseDoubleClickEvent(event); | ||
} | ||
void TextItem::reset_text_rect(void) | ||
{ | ||
text_rect = text_item->boundingRect(); | ||
} | ||
|
||
|
58 changes: 58 additions & 0 deletions
58
FourthOne/vector-editor_changed/vector-editor_changed/src/TextItem.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#ifndef TEXTITEM_H | ||
#define TEXTITEM_H | ||
#include <QCursor> | ||
#include <QGraphicsItem> | ||
#include <QGraphicsTextItem> | ||
#include <QGraphicsRectItem> | ||
#include <QGraphicsTextItem> | ||
#include <QGraphicsSceneEvent> | ||
#include <QObject> | ||
#include <QFont> | ||
#include "textdialog.h" | ||
|
||
class TextItem : public QObject, public QGraphicsItem | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit TextItem(QObject *parent = 0); | ||
virtual ~TextItem(); | ||
QRectF boundingRect(void) const; | ||
//虚函数,不用但需存在 | ||
void paint(QPainter *painter, | ||
const QStyleOptionGraphicsItem *option, | ||
QWidget *widget); | ||
|
||
private: | ||
QGraphicsTextItem *text_item; | ||
QGraphicsRectItem *rect_item; | ||
bool text_interaction; //可编辑状态 | ||
|
||
QString tFont;//字体: 黑体等 | ||
QFont myFont; //字体 | ||
int tWeight;//字宽 | ||
qreal myWidth; //文本框的宽度 | ||
qreal adjust; //距离调整 | ||
QRectF text_rect; //文本的边框 | ||
|
||
void reset_text_rect(void); //重新设置文本边框的函数 | ||
|
||
TextDialog td; //出现窗口,设置字体 | ||
|
||
|
||
|
||
protected: | ||
void keyPressEvent(QKeyEvent *event); | ||
void mousePressEvent(QGraphicsSceneMouseEvent *event); | ||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | ||
void hoverLeaveEvent (QGraphicsSceneHoverEvent * event); | ||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | ||
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); | ||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent * event); | ||
|
||
signals: | ||
|
||
public slots: | ||
|
||
}; | ||
|
||
#endif // TEXTITEM_H |
Binary file added
BIN
+452 KB
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/TextItem.o
Binary file not shown.
Binary file modified
BIN
+875 KB
(110%)
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/VectorEditor.exe
Binary file not shown.
Binary file modified
BIN
+7.1 KB
(100%)
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/main.o
Binary file not shown.
Binary file modified
BIN
-717 Bytes
(100%)
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/mainwindow.o
Binary file not shown.
90 changes: 90 additions & 0 deletions
90
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/moc_TextItem.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/**************************************************************************** | ||
** Meta object code from reading C++ file 'TextItem.h' | ||
** | ||
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.2.0) | ||
** | ||
** WARNING! All changes made in this file will be lost! | ||
*****************************************************************************/ | ||
|
||
#include "../TextItem.h" | ||
#include <QtCore/qbytearray.h> | ||
#include <QtCore/qmetatype.h> | ||
#if !defined(Q_MOC_OUTPUT_REVISION) | ||
#error "The header file 'TextItem.h' doesn't include <QObject>." | ||
#elif Q_MOC_OUTPUT_REVISION != 67 | ||
#error "This file was generated using the moc from 5.2.0. It" | ||
#error "cannot be used with the include files from this version of Qt." | ||
#error "(The moc has changed too much.)" | ||
#endif | ||
|
||
QT_BEGIN_MOC_NAMESPACE | ||
struct qt_meta_stringdata_TextItem_t { | ||
QByteArrayData data[1]; | ||
char stringdata[10]; | ||
}; | ||
#define QT_MOC_LITERAL(idx, ofs, len) \ | ||
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ | ||
offsetof(qt_meta_stringdata_TextItem_t, stringdata) + ofs \ | ||
- idx * sizeof(QByteArrayData) \ | ||
) | ||
static const qt_meta_stringdata_TextItem_t qt_meta_stringdata_TextItem = { | ||
{ | ||
QT_MOC_LITERAL(0, 0, 8) | ||
}, | ||
"TextItem\0" | ||
}; | ||
#undef QT_MOC_LITERAL | ||
|
||
static const uint qt_meta_data_TextItem[] = { | ||
|
||
// content: | ||
7, // revision | ||
0, // classname | ||
0, 0, // classinfo | ||
0, 0, // methods | ||
0, 0, // properties | ||
0, 0, // enums/sets | ||
0, 0, // constructors | ||
0, // flags | ||
0, // signalCount | ||
|
||
0 // eod | ||
}; | ||
|
||
void TextItem::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) | ||
{ | ||
Q_UNUSED(_o); | ||
Q_UNUSED(_id); | ||
Q_UNUSED(_c); | ||
Q_UNUSED(_a); | ||
} | ||
|
||
const QMetaObject TextItem::staticMetaObject = { | ||
{ &QObject::staticMetaObject, qt_meta_stringdata_TextItem.data, | ||
qt_meta_data_TextItem, qt_static_metacall, 0, 0} | ||
}; | ||
|
||
|
||
const QMetaObject *TextItem::metaObject() const | ||
{ | ||
return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; | ||
} | ||
|
||
void *TextItem::qt_metacast(const char *_clname) | ||
{ | ||
if (!_clname) return 0; | ||
if (!strcmp(_clname, qt_meta_stringdata_TextItem.stringdata)) | ||
return static_cast<void*>(const_cast< TextItem*>(this)); | ||
if (!strcmp(_clname, "QGraphicsItem")) | ||
return static_cast< QGraphicsItem*>(const_cast< TextItem*>(this)); | ||
return QObject::qt_metacast(_clname); | ||
} | ||
|
||
int TextItem::qt_metacall(QMetaObject::Call _c, int _id, void **_a) | ||
{ | ||
_id = QObject::qt_metacall(_c, _id, _a); | ||
if (_id < 0) | ||
return _id; | ||
return _id; | ||
} | ||
QT_END_MOC_NAMESPACE |
Binary file added
BIN
+255 KB
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/moc_TextItem.o
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+38.8 KB
(120%)
FourthOne/vector-editor_changed/vector-editor_changed/src/debug/moc_mainwindow.o
Binary file not shown.
Oops, something went wrong.