TTKMusicPlayer  3.7.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"
7 #include "musicpagequerywidget.h"
8 #include "musicwidgetheaders.h"
9 #include "musicwidgetutils.h"
10 #include "ttkclickedlabel.h"
11 
12 #include <QTextEdit>
13 
15  : QWidget(parent)
16 {
17  setFixedHeight(60);
18  QVBoxLayout *layout = new QVBoxLayout(this);
19  layout->setContentsMargins(10, 0, 10, 0);
20  layout->addSpacing(2);
21  //
22  QWidget *centerWidget = new QWidget(this);
23  QHBoxLayout *centerWidgetLayout = new QHBoxLayout(centerWidget);
24  centerWidgetLayout->setContentsMargins(0, 0, 0, 0);
25  //
26  QWidget *textWidget = new QWidget(centerWidget);
27  QVBoxLayout *textWidgetLayout = new QVBoxLayout(textWidget);
28  textWidgetLayout->setContentsMargins(0, 5, 0, 6);
29  textWidgetLayout->setSpacing(0);
30  //
31  QWidget *userWidget = new QWidget(textWidget);
32  QHBoxLayout *userWidgetLayout = new QHBoxLayout(userWidget);
33  userWidgetLayout->setContentsMargins(0, 0, 0, 0);
34  userWidgetLayout->setSpacing(2);
35  //
36  m_userName = new QLabel(userWidget);
37  m_userCommit = new QTextEdit(userWidget);
38  m_userCommit->setReadOnly(true);
39  m_userCommit->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
43  m_userName->setStyleSheet(TTK::UI::ColorStyle03);
44  userWidgetLayout->addWidget(m_userName);
45  userWidgetLayout->addWidget(m_userCommit);
46  userWidget->setLayout(userWidgetLayout);
47  //
48  QWidget *operWidget = new QWidget(textWidget);
49  QHBoxLayout *operWidgetLayout = new QHBoxLayout(operWidget);
50  operWidgetLayout->setContentsMargins(0, 0, 0, 0);
51  operWidgetLayout->setSpacing(4);
52 
53  m_timerLabel = new QLabel(operWidget);
54  m_timerLabel->setStyleSheet(TTK::UI::ColorStyle03);
55 
56  TTKClickedLabel *ngReportLabel = new TTKClickedLabel(tr("Report"), operWidget);
57  ngReportLabel->setStyleSheet(TTK::UI::ColorStyle03);
58 
59  QFrame *spliteLine1 = new QFrame(operWidget);
60  spliteLine1->setFixedWidth(1);
61  spliteLine1->setFrameShape(QFrame::VLine);
62  spliteLine1->setStyleSheet(TTK::UI::ColorStyle03);
63 
64  QPushButton *starButton = new QPushButton(operWidget);
65  starButton->setCursor(QCursor(Qt::PointingHandCursor));
66  starButton->setFixedSize(12, 11);
67  starButton->setStyleSheet(TTK::UI::InteriorStar);
68 
69  m_starLabel = new QLabel(operWidget);
70  m_starLabel->setText("(0)");
72 
73  QFrame *spliteLine2 = new QFrame(operWidget);
74  spliteLine2->setFixedWidth(1);
75  spliteLine2->setFrameShape(QFrame::VLine);
76  spliteLine2->setStyleSheet(TTK::UI::ColorStyle03);
77  TTKClickedLabel *ReplyLabel = new TTKClickedLabel(tr("Reply"), operWidget);
78  ReplyLabel->setStyleSheet(TTK::UI::ColorStyle03);
79  //
80 #ifdef Q_OS_UNIX
81  starButton->setFocusPolicy(Qt::NoFocus);
82 #endif
83  //
84  operWidgetLayout->addWidget(m_timerLabel);
85  operWidgetLayout->addStretch(1);
86  operWidgetLayout->addWidget(ngReportLabel);
87  operWidgetLayout->addWidget(spliteLine1);
88  operWidgetLayout->addWidget(starButton);
89  operWidgetLayout->addWidget(m_starLabel);
90  operWidgetLayout->addWidget(spliteLine2);
91  operWidgetLayout->addWidget(ReplyLabel);
92  operWidget->setLayout(operWidgetLayout);
93  //
94  textWidgetLayout->addWidget(userWidget);
95  textWidgetLayout->addWidget(operWidget);
96  textWidget->setLayout(textWidgetLayout);
97  //
98  m_iconLabel = new QLabel(centerWidget);
99  m_iconLabel->setFixedSize(40, 40);
100  m_iconLabel->setPixmap(QPixmap(":/image/lb_default_art").scaled(m_iconLabel->size()));
101  centerWidgetLayout->addWidget(m_iconLabel);
102  centerWidgetLayout->addWidget(textWidget);
103  centerWidget->setLayout(centerWidgetLayout);
104  //
105  QFrame *solidLine = new QFrame(this);
106  solidLine->setFixedHeight(1);
107  solidLine->setStyleSheet(TTK::UI::BorderStyle05 + TTK::UI::ColorStyle03);
108  //
109  layout->addWidget(centerWidget);
110  layout->addWidget(solidLine);
111  setLayout(layout);
112 }
113 
115 {
116  delete m_userName;
117  delete m_userCommit;
118  delete m_timerLabel;
119  delete m_iconLabel;
120  delete m_starLabel;
121 }
122 
124 {
125  m_userName->setText(item.m_nickName + ":");
126  m_userName->setFixedWidth(TTK::Widget::fontTextWidth(m_userName->font(), m_userName->text()));
128  m_timerLabel->setFixedWidth(TTK::Widget::fontTextWidth(m_timerLabel->font(), m_timerLabel->text()));
129  m_starLabel->setText(QString("(%1)").arg(item.m_count));
130  m_userCommit->setText(item.m_description);
131 
132  MusicCoverRequest *d = G_DOWNLOAD_QUERY_PTR->makeCoverRequest(this);
133  connect(d, SIGNAL(downLoadRawDataChanged(QByteArray)), SLOT(downLoadFinished(QByteArray)));
134  d->startToRequest(item.m_coverUrl);
135 }
136 
137 void MusicCommentsItem::downLoadFinished(const QByteArray &bytes)
138 {
139  if(bytes.isEmpty())
140  {
141  TTK_ERROR_STREAM("Input byte data is empty");
142  return;
143  }
144 
145  QPixmap pix;
146  pix.loadFromData(bytes);
147  m_iconLabel->setPixmap(pix.scaled(m_iconLabel->size()));
148 }
149 
150 
151 
153  : QLabel(parent),
154  m_isPain(true),
155  m_messageEdit(nullptr),
156  m_topLabel(nullptr),
157  m_commentsLabel(nullptr),
158  m_messageComments(nullptr),
159  m_pageQueryWidget(nullptr),
160  m_networkRequest(nullptr)
161 {
162 
163 }
164 
166 {
168  delete m_topLabel;
169  delete m_commentsLabel;
170  delete m_messageEdit;
171  delete m_pageQueryWidget;
172  delete m_messageComments;
173  delete m_networkRequest;
174 }
175 
177 {
178  m_isPain = isPain;
179 
180  setObjectName(className());
181  setStyleSheet(QString("#%1{%2}").arg(className(), TTK::UI::BackgroundStyle07));
182 
183  QVBoxLayout *mainLayout = new QVBoxLayout(this);
184  mainLayout->setContentsMargins(0, 0, 0, 0);
185  mainLayout->setSpacing(0);
186 
187  QWidget *topWidget = nullptr;
188  if(isPain)
189  {
190  topWidget = new QWidget(this);
191  topWidget->setFixedHeight(40);
192  QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
193  topWidgetLayout->setContentsMargins(0, 0, 10, 0);
194 
195  m_topLabel = new QLabel(topWidget);
196  m_topLabel->setAlignment(Qt::AlignCenter);
197  topWidgetLayout->addWidget(m_topLabel);
198 
199  QPushButton *closeButton = new QPushButton(this);
200  closeButton->setFixedSize(14, 14);
201  closeButton->setStyleSheet(TTK::UI::BtnPClose);
202  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
203 #ifdef Q_OS_UNIX
204  closeButton->setFocusPolicy(Qt::NoFocus);
205 #endif
206  connect(closeButton, SIGNAL(clicked()), SLOT(close()));
207 
208  topWidgetLayout->addWidget(closeButton);
209  topWidget->setLayout(topWidgetLayout);
210  }
211  else
212  {
213  m_topLabel = new QLabel(this);
214  m_topLabel->hide();
215  }
216 
217  QWidget *contentsWidget = new QWidget(this);
218  QVBoxLayout *contentsLayout = new QVBoxLayout(contentsWidget);
219  contentsLayout->setContentsMargins(0, 0, 0 ,0);
220  contentsLayout->setSpacing(0);
221  //
222  QWidget *messageBox = new QWidget(contentsWidget);
223  messageBox->setFixedHeight(150);
224  QVBoxLayout *messageBoxLayout = new QVBoxLayout(messageBox);
225  messageBoxLayout->setContentsMargins(10, 10, 10, 3);
226  messageBox->setAttribute(Qt::WA_TranslucentBackground, false);
227  m_messageEdit = new QTextEdit(messageBox);
228  m_messageEdit->setFixedHeight(75);
229  m_messageEdit->verticalScrollBar()->setStyleSheet(TTK::UI::ScrollBarStyle01);
231  m_messageEdit->viewport()->setStyleSheet(TTK::UI::BackgroundStyle01 + TTK::UI::ColorStyle04);
232  messageBox->setAttribute(Qt::WA_TranslucentBackground, true);
233  m_commentsLabel = new QLabel(contentsWidget);
234  m_commentsLabel->setStyleSheet(TTK::UI::ColorStyle04);
235  QFrame *solidLine = new QFrame(contentsWidget);
236  solidLine->setFrameShape(QFrame::HLine);
237  solidLine->setFixedHeight(1);
238  solidLine->setStyleSheet(TTK::UI::ColorStyle03);
239  //
240  QWidget *messageMiddle = new QWidget(messageBox);
241  QHBoxLayout *messageMiddleLayout = new QHBoxLayout(messageMiddle);
242  messageMiddleLayout->setContentsMargins(0, 10, 0, 0);
243  QPushButton *emojiButton = new QPushButton(messageMiddle);
244  QPushButton *sendButton = new QPushButton(tr("Send"), messageMiddle);
245  emojiButton->setIcon(QIcon(":/lrc/lb_emoji"));
246  emojiButton->setCursor(QCursor(Qt::PointingHandCursor));
247  emojiButton->setStyleSheet(TTK::UI::BackgroundStyle01);
248  connect(emojiButton, SIGNAL(clicked()), SLOT(createEMOJILabelWidget()));
249  sendButton->setFixedSize(65, 25);
250  sendButton->setCursor(QCursor(Qt::PointingHandCursor));
251  sendButton->setStyleSheet(TTK::UI::PushButtonStyle03);
252  messageMiddleLayout->addWidget(emojiButton);
253  messageMiddleLayout->addStretch(1);
254  messageMiddleLayout->addWidget(sendButton);
255  messageMiddle->setLayout(messageMiddleLayout);
256 #ifdef Q_OS_UNIX
257  emojiButton->setFocusPolicy(Qt::NoFocus);
258  sendButton->setFocusPolicy(Qt::NoFocus);
259 #endif
260  //
261  messageBoxLayout->addWidget(m_messageEdit);
262  messageBoxLayout->addWidget(messageMiddle);
263  messageBoxLayout->addWidget(m_commentsLabel);
264  messageBoxLayout->addWidget(solidLine);
265  messageBox->setLayout(messageBoxLayout);
266  //
267  m_messageComments = new QWidget(contentsWidget);
268  QVBoxLayout *messageCommentsLayout = new QVBoxLayout(m_messageComments);
269  messageCommentsLayout->setContentsMargins(0, 0, 0, 0);
270  m_messageComments->setLayout(messageCommentsLayout);
271 
272  contentsLayout->addWidget(messageBox);
273  contentsLayout->addWidget(m_messageComments);
274  contentsWidget->setLayout(contentsLayout);
275  //
276  if(isPain)
277  {
278  QScrollArea *scrollArea = new QScrollArea(this);
279  TTK::Widget::generateVScrollAreaFormat(scrollArea, contentsWidget, false);
280 
281  contentsWidget->setObjectName("ContentsWidget");
282  contentsWidget->setStyleSheet(QString("#ContentsWidget{%1}").arg(TTK::UI::BackgroundStyle01));
283  QWidget *view = scrollArea->viewport();
284  view->setObjectName("Viewport");
285  view->setStyleSheet(QString("#Viewport{%1}").arg(TTK::UI::BackgroundStyle01));
286  //
287  mainLayout->addWidget(topWidget);
288  mainLayout->addWidget(scrollArea);
289  }
290  else
291  {
292  mainLayout->addWidget(contentsWidget);
293  setFixedHeight(300);
294  }
295  setLayout(mainLayout);
296 
297  initLabel({}, 0);
298 }
299 
301 {
303 
304  TTKSemaphoreLoop loop;
305  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), &loop, SLOT(quit()));
307  loop.exec();
308 
309  TTKObjectCast(QVBoxLayout*, m_messageComments->layout())->addStretch(1);
311 
313 }
314 
316 {
318  comment->addCellItem(item);
319  m_commentsItems << comment;
320 
321  QVBoxLayout *layout = TTKObjectCast(QVBoxLayout*, m_messageComments->layout());
322  layout->insertWidget(layout->count() - 1, comment);
323 
324  if(!m_isPain)
325  {
326  setFixedHeight(height() + comment->height());
327  }
328 }
329 
331 {
333 
336 }
337 
339 {
341  connect(w, SIGNAL(dataChanged(QString)), SLOT(currentEMOJIchanged(QString)));
342  w->move(15, 160);
343  w->show();
344 }
345 
347 {
348  m_messageEdit->insertPlainText(data);
349 }
350 
351 void MusicCommentsWidget::mousePressEvent(QMouseEvent *event)
352 {
353  Q_UNUSED(event);
354 }
355 
356 void MusicCommentsWidget::mouseMoveEvent(QMouseEvent *event)
357 {
358  Q_UNUSED(event);
359 }
360 
362 {
363  Q_UNUSED(event);
364 }
365 
366 void MusicCommentsWidget::initLabel(const QString &name, int total)
367 {
368  m_topLabel->setText(tr("<span style='font-size:15pt;color:#AAAAAA;font-style:bold;'>\"%1\" Commit</span>"
369  "<span style='font-size:11pt;color:#666666;font-style:bold;'> (Just %2 Commits)</span>").arg(name).arg(total));
370  m_commentsLabel->setText(tr("All Comments(%1)").arg(total));
371 }
372 
374 {
375  qDeleteAll(m_commentsItems);
376  m_commentsItems.clear();
377 
378  if(!m_isPain)
379  {
380  setFixedHeight(300);
381  }
382 }
383 
385 {
387  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
388 
390  m_messageComments->layout()->addWidget(w);
391 }
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)
virtual void initialize(bool isPain)
static const QString BorderStyle01
border
void buttonClicked(int index)
#define TTK_DATE_TIMEZ_FORMAT
Definition: ttkglobal.h:234
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
static const QString ColorStyle04
Definition: musicuiobject.h:46
int exec(ProcessEventsFlags flags=AllEvents)
static const QString BorderStyle05
The class of the label widget that can click.
virtual void startToSearch(const QString &value)
const char * name
Definition: http_parser.c:458
static const QString ScrollBarStyle01
ScrollBar.
void downLoadFinished(const QByteArray &bytes)
static const QString PushButtonStyle03
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.
virtual void startToPage(int offset)
void page(int index, int total)
static const QString ColorStyle03
Definition: musicuiobject.h:43
virtual void mouseReleaseEvent(QMouseEvent *event) overridefinal
MusicCommentsRequest * m_networkRequest
TTK_MODULE_EXPORT void generateVScrollAreaFormat(QWidget *widget, QWidget *parent, bool background=true)
QWidget * createPageWidget(QWidget *parent, int total)
TTK_MODULE_EXPORT int fontTextWidth(const QFont &font, const QString &text)
static const QString BackgroundStyle07
Definition: musicuiobject.h:99
static const QString BorderStyle02
void currentEMOJIchanged(const QString &data)
#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:69
The class of the semaphore event loop.
int totalSize() const noexcept
The class of the emoji label widget.
MusicCommentsWidget(QWidget *parent=nullptr)
MusicPageQueryWidget * m_pageQueryWidget
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60