Skip to content

Commit

Permalink
Merge pull request #122 from Nighty3098/InDev
Browse files Browse the repository at this point in the history
The user's window has been changed. Added custom progressbar.
  • Loading branch information
Nighty3098 authored Jul 19, 2024
2 parents 86d3cc3 + 21114e0 commit b80b9a2
Show file tree
Hide file tree
Showing 10 changed files with 331 additions and 31 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"locale": "cpp"
"locale": "cpp",
"ios": "cpp"
}
}
7 changes: 7 additions & 0 deletions rm_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@ rm src/CodeKeeper/moc_accountwindow.cpp
rm src/CodeKeeper/moc_accountwindow.o
rm src/CodeKeeper/object_script.CodeKeeper.Debug
rm src/CodeKeeper/object_script.CodeKeeper.Release
rm src/CodeKeeper/CircledProgressBar.o
rm src/CodeKeeper/moc_CircledProgressBar.o
rm src/CodeKeeper/moc_CircledProgressBar.cpp
rm src/CodeKeeper/moc_ProgressCircle.cpp
rm src/CodeKeeper/moc_ProgressCircle.o
rm src/CodeKeeper/ProgressCircle.o


echo "Done!"
4 changes: 3 additions & 1 deletion src/CodeKeeper/CodeKeeper.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SOURCES += \
keeperFunc/projectsFunc.cpp \
keeperFunc/notesFunc.cpp \
keeperFunc/getProjectInfo.cpp \
accountFunc/functional.cpp \
syncFunc/functional.cpp \
sql_db/projectsDB.cpp \
sql_db/tasksDB.cpp \
Expand All @@ -35,7 +36,8 @@ HEADERS += \
accountwindow.h \
mainwindow.h \
settingswindow.h \
syncwindow.h
syncwindow.h \
custom/circleProgressbar/ProgressCircle.h

RESOURCES += \
../resources/resources.qrc \
Expand Down
103 changes: 98 additions & 5 deletions src/CodeKeeper/accountFunc/functional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ void AccountWindow::setImageFromUrl(const QString& url, QLabel* label)
});
}

void AccountWindow::get_image_url(const QString& username, QLabel* label)
{
QNetworkAccessManager* manager = new QNetworkAccessManager(this);
QUrl url("https://api.github.com/users/" + git_user);

QUrlQuery query;
query.addQueryItem("login", username);
url.setQuery(query);

QNetworkRequest request(url);
request.setHeader(QNetworkRequest::UserAgentHeader, "CodeKeeper");
request.setRawHeader("Authorization", ("Bearer " + git_token).toUtf8());
request.setRawHeader("X-GitHub-Api-Version", "2022-11-28");
request.setRawHeader("Accept", "application/vnd.github.v3+json");

QNetworkReply* reply = manager->get(request);
QObject::connect(reply, &QNetworkReply::finished, [=]() {
if (reply->error()) {
qWarning() << "Error:" << reply->errorString();
reply->deleteLater();
return;
}

QJsonDocument doc = QJsonDocument::fromJson(reply->readAll());
QJsonObject obj = doc.object();

qDebug() << obj["avatar_url"].toString();

setImageFromUrl(obj["avatar_url"].toString(), label);

reply->deleteLater();
});
}

