Beispiel #1
0
MusicPage::MusicPage(QWidget *parent) : QWidget(parent)
{
    this->setAttribute(Qt::WA_TranslucentBackground, true);//设置透明:窗体标题栏不透明,背景透明

    QHBoxLayout *controlLayout = new QHBoxLayout;
    addButton = new QPushButton("添加");
    addButton->setFixedHeight(22);
    controlLayout->addWidget(addButton);
    controlLayout->setSpacing(1);
    controlLayout->setMargin(0);
    connect(addButton, SIGNAL(clicked(bool)), this, SIGNAL(addMusics()));

    QWidget *controlBar = new QWidget;
    controlBar->setStyleSheet("background:rgba(244,244,244,40%);");
    //controlBar->setAttribute(Qt::WA_TranslucentBackground, true);
    controlBar->setFixedHeight(22);
    controlBar->setLayout(controlLayout);

    QPushButton *addList = new QPushButton("+创建列表");
    addList->setStyleSheet("background:rgba(244,244,244,40%);");

    listList = new ListList;
    connect(addList, SIGNAL(clicked(bool)), listList, SLOT(wantToCreateList()));
    connect(listList, SIGNAL(tryToCreateList(QString)), this, SIGNAL(tryToCreateList(QString)));
    connect(this, SIGNAL(createList(QString)), listList, SLOT(createList(QString)));
    connect(this, SIGNAL(createList(QString)), this, SLOT(createList()));
    connect(listList, SIGNAL(changeList(int)), this, SLOT(changeMusicList(int)));
    connect(listList, SIGNAL(deleteList(QString)), this, SIGNAL(deleteList(QString)));
    connect(listList, SIGNAL(deleteList(int)), this, SLOT(deleteList(int)));

    QVBoxLayout *leftLayout = new QVBoxLayout;
    leftLayout->addWidget(addList);
    leftLayout->addWidget(listList);
    leftLayout->setSpacing(1);
    leftLayout->setMargin(0);

    QWidget *leftWidget = new QWidget;
    leftWidget->setLayout(leftLayout);
    //leftWidget->setFixedWidth(80);
    leftWidget->setMinimumWidth(80);
    leftWidget->setMaximumWidth(120);

    musicLists = new QStackedWidget;
    musicLists->setMinimumWidth(80);
    musicLists->setMaximumWidth(420);

    QSplitter *splitter = new QSplitter(Qt::Horizontal, this);
    splitter->setOpaqueResize(true);
    splitter->setChildrenCollapsible(false);
    splitter->addWidget(leftWidget);
    splitter->addWidget(musicLists);
    splitter->setStretchFactor(0, 2);
    splitter->setStretchFactor(1, 5);
    splitter->setStyleSheet("QSplitter::handle { background-color: rgba(0,0,0,0%) }");
    splitter->setHandleWidth(1);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(controlBar);
    //mainLayout->addLayout(midLayout);
    mainLayout->addWidget(splitter);
    mainLayout->setSpacing(1);
    mainLayout->setMargin(1);

    this->setLayout(mainLayout);
}
Beispiel #2
0
MusicWindow::MusicWindow(QWidget *parent) : MainWindow(parent)
{
    this->setWindowIcon(QIcon(":/images/icons/app_icon"));

    systemTrayIcon = new MySystemTrayIcon(this);
    connect(systemTrayIcon, SIGNAL(showWindow()), this, SLOT(show()));
    connect(systemTrayIcon, SIGNAL(quit()), this, SLOT(close()));

    player = new MyPlayer();
    connect(player, SIGNAL(playerStateChanged(int)), this, SLOT(playerStateChanged(int)));
    connect(player, SIGNAL(musicChanged(QString,int)), this, SLOT(musicChanged(QString,int)));

    topBar = new TopBar(this);
    connect(topBar, SIGNAL(setMinSize()), this, SLOT(showMinimized()));
    connect(topBar, SIGNAL(setMaxSize()), this, SLOT(setMaxSize()));
    connect(topBar, SIGNAL(closeWindow()), this, SLOT(hide()));
    connect(topBar, SIGNAL(quit()), this, SLOT(close()));
    connect(topBar, SIGNAL(setBackgroud(QString)), this, SLOT(setBackgroud(QString)));
    connect(topBar, SIGNAL(aboutQtMusic()), this, SLOT(aboutQtMusic()));

    fuctionPage = new QStackedWidget;
    fuctionPage->setMinimumWidth(200);

    lyricLabel = new LyricLabel(false, this);
    connect(player, SIGNAL(positionChanged(qint64)), lyricLabel, SLOT(postionChanged(qint64)));
    connect(lyricLabel, SIGNAL(changeTo(qint64)), player, SLOT(setPosition(qint64)));

    networkPage = new NetworkPage();

    QLabel *label2 = new QLabel("Network");
    label2->setAlignment(Qt::AlignCenter);
    QLabel *label3 = new QLabel("Download");
    label3->setAlignment(Qt::AlignCenter);
    fuctionPage->addWidget(lyricLabel);
    fuctionPage->addWidget(networkPage);
    fuctionPage->addWidget(label3);
    fuctionPage->setCurrentIndex(0);
    connect(topBar, SIGNAL(selectFuction(int)), fuctionPage, SLOT(setCurrentIndex(int)));

    musicPage = new MusicPage;
    musicPage->setMaximumWidth(500);
    musicPage->setMinimumWidth(300);
    connect(musicPage, SIGNAL(tryToCreateList(QString)), this, SLOT(tryToCreateList(QString)));
    connect(musicPage, SIGNAL(deleteList(QString)), this, SLOT(deleteList(QString)));
    connect(musicPage, SIGNAL(addMusics()), this, SLOT(addMusics()));
    connect(musicPage, SIGNAL(play(QString,int)), player, SLOT(playTheMusic(QString,int)));
    connect(musicPage, SIGNAL(removeTheMusic(QString,int)), this, SLOT(removeTheMusic(QString,int)));
    connect(musicPage, SIGNAL(removeAllMusics(QString)), this, SLOT(removeAllMusics(QString)));
    connect(musicPage, SIGNAL(moveMusic(QString,int,int)), this, SLOT(moveMusic(QString,int,int)));

    bottomBar = new BottomBar(this);
    connect(bottomBar, SIGNAL(setVoice(int)), player, SLOT(setVoice(int)));
    connect(bottomBar, SIGNAL(setMode(int)), player, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(setPostion(qint64)), player, SLOT(setPosition(qint64)));
    connect(bottomBar, SIGNAL(setPostion(qint64)), lyricLabel, SLOT(setPostion(qint64)));
    connect(player, SIGNAL(durationChanged(qint64)), bottomBar, SLOT(setMaxDuration(qint64)));
    connect(player, SIGNAL(positionChanged(qint64)), bottomBar, SLOT(changePostionTo(qint64)));
    connect(musicPage, SIGNAL(play(QString,int)), bottomBar, SLOT(setPostionAvailable()));
    connect(bottomBar, SIGNAL(tryplay()), this, SLOT(clickPlay()));
    connect(bottomBar, SIGNAL(playPre()), this, SLOT(playPre()));
    connect(bottomBar, SIGNAL(playNext()), this, SLOT(playNext()));
    connect(systemTrayIcon, SIGNAL(setMode(int)), bottomBar, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(setMode(int)), systemTrayIcon, SLOT(setPlayMode(int)));
    connect(bottomBar, SIGNAL(showLyric(QString)), topBar, SLOT(changeFuction(QString)));
    //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SLOT(changePostionTo(qint64)));
    //connect(lyricLabel, SIGNAL(changeTo(qint64)), bottomBar, SIGNAL(setPostion(qint64)));

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(topBar);

    QSplitter *splitter = new QSplitter(Qt::Horizontal, this);
    //设定分割窗口的分割条在拖动时是否为实时更新 true为实时更新 false则在拖动时只显示一条灰色的线条
    //在拖动到位并弹起鼠标后再显示分隔条
    splitter->setOpaqueResize(false);
    splitter->setChildrenCollapsible(false);
    splitter->addWidget(fuctionPage);
    splitter->addWidget(musicPage);
    splitter->setStretchFactor(0, 10);
    splitter->setStretchFactor(1, 1);
    splitter->setStyleSheet("QSplitter::handle { background-color: rgba(0,0,0,0%) }");
    splitter->setHandleWidth(4);
    mainLayout->addWidget(splitter);
    mainLayout->addWidget(bottomBar);
    mainLayout->setMargin(1);
    mainLayout->setSpacing(3);
    this->setLayout(mainLayout);

    dealMouse();
    readData();
}