TTKMusicPlayer  4.1.3.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 deleteAllItems(m_index);
48 }
49 
51 {
52  if(!m_renameEdit)
53  {
54  m_renameEdit = new MusicItemRenameEidt(title(false), 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  Q_EMIT changRowItemName(m_index, name);
64 
65  m_renameEdit->deleteLater();
66  m_renameEdit = nullptr;
67 }
68 
70 {
71  Q_EMIT addNewFiles(m_index);
72 }
73 
75 {
76  Q_EMIT addNewDir(m_index);
77 }
78 
80 {
82 }
83 
85 {
86  QMenu menu(this);
87  menu.setStyleSheet(TTK::UI::MenuStyle02);
88  menu.addAction(tr("Create Item"), this, SIGNAL(addNewRowItem()));
89  menu.addSeparator();
90 
91  QMenu addNewFiles(tr("Add New Files"), &menu);
92  bool disable = TTK::playlistRowValid(m_index);
93  menu.addMenu(&addNewFiles)->setEnabled(disable);
94  addNewFiles.addAction(tr("Open Files"), this, SLOT(addNewFilesChanged()));
95  addNewFiles.addAction(tr("Open Dir"), this, SLOT(addNewDirChanged()));
96  TTK::Widget::adjustMenuPosition(&addNewFiles);
97 
98  menu.addAction(tr("Play Later"), this, SLOT(addToPlayLater()));
99  menu.addAction(tr("Add To Playlist"), this, SLOT(addToPlayedList()));
100 
101  QMenu sortFiles(tr("Sort"), &menu);
102  sortFiles.addAction(tr("Sort By FileName"))->setData(0);
103  sortFiles.addAction(tr("Sort By Singer"))->setData(1);
104  sortFiles.addAction(tr("Sort By FileSize"))->setData(2);
105  sortFiles.addAction(tr("Sort By AddTime"))->setData(3);
106  sortFiles.addAction(tr("Sort By Duration"))->setData(4);
107  sortFiles.addAction(tr("Sort By PlayCount"))->setData(5);
109  connect(&sortFiles, SIGNAL(triggered(QAction*)), SLOT(songListSortBy(QAction*)));
110 
111  if(m_songSort)
112  {
113  const QList<QAction*> actions(sortFiles.actions());
114  if(-1 < m_songSort->m_type && m_songSort->m_type < actions.count())
115  {
116  const bool asc = m_songSort->m_order == Qt::AscendingOrder;
117  actions[m_songSort->m_type]->setIcon(QIcon(asc ? ":/tiny/lb_sort_asc" : ":/tiny/lb_sort_desc"));
118  }
119  }
120  menu.addMenu(&sortFiles);
121 
122  menu.addAction(tr("Export List"), this, SLOT(exportSongsItem()));
123  menu.addSeparator();
124 
125  disable = isItemEnabled();
126  menu.addAction(tr("Delete All"), this, SLOT(deleteAllItemsChanged()));
127  menu.addAction(QIcon(":/contextMenu/btn_delete"), tr("Delete Item"), this, SLOT(deleteRowItemChanged()))->setEnabled(disable);
128  menu.addAction(tr("Rename"), this, SLOT(changRowItemNameChanged()))->setEnabled(disable);
129 
130  menu.exec(QCursor::pos());
131 }
132 
134 {
135  if(m_songSort)
136  {
137  const int type = m_songSort->m_type;
138  const int newType = action->data().toInt();
139  m_songSort->m_type = newType;
140 
141  if(type == newType)
142  {
143  const bool asc = m_songSort->m_order == Qt::AscendingOrder;
144  m_songSort->m_order = asc ? Qt::DescendingOrder : Qt::AscendingOrder;
145  }
146  else
147  {
148  m_songSort->m_order = Qt::AscendingOrder;
149  }
150  Q_EMIT songListSortBy(m_index);
151  }
152 }
153 
155 {
156  Q_EMIT addToPlayLater(m_index);
157 }
158 
160 {
161  Q_EMIT addToPlayedList(m_index);
162 }
163 
165 {
167 }
168 
169 void MusicSongsToolBoxTopWidget::contextMenuEvent(QContextMenuEvent *event)
170 {
171  Q_UNUSED(event);
172  showMenu();
173 }
174 
176 {
178 
179  QPainter painter(this);
180  painter.setRenderHints(QPainter::Antialiasing);
181 
183  {
184  m_isActive = false;
185  painter.fillRect(0, 1, width(), height() - 2, QColor(0, 0, 0, 50));
186  }
187 }
188 
189 
190 
192  : MusicSongsToolBoxTopWidget(-1, {}, parent)
193 {
194  move(0, 0);
195  setFixedWidth(LEFT_SIDE_WIDTH_MIN);
196  m_isBlockMoveExpand = true;
197 
198  hide();
199 
200  m_updateTimer = new QTimer(this);
201  m_updateTimer->setInterval(200 * TTK_DN_MS);
202  connect(m_updateTimer, SIGNAL(timeout()), SLOT(update()));
203  m_updateTimer->start();
204 }
205 
207 {
208  m_updateTimer->stop();
209  delete m_updateTimer;
210 }
211 
213 {
215  alpha = TTK::Image::boundValue<int>(0xFF, 0x1F, TTK_RN_MAX - alpha);
216 
217  QWidget::paintEvent(event);
218  QPainter painter(this);
219 
220  QLinearGradient gradient;
221  gradient.setStart(0, 32);
222  gradient.setFinalStop(0, height());
223  gradient.setColorAt(0.1, QColor(150, 150, 150, 150));
224  gradient.setColorAt(0.9, QColor(180, 180, 180, 50));
225  painter.fillRect(0, 32, width(), height(), gradient);
226 
227  const QPixmap pix(MusicTopAreaWidget::instance()->renderPixmap());
228  painter.drawPixmap(0, 0, width(), height() - 3, pix.copy(1, 91, width(), height() - 3));
229  painter.fillRect(QRect(0, 0, width(), height() - 3), QColor(255, 255, 255, alpha));
230 }
231 
232 
233 
234 MusicSongsToolBoxWidgetItem::MusicSongsToolBoxWidgetItem(int index, const QString &text, QWidget *parent)
236 {
237  m_topWidget = new MusicSongsToolBoxTopWidget(index, text, this);
238  connect(m_topWidget, SIGNAL(addNewRowItem()), SIGNAL(addNewRowItem()));
239  connect(m_topWidget, SIGNAL(deleteRowItem(int)), SIGNAL(deleteRowItem(int)));
240  connect(m_topWidget, SIGNAL(deleteAllItems(int)), SIGNAL(deleteAllItems(int)));
241  connect(m_topWidget, SIGNAL(changRowItemName(int,QString)), SIGNAL(changRowItemName(int,QString)));
242  connect(m_topWidget, SIGNAL(addNewFiles(int)), SIGNAL(addNewFiles(int)));
243  connect(m_topWidget, SIGNAL(addNewDir(int)), SIGNAL(addNewDir(int)));
244  connect(m_topWidget, SIGNAL(songListSortBy(int)), SIGNAL(songListSortBy(int)));
245  connect(m_topWidget, SIGNAL(addToPlayLater(int)), SIGNAL(addToPlayLater(int)));
246  connect(m_topWidget, SIGNAL(addToPlayedList(int)), SIGNAL(addToPlayedList(int)));
247 
248  initialize();
249 }
250 
252 {
254 }
255 
256 
257 
260 {
261 
262 }
263 
265 {
266  for(int i = 0; i < m_itemList.count(); ++i)
267  {
268  MusicFunctionToolBoxWidgetItem *it = m_itemList[i].m_widgetItem;
269  if(it->item() == item)
270  {
271  TTKObjectCast(MusicSongsToolBoxWidgetItem*, it)->setSongSort(sort);
272  return;
273  }
274  }
275 }
276 
278 {
279  int index = MUSIC_NORMAL_LIST;
280  for(int i = 0; i < m_itemList.count(); ++i)
281  {
282  if(TTK::playlistRowValid(i) && m_itemList[i].m_widgetItem->isExpand())
283  {
284  index = i;
285  break;
286  }
287  }
288  return index;
289 }
290 
292 {
294  it->addCellItem(item);
295  it->setExpand(true);
296  return it;
297 }
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
void addNewDir(int index)
void setSongSort(MusicSongSort *sort)
void deleteAllItems(int index)
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:364
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.
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
static constexpr int RENAME_WIDTH
static const QString MenuStyle02
void changItemName(const QString &name)
void deleteAllItems(int index)
void addToPlayLater(int index)
virtual void paintEvent(QPaintEvent *event) override
virtual void contextMenuEvent(QContextMenuEvent *event) overridefinal
MusicSongsToolBoxMaskWidget(QWidget *parent=nullptr)
void exportSongsItem(int index)
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:275
#define G_SETTING_PTR
#define TTKObjectCast(x, y)
Definition: ttkqtglobal.h:76
void addNewFiles(int index)
MusicFunctionToolBoxTopWidget * m_topWidget
#define LEFT_SIDE_WIDTH_MIN
Definition: musicobject.h:157