void AccountWindow::closeWindowSlot()
{
this->close();
Expand All @@ -52,6 +86,17 @@ void AccountWindow::setFontStyle()
{
userName->setFont(selectedFont);

int header_size = font_size.toInt() + 5;
qDebug() << header_size;

tasksTitle->setFont(selectedFont);
tasksTitle->setStyleSheet("font-size: " + QString(header_size) + "px;");

projectTitle->setFont(selectedFont);
projectTitle->setStyleSheet("font-size: " + QString(header_size) + "px;");

userName->setStyleSheet("font-size: 36pt;");

profilePicture->setFont(selectedFont);
profilePicture->setStyleSheet("font-size: " + font_size + "pt;");

Expand All @@ -64,6 +109,9 @@ void AccountWindow::setFontStyle()
profileInfo->setFont(selectedFont);
profileInfo->setStyleSheet("font-size: " + font_size + "pt;");

tasksStatsProgress->setFont(selectedFont);
tasksStatsProgress->setStyleSheet("font-size: " + font_size + "pt;");

closeWindow->setStyleSheet("QPushButton {"
" border-color: rgba(0, 0, 0, 0);"
" background-color: rgba(0, 0, 0, 0);"
Expand Down Expand Up @@ -133,7 +181,7 @@ int AccountWindow::getStarsCount(const QString& username)
return totalStars;
}

void AccountWindow::setUserData(const QString& username, QLabel* label)
void AccountWindow::setUserData(const QString& username)
{
QNetworkAccessManager* manager = new QNetworkAccessManager(this);
QUrl url("https://api.github.com/users/" + git_user);
Expand Down Expand Up @@ -179,7 +227,6 @@ void AccountWindow::setUserData(const QString& username, QLabel* label)
+ QString::number(obj["following"].toInt()) + "\n\nFollowers: " + QString::number(obj["followers"].toInt())
+ "\n\nStars: " + QString::number(getStarsCount(git_user)) + "\n");

setImageFromUrl(obj["avatar_url"].toString(), profilePicture);
reply->deleteLater();
});
}
Expand All @@ -204,7 +251,53 @@ void AccountWindow::setTasksProgress()

qDebug() << completeTasksCount << "/" << totalTasks;

tasksStatsProgress->setMaximum(100);
tasksStatsProgress->setValue(percentage);
tasksStatsProgress->setFormat("Completed tasks: " + QString::number(completeTasksCount) + "/" + QString::number(totalTasks));
}
tasksStatsProgress->setMaxValue(100);

if (percentage < 101) {
tasksStatsProgress->setProgressColor(QColor("#51afef"));
}

if (percentage < 51) {
tasksStatsProgress->setProgressColor(QColor("#ecbe7b"));
}

if (percentage < 26) {
tasksStatsProgress->setProgressColor(QColor("#ec7b85"));
}
}

void AccountWindow::setProjectsStats()
{
MainWindow* mainWindow = qobject_cast<MainWindow*>(this->parent());
QString stats = mainWindow->getKeeperStats();

// Extract the values using regular expressions
QRegExp rx("Not started projects: (\\d+)");
rx.indexIn(stats);
int notStartedProjectsCount = rx.cap(1).toInt();

rx.setPattern("Started projects: (\\d+)");
rx.indexIn(stats);
int startedProjectsCount = rx.cap(1).toInt();

rx.setPattern("Projects on review: (\\d+)");
rx.indexIn(stats);
int finishlineProjectsCount = rx.cap(1).toInt();

rx.setPattern("Finished projects: (\\d+)");
rx.indexIn(stats);
int finishedProjectsCount = rx.cap(1).toInt();

int totalProjects = notStartedProjectsCount + startedProjectsCount + finishlineProjectsCount + finishedProjectsCount;

notStartedProjectsProgress->setMaxValue(100);
startedProjectsProgress->setMaxValue(100);
reviewProjectsProgress->setMaxValue(100);
completedProjectsProgress->setMaxValue(100);

notStartedProjectsProgress->setValue(static_cast<double>(notStartedProjectsCount) / static_cast<double>(totalProjects) * 100.0);
startedProjectsProgress->setValue(static_cast<double>(startedProjectsCount) / static_cast<double>(totalProjects) * 100.0);
reviewProjectsProgress->setValue(static_cast<double>(finishlineProjectsCount) / static_cast<double>(totalProjects) * 100.0);
completedProjectsProgress->setValue(static_cast<double>(finishedProjectsCount) / static_cast<double>(totalProjects) * 100.0);
}
89 changes: 74 additions & 15 deletions src/CodeKeeper/accountwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
#include <QtWidgets>
#include <QHBoxLayout>

