commit 8df2ee44e0e9151681bb3c546f1327ef90e305e1 Author: Gary Wang Date: Mon Apr 6 15:15:13 2020 +0800 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1358d83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8d85f48 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.5) + +project(pineapple-music LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(Qt5 COMPONENTS Widgets REQUIRED) + +add_executable(pineapple-music + main.cpp + mainwindow.cpp + mainwindow.h + seekableslider.cpp + seekableslider.h + mainwindow.ui + resources.qrc +) + +target_link_libraries(pineapple-music PRIVATE Qt5::Widgets) diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user new file mode 100644 index 0000000..6885971 --- /dev/null +++ b/CMakeLists.txt.user @@ -0,0 +1,344 @@ + + + + + + EnvironmentId + {9f1781ab-997a-40f7-b069-9b551fb2d8f3} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.13.1 MinGW 64-bit + Desktop Qt 5.13.1 MinGW 64-bit + qt.qt5.5131.win64_mingw73_kit + 0 + 0 + 0 + + + CMAKE_BUILD_TYPE:STRING=Debug + + C:/Users/Gary/Source/build-pineapple-music-Desktop_Qt_5_13_1_MinGW_64_bit-Debug + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=Release + + C:/Users/Gary/Source/build-pineapple-music-Desktop_Qt_5_13_1_MinGW_64_bit-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=RelWithDebInfo + + C:/Users/Gary/Source/build-pineapple-music-Desktop_Qt_5_13_1_MinGW_64_bit-Release-with-Debug-Information + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release with Debug Information + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + + CMAKE_BUILD_TYPE:STRING=MinSizeRel + + C:/Users/Gary/Source/build-pineapple-music-Desktop_Qt_5_13_1_MinGW_64_bit-Minimum-Size-Release + + + + + all + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Build + + ProjectExplorer.BuildSteps.Build + + + + + + clean + + true + CMake Build + + CMakeProjectManager.MakeStep + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Minimum Size Release + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + pineapple-music + CMakeProjectManager.CMakeRunConfiguration.C:/Users/Gary/Source/pineapple-music///::///pineapple-music + + 3768 + false + true + false + false + true + + C:/Users/Gary/Source/build-pineapple-music-Desktop_Qt_5_13_1_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/icons/audio-volume-high.png b/icons/audio-volume-high.png new file mode 100644 index 0000000..a1ab4fd Binary files /dev/null and b/icons/audio-volume-high.png differ diff --git a/icons/media-playback-start.png b/icons/media-playback-start.png new file mode 100644 index 0000000..37ee0c8 Binary files /dev/null and b/icons/media-playback-start.png differ diff --git a/icons/media-playback-stop.png b/icons/media-playback-stop.png new file mode 100644 index 0000000..751449e Binary files /dev/null and b/icons/media-playback-stop.png differ diff --git a/icons/media-playlist-repeat.png b/icons/media-playlist-repeat.png new file mode 100644 index 0000000..2e1b3fc Binary files /dev/null and b/icons/media-playlist-repeat.png differ diff --git a/icons/media-skip-backward.png b/icons/media-skip-backward.png new file mode 100644 index 0000000..61bcb09 Binary files /dev/null and b/icons/media-skip-backward.png differ diff --git a/icons/media-skip-forward.png b/icons/media-skip-forward.png new file mode 100644 index 0000000..95a963f Binary files /dev/null and b/icons/media-skip-forward.png differ diff --git a/icons/view-media-playlist.png b/icons/view-media-playlist.png new file mode 100644 index 0000000..98ffdce Binary files /dev/null and b/icons/view-media-playlist.png differ diff --git a/icons/window-close.png b/icons/window-close.png new file mode 100644 index 0000000..d0ac6e7 Binary files /dev/null and b/icons/window-close.png differ diff --git a/icons/window-minimize.png b/icons/window-minimize.png new file mode 100644 index 0000000..d6ab8fd Binary files /dev/null and b/icons/window-minimize.png differ diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..aff48df --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..4c6c0f8 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,80 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" + +#include +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + this->setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint); + this->setAttribute(Qt::WA_TranslucentBackground, true); + + m_bgLinearGradient.setColorAt(0, QColor(255, 255, 255, 25)); // a:0 + m_bgLinearGradient.setColorAt(1, QColor(255, 255, 255, 200)); + m_bgLinearGradient.setStart(0, 0); + m_bgLinearGradient.setFinalStop(0, height()); + + m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity", this); + m_fadeOutAnimation->setDuration(400); + m_fadeOutAnimation->setStartValue(1); + m_fadeOutAnimation->setEndValue(0); + connect(m_fadeOutAnimation, &QPropertyAnimation::finished, this, &QMainWindow::close); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::closeEvent(QCloseEvent *) +{ + qApp->exit(); +} + +void MainWindow::paintEvent(QPaintEvent * e) +{ + QPainter painter(this); + + painter.setBrush(QBrush(m_bgLinearGradient)); + painter.setPen(Qt::NoPen); + painter.drawRect(0, 0, width(), height()); + + return QMainWindow::paintEvent(e); +} + +void MainWindow::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton && !isMaximized()) { + m_clickedOnWindow = true; + m_oldMousePos = event->pos(); + event->accept(); + } + + return QMainWindow::mousePressEvent(event); +} + +void MainWindow::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton && m_clickedOnWindow) { + move(event->globalPos() - m_oldMousePos); + event->accept(); + } + + return QMainWindow::mouseMoveEvent(event); +} + +void MainWindow::mouseReleaseEvent(QMouseEvent *event) +{ + m_clickedOnWindow = false; + + return QMainWindow::mouseReleaseEvent(event); +} + +void MainWindow::on_closeWindowBtn_clicked() +{ + m_fadeOutAnimation->start(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..6f9b7ec --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,39 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } + +class QPropertyAnimation; +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow() override; + +protected: + void closeEvent(QCloseEvent *) override; + void paintEvent(QPaintEvent *e) override; + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + +private slots: + void on_closeWindowBtn_clicked(); + +private: + QPoint m_oldMousePos; + bool m_clickedOnWindow = false; + QLinearGradient m_bgLinearGradient; + + Ui::MainWindow *ui; + + QPropertyAnimation *m_fadeOutAnimation; +}; +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..edf7775 --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,537 @@ + + + MainWindow + + + + 0 + 0 + 485 + 160 + + + + + 485 + 160 + + + + Pineapple Player + + + /****** Slider ******/ + +QSlider::groove:horizontal { + border: 1px solid grey; + border-radius: 3px; + height: 4px; + margin: 0px 0; +} + +QSlider::sub-page:horizontal { + border-radius: 3px; + background: rgb(85, 170, 0); +} + +QSlider::groove:vertical { + border: 1px solid grey; + border-radius: 3px; + width: 4px; + margin: 0px 0; +} + +QSlider::handle:vertical { + border-radius: 3px; + border: 0px solid #5c5c5c; + background: rgb(85, 170, 0); + margin: -5px -5px -5px -5px; + top: 5px; bottom: 5px; +} + +QSlider::handle:vertical:hover { + border-radius: 3px; + border: 0px solid #5c5c5c; + background: rgb(85, 255, 0); + margin: -5px -5px -5px -5px; + top: 5px; bottom: 5px; +} + +QSlider::add-page:vertical { + border-radius: 3px; + background: rgb(85, 170, 0); +} + +/****** PushButton ******/ + +QPushButton { + border: 0px solid grey; + background-color: transparent; +} + +QPushButton:hover { + background-color: rgba(255, 255, 255, 220); +} + +QPushButton:pressed { + background-color: rgba(255, 255, 255, 250); +} + +QPushButton#closeWindowBtn { + color: white; + background-color: rgb(230, 0, 0); +} + +QPushButton#closeWindowBtn:hover { + background-color: rgb(255, 0, 0); +} + +/****** Label ******/ + +QLabel#coverLabel{ + border: 1px solid grey; +} + + + + + + + + 0 + 0 + + + + + 7 + + + 10 + + + 0 + + + 0 + + + 0 + + + + + 10 + + + + + + 0 + 0 + + + + + 128 + 128 + + + + + 128 + 128 + + + + AlbumCover + + + + + + + 0 + + + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 25 + 20 + + + + ^ + + + + + + + + 25 + 20 + + + + + + + + :/icons/icons/window-minimize.png:/icons/icons/window-minimize.png + + + + + + + + 40 + 20 + + + + + 40 + 20 + + + + + + + + :/icons/icons/window-close.png:/icons/icons/window-close.png + + + + + + + + + QLayout::SetDefaultConstraint + + + 10 + + + 10 + + + + + + 0 + 0 + + + + The Doge Song - Various Artists + + + + + + + 44100 Hz | 233 Kbps | Stereo | MP3 + + + + + + + + + 1:10 + + + + + + + 3:12 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + + + + + 5 + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + + + + :/icons/icons/media-playback-start.png:/icons/icons/media-playback-start.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/media-playback-stop.png:/icons/icons/media-playback-stop.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/media-skip-backward.png:/icons/icons/media-skip-backward.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/media-skip-forward.png:/icons/icons/media-skip-forward.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/view-media-playlist.png:/icons/icons/view-media-playlist.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/media-playlist-repeat.png:/icons/icons/media-playlist-repeat.png + + + + 32 + 32 + + + + + + + + + 32 + 32 + + + + + 32 + 32 + + + + + + + + :/icons/icons/audio-volume-high.png:/icons/icons/audio-volume-high.png + + + + 32 + 32 + + + + + + + + + 64 + 32 + + + + 99 + + + Qt::Horizontal + + + + + + + + + + + + + + + + + SeekableSlider + QSlider +
seekableslider.h
+
+
+ + + + +
diff --git a/resources.qrc b/resources.qrc new file mode 100644 index 0000000..98f22de --- /dev/null +++ b/resources.qrc @@ -0,0 +1,13 @@ + + + icons/media-playback-start.png + icons/media-playback-stop.png + icons/media-skip-backward.png + icons/media-skip-forward.png + icons/audio-volume-high.png + icons/media-playlist-repeat.png + icons/view-media-playlist.png + icons/window-close.png + icons/window-minimize.png + + diff --git a/seekableslider.cpp b/seekableslider.cpp new file mode 100644 index 0000000..4d79ad4 --- /dev/null +++ b/seekableslider.cpp @@ -0,0 +1,29 @@ +#include "seekableslider.h" + +SeekableSlider::SeekableSlider(QWidget *parent) : + QSlider(parent) +{ + //关闭分段移动 + setSingleStep(0); + setPageStep(0); +} + +//点击Slider即可调节Value +//只写了横向模式的Slider…… +void SeekableSlider::mousePressEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton) { + QSlider::mousePressEvent(event); + double pos = event->pos().x() / (double)width(); + setValue(pos * (maximum() - minimum()) + minimum()); + } +} + +void SeekableSlider::mouseMoveEvent(QMouseEvent *event) +{ + if (event->buttons() & Qt::LeftButton) { + QSlider::mousePressEvent(event); + double pos = event->pos().x() / (double)width(); + setValue(pos * (maximum() - minimum()) + minimum()); + } +} diff --git a/seekableslider.h b/seekableslider.h new file mode 100644 index 0000000..3ed4e50 --- /dev/null +++ b/seekableslider.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +class SeekableSlider : public QSlider +{ + Q_OBJECT +public: + explicit SeekableSlider(QWidget *parent = nullptr); + +signals: + +public slots: + +protected: + void mousePressEvent(QMouseEvent *event) override; + void mouseMoveEvent(QMouseEvent *event) override; +}; +