293 lines
8.7 KiB
C++
293 lines
8.7 KiB
C++
|
|
#include "dataPanel.h"
|
|||
|
|
#include "ui_panelToolWidget.h"
|
|||
|
|
|
|||
|
|
#include "panelConfigurationWidget.h"
|
|||
|
|
#include "customBorderContainer.h"
|
|||
|
|
#include "customMenu.h"
|
|||
|
|
|
|||
|
|
#include <QKeyEvent>
|
|||
|
|
#include <QBoxLayout>
|
|||
|
|
#include <QScrollArea>
|
|||
|
|
#include <QPainter>
|
|||
|
|
|
|||
|
|
PanelToolWidget::PanelToolWidget(QWidget* parent)
|
|||
|
|
:QWidget(parent)
|
|||
|
|
, ui(new Ui::panelToolWidget)
|
|||
|
|
{
|
|||
|
|
ui->setupUi(this);
|
|||
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::SubWindow);
|
|||
|
|
|
|||
|
|
ui->btnFullScree->setProperty("currentState", "enterFullScreen");
|
|||
|
|
}
|
|||
|
|
PanelToolWidget::~PanelToolWidget()
|
|||
|
|
{
|
|||
|
|
delete ui;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
DataPanel::DataPanel(QWidget *parent)
|
|||
|
|
: QDialog(parent)
|
|||
|
|
{
|
|||
|
|
setWindowFlags(Qt::FramelessWindowHint | Qt::SubWindow);
|
|||
|
|
|
|||
|
|
m_strName = "";
|
|||
|
|
m_bMouseEnter = false;
|
|||
|
|
m_pContentWidget = nullptr;
|
|||
|
|
m_pScrollArea = nullptr;
|
|||
|
|
m_pLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
|||
|
|
m_pLayout->setContentsMargins(0, 0, 0, 0);
|
|||
|
|
m_pLayout->setSpacing(0);
|
|||
|
|
setLayout(m_pLayout);
|
|||
|
|
|
|||
|
|
m_pConfigurationWidget = new PanelConfigurationWidget();
|
|||
|
|
setWiget(m_pConfigurationWidget);
|
|||
|
|
resize(533, 300);
|
|||
|
|
|
|||
|
|
m_pCustomBorderContainer = new CustomBorderContainer(this);
|
|||
|
|
m_pCustomBorderContainer->setOperationOption(CustomBorderContainer::WidgetMovable | CustomBorderContainer::WidgetResizable | CustomBorderContainer::WidgetAutoAdjustGeometry);
|
|||
|
|
|
|||
|
|
m_pToolWidget = new PanelToolWidget(this);
|
|||
|
|
connect(m_pToolWidget->ui->btnSetting, SIGNAL(clicked()), this, SLOT(onToolBtnClicked_setting()));
|
|||
|
|
connect(m_pToolWidget->ui->btnFullScree, SIGNAL(clicked()), this, SLOT(onToolBtnClicked_fullScreen()));
|
|||
|
|
connect(m_pToolWidget->ui->btnMenu, SIGNAL(clicked()), this, SLOT(onToolBtnClicked_menu()));
|
|||
|
|
m_pToolWidget->raise();
|
|||
|
|
|
|||
|
|
m_pToolMenu = new CustomMenu(this);
|
|||
|
|
connect(m_pToolMenu, SIGNAL(aboutToHide()), this, SLOT(onAboutToHide_toolMenu()));
|
|||
|
|
m_pToolMenu->addAction(QString::fromWCharArray(L"移除面板"), this, SLOT(onAction_remove()));
|
|||
|
|
//m_pToolMenu->addAction(QString::fromWCharArray(L"放置最前"), this, SLOT(onAction_moveToFront()));
|
|||
|
|
m_pToolMenu->addAction(QString::fromWCharArray(L"放置最后"), this, SLOT(onAction_moveToBack()));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
DataPanel::~DataPanel()
|
|||
|
|
{
|
|||
|
|
// if(m_pToolMenu)
|
|||
|
|
// {
|
|||
|
|
// delete m_pToolMenu;
|
|||
|
|
// m_pToolMenu = nullptr;
|
|||
|
|
// }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
bool DataPanel::event(QEvent* event)
|
|||
|
|
{
|
|||
|
|
if(event->type() == QEvent::KeyPress)
|
|||
|
|
{
|
|||
|
|
QKeyEvent* pKeyEvent = static_cast<QKeyEvent*>(event);
|
|||
|
|
if (pKeyEvent->key() == Qt::Key_Escape)
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
else if(event->type() == QEvent::Resize)
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->move(this->width() - m_pToolWidget->width() - 8, 3);
|
|||
|
|
}
|
|||
|
|
else if(event->type() == QEvent::MouseButtonPress)
|
|||
|
|
{
|
|||
|
|
raise();
|
|||
|
|
}
|
|||
|
|
else if(event->type() == QEvent::Enter)
|
|||
|
|
{
|
|||
|
|
//qDebug() << "Enter";
|
|||
|
|
m_pToolWidget->show();
|
|||
|
|
QString strCurState = m_pToolWidget->ui->btnFullScree->property("currentState").toString();
|
|||
|
|
if(strCurState == "enterFullScreen")
|
|||
|
|
m_pCustomBorderContainer->showBorderDraw();
|
|||
|
|
}
|
|||
|
|
else if(event->type() == QEvent::Leave)
|
|||
|
|
{
|
|||
|
|
//qDebug() << "Leave";
|
|||
|
|
if(!m_pToolMenu->isVisible())
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->hide();
|
|||
|
|
m_pCustomBorderContainer->hideBorderDraw();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return QDialog::event(event);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/*void DataPanel::keyPressEvent(QKeyEvent* e)
|
|||
|
|
{
|
|||
|
|
if(e->key() == Qt::Key_Escape)
|
|||
|
|
return;
|
|||
|
|
else
|
|||
|
|
return QDialog::keyPressEvent(e);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::mousePressEvent(QMouseEvent* e)
|
|||
|
|
{
|
|||
|
|
Q_UNUSED(e);
|
|||
|
|
raise(); //设置为SubWindow后,需要手动置顶
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::enterEvent(QEnterEvent* e)
|
|||
|
|
{
|
|||
|
|
Q_UNUSED(e);
|
|||
|
|
m_pToolWidget->show();
|
|||
|
|
QString strCurState = m_pToolWidget->ui->btnFullScree->property("currentState").toString();
|
|||
|
|
if(strCurState == "enterFullScreen")
|
|||
|
|
m_pCustomBorderContainer->showBorderDraw();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::leaveEvent(QEvent* e)
|
|||
|
|
{
|
|||
|
|
Q_UNUSED(e);
|
|||
|
|
if(!m_pToolMenu->mouseIsInside()) //打开menu后鼠标会离开进入menu
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->hide();
|
|||
|
|
if(m_pToolMenu->isVisible())
|
|||
|
|
m_pToolMenu->hide();
|
|||
|
|
m_pCustomBorderContainer->hideBorderDraw();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::resizeEvent(QResizeEvent* e)
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->move(this->width() - m_pToolWidget->width() - 8, 3);
|
|||
|
|
}*/
|
|||
|
|
|
|||
|
|
void DataPanel::setupScrollArea()
|
|||
|
|
{
|
|||
|
|
if(m_pScrollArea == nullptr)
|
|||
|
|
{
|
|||
|
|
m_pScrollArea = new QScrollArea(this);
|
|||
|
|
m_pScrollArea->setWidgetResizable(true);
|
|||
|
|
m_pLayout->addWidget(m_pScrollArea);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::autoSetGeometry()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::setWiget(QWidget* pWidget, eInsertMode InsertMode)
|
|||
|
|
{
|
|||
|
|
if(m_pContentWidget)
|
|||
|
|
{
|
|||
|
|
QWidget* w = takeWidget();
|
|||
|
|
if(w)
|
|||
|
|
delete w;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QScrollArea* scrollAreaWiget = qobject_cast<QScrollArea*>(pWidget);
|
|||
|
|
if(scrollAreaWiget || InsertMode == ForceNoScrollArea)
|
|||
|
|
{
|
|||
|
|
m_pLayout->addWidget(pWidget);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
setupScrollArea();
|
|||
|
|
m_pScrollArea->setWidget(pWidget);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
m_pContentWidget = pWidget;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
QWidget* DataPanel::takeWidget()
|
|||
|
|
{
|
|||
|
|
QWidget* w = nullptr;
|
|||
|
|
if(m_pScrollArea)
|
|||
|
|
{
|
|||
|
|
m_pLayout->removeWidget(m_pScrollArea);
|
|||
|
|
w = m_pScrollArea->takeWidget();
|
|||
|
|
delete m_pScrollArea;
|
|||
|
|
m_pScrollArea = nullptr;
|
|||
|
|
m_pContentWidget = nullptr;
|
|||
|
|
}
|
|||
|
|
else if(m_pContentWidget)
|
|||
|
|
{
|
|||
|
|
m_pLayout->removeWidget(m_pContentWidget);
|
|||
|
|
w = m_pContentWidget;
|
|||
|
|
m_pContentWidget = nullptr;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if(w)
|
|||
|
|
w->setParent(nullptr);
|
|||
|
|
|
|||
|
|
return w;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::setName(const QString& strName)
|
|||
|
|
{
|
|||
|
|
m_strName = strName;
|
|||
|
|
}
|
|||
|
|
const QString& DataPanel::getName()
|
|||
|
|
{
|
|||
|
|
return m_strName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::onToolBtnClicked_setting()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::onToolBtnClicked_fullScreen()
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
QString strCurState = m_pToolWidget->ui->btnFullScree->property("currentState").toString();
|
|||
|
|
if(strCurState == "enterFullScreen")
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->ui->btnFullScree->setProperty("currentState", "exitFullScreen");
|
|||
|
|
m_pToolWidget->ui->btnFullScree->setStyleSheet("QPushButton{\n"
|
|||
|
|
" padding:3px;\n"
|
|||
|
|
" image: url(:/images/icon_exitfullscreen.png);\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QPushButton:hover{\n"
|
|||
|
|
" padding:2px;\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QPushButton:pressed{\n"
|
|||
|
|
" padding:3px;\n"
|
|||
|
|
"}\n");
|
|||
|
|
m_pCustomBorderContainer->setOperationOption(CustomBorderContainer::WidgetNoOperation);
|
|||
|
|
m_pCustomBorderContainer->hideBorderDraw();
|
|||
|
|
m_curGeometry = geometry();
|
|||
|
|
setGeometry(0, 0, parentWidget()->width(), parentWidget()->height());
|
|||
|
|
}
|
|||
|
|
else if(strCurState == "exitFullScreen")
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->ui->btnFullScree->setProperty("currentState", "enterFullScreen");
|
|||
|
|
m_pToolWidget->ui->btnFullScree->setStyleSheet("QPushButton{\n"
|
|||
|
|
" padding:3px;\n"
|
|||
|
|
" image: url(:/images/icon_fullscreen.png);\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QPushButton:hover{\n"
|
|||
|
|
" padding:2px;\n"
|
|||
|
|
"}\n"
|
|||
|
|
"QPushButton:pressed{\n"
|
|||
|
|
" padding:3px;\n"
|
|||
|
|
"}\n");
|
|||
|
|
m_pCustomBorderContainer->setOperationOption(CustomBorderContainer::WidgetMovable | CustomBorderContainer::WidgetResizable | CustomBorderContainer::WidgetAutoAdjustGeometry);
|
|||
|
|
m_pCustomBorderContainer->showBorderDraw();
|
|||
|
|
setGeometry(m_curGeometry);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::onToolBtnClicked_menu()
|
|||
|
|
{
|
|||
|
|
QPoint originPoint = m_pToolWidget->mapToGlobal(QPoint(0, 0));
|
|||
|
|
int nX = originPoint.x() - (m_pToolMenu->width() - m_pToolWidget->width());
|
|||
|
|
int nY = originPoint.y() + m_pToolWidget->height() + 2;
|
|||
|
|
// m_pToolMenu->move(nX,nY);
|
|||
|
|
// m_pToolMenu->show();
|
|||
|
|
m_pToolMenu->popup(QPoint(nX, nY));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::onAction_remove()
|
|||
|
|
{
|
|||
|
|
emit sgl_remove(m_strName);
|
|||
|
|
}
|
|||
|
|
void DataPanel::onAction_moveToFront()
|
|||
|
|
{
|
|||
|
|
this->raise();
|
|||
|
|
}
|
|||
|
|
void DataPanel::onAction_moveToBack()
|
|||
|
|
{
|
|||
|
|
this->lower();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DataPanel::onAboutToHide_toolMenu()
|
|||
|
|
{
|
|||
|
|
m_pToolWidget->hide();
|
|||
|
|
m_pCustomBorderContainer->hideBorderDraw();
|
|||
|
|
}
|