鈴音定時播放系統(tǒng)_第1頁
鈴音定時播放系統(tǒng)_第2頁
鈴音定時播放系統(tǒng)_第3頁
鈴音定時播放系統(tǒng)_第4頁
鈴音定時播放系統(tǒng)_第5頁
已閱讀5頁,還剩21頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、.鈴音定時播放系統(tǒng)程序功能程序的主要功能是定時播放音樂。為了符合學(xué)校的需求,本程序設(shè)定了方案為主的方式,進(jìn)行配置。在一個方案可以隨意建立256條以內(nèi)的項目,每條項目有描述,時間,音樂地址三項描述,可以在24小時的時間內(nèi)自動播放。本程序還內(nèi)置了4種方案,進(jìn)行修改后可以符合學(xué)校不同季節(jié)不同的作息時間安排。程序流程圖1 保存當(dāng)前方案2 保存內(nèi)置的方案3 保存音樂播放數(shù)據(jù)1. 循環(huán)更新時間2. 按時間定時播放音樂3. 顯示下一項目1. 添加項目2. 刪除項目3. 按時間進(jìn)行項目排序程序代碼MusicF.pro#-# Project created by QtCreator 2015-08-07T08:

2、13:53#-QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets QT += multimediawidgetsTARGET = MusicFTEMPLATE = appSOURCES += main.cpp mainwindow.cpp modelmusic.cpp adddlg.cpp datadelegate.cppHEADERS += mainwindow.h modelmusic.h adddlg.h datadelegate.hmain.cpp/主要功能:/顯示程序打開前的畫面/創(chuàng)建主窗口/#include &

3、quot;mainwindow.h"#include <QApplication>#include <QSplashScreen>int main(int argc, char *argv) QApplication a(argc, argv); QPixmap pixmap("first.png"); QSplashScreen splash(pixmap); splash.show(); cessEvents(); MainWindow w; w.resize(QSize(840, 580); w.setWindowTitle

