• 大小: 54KB
    文件类型: .tar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: 其他
  • 标签: Qt  画图  

资源简介

Qt做的画图程序的源代码,已在Qt4上通过运行

资源截图

代码片段和文件信息

#include 
#include 
#include 
#include 
#include 
#include 
#include “CentralWidget.h“
#include “MainWindowframework.h“
#include “GraphLine.h“
#include “GraphRect.h“
#include “Graphics.h“


using namespace KING;
using namespace std;

QCentralWidget::QCentralWidget(QWidget* parent Qt::WindowFlags f)
: QWidget(parent f)
 m_eGraphicsType(NONE)
 m_pSelectedGraph(NULL)
{
QMainWindowframework* pframe = (QMainWindowframework*)parentWidget();
pframe->actionLine->setChecked(m_eGraphicsType == LINE);
pframe->actionLine->setChecked(m_eGraphicsType == RECT);




}

void QCentralWidget::onGraphicsLine(bool bChecked)
{
m_eGraphicsType = bChecked ? LINE : NONE;
QMainWindowframework* pframe = (QMainWindowframework*)parentWidget();
pframe->actionLine->setChecked(m_eGraphicsType == LINE);
pframe->actionRect->setChecked(m_eGraphicsType == RECT);
}

void QCentralWidget::onGraphicsRect(bool bChecked)
{
m_eGraphicsType = bChecked ? RECT : NONE;
QMainWindowframework* pframe = (QMainWindowframework*)parentWidget();
pframe->actionLine->setChecked(m_eGraphicsType == LINE);
pframe->actionRect->setChecked(m_eGraphicsType == RECT);
}

void QCentralWidget::onRemove()
{
if(m_eGraphicsType == NONE && m_pSelectedGraph != NULL)
{
/**
for(list::iterator itGraph = m_lstGraph.begin();
itGraph != m_lstGraph.end(); itGraph++)
{
if(*itGraph == m_pSelectedGraph)
{
m_lstGraph.erase(itGraph);
delete(m_pSelectedGraph);
m_pSelectedGraph = NULL;
repaint(0 0 1000 1000);
return;
}
}
*/
QRect rect(m_pSelectedGraph->GetTopLeft().GetX() m_pSelectedGraph->GetTopLeft().GetY() 
m_pSelectedGraph->GetWidth() m_pSelectedGraph->GetHeight());
QRect rectNormal(rect.normalized());
rectNormal.adjust(-5 -5 5 5);
m_lstGraph.remove(m_pSelectedGraph);
delete m_pSelectedGraph;
m_pSelectedGraph = NULL;
repaint(rectNormal);
}
}


void QCentralWidget::onUp()
{

}

void QCentralWidget::onDown()
{

}

void QCentralWidget::onUpTop()
{

}

void QCentralWidget::onDownButton()
{

}


void QCentralWidget::mousePressEvent(QMouseEvent * event)
{
m_pSelectedGraph = NULL;//清空指针

if(m_eGraphicsType == NONE)//移动图形
{
for(list::reverse_iterator ritGraph = m_lstGraph.rbegin();
ritGraph != m_lstGraph.rend(); ritGraph++)
{
CGraphics* pGraph = *ritGraph;
QRect rRect(pGraph->GetTopLeft().GetX() pGraph->GetTopLeft().GetY() pGraph->GetWidth() pGraph->GetHeight());
if(rRect.contains(event->pos()))//选中图形
{
m_pSelectedGraph = pGraph;
m_posPoint = event->pos();
//选中加框
//.....
/*QString strMsg(tr(“选中图形!“));
QMainWindowframework* pframe = (QMainWindowframework*)parentWidget();
pframe->statusBar()->showMessage(strMsg);
return;*/
}
}
}
else//添加图形
{
if (Qt::LeftButton == event->button())

评论

共有 条评论