]> git.sur5r.net Git - minitube/commitdiff
Volume keyboard shortcuts
authorFlavio Tordini <flavio.tordini@gmail.com>
Wed, 12 Aug 2009 23:00:54 +0000 (01:00 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Wed, 12 Aug 2009 23:00:54 +0000 (01:00 +0200)
Automatically unmute when volume changes

src/MainWindow.cpp
src/MainWindow.h

index cc967d9db70c8e272910455693538cd17288f307..d19c080f1bb64220dc5fb1ac38011ec14efbc257 100755 (executable)
@@ -171,12 +171,26 @@ void MainWindow::createActions() {
     actions->insert("about", aboutAct);
     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
 
+    // Invisible actions
+
     searchFocusAct = new QAction(tr("&Search"), this);
     searchFocusAct->setShortcut(QKeySequence::Find);
     actions->insert("search", searchFocusAct);
     connect(searchFocusAct, SIGNAL(triggered()), this, SLOT(searchFocus()));
     addAction(searchFocusAct);
 
+    volumeUpAct = new QAction(tr("&Volume up"), this);
+    volumeUpAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus));
+    actions->insert("volume-up", volumeUpAct);
+    connect(volumeUpAct, SIGNAL(triggered()), this, SLOT(volumeUp()));
+    addAction(volumeUpAct);
+
+    volumeDownAct = new QAction(tr("&Volume down"), this);
+    volumeDownAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Minus));
+    actions->insert("volume-down", volumeDownAct);
+    connect(volumeDownAct, SIGNAL(triggered()), this, SLOT(volumeDown()));
+    addAction(volumeDownAct);
+
     // common action properties
     foreach (QAction *action, actions->values()) {
 
@@ -567,6 +581,8 @@ void MainWindow::initPhonon() {
     connect(mediaObject, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
     seekSlider->setMediaObject(mediaObject);
     audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
+    connect(audioOutput, SIGNAL(volumeChanged(qreal)), this, SLOT(volumeChanged(qreal)));
+    connect(audioOutput, SIGNAL(mutedChanged(bool)), this, SLOT(volumeMutedChanged(bool)));
     volumeSlider->setAudioOutput(audioOutput);
     Phonon::createPath(mediaObject, audioOutput);
 }
@@ -591,6 +607,38 @@ void MainWindow::totalTimeChanged(qint64 time) {
     // qDebug() << "totalTime" << time << displayTime.toString("mm:ss");
 }
 
+void MainWindow::volumeUp() {
+    qreal newVolume = volumeSlider->audioOutput()->volume() + .1;
+    if (newVolume > volumeSlider->maximumVolume())
+        newVolume = volumeSlider->maximumVolume();
+    volumeSlider->audioOutput()->setVolume(newVolume);
+}
+
+void MainWindow::volumeDown() {
+    qreal newVolume = volumeSlider->audioOutput()->volume() - .1;
+    if (newVolume < 0)
+        newVolume = 0;
+    volumeSlider->audioOutput()->setVolume(newVolume);
+}
+
+void MainWindow::volumeMute() {
+    volumeSlider->audioOutput()->setMuted(!volumeSlider->audioOutput()->isMuted());
+}
+
+void MainWindow::volumeChanged(qreal newVolume) {
+    // automatically unmute when volume changes
+    if (volumeSlider->audioOutput()->isMuted())
+        volumeSlider->audioOutput()->setMuted(false);
+    statusBar()->showMessage(tr("Volume at %1%").arg(newVolume*100));
+}
+
+void MainWindow::volumeMutedChanged(bool muted) {
+    if (muted)
+        statusBar()->showMessage(tr("Volume is muted"));
+    else
+        statusBar()->showMessage(tr("Volume is unmuted"));
+}
+
 void MainWindow::abortDownload() {
     QProgressDialog* dlg = dynamic_cast<QProgressDialog*>(this->sender());
     QMap<QNetworkReply*, DownloadResource>::iterator cur;
index 0a44beaf32c4054e2915c9311be77ad5791c8212..1f493f16e52c7df1d4600ae7991abfeb81a458da 100755 (executable)
@@ -27,11 +27,11 @@ public:
 protected:
     void closeEvent(QCloseEvent *);
 
-        struct DownloadResource
-        {
-                QProgressDialog* dialog;
-                QFile* file;
-        };
+    struct DownloadResource
+    {
+        QProgressDialog* dialog;
+        QFile* file;
+    };
 
 private slots:
     void fadeInWidget(QWidget *oldWidget, QWidget *newWidget);
@@ -44,21 +44,29 @@ private slots:
     void about();
     void quit();
     void fullscreen();
-        void compactView(bool enable);
+    void compactView(bool enable);
     void stop();
     void stateChanged(Phonon::State newState, Phonon::State oldState);
     void searchFocus();
     void tick(qint64 time);
     void totalTimeChanged(qint64 time);
-        // download related stuff
-        void abortDownload();
-        void download();
-        void download(const QUrl& url, const DownloadResource& res);
-        void replyReadyRead();
-        void replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
-        void replyError(QNetworkReply::NetworkError code);
-        void replyFinished();
-        void replyMetaDataChanged();
+
+    // volume shortcuts
+    void volumeUp();
+    void volumeDown();
+    void volumeMute();
+    void volumeChanged(qreal newVolume);
+    void volumeMutedChanged(bool muted);
+
+    // download related stuff
+    void abortDownload();
+    void download();
+    void download(const QUrl& url, const DownloadResource& res);
+    void replyReadyRead();
+    void replyDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+    void replyError(QNetworkReply::NetworkError code);
+    void replyFinished();
+    void replyMetaDataChanged();
 
 private:
     void initPhonon();
@@ -96,9 +104,12 @@ private:
     QAction *pauseAct;
     QAction *stopAct;
     QAction *fullscreenAct;
-        QAction *compactViewAct;
+    QAction *compactViewAct;
     QAction *webPageAct;
     QAction *downloadAct;
+    QAction *volumeUpAct;
+    QAction *volumeDownAct;
+    QAction *volumeMuteAct;
 
     // playlist actions
     QAction *removeAct;
@@ -127,7 +138,7 @@ private:
     bool m_fullscreen;
     bool m_maximized;
 
-        QMap<QNetworkReply*, DownloadResource> m_downloads;
+    QMap<QNetworkReply*, DownloadResource> m_downloads;
 };
 
 #endif