TTKMusicPlayer  4.2.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musiccommentswidget.cpp
Go to the documentation of this file.
1 #include "musiccommentswidget.h"
3 #include "musiccoverrequest.h"
6 #include "musicpagequerywidget.h"
7 #include "musicwidgetheaders.h"
8 #include "musicwidgetutils.h"
9 #include "ttkclickedlabel.h"
10 
11 #include <QTextEdit>
12 
14  : QWidget(parent)
15 {
16  setFixedHeight(60);
17  QVBoxLayout *layout = new QVBoxLayout(this);
18  layout->setContentsMargins(10, 0, 10, 0);
19  layout->addSpacing(2);
20  //
21  QWidget *centerWidget = new QWidget(this);
22  QHBoxLayout *centerWidgetLayout = new QHBoxLayout(centerWidget);
23  centerWidgetLayout->setContentsMargins(0, 0, 0, 0);
24  //
25  QWidget *textWidget = new QWidget(centerWidget);
26  QVBoxLayout *textWidgetLayout = new QVBoxLayout(textWidget);
27  textWidgetLayout->setContentsMargins(0, 5, 0, 6);
28  textWidgetLayout->setSpacing(0);
29  //
30  QWidget *userWidget = new QWidget(textWidget);
31  QHBoxLayout *userWidgetLayout = new QHBoxLayout(userWidget);
32  userWidgetLayout->setContentsMargins(0, 0, 0, 0);
33  userWidgetLayout->setSpacing(2);
34  //
35  m_userName = new QLabel(userWidget);
36  m_userCommit = new QTextEdit(userWidget);
37  m_userCommit->setReadOnly(true);
38  m_userCommit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
41  m_userName->setStyleSheet(TTK::UI::ColorStyle03);
42  userWidgetLayout->addWidget(m_userName);
43  userWidgetLayout->addWidget(m_userCommit);
44  userWidget->setLayout(userWidgetLayout);
45  //
46  QWidget *operWidget = new QWidget(textWidget);
47  QHBoxLayout *operWidgetLayout = new QHBoxLayout(operWidget);
48  operWidgetLayout->setContentsMargins(0, 0, 0, 0);
49  operWidgetLayout->setSpacing(4);
50 
51  m_timerLabel = new QLabel(operWidget);
52  m_timerLabel->setStyleSheet(TTK::UI::ColorStyle03);
53 
54  TTKClickedLabel *ngReportLabel = new TTKClickedLabel(tr("Report"), operWidget);
55  ngReportLabel->setStyleSheet(TTK::UI::ColorStyle03);
56 
57  QFrame *spliteLine1 = new QFrame(operWidget);
58  spliteLine1->setFixedWidth(1);
59  spliteLine1->setFrameShape(QFrame::VLine);
60  spliteLine1->setStyleSheet(TTK::UI::ColorStyle03);
61 
62  QPushButton *starButton = new QPushButton(operWidget);
63  starButton->setCursor(QCursor(Qt::PointingHandCursor));
64  starButton->setFixedSize(12, 11);
65  starButton->setStyleSheet(TTK::UI::InteriorStar);
66 
67  m_starLabel = new QLabel(operWidget);
68  m_starLabel->setText("(0)");
70 
71  QFrame *spliteLine2 = new QFrame(operWidget);
72  spliteLine2->setFixedWidth(1);
73  spliteLine2->setFrameShape(QFrame::VLine);
74  spliteLine2->setStyleSheet(TTK::UI::ColorStyle03);
75  TTKClickedLabel *ReplyLabel = new TTKClickedLabel(tr("Reply"), operWidget);
76  ReplyLabel->setStyleSheet(TTK::UI::ColorStyle03);
77  //
78 #ifdef Q_OS_UNIX
79  starButton->setFocusPolicy(Qt::NoFocus);
80 #endif
81  //
82  operWidgetLayout->addWidget(m_timerLabel);
83  operWidgetLayout->addStretch(1);
84  operWidgetLayout->addWidget(ngReportLabel);
85  operWidgetLayout->addWidget(spliteLine1);
86  operWidgetLayout->addWidget(starButton);
87  operWidgetLayout->addWidget(m_starLabel);
88  operWidgetLayout->addWidget(spliteLine2);
89  operWidgetLayout->addWidget(ReplyLabel);
90  operWidget->setLayout(operWidgetLayout);
91  //
92  textWidgetLayout->addWidget(userWidget);
93  textWidgetLayout->addWidget(operWidget);
94  textWidget->setLayout(textWidgetLayout);
95  //
96  m_iconLabel = new QLabel(centerWidget);
97  m_iconLabel->setFixedSize(40, 40);
98  m_iconLabel->setPixmap(QPixmap(":/image/lb_default_art").scaled(m_iconLabel->size()));
99  centerWidgetLayout->addWidget(m_iconLabel);
100  centerWidgetLayout->addWidget(textWidget);
101  centerWidget->setLayout(centerWidgetLayout);
102  //
103  QFrame *solidLine = new QFrame(this);
104  solidLine->setFixedHeight(1);
105  solidLine->setStyleSheet(TTK::UI::BorderStyle04 + TTK::UI::ColorStyle03);
106  //
107  layout->addWidget(centerWidget);
108  layout->addWidget(solidLine);
109  setLayout(layout);
110 }
111 
113 {
114  delete m_userName;
115  delete m_userCommit;
116  delete m_timerLabel;
117  delete m_iconLabel;
118  delete m_starLabel;
119 }
120 
122 {
123  m_userName->setText(item.m_nickName + ":");
124  m_userName->setFixedWidth(TTK::Widget::fontTextWidth(m_userName->font(), m_userName->text()));
125  m_timerLabel->setText(TTKDateTime::format(item.m_time.toULongLong(), TTK_DATE_TIMES_FORMAT));
126  m_timerLabel->setFixedWidth(TTK::Widget::fontTextWidth(m_timerLabel->font(), m_timerLabel->text()));
127  m_starLabel->setText(QString("(%1)").arg(item.m_count));
128  m_userCommit->setText(item.m_description);
129 
130  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
131  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
132  d->startToRequest(item.m_coverUrl);
133 }
134 
135 void MusicCommentsItem::downLoadFinished(const QByteArray &bytes)
136 {
137  if(bytes.isEmpty())
138  {
139  TTK_ERROR_STREAM("Input byte data is empty");
140  return;
141  }
142 
143  QPixmap pix;
144  if(pix.loadFromData(bytes))
145  {
146  m_iconLabel->setPixmap(pix.scaled(m_iconLabel->size()));
147  }
148 }
149 
150 
151 
153  : QLabel(parent),
154  m_plain(true),
155  m_topLabel(nullptr),
156  m_commentsLabel(nullptr),
157  m_messageComments(nullptr),
158  m_pageQueryWidget(nullptr),
159  m_networkRequest(nullptr)
160 {
161 
162 }
163 
165 {
167  delete m_topLabel;
168  delete m_commentsLabel;
169  delete m_pageQueryWidget;
170  delete m_messageComments;
171  delete m_networkRequest;
172 }
173 
175 {
176  m_plain = plain;
177 
178  setObjectName(className());
179  setStyleSheet(QString("#%1{ %2 }").arg(objectName(), TTK::UI::BackgroundStyle07));
180 
181  QVBoxLayout *mainLayout = new QVBoxLayout(this);
182  mainLayout->setContentsMargins(0, 0, 0, 0);
183  mainLayout->setSpacing(0);
184 
185  QWidget *topWidget = nullptr;
186  if(plain)
187  {
188  topWidget = new QWidget(this);
189  topWidget->setFixedHeight(40);
190  QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
191  topWidgetLayout->setContentsMargins(0, 0, 10, 0);
192 
193  m_topLabel = new QLabel(topWidget);
194  m_topLabel->setAlignment(Qt::AlignCenter);
195  topWidgetLayout->addWidget(m_topLabel);
196 
197  QPushButton *closeButton = new QPushButton(this);
198  closeButton->setFixedSize(14, 14);
199  closeButton->setStyleSheet(TTK::UI::BtnPClose);
200  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
201 #ifdef Q_OS_UNIX
202  closeButton->setFocusPolicy(Qt::NoFocus);
203 #endif
204  connect(closeButton, SIGNAL(clicked()), SLOT(close()));
205 
206  topWidgetLayout->addWidget(closeButton);
207  topWidget->setLayout(topWidgetLayout);
208  }
209  else
210  {
211  m_topLabel = new QLabel(this);
212  m_topLabel->hide();
213  }
214 
215  QWidget *contentsWidget = new QWidget(this);
216  QVBoxLayout *contentsLayout = new QVBoxLayout(contentsWidget);
217  contentsLayout->setContentsMargins(0, 0, 0 ,0);
218  contentsLayout->setSpacing(0);
219  //
220  QWidget *messageBox = new QWidget(contentsWidget);
221  messageBox->setAttribute(Qt::WA_TranslucentBackground, true);
222  messageBox->setFixedHeight(60);
223  QVBoxLayout *messageBoxLayout = new QVBoxLayout(messageBox);
224  messageBoxLayout->setContentsMargins(10, 10, 10, 3);
225  m_commentsLabel = new QLabel(messageBox);
226  m_commentsLabel->setStyleSheet(TTK::UI::ColorStyle04);
227  QFrame *solidLine = new QFrame(messageBox);
228  solidLine->setFrameShape(QFrame::HLine);
229  solidLine->setFixedHeight(1);
230  solidLine->setStyleSheet(TTK::UI::ColorStyle03);
231  //
232  messageBoxLayout->addWidget(m_commentsLabel);
233  messageBoxLayout->addWidget(solidLine);
234  messageBox->setLayout(messageBoxLayout);
235  //
236  m_messageComments = new QWidget(contentsWidget);
237  QVBoxLayout *messageCommentsLayout = new QVBoxLayout(m_messageComments);
238  messageCommentsLayout->setContentsMargins(0, 0, 0, 0);
239  m_messageComments->setLayout(messageCommentsLayout);
240 
241  contentsLayout->addWidget(messageBox);
242  contentsLayout->addWidget(m_messageComments);
243  contentsWidget->setLayout(contentsLayout);
244  //
245  if(plain)
246  {
247  QScrollArea *scrollArea = new QScrollArea(this);
248  TTK::Widget::generateVScrollAreaStyle(scrollArea, contentsWidget, false);
249 
250  contentsWidget->setObjectName("ContentsWidget");
251  contentsWidget->setStyleSheet(QString("#%1{ %2 }").arg(contentsWidget->objectName(), TTK::UI::BackgroundStyle01));
252  QWidget *view = scrollArea->viewport();
253  view->setObjectName("Viewport");
254  view->setStyleSheet(QString("#%1{ %2 }").arg(view->objectName(), TTK::UI::BackgroundStyle01));
255  //
256  mainLayout->addWidget(topWidget);
257  mainLayout->addWidget(scrollArea);
258  }
259  else
260  {
261  mainLayout->addWidget(contentsWidget);
262  setFixedHeight(210);
263  }
264 
265  initLabel({}, 0);
266  setLayout(mainLayout);
267 }
268 
270 {
272 
273  TTKEventLoop loop;
274  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), &loop, SLOT(quit()));
276  loop.exec();
277 
278  TTKObjectCast(QVBoxLayout*, m_messageComments->layout())->addStretch(1);
280 
282 }
283 
285 {
287  comment->addCellItem(item);
288  m_commentsItems << comment;
289 
290  QVBoxLayout *layout = TTKObjectCast(QVBoxLayout*, m_messageComments->layout());
291  layout->insertWidget(layout->count() - 1, comment);
292 
293  if(!m_plain)
294  {
295  setFixedHeight(height() + comment->height());
296  }
297 }
298 
300 {
302 
305 }
306 
307 void MusicCommentsWidget::mousePressEvent(QMouseEvent *event)
308 {
309  Q_UNUSED(event);
310 }
311 
312 void MusicCommentsWidget::mouseMoveEvent(QMouseEvent *event)
313 {
314  Q_UNUSED(event);
315 }
316 
318 {
319  Q_UNUSED(event);
320 }
321 
322 void MusicCommentsWidget::initLabel(const QString &name, int total)
323 {
324  m_topLabel->setText(tr("<span style='font-size:15pt;color:#AAAAAA;font-style:bold;'>\"%1\" Commit</span>"
325  "<span style='font-size:11pt;color:#666666;font-style:bold;'> (Just %2 Commits)</span>").arg(name).arg(total));
326  m_commentsLabel->setText(tr("All Comments(%1)").arg(total));
327 }
328 
330 {
331  qDeleteAll(m_commentsItems);
332  m_commentsItems.clear();
333 
334  if(!m_plain)
335  {
336  setFixedHeight(210);
337  }
338 }
339 
341 {
343  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
344 
346  m_messageComments->layout()->addWidget(w);
347 }
void initLabel(const QString &name, int total)
virtual void mousePressEvent(QMouseEvent *event) overridefinal
The class of the search result data item.
void createCommentItem(const MusicResultDataItem &item)
static const QString BorderStyle01
border
void buttonClicked(int index)
The class of the song comment item.
int pageTotalSize() const noexcept
virtual void startToRequest(const QString &url)=0
QList< MusicCommentsItem * > m_commentsItems
void addCellItem(const MusicResultDataItem &item)
static constexpr const char * BtnPClose
int exec(ProcessEventsFlags flags=AllEvents)
static const QString ColorStyle04
Definition: musicuiobject.h:46
The class of the label widget that can click.
virtual void startToSearch(const QString &value)
static const QString BorderStyle04
The class of the ttk event loop.
Definition: ttkeventloop.h:29
virtual void initialize(bool plain)
const char * name
Definition: http_parser.c:458
void downLoadFinished(const QByteArray &bytes)
static constexpr const char * InteriorStar
static const QString BackgroundStyle01
Background.
Definition: musicuiobject.h:77
void setCurrentSongName(const QString &name)
virtual void mouseMoveEvent(QMouseEvent *event) overridefinal
The class of the page query widget.
#define TTK_DATE_TIMES_FORMAT
Definition: ttkglobal.h:312
virtual void startToPage(int offset)
void page(int index, int total)
TTK_MODULE_EXPORT void generateVScrollAreaStyle(QWidget *widget, QWidget *parent, bool background=true)
static const QString ColorStyle03
Definition: musicuiobject.h:43
virtual void mouseReleaseEvent(QMouseEvent *event) overridefinal
MusicCommentsRequest * m_networkRequest
QWidget * createPageWidget(QWidget *parent, int total)
TTK_MODULE_EXPORT int fontTextWidth(const QFont &font, const QString &text)
static const QString BackgroundStyle07
#define G_DOWNLOAD_QUERY_PTR
The class of the cover data download request.
static QString format(const QString &time, const QString &format)
Definition: ttktime.cpp:254
MusicCommentsItem(QWidget *parent=nullptr)
#define TTK_ERROR_STREAM(msg)
Definition: ttklogger.h:76
int totalSize() const noexcept
MusicCommentsWidget(QWidget *parent=nullptr)
MusicPageQueryWidget * m_pageQueryWidget
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:82