57 lines
1.3 KiB
C++
57 lines
1.3 KiB
C++
#ifndef PICSCHEDULESHIFTITEM_H
|
|
#define PICSCHEDULESHIFTITEM_H
|
|
|
|
#include "pictextitem.h"
|
|
#include <QTime>
|
|
#include <QString>
|
|
#include <QTimer>
|
|
#include <QSize>
|
|
|
|
struct ScheduleModel
|
|
{
|
|
QTime startTime;
|
|
QString name;
|
|
};
|
|
|
|
static bool operator < (const ScheduleModel& l, const ScheduleModel& r) {
|
|
return l.startTime < r.startTime;
|
|
}
|
|
|
|
Q_DECLARE_METATYPE(ScheduleModel);
|
|
|
|
class PicScheduleShiftItem : public PicTextItem
|
|
{
|
|
public:
|
|
PicScheduleShiftItem(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0, const SourceType type = SourceType::SCHEDULE_SHIFT);
|
|
|
|
const QVector<ScheduleModel>& schedules() const;
|
|
|
|
void setSchedules(QVector<ScheduleModel> schedules);
|
|
|
|
bool updateScheduleName();
|
|
|
|
virtual QRectF boundingRect() const override;
|
|
|
|
protected:
|
|
virtual void setCustomAttrs(const QXmlStreamAttributes& attrs) override;
|
|
|
|
virtual void saveCustomAttrs(QXmlStreamAttributes& attrs) override;
|
|
|
|
virtual QImage itemImage();
|
|
|
|
virtual void letterSpaceChanged() override;
|
|
|
|
private:
|
|
|
|
QString findScheduleName(const QTime& time);
|
|
|
|
QVector<ScheduleModel> m_schedules;
|
|
QTimer m_updateTimer;
|
|
QString m_currScheduleName;
|
|
QSize m_maxSize; // 缓存最长名称的像素宽高
|
|
|
|
QSize calcMaxSize();
|
|
};
|
|
|
|
#endif // PICSCHEDULESHIFTITEM_H
|