TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
musicitemrenameedit.cpp
Go to the documentation of this file.
1 #include "musicitemrenameedit.h"
2 #include "musicstringutils.h"
3 #include "musicuiobject.h"
4 #include "musictoastlabel.h"
5 
7  : QLineEdit(parent),
8  m_focusBlock(false)
9 {
10  setGeometry(1, 0, 330, 20);
11  setStyleSheet(TTK::UI::LineEditStyle01);
12  setFocus(Qt::MouseFocusReason);
13  setFocusPolicy(Qt::ClickFocus);
14 
15  connect(this, SIGNAL(textChanged(QString)), SLOT(textChanged(QString)));
16  connect(this, SIGNAL(editingFinished()), SLOT(renameFinished()));
17 }
18 
19 MusicItemRenameEidt::MusicItemRenameEidt(const QString &text, QWidget *parent)
20  : MusicItemRenameEidt(parent)
21 {
22  setText(text);
23 }
24 
25 void MusicItemRenameEidt::textChanged(const QString &text)
26 {
27  if(TTK::String::isCharValid(text))
28  {
29  backspace();
30  m_focusBlock = true;
31 
32  MusicToastLabel *toast = new MusicToastLabel(this);
33  connect(toast, SIGNAL(finished()), SLOT(animationCloseChanged()));
34 
35  toast->setText(tr("Illegal chars %1").arg(TTK::String::characters().join("")));
36  toast->popup();
37  }
38 }
39 
41 {
42  Q_EMIT renameFinished(text());
43 }
44 
46 {
47  m_focusBlock = false;
48  setFocus(Qt::MouseFocusReason);
49 }
50 
51 void MusicItemRenameEidt::focusOutEvent(QFocusEvent *event)
52 {
53  if(!m_focusBlock)
54  {
55  QLineEdit::focusOutEvent(event);
56  Q_EMIT renameFinished(text());
57  close();
58  }
59  else
60  {
61  Q_UNUSED(event);
62  }
63 }
void setText(const QString &text)
TTK_MODULE_EXPORT bool isCharValid(const QString &value)
TTK_MODULE_EXPORT QStringList characters()
The class of the toast widget.
The class of the item rename edit.
static void popup(const QString &text)
virtual void focusOutEvent(QFocusEvent *event) overridefinal
static const QString LineEditStyle01
LineEdit.
MusicItemRenameEidt(QWidget *parent=nullptr)
void textChanged(const QString &text)