資源簡介
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())
評論
共有 條評論