修改文件换行符,修正轮班图元长度计算问题
This commit is contained in:
@@ -97,6 +97,15 @@ void PicDateItem::setSource(QVariant var)
|
|||||||
if(m_model.datetimePattern.isEmpty())
|
if(m_model.datetimePattern.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// 重新计算最长显示尺寸(以防 font()/letterSpace 改变时未重算)
|
||||||
|
m_maxDateTimeStr = generateMaxDateTimeString(m_model, font());
|
||||||
|
if (m_maxDateTimeStr.isEmpty()) {
|
||||||
|
m_maxSize = QSize();
|
||||||
|
} else {
|
||||||
|
QFontMetrics fm(font());
|
||||||
|
m_maxSize = QSize(fm.horizontalAdvance(m_maxDateTimeStr), fm.height());
|
||||||
|
}
|
||||||
|
|
||||||
m_currDateTimeStr = ItemUtils::generateTxtFromDateItemModel(m_model, QDateTime::currentDateTime());
|
m_currDateTimeStr = ItemUtils::generateTxtFromDateItemModel(m_model, QDateTime::currentDateTime());
|
||||||
applyModify();
|
applyModify();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "PicScheduleShiftItem.h"
|
#include "PicScheduleShiftItem.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "LogInfo.h"
|
#include "LogInfo.h"
|
||||||
|
#include <QFontMetrics>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
PicScheduleShiftItem::PicScheduleShiftItem(QGraphicsItem *parent, QGraphicsScene *scene, const SourceType type)
|
PicScheduleShiftItem::PicScheduleShiftItem(QGraphicsItem *parent, QGraphicsScene *scene, const SourceType type)
|
||||||
:PicTextItem(parent, scene, type)
|
:PicTextItem(parent, scene, type)
|
||||||
@@ -19,6 +21,9 @@ QVariant PicScheduleShiftItem::source()
|
|||||||
|
|
||||||
void PicScheduleShiftItem::setSource(QVariant var)
|
void PicScheduleShiftItem::setSource(QVariant var)
|
||||||
{
|
{
|
||||||
|
// 重新计算基于当前字体的最大名称像素宽度
|
||||||
|
m_maxSize = calcMaxSize();
|
||||||
|
|
||||||
m_currScheduleName = findScheduleName(QTime::currentTime());
|
m_currScheduleName = findScheduleName(QTime::currentTime());
|
||||||
applyModify();
|
applyModify();
|
||||||
}
|
}
|
||||||
@@ -31,6 +36,8 @@ const QVector<ScheduleModel>& PicScheduleShiftItem::schedules() const
|
|||||||
void PicScheduleShiftItem::setSchedules(QVector<ScheduleModel> schedules)
|
void PicScheduleShiftItem::setSchedules(QVector<ScheduleModel> schedules)
|
||||||
{
|
{
|
||||||
m_schedules = std::move(schedules);
|
m_schedules = std::move(schedules);
|
||||||
|
m_maxSize = calcMaxSize();
|
||||||
|
|
||||||
m_currScheduleName = findScheduleName(QTime::currentTime());
|
m_currScheduleName = findScheduleName(QTime::currentTime());
|
||||||
applyModify();
|
applyModify();
|
||||||
}
|
}
|
||||||
@@ -95,11 +102,40 @@ QImage PicScheduleShiftItem::itemImage()
|
|||||||
auto str = m_currScheduleName;
|
auto str = m_currScheduleName;
|
||||||
|
|
||||||
if(str.isEmpty()) {
|
if(str.isEmpty()) {
|
||||||
QImage();
|
return QImage();
|
||||||
}
|
}
|
||||||
return strToImage(str);
|
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)
|
QString PicScheduleShiftItem::findScheduleName(const QTime &time)
|
||||||
{
|
{
|
||||||
if(m_schedules.isEmpty())
|
if(m_schedules.isEmpty())
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QSize>
|
||||||
|
|
||||||
struct ScheduleModel
|
struct ScheduleModel
|
||||||
{
|
{
|
||||||
@@ -45,6 +46,11 @@ private:
|
|||||||
QVector<ScheduleModel> m_schedules;
|
QVector<ScheduleModel> m_schedules;
|
||||||
QTimer m_updateTimer;
|
QTimer m_updateTimer;
|
||||||
QString m_currScheduleName;
|
QString m_currScheduleName;
|
||||||
|
QSize m_maxSize; // 缓存最长名称的像素宽高
|
||||||
|
|
||||||
|
virtual QRectF boundingRect() const override;
|
||||||
|
|
||||||
|
QSize calcMaxSize();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PICSCHEDULESHIFTITEM_H
|
#endif // PICSCHEDULESHIFTITEM_H
|
||||||
|
|||||||
Reference in New Issue
Block a user