4、("鈴音"); w.setWindowIcon(QIcon("wind.png"); w.show(); splash.finish(&w); return a.exec();mainwindow.h/主要功能:/主窗口類的聲明/#ifndef MAINWINDOW_H#define MAINWINDOW_H#include <QMainWindow>#include <QLabel>#include <QPushButton>#include <QTableView>#include <QC

5、omboBox>#include <QVBoxLayout>#include <QMediaPlayer>#include <QSlider>#include "modelmusic.h"class MainWindow : public QMainWindow Q_OBJECTpublic: MainWindow(QWidget *parent = 0); MainWindow(); void createFrame(); void creatNext(); ModelMusic model;public slots: void

6、addBtnFunction(); void delBtnFunction(); void sortBtnFunction(); void writeBtnFunction(); void doitBtnFunction(); void read(); void showtime(); void setVolume();private: QFrame *mainFrame; QLabel *headerLabel; QLabel *footerLabel; QPushButton *addBtn; QPushButton *delBtn; QPushButton *sortBtn; QPush

7、Button *writeBtn; QPushButton *doitBtn; QTableView *tableView; QMediaPlayer *player; qint32 nextNumber; bool doit; QLabel *timeLabel; QLabel *timeNow; QTimer *timer; QLabel *optionLabel; QComboBox *optionComboBox; QLabel *nextLabel; QLabel *volum; QSlider *slider;#endif / MAINWINDOW_Hmainwindow.cpp/

8、主要功能:/主窗口類的具體函數(shù)實現(xiàn)/#include "mainwindow.h"#include "adddlg.h"#include "datadelegate.h"#include <QHBoxLayout>#include <QGridLayout>#include <QString>#include <QStringList>#include <QFile>#include <QTimer>#include <QDataStream>#inc

9、lude <QPixmap>#include <windows.h>MainWindow:MainWindow(QWidget *parent) : QMainWindow(parent) mainFrame = new QFrame; createFrame(); headerLabel = new QLabel; QPixmap mapheader; mapheader.load("header.png"); headerLabel->setPixmap(mapheader); footerLabel = new QLabel; foote

10、rLabel->setText(tr("footer"); QTime time = QTime:currentTime(); QString str = time.toString("hh:mm"); timeNow->setText(str); player = new QMediaPlayer(this); QFile file("datanow.dat"); if(file.open(QIODevice:ReadOnly) QDataStream in(&file); int size; QString o

11、ne; QString two; QString three; in>>size; model.nowData.clear(); for(int i=0; i<size; i+) in>>three>>two>>one; musicData tmp; tmp.description = three; tmp.time = two; tmp.destination = one; model.nowData.append(tmp); file.close(); model.refresh(); doit = false; footerLabel

12、->setText(tr("編輯中"); QWidget *widget = new QWidget; QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(headerLabel); mainLayout->addWidget(mainFrame); mainLayout->addWidget(footerLabel); widget->setLayout(mainLayout); this->setCentralWidget(widget); connect(

13、addBtn, SIGNAL(clicked(bool), this, SLOT(addBtnFunction(); connect(delBtn, SIGNAL(clicked(bool), this, SLOT(delBtnFunction(); connect(sortBtn, SIGNAL(clicked(bool), this, SLOT(sortBtnFunction(); connect(writeBtn, SIGNAL(clicked(bool), this, SLOT(writeBtnFunction(); connect(doitBtn, SIGNAL(clicked(bo

14、ol), this, SLOT(doitBtnFunction(); connect(optionComboBox, SIGNAL(currentIndexChanged(int), this, SLOT(read(); connect(timer, SIGNAL(timeout(), this, SLOT(showtime(); connect(slider, SIGNAL(valueChanged(int), this, SLOT(setVolume(); Sleep(1000);MainWindow:MainWindow() QFile file("datanow.dat&qu

15、ot;); file.open(QIODevice:WriteOnly | QIODevice:Truncate); QDataStream out(&file); out<<model.nowData.size(); for(int i = 0; i<model.nowData.size(); i+) out<<model.nowDatai.description; out<<model.nowDatai.time; out<<model.nowDatai.destination; file.close();void MainWi

16、ndow:createFrame() QPixmap map; map.load("addbtn.png"); addBtn = new QPushButton; addBtn->clearMask(); addBtn->setFixedSize(map.width(), map.height(); /addBtn->setMask(map.createHeuristicMask(); addBtn->setIcon(map); addBtn->setIconSize(QSize(map.width(), map.height(); addBt

17、n->setToolTip("添加一項項目"); map.load("delbtn.png"); delBtn = new QPushButton; delBtn->clearMask(); delBtn->setFixedSize(map.width(), map.height(); /addBtn->setMask(map.createHeuristicMask(); delBtn->setIcon(map); delBtn->setIconSize(QSize(map.width(), map.height();

18、 delBtn->setToolTip("刪除一項項目"); map.load("sortbtn.png"); sortBtn = new QPushButton; sortBtn->clearMask(); sortBtn->setFixedSize(map.width(), map.height(); /addBtn->setMask(map.createHeuristicMask(); sortBtn->setIcon(map); sortBtn->setIconSize(QSize(map.width(), m

19、ap.height(); sortBtn->setToolTip("排序"); map.load("okbtn.png"); doitBtn = new QPushButton; doitBtn->clearMask(); doitBtn->setFixedSize(map.width(), map.height(); /addBtn->setMask(map.createHeuristicMask(); doitBtn->setIcon(map); doitBtn->setIconSize(QSize(map.wid

20、th(), map.height(); doitBtn->setToolTip("執(zhí)行"); map.load("writebtn.png"); writeBtn = new QPushButton; writeBtn->clearMask(); writeBtn->setFixedSize(map.width(), map.height(); /addBtn->setMask(map.createHeuristicMask(); writeBtn->setIcon(map); writeBtn->setIconSiz

21、e(QSize(map.width(), map.height(); writeBtn->setToolTip("保存"); QVBoxLayout *btnLayout = new QVBoxLayout; btnLayout->addWidget(addBtn); btnLayout->addWidget(delBtn); btnLayout->addWidget(sortBtn); btnLayout->addWidget(writeBtn); btnLayout->addWidget(doitBtn); tableView = n

22、ew QTableView; tableView->setModel(&model); tableView->setSelectionBehavior(QAbstractItemView:SelectRows); tableView->setColumnWidth(2, 350); tableView->setColumnWidth(0, 250); tableView->setColumnWidth(1, 50); /DataDelegate dataDelegate; /tableView->setItemDelegateForColumn(1,

23、 &dataDelegate); optionLabel = new QLabel; optionLabel->setText(tr("方案:"); timeNow = new QLabel; timeLabel = new QLabel; timeLabel->setText(tr("當(dāng)前系統(tǒng)時間:"); nextLabel = new QLabel; timer = new QTimer(this); timer->start(1000); volum = new QLabel; volum->setText(&quo

24、t;音量:"); slider = new QSlider(Qt:Horizontal); slider->setMinimum(0); slider->setMaximum(100); slider->setMaximumWidth(100); slider->setValue(100); optionComboBox = new QComboBox; optionComboBox->addItem("方案一"); optionComboBox->addItem("方案二"); optionComboBox

25、->addItem("方案三"); optionComboBox->addItem("方案四"); QGridLayout *optionLayout = new QGridLayout; optionLayout->addWidget(timeLabel, 0, 0); optionLayout->addWidget(timeNow, 1, 0); optionLayout->addWidget(optionLabel, 2, 0); optionLayout->addWidget(optionComboBox, 3

26、, 0); optionLayout->addWidget(nextLabel, 4, 0); optionLayout->addWidget(volum, 5, 0); optionLayout->addWidget(slider, 6, 0); QHBoxLayout *frameLayout = new QHBoxLayout(mainFrame); frameLayout->addLayout(btnLayout); frameLayout->addWidget(tableView); frameLayout->addLayout(optionLay

27、out);void MainWindow:addBtnFunction() doit = false; footerLabel->setText(tr("編輯中"); addDlg *dlg = new addDlg(&model); dlg->show();void MainWindow:delBtnFunction() doit = false; footerLabel->setText(tr("編輯中"); int row = tableView->currentIndex().row(); model.nowDat

28、a.removeAt(row); model.refresh();void MainWindow:sortBtnFunction() doit = false; footerLabel->setText(tr("編輯中"); for(int i=model.nowData.size()-1; i > 0; i-) for(int j=0; j < i; j+) QStringList pieces1 = model.nowDataj.time.split(":", QString:SkipEmptyParts); QStringList

29、 pieces2 = model.nowDataj+1.time.split(":", QString:SkipEmptyParts); QString one = pieces1.join(""); QString two = pieces2.join(""); if(one.toInt() > two.toInt() musicData tmp; tmp.description = model.nowDataj.description; tmp.destination = model.nowDataj.destination

30、; tmp.time = model.nowDataj.time; model.nowDataj.description = model.nowDataj+1.description; model.nowDataj.destination = model.nowDataj+1.destination; model.nowDataj.time = model.nowDataj+1.time; model.nowDataj+1.description = tmp.description; model.nowDataj+1.destination = tmp.destination; model.n

31、owDataj+1.time = tmp.time; model.refresh();void MainWindow:writeBtnFunction() QFile file; switch(optionComboBox->currentIndex() case 0: file.setFileName("data0.dat"); break; case 1: file.setFileName("data1.dat"); break; case 2: file.setFileName("data2.dat"); break; c

32、ase 3: file.setFileName("data3.dat"); break; default: break; file.open(QIODevice:WriteOnly | QIODevice:Truncate); QDataStream out(&file); out<<model.nowData.size(); for(int i = 0; i<model.nowData.size(); i+) out<<model.nowDatai.description; out<<model.nowDatai.time

33、; out<<model.nowDatai.destination; file.close();void MainWindow:read() QFile file; switch(optionComboBox->currentIndex() case 0: file.setFileName("data0.dat"); break; case 1: file.setFileName("data1.dat"); break; case 2: file.setFileName("data2.dat"); break; ca

34、se 3: file.setFileName("data3.dat"); break; default: break; if(!file.open(QIODevice:ReadOnly) return; QDataStream in(&file); int size; QString one; QString two; QString three; in>>size; model.nowData.clear(); for(int i=0; i<size; i+) in>>three>>two>>one; musi

35、cData tmp; tmp.description = three; tmp.time = two; tmp.destination = one; model.nowData.append(tmp); file.close(); model.refresh();void MainWindow:showtime() QTime time = QTime:currentTime(); QString text = time.toString("hh:mm"); timeNow->setText(text); if(doit) QStringList oneList; Q

36、StringList twoList; QString two; oneList = text.split(":", QString:SkipEmptyParts); twoList = model.nowDatanextNumber.time.split(":", QString:SkipEmptyParts); text = oneList.join(""); two = twoList.join(""); nextLabel->setText(QString("下一計劃:序號%1")

37、.arg(nextNumber+1); if(text.toInt() = two.toInt() player->setMedia(QUrl:fromLocalFile(model.nowDatanextNumber.destination); player->setVolume(100); player->play(); if(nextNumber = model.nowData.size()-1) nextNumber = 0; else nextNumber +; void MainWindow:creatNext() nextNumber = 0; QString

38、tryit; QStringList tryitList; QStringList now; QString nowt; now = timeNow->text().split(":", QString:SkipEmptyParts); nowt = now.join(""); do tryit = model.nowDatanextNumber.time; tryitList = tryit.split(":", QString:SkipEmptyParts); tryit = tryitList.join("&qu

39、ot;); if(nextNumber = model.nowData.size()-1) nextNumber = 0; return; else nextNumber +; while(nowt.toInt() > tryit.toInt() ); nextNumber -; for(int i=nextNumber; i<model.nowData.size(); i+) QString one; QString two; QStringList oneL; QStringList twoL; one = model.nowDatanextNumber.time; two =

40、 model.nowDatai.time; oneL = one.split(":", QString:SkipEmptyParts); twoL = two.split(":", QString:SkipEmptyParts); one = oneL.join(""); two = twoL.join(""); if(two.toInt() >= nowt.toInt() if(one.toInt() > two.toInt() nextNumber = i; void MainWindow:doit

41、BtnFunction() if(!doit) sortBtnFunction(); doit = true; footerLabel->setText(tr("執(zhí)行中"); creatNext(); else doit = false; footerLabel->setText(tr("編輯中"); void MainWindow:setVolume() int volume = slider->value(); player->setVolume(volume);adddlg.h/主要功能:/新建項目類的對話框的聲明/#ifn

42、def ADDDLG_H#define ADDDLG_H#include <mainwindow.h>#include <QDialog>#include <QLabel>#include <QLineEdit>#include <QTimeEdit>#include <QPushButton>#include <QGridLayout>#include <QMediaPlayer>class addDlg : public QDialog Q_OBJECTpublic: addDlg(ModelM

43、usic *, QWidget *parent = 0); /void readDescription(); /void readTime(); /void readDestination(); void writeDescription(QString); void writeTime(QTime); void writeDestination(QString); friend class MainWindow;public slots: void openFile(); void okFuncion(); void cancelFunction(); void playMusic();pr

44、ivate: ModelMusic *musicm; QLabel *title; QLabel *descriptionLabel; QLineEdit *descriptionLineEdit; QLabel *timeLabel; QTimeEdit *timeEdit; QLabel *destinationLabel; QLineEdit *destinationLineEdit; QPushButton *destinationBtn; QPushButton *tryMusicBtn; QPushButton *OkBtn; QPushButton *CleBtn; QMedia

45、Player *player; QGridLayout *mainLayout;#endif / ADDDLG_Hadddlg.cpp/主要功能:/ 新建項目類的對話框的全部實現(xiàn)/#include "adddlg.h"#include "modelmusic.h"#include <QString>#include <QFileDialog>#include <QFont>addDlg:addDlg(ModelMusic *muc, QWidget *parent) :QDialog(parent) musicm =

46、muc; title = new QLabel; title->setText(tr("項目"); QFont font; font.setPointSize(18); font.setBold(true); title->setFont(font); descriptionLabel = new QLabel; descriptionLabel->setText(tr("描述(請輸入對于此項目的描述)"); descriptionLineEdit = new QLineEdit; timeLabel = new QLabel; tim

47、eLabel->setText(tr("時間(請輸入播放的時間)"); timeEdit = new QTimeEdit; destinationLabel = new QLabel; destinationLabel->setText(tr("地址(請輸入播放音樂的地址)"); destinationLineEdit = new QLineEdit; destinationBtn = new QPushButton; destinationBtn->setText(tr("."); player = new QMe

48、diaPlayer(this); player->setVolume(100); tryMusicBtn = new QPushButton; tryMusicBtn->setText(tr("試聽"); OkBtn = new QPushButton; OkBtn->setText(tr("確定"); CleBtn = new QPushButton; CleBtn->setText(tr("取消"); mainLayout = new QGridLayout(this); mainLayout->se

49、tMargin(10); mainLayout->setSpacing(15); mainLayout->addWidget(title, 0, 0, 1, 2); mainLayout->addWidget(descriptionLabel, 1, 0, 1, 2); mainLayout->addWidget(descriptionLineEdit, 2, 0, 1, 2); mainLayout->addWidget(timeLabel, 3, 0, 1, 2); mainLayout->addWidget(timeEdit, 4, 0, 1, 2); mainLayout->

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論