TTKMusicPlayer  3.7.0.0
TTKMusicPlayer imitates Kugou UI, the music player uses of qmmp core library based on Qt for windows and linux
ttkabstracttablewidget.cpp
Go to the documentation of this file.
2 
4  : QTableWidget(parent),
5  m_previousColorRow(-1),
6  m_previousClickRow(-1),
7  m_backgroundColor(255, 255, 255, 0)
8 {
9  setAttribute(Qt::WA_TranslucentBackground);
10  setColumnCount(3);
11  setRowCount(0);
12 
13  QHeaderView *headerView = horizontalHeader();
14  headerView->setMinimumSectionSize(0);
15  headerView->setVisible(false);
16  headerView->resizeSection(0, 20);
17  headerView->resizeSection(1, 247);
18  headerView->resizeSection(2, 45);
19  verticalHeader()->setVisible(false);
20 
21  setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22 
23  setMouseTracking(true); //Open the capture mouse function
24 
25  QFont font = this->font();
26  font.setBold(false);
27  setFont(font);
28 
29  setShowGrid(false);//Does not display the grid
30  setFrameShape(QFrame::NoFrame);//Set No Border
31  setEditTriggers(QAbstractItemView::NoEditTriggers);//No edit
32  setSelectionBehavior(QAbstractItemView::SelectRows);
33  setSelectionMode(QAbstractItemView::SingleSelection);
34  setFocusPolicy(Qt::NoFocus);
35 
36  QPalette plt = palette();
37  plt.setBrush(QPalette::Base, QBrush(QColor(255, 255, 255, 150)));
38 #if defined Q_OS_UNIX && !TTK_QT_VERSION_CHECK(5,7,0) //Fix linux selection-background-color stylesheet bug
39  plt.setBrush(QPalette::Highlight, QColor(20, 20, 20, 20));
40 #endif
41  setPalette(plt);
42 
43  connect(this, SIGNAL(cellEntered(int,int)), SLOT(itemCellEntered(int,int)));
44  connect(this, SIGNAL(cellClicked(int,int)), SLOT(itemCellClicked(int,int)));
45 }
46 
48 {
49 
50 }
51 
53 {
54  TTKIntSet rows;
55  for(const QModelIndex &index : selectedIndexes())
56  {
57  rows.insert(index.row());
58  }
59 
60  TTKIntList indexs = rows.values();
61  std::sort(indexs.begin(), indexs.end());
62  return indexs;
63 }
64 
65 void TTKAbstractTableWidget::itemCellEntered(int row, int column)
66 {
67  if(item(m_previousColorRow, 0))
68  {
70  }
71 
72  if(item(row, column))
73  {
74  setRowColor(row, QColor(20, 20, 20, 20));
75  }
76 
77  m_previousColorRow = row;
78 }
79 
80 void TTKAbstractTableWidget::itemCellClicked(int row, int column)
81 {
82  Q_UNUSED(row);
83  Q_UNUSED(column);
84 }
85 
87 {
88  clearContents();
89  setRowCount(0);
90 
91  m_previousColorRow = -1;
92  m_previousClickRow = -1;
93  m_backgroundColor = Qt::transparent;
94 }
95 
97 {
98  QTableWidget::leaveEvent(event);
99  itemCellEntered(-1, -1);
100 }
101 
102 void TTKAbstractTableWidget::setRowColor(int row, const QColor &color) const
103 {
104  for(int i = 0; i < columnCount(); ++i)
105  {
106  QTableWidgetItem *it = item(row, i);
107  if(it)
108  {
109  it->setBackground(color);
110  }
111  }
112 }
virtual void leaveEvent(QEvent *event) override
TTKAbstractTableWidget(QWidget *parent=nullptr)
QList< int > TTKIntList
Definition: ttkqtglobal.h:188
void setRowColor(int row, const QColor &color) const
QSet< int > TTKIntSet
Definition: ttkqtglobal.h:187
virtual void itemCellClicked(int row, int column)
virtual void itemCellEntered(int row, int column)
TTKIntList selectedIndexList() const