TTKMusicPlayer  4.1.3.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  pix.loadFromData(bytes);
145  m_iconLabel->setPixmap(pix.scaled(m_iconLabel->size()));
146 }
147 
148 
149 
151  : QLabel(parent),
152  m_plain(true),
153  m_topLabel(nullptr),
154  m_commentsLabel(nullptr),
155  m_messageComments(nullptr),
156  m_pageQueryWidget(nullptr),
157  m_networkRequest(nullptr)
158 {
159 
160 }
161 
163 {
165  delete m_topLabel;
166  delete m_commentsLabel;
167  delete m_pageQueryWidget;
168  delete m_messageComments;
169  delete m_networkRequest;
170 }
171 
173 {
174  m_plain = plain;
175 
176  setObjectName(className());
177  setStyleSheet(QString("#%1{ %2 }").arg(objectName(), TTK::UI::BackgroundStyle07));
178 
179  QVBoxLayout *mainLayout = new QVBoxLayout(this);
180  mainLayout->setContentsMargins(0, 0, 0, 0);
181  mainLayout->setSpacing(0);
182 
183  QWidget *topWidget = nullptr;
184  if(plain)
185  {
186  topWidget = new QWidget(this);
187  topWidget->setFixedHeight(40);
188  QHBoxLayout *topWidgetLayout = new QHBoxLayout(topWidget);
189  topWidgetLayout->setContentsMargins(0, 0, 10, 0);
190 
191  m_topLabel = new QLabel(topWidget);
192  m_topLabel->setAlignment(Qt::AlignCenter);
193  topWidgetLayout->addWidget(m_topLabel);
194 
195  QPushButton *closeButton = new QPushButton(this);
196  closeButton->setFixedSize(14, 14);
197  closeButton->setStyleSheet(TTK::UI::BtnPClose);
198  closeButton->setCursor(QCursor(Qt::PointingHandCursor));
199 #ifdef Q_OS_UNIX
200  closeButton->setFocusPolicy(Qt::NoFocus);
201 #endif
202  connect(closeButton, SIGNAL(clicked()), SLOT(close()));
203 
204  topWidgetLayout->addWidget(closeButton);
205  topWidget->setLayout(topWidgetLayout);
206  }
207  else
208  {
209  m_topLabel = new QLabel(this);
210  m_topLabel->hide();
211  }
212 
213  QWidget *contentsWidget = new QWidget(this);
214  QVBoxLayout *contentsLayout = new QVBoxLayout(contentsWidget);
215  contentsLayout->setContentsMargins(0, 0, 0 ,0);
216  contentsLayout->setSpacing(0);
217  //
218  QWidget *messageBox = new QWidget(contentsWidget);
219  messageBox->setAttribute(Qt::WA_TranslucentBackground, true);
220  messageBox->setFixedHeight(60);
221  QVBoxLayout *messageBoxLayout = new QVBoxLayout(messageBox);
222  messageBoxLayout->setContentsMargins(10, 10, 10, 3);
223  m_commentsLabel = new QLabel(messageBox);
224  m_commentsLabel->setStyleSheet(TTK::UI::ColorStyle04);
225  QFrame *solidLine = new QFrame(messageBox);
226  solidLine->setFrameShape(QFrame::HLine);
227  solidLine->setFixedHeight(1);
228  solidLine->setStyleSheet(TTK::UI::ColorStyle03);
229  //
230  messageBoxLayout->addWidget(m_commentsLabel);
231  messageBoxLayout->addWidget(solidLine);
232  messageBox->setLayout(messageBoxLayout);
233  //
234  m_messageComments = new QWidget(contentsWidget);
235  QVBoxLayout *messageCommentsLayout = new QVBoxLayout(m_messageComments);
236  messageCommentsLayout->setContentsMargins(0, 0, 0, 0);
237  m_messageComments->setLayout(messageCommentsLayout);
238 
239  contentsLayout->addWidget(messageBox);
240  contentsLayout->addWidget(m_messageComments);
241  contentsWidget->setLayout(contentsLayout);
242  //
243  if(plain)
244  {
245  QScrollArea *scrollArea = new QScrollArea(this);
246  TTK::Widget::generateVScrollAreaStyle(scrollArea, contentsWidget, false);
247 
248  contentsWidget->setObjectName("ContentsWidget");
249  contentsWidget->setStyleSheet(QString("#%1{ %2 }").arg(contentsWidget->objectName(), TTK::UI::BackgroundStyle01));
250  QWidget *view = scrollArea->viewport();
251  view->setObjectName("Viewport");
252  view->setStyleSheet(QString("#%1{ %2 }").arg(view->objectName(), TTK::UI::BackgroundStyle01));
253  //
254  mainLayout->addWidget(topWidget);
255  mainLayout->addWidget(scrollArea);
256  }
257  else
258  {
259  mainLayout->addWidget(contentsWidget);
260  setFixedHeight(210);
261  }
262 
263  initLabel({}, 0);
264  setLayout(mainLayout);
265 }
266 
268 {
270 
271  TTKSemaphoreLoop loop;
272  connect(m_networkRequest, SIGNAL(downLoadDataChanged(QString)), &loop, SLOT(quit()));
274  loop.exec();
275 
276  TTKObjectCast(QVBoxLayout*, m_messageComments->layout())->addStretch(1);
278 
280 }
281 
283 {
285  comment->addCellItem(item);
286  m_commentsItems << comment;
287 
288  QVBoxLayout *layout = TTKObjectCast(QVBoxLayout*, m_messageComments->layout());
289  layout->insertWidget(layout->count() - 1, comment);
290 
291  if(!m_plain)
292  {
293  setFixedHeight(height() + comment->height());
294  }
295 }
296 
298 {
300 
303 }
304 
305 void MusicCommentsWidget::mousePressEvent(QMouseEvent *event)
306 {
307  Q_UNUSED(event);
308 }
309 
310 void MusicCommentsWidget::mouseMoveEvent(QMouseEvent *event)
311 {
312  Q_UNUSED(event);
313 }
314 
316 {
317  Q_UNUSED(event);
318 }
319 
320 void MusicCommentsWidget::initLabel(const QString &name, int total)
321 {
322  m_topLabel->setText(tr("<span style='font-size:15pt;color:#AAAAAA;font-style:bold;'>\"%1\" Commit</span>"
323  "<span style='font-size:11pt;color:#666666;font-style:bold;'> (Just %2 Commits)</span>").arg(name).arg(total));
324  m_commentsLabel->setText(tr("All Comments(%1)").arg(total));
325 }
326 
328 {
329  qDeleteAll(m_commentsItems);
330  m_commentsItems.clear();
331 
332  if(!m_plain)
333  {
334  setFixedHeight(210);
335  }
336 }
337 
339 {
341  connect(m_pageQueryWidget, SIGNAL(clicked(int)), SLOT(buttonClicked(int)));
342 
344  m_messageComments->layout()->addWidget(w);
345 }
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
static const QString ColorStyle04
Definition: musicuiobject.h:46
int exec(ProcessEventsFlags flags=AllEvents)
The class of the label widget that can click.
virtual void startToSearch(const QString &value)
static const QString BorderStyle04
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:238
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:70
The class of the semaphore event loop.
int totalSize() const noexcept
MusicCommentsWidget(QWidget *parent=nullptr)
MusicPageQueryWidget * m_pageQueryWidget
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:76