提交原始齿轮泵代码

This commit is contained in:
kite_lucs
2026-08-26 16:13:59 +08:00
commit afc8fcf2a4
1688 changed files with 316635 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+126
View File
@@ -0,0 +1,126 @@
#ifndef SCENEEDITOPTION_H
#define SCENEEDITOPTION_H
#include <QWidget>
#include <QTextEdit>
#include <QMessageBox>
#include <QFileDialog>
#include <QTextCharFormat>
#include <QXmlStreamReader>
#include <QGraphicsView>
#include "ParaSettingUI.h"
#include "MyFileDialog.h"
#include <QComboBox>
#include <QPushButton>
#include <QCheckBox>
#include "DialogFileOperation.h"
#include "DialogInsertVari.h"
#include "DialogFontSize.h"
#include "DialogLineSpace.h"
#include "PicWidget.h"
#include <QStackedWidget>
#include "dlgQrCode.h"
#include "QBarCode.h"
#include "DialogSaveFile.h"
#include "SceneEditOption.h"
#include "pictextitem.h"
#include "picscene.h"
#include "moveinput.h"
#include "formscenedlg.h"
#include <mainwindow.h>
#include "MyFileDialog.h"
namespace Ui {
class SceneEditOption;
}
class SceneEditOption : public QWidget,public ParaSettingUI
{
Q_OBJECT
public:
explicit SceneEditOption(QWidget *parent = 0);
~SceneEditOption();
void bindStackWidget(QStackedWidget *stackedWidgetOption,QStackedWidget *stackedWidgetText);
void bindSysPara(SysPara *sysPara);
void bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer, QTextEdit *pTextEdit);
bool createItemImage();
void updatePicScene2Item();
QList<QGraphicsItem *> getPicSceneItems();
signals:
void previewScene();
void addPicTextItem();
void importFile(QString);
void delItem();
void saveScene(QString);
void openSceneFile(QString);
void editItem();
void editItemMode();
void fileNameChanged(QString);
void generateQRCode(QString);
public slots:
void enableButtonSave();
void onSaveASFile(QString filename,bool Flag);
void saveFile();
void onFileOpen(QString filePath,bool insertFlag);
void onEditItemDone();
void onCreateSceneImage(QString filePath);//生成场景图片
void onStackedWidgetOptionCurrentChanged(int index);
//edit@12-07
void show_scene_new_dlg();
void on_btn_test2();
void onInkJetPrinterCurrentChanged(int index);
void insertImageItem(QString,bool);
private slots:
void on_delButton_pressed();
void on_saveButton_pressed();
void on_openfileButton_pressed();
void on_previewButton_pressed();
void on_addButton_pressed();
void on_EditItemButton_pressed();
void on_saveAsButton_pressed();
void on_newfileButton_pressed();
void on_enlargeButton_pressed();
void on_reduceButton_pressed();
void on_test_pressed();
private:
// 修复编辑时文本和变量错位问题
QString fixVariableImagesAlignment(const QString &html);
void parseVbfile(QXmlStreamReader &reader);
bool maybeSave();
Ui::SceneEditOption *ui;
QStackedWidget *stackedWidgetOption;
QStackedWidget *stackedWidgetText;
PicScene *pPicScene; //保存Item的Html对应的图片 用于显示 解决场景模式文本无法放大的问题
PicScene *pPicScene2; //保存Item的Html 用于编辑和保存 pPicScene和pPicScene2的Item一一对应
QGraphicsView *pViewer;
QTextEdit *textEdit;
QGraphicsScene *m_pSavePicScene;
bool m_CreateImageFlag;
int getSelectedIndex();
void syncAllPositions();
DialogFileOperation *dialogFileOperation;
#ifdef MYSAVEFILEDLG
DialogSaveFile *dialogSaveFile;
#endif
MyFileDialog *fileDialog;
PicTextItem *textItem;
PicTextItem *textItem2;
//PicScene *scene;
QString currFileName;
void onSceneAccepted(PicTextItem *pTextItem);
int editMode;//保存当前的编辑模式
QString xmlfileName;
FormScenedlg *newScene;
};
#endif // SCENEEDITOPTION_H
+559
View File
@@ -0,0 +1,559 @@
#include "formscenedlg.h"
#include "ui_formscenedlg.h"
#include <QTimer>
#include <QStackedWidget>
#include <QDebug>
#include <QScrollBar>
#include "MyInputMethod.h"
FormScenedlg::FormScenedlg(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormScenedlg),pPicScene(0),tabMainWindow(0),dialogFileOperation(0),textEdit(0)
{
ui->setupUi(this);
SWmaximumSize1={};
SWgeometry1={};
FVgeometry2={};
GVgeometry3={};
QPushButton *btnArray[]={
// ui->KeyDown,
// ui->KeyLeft,
// ui->KeyRight,
// ui->KeyUp,
ui->itemLast,
ui->itemFirst,
ui->saveAsButton,
ui->saveButton,
ui->addButton,
//ui->itemPrev,
//ui->itemNext,
ui->previewButton,
ui->newfileButton,
ui->openfileButton,
ui->delButton,
ui->EditItemButton,
ui->insertImage,
ui->reduceButton,
ui->enlargeButton,
ui->ZoomOrigin
};
const QString sysfamily=qApp->font().family();
for(int i=0;i<sizeof(btnArray)/sizeof(*btnArray);i++)
{
QFont font = ui->ZoomOrigin->font(); // 获取当前字体
const int defaultPointSize=16;//font.pointSize()<10?10:font.pointSize();
if(Public::ReadLanguageName()=="English"){
font.setFamily("Arial");
}
// font.setFamily("WenQuanYiMH");
//font.setFamily("wenquanyi");
font.setBold(true);
font.setPointSize(1*defaultPointSize); // 设置字体大小为12点
font.setWeight(QFont::Black);
btnArray[i]->setFont(font); // 应用新字体到按钮
}
//不显示测试按钮
ui->itemPrev->setVisible(false);
ui->itemNext->setVisible(false);
ui->ZoomOrigin->setVisible(false);
ui->btn_test2->setVisible(false);
}
FormScenedlg::~FormScenedlg()
{
delete ui;
delete dialogFileOperation;
dialogFileOperation=0;
}
void FormScenedlg::horizontalScrollBar_valueChanged(int value)
{
QTimer::singleShot(100,this,SLOT(sceneRectChanged_timerHandler()));
}
void FormScenedlg::verticalScrollBar_valueChanged(int value)
{
QTimer::singleShot(100,this,SLOT(sceneRectChanged_timerHandler()));
}
void FormScenedlg::bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer,QTextEdit *pTextEdit){
this->pPicScene = pPicScene;
this->pViewer = pGraphicViewer;
this->textEdit = pTextEdit;
QObject::connect(pViewer->verticalScrollBar(), SIGNAL(valueChanged(int)), this,SLOT(verticalScrollBar_valueChanged(int)));
QObject::connect(pViewer->horizontalScrollBar(), SIGNAL(valueChanged(int)), this,SLOT(horizontalScrollBar_valueChanged(int)));
dialogFileOperation = new DialogFileOperation(0);
dialogFileOperation->setWindowTitle(tr("插入图片"));
// connect(dialogFileOperation,SIGNAL(openFile(QString,bool)),this,SLOT(onFileOpen(QString,bool)));
//Scene Test
connect(dialogFileOperation,SIGNAL(openFile(QString,bool)),this,SIGNAL(insertImage(QString,bool)));
//edit@12-12读取旧的布局信息
const QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
const QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
if(pStackedWidget && fileSceneViewer)
{
tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
SWmaximumSize1=pStackedWidget->maximumSize();
SWgeometry1=pStackedWidget->geometry();
//QSize FVmaximumSize=fileSceneViewer->maximumSize();
FVgeometry2=fileSceneViewer->geometry();
//QSize GVmaximumSize=this->pViewer->maximumSize();
GVgeometry3=this->pViewer->geometry();
//qDebug()<<"1-2-3-size="<<SWmaximumSize1<<", "<<SWgeometry1<<", "<<FVgeometry2<<", "<<GVgeometry3;
}
}
void FormScenedlg::sceneRectChanged_timerHandler()
{
// if(this->pViewer && this->pPicScene)
// {
// const QPoint originScene=pViewer->mapFromScene(0,0);
// if(originScene!=lastOriginScene)
// {
// lastOriginScene=originScene;
this->pPicScene->update();
// //qDebug()<<"sceneRectChanged-update="<<lastOriginScene;
// }
// //qDebug()<<"sceneRectChanged="<<this->pPicScene->sceneRect();
// }
}
//edit@12-12 改变布局
void FormScenedlg::Layout_ToNew()
{
QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
//QWidget *tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
QHBoxLayout *horizontalLayout=dynamic_cast<QHBoxLayout*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"horizontalLayout"));//edit@12-14 信息提示栏
FormScenedlg::showQLayout(horizontalLayout,false);
if(pStackedWidget && fileSceneViewer)
{
pStackedWidget->setMaximumSize(SWmaximumSize1.width(),SWmaximumSize1.height()+150);
pStackedWidget->setGeometry(SWgeometry1.x(),SWgeometry1.y(),SWgeometry1.width(),SWgeometry1.height()+150);
fileSceneViewer->setGeometry(FVgeometry2.x(),FVgeometry2.y(),FVgeometry2.width(),FVgeometry2.height()+150);
this->pViewer->setGeometry(GVgeometry3.x(),GVgeometry3.y(),GVgeometry3.width(),GVgeometry3.height()+80);
}
}
//edit@12-12 恢复布局
void FormScenedlg::Layout_ToDefault()
{
QStackedWidget* pStackedWidget= static_cast<QStackedWidget*>(this->pViewer->parentWidget()->parentWidget());
QWidget* fileSceneViewer = static_cast<QWidget*>(this->pViewer->parentWidget());
//QWidget *tabMainWindow=fileSceneViewer->parentWidget()->parentWidget();
QHBoxLayout *horizontalLayout=dynamic_cast<QHBoxLayout*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"horizontalLayout"));//edit@12-14 信息提示栏
FormScenedlg::showQLayout(horizontalLayout,true);
if(pStackedWidget && fileSceneViewer)
{
pStackedWidget->setMaximumSize(SWmaximumSize1);
pStackedWidget->setGeometry(SWgeometry1);
fileSceneViewer->setGeometry(FVgeometry2);
this->pViewer->setGeometry(GVgeometry3);
}
}
void FormScenedlg::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
void FormScenedlg::on_addButton_clicked()
{
emit addButton();
}
void FormScenedlg::on_EditItemButton_clicked()
{
emit EditItemButton();
}
void FormScenedlg::on_delButton_clicked()
{
emit delButton();
}
void FormScenedlg::on_newfileButton_clicked()
{
emit newfileButton();
}
void FormScenedlg::on_openfileButton_clicked()
{
emit openfileButton();
}
void FormScenedlg::on_previewButton_clicked()
{
pPicScene->clearSelection();
foreach (QGraphicsItem *item, pPicScene->items()) {
item->clearFocus();
item->setSelected(false);
}
//ui->previewButton->setFocus();
emit previewButton();
}
void FormScenedlg::on_saveButton_clicked()
{
emit saveButton();
}
void FormScenedlg::on_saveAsButton_clicked()
{
emit saveAsButton();
}
//edit@12-06 放大
void FormScenedlg::on_enlargeButton_clicked()
{
emit enlargeButton();
adjustItemsPos();
//QTimer::singleShot(100,this,SLOT(adjustItemsPos()));
}
void FormScenedlg::on_reduceButton_clicked()
{
emit reduceButton();
adjustItemsPos();
//QTimer::singleShot(100,this,SLOT(adjustItemsPos()));
}
void FormScenedlg::on_KeyLeft_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Left,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Left,Qt::NoModifier);
#endif
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
}
void FormScenedlg::on_KeyUp_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Up,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Up,Qt::NoModifier);
#endif
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
}
void FormScenedlg::on_KeyRight_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Right,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Right,Qt::NoModifier);
#endif
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
}
void FormScenedlg::on_KeyDown_clicked()
{
pViewer->setFocus();
#ifndef Q_OS_WIN32
//QWSServer::sendKeyEvent(0,Qt::Key_Down,Qt::NoModifier,true,false); //向系统发送键盘事件
MyInputMethod::sendEvent(Qt::Key_Down,Qt::NoModifier);
#endif
//QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
}
void FormScenedlg::on_insertImage_clicked()
{
if(dialogFileOperation)
{
dialogFileOperation->refreshListView(PICFILE);
dialogFileOperation->exec();
}
}
void FormScenedlg::on_ZoomOrigin_clicked()
{
adjustItemsPos(false);
}
void FormScenedlg::on_btn_test2_clicked()
{
emit ZoomOrigin();
}
//edit@12-11 选中下一个图元
void FormScenedlg::on_itemNext_clicked()
{
QList<QGraphicsItem *> items=pPicScene->items();
if(!items.empty())
{
int index=0;
for(index=0;index<items.size();index++)
{
if(items.at(index)->isSelected())break;
}
pPicScene->clearSelection();
if(index+1<items.size())
{
index+=1;
//edit@12-11选中下一个
items.at(index)->setSelected(true);
items.at(index)->setFocus();
}
else
{
//edit@12-11 超范围,滚动到第一个
index=0;
items.front()->setSelected(true);
items.front()->setFocus();
}
//PrintselectedItemInfo();
}
}
//edit@12-11选中上一个图元
void FormScenedlg::on_itemPrev_clicked()
{
QList<QGraphicsItem *> items=pPicScene->items();
if(!items.empty())
{
int index=0;
for(index=0;index<items.size();index++)
{
if(items.at(index)->isSelected())break;
}
pPicScene->clearSelection();
if(0<=index-1)
{
index-=1;
//edit@12-11选中前一个
items.at(index)->setSelected(true);
items.at(index)->setFocus();
}
else
{
//edit@12-11 超范围,滚动到最后位置
index=items.size()-1;
items.back()->setSelected(true);
items.back()->setFocus();
}
//PrintselectedItemInfo();
}
}
void FormScenedlg::PrintselectedItemInfo()
{
foreach (QGraphicsItem *item, pPicScene->items()) {
if(item->isSelected())
{
qDebug()<<"PrintselectedItemInfo-pos="<<item->pos();
//qDebug()<<"PrintselectedItemInfo-pos="<<pPicScene->views().front()->mapFromScene(item->pos());
break;
}
}
}
//edit@12-11 自动调整元素位置到原点
void FormScenedlg::adjustItemsPos(bool bMoveScrollBar)
{
auto items = pPicScene->items();
// if(!items.isEmpty()){
// pViewer->centerOn(items.first());
// auto i = items.first();
// if(i->flags() & QGraphicsItem::ItemIgnoresTransformations)
// qDebug() << "ItemIgnoresTransformations";
// pPicScene->update();
// return;
// }
if(bMoveScrollBar)
{
pViewer->verticalScrollBar()->setValue(0);
pViewer->horizontalScrollBar()->setValue(0);
}
QPointF movePoint;
const QRectF sceneRect=pPicScene->sceneRect();
qreal left=sceneRect.width(),top=sceneRect.width();
foreach (const QGraphicsItem *item, pPicScene->items()) {
left=qMin(left,item->pos().x());
top=qMin(top,item->pos().y());
}
foreach (QGraphicsItem *item, pPicScene->items()) {
QPointF oldpos=item->pos();
//oldpos=QPointF(qCeil(oldpos.x()-left-1),qCeil(oldpos.y()-(top-pViewer->mapToScene(0,0).y()+1)));
oldpos=QPointF(qCeil(oldpos.x()-left),qCeil(oldpos.y()-(top-pViewer->mapToScene(0,0).y())));
item->setPos(oldpos);
if(item->isSelected())movePoint=oldpos;
}
if(bMoveScrollBar)
{
//pViewer->verticalScrollBar()->setValue(0);
//pViewer->horizontalScrollBar()->setValue(0);
if(0<movePoint.x())
{
movePoint=pViewer->mapFromScene(movePoint.x(),movePoint.y());
//pViewer->verticalScrollBar()->setValue(movePoint.y());
pViewer->horizontalScrollBar()->setValue(movePoint.x());
}
}
if(!pPicScene->items().empty())pPicScene->update();
//qDebug()<<"adjustItemsPos="<<bMoveScrollBar;
}
void FormScenedlg::showQLayout(QLayout *layout,bool visible)
{
for (int i = 0; i < layout->count(); ++i) {
QLayoutItem *item = layout->itemAt(i);
if (QWidget *widget = item->widget()) {
visible?widget->show():widget->hide();
} else if (QLayout *subLayout = item->layout()) {
showQLayout(subLayout,visible);
}
}
}
QObject *FormScenedlg::findChildAll(const QLayout *layout,const QString &name)
{
for (int i = 0; i < layout->count(); ++i) {
QLayoutItem *item = layout->itemAt(i);
if (QObject *widget = item->widget()) {
if(widget->objectName()==name)return widget;
} else if (QLayout *subLayout = item->layout()) {
if(subLayout->objectName()==name)return subLayout;
QObject *q= findChildAll(subLayout,name);
if(q)return q;continue;
}
}
return 0;
}
void FormScenedlg::onFileOpen(QString filePath,bool ){
pPicScene->clearSelection();
QString html = "<img src='" + filePath + "'/>";
textEdit->setHtml (html);
textItem = new PicTextItem();
pPicScene->addItem(textItem);
QList<QGraphicsItem *> items = pPicScene->items();
if(pPicScene->items().count()>1){
QRectF itemRect= items.at(1)->boundingRect();
textItem->setPos( items.at(1)->scenePos().x()+itemRect.width()+20, items.at(1)->scenePos().y());
}
else textItem->setPos(this->pViewer->mapToScene(0,0));//edit@12-07
textItem->setSelected(true);
textItem->setHtml(textEdit->toHtml());
}
void FormScenedlg::reset_showTextWidthHeight()
{
const QRectF BoundingRect=pPicScene->itemsBoundingRect();
QLabel *labelTextWidthHeight=dynamic_cast<QLabel*>(FormScenedlg::findChildAll(tabMainWindow->layout(),"labelTextWidthHeight"));
if(labelTextWidthHeight && 1<BoundingRect.height())
{
qreal bottomItem[2]={-1};//txt,img
foreach (QGraphicsItem *item, pPicScene->items()) {
if(item->x()<0)item->setX(0);
if(item->y()<0)item->setY(0);
//const int i=-1==((QGraphicsTextItem*)item)->toHtml().indexOf("img ",0,Qt::CaseInsensitive)?0:1;
const int i=-1==((QGraphicsTextItem*)item)->toHtml().indexOf("home/plg/doc/",0,Qt::CaseInsensitive)?0:1;
if(item->sceneBoundingRect().bottom()>bottomItem[i])
{
bottomItem[i]=item->sceneBoundingRect().bottom();
}
}
QString newText;
int HighlightedValue= BoundingRect.height();
newText = tr("[ %1行 x %2列 ]").arg(HighlightedValue).arg(BoundingRect.width());
const QString oldText=labelTextWidthHeight->text();
if(32<HighlightedValue)
{
//edit@12-17 超出范围的高亮提示
labelTextWidthHeight->setText(tr("<html><head/><body><p>[<span style=\"color:red;font-size:16px;\"> %1行 </span>x %2列 ]</p></body></html>")
.arg(HighlightedValue).arg(qCeil(BoundingRect.width())));
}
else
{
labelTextWidthHeight->setText(newText);
}
if(oldText!=newText)
{
//QTimer::singleShot(10,this,SLOT(adjustItemsPos()));
QTimer::singleShot(10,this,SLOT(adjustItemsPosFalse()));
}
}
}
void FormScenedlg::on_itemFirst_clicked()
{
int index=-1;
const QRectF sceneRect=pPicScene->sceneRect();
qreal left=sceneRect.width();
QList<QGraphicsItem *> allitems=pPicScene->items();
for(int i =0;i<allitems.size();i++)
{
allitems.at(i)->clearFocus();
allitems.at(i)->setSelected(false);
if(left>allitems.at(i)->pos().x())
{
index=i;
left=allitems.at(i)->pos().x();
}
}
if(-1!=index)pPicScene->items().at(index)->setSelected(true);
adjustItemsPos();
}
void FormScenedlg::on_itemLast_clicked()
{
pPicScene->clearSelection();
int index=-1;
const QRectF sceneRect=pPicScene->sceneRect();
qreal left=0;
QList<QGraphicsItem *> allitems=pPicScene->items();
for(int i =0;i<allitems.size();i++)
{
allitems.at(i)->clearFocus();
allitems.at(i)->setSelected(false);
if(left<allitems.at(i)->pos().x())
{
index=i;
left=allitems.at(i)->pos().x();
}
}
if(-1!=index)pPicScene->items().at(index)->setSelected(true);
adjustItemsPos();
}
//void FormScenedlg::onSceneRectChanged(const QString &text)
//{
// qDebug()<<"FormScenedlg::sceneRectChanged=";
//}
+128
View File
@@ -0,0 +1,128 @@
#ifndef FORMSCENEDLG_H
#define FORMSCENEDLG_H
#include <QWidget>
#include <QGraphicsView>
#include <QKeyEvent>
//#include <QWSServer>
#include <QBoxLayout>
#include <QTimer>
#include <QLabel>
#include <QTextEdit>
#include <QFontDatabase>
#include <qmath.h>
#include "picscene.h"
#include "DialogFileOperation.h"
#include "pictextitem.h"
#include "myinclude.h"
#include "Public.h"
namespace Ui {
class FormScenedlg;
}
class FormScenedlg : public QWidget
{
Q_OBJECT
public:
explicit FormScenedlg(QWidget *parent = 0);
~FormScenedlg();
void bindScene(PicScene *pPicScene, QGraphicsView *pGraphicViewer,QTextEdit *pTextEdit);
static void showQLayout(QLayout *layout, bool visible=true);
static QObject *findChildAll(const QLayout *layout, const QString &name);
void Layout_ToNew();
void Layout_ToDefault();
public slots:
//void onSceneRectChanged(const QString &text);
protected:
void changeEvent(QEvent *e);
signals:
void delButton();
void saveButton();
void openfileButton();
void previewButton();
void addButton();
void EditItemButton();
void saveAsButton();
void newfileButton();
void enlargeButton();
void reduceButton();
void ZoomOrigin();
void btn_test2();
void insertImage(QString,bool);
private slots:
void on_addButton_clicked();
void on_EditItemButton_clicked();
void on_delButton_clicked();
void on_newfileButton_clicked();
void on_openfileButton_clicked();
void on_previewButton_clicked();
void on_saveButton_clicked();
void on_saveAsButton_clicked();
void on_enlargeButton_clicked();
void on_reduceButton_clicked();
void on_KeyLeft_clicked();
void on_KeyUp_clicked();
void on_KeyRight_clicked();
void on_KeyDown_clicked();
void on_insertImage_clicked();
void on_ZoomOrigin_clicked();
void on_btn_test2_clicked();
void on_itemNext_clicked();
void on_itemPrev_clicked();
void PrintselectedItemInfo();
void adjustItemsPos(bool bMoveScrollBar=true);
void adjustItemsPosFalse(){adjustItemsPos(false);}
void sceneRectChanged_timerHandler();
void verticalScrollBar_valueChanged(int value);
void horizontalScrollBar_valueChanged(int value);
void onFileOpen(QString filePath, bool insertFlag);
void reset_showTextWidthHeight();
void on_itemFirst_clicked();
void on_itemLast_clicked();
private:
Ui::FormScenedlg *ui;
PicScene *pPicScene;
QGraphicsView *pViewer;
QSize SWmaximumSize1;
QRect SWgeometry1;
QRect FVgeometry2;
QRect GVgeometry3;
QPoint lastOriginScene;
QWidget *tabMainWindow;
DialogFileOperation *dialogFileOperation;
QTextEdit *textEdit;
PicTextItem *textItem;
// QWidget interface
protected:
};
#endif // FORMSCENEDLG_H
+866
View File
@@ -0,0 +1,866 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormScenedlg</class>
<widget class="QWidget" name="FormScenedlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>258</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>510</x>
<y>90</y>
<width>281</width>
<height>161</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_keygroup">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>10</number>
</property>
<property name="verticalSpacing">
<number>18</number>
</property>
<item row="1" column="1">
<widget class="QPushButton" name="KeyDown">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keydown.png</normaloff>:/icon/keydown.png</iconset>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="KeyLeft">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keyleft.png</normaloff>:/icon/keyleft.png</iconset>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="KeyRight">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keyright.png</normaloff>:/icon/keyright.png</iconset>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="KeyUp">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keyup.png</normaloff>:/icon/keyup.png</iconset>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="itemLast">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="styleSheet">
<string notr="true">QPushButton{spacing:0px;}</string>
</property>
<property name="text">
<string>Last</string>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keyend.png</normaloff>:/icon/keyend.png</iconset>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="itemFirst">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>First</string>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/keyhome.png</normaloff>:/icon/keyhome.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QPushButton" name="ZoomOrigin">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>425</x>
<y>189</y>
<width>71</width>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">font: 800 16pt &quot;wenquanyi&quot;;</string>
</property>
<property name="text">
<string>重置位置</string>
</property>
</widget>
<widget class="QPushButton" name="btn_test2">
<property name="geometry">
<rect>
<x>430</x>
<y>50</y>
<width>61</width>
<height>101</height>
</rect>
</property>
<property name="text">
<string>Test2</string>
</property>
</widget>
<widget class="QPushButton" name="saveAsButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>150</x>
<y>170</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>另存为</string>
</property>
</widget>
<widget class="QPushButton" name="saveButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>170</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>保存</string>
</property>
</widget>
<widget class="QPushButton" name="previewButton">
<property name="geometry">
<rect>
<x>11</x>
<y>0</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>212</green>
<blue>159</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>56</red>
<green>113</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>212</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>212</green>
<blue>159</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>56</red>
<green>113</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>170</red>
<green>212</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Button">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Light">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>127</red>
<green>255</green>
<blue>191</blue>
</color>
</brush>
</colorrole>
<colorrole role="Midlight">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>106</red>
<green>212</green>
<blue>159</blue>
</color>
</brush>
</colorrole>
<colorrole role="Dark">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Mid">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>56</red>
<green>113</green>
<blue>84</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="BrightText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="ButtonText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>42</red>
<green>85</green>
<blue>63</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="Shadow">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="AlternateBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>85</red>
<green>170</green>
<blue>127</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipBase">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>220</blue>
</color>
</brush>
</colorrole>
<colorrole role="ToolTipText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
<property name="text">
<string>预览</string>
</property>
</widget>
<widget class="QPushButton" name="addButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>11</x>
<y>84</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">QPushButton#evilButton {
background-color: blue;
border-style: outset;
border-width: 2px;
border-radius: 10px;
border-color: beige;
font: bold 14px;
min-width: 10em;
padding: 6px;
}
QPushButton#evilButton:pressed {
background-color: rgb(224, 0, 0);
border-style: inset;
}</string>
</property>
<property name="text">
<string>新增图元</string>
</property>
</widget>
<widget class="QPushButton" name="itemNext">
<property name="geometry">
<rect>
<x>480</x>
<y>230</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Next-item</string>
</property>
</widget>
<widget class="QPushButton" name="newfileButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>150</x>
<y>0</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>新建</string>
</property>
</widget>
<widget class="QPushButton" name="openfileButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>290</x>
<y>0</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>打开</string>
</property>
</widget>
<widget class="QPushButton" name="delButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>290</x>
<y>170</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>删除图元</string>
</property>
</widget>
<widget class="QPushButton" name="EditItemButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>290</x>
<y>84</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>编辑图元</string>
</property>
</widget>
<widget class="QPushButton" name="insertImage">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>150</x>
<y>84</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string>插入图像</string>
</property>
</widget>
<widget class="QPushButton" name="itemPrev">
<property name="geometry">
<rect>
<x>460</x>
<y>230</y>
<width>16</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Prev-item</string>
</property>
</widget>
<widget class="QPushButton" name="reduceButton">
<property name="geometry">
<rect>
<x>510</x>
<y>0</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="text">
<string>场景缩小</string>
</property>
</widget>
<widget class="QPushButton" name="enlargeButton">
<property name="geometry">
<rect>
<x>660</x>
<y>0</y>
<width>131</width>
<height>81</height>
</rect>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>场景放大</string>
</property>
</widget>
</widget>
<resources>
<include location="../image.qrc"/>
</resources>
<connections/>
</ui>
+64
View File
@@ -0,0 +1,64 @@
#include "myview.h"
#include <QWheelEvent>
#include "picscene.h"
#include <QDebug>
MyView::MyView(QWidget *parent) :
QGraphicsView(parent)
{
zoomRatio = 1;
//setDragMode(QGraphicsView::ScrollHandDrag);//手型拖动
//setAlignment(Qt::AlignLeft | Qt::AlignTop);
//setFocusPolicy( Qt::NoFocus );
}
static float a = 1.61;
void MyView::ZoomOut(void)
{
if(zoomRatio < 6)
{
zoomRatio++;
// scale(2,2);
scale(a,a);
}
}
void MyView::ZoomIn(void)
{
if(zoomRatio > 2)
{
zoomRatio--;
scale(1/a,1/a);
}
}
//void MyView::wheelEvent(QWheelEvent*event) //滚轮事件
//{
//// if(event->delta() > 0) //如果鼠标滚轮远离使用者,则delta()返回正值
//// scale(0.5,0.5); //视图缩放
//// else scale(2,2);
//}
//void MyView::mousePressEvent(QMouseEvent*event)
//{
//// rotate(90); //视图旋转顺时针90度
//}
void MyView::keyPressEvent(QKeyEvent *event)
{
//event->accept();
//parent()->event((QEvent*) event);
if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || event->key() == Qt::Key_Up || event->key() == Qt::Key_Down)
{
// 处理上下键事件
PicScene* picScene = dynamic_cast<PicScene*>(this->scene());
if(picScene)
{
picScene->keyPressEvent(event);
}
}
else
{
// 其他键事件交给父类处理
QGraphicsView::keyPressEvent(event);
}
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef MYVIEW_H
#define MYVIEW_H
#include <QGraphicsView>
class MyView : public QGraphicsView
{
Q_OBJECT
public:
explicit MyView(QWidget *parent = 0);
void ZoomOut(void);
void ZoomIn(void);
//char getzoomRatio(){return zoomRatio;}
private:
char zoomRatio;
signals:
public slots:
protected :
// void wheelEvent(QWheelEvent *event);
// void mousePressEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
};
#endif // MYVIEW_H
+117
View File
@@ -0,0 +1,117 @@
#include "picscene.h"
#include <QDebug>
#include <QRectF>
#include <QPainter>
#include <QGraphicsView>
PicScene::PicScene(QObject *parent) :
QGraphicsScene(parent),IsdrawBackground(false)
{
}
void PicScene::setMode(Mode mode)
{
myMode = mode;
}
void PicScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
if (mouseEvent->button() != Qt::LeftButton)
return;
QGraphicsScene::mousePressEvent(mouseEvent);
}
//! [9]
//! [10]
void PicScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
update();//edit@12-12
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
//! [10]
//! [11]
void PicScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
//! [13]
//! [14]
bool PicScene::isItemChange(int type)
{
foreach (QGraphicsItem *item, selectedItems()) {
if (item->type() == type)
return true;
}
return false;
}
//! [14]
void PicScene::keyPressEvent(QKeyEvent *event)
{
QGraphicsScene::keyPressEvent(event);
}
//edit@12-09
void PicScene::drawBackground(QPainter *painter, const QRectF &rect)
{
QGraphicsScene::drawBackground(painter,rect);
if(IsdrawBackground)
{
Q_UNUSED(rect);
QPen pen;
const qreal left=rect.left();
const qreal right=rect.right();
const qreal top=rect.top();
const qreal bottom=rect.bottom();
const int step=1;
//pen.setColor(QColor(60,60,60));
pen.setColor(Qt::lightGray);
//pen.setColor(Qt::darkCyan);
pen.setWidth(0);
//pen.setStyle(Qt::DashLine);
painter->setPen(pen);
//绘制横线
//绘制Y轴正半轴
for(int i=0;i>=top;i-=step)
{
painter->drawLine(left,i,right,i);
}
//绘制Y轴负半轴
for(int i=0;i<=bottom;i+=step)
{
painter->drawLine(left,i,right,i);
}
//绘制竖线
//绘制X轴正半轴
for(int i=0;i<=right;i+=step)
{
painter->drawLine(i,top,i,bottom);
}
//绘制X轴负半轴
for(int i=0;i>=left;i-=step)
{
painter->drawLine(i,top,i,bottom);
}
//edit@12-11
pen.setColor(Qt::green);
painter->setPen(pen);
QRectF BoundingRect=this->itemsBoundingRect();
BoundingRect.setHeight(32);
painter->drawRect(BoundingRect);
}
emit showTextWidthHeight();
}
//edit@12-09
void PicScene::setIsdrawBackground(bool newIsdrawBackground)
{
IsdrawBackground = newIsdrawBackground;
}
+69
View File
@@ -0,0 +1,69 @@
#ifndef PICSCENE_H
#define PICSCENE_H
#include <QGraphicsScene>
#include "pictextitem.h"
#include <QGraphicsSceneMouseEvent>
QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
QT_END_NAMESPACE
class PicScene : public QGraphicsScene
{
Q_OBJECT
public:
enum Mode { InsertItem, InsertLine, InsertText, InsertPic, MoveItem };
explicit PicScene(QObject *parent = 0);
QFont font() const
{ return myFont; }
QColor textColor() const
{ return myTextColor; }
QColor itemColor() const
{ return myItemColor; }
QColor lineColor() const
{ return myLineColor; }
void setLineColor(const QColor &color);
void setTextColor(const QColor &color);
void setItemColor(const QColor &color);
void setFont(const QFont &font);
void keyPressEvent(QKeyEvent *event);
public slots:
void setMode(Mode mode);
void setIsdrawBackground(bool newIsdrawBackground);
signals:
void textInserted(QGraphicsTextItem *item);
void itemSelected(QGraphicsItem *item);
void xmlContentChanged();
void showTextWidthHeight();
void adjustItemsPos();
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);
void drawBackground(QPainter *painter, const QRectF &rect);
private:
bool isItemChange(int type);
QMenu *myItemMenu;
Mode myMode;
bool leftButtonDown;
QPointF startPoint;
QGraphicsLineItem *line;
QFont myFont;
PicTextItem *textItem;
QColor myTextColor;
QColor myItemColor;
QColor myLineColor;
private:
bool IsdrawBackground;
};
#endif // PICSCENE_H
+100
View File
@@ -0,0 +1,100 @@
#include <QtGui>
#include "pictextitem.h"
#include "picscene.h"
#include "moveinput.h"
extern MoveInput* moveInput;
PicTextItem::PicTextItem(QGraphicsItem *parent, QGraphicsScene *scene) :
QGraphicsTextItem(parent)//edit@02-07
{
setFlag(QGraphicsItem::ItemIsMovable);
setFlag(QGraphicsItem::ItemIsSelectable);
setFlag(QGraphicsItem::ItemIsFocusable);
QFont font;
font.setFamily("wenquanyi");
font.setPixelSize(12);
document()->setDefaultStyleSheet("p { margin: 0; }");
document()->setDocumentMargin(0);
SpecialConditions = false;
CatchCnt1CurrValue = -1;
CatchCnt1StartValue = -1;
// 插入的变量贴底部,防止错位,修复打开文件时变量图片的垂直对齐
document()->setDefaultStyleSheet("img { vertical-align: bottom; }");
}
//! [1]
QVariant PicTextItem::itemChange(GraphicsItemChange change,
const QVariant &value)
{
if (change == ItemSceneChange && scene()) {
QPointF newPos = value.toPoint();
QRectF rect = scene()->sceneRect();
if (!rect.contains(newPos)) {
newPos.setX(qMin(rect.right(), qMax(newPos.x(), rect.left())));
newPos.setY(qMin(rect.bottom(), qMax(newPos.y(), rect.top())));
}
}
return QGraphicsItem::itemChange(change, value);
}
//! [1]
//! [2]
void PicTextItem::focusOutEvent(QFocusEvent *event)
{
moveInput->hide();
emit lostFocus(this);
QGraphicsTextItem::focusOutEvent(event);
//
}
//! [2]
//! [5]
void PicTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
//if (textInteractionFlags() == Qt::NoTextInteraction)
// setTextInteractionFlags(Qt::TextEditorInteraction);
//setTextInteractionFlags(Qt::TextBrowserInteraction);
QGraphicsTextItem::mouseDoubleClickEvent(event);
//emit itemEdit(toHtml());
}
//! [5]
//限制图元拖动范围
void PicTextItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
//edit@12-07
QPointF newPos = this->pos();
this->setPos(qCeil(newPos.x()),qCeil(newPos.y()));
if(scene())
scene()->update();
QGraphicsTextItem::mouseReleaseEvent(event);
}
void PicTextItem::keyPressEvent(QKeyEvent *event)
{
foreach (QGraphicsItem *item, scene()->selectedItems()) {
if(event->key() == Qt::Key_Left)
{
item->moveBy(-1, 0);
}
else if(event->key() == Qt::Key_Right)
{
item->moveBy(1, 0);
}
else if(event->key() == Qt::Key_Up)
{
item->moveBy(0, -1);
}
else if(event->key() == Qt::Key_Down)
{
item->moveBy(0, 1);
}
}
if(!scene()->selectedItems().empty())
{
scene()->update();
}
QGraphicsTextItem::keyPressEvent(event);
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef PICTEXTITEM_H
#define PICTEXTITEM_H
#include <QGraphicsTextItem>
#include <QPen>
#include <QGraphicsSceneMouseEvent>
class QFocusEvent;
class QGraphicsItem;
class QGraphicsScene;
class QGraphicsSceneMouseEvent;
class PicTextItem : public QGraphicsTextItem
{
Q_OBJECT
public:
enum { Type = UserType + 3 };
explicit PicTextItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
int type() const
{ return Type; }
signals:
void lostFocus(PicTextItem *item);
void selectedChange(QGraphicsItem *item);
void itemEdit(QString);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void focusOutEvent(QFocusEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent * event);
void keyPressEvent(QKeyEvent *event);
public slots:
public:
bool SpecialConditions;
int CatchCnt1StartValue;
int CatchCnt1CurrValue;
};
#endif // PICTEXTITEM_H
+186
View File
@@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SceneEditOption</class>
<widget class="QWidget" name="SceneEditOption">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>924</width>
<height>58</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="previewButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>预览</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="newfileButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>新建</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="openfileButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>打开</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>保存</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveAsButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>另存为</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>新增图元</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="EditItemButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>编辑图元</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="delButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>删除图元</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enlargeButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>放大</string>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/zoomin.png</normaloff>:/icon/zoomin.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reduceButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string>缩小</string>
</property>
<property name="icon">
<iconset resource="../image.qrc">
<normaloff>:/icon/zoomout.png</normaloff>:/icon/zoomout.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../image.qrc"/>
</resources>
<connections/>
</ui>
+8
View File
@@ -0,0 +1,8 @@
#include "sceneviewwidget.h"
#include <QGraphicsScene>
SceneViewWidget::SceneViewWidget(QWidget *parent) :
QWidget(parent)
{
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef SCENEVIEWWIDGET_H
#define SCENEVIEWWIDGET_H
#include <QWidget>
#include <QGraphicsView>
class SceneViewWidget : public QWidget
{
Q_OBJECT
public:
explicit SceneViewWidget(QWidget *parent = 0);
QGraphicsView *pView;
signals:
public slots:
};
#endif // SCENEVIEWWIDGET_H