267 lines
6.4 KiB
C++
267 lines
6.4 KiB
C++
/**
|
|
* @file PaiJobParameterItemWidget.cpp
|
|
* @brief 日志中参数设置界面
|
|
* @date: 2013-4-18
|
|
* @author: cuizh
|
|
*/
|
|
|
|
#include "PaiJobParameterItemWidget.h"
|
|
#include <QHBoxLayout>
|
|
#include <QScrollBar>
|
|
#include <QDebug>
|
|
#include <QMouseEvent>
|
|
#include <QPushButton>
|
|
#include <QLabel>
|
|
#include <QPainter>
|
|
|
|
using namespace pai::gui;
|
|
|
|
const int PADDING = 10; //边界内空隙,主要用于判断鼠标点是否位于边界附近
|
|
|
|
PaiJobParameterItemWidget::PaiJobParameterItemWidget(QWidget *pParent) : QWidget(pParent)
|
|
{
|
|
QPalette pal = palette();
|
|
pal.setColor(QPalette::Background, QColor("#daf5fe"));
|
|
setPalette(pal);
|
|
|
|
setWindowFlags(Qt::FramelessWindowHint);
|
|
setWindowModality(Qt::ApplicationModal);
|
|
this->resize(400,210);
|
|
|
|
SetWidgetLayout();
|
|
m_EnterFlag = false;
|
|
m_fixed = false;
|
|
m_press = false;
|
|
|
|
m_direction = NONE;
|
|
this->setMouseTracking(true);
|
|
}
|
|
|
|
PaiJobParameterItemWidget::~PaiJobParameterItemWidget()
|
|
{
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::SetWidgetLayout()
|
|
{
|
|
QHBoxLayout *phLayout = new QHBoxLayout;
|
|
m_pLable = new QLabel("Parameter",this);
|
|
m_pBtn = new QPushButton(QIcon(":/log_Error_drawingup.png"),tr(""),this);
|
|
m_pBtn->setStyleSheet("QPushButton{border: 0px solid red;border-radius:10px}");
|
|
m_pBtn->resize(10,15);
|
|
|
|
connect(m_pBtn,SIGNAL(clicked(bool)),this,SLOT(FixTheWidget(bool)));
|
|
|
|
phLayout->addWidget(m_pLable);
|
|
phLayout->addStretch(100);
|
|
phLayout->addWidget(m_pBtn);
|
|
|
|
m_pParamInfoTextEdit = new pai::gui::PaiParameTextEdit(this);
|
|
QVBoxLayout *pMainLayout = new QVBoxLayout;
|
|
pMainLayout->addLayout(phLayout);
|
|
pMainLayout->addWidget(m_pParamInfoTextEdit);
|
|
pMainLayout->setContentsMargins(5,4,5,5);
|
|
|
|
this->setLayout(pMainLayout);
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::FixTheWidget(bool /*fixed*/)
|
|
{
|
|
if(!m_fixed)
|
|
{
|
|
m_fixed = true;
|
|
m_pBtn->setIcon(QIcon(":/log_Error_drawingdown.png"));
|
|
}
|
|
else
|
|
{
|
|
m_fixed = false;
|
|
m_pBtn->setIcon(QIcon(":/log_Error_drawingup.png"));
|
|
}
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::enterEvent ( QEvent *pEvent)
|
|
{
|
|
QWidget::enterEvent(pEvent);
|
|
m_EnterFlag = true;
|
|
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::leaveEvent ( QEvent *pEvent)
|
|
{
|
|
QWidget::leaveEvent(pEvent);
|
|
m_EnterFlag = false;
|
|
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::SetParamEditInfo(const QString& text)
|
|
{
|
|
if(m_pParamInfoTextEdit)
|
|
{
|
|
m_pParamInfoTextEdit->setHtml(text);
|
|
}
|
|
}
|
|
|
|
bool PaiJobParameterItemWidget::GetMouseEnterWidgetFlag() const
|
|
{
|
|
return m_EnterFlag;
|
|
}
|
|
|
|
bool PaiJobParameterItemWidget::GetFixWidgetPosFlag() const
|
|
{
|
|
return m_fixed;
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::mouseMoveEvent(QMouseEvent * pEvent)
|
|
{
|
|
QPoint gloPoint = pEvent->globalPos();
|
|
QRect WidgetShowRect = this->rect();
|
|
QPoint tl = mapToGlobal(WidgetShowRect.topLeft());
|
|
QPoint rb = mapToGlobal(WidgetShowRect.bottomRight());
|
|
|
|
//鼠标没有按下情况
|
|
if(!m_press)
|
|
{
|
|
this->SetRegionCursorShape(gloPoint);
|
|
}
|
|
else //鼠标按下情况
|
|
{
|
|
if(m_direction != NONE)
|
|
{
|
|
QRect rMove(tl, rb);
|
|
|
|
switch(m_direction)
|
|
{
|
|
case RIGHT: //向右
|
|
rMove.setWidth(gloPoint.x() - tl.x());
|
|
break;
|
|
case DOWN: //向下
|
|
rMove.setHeight(gloPoint.y() - tl.y());
|
|
break;
|
|
case RIGHTBOTTOM: //右下
|
|
rMove.setWidth(gloPoint.x() - tl.x());
|
|
rMove.setHeight(gloPoint.y() - tl.y());
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
this->setGeometry(rMove);
|
|
}
|
|
else
|
|
{
|
|
pEvent->accept();
|
|
}
|
|
}
|
|
QWidget::mouseMoveEvent(pEvent);
|
|
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::mousePressEvent(QMouseEvent * pEvent)
|
|
{
|
|
switch(pEvent->button())
|
|
{
|
|
case Qt::LeftButton:
|
|
m_press = true;
|
|
if(m_direction != NONE)
|
|
{
|
|
this->mouseGrabber();
|
|
} else
|
|
{
|
|
m_DragPosition = pEvent->globalPos() - this->frameGeometry().topLeft();
|
|
}
|
|
break;
|
|
case Qt::RightButton:
|
|
break;
|
|
default:
|
|
QWidget::mousePressEvent(pEvent);
|
|
}
|
|
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::mouseReleaseEvent(QMouseEvent * pEvent)
|
|
{
|
|
if(pEvent->button() == Qt::LeftButton)
|
|
{
|
|
m_press = false;
|
|
if(m_direction != NONE)
|
|
{
|
|
this->releaseMouse();
|
|
this->setCursor(QCursor(Qt::ArrowCursor));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
QWidget::mouseReleaseEvent(pEvent);
|
|
}
|
|
}
|
|
|
|
void PaiJobParameterItemWidget::paintEvent(QPaintEvent *pEvent)
|
|
{
|
|
QPainter paint(this);
|
|
QPen pen;
|
|
pen.setWidth(1);
|
|
pen.setColor(QColor("#68bee6"));
|
|
paint.setPen(pen);
|
|
paint.drawLine(5,25,this->width() - 5,25);
|
|
|
|
paint.drawRect(1,1,this->width()-2.5,this->height()-2.5);
|
|
QWidget::paintEvent(pEvent);
|
|
}
|
|
|
|
|
|
void PaiJobParameterItemWidget::SetRegionCursorShape(const QPoint &cursorGlobalPoint)
|
|
{
|
|
QRect rect = this->rect();
|
|
QPoint rb = mapToGlobal(rect.bottomRight());
|
|
int x = cursorGlobalPoint.x();
|
|
int y = cursorGlobalPoint.y();
|
|
|
|
//设置光标显示形状
|
|
if(x >= rb.x() - PADDING && x <= rb.x() && y >= rb.y() - PADDING && y <= rb.y())
|
|
{
|
|
m_direction = RIGHTBOTTOM; //右下
|
|
this->setCursor(QCursor(Qt::SizeFDiagCursor));
|
|
}
|
|
else if( x <= rb.x() && x >= rb.x() - PADDING)
|
|
{
|
|
m_direction = RIGHT; //向右
|
|
this->setCursor(QCursor(Qt::SizeHorCursor));
|
|
}
|
|
else if(y <= rb.y() && y >= rb.y() - PADDING)
|
|
{
|
|
m_direction = DOWN; //向下
|
|
this->setCursor(QCursor(Qt::SizeVerCursor));
|
|
}
|
|
else
|
|
{
|
|
m_direction = NONE; //默认
|
|
this->setCursor(QCursor(Qt::ArrowCursor));
|
|
}
|
|
}
|
|
|
|
|
|
////////////////////////////class PaiParameTextEdit////////////////////////////////////
|
|
|
|
PaiParameTextEdit::PaiParameTextEdit(QWidget* parent ) : QTextEdit(parent)
|
|
{
|
|
this->setMouseTracking(true);
|
|
this->verticalScrollBar()->setMouseTracking(true);
|
|
this->verticalScrollBar()->installEventFilter(this);
|
|
}
|
|
PaiParameTextEdit::~PaiParameTextEdit()
|
|
{
|
|
}
|
|
|
|
bool PaiParameTextEdit::eventFilter(QObject *pObj, QEvent *pEvent)
|
|
{
|
|
QScrollBar* qQScrollBar = qobject_cast<QScrollBar*> (pObj);
|
|
if(qQScrollBar)
|
|
{
|
|
if(pEvent->type() == QEvent::MouseMove)
|
|
{
|
|
qQScrollBar->setCursor(QCursor(Qt::ArrowCursor)); //设置默认图标
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|