#include "accountwindow.h"
#include "accountFunc/functional.cpp"
#include <QtWidgets>
#include "mainwindow.h"
#include "custom/circleProgressbar/ProgressCircle.h"

#include <git2.h>

AccountWindow::AccountWindow(QWidget* parent) : QMainWindow { parent }
{
setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

globalSettings = new QSettings("CodeKeeper", "CodeKeeper");

centralWidget = new QWidget(this);
setCentralWidget(centralWidget);

mainLayout = new QGridLayout(centralWidget);
setFixedSize(400, 750);
setFixedSize(800, 500);

globalSettings = new QSettings("CodeKeeper", "CodeKeeper");

getSettingsData();

tasksTitle = new QLabel();
tasksTitle->setText("\nTasks\n");

projectTitle = new QLabel();
projectTitle->setText("\n\nProjects\n");

profilePicture = new QLabel();
profilePicture->setText("Loading...");
profilePicture->setFixedSize(300, 300);
profilePicture->setStyleSheet("border-radius: 145px;");

profileInfo = new QLabel();
Expand All @@ -33,21 +46,53 @@ AccountWindow::AccountWindow(QWidget* parent) : QMainWindow { parent }
codeKeeperStats->setText(stats);
codeKeeperStats->setAlignment(Qt::AlignHCenter);

tasksStatsProgress = new QProgressBar();
tasksStatsProgress->setFixedHeight(25);
tasksStatsProgress->setAlignment(Qt::AlignCenter);
tasksStatsProgress = new CircleProgressBar();
tasksStatsProgress->setFixedSize(50, 50);
tasksStatsProgress->setBackgroundColor(QColor(Qt::transparent));
tasksStatsProgress->setLineWidth(font_size.toInt());
tasksStatsProgress->setDisplayMode(CircleProgressBar::Percent); // Percent, CustomText, NoPercent, Hidden

userName = new QLabel();
userName->setText(git_user);
userName->setAlignment(Qt::AlignHCenter);
userName->setStyleSheet("font-size: 36pt;");

openRepo = new QPushButton("Open Git");
openRepo->setFixedSize(100, 25);

closeWindow = new QPushButton("");
closeWindow->setFixedSize(15, 15);

QHBoxLayout* projectsStatsLayout = new QHBoxLayout();

notStartedProjectsProgress = new CircleProgressBar();
notStartedProjectsProgress->setFixedSize(50, 50);
notStartedProjectsProgress->setBackgroundColor(QColor(Qt::transparent));
notStartedProjectsProgress->setProgressColor(QColor("#ef5a51"));
notStartedProjectsProgress->setLineWidth(font_size.toInt() - 3);

startedProjectsProgress = new CircleProgressBar();
startedProjectsProgress->setFixedSize(50, 50);
startedProjectsProgress->setBackgroundColor(QColor(Qt::transparent));
startedProjectsProgress->setProgressColor(QColor("#d8ef51"));
startedProjectsProgress->setLineWidth(font_size.toInt() - 3);

reviewProjectsProgress = new CircleProgressBar();
reviewProjectsProgress->setFixedSize(50, 50);
reviewProjectsProgress->setBackgroundColor(QColor(Qt::transparent));
reviewProjectsProgress->setProgressColor(QColor("#51afef"));
reviewProjectsProgress->setLineWidth(font_size.toInt() - 3);

completedProjectsProgress = new CircleProgressBar();
completedProjectsProgress->setFixedSize(50, 50);
completedProjectsProgress->setBackgroundColor(QColor(Qt::transparent));
completedProjectsProgress->setProgressColor(QColor("#8cef51"));
completedProjectsProgress->setLineWidth(font_size.toInt() - 3);

projectsStatsLayout->addWidget(notStartedProjectsProgress);
projectsStatsLayout->addWidget(startedProjectsProgress);
projectsStatsLayout->addWidget(reviewProjectsProgress);
projectsStatsLayout->addWidget(completedProjectsProgress);

QThread* styleThread = new QThread;
QObject::connect(styleThread, &QThread::started, this, [this]() {
setFontStyle();
Expand All @@ -58,20 +103,34 @@ AccountWindow::AccountWindow(QWidget* parent) : QMainWindow { parent }

QThread* setUserDataThread = new QThread;
QObject::connect(setUserDataThread, &QThread::started, this, [this]() {
setUserData(git_user, profilePicture);
setTasksProgress();

qDebug() << "setUserDataThread started";

setUserData(git_user);
setTasksProgress();
setProjectsStats();
});
setUserDataThread->start();

mainLayout->addWidget(closeWindow, 0, 0, 1, 3, Qt::AlignLeft);
QThread* setUserImageThread = new QThread;
QObject::connect(setUserImageThread, &QThread::started, this, [this]() {
qDebug() << "setUserImageThread started";

get_image_url(git_user, profilePicture);
});
setUserImageThread->start();

mainLayout->addWidget(closeWindow, 0, 0, 1, 6, Qt::AlignLeft);
mainLayout->addWidget(profilePicture, 1, 0, 3, 3, Qt::AlignCenter);
mainLayout->addWidget(userName, 5, 0, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(profileInfo, 6, 0, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(tasksStatsProgress, 9, 0, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(codeKeeperStats, 10, 0, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(openRepo, 13, 0, 1, 3, Qt::AlignCenter);

mainLayout->addWidget(userName, 1, 3, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(tasksTitle, 2, 3, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(tasksStatsProgress, 3, 3, 1, 3, Qt::AlignCenter);
mainLayout->addWidget(projectTitle, 4, 3, 1, 3, Qt::AlignCenter);
mainLayout->addLayout(projectsStatsLayout, 5, 3, 1, 3, Qt::AlignCenter);

mainLayout->addWidget(profileInfo, 14, 0, 3, 3, Qt::AlignCenter);
mainLayout->addWidget(codeKeeperStats, 14, 3, 3, 3, Qt::AlignCenter);
mainLayout->addWidget(openRepo, 17, 0, 1, 6, Qt::AlignCenter);

connect(closeWindow, SIGNAL(clicked()), this, SLOT(closeWindowSlot()));
connect(openRepo, SIGNAL(clicked()), this, SLOT(onOpenRepoClicked()));
Expand Down
15 changes: 12 additions & 3 deletions src/CodeKeeper/accountwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QObject>
#include <QGridLayout>
#include <QtWidgets>

#include "custom/circleProgressbar/ProgressCircle.h"
class AccountWindow : public QMainWindow
{
Q_OBJECT
Expand Down Expand Up @@ -38,19 +38,28 @@ class AccountWindow : public QMainWindow
QLabel *codeKeeperStats;
QLabel *tasksStats;

QLabel *tasksTitle;
QLabel *projectTitle;

QPushButton *closeWindow;
QPushButton *openRepo;

QProgressBar *tasksStatsProgress;
CircleProgressBar *tasksStatsProgress;
CircleProgressBar *notStartedProjectsProgress;
CircleProgressBar *startedProjectsProgress;
CircleProgressBar *reviewProjectsProgress;
CircleProgressBar *completedProjectsProgress;

private slots:
void setUserData(const QString &username, QLabel *label);
void setUserData(const QString &username);
void closeWindowSlot();
void getSettingsData();
void setImageFromUrl(const QString &url, QLabel *label);
void onOpenRepoClicked();
int getStarsCount(const QString &username);
void setTasksProgress();
void setProjectsStats();
void get_image_url(const QString& username, QLabel *label);
};

#endif // ACCOUNTWINDOW_H
Loading

0 comments on commit b80b9a2

Please sign in to comment.