|
|
@ -16,13 +16,14 @@ from UI.DeviceDialogWidget import DeviceDialog
|
|
|
|
|
|
|
|
|
|
|
|
from PyQt5.QtWidgets import QApplication, QStyleOptionTab, QTabBar, QWidget
|
|
|
|
from PyQt5.QtWidgets import QApplication, QStyleOptionTab, QTabBar, QWidget
|
|
|
|
from PyQt5.QtGui import QPainter, QPen, QColor, QPainterPath, QPolygonF, QFontMetrics, QTextOption, QFont
|
|
|
|
from PyQt5.QtGui import QPainter, QPen, QColor, QPainterPath, QPolygonF, QFontMetrics, QTextOption, QFont
|
|
|
|
from PyQt5.QtCore import Qt, QRectF, QPointF
|
|
|
|
from PyQt5.QtCore import Qt, QRectF, QPointF, QSizeF
|
|
|
|
|
|
|
|
|
|
|
|
class NewChromeTabStyle(QProxyStyle):
|
|
|
|
class NewChromeTabStyle(QProxyStyle):
|
|
|
|
def drawControl(self, element, option, painter, widget):
|
|
|
|
def drawControl(self, element, option, painter, widget):
|
|
|
|
# painter.save()
|
|
|
|
# painter.save()
|
|
|
|
# painter.setPen(Qt.red);
|
|
|
|
# painter.setPen(Qt.red);
|
|
|
|
# painter.restore();
|
|
|
|
# painter.restore();
|
|
|
|
|
|
|
|
margin = 4
|
|
|
|
if element == QStyle.CE_TabBarTabLabel:
|
|
|
|
if element == QStyle.CE_TabBarTabLabel:
|
|
|
|
tab = option
|
|
|
|
tab = option
|
|
|
|
# print(type(tab))
|
|
|
|
# print(type(tab))
|
|
|
@ -52,18 +53,19 @@ class NewChromeTabStyle(QProxyStyle):
|
|
|
|
painter.setRenderHint(QPainter.Antialiasing);
|
|
|
|
painter.setRenderHint(QPainter.Antialiasing);
|
|
|
|
|
|
|
|
|
|
|
|
shapeRect = QRectF(tab.rect);
|
|
|
|
shapeRect = QRectF(tab.rect);
|
|
|
|
|
|
|
|
shapeRect.setY(shapeRect.y() + margin)
|
|
|
|
arcLen = shapeRect.height() / 2;
|
|
|
|
arcLen = shapeRect.height() / 2;
|
|
|
|
|
|
|
|
|
|
|
|
if (tab.state & QStyle.State_Selected):
|
|
|
|
if (tab.state & QStyle.State_Selected):
|
|
|
|
painter.save();
|
|
|
|
painter.save();
|
|
|
|
pen = QPen(Qt.red);
|
|
|
|
pen = QPen(Qt.white);
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.restore();
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
painter.save();
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4);
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen *3/ 5);
|
|
|
|
|
|
|
|
|
|
|
|
path = QPainterPath();
|
|
|
|
path = QPainterPath();
|
|
|
|
|
|
|
|
|
|
|
@ -116,75 +118,38 @@ class NewChromeTabStyle(QProxyStyle):
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
arcRect1.y() + arcRect1.height()));
|
|
|
|
|
|
|
|
|
|
|
|
painter.setPen(Qt.NoPen);
|
|
|
|
painter.setPen(Qt.NoPen);
|
|
|
|
painter.setBrush(Qt.blue);
|
|
|
|
painter.setBrush(Qt.white);
|
|
|
|
polygon = path.toFillPolygon();
|
|
|
|
polygon = path.toFillPolygon();
|
|
|
|
painter.drawPolygon(polygon);
|
|
|
|
painter.drawPolygon(polygon);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter.setBrush(QColor('#D3E3FD'));
|
|
|
|
|
|
|
|
magPoint = shapeRect.topLeft()
|
|
|
|
|
|
|
|
magPoint.setY(magPoint.y() - margin)
|
|
|
|
|
|
|
|
painter.drawRect(QRectF(magPoint, QSizeF(shapeRect.width(), margin)))
|
|
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
painter.restore();
|
|
|
|
elif (tab.state & QStyle.State_MouseOver):
|
|
|
|
elif (tab.state & QStyle.State_MouseOver):
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
pen = QPen(Qt.black);
|
|
|
|
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
|
|
|
|
painter.setPen(pen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
painter.save();
|
|
|
|
painter.save();
|
|
|
|
|
|
|
|
# 设置画笔颜色和宽度
|
|
|
|
|
|
|
|
painter.setBrush(QColor('#D3E3FD'));
|
|
|
|
|
|
|
|
painter.setPen(Qt.NoPen)
|
|
|
|
|
|
|
|
magPoint = shapeRect.topLeft()
|
|
|
|
|
|
|
|
magPoint.setY(magPoint.y() - margin)
|
|
|
|
|
|
|
|
painter.drawRect(QRectF(magPoint, QSizeF(shapeRect.width(), shapeRect.height() + 4)))
|
|
|
|
|
|
|
|
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
shapeRect.setX(shapeRect.x());
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen *3/ 4);
|
|
|
|
shapeRect.setWidth(shapeRect.width() - 15);
|
|
|
|
|
|
|
|
shapeRect.setHeight(shapeRect.height() - 4)
|
|
|
|
path = QPainterPath()
|
|
|
|
painter.setPen(QColor('#A8C7FA'))
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
# 设置填充颜色(如果需要)
|
|
|
|
|
|
|
|
painter.setBrush(QColor('#A8C7FA'))
|
|
|
|
|
|
|
|
|
|
|
|
path.lineTo(QPointF(arcRect3.x() + arcRect3.width(),
|
|
|
|
# 圆角矩形的参数:左上角坐标x, y,宽度w,高度h,以及圆角半径r
|
|
|
|
arcRect3.y() + arcRect3.height()));
|
|
|
|
radius = 5
|
|
|
|
|
|
|
|
painter.drawRoundedRect(shapeRect, radius, radius)
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
|
@ -194,12 +159,24 @@ class NewChromeTabStyle(QProxyStyle):
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
shapeRect.setX(shapeRect.x() - arcLen);
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen / 2);
|
|
|
|
shapeRect.setWidth(shapeRect.width() + arcLen / 2);
|
|
|
|
|
|
|
|
|
|
|
|
pen = QPen(Qt.white);
|
|
|
|
pen = QPen(QColor('#D3E3FD'));
|
|
|
|
pen.setWidthF(0.5);
|
|
|
|
pen.setWidthF(0.1);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.setPen(pen)
|
|
|
|
|
|
|
|
painter.drawLine(shapeRect.bottomLeft(),shapeRect.bottomRight());
|
|
|
|
|
|
|
|
# painter.drawLine(QPointF(shapeRect.x() + arcLen*2/3 -1, shapeRect.height() / 3),
|
|
|
|
|
|
|
|
# QPointF(shapeRect.x() + arcLen*2/3 -1, shapeRect.height() * 2 / 3));
|
|
|
|
|
|
|
|
painter.setBrush(QColor('#D3E3FD'));
|
|
|
|
|
|
|
|
painter.drawRect(shapeRect)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
magPoint = shapeRect.topLeft()
|
|
|
|
|
|
|
|
magPoint.setY(magPoint.y() - margin)
|
|
|
|
|
|
|
|
painter.drawRect(QRectF(magPoint, QSizeF(shapeRect.width(), margin)))
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# painter.save();
|
|
|
|
|
|
|
|
# painter.restore();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter.restore();
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
super(NewChromeTabStyle, self).drawControl(element, option, painter, widget);
|
|
|
|
super(NewChromeTabStyle, self).drawControl(element, option, painter, widget);
|
|
|
|
|
|
|
|
|
|
|
@ -213,8 +190,13 @@ class DeviceTabBar(QTabBar):
|
|
|
|
def tabSizeHint(self, index):
|
|
|
|
def tabSizeHint(self, index):
|
|
|
|
newSize = QTabBar().tabSizeHint(index)
|
|
|
|
newSize = QTabBar().tabSizeHint(index)
|
|
|
|
width = len(self.tabText(index)) * 20 + 100
|
|
|
|
width = len(self.tabText(index)) * 20 + 100
|
|
|
|
|
|
|
|
|
|
|
|
newSize.setWidth(width)
|
|
|
|
newSize.setWidth(width)
|
|
|
|
newSize.setHeight(40)
|
|
|
|
newSize.setHeight(35)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# tabRect = QTabBar().tabRect(index)
|
|
|
|
|
|
|
|
# padding = 50
|
|
|
|
|
|
|
|
# tabRect.adjust(padding, padding, padding, padding)
|
|
|
|
|
|
|
|
|
|
|
|
return newSize
|
|
|
|
return newSize
|
|
|
|
|
|
|
|
|
|
|
@ -275,12 +257,11 @@ class DeviceTab(QTabWidget):
|
|
|
|
self.titleName, pvUpperLimit, pvLowerLimit, pvUnit = dialog.getParameters()
|
|
|
|
self.titleName, pvUpperLimit, pvLowerLimit, pvUnit = dialog.getParameters()
|
|
|
|
self.deviceName = self.titleName + self.dataTypeAndModel
|
|
|
|
self.deviceName = self.titleName + self.dataTypeAndModel
|
|
|
|
DeviceDB().addDevice(deviceName = self.deviceName, proType = self.proType , masterSlaveModel = self.masterSlaveModel, pvUpperLimit=pvUpperLimit, pvLowerLimit=pvLowerLimit, pvUnit=pvUnit)
|
|
|
|
DeviceDB().addDevice(deviceName = self.deviceName, proType = self.proType , masterSlaveModel = self.masterSlaveModel, pvUpperLimit=pvUpperLimit, pvLowerLimit=pvLowerLimit, pvUnit=pvUnit)
|
|
|
|
areaTabWidget = AreaTabWidget(self)
|
|
|
|
|
|
|
|
if init:
|
|
|
|
if init:
|
|
|
|
self.removeTab(0)
|
|
|
|
self.removeTab(0)
|
|
|
|
tabIndex = self.count()
|
|
|
|
tabIndex = self.count()
|
|
|
|
self.tabBar().setHidden(False)
|
|
|
|
self.tabBar().setHidden(False)
|
|
|
|
self.addTab(areaTabWidget,str(self.titleName))
|
|
|
|
self.addTab(AreaTabWidget(self),str(self.titleName))
|
|
|
|
self.setCurrentIndex(tabIndex)
|
|
|
|
self.setCurrentIndex(tabIndex)
|
|
|
|
self.devicesManange.addDevice(proType=self.proType, masterSlaveModel = self.masterSlaveModel, deviceName = self.deviceName)
|
|
|
|
self.devicesManange.addDevice(proType=self.proType, masterSlaveModel = self.masterSlaveModel, deviceName = self.deviceName)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -288,9 +269,8 @@ class DeviceTab(QTabWidget):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.deviceName = deviceName
|
|
|
|
self.deviceName = deviceName
|
|
|
|
self.titleName = self.deviceName[:-4]
|
|
|
|
self.titleName = self.deviceName[:-4]
|
|
|
|
areaTabWidget = AreaTabWidget(self)
|
|
|
|
|
|
|
|
self.tabBar().setHidden(False)
|
|
|
|
self.tabBar().setHidden(False)
|
|
|
|
self.addTab(areaTabWidget,str(self.titleName))
|
|
|
|
self.addTab(AreaTabWidget(self),str(self.titleName))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|