Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/render/notes/NotesItem.cpp
Context not available. | |||||
7 | 7 | | |||
---|---|---|---|---|---|
8 | #include "NotesItem.h" | 8 | #include "NotesItem.h" | ||
9 | #include "MarbleDirs.h" | 9 | #include "MarbleDirs.h" | ||
10 | #include "MarbleDebug.h" | ||||
10 | 11 | | |||
11 | #include <QPainter> | 12 | #include <QPainter> | ||
12 | #include <QRect> | 13 | #include <QRect> | ||
13 | 14 | | |||
14 | using namespace Marble; | 15 | using namespace Marble; | ||
15 | 16 | | |||
17 | const QFont NotesItem::s_font = QFont( QStringLiteral( "Sans Serif" ), 10 ); | ||||
18 | const int NotesItem::s_labelOutlineWidth = 5; | ||||
19 | | ||||
16 | NotesItem::NotesItem(QObject *parent) | 20 | NotesItem::NotesItem(QObject *parent) | ||
17 | : AbstractDataPluginItem(parent), | 21 | : AbstractDataPluginItem(parent), | ||
18 | m_pixmap(MarbleDirs::path("bitmaps/waypoint.png")) | 22 | m_pixmap_open(MarbleDirs::path("bitmaps/notes_open.png")), | ||
23 | m_pixmap_closed(MarbleDirs::path("bitmaps/notes_closed.png")) | ||||
19 | { | 24 | { | ||
20 | setSize(m_pixmap.size()); | 25 | MarbleDebug::setEnabled(true); | ||
26 | | ||||
27 | setSize(m_pixmap_open.size()); | ||||
28 | setAlignment(Qt::AlignHCenter | Qt::AlignTop); | ||||
21 | setCacheMode(ItemCoordinateCache); | 29 | setCacheMode(ItemCoordinateCache); | ||
22 | } | 30 | } | ||
23 | 31 | | |||
Context not available. | |||||
37 | 45 | | |||
38 | void NotesItem::paint(QPainter *painter) | 46 | void NotesItem::paint(QPainter *painter) | ||
39 | { | 47 | { | ||
40 | painter->drawPixmap(0, 0, m_pixmap); | 48 | painter->save(); | ||
49 | | ||||
50 | painter->setFont(s_font); | ||||
51 | const int fontAscent = painter->fontMetrics().ascent(); | ||||
52 | QPen outlinepen( Qt::white ); | ||||
53 | outlinepen.setWidthF( s_labelOutlineWidth ); | ||||
54 | QBrush outlinebrush( Qt::black ); | ||||
55 | | ||||
56 | const QPointF baseline( s_labelOutlineWidth / 2.0, fontAscent ); | ||||
57 | | ||||
58 | QPainterPath outlinepath; | ||||
59 | outlinepath.addText( baseline, painter->font(), m_labelText ); | ||||
60 | | ||||
61 | painter->setRenderHint( QPainter::Antialiasing, true ); | ||||
62 | painter->setPen( outlinepen ); | ||||
63 | painter->setBrush( outlinebrush ); | ||||
64 | painter->drawPath( outlinepath ); | ||||
65 | painter->setPen( Qt::NoPen ); | ||||
66 | painter->drawPath( outlinepath ); | ||||
67 | painter->setRenderHint( QPainter::Antialiasing, false ); | ||||
68 | | ||||
69 | int const y = qMax(0, int(size().width() - m_pixmap_open.width()) / 2); | ||||
70 | | ||||
71 | //The two pixmaps have the same dimensions, so all the logic for one works for the other | ||||
72 | if (m_noteStatus == "open") { | ||||
73 | painter->drawPixmap(y, 2 + painter->fontMetrics().height(), m_pixmap_open); | ||||
74 | } else if (m_noteStatus == "closed") { | ||||
75 | painter->drawPixmap(y, 2 + painter->fontMetrics().height(), m_pixmap_closed); | ||||
76 | } | ||||
77 | | ||||
78 | painter->restore(); | ||||
41 | } | 79 | } | ||
80 | | ||||
81 | void NotesItem::setDateCreated(const QDateTime& dateCreated) | ||||
82 | { | ||||
83 | m_dateCreated = dateCreated; | ||||
84 | } | ||||
85 | | ||||
86 | void NotesItem::setDateClosed(const QDateTime& dateClosed) | ||||
87 | { | ||||
88 | m_dateClosed = dateClosed; | ||||
89 | } | ||||
90 | | ||||
91 | void NotesItem::setNoteStatus(const QString& noteStatus) | ||||
92 | { | ||||
93 | m_noteStatus = noteStatus; | ||||
94 | } | ||||
95 | | ||||
96 | void NotesItem::addLatestComment(const Comment& comment) | ||||
97 | { | ||||
98 | m_commentsList.push_back(comment); | ||||
99 | std::sort(m_commentsList.begin(), m_commentsList.end(), [] (const Comment& a, const Comment& b) {return a.getDate() < b.getDate();} ); | ||||
100 | setComment(m_commentsList.back()); | ||||
101 | } | ||||
102 | | ||||
103 | void NotesItem::setComment(const Comment& comment) | ||||
104 | { | ||||
105 | QFontMetrics fontmet(s_font); | ||||
106 | m_labelText = fontmet.elidedText(comment.getText(), Qt::ElideRight, 125); | ||||
107 | auto const width = qMax(fontmet.width(m_labelText), m_pixmap_open.width()); | ||||
108 | setSize(QSizeF(width, fontmet.height() + 2 + m_pixmap_open.height())); | ||||
109 | } | ||||
110 | | ||||
111 | qreal NotesItem::width() | ||||
112 | { | ||||
113 | return m_pixmap_open.size().width(); | ||||
114 | } | ||||
115 | | ||||
116 | qreal NotesItem::height() | ||||
117 | { | ||||
118 | return m_pixmap_open.size().height(); | ||||
119 | } | ||||
120 | | ||||
121 | Comment::Comment() | ||||
122 | { | ||||
123 | } | ||||
124 | | ||||
125 | Comment::Comment(QDateTime date, QString text, QString user, int uid) | ||||
126 | : m_date(date) | ||||
127 | , m_text(text) | ||||
128 | , m_user(user) | ||||
129 | { | ||||
130 | m_uid = uid; | ||||
131 | } | ||||
132 | | ||||
133 | #include "moc_NotesItem.cpp" | ||||
Context not available. |