图头表格,支持设置边框线形。
This commit is contained in:
parent
795e1c09f4
commit
843c819611
626
logPlus/BorderPreView.cpp
Normal file
626
logPlus/BorderPreView.cpp
Normal file
|
|
@ -0,0 +1,626 @@
|
|||
#include "BorderPreView.h"
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QPair>
|
||||
#include <QPen>
|
||||
|
||||
#define MARGIN_SIZE 5
|
||||
#define LINECON_SZIE 10
|
||||
|
||||
BorderPreView::BorderPreView(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
m_pCelll=(NULL);
|
||||
m_selectCurrentStyle=(-1);
|
||||
m_selectCurrentLineWidth=(-1);
|
||||
m_isBorderStyle=(false);
|
||||
m_TopState=m_RightState=m_BottomState=m_LeftState=true;
|
||||
m_ResetArea=false;
|
||||
}
|
||||
|
||||
BorderPreView::~BorderPreView()
|
||||
{
|
||||
|
||||
}
|
||||
void BorderPreView::SetBorderStyle(int width,int style)
|
||||
{
|
||||
m_selectCurrentStyle=style;
|
||||
m_selectCurrentLineWidth=width;
|
||||
m_isBorderStyle=true;
|
||||
}
|
||||
|
||||
void BorderPreView::paintEvent(QPaintEvent * pEvt)
|
||||
{
|
||||
QPainter paint;
|
||||
QRect viewRect=this->rect();
|
||||
paint.begin(this);
|
||||
|
||||
paint.save();
|
||||
paint.setPen(Qt::NoPen);
|
||||
paint.setBrush(Qt::white);
|
||||
paint.drawRect(viewRect);
|
||||
paint.restore();
|
||||
|
||||
// lines horn
|
||||
DrawBackgroundHorn(&paint);
|
||||
BuildBorderLines();
|
||||
if(m_ResetArea)
|
||||
{
|
||||
BuidlClickEventAreas();
|
||||
}
|
||||
DrawBorderLines(&paint);
|
||||
paint.end();
|
||||
}
|
||||
|
||||
void BorderPreView::SetCellObject(FormTableItem *pCell)
|
||||
{
|
||||
m_pCelll=pCell;
|
||||
}
|
||||
|
||||
void BorderPreView::BuidlClickEventAreas()
|
||||
{
|
||||
//m_AreaHandler
|
||||
int marginValue=LINECON_SZIE+MARGIN_SIZE;
|
||||
QRect viewRect=rect();
|
||||
int areaMargin=marginValue/2.0;
|
||||
int width=areaMargin*2;
|
||||
int height=viewRect.height()-marginValue*2;
|
||||
QRectF topRect,leftRect,rightRect,bottomRect;
|
||||
QPointF point= m_TopLine.p1();
|
||||
|
||||
point.setY( areaMargin);
|
||||
topRect.setTopLeft(point);
|
||||
topRect.setWidth(height);
|
||||
topRect.setHeight(width);
|
||||
|
||||
point= m_LeftLine.p1();
|
||||
point.setX(areaMargin);
|
||||
leftRect.setTopLeft(point);
|
||||
leftRect.setWidth(width);
|
||||
leftRect.setHeight(height);
|
||||
|
||||
point= m_RightLine.p1();
|
||||
point.setX(point.x()-areaMargin);
|
||||
rightRect.setTopLeft(point);
|
||||
rightRect.setWidth(width);
|
||||
rightRect.setHeight(height);
|
||||
|
||||
point= m_BottomLine.p2();
|
||||
point.setY(point.y()-areaMargin);
|
||||
bottomRect.setTopLeft(point);
|
||||
bottomRect.setWidth(height);
|
||||
bottomRect.setHeight(width);
|
||||
m_AreaEventHandler.clear();
|
||||
m_AreaEventHandler.insert(CellTop,topRect);
|
||||
m_AreaEventHandler.insert(CellLeft,leftRect);
|
||||
m_AreaEventHandler.insert(CellBottom,bottomRect);
|
||||
m_AreaEventHandler.insert(CellRight,rightRect);
|
||||
}
|
||||
|
||||
void BorderPreView::BuildBorderLines()
|
||||
{
|
||||
int marginValue=LINECON_SZIE+MARGIN_SIZE;
|
||||
int outVlaue=5;
|
||||
QPointF point,p1,p2;
|
||||
|
||||
QRect viewRect=rect();
|
||||
point=viewRect.topLeft();
|
||||
p1.setX(point.x()+marginValue);
|
||||
p1.setY(point.y()+marginValue+outVlaue);
|
||||
|
||||
point=viewRect.bottomLeft();
|
||||
p2.setX(point.x()+marginValue);
|
||||
p2.setY(point.y()-(marginValue+outVlaue));
|
||||
m_LeftLine.setP1(p1);
|
||||
m_LeftLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.topLeft();
|
||||
p1.setX(point.x()+marginValue+outVlaue);
|
||||
p1.setY(point.y()+marginValue);
|
||||
|
||||
point=viewRect.topRight();
|
||||
p2.setX(point.x()-(marginValue+outVlaue));
|
||||
p2.setY(point.y()+marginValue);
|
||||
m_TopLine.setP1(p1);
|
||||
m_TopLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.topRight();
|
||||
p1.setX(point.x()-marginValue);
|
||||
p1.setY(point.y()+(marginValue+outVlaue));
|
||||
|
||||
point=viewRect.bottomRight();
|
||||
p2.setX(point.x()-marginValue);
|
||||
p2.setY(point.y()-(marginValue+outVlaue));
|
||||
m_RightLine.setP1(p1);
|
||||
m_RightLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.bottomRight();
|
||||
p1.setX(point.x()-(marginValue+outVlaue));
|
||||
p1.setY(point.y()-marginValue);
|
||||
|
||||
point=viewRect.bottomLeft();
|
||||
p2.setX(point.x()+marginValue+outVlaue);
|
||||
p2.setY(point.y()-marginValue);
|
||||
m_BottomLine.setP1(p1);
|
||||
m_BottomLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
void BorderPreView::DrawBorderLines(QPainter *paint)
|
||||
{
|
||||
// CSheet* pHeadSheet =NULL;
|
||||
// if(m_pDigitizer->m_bSelectGraphicsHead)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetHeadSheet( m_pDigitizer->m_curGraphicsHeadSheetIndex );
|
||||
// }else if(m_pDigitizer->m_bSelectGraphicsFoot)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetFootSheet( m_pDigitizer->m_curGraphicsFootSheetIndex );
|
||||
// }
|
||||
// m_pSheet=pHeadSheet;
|
||||
|
||||
FormTableItem *m_pCell=NULL;
|
||||
if(m_pCelll) m_pCell=m_pCelll;
|
||||
// else {
|
||||
// if(m_pSheet)m_pCell=m_pSheet->GetSelGraphicsHeadCell();
|
||||
// }
|
||||
|
||||
if(!m_pCell) return;
|
||||
|
||||
paint->save();
|
||||
if (m_pCell)
|
||||
{
|
||||
switch(m_pCell->m_drawBorder)
|
||||
{
|
||||
case FormTableItem::All:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_TopState=m_RightState=m_BottomState=m_LeftState=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::Top:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=true;
|
||||
m_RightState=m_BottomState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Right:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_RightState=true;
|
||||
m_TopState=m_BottomState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Bottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_BottomState=true;
|
||||
m_TopState=m_RightState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Left:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_LeftState=true;
|
||||
m_TopState=m_RightState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_RightState=true;
|
||||
m_LeftState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::RightBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_BottomState=m_RightState=true;
|
||||
m_LeftState=m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::BottomLeft:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_BottomState=m_LeftState=true;
|
||||
m_RightState=m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftTop:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=m_LeftState=true;
|
||||
m_RightState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_TopState=m_BottomState=true;
|
||||
m_RightState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_BottomState=false;
|
||||
m_RightState=m_LeftState=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopRightBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_RightState=m_TopState=m_BottomState=true;
|
||||
m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::RightBottomLeft:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_RightState=m_LeftState=m_BottomState=true;
|
||||
m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::BottomLeftTop:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->BottomBorderWidth,(Qt::PenStyle)m_pCell->BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=m_LeftState=m_BottomState=true;
|
||||
m_RightState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftTopRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,m_pCell->LeftBorderWidth,(Qt::PenStyle)m_pCell->LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->TopBorderWidth,(Qt::PenStyle)m_pCell->TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,m_pCell->RightBorderWidth,(Qt::PenStyle)m_pCell->RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_LeftState=m_RightState=true;
|
||||
m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
default: //None
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
paint->restore();
|
||||
}
|
||||
|
||||
void BorderPreView::DrawBackgroundHorn(QPainter *paint)
|
||||
{
|
||||
QLineF line_topLeft1,line_topLeft2,line_bottomLeft1,line_bottomLeft2,
|
||||
line_topRight1,line_topRight2,line_bottomRight1,line_bottomRight2;
|
||||
QPointF point;
|
||||
QRect viewRect=rect();
|
||||
point=viewRect.topLeft();
|
||||
line_topLeft1.setP1(QPointF(point.x()+MARGIN_SIZE,point.y()+MARGIN_SIZE+LINECON_SZIE));
|
||||
line_topLeft1.setP2(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()+MARGIN_SIZE+LINECON_SZIE));
|
||||
|
||||
line_topLeft2.setP1(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()+MARGIN_SIZE));
|
||||
line_topLeft2.setP2(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()+MARGIN_SIZE+LINECON_SZIE));
|
||||
|
||||
|
||||
point=viewRect.bottomLeft();
|
||||
line_bottomLeft1.setP1(QPointF(point.x()+MARGIN_SIZE,point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
line_bottomLeft1.setP2(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
line_bottomLeft2.setP1(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()-MARGIN_SIZE));
|
||||
line_bottomLeft2.setP2(QPointF(point.x()+MARGIN_SIZE+LINECON_SZIE,point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
|
||||
point=viewRect.bottomRight();
|
||||
line_bottomRight1.setP1(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()-(MARGIN_SIZE)));
|
||||
line_bottomRight1.setP2(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
line_bottomRight2.setP1(QPointF(point.x()-(MARGIN_SIZE),point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
line_bottomRight2.setP2(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()-(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
|
||||
point=viewRect.topRight();
|
||||
line_topRight1.setP1(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()+(MARGIN_SIZE)));
|
||||
line_topRight1.setP2(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()+(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
line_topRight2.setP1(QPointF(point.x()-(MARGIN_SIZE),point.y()+(MARGIN_SIZE+LINECON_SZIE)));
|
||||
line_topRight2.setP2(QPointF(point.x()-(MARGIN_SIZE+LINECON_SZIE),point.y()+(MARGIN_SIZE+LINECON_SZIE)));
|
||||
|
||||
|
||||
paint->save();
|
||||
paint->drawLine(line_topLeft1);
|
||||
paint->drawLine(line_topLeft2);
|
||||
paint->drawLine(line_bottomLeft1);
|
||||
paint->drawLine(line_bottomLeft2);
|
||||
paint->drawLine(line_topRight1);
|
||||
paint->drawLine(line_topRight2);
|
||||
paint->drawLine(line_bottomRight1);
|
||||
paint->drawLine(line_bottomRight2);
|
||||
paint->restore();
|
||||
}
|
||||
|
||||
void BorderPreView::mouseReleaseEvent(QMouseEvent *pEvt)
|
||||
{
|
||||
ClickBorder(pEvt->pos());
|
||||
}
|
||||
|
||||
void BorderPreView::ClickBorder(QPointF point)
|
||||
{
|
||||
// CSheet* pHeadSheet =NULL;
|
||||
// if(m_pDigitizer->m_bSelectGraphicsHead)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetHeadSheet( m_pDigitizer->m_curGraphicsHeadSheetIndex );
|
||||
// }else if(m_pDigitizer->m_bSelectGraphicsFoot)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetFootSheet( m_pDigitizer->m_curGraphicsFootSheetIndex );
|
||||
// }
|
||||
|
||||
QMap<BorderDirect,QRectF>::const_iterator itor= m_AreaEventHandler.constBegin();
|
||||
BorderDirect bdirect=BorderDirect::None;
|
||||
QRectF rectEvt;
|
||||
FormTableItem *m_pCell=NULL;
|
||||
if(m_pCelll) m_pCell=m_pCelll;
|
||||
// else {
|
||||
// m_pSheet=pHeadSheet;
|
||||
// if(m_pSheet)m_pCell=m_pSheet->GetSelGraphicsHeadCell();
|
||||
// }
|
||||
|
||||
if(!m_pCell) return;
|
||||
for (;itor!=m_AreaEventHandler.end();++itor)
|
||||
{
|
||||
rectEvt= itor.value();
|
||||
if (rectEvt.contains(point))
|
||||
{
|
||||
bdirect=itor.key();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (bdirect !=None)
|
||||
{
|
||||
switch(bdirect)
|
||||
{
|
||||
case CellTop:
|
||||
if (m_selectCurrentStyle !=-1 && m_selectCurrentLineWidth !=-1)
|
||||
{
|
||||
m_pCell->TopBorderStyle=m_selectCurrentStyle;
|
||||
m_pCell->TopBorderWidth=m_selectCurrentLineWidth;
|
||||
}
|
||||
if (!m_isBorderStyle)
|
||||
{
|
||||
m_TopState=!m_TopState;
|
||||
}else
|
||||
{
|
||||
m_isBorderStyle=false;
|
||||
}
|
||||
break;
|
||||
case CellRight:
|
||||
if (m_selectCurrentStyle !=-1 && m_selectCurrentLineWidth !=-1)
|
||||
{
|
||||
m_pCell->RightBorderStyle=m_selectCurrentStyle;
|
||||
m_pCell->RightBorderWidth=m_selectCurrentLineWidth;
|
||||
|
||||
}
|
||||
if (!m_isBorderStyle)
|
||||
{
|
||||
m_RightState=!m_RightState;
|
||||
}else
|
||||
{
|
||||
m_isBorderStyle=false;
|
||||
}
|
||||
break;
|
||||
case CellBottom:
|
||||
if (m_selectCurrentStyle !=-1 && m_selectCurrentLineWidth !=-1)
|
||||
{
|
||||
m_pCell->BottomBorderStyle=m_selectCurrentStyle;
|
||||
m_pCell->BottomBorderWidth=m_selectCurrentLineWidth;
|
||||
|
||||
}
|
||||
if (!m_isBorderStyle)
|
||||
{
|
||||
m_BottomState=!m_BottomState;
|
||||
}else
|
||||
{
|
||||
m_isBorderStyle=false;
|
||||
}
|
||||
break;
|
||||
case CellLeft:
|
||||
if (m_selectCurrentStyle !=-1 && m_selectCurrentLineWidth !=-1)
|
||||
{
|
||||
m_pCell->LeftBorderStyle=m_selectCurrentStyle;
|
||||
m_pCell->LeftBorderWidth=m_selectCurrentLineWidth;
|
||||
|
||||
}
|
||||
if (!m_isBorderStyle)
|
||||
{
|
||||
m_LeftState=!m_LeftState;
|
||||
}else
|
||||
{
|
||||
m_isBorderStyle=false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
BindBorderStates();
|
||||
}
|
||||
this->update();
|
||||
}
|
||||
|
||||
void BorderPreView::BindBorderStates()
|
||||
{
|
||||
// CSheet* pHeadSheet =NULL;
|
||||
// if(m_pDigitizer->m_bSelectGraphicsHead)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetHeadSheet( m_pDigitizer->m_curGraphicsHeadSheetIndex );
|
||||
// }else if(m_pDigitizer->m_bSelectGraphicsFoot)
|
||||
// {
|
||||
// pHeadSheet =m_pDigitizer->m_pDoc->GetFootSheet( m_pDigitizer->m_curGraphicsFootSheetIndex );
|
||||
// }
|
||||
|
||||
FormTableItem *m_pCell=NULL;
|
||||
if(m_pCelll) m_pCell=m_pCelll;
|
||||
// else {
|
||||
// m_pSheet=pHeadSheet;
|
||||
// if(m_pSheet)m_pCell=m_pSheet->GetSelGraphicsHeadCell();
|
||||
// }
|
||||
|
||||
if (!m_pCell)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isChkTop=m_TopState;//ui.btnTo->isChecked();
|
||||
bool isChkRight=m_RightState;//ui.btnRight->isChecked();
|
||||
bool isChkBottom=m_BottomState;//ui.btnBottom->isChecked();
|
||||
bool isChkLeft=m_LeftState;//ui.btnLeft->isChecked();
|
||||
FormTableItem::MetaBorder selBorder=FormTableItem::All;
|
||||
bool isAll = (isChkTop && isChkRight && isChkBottom && isChkLeft);
|
||||
bool isNone = (!isChkTop && !isChkRight && !isChkBottom && !isChkLeft);
|
||||
bool isTop = (isChkTop && !isChkRight && !isChkBottom && !isChkLeft);
|
||||
bool isRight = (!isChkTop && isChkRight && !isChkBottom && !isChkLeft);
|
||||
bool isBottom = (!isChkTop && !isChkRight && isChkBottom && !isChkLeft);
|
||||
bool isLeft = (!isChkTop && !isChkRight && !isChkBottom && isChkLeft);
|
||||
bool isTopRight = (isChkTop && isChkRight && !isChkBottom && !isChkLeft);
|
||||
bool isRightBottom = (!isChkTop && isChkRight && isChkBottom && !isChkLeft);
|
||||
bool isBottomLeft = (!isChkTop && !isChkRight && isChkBottom && isChkLeft);
|
||||
bool isLeftTop = (isChkTop && !isChkRight && !isChkBottom && isChkLeft);
|
||||
bool isTopBottom = (isChkTop && !isChkRight && isChkBottom && !isChkLeft);
|
||||
bool isLeftRight = (!isChkTop && isChkRight && !isChkBottom && isChkLeft);
|
||||
bool isTopRightBottom = (isChkTop && isChkRight && isChkBottom && !isChkLeft);
|
||||
bool isRightBottomLeft = (!isChkTop && isChkRight && isChkBottom && isChkLeft);
|
||||
bool isBottomLeftTop = (isChkTop && !isChkRight && isChkBottom && isChkLeft);
|
||||
bool isLeftTopRight = (isChkTop && isChkRight && !isChkBottom && isChkLeft);
|
||||
|
||||
if (isAll)
|
||||
{
|
||||
selBorder=FormTableItem::All;
|
||||
}
|
||||
if (isNone)
|
||||
{
|
||||
selBorder=FormTableItem::None;
|
||||
}
|
||||
if (isTop)
|
||||
{
|
||||
selBorder=FormTableItem::Top;
|
||||
}
|
||||
if (isRight)
|
||||
{
|
||||
selBorder=FormTableItem::Right;
|
||||
}
|
||||
if (isBottom)
|
||||
{
|
||||
selBorder=FormTableItem::Bottom;
|
||||
}
|
||||
if (isLeft)
|
||||
{
|
||||
selBorder=FormTableItem::Left;
|
||||
}
|
||||
if (isTopRight)
|
||||
{
|
||||
selBorder=FormTableItem::TopRight;
|
||||
}
|
||||
if (isRightBottom)
|
||||
{
|
||||
selBorder=FormTableItem::RightBottom;
|
||||
}
|
||||
if (isBottomLeft)
|
||||
{
|
||||
selBorder=FormTableItem::BottomLeft;
|
||||
}
|
||||
if (isLeftTop)
|
||||
{
|
||||
selBorder=FormTableItem::LeftTop;
|
||||
}
|
||||
if (isTopBottom)
|
||||
{
|
||||
selBorder=FormTableItem::TopBottom;
|
||||
}
|
||||
if (isLeftRight)
|
||||
{
|
||||
selBorder=FormTableItem::LeftRight;
|
||||
}
|
||||
if (isTopRightBottom)
|
||||
{
|
||||
selBorder=FormTableItem::TopRightBottom;
|
||||
}
|
||||
if (isRightBottomLeft)
|
||||
{
|
||||
selBorder=FormTableItem::RightBottomLeft;
|
||||
}
|
||||
if (isBottomLeftTop)
|
||||
{
|
||||
selBorder=FormTableItem::BottomLeftTop;
|
||||
}
|
||||
if (isLeftTopRight)
|
||||
{
|
||||
selBorder=FormTableItem::LeftTopRight;
|
||||
}
|
||||
m_pCell->m_drawBorder=selBorder;
|
||||
//if(m_pSheet)m_pSheet->SetFormBorders(m_pCell);
|
||||
}
|
||||
|
||||
|
||||
void BorderPreView::resizeEvent(QResizeEvent *pResizEvt)
|
||||
{
|
||||
if (pResizEvt->size().isValid())
|
||||
{
|
||||
m_ResetArea=true;
|
||||
}
|
||||
}
|
||||
|
||||
void BorderPreView::slotSelectLineStyleChanged(int style,int lineWidth)
|
||||
{
|
||||
m_selectCurrentStyle=style;
|
||||
m_selectCurrentLineWidth=lineWidth;
|
||||
}
|
||||
63
logPlus/BorderPreView.h
Normal file
63
logPlus/BorderPreView.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef BORDERPREVIEW_H
|
||||
#define BORDERPREVIEW_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include <QRect>
|
||||
#include "formtableitem.h"
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
class BorderPreView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
enum BorderDirect
|
||||
{
|
||||
None=-1,
|
||||
CellTop=1,
|
||||
CellLeft=2,
|
||||
CellRight=3,
|
||||
CellBottom=4
|
||||
};
|
||||
|
||||
public:
|
||||
explicit BorderPreView(QWidget *parent=NULL);
|
||||
~BorderPreView();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
public:
|
||||
void SetCellObject(FormTableItem *pCell);
|
||||
void SetBorderStyle(int width,int style);
|
||||
|
||||
private slots:
|
||||
void slotSelectLineStyleChanged(int style,int lineWidth);
|
||||
|
||||
private:
|
||||
void DrawBackgroundHorn(QPainter *paint);
|
||||
void DrawBorderLines(QPainter *paint);
|
||||
void BuildBorderLines();
|
||||
|
||||
void BuidlClickEventAreas();
|
||||
|
||||
virtual void mouseReleaseEvent(QMouseEvent *);
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
void ClickBorder(QPointF point);
|
||||
void BindBorderStates();
|
||||
|
||||
private:
|
||||
QLineF m_LeftLine,m_TopLine,m_RightLine,m_BottomLine;
|
||||
bool m_TopState,m_RightState,m_BottomState,m_LeftState;
|
||||
QMap<BorderDirect,QRectF> m_AreaEventHandler;
|
||||
|
||||
FormTableItem* m_pCelll;
|
||||
int m_selectCurrentStyle;
|
||||
int m_selectCurrentLineWidth;
|
||||
//
|
||||
bool m_isBorderStyle;
|
||||
bool m_ResetArea;
|
||||
};
|
||||
|
||||
#endif // BORDERPREVIEW_H
|
||||
93
logPlus/CellBorderDalog.ui
Normal file
93
logPlus/CellBorderDalog.ui
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CellBorder</class>
|
||||
<widget class="QDialog" name="CellBorder">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>667</width>
|
||||
<height>414</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>边框线形设置</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="btnAccess">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>360</x>
|
||||
<y>330</y>
|
||||
<width>301</width>
|
||||
<height>71</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>确定</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>9</x>
|
||||
<y>9</y>
|
||||
<width>331</width>
|
||||
<height>391</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>线条及线型</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="LineStyleView" name="lineGridView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>360</x>
|
||||
<y>10</y>
|
||||
<width>300</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>预览</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="BorderPreView" name="preView" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LineStyleView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header location="global">linestyleview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BorderPreView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">borderpreview.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
33
logPlus/CellBorderDlg.cpp
Normal file
33
logPlus/CellBorderDlg.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#include "CellBorderDlg.h"
|
||||
#include <QPainter>
|
||||
|
||||
CellBorderDlg::CellBorderDlg(FormTableItem *pCell, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
|
||||
ui.preView->SetCellObject(pCell);
|
||||
//setWindowTitle(QString::fromLocal8Bit("边框线形设置"));
|
||||
connect(ui.btnAccess,SIGNAL(clicked()),this,SLOT(onEnter()));
|
||||
connect(ui.lineGridView,SIGNAL(signalSelectLineStyleChanged(int,int)),
|
||||
this,SLOT(OnSelectLineStyleChanged(int,int)));
|
||||
}
|
||||
|
||||
CellBorderDlg::~CellBorderDlg()
|
||||
{
|
||||
|
||||
}
|
||||
void CellBorderDlg::OnSelectLineStyleChanged(int style,int lineWidth)
|
||||
{
|
||||
ui.preView->SetBorderStyle(lineWidth,style);
|
||||
|
||||
}
|
||||
void CellBorderDlg::onEnter()
|
||||
{
|
||||
this->accept();
|
||||
}
|
||||
|
||||
void CellBorderDlg::paintEvent(QPaintEvent *pevt)
|
||||
{
|
||||
QDialog::paintEvent(pevt);
|
||||
}
|
||||
28
logPlus/CellBorderDlg.h
Normal file
28
logPlus/CellBorderDlg.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#ifndef CELLBORDERDLG_H
|
||||
#define CELLBORDERDLG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_CellBorderDalog.h"
|
||||
#include "formtableitem.h"
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
//单元格边框选中对话框
|
||||
class CellBorderDlg : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CellBorderDlg(FormTableItem *m_pCell, QWidget *parent = 0);
|
||||
~CellBorderDlg();
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *pevt);
|
||||
private slots:
|
||||
void OnSelectLineStyleChanged(int ,int);
|
||||
void onEnter();
|
||||
|
||||
private:
|
||||
Ui::CellBorder ui;
|
||||
};
|
||||
|
||||
#endif // CELLBORDERDLG_H
|
||||
179
logPlus/LineStyleView.cpp
Normal file
179
logPlus/LineStyleView.cpp
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
#include "LineStyleView.h"
|
||||
#include <QAbstractTableModel>
|
||||
#include <QScrollBar>
|
||||
#include <QHeaderView>
|
||||
#include <QPainter>
|
||||
#include <QPaintEvent>
|
||||
#include <QDebug>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
class LineStyleModel:public QAbstractTableModel
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
explicit LineStyleModel(QObject *parent=NULL):
|
||||
QAbstractTableModel(parent){
|
||||
m_PenList
|
||||
<<(int) Qt::SolidLine
|
||||
<<(int)Qt::DashLine
|
||||
<<(int) Qt::DotLine
|
||||
<<(int)Qt::DashDotLine
|
||||
<<(int) Qt::DashDotDotLine;
|
||||
|
||||
}
|
||||
~LineStyleModel(){}
|
||||
// QAbstractItemModel interface
|
||||
public:
|
||||
virtual int rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
virtual int columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
virtual QVariant data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(!index.isValid() || index.row() <0 ||index.column() <0)
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if(role == Qt::DisplayRole)
|
||||
{
|
||||
return m_PenList.at(index.row());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
private:
|
||||
QList<int> m_PenList;
|
||||
};
|
||||
|
||||
class LineItemStyleDelegate:public QStyledItemDelegate
|
||||
{
|
||||
public:
|
||||
LineItemStyleDelegate(QObject *parent=NULL):QStyledItemDelegate(parent) {
|
||||
|
||||
}
|
||||
~LineItemStyleDelegate(){}
|
||||
// QAbstractItemDelegate interface
|
||||
public:
|
||||
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
|
||||
// QStyledItemDelegate::paint(painter,option,index);
|
||||
QStyleOptionViewItemV3 v3=option;
|
||||
QWidget *widget= (QWidget*)v3.widget;
|
||||
QTableView* view=qobject_cast<QTableView*>(widget);
|
||||
int colIndex=index.column();
|
||||
|
||||
QPen linePen;
|
||||
QPointF p1,p2,pCenter;
|
||||
QRect cellRect=option.rect;
|
||||
Qt::PenStyle pStyle= (Qt::PenStyle)index.data(Qt::DisplayRole).value<int>();
|
||||
if(view)
|
||||
{
|
||||
QModelIndex curIndex=view->currentIndex();
|
||||
if(curIndex == index)
|
||||
{
|
||||
painter->save();
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(Qt::lightGray);
|
||||
painter->drawRect(cellRect);
|
||||
painter->restore();
|
||||
}
|
||||
}
|
||||
//if(pStyle == Qt::NoPen)
|
||||
//{
|
||||
// painter->drawText(cellRect,QString::fromLocal8Bit("无"),QTextOption(Qt::AlignCenter|Qt::AlignVCenter));
|
||||
//}
|
||||
linePen=painter->pen();
|
||||
linePen.setWidthF(colIndex+1);
|
||||
linePen.setStyle(pStyle);
|
||||
//if(pStyle != Qt::NoPen)
|
||||
painter->setPen(linePen);
|
||||
|
||||
pCenter=cellRect.center();
|
||||
cellRect= cellRect.adjusted(10,0,-10,0);
|
||||
p1.setX(cellRect.left());
|
||||
p1.setY(pCenter.y());
|
||||
|
||||
p2.setX(cellRect.right());
|
||||
p2.setY(pCenter.y());
|
||||
//if(pStyle != Qt::NoPen)
|
||||
painter->drawLine(p1,p2);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
LineStyleView::LineStyleView(QWidget *parent)
|
||||
: QTableView(parent),m_currentStyle((int)Qt::SolidLine),m_currentLineWidth(1)
|
||||
{
|
||||
horizontalHeader()->setVisible(false);
|
||||
verticalHeader()->setVisible(false);
|
||||
horizontalScrollBar()->setVisible(false);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setGridStyle(Qt::NoPen);
|
||||
setSelectionMode(QAbstractItemView::SingleSelection);
|
||||
setSelectionBehavior(QAbstractItemView::SelectItems);
|
||||
setModel(new LineStyleModel(this));
|
||||
LineItemStyleDelegate *lineStyle=new LineItemStyleDelegate(this);
|
||||
setMouseTracking(true);
|
||||
setItemDelegate(lineStyle);
|
||||
connect(this,SIGNAL(pressed(const QModelIndex&)),this,SLOT(slotCellPressed(const QModelIndex&)));
|
||||
|
||||
}
|
||||
|
||||
LineStyleView::~LineStyleView()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void LineStyleView::slotCellPressed(const QModelIndex &mIndex)
|
||||
{
|
||||
int row=mIndex.row();
|
||||
int col=mIndex.column();
|
||||
if (row <0 || col <0 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
LineStyleModel* styleModel=dynamic_cast<LineStyleModel*>(model());
|
||||
if (!styleModel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int styleValue=styleModel->data(mIndex,Qt::DisplayRole).toInt();
|
||||
int lineWindth=mIndex.column()+1;
|
||||
if (m_currentStyle != styleValue || m_currentLineWidth !=lineWindth)
|
||||
{
|
||||
m_currentStyle=styleValue;
|
||||
m_currentLineWidth=lineWindth;
|
||||
emit signalSelectLineStyleChanged(styleValue,lineWindth);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void LineStyleView::resizeEvent(QResizeEvent *reSize)
|
||||
{
|
||||
if(reSize->size().isValid())
|
||||
{
|
||||
int h=reSize->size().height();
|
||||
int w=reSize->size().width();
|
||||
int count= model()->columnCount();
|
||||
int sValue=w/(float)count;
|
||||
for(int j=0;j<count;j++)
|
||||
{
|
||||
setColumnWidth(j,sValue);
|
||||
}
|
||||
|
||||
count= model()->rowCount();
|
||||
sValue=h/(float)count;
|
||||
for(int i=0;i<count;i++)
|
||||
{
|
||||
setRowHeight(i,sValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
#include "PropertyWidget.h"
|
||||
#include "geometryutils.h"
|
||||
#include "qtprojectwidgets.h"
|
||||
#include "CellBorderDlg.h"
|
||||
|
||||
//extern int g_iRows;
|
||||
//extern int g_iCols;
|
||||
|
|
@ -56,6 +57,8 @@ FormHead::FormHead(QWidget *parent, QString indexID) :
|
|||
|
||||
//ui->tableWidget->setSizeAdjustPolicy(QTableWidget::AdjustToContents); //表格大小随内容改变,会占满
|
||||
|
||||
//隐藏网格线
|
||||
ui->tableWidget->setShowGrid(false);
|
||||
//
|
||||
ui->tableWidget->verticalHeader()->hide(); //行
|
||||
ui->tableWidget->horizontalHeader()->hide(); //列
|
||||
|
|
@ -532,6 +535,66 @@ void FormHead::DisplayItems(QJsonArray itemsArray, bool bMultiProject)
|
|||
formTableItemTmp->m_strShowTxt = computeCellResult;
|
||||
}
|
||||
|
||||
//边框
|
||||
if (itemObj.contains("drawBorder"))
|
||||
{
|
||||
formTableItemTmp->m_drawBorder = (FormTableItem::MetaBorder)itemObj["drawBorder"].toInt();
|
||||
}
|
||||
|
||||
//线宽
|
||||
if (itemObj.contains("TopBorderWidth"))
|
||||
{
|
||||
formTableItemTmp->TopBorderWidth = itemObj["TopBorderWidth"].toInt();
|
||||
}
|
||||
if (itemObj.contains("RightBorderWidth"))
|
||||
{
|
||||
formTableItemTmp->RightBorderWidth = itemObj["RightBorderWidth"].toInt();
|
||||
}
|
||||
if (itemObj.contains("BottomBorderWidth"))
|
||||
{
|
||||
formTableItemTmp->BottomBorderWidth = itemObj["BottomBorderWidth"].toInt();
|
||||
}
|
||||
if (itemObj.contains("LeftBorderWidth"))
|
||||
{
|
||||
formTableItemTmp->LeftBorderWidth = itemObj["LeftBorderWidth"].toInt();
|
||||
}
|
||||
|
||||
//线形
|
||||
if (itemObj.contains("TopBorderStyle"))
|
||||
{
|
||||
formTableItemTmp->TopBorderStyle = itemObj["TopBorderStyle"].toInt();
|
||||
}
|
||||
if (itemObj.contains("RightBorderStyle"))
|
||||
{
|
||||
formTableItemTmp->RightBorderStyle = itemObj["RightBorderStyle"].toInt();
|
||||
}
|
||||
if (itemObj.contains("BottomBorderStyle"))
|
||||
{
|
||||
formTableItemTmp->BottomBorderStyle = itemObj["BottomBorderStyle"].toInt();
|
||||
}
|
||||
if (itemObj.contains("LeftBorderStyle"))
|
||||
{
|
||||
formTableItemTmp->LeftBorderStyle = itemObj["LeftBorderStyle"].toInt();
|
||||
}
|
||||
|
||||
//是否显示
|
||||
if (itemObj.contains("TopState"))
|
||||
{
|
||||
formTableItemTmp->m_TopState = itemObj["TopState"].toBool();
|
||||
}
|
||||
if (itemObj.contains("RightState"))
|
||||
{
|
||||
formTableItemTmp->m_RightState = itemObj["RightState"].toBool();
|
||||
}
|
||||
if (itemObj.contains("BottomState"))
|
||||
{
|
||||
formTableItemTmp->m_BottomState = itemObj["BottomState"].toBool();
|
||||
}
|
||||
if (itemObj.contains("LeftState"))
|
||||
{
|
||||
formTableItemTmp->m_LeftState = itemObj["LeftState"].toBool();
|
||||
}
|
||||
|
||||
//刷新,重新调整字体高度等
|
||||
formTableItemTmp->update();
|
||||
|
||||
|
|
@ -722,6 +785,23 @@ QJsonObject FormHead::makeJson()
|
|||
formHeadObj["WellName"] = strWellName;
|
||||
formHeadObj["FormulaType"] = iFormulaType;
|
||||
formHeadObj["VerticaDrawing"] = formTableItemTmp->m_bVerticaDrawing;
|
||||
//
|
||||
formHeadObj["drawBorder"] = (int)formTableItemTmp->m_drawBorder;
|
||||
formHeadObj["TopBorderWidth"] = formTableItemTmp->TopBorderWidth;
|
||||
formHeadObj["RightBorderWidth"] = formTableItemTmp->RightBorderWidth;
|
||||
formHeadObj["BottomBorderWidth"] = formTableItemTmp->BottomBorderWidth;
|
||||
formHeadObj["LeftBorderWidth"] = formTableItemTmp->LeftBorderWidth;
|
||||
//
|
||||
formHeadObj["TopBorderStyle"] = formTableItemTmp->TopBorderStyle;
|
||||
formHeadObj["RightBorderStyle"] = formTableItemTmp->RightBorderStyle;
|
||||
formHeadObj["BottomBorderStyle"] = formTableItemTmp->BottomBorderStyle;
|
||||
formHeadObj["LeftBorderStyle"] = formTableItemTmp->LeftBorderStyle;
|
||||
//
|
||||
formHeadObj["TopState"] = formTableItemTmp->m_TopState;
|
||||
formHeadObj["RightState"] = formTableItemTmp->m_RightState;
|
||||
formHeadObj["BottomState"] = formTableItemTmp->m_BottomState;
|
||||
formHeadObj["LeftState"] = formTableItemTmp->m_LeftState;
|
||||
|
||||
}
|
||||
subcaseArray.append(formHeadObj);
|
||||
}
|
||||
|
|
@ -794,6 +874,7 @@ void FormHead::slotContextMenu(QPoint pos)
|
|||
menu.addSeparator();
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/MergeCell.png"), "合并单元格", this, &FormHead::slotMerge);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/Grid.png"), "拆分单元格", this, &FormHead::slotSplit);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/Grid.png"), "边框", this, &FormHead::slotCellBorder);
|
||||
menu.addSeparator();
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddRow.png"), "前插入行", this, &FormHead::slotAddRow);
|
||||
menu.addAction(QIcon(::GetImagePath() + "icon/AddRow.png"), "后插入行", this, &FormHead::slotAddAfterRow);
|
||||
|
|
@ -854,6 +935,45 @@ void FormHead::slotMerge()
|
|||
ui->tableWidget->setRowHeight(topRow, iHight);
|
||||
}
|
||||
|
||||
//边框
|
||||
void FormHead::slotCellBorder()
|
||||
{
|
||||
QModelIndexList list = ui->tableWidget->selectionModel()->selectedIndexes();
|
||||
if (list.size() != 1)
|
||||
{
|
||||
QMessageBox::warning(this, "边框设置", "请选择单个单元格", "确定");
|
||||
return;
|
||||
}
|
||||
|
||||
FormTableItem* formTableItemTmp = nullptr;
|
||||
int row = list[0].row();
|
||||
int column = list[0].column();
|
||||
if(row>=0 && column>=0)
|
||||
{
|
||||
auto myWidget = ui->tableWidget->cellWidget(row, column);
|
||||
if(myWidget)
|
||||
{
|
||||
formTableItemTmp = (FormTableItem*)myWidget;//获得widget
|
||||
}
|
||||
}
|
||||
if(!formTableItemTmp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CellBorderDlg dlgBorder(formTableItemTmp, this);
|
||||
dlgBorder.setFixedSize(QSize(667,414));
|
||||
dlgBorder.setModal(false);
|
||||
Qt::WindowFlags flags = dlgBorder.windowFlags();
|
||||
flags |= Qt::WindowStaysOnTopHint;
|
||||
flags &= ~Qt::WindowContextHelpButtonHint;
|
||||
dlgBorder.setWindowFlags(flags);
|
||||
dlgBorder.show();
|
||||
if(dlgBorder.exec()!=QDialog::Accepted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//拆分
|
||||
void FormHead::slotSplit()
|
||||
|
|
|
|||
|
|
@ -68,8 +68,10 @@ public slots:
|
|||
|
||||
//图头右键菜单响应函数
|
||||
void slotContextMenu(QPoint pos);
|
||||
//
|
||||
void slotMerge();//合并
|
||||
void slotSplit();//拆分
|
||||
void slotCellBorder();//拆分
|
||||
//
|
||||
void slotAddRow();//前插入行
|
||||
void slotAddAfterRow();//后插入行
|
||||
|
|
|
|||
|
|
@ -84,4 +84,230 @@ void FormTableItem::paintEvent(QPaintEvent* event)
|
|||
//文字
|
||||
painter.drawText(rt, Qt::AlignCenter, text);
|
||||
}
|
||||
|
||||
//边框
|
||||
BuildBorderLines();
|
||||
DrawBorderLines(&painter);
|
||||
}
|
||||
|
||||
void FormTableItem::BuildBorderLines()
|
||||
{
|
||||
int marginValue=0;
|
||||
int outVlaue=0;
|
||||
QPointF point,p1,p2;
|
||||
|
||||
QRect viewRect=rect();
|
||||
point=viewRect.topLeft();
|
||||
p1.setX(point.x()+marginValue);
|
||||
p1.setY(point.y()+marginValue+outVlaue);
|
||||
|
||||
point=viewRect.bottomLeft();
|
||||
p2.setX(point.x()+marginValue);
|
||||
p2.setY(point.y()-(marginValue+outVlaue));
|
||||
m_LeftLine.setP1(p1);
|
||||
m_LeftLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.topLeft();
|
||||
p1.setX(point.x()+marginValue+outVlaue);
|
||||
p1.setY(point.y()+marginValue);
|
||||
|
||||
point=viewRect.topRight();
|
||||
p2.setX(point.x()-(marginValue+outVlaue));
|
||||
p2.setY(point.y()+marginValue);
|
||||
m_TopLine.setP1(p1);
|
||||
m_TopLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.topRight();
|
||||
p1.setX(point.x()-marginValue);
|
||||
p1.setY(point.y()+(marginValue+outVlaue));
|
||||
|
||||
point=viewRect.bottomRight();
|
||||
p2.setX(point.x()-marginValue);
|
||||
p2.setY(point.y()-(marginValue+outVlaue));
|
||||
m_RightLine.setP1(p1);
|
||||
m_RightLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
point=viewRect.bottomRight();
|
||||
p1.setX(point.x()-(marginValue+outVlaue));
|
||||
p1.setY(point.y()-marginValue);
|
||||
|
||||
point=viewRect.bottomLeft();
|
||||
p2.setX(point.x()+marginValue+outVlaue);
|
||||
p2.setY(point.y()-marginValue);
|
||||
m_BottomLine.setP1(p1);
|
||||
m_BottomLine.setP2(p2);
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
}
|
||||
|
||||
void FormTableItem::DrawBorderLines(QPainter *paint)
|
||||
{
|
||||
paint->save();
|
||||
//
|
||||
switch(m_drawBorder)
|
||||
{
|
||||
case FormTableItem::All:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_TopState=m_RightState=m_BottomState=m_LeftState=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::Top:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=true;
|
||||
m_RightState=m_BottomState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Right:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_RightState=true;
|
||||
m_TopState=m_BottomState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Bottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_BottomState=true;
|
||||
m_TopState=m_RightState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::Left:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_LeftState=true;
|
||||
m_TopState=m_RightState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_RightState=true;
|
||||
m_LeftState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::RightBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_BottomState=m_RightState=true;
|
||||
m_LeftState=m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::BottomLeft:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_BottomState=m_LeftState=true;
|
||||
m_RightState=m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftTop:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=m_LeftState=true;
|
||||
m_RightState=m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_TopState=m_BottomState=true;
|
||||
m_RightState=m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_BottomState=false;
|
||||
m_RightState=m_LeftState=true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FormTableItem::TopRightBottom:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
m_RightState=m_TopState=m_BottomState=true;
|
||||
m_LeftState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::RightBottomLeft:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
m_RightState=m_LeftState=m_BottomState=true;
|
||||
m_TopState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::BottomLeftTop:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,BottomBorderWidth,(Qt::PenStyle)BottomBorderStyle));
|
||||
paint->drawLine(m_BottomLine);
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
m_TopState=m_LeftState=m_BottomState=true;
|
||||
m_RightState=false;
|
||||
}
|
||||
break;
|
||||
case FormTableItem::LeftTopRight:
|
||||
{
|
||||
paint->setPen(QPen(Qt::black,LeftBorderWidth,(Qt::PenStyle)LeftBorderStyle));
|
||||
paint->drawLine(m_LeftLine);
|
||||
paint->setPen(QPen(Qt::black,TopBorderWidth,(Qt::PenStyle)TopBorderStyle));
|
||||
paint->drawLine(m_TopLine);
|
||||
paint->setPen(QPen(Qt::black,RightBorderWidth,(Qt::PenStyle)RightBorderStyle));
|
||||
paint->drawLine(m_RightLine);
|
||||
m_TopState=m_LeftState=m_RightState=true;
|
||||
m_BottomState=false;
|
||||
}
|
||||
break;
|
||||
default: //None
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
//
|
||||
paint->restore();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,62 @@ public:
|
|||
|
||||
QString m_strSlfName = "";
|
||||
QString m_strWellName = "";
|
||||
|
||||
//单元格边线
|
||||
typedef enum _MetaBorder
|
||||
{
|
||||
// 全部显示
|
||||
All=1,
|
||||
// 不显示
|
||||
None,
|
||||
// 显示上边
|
||||
Top,
|
||||
// 显示右边
|
||||
Right,
|
||||
// 显示下边
|
||||
Bottom,
|
||||
// 显示左边
|
||||
Left,
|
||||
// 显示上边和右边
|
||||
TopRight,
|
||||
// 显示右边和下边
|
||||
RightBottom,
|
||||
// 显示下边和左边
|
||||
BottomLeft,
|
||||
// 显示左边和上边
|
||||
LeftTop,
|
||||
// 显示上边和下边
|
||||
TopBottom,
|
||||
// 显示左边和右边
|
||||
LeftRight,
|
||||
// 显示上边右边下边
|
||||
TopRightBottom,
|
||||
// 显示右边下边左边
|
||||
RightBottomLeft,
|
||||
// 显示下边左边上边
|
||||
BottomLeftTop,
|
||||
// 显示左边上边右边
|
||||
LeftTopRight
|
||||
|
||||
} MetaBorder;
|
||||
|
||||
// 单元格边框
|
||||
MetaBorder m_drawBorder=MetaBorder::All;
|
||||
// borderWidth 边框宽度
|
||||
int TopBorderWidth=1;
|
||||
int RightBorderWidth=1;
|
||||
int BottomBorderWidth=1;
|
||||
int LeftBorderWidth=1;
|
||||
//边框样式
|
||||
int TopBorderStyle=(int)Qt::SolidLine;
|
||||
int RightBorderStyle=(int)Qt::SolidLine;
|
||||
int BottomBorderStyle=(int)Qt::SolidLine;
|
||||
int LeftBorderStyle=(int)Qt::SolidLine;
|
||||
//
|
||||
QLineF m_LeftLine,m_TopLine,m_RightLine,m_BottomLine;
|
||||
bool m_TopState=true,m_RightState=true,m_BottomState=true,m_LeftState=true;
|
||||
void BuildBorderLines();
|
||||
void DrawBorderLines(QPainter *paint);
|
||||
};
|
||||
|
||||
#endif // FORMTABLEITEM_H
|
||||
|
|
|
|||
30
logPlus/linestyleview.h
Normal file
30
logPlus/linestyleview.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef LINESTYLEVIEW_H
|
||||
#define LINESTYLEVIEW_H
|
||||
|
||||
#include <QTableView>
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
|
||||
class LineStyleView :public QTableView
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
LineStyleView(QWidget *parent);
|
||||
~LineStyleView();
|
||||
signals:
|
||||
void signalSelectLineStyleChanged(int style,int lineWidth);
|
||||
|
||||
private slots:
|
||||
void slotCellPressed(const QModelIndex &mIndex);
|
||||
|
||||
// QWidget interface
|
||||
protected:
|
||||
virtual void resizeEvent(QResizeEvent *);
|
||||
private:
|
||||
int m_currentStyle;
|
||||
int m_currentLineWidth;
|
||||
|
||||
};
|
||||
|
||||
#endif // LINESTYLEVIEW_H
|
||||
|
|
@ -28,7 +28,9 @@ CONFIG += c++11
|
|||
|
||||
SOURCES += \
|
||||
../common/geometryutils.cpp \
|
||||
BorderPreView.cpp \
|
||||
CallManage.cpp \
|
||||
CellBorderDlg.cpp \
|
||||
ConsoleOutputWidget.cpp \
|
||||
CurveLine.cpp \
|
||||
DepPairs.cpp \
|
||||
|
|
@ -38,6 +40,7 @@ SOURCES += \
|
|||
GeoIndicatorGenerator.cpp \
|
||||
InDefTableDlg.cpp \
|
||||
InterfaceWidget.cpp \
|
||||
LineStyleView.cpp \
|
||||
LogmudItemDrawer.cpp \
|
||||
LogmudResultItem.cpp \
|
||||
MyGraphicsView.cpp \
|
||||
|
|
@ -105,7 +108,9 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
../common/geometryutils.h \
|
||||
BorderPreView.h \
|
||||
CallManage.h \
|
||||
CellBorderDlg.h \
|
||||
ConsoleOutputWidget.h \
|
||||
CurveLine.h \
|
||||
DepPairs.h \
|
||||
|
|
@ -116,6 +121,7 @@ HEADERS += \
|
|||
GeoIndicatorGenerator.h \
|
||||
InDefTableDlg.h \
|
||||
InterfaceWidget.h \
|
||||
LineStyleView.h \
|
||||
LogmudResultItem.h \
|
||||
LogmuditemDrawer.h \
|
||||
MyGraphicsView.h \
|
||||
|
|
@ -181,6 +187,7 @@ HEADERS += \
|
|||
wellheader.h
|
||||
|
||||
FORMS += \
|
||||
CellBorderDalog.ui \
|
||||
InDefTable.ui \
|
||||
SetPageMeg.ui \
|
||||
chooseShiftCurves.ui \
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user