//上一曲 QString PlayList::previous(bool isLoop) { if (!fileList.isEmpty()) { if (isLoop) { if (curIndex == 0) { curIndex = fileList.length() - 1;//循环读取 } else { --curIndex; } ui->playListTable->selectRow(curIndex); tableUpdate(); return fileList[curIndex]; } else { if (curIndex > 0) { --curIndex; ui->playListTable->selectRow(curIndex); tableUpdate(); return fileList[curIndex]; } else { return "stop";//前面没有了。 } } } return "";//空列表 }
//下一曲 参数:是否循环 QString PlayList::next(bool isLoop) { if (!fileList.isEmpty()) { if (isLoop) { if (curIndex < fileList.length() - 1) { ++curIndex; } else { curIndex = 0; } ui->playListTable->selectRow(curIndex);//让视图跟随当前播放歌曲,下一句使该行不选中 tableUpdate(); return fileList[curIndex]; } else { if (curIndex < fileList.length() - 1) { ++curIndex; ui->playListTable->selectRow(curIndex); tableUpdate(); return fileList[curIndex]; } else { return "stop";//后面没有了。此信息将不处理 } } } return "";//空列表 }
//index从0开始计 QString PlayList::playIndex(int index) { curIndex = index; ui->playListTable->selectRow(curIndex); tableUpdate(); return fileList[curIndex]; }
void PlayList::clearAll() { fileList.clear(); timeList.clear(); curIndex = 0; tableUpdate(); }
void PlayList::remove(int index) { if (index <= curIndex && index > -1)//大于-1用于判断是否未选任何项 --curIndex;//删除前方项,上移当前项索引 fileList.removeAt(index); timeList.removeAt(index); tableUpdate(); }
//核心函数,添加歌曲 void PlayList::add(QString fileName) { if (fixSuffix(fileName)) { if ((int)(player->getFileSecond(fileName)) >= lengthFilter) { fileList.append(fileName); timeList.append(player->getFileTotalTime(fileName)); } } tableUpdate(); }
//返回最后一个文件名,并设置索引 QString PlayList::playLast() { if (!fileList.isEmpty()) { curIndex = fileList.length() - 1; ui->playListTable->selectRow(curIndex); tableUpdate(); return fileList[curIndex]; } else { return ""; } }
void SGBattle::SendTableUpdate() { SFProtobufPacket<SevenGamePacket::TableUpdate> tableUpdate(SevenGame::TableUpdate); SGTable* pTable = m_pSevenGameManager->GetTable(); int *paSpadeTable = pTable->GetSpadeTableArray(); int *paHeartTable = pTable->GetHeartTableArray(); int *paCloverTable = pTable->GetCloverTableArray(); int *paDiamondTable = pTable->GetDiamondTableArray(); for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paSpadeTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paSpadeTable[i]); pCard->set_cardtype(TYPE_SPADE); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paHeartTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paHeartTable[i]); pCard->set_cardtype(TYPE_HEART); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paCloverTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paCloverTable[i]); pCard->set_cardtype(TYPE_CLOVER); } } for(int i=1; i<=MAX_CARD_NUM; i++ ) { if(paDiamondTable[i] != -1) { SevenGamePacket::TableUpdate::AddCard* pCard = tableUpdate.GetData().add_card(); pCard->set_cardnum(paDiamondTable[i]); pCard->set_cardtype(TYPE_DIAMOND); } } BroadCast(tableUpdate); }
//核心函数 void PlayList::insert(int index, QString fileName) { if (fixSuffix(fileName)) { if ((int)(player->getFileSecond(fileName)) >= lengthFilter) { if (index < curIndex) ++curIndex;//如果在前端插入,后移播放索引 fileList.insert(index, fileName); timeList.insert(index, player->getFileTotalTime(fileName)); } } tableUpdate(); }