修改文件换行符,修正轮班图元长度计算问题
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "PicScheduleShiftItem.h"
|
||||
#include <algorithm>
|
||||
#include "LogInfo.h"
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
|
||||
PicScheduleShiftItem::PicScheduleShiftItem(QGraphicsItem *parent, QGraphicsScene *scene, const SourceType type)
|
||||
:PicTextItem(parent, scene, type)
|
||||
@@ -19,6 +21,9 @@ QVariant PicScheduleShiftItem::source()
|
||||
|
||||
void PicScheduleShiftItem::setSource(QVariant var)
|
||||
{
|
||||
// 重新计算基于当前字体的最大名称像素宽度
|
||||
m_maxSize = calcMaxSize();
|
||||
|
||||
m_currScheduleName = findScheduleName(QTime::currentTime());
|
||||
applyModify();
|
||||
}
|
||||
@@ -31,6 +36,8 @@ const QVector<ScheduleModel>& PicScheduleShiftItem::schedules() const
|
||||
void PicScheduleShiftItem::setSchedules(QVector<ScheduleModel> schedules)
|
||||
{
|
||||
m_schedules = std::move(schedules);
|
||||
m_maxSize = calcMaxSize();
|
||||
|
||||
m_currScheduleName = findScheduleName(QTime::currentTime());
|
||||
applyModify();
|
||||
}
|
||||
@@ -95,11 +102,40 @@ QImage PicScheduleShiftItem::itemImage()
|
||||
auto str = m_currScheduleName;
|
||||
|
||||
if(str.isEmpty()) {
|
||||
QImage();
|
||||
return QImage();
|
||||
}
|
||||
return strToImage(str);
|
||||
}
|
||||
|
||||
QSize PicScheduleShiftItem::calcMaxSize()
|
||||
{
|
||||
if (m_schedules.isEmpty())
|
||||
return QSize();
|
||||
|
||||
QFontMetrics fm(font());
|
||||
int bestW = 0;
|
||||
for (const auto &mdl : m_schedules) {
|
||||
int w = fm.horizontalAdvance(mdl.name);
|
||||
if (w > bestW) bestW = w;
|
||||
}
|
||||
return QSize(bestW, fm.height());
|
||||
}
|
||||
|
||||
QRectF PicScheduleShiftItem::boundingRect() const
|
||||
{
|
||||
if (!m_itemImage.isNull()) {
|
||||
return QRectF(0, 0, m_itemImage.width(), m_itemImage.height());
|
||||
}
|
||||
|
||||
int w = m_maxSize.width();
|
||||
int h = m_maxSize.height();
|
||||
if (w <= 0 || h <= 0)
|
||||
return QGraphicsTextItem::boundingRect();
|
||||
|
||||
qreal bw = qreal(w) * qMax(1, m_boldMultiple);
|
||||
return QRectF(0, 0, bw, qreal(h));
|
||||
}
|
||||
|
||||
QString PicScheduleShiftItem::findScheduleName(const QTime &time)
|
||||
{
|
||||
if(m_schedules.isEmpty())
|
||||
|
||||
Reference in New Issue
Block a user