TTKMusicPlayer  4.3.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 ft = font();
26  ft.setBold(false);
27  setFont(ft);
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  TTKIntSet indexes;
50  for(const QModelIndex &index : selectedIndexes())
51  {
52  indexes.insert(index.row());
53  }
54 
55  TTKIntList rows = indexes.values();
56  std::sort(rows.begin(), rows.end());
57  return rows;
58 }
59 
60 void TTKAbstractTableWidget::itemCellEntered(int row, int column)
61 {
62  if(item(m_previousColorRow, 0))
63  {
65  }
66 
67  if(item(row, column))
68  {
69  setRowColor(row, QColor(20, 20, 20, 20));
70  }
71 
72  m_previousColorRow = row;
73 }
74 
75 void TTKAbstractTableWidget::itemCellClicked(int row, int column)
76 {
77  Q_UNUSED(row);
78  Q_UNUSED(column);
79 }
80 
82 {
83  clearContents();
84  setRowCount(0);
85 
86  m_previousColorRow = -1;
87  m_previousClickRow = -1;
88  m_backgroundColor = Qt::transparent;
89 }
90 
92 {
93  QTableWidget::leaveEvent(event);
94  itemCellEntered(-1, -1);
95 }
96 
97 void TTKAbstractTableWidget::setRowColor(int row, const QColor &color) const
98 {
99  for(int i = 0; i < columnCount(); ++i)
100  {
101  QTableWidgetItem *it = item(row, i);
102  if(it)
103  {
104  it->setBackground(color);
105  }
106  }
107 }
virtual void leaveEvent(QEvent *event) override
TTKAbstractTableWidget(QWidget *parent=nullptr)
TTKIntList selectedRows() const
QList< int > TTKIntList
Definition: ttkqtglobal.h:200
void setRowColor(int row, const QColor &color) const
QSet< int > TTKIntSet
Definition: ttkqtglobal.h:199
virtual void itemCellClicked(int row, int column)
virtual void itemCellEntered(int row, int column)