TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicsongstoolboxwidget.cpp
Go to the documentation of this file.
2 #include "musicitemrenameedit.h"
3 #include "musicsettingmanager.h"
4 #include "musictinyuiobject.h"
5 #include "musicimageutils.h"
6 #include "musicapplication.h"
7 #include "musictopareawidget.h"
8 #include "musicwidgetutils.h"
9 #include "musicsong.h"
10 
11 MusicSongsToolBoxTopWidget::MusicSongsToolBoxTopWidget(int index, const QString &text, QWidget *parent)
12  : MusicFunctionToolBoxTopWidget(index, text, parent),
13  m_songSort(nullptr),
14  m_renameEdit(nullptr)
15 {
16  QPushButton *shareListButton = new QPushButton(this);
17  shareListButton->setToolTip(tr("Share Playlist"));
18  shareListButton->setStyleSheet(TTK::UI::TinyBtnShare);
19  shareListButton->setCursor(QCursor(Qt::PointingHandCursor));
20  shareListButton->setGeometry(265, 12, 16, 16);
21 
22  QPushButton *menuButton = new QPushButton(this);
23  menuButton->setToolTip(tr("Menu"));
24  menuButton->setStyleSheet(TTK::UI::TinyBtnListMenu);
25  menuButton->setCursor(QCursor(Qt::PointingHandCursor));
26  menuButton->setGeometry(290, 12, 16, 16);
27  connect(menuButton, SIGNAL(clicked()), SLOT(showMenu()));
28 
29 #ifdef Q_OS_UNIX
30  shareListButton->setFocusPolicy(Qt::NoFocus);
31  menuButton->setFocusPolicy(Qt::NoFocus);
32 #endif
33 }
34 
36 {
37  delete m_renameEdit;
38 }
39 
41 {
42  Q_EMIT deleteRowItem(m_index);
43 }
44 
46 {
47  Q_EMIT deleteRowItemAll(m_index);
48 }
49 
51 {
52  if(!m_renameEdit)
53  {
54  m_renameEdit = new MusicItemRenameEidt(title(), this);
55  connect(m_renameEdit, SIGNAL(renameFinished(QString)), SLOT(changItemName(QString)));
56  m_renameEdit->setGeometry(m_labelIcon->width(), 3, RENAME_WIDTH, height() - 6);
57  }
58  m_renameEdit->show();
59 }
60 
62 {
63  setTitle(name + m_suffixString);
64  Q_EMIT changRowItemName(m_index, name);
65 
66  m_renameEdit->deleteLater();
67  m_renameEdit = nullptr;
68 }
69 
71 {
72  Q_EMIT addNewFiles(m_index);
73 }
74 
76 {
77  Q_EMIT addNewDir(m_index);
78 }
79 
81 {
83 }
84 
86 {
87  QMenu menu(this);
88  menu.setStyleSheet(TTK::UI::MenuStyle02);
89  menu.addAction(tr("Create Item"), this, SIGNAL(addNewRowItem()));
90  menu.addSeparator();
91 
92  QMenu addNewFiles(tr("Add New Files"), &menu);
93  bool disable = TTK::playlistRowValid(m_index);
94  menu.addMenu(&addNewFiles)->setEnabled(disable);
95  addNewFiles.addAction(tr("Open Files"), this, SLOT(addNewFilesChanged()));
96  addNewFiles.addAction(tr("Open Dir"), this, SLOT(addNewDirChanged()));
97  TTK::Widget::adjustMenuPosition(&addNewFiles);
98 
99  menu.addAction(tr("Play Later"), this, SLOT(addToPlayLater()));
100  menu.addAction(tr("Add To Playlist"), this, SLOT(addToPlayedList()));
101 
102  QMenu sortFiles(tr("Sort"), &menu);
103  sortFiles.addAction(tr("Sort By FileName"))->setData(0);
104  sortFiles.addAction(tr("Sort By Singer"))->setData(1);
105  sortFiles.addAction(tr("Sort By FileSize"))->setData(2);
106  sortFiles.addAction(tr("Sort By AddTime"))->setData(3);
107  sortFiles.addAction(tr("Sort By Duration"))->setData(4);
108  sortFiles.addAction(tr("Sort By PlayCount"))->setData(5);
110  connect(&sortFiles, SIGNAL(triggered(QAction*)), SLOT(songListSortBy(QAction*)));
111 
112  if(m_songSort)
113  {
114  const QList<QAction*> actions(sortFiles.actions());
115  if(-1 < m_songSort->m_type && m_songSort->m_type < actions.count())
116  {
117  const bool asc = m_songSort->m_order == Qt::AscendingOrder;
118  actions[m_songSort->m_type]->setIcon(QIcon(asc ? ":/tiny/lb_sort_asc" : ":/tiny/lb_sort_desc"));
119  }
120  }
121  menu.addMenu(&sortFiles);
122 
123  menu.addAction(tr("Export List"), this, SLOT(exportSongsItemList()));
124  menu.addSeparator();
125 
126  disable = isItemEnabled();
127  menu.addAction(tr("Delete All"), this, SLOT(deleteRowItemAllChanged()));
128  menu.addAction(QIcon(":/contextMenu/btn_delete"), tr("Delete Item"), this, SLOT(deleteRowItemChanged()))->setEnabled(disable);
129  menu.addAction(tr("Rename"), this, SLOT(changRowItemNameChanged()))->setEnabled(disable);
130 
131  menu.exec(QCursor::pos());
132 }
133 
135 {
136  if(m_songSort)
137  {
138  const int type = m_songSort->m_type;
139  const int newType = action->data().toInt();
140  m_songSort->m_type = newType;
141 
142  if(type == newType)
143  {
144  const bool asc = m_songSort->m_order == Qt::AscendingOrder;
145  m_songSort->m_order = asc ? Qt::DescendingOrder : Qt::AscendingOrder;
146  }
147  else
148  {
149  m_songSort->m_order = Qt::AscendingOrder;
150  }
151  Q_EMIT songListSortBy(m_index);
152  }
153 }
154 
156 {
157  Q_EMIT addToPlayLater(m_index);
158 }
159 
161 {
162  Q_EMIT addToPlayedList(m_index);
163 }
164 
166 {
168 }
169 
170 void MusicSongsToolBoxTopWidget::contextMenuEvent(QContextMenuEvent *event)
171 {
172  Q_UNUSED(event);
173  showMenu();
174 }
175 
177 {
179 
180  QPainter painter(this);
181  painter.setRenderHints(QPainter::Antialiasing);
182 
184  {
185  m_isActive = false;
186  painter.fillRect(0, 1, width(), height() - 2, QColor(0, 0, 0, 50));
187  }
188 }
189 
190 
191 
193  : MusicSongsToolBoxTopWidget(-1, {}, parent)
194 {
195  move(0, 0);
196  setFixedWidth(LEFT_SIDE_WIDTH_MIN);
197  m_isBlockMoveExpand = true;
198 
199  hide();
200 
201  m_updateTimer = new QTimer(this);
202  m_updateTimer->setInterval(200 * TTK_DN_MS);
203  connect(m_updateTimer, SIGNAL(timeout()), SLOT(update()));
204  m_updateTimer->start();
205 }
206 
208 {
209  m_updateTimer->stop();
210  delete m_updateTimer;
211 }
212 
214 {
216  alpha = TTK::Image::reRenderValue<int>(0xFF, 0x1F, TTK_RN_MAX - alpha);
217 
218  QWidget::paintEvent(event);
219  QPainter painter(this);
220 
221  QLinearGradient gradient;
222  gradient.setStart(0, 32);
223  gradient.setFinalStop(0, height());
224  gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
225  gradient.setColorAt(0.9, QColor(180, 180, 180, 50));
226  painter.fillRect(0, 32, width(), height(), gradient);
227 
228  const QPixmap pix(MusicTopAreaWidget::instance()->rendererPixmap());
229  painter.drawPixmap(0, 0, width(), height() - 3, pix.copy(1, 91, width(), height() - 3));
230  painter.fillRect(QRect(0, 0, width(), height() - 3), QColor(255, 255, 255, alpha));
231 }
232 
233 
234 
235 MusicSongsToolBoxWidgetItem::MusicSongsToolBoxWidgetItem(int index, const QString &text, QWidget *parent)
237 {
238  m_topWidget = new MusicSongsToolBoxTopWidget(index, text, this);
239  connect(m_topWidget, SIGNAL(addNewRowItem()), SIGNAL(addNewRowItem()));
240  connect(m_topWidget, SIGNAL(deleteRowItem(int)), SIGNAL(deleteRowItem(int)));
241  connect(m_topWidget, SIGNAL(deleteRowItemAll(int)), SIGNAL(deleteRowItemAll(int)));
242  connect(m_topWidget, SIGNAL(changRowItemName(int,QString)), SIGNAL(changRowItemName(int,QString)));
243  connect(m_topWidget, SIGNAL(addNewFiles(int)), SIGNAL(addNewFiles(int)));
244  connect(m_topWidget, SIGNAL(addNewDir(int)), SIGNAL(addNewDir(int)));
245  connect(m_topWidget, SIGNAL(songListSortBy(int)), SIGNAL(songListSortBy(int)));
246  connect(m_topWidget, SIGNAL(addToPlayLater(int)), SIGNAL(addToPlayLater(int)));
247  connect(m_topWidget, SIGNAL(addToPlayedList(int)), SIGNAL(addToPlayedList(int)));
248 
249  initialize();
250 }
251 
253 {
255 }
256 
257 
258 
261 {
262 
263 }
264 
266 {
267  for(int i = 0; i < m_itemList.count(); ++i)
268  {
269  MusicFunctionToolBoxWidgetItem *it = m_itemList[i].m_widgetItem;
270  if(it->item() == item)
271  {
272  TTKObjectCast(MusicSongsToolBoxWidgetItem*, it)->setSongSort(sort);
273  return;
274  }
275  }
276 }
277 
279 {
280  int index = MUSIC_NORMAL_LIST;
281  for(int i = 0; i < m_itemList.count(); ++i)
282  {
283  if(TTK::playlistRowValid(i) && m_itemList[i].m_widgetItem->isExpand())
284  {
285  index = i;
286  break;
287  }
288  }
289  return index;
290 }
291 
293 {
295  it->addCellItem(item);
296  it->setExpand(true);
297  return it;
298 }
The class of the tool box widget item.
MusicSongsToolBoxTopWidget(int index, const QString &text, QWidget *parent=nullptr)
static MusicApplication * instance()
TTK_MODULE_EXPORT bool playlistRowValid(int index)
Definition: musicsong.cpp:95
The class of the function tool box widget.
The class of the function tool box top widget.
static constexpr const char * TinyBtnShare
virtual MusicFunctionToolBoxWidgetItem * initialItem(QWidget *item, const QString &text) overridefinal
static void rendererPixmap(Ui::MusicFileInformationWidget *ui, const QPixmap &pixmap)
void deleteRowItemAll(int index)
void addNewDir(int index)
void setSongSort(MusicSongSort *sort)
void changRowItemName(int index, const QString &name)
MusicItemRenameEidt * m_renameEdit
The class of the tool box top widget.
void songListSortBy(int index)
void setSongSort(QWidget *item, MusicSongSort *sort)
#define TTK_RN_MAX
Definition: ttkglobal.h:359
The class of the item rename edit.
virtual void paintEvent(QPaintEvent *event) override
void addNewFiles(int index)
virtual bool isItemEnabled() const overridefinal
virtual void paintEvent(QPaintEvent *event) overridefinal
const char * name
Definition: http_parser.c:458
The class of the function tool box widget item.
void exportSongsItemList(int index)
MusicSongsToolBoxWidgetItem(int index, const QString &text, QWidget *parent=nullptr)
void changRowItemName(int index, const QString &name)
void deleteRowItem(int index)
void songListSortBy(int index)
MusicSongsToolBoxWidget(QWidget *parent=nullptr)
MusicToolBoxWidgetItemList m_itemList
The class of the music song sort tag.
Definition: musicsong.h:142
void deleteRowItemAll(int index)
static constexpr int RENAME_WIDTH
static const QString MenuStyle02
void changItemName(const QString &name)
void addToPlayLater(int index)
virtual void paintEvent(QPaintEvent *event) override
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
MusicSongsToolBoxMaskWidget(QWidget *parent=nullptr)
void addToPlayedList(int index)
static unsigned char alpha[symbols+1]
Definition: rsecc.c:50
void deleteRowItem(int index)
static constexpr const char * TinyBtnListMenu
Qt::SortOrder m_order
Definition: musicsong.h:145
#define MUSIC_NORMAL_LIST
TTK_MODULE_EXPORT void adjustMenuPosition(QMenu *menu)
static MusicTopAreaWidget * instance()
#define TTK_DN_MS
Definition: ttkglobal.h:270
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:60
void addNewFiles(int index)
MusicFunctionToolBoxTopWidget * m_topWidget
#define LEFT_SIDE_WIDTH_MIN
Definition: musicobject.h:155