//响应鼠标右键点击事件 void MusicList::contextMenuEvent(QContextMenuEvent *event) { QMenu menu; menu.addAction(QIcon(":/images/shareMusic.png"), tr("分享"), this, SLOT(slot_ShareCurrentMusic())); menu.addAction(QIcon(":/images/locateButton.png"), tr("定位到当前播放歌曲"), this, SLOT(slot_LocateCurrentMusic())); menu.addSeparator(); menu.addAction(QIcon(":/images/delCurrentMusic.png"), tr("删除当前歌曲"), this, SLOT(slot_DelCurrentMusic())); menu.addAction(QIcon(":/images/clearMusicList.png"), tr("清空列表"), this, SLOT(slot_ClearAllMusicList())); menu.addAction(QIcon(":/images/saveList.png"), tr("保存列表"), this, SLOT(slot_SaveList())); menu.addSeparator(); menu.addAction(QIcon(":/images/quitAction.png"), tr("关闭音乐列表"), parent, SLOT(slot_OpenMusicList())); menu.exec(event->globalPos());//返回鼠标指针的全局位置 event->accept(); }
MusicListWidget::MusicListWidget(MusicList *playList, map<QString, int> *mapMusicRows, QWidget *parent) : m_playList(playList), m_mapMusicRows(mapMusicRows), m_parent(parent) { //ÉèÖô°¿Ú»ù±¾ÊôÐÔ this ->resize(400, 450);//ÉèÖô°Ìå´óС this ->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);//È¥µô´°Ìå±ß¿ò this ->setAttribute(Qt::WA_TranslucentBackground);//ÉèÖñ³¾°Í¸Ã÷ this ->setWindowIcon(QIcon(":/images/CZPlayer.png"));//ÉèÖÃlogo this ->setWindowTitle(tr("ÒôÀÖÁбí")); //ËÑË÷¿ò searchLineEdit = new QLineEdit(this); searchLineEdit ->setObjectName(tr("searchLineEdit")); searchLineEdit ->setText(tr("ËÑË÷¸èÊÖ¡¢¸èÇú")); searchLineEdit ->installEventFilter(this); //searchLineEdit ->setPlaceholderText(tr("ËÑË÷¸èÊÖ¡¢¸èÇú")); //ËÑË÷°´Å¥ searchButton = new QPushButton(this); searchButton ->setObjectName(tr("searchButton")); //·µ»Ø backButton = new QPushButton(this); backButton ->setObjectName(tr("backButton")); backButton ->setToolTip(tr("·µ»ØÒôÀÖÁбí")); backButton ->setVisible(false); //Ìí¼Ó¸èÇú addMusicButton = new QPushButton(this); addMusicButton ->setObjectName(tr("addMusicButton")); addMusicButton ->setToolTip(tr("Ìí¼Ó¸èÇú")); //¶¨Î»¸èÇú localeButton = new QPushButton(this); localeButton ->setObjectName(tr("localeButton")); localeButton ->setToolTip(tr("¶¨Î»µ±Ç°²¥·Å¸èÇú")); //ɾ³ýµ±Ç°¸èÇú delMusicButton = new QPushButton(this); delMusicButton ->setObjectName(tr("delMusicButton")); delMusicButton ->setToolTip(tr("ɾ³ýµ±Ç°¸èÇú")); //ËÑË÷¸èÇú findButton = new QPushButton(this); findButton ->setObjectName(tr("findButton")); findButton ->setToolTip(tr("ËÑË÷¸èÇú")); //Ìí¼Ó¸èÇú addMusicAction = new QAction(this); addMusicAction ->setIcon(QIcon(":/images/addMusic.png")); addMusicAction ->setText(tr("Ìí¼Ó¸èÇú")); //Ìí¼Ó²¥·ÅÁбí addMusicListAction = new QAction(this); addMusicListAction ->setIcon(QIcon(":/images/addMusicList.png")); addMusicListAction ->setText(tr("ÔØÈë²¥·ÅÁбí")); //¶¨Ê±Æ÷ timer = new QTimer(this); timer ->start(1000); QSpacerItem *topItem = new QSpacerItem(380, 37, QSizePolicy::Fixed, QSizePolicy::Fixed); QSpacerItem *bottomItem = new QSpacerItem(380, 30, QSizePolicy::Fixed, QSizePolicy::Fixed); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout ->addItem(topItem); mainLayout ->addWidget(m_playList); mainLayout ->addItem(bottomItem); this ->setLayout(mainLayout); searchLineEdit ->setGeometry(27, 7, 250, 30); searchButton ->setGeometry(287, 9, 90, 30); backButton ->setGeometry(257, 15, 15, 14); // m_playList ->setGeometry(10, 37, 380, 360); addMusicButton ->setGeometry(60, 417, 25, 25); localeButton ->setGeometry(145, 417, 25, 25); delMusicButton ->setGeometry(230, 417, 25, 25); findButton ->setGeometry(315, 417, 25, 25); //ÐźÅÓë²Û connect(addMusicButton, SIGNAL(clicked()), this, SLOT(slot_OnClickedAddMusic())); //Ìí¼Ó¸èÇú connect(localeButton, SIGNAL(clicked()), m_playList, SLOT(slot_LocateCurrentMusic())); //¶¨Î»µ±Ç°²¥·Å¸èÇú connect(delMusicButton, SIGNAL(clicked()), m_playList, SLOT(slot_DelCurrentMusic())); //ɾ³ýµ±Ç°¸èÇú connect(searchButton, SIGNAL(clicked()), this, SLOT(slot_SearchMusic())); //ËÑË÷¸èÇú connect(timer, SIGNAL(timeout()), this, SLOT(slot_LineEditFocus())); //ÊäÈë¿ò¾Û½¹ connect(backButton, SIGNAL(clicked()), this, SLOT(slot_BackMusicList())); //·µ»ØÒôÀÖÁбí connect(addMusicAction, SIGNAL(triggered()), this, SLOT(slot_AddMusic())); //Ìí¼Ó¸èÇú connect(addMusicListAction, SIGNAL(triggered()), this, SLOT(slot_AddMusicList())); //Ìí¼Ó²¥·ÅÁбí }
MusicList::MusicList(Phonon::MediaObject *mediaObject, QList<Phonon::MediaSource> *sources, QWidget *widget) : m_mediaObject(mediaObject), m_sources(sources), parent(widget) { //设置窗口基本属性 this ->resize(380, 360);//设置窗体大小 //this ->setWindowFlags(Qt::FramelessWindowHint);//去掉窗体边框 this ->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);//去掉窗体边框,不在任务栏显示图标 //this ->setAttribute(Qt::WA_TranslucentBackground);//设置背景透明 this ->setWindowIcon(QIcon(":/images/CZPlayer.png"));//设置logo this ->setWindowTitle(tr("音乐播放列表")); this ->setRowCount(0);//初始化的行数为0 this ->setColumnCount(4);//初始化的列数为3 QStringList headList; headList << tr("序号") << tr("标题") << tr("艺术家") << tr("长度"); this ->setHorizontalHeaderLabels(headList);//设置头信息 this ->horizontalHeader() ->setVisible(false); this ->verticalHeader() ->setVisible(false); //this ->horizontalHeader() ->setResizeMode(QHeaderView::Stretch);//设置内容自动横向填满可用区域 this ->horizontalHeader() ->resizeSection(0, 30); this ->horizontalHeader() ->resizeSection(1, 170); this ->horizontalHeader() ->resizeSection(2, 100); this ->horizontalHeader() ->resizeSection(3, 65); this ->horizontalHeader() ->setHighlightSections(false);//点击表时不对表头行光亮(获取焦点) this ->horizontalHeader() ->setClickable(false);//不响应鼠标单击 this ->setSelectionMode(QAbstractItemView::SingleSelection);//设置只能选中单行 this ->setSelectionBehavior(QAbstractItemView::SelectRows);//设置选择习惯为选择行 this ->setEditTriggers(QAbstractItemView::NoEditTriggers);//设置内容不可编辑 this ->setShowGrid(false);//设置不显示网格 this ->setItemDelegate(new NoFocusDelegate());//去掉选中单元格的虚线 // QTableWidgetItem *columnHeadItem = this ->horizontalHeaderItem(0); // columnHeadItem ->setFont(QFont("幼圆")); // columnHeadItem ->setBackground(Qt::gray); // columnHeadItem ->setTextColor(Qt::white); // QTableWidgetItem *columnHeadItem2 = this ->horizontalHeaderItem(1); // columnHeadItem2 ->setFont(QFont("幼圆")); // columnHeadItem2 ->setBackground(Qt::gray); // columnHeadItem2 ->setTextColor(Qt::white); // QTableWidgetItem *columnHeadItem3 = this ->horizontalHeaderItem(2); // columnHeadItem3 ->setFont(QFont("幼圆")); // columnHeadItem3 ->setBackground(Qt::gray); // columnHeadItem3 ->setTextColor(Qt::white); //设置header样式 this ->horizontalHeader() ->setStyleSheet("QHeaderView::section{background: gray; color:white; font-family:'微软雅黑'}"); this ->setStyleSheet("QTableCornerButton::section{background:gray};");//设置表格直角方格样式 this ->verticalHeader() ->setStyleSheet("QHeaderView::section{background: gray; color:white; font-family:'微软雅黑';}"); clearMusicList = new QAction(this); clearMusicList ->setIcon(QIcon(":/images/clearMusicList.png")); clearMusicList ->setText(tr("清空列表")); closeAction = new QAction(this); closeAction ->setIcon(QIcon(":/images/quitAction")); closeAction ->setText(tr("关闭音乐列表")); delCurrentMusicAction = new QAction(this); delCurrentMusicAction ->setIcon(QIcon(":/images/delCurrentMusic.png")); delCurrentMusicAction ->setText(tr("删除当前歌曲")); saveListAction = new QAction(this); saveListAction ->setIcon(QIcon(":/images/saveList.png")); saveListAction ->setText(tr("保存列表")); connect(clearMusicList, SIGNAL(triggered()), this, SLOT(slot_ClearAllMusicList())); connect(closeAction, SIGNAL(triggered()), parent, SLOT(slot_OpenMusicList())); connect(delCurrentMusicAction, SIGNAL(triggered()), this, SLOT(slot_DelCurrentMusic())); connect(saveListAction, SIGNAL(triggered()), this, SLOT(slot_SaveList())); connect(this, SIGNAL(cellClicked(int,int)), this, SLOT(slot_TableClicked(int))); }