Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Final Version of Quran App For Windows , Added Progressbar while play…
Browse files Browse the repository at this point in the history
…ing quran and new Font
  • Loading branch information
Nashid P committed Apr 23, 2021
1 parent 99d9e16 commit 7faf405
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 40 deletions.
Binary file added resources/Harmattan-Regular.ttf
Binary file not shown.
57 changes: 47 additions & 10 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <string>
#include <QFile>
#include <QTextStream>
#include <QtFontDatabaseSupport/QtFontDatabaseSupport>
#include "window.hpp"
#include "json/json.hpp"

Expand Down Expand Up @@ -62,6 +63,8 @@ Window::Window()
connect(play, SIGNAL(clicked()), this, SLOT(set_play()));
connect(pause, SIGNAL(clicked()), this, SLOT(set_pause()));
connect(stop, SIGNAL(clicked()), this, SLOT(set_stop()));
connect(&Mediaplayer, &QMediaPlayer::durationChanged, this, &Window::updateDuration);
connect(&Mediaplayer, &QMediaPlayer::positionChanged, this, &Window::updatePosition);
}

void Window::createMenu()
Expand Down Expand Up @@ -136,11 +139,16 @@ QGroupBox *Window::createPlayerUi()
play = new QPushButton("Play");
pause = new QPushButton("Pause");
stop = new QPushButton("Stop");
player = new QMediaPlayer;
player->setMedia(QuranUrl);
positionSlider = new QSlider(Qt::Horizontal);
positionLabel = new QLabel(tr("00:00"));
positionLabel->setMinimumWidth(positionLabel->sizeHint().width());
positionSlider->setEnabled(false);
Mediaplayer.setMedia(QuranUrl);
PlayerLayout->addWidget(play);
PlayerLayout->addWidget(pause);
PlayerLayout->addWidget(stop);
PlayerLayout->addWidget(positionSlider);
PlayerLayout->addWidget(positionLabel);
PlayerBox->setLayout(PlayerLayout);
return PlayerBox;

Expand Down Expand Up @@ -178,6 +186,9 @@ void Window::getSurah(std::string surah_name, std::string edition)
QDBReader Database;
std::vector<std::string> data;
std::vector<std::string> meta = Database.metadata();
int id = QFontDatabase::addApplicationFont("resources/Harmattan-Regular.ttf");
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
QFont arabic(family);
show_surah->setText(QString::fromStdString(meta.at(surah_number)) + "\n");
QTextCursor cursor = show_surah->textCursor();
QTextBlockFormat textBlockFormat = cursor.blockFormat();
Expand All @@ -187,7 +198,8 @@ void Window::getSurah(std::string surah_name, std::string edition)
for(auto str : data)
show_surah->append(QString::fromStdString(str) + "\n");
show_surah->selectAll();
show_surah->setFontPointSize(16); // set Font Size
show_surah->setFont(arabic);
show_surah->setFontPointSize(22); // set Font Size
show_surah->setTextCursor(cursor);
show_surah->setReadOnly(true); // set Text Box Read Only
}
Expand Down Expand Up @@ -220,8 +232,8 @@ void Window::showSurah()
getSurah(data.at(surah_number), "quran");
getTranslation(data.at(surah_number), translation->currentText().toStdString());
QuranUrl = getQuranUrl(surah->currentIndex()+1);
player->stop();
player->setMedia(QuranUrl);
Mediaplayer.stop();
Mediaplayer.setMedia(QuranUrl);
}

void Window::showTranslation()
Expand Down Expand Up @@ -250,7 +262,7 @@ void Window::showAbout()
QLabel *Instagram = new QLabel("Instagram : @muslimpgmrs");
QLabel *Contributers = new QLabel("Contributers : Nashid , Jonas");
QLabel *footer = new QLabel("https://www.muslimprogrammers.com");
QLabel *version = new QLabel("Version 1.4 beta");
QLabel *version = new QLabel("Version 1.4 stable");
icon->setPixmap(pixmap);
icon->setAlignment(Qt::AlignCenter);
icon->setGeometry(QRect(312, 454, 21, 20));
Expand Down Expand Up @@ -433,16 +445,17 @@ void Window::set_play()
{
if(!quran_is_playing || quran_is_paused)
{
player->play();
Mediaplayer.play();
quran_is_playing = true;
positionSlider->setEnabled(true);
}
}

void Window::set_pause()
{
if(quran_is_playing)
{
player->pause();
Mediaplayer.pause();
quran_is_paused = true;
quran_is_playing = false;
}
Expand All @@ -452,8 +465,32 @@ void Window::set_stop()
{
if(quran_is_playing || quran_is_paused)
{
player->stop();
Mediaplayer.stop();
quran_is_playing = false;
quran_is_paused = false;
positionSlider->setEnabled(false);
}
}
}

static QString formatTime(qint64 timeMilliSeconds)
{
qint64 seconds = timeMilliSeconds / 1000;
const qint64 minutes = seconds / 60;
seconds -= minutes * 60;
return QStringLiteral("%1:%2")
.arg(minutes, 2, 10, QLatin1Char('0'))
.arg(seconds, 2, 10, QLatin1Char('0'));
}

void Window::updateDuration(qint64 duration)
{
positionSlider->setRange(0, duration);
positionSlider->setEnabled(duration > 0);
positionSlider->setPageStep(duration / 10);
}

void Window::updatePosition(qint64 position)
{
positionSlider->setValue(position);
positionLabel->setText(formatTime(position));
}
66 changes: 36 additions & 30 deletions src/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QUrl>
#include <QtMultimedia/QtMultimedia>
#include <QProgressBar>
#include <QSlider>
#include "curl_parser.hpp"
#include "db_reader.hpp"

Expand All @@ -43,39 +44,42 @@ class Window : public QMainWindow , public CURLParser
bool quran_is_playing = false;
bool quran_is_paused = true;
QUrl QuranUrl = "https://server8.mp3quran.net/afs/001.mp3";
void createMenu();
void createTaskbar();
QGroupBox *createComboBox();
QGroupBox *createTextBox();
QGroupBox *createPlayerUi();
void createMenu();
QComboBox *surah;
QComboBox *translation;
QTextEdit *show_surah;
QTextEdit *show_translation;
QMenuBar *menuBar;
QMenu *Menu;
QAction *about;
QAction *darkmode;
QAction *prayertimes;
QTimer *timer;
QLabel *display;
QLabel *imsak;
QLabel *fajr;
QLabel *sunrise;
QLabel *zuhr;
QLabel *asr;
QLabel *maghrib;
QLabel *isha;
QLabel *midnight;
QLabel *sunset;
QLineEdit *Country;
QLineEdit *City;
QPushButton *Show;
QWidget *PrayerTimeWidget;
QWidget *MediaPlayerWidget;
QMediaPlayer *player;
QPushButton *play;
QPushButton *pause;
QPushButton *stop;
QComboBox *surah = nullptr;
QComboBox *translation = nullptr;
QTextEdit *show_surah = nullptr;
QTextEdit *show_translation = nullptr;
QMenuBar *menuBar = nullptr;
QMenu *Menu = nullptr;
QAction *about = nullptr;
QAction *darkmode = nullptr;
QAction *prayertimes = nullptr;
QTimer *timer = nullptr;
QLabel *display = nullptr;
QLabel *imsak = nullptr;
QLabel *fajr = nullptr;
QLabel *sunrise = nullptr;
QLabel *zuhr = nullptr;
QLabel *asr = nullptr;
QLabel *maghrib = nullptr;
QLabel *isha = nullptr;
QLabel *midnight = nullptr;
QLabel *sunset = nullptr;
QLineEdit *Country = nullptr;
QLineEdit *City = nullptr;
QPushButton *Show = nullptr;
QWidget *PrayerTimeWidget = nullptr;
QWidget *MediaPlayerWidget = nullptr;
QMediaPlayer Mediaplayer;
QPushButton *play = nullptr;
QPushButton *pause = nullptr;
QPushButton *stop = nullptr;
QSlider *positionSlider = nullptr;
QLabel *positionLabel = nullptr;
void getSurah(std::string, std::string);
void getTranslation(std::string, std::string);
QUrl getQuranUrl(int surah_number);
Expand All @@ -90,6 +94,8 @@ class Window : public QMainWindow , public CURLParser
void set_play();
void set_pause();
void set_stop();
void updateDuration(qint64 duration);
void updatePosition(qint64 position);
};

#endif

0 comments on commit 7faf405

Please sign in to comment.