|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy,QMessageBox, QHBoxLayout, QWidget
|
|
|
|
|
from PyQt5.QtWidgets import QMainWindow, QDialog, QTabWidget, QPushButton, QSpacerItem, QSizePolicy\
|
|
|
|
|
,QMessageBox, QHBoxLayout, QWidget, QTabBar, QProxyStyle, QStyle
|
|
|
|
|
from PyQt5.QtGui import QIcon
|
|
|
|
|
from PyQt5.QtCore import QSize
|
|
|
|
|
|
|
|
|
@ -13,7 +14,212 @@ from utils.DBModels.DeviceModels import DeviceDB
|
|
|
|
|
from model.ProjectModel.DeviceManage import DevicesManange
|
|
|
|
|
from UI.DeviceDialogWidget import DeviceDialog
|
|
|
|
|
|
|
|
|
|
class DeviceWidget(QTabWidget):
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QStyleOptionTab, QTabBar, QWidget
|
|
|
|
|
from PyQt5.QtGui import QPainter, QPen, QColor, QPainterPath, QPolygonF, QFontMetrics, QTextOption, QFont
|
|
|
|
|
from PyQt5.QtCore import Qt, QRectF, QPointF
|
|
|
|
|
|
|
|
|
|
class NewChromeTabStyle(QProxyStyle):
|
|
|
|
|
def drawControl(self, element, option, painter, widget):
|
|
|
|
|
# painter.save()
|
|
|
|
|
# painter.setPen(Qt.red);
|
|
|
|
|
# painter.restore();
|
|
|
|
|
if element == QStyle.CE_TabBarTabLabel:
|
|
|
|
|
tab = option
|
|
|
|
|
# print(type(tab))
|
|
|
|
|
textRect = QRectF(self.subElementRect(QStyle.SE_TabBarTabText, tab, widget))
|
|
|
|
|
painter.save()
|
|
|
|
|
if (tab.state & QStyle.State_Selected):
|
|
|
|
|
painter.setPen(QPen(QColor("black")))
|
|
|
|
|
elif (tab.state & QStyle.State_MouseOver):
|
|
|
|
|
painter.setPen(QPen(QColor("black")))
|
|
|
|
|
else:
|
|
|
|
|
painter.setPen(QPen(QColor("black")))
|
|
|
|
|
option = QTextOption()
|
|
|
|
|
# 设置对齐方式,Qt.AlignLeft 和 Qt.AlignVCenter 分别对应左对齐和垂直居中
|
|
|
|
|
font = QFont();
|
|
|
|
|
font.setPointSize(20);
|
|
|
|
|
painter.setFont(font);
|
|
|
|
|
|
|
|
|
|
option.setAlignment(Qt.AlignCenter | Qt.AlignVCenter)
|
|
|
|
|
# 设置换行模式为不换行
|
|
|
|
|
option.setWrapMode(QTextOption.NoWrap)
|
|
|
|
|
painter.drawText(textRect, tab.text, option)
|
|
|
|
|
painter.restore()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif element == QStyle.CE_TabBarTabShape:
|
|
|
|
|
tab = option
|
|
|
|
|
painter.setRenderHint(QPainter.Antialiasing);
|
|
|
|
|
|
|
|
|
|
shapeRect = QRectF(tab.rect);
|
|
|
|
|
arcLen = shapeRect.height() / 2;
|
|
|
|
|
|
|
|
|
|
if (tab.state & QStyle.State_Selected):
|
|
|
|
|
painter.save();
|
|
|
|
|
pen = QPen(Qt.red);
|
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4);
|
|
|
|
|
|
|
|
|
|
path = QPainterPath();
|
|
|
|
|
|
|
|
|
|
arcRect1 = QRectF(shapeRect.x(),
|
|
|
|
|
shapeRect.y() + shapeRect.height() / 3,
|
|
|
|
|
arcLen,
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.moveTo(QPointF(arcRect1.x(),
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x() + arcRect1.width() / 2,
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
# // Starting from 270°, returning to the arc of 90°
|
|
|
|
|
path.arcTo(arcRect1, 270.0, 90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x() + arcRect1.width(),
|
|
|
|
|
arcRect1.y()));
|
|
|
|
|
|
|
|
|
|
arcRect2 = QRectF(shapeRect.x() + arcRect1.width(),
|
|
|
|
|
shapeRect.y(),
|
|
|
|
|
arcLen,
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
# // Starting from 180°, returning to the arc of -90°
|
|
|
|
|
path.arcTo(arcRect2, 180.0, -90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect2.x() + shapeRect.width() - 2 * (arcRect2.x() + arcRect2.width()) + arcRect2.width() / 2,
|
|
|
|
|
arcRect2.y()));
|
|
|
|
|
|
|
|
|
|
arcRect3 = QRectF(shapeRect.x() + shapeRect.width() - 2 * arcRect1.width(),
|
|
|
|
|
shapeRect.y(),
|
|
|
|
|
arcRect1.width(),
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect3, 90.0, -90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect3.x() + arcRect3.width(),
|
|
|
|
|
arcRect3.y() + arcRect3.height()));
|
|
|
|
|
|
|
|
|
|
arcRect4 = QRectF(arcRect3.x() + arcRect3.width(),
|
|
|
|
|
arcRect3.y() + arcRect3.height() / 2,
|
|
|
|
|
arcRect1.width(),
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect4, 180.0, 90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x(),
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
painter.setPen(Qt.NoPen);
|
|
|
|
|
painter.setBrush(Qt.blue);
|
|
|
|
|
polygon = path.toFillPolygon();
|
|
|
|
|
painter.drawPolygon(polygon);
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
elif (tab.state & QStyle.State_MouseOver):
|
|
|
|
|
painter.save();
|
|
|
|
|
pen = QPen(Qt.black);
|
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4);
|
|
|
|
|
|
|
|
|
|
path = QPainterPath()
|
|
|
|
|
|
|
|
|
|
arcRect1 = QRectF(shapeRect.x(),
|
|
|
|
|
shapeRect.y() + shapeRect.height() / 3,
|
|
|
|
|
arcLen,
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.moveTo(QPointF(arcRect1.x(),
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x() + arcRect1.width() / 2,
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect1, 270.0, 90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x() + arcRect1.width(),
|
|
|
|
|
arcRect1.y()));
|
|
|
|
|
|
|
|
|
|
arcRect2 = QRectF(shapeRect.x() + arcRect1.width(),
|
|
|
|
|
shapeRect.y(),
|
|
|
|
|
arcLen,
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect2, 180.0, -90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect2.x() + shapeRect.width() - 2 * (arcRect2.x() + arcRect2.width()) + arcRect2.width() / 2,
|
|
|
|
|
arcRect2.y()));
|
|
|
|
|
|
|
|
|
|
arcRect3 = QRectF(shapeRect.x() + shapeRect.width() - 2 * arcRect1.width(),
|
|
|
|
|
shapeRect.y(),
|
|
|
|
|
arcRect1.width(),
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect3, 90.0, -90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect3.x() + arcRect3.width(),
|
|
|
|
|
arcRect3.y() + arcRect3.height()));
|
|
|
|
|
|
|
|
|
|
arcRect4 = QRectF(arcRect3.x() + arcRect3.width(),
|
|
|
|
|
arcRect3.y() + arcRect3.height() / 2,
|
|
|
|
|
arcRect1.width(),
|
|
|
|
|
shapeRect.height() * 2 / 3);
|
|
|
|
|
|
|
|
|
|
path.arcTo(arcRect4, 180.0, 90.0);
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect1.x(),
|
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
painter.setPen(Qt.NoPen);
|
|
|
|
|
painter.setBrush(QColor("yellow"));
|
|
|
|
|
polygon = path.toFillPolygon();
|
|
|
|
|
painter.drawPolygon(polygon);
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen / 2);
|
|
|
|
|
|
|
|
|
|
pen = QPen(Qt.white);
|
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
else:
|
|
|
|
|
super(NewChromeTabStyle, self).drawControl(element, option, painter, widget);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceTabBar(QTabBar):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.setStyle(NewChromeTabStyle())
|
|
|
|
|
|
|
|
|
|
def tabSizeHint(self, index):
|
|
|
|
|
newSize = QTabBar().tabSizeHint(index)
|
|
|
|
|
width = len(self.tabText(index)) * 20 + 100
|
|
|
|
|
newSize.setWidth(width)
|
|
|
|
|
newSize.setHeight(40)
|
|
|
|
|
|
|
|
|
|
return newSize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DeviceTab(QTabWidget):
|
|
|
|
|
def __init__(self, dockWidget, devicesManange):
|
|
|
|
|
super().__init__()
|
|
|
|
|
self.dockWidget = dockWidget
|
|
|
|
@ -23,6 +229,8 @@ class DeviceWidget(QTabWidget):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initUI(self):
|
|
|
|
|
# self.tabBar = DeviceTabBar()
|
|
|
|
|
self.setTabBar(DeviceTabBar())
|
|
|
|
|
#获取DP、PA协议和主从模式
|
|
|
|
|
self.dataTypeAndModel = self.dockWidget.windowTitle()
|
|
|
|
|
self.proType = self.dataTypeAndModel[0:2]
|
|
|
|
@ -129,3 +337,5 @@ class DeviceWidget(QTabWidget):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|