diff --git a/src/dashboard.py b/src/dashboard.py index 00bf39e700211b7d0692ea0e023d6fb26f5c2907..4a29e426206006259dcda669a71e0fa0f3ad1bbc 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1,17 +1,59 @@ import sys -from PyQt6.QtCore import Qt, pyqtSignal -from PyQt6.QtGui import QCursor, QFont, QPixmap -from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QWidget +from PyQt6.QtCore import Qt, pyqtSignal, QSize +from PyQt6.QtGui import QCursor, QFont, QPixmap, QMovie +from PyQt6.QtWidgets import QApplication, QLabel, QPushButton, QWidget, QScrollArea, QVBoxLayout, QHBoxLayout +import sqlite3 +con = sqlite3.connect("fitu.db") +cur = con.cursor() background = '#5A8D6C' button_color = '#174728' text_color = '#EEEEE2' card_color = '#D2DCC4' + +# kumpulan font +helloFont = QFont() +helloFont.setFamily('Segoe UI') +helloFont.setPointSize(47) +# helloFont.setBold(True) + +quoteFont = QFont() +quoteFont.setFamily('Segoe UI') +quoteFont.setPointSize(25) + +buttonFont = QFont() +buttonFont.setFamily('Segoe UI') +buttonFont.setPointSize(18) +buttonFont.setBold(True) + +dateFont = QFont() +dateFont.setFamily('Segoe UI') +dateFont.setPointSize(23) +dateFont.setBold(True) + +historyFont = QFont() +historyFont.setFamily('Segoe UI') +historyFont.setPointSize(16) + +rincianFont = QFont() +rincianFont.setFamily('Segoe UI') +rincianFont.setPointSize(13) + +repetisiFont = QFont() +repetisiFont.setFamily('Segoe UI') +repetisiFont.setPointSize(10) + +styleSheetCard = ( + "background-color: #5A8D6C;" + "border-radius: 20px;" + ) + + class dashboard(QWidget): - switch = pyqtSignal(str, dict) + switch_window = pyqtSignal(str, dict) def __init__(self, user=None): super().__init__() if (user == None): @@ -25,36 +67,170 @@ class dashboard(QWidget): } else: self.user = user + self.index_history = int(-1) + self.banyaknyaKartu = int(-1) self.dashboardWindow() def dashboardWindow(self): self.setWindowTitle('Dashboard - FitU') self.setFixedSize(1280, 720) self.setStyleSheet(f'background-color: {background};') + self.label = QLabel("") + self.label.setParent(self) self.element() - def element(self): - # kumpulan font - helloFont = QFont() - helloFont.setFamily('Segoe UI') - helloFont.setPointSize(47) + def historyElement(self, historyDate, idx): + self.index_history = idx + print(self.index_history) + print("panjang historyDate: ", len(historyDate)) + tanggal = historyDate[self.index_history][0] + print(tanggal) + # menyiapkan history card + self.card = QLabel(self) + self.card.setPixmap(QPixmap('img/card-dashboard.png')) + self.card.move(633, 172) + + daftar_latihan = cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' + """).fetchall() + + jumlahCard = len(daftar_latihan) + + self.banyaknyaKartu = jumlahCard + + self.date = QLabel(self) + self.date.setText(f"{tanggal}") + self.date.setStyleSheet(f'color: {button_color}; background-color: {card_color};') + self.date.move(820, 195) + self.date.setFont(dateFont) + self.date.setAlignment(Qt.AlignmentFlag.AlignLeft) + + keterangan = cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' + """).fetchone() + print(keterangan) + self.duration = QLabel(self) + self.duration.setText("Duration : " + str(keterangan[0]) + " minutes") + self.duration.setStyleSheet(f'color: {button_color}; background-color: {card_color};') + self.duration.move(667,282) + self.duration.setFixedWidth(300) + self.duration.setFont(historyFont) + self.duration.setAlignment(Qt.AlignmentFlag.AlignLeft) + + self.prog = QLabel(self) + self.prog.setText("Program Name: " + keterangan[1]) + self.prog.setStyleSheet(f'color: {button_color}; background-color: {card_color};') + self.prog.move(667, 317) + self.prog.setFixedWidth(300) + self.prog.setFont(historyFont) + self.prog.setAlignment(Qt.AlignmentFlag.AlignLeft) - quoteFont = QFont() - quoteFont.setFamily('Segoe UI') - quoteFont.setPointSize(25) + + self.scroll = QScrollArea(self) + self.scroll.setGeometry(654, 369, 486, 204) # mengatur posisi dan ukuran QScrollArea + self.scroll.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget = QWidget(self.scroll) + self.scrollLayout = QHBoxLayout(self.scrollWidget) + self.scrollWidget.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + self.scrollWidget.setLayout(self.scrollLayout) + horizontal_scrollbar = self.scroll.horizontalScrollBar() + # Mengatur bentuk scroll bar + scroll_bar_style = """ + QScrollBar:horizontal { + border : 0px; + background-color: #5A8D6C; + height: 10px; + margin: 0px 0px 0px 0px; + } + QScrollBar::handle:horizontal { + background-color: #174728; + border-radius: 50px; + border: 0px; + } + """ + self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) + self.hbox = QHBoxLayout() + print(jumlahCard) + for j in range(self.banyaknyaKartu): + self.label = QLabel() + self.label.setFixedSize(150, 175) + self.label.setStyleSheet(styleSheetCard) + self.hbox.addWidget(self.label) + nama_latihan = daftar_latihan[j][0] + repetisi_latihan = cur.execute(f""" + SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + durasi_latihan = cur.execute(f""" + SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + gambar_latihan = cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + con.commit() + self.show_nama_latihan = QLabel(self.label) + self.show_nama_latihan.setText(nama_latihan) + self.show_nama_latihan.setStyleSheet(f'color: {card_color};') + self.show_nama_latihan.move(10, 120) + self.show_nama_latihan.setFont(rincianFont) + self.show_nama_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) - buttonFont = QFont() - buttonFont.setFamily('Segoe UI') - buttonFont.setPointSize(18) + self.show_repetisi_latihan = QLabel(self.label) + if (repetisi_latihan[0] == None): + self.show_repetisi_latihan.setText("Duration: " + str(durasi_latihan[0]) + " seconds") + else: + self.show_repetisi_latihan.setText("Repetition: " + str(repetisi_latihan[0])) + self.show_repetisi_latihan.setStyleSheet(f'color: {card_color};') + self.show_repetisi_latihan.move(10, 145) + self.show_repetisi_latihan.setFont(repetisiFont) + self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) - dateFont = QFont() - dateFont.setFamily('Segoe UI') - dateFont.setPointSize(23) + self.gif = "img/exercise-unscreen.gif" + self.gif2 = QMovie(self.gif) + self.gif2.setScaledSize(QSize(90, 90)) + self.gif2.start() + self.show_gambar_latihan = QLabel(self.label) + self.show_gambar_latihan.setMovie(self.gif2) + self.show_gambar_latihan.move(25, 20) + self.scrollLayout.addLayout(self.hbox) + self.scroll.setWidget(self.scrollWidget) + + self.kiri = QPushButton(self) + self.kiri.setText('<') + self.kiri.setStyleSheet(f''' + QPushButton {{ + color: {button_color}; + background-color: {card_color}; + border: none; + border-radius: 20px; + }} + ''') + self.kiri.setFont(dateFont) + self.kiri.move(727, 195) + self.kiri.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.kiri.clicked.connect(lambda:self.prev(historyDate)) + + + self.kanan = QPushButton(self) + self.kanan.setText('>') + self.kanan.setStyleSheet(f''' + QPushButton {{ + color: {button_color}; + background-color: {card_color}; + border: none; + border-radius: 20px; + }} + ''') + self.kanan.setFont(dateFont) + self.kanan.move(1047, 195) + self.kanan.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) + self.kanan.clicked.connect(lambda:self.next(historyDate)) - historyFont = QFont() - historyFont.setFamily('Segoe UI') - historyFont.setPointSize(16) + if(idx == len(historyDate)-1): + self.kanan.hide() + elif (idx == 0): + self.kiri.hide() + def element(self): # masukkan logo logo = QLabel(self) logo.setPixmap(QPixmap('img/logo-dashboard.png')) @@ -108,6 +284,7 @@ class dashboard(QWidget): planButton.move(807, 58) planButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + planButton.clicked.connect(self.planWindow) # tombol list listButton = QPushButton(self) @@ -125,6 +302,7 @@ class dashboard(QWidget): listButton.setCursor( QCursor(Qt.CursorShape.PointingHandCursor)) + # tombol history historyButton = QPushButton(self) historyButton.setText('History') @@ -179,64 +357,156 @@ class dashboard(QWidget): start.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) # membuat history card - card = QLabel(self) - card.setPixmap(QPixmap('img/card-dashboard.png')) - card.move(633, 172) + historyDate = cur.execute(""" + SELECT DISTINCT strftime(date) FROM riwayat_latihan + """).fetchall() + + # menyiapkan history card + + print(len(historyDate)) + tanggal = historyDate[0][0] + print(tanggal) + idx = (len(historyDate)-1) + # print(idx) + self.historyElement(historyDate, idx) - kiri = QPushButton(self) - kiri.setText('<') - kiri.setStyleSheet(f''' - QPushButton {{ - color: {button_color}; - background-color: {card_color}; - border: none; - border-radius: 20px; - }} - ''') - kiri.setFont(dateFont) - kiri.move(727, 195) - kiri.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - - date = QLabel(self) - date.setText("Date :") - date.setStyleSheet(f'color: {button_color}; background-color: {card_color};') - date.move(793, 195) - date.setFont(dateFont) - date.setAlignment(Qt.AlignmentFlag.AlignLeft) - - kanan = QPushButton(self) - kanan.setText('>') - kanan.setStyleSheet(f''' - QPushButton {{ - color: {button_color}; - background-color: {card_color}; - border: none; - border-radius: 20px; - }} - ''') - kanan.setFont(dateFont) - kanan.move(1047, 195) - kanan.setCursor(QCursor(Qt.CursorShape.PointingHandCursor)) - - duration = QLabel(self) - duration.setText("Duration :") - duration.setStyleSheet(f'color: {button_color}; background-color: {card_color};') - duration.move(667,282) - duration.setFont(historyFont) - duration.setAlignment(Qt.AlignmentFlag.AlignLeft) - - prog = QLabel(self) - prog.setText("Program Name: ") - prog.setStyleSheet(f'color: {button_color}; background-color: {card_color};') - prog.move(667, 317) - prog.setFont(historyFont) - prog.setAlignment(Qt.AlignmentFlag.AlignLeft) - def showRegister(self): - self.switch.emit(self, "register") + def prev(self, historyDate): + if (self.index_history == 0): + self.kiri.hide() + else: + self.scroll.setParent(None) + tanggal = historyDate[self.index_history-1][0] + self.date.setText(f"{tanggal}") + daftar_latihan = cur.execute(f""" + SELECT name FROM riwayat_latihan WHERE date = '{tanggal}' + """).fetchall() + print(daftar_latihan) + jumlahCard = len(daftar_latihan) + keterangan = cur.execute(f""" + SELECT tot_duration, title_program FROM riwayat_latihan WHERE date = '{tanggal}' + """).fetchone() + + self.duration.setText("Duration : " + str(keterangan[0]) + " minutes") + self.prog.setText("Program Name: " + keterangan[1]) + # for k in range(self.banyaknyaKartu): + # print(k) + # self.boxdelete(k) + # self.scroll.setParent(None) + for i in reversed(range(self.banyaknyaKartu)): + self.hbox.itemAt(i).widget().setParent(None) + + # self.scroll = QScrollArea(self) + # self.scroll.setGeometry(654, 369, 486, 204) # mengatur posisi dan ukuran QScrollArea + # self.scroll.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + # self.scrollWidget = QWidget(self.scroll) + # self.scrollLayout = QVBoxLayout(self.scrollWidget) + # self.scrollWidget.setStyleSheet(f"background-color: {card_color}; border-radius: 0px;") + # self.scrollWidget.setLayout(self.scrollLayout) + # horizontal_scrollbar = self.scroll.horizontalScrollBar() + # # Mengatur bentuk scroll bar + # scroll_bar_style = """ + # QScrollBar:horizontal { + # border : 0px; + # background-color: #5A8D6C; + # height: 10px; + # margin: 0px 0px 0px 0px; + # } + # QScrollBar::handle:horizontal { + # background-color: #174728; + # border-radius: 50px; + # border: 0px; + # } + # """ + # self.scroll.horizontalScrollBar().setStyleSheet(scroll_bar_style) + # self.hbox = QHBoxLayout() + # print(jumlahCard) + + self.banyaknyaKartu = jumlahCard + for j in range(self.banyaknyaKartu): + print(j) + self.label = QLabel() + self.label.setFixedSize(150, 175) + self.label.setStyleSheet(styleSheetCard) + self.hbox.addWidget(self.label) + nama_latihan = daftar_latihan[j][0] + print(nama_latihan) + repetisi_latihan = cur.execute(f""" + SELECT repetition FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + durasi_latihan = cur.execute(f""" + SELECT duration FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + gambar_latihan = cur.execute(f""" + SELECT gif FROM daftar_latihan WHERE title = '{nama_latihan}' + """).fetchone() + con.commit() + self.show_nama_latihan = QLabel(self.label) + self.show_nama_latihan.setText(nama_latihan) + self.show_nama_latihan.setStyleSheet(f'color: {card_color};') + self.show_nama_latihan.move(10, 120) + self.show_nama_latihan.setFont(rincianFont) + self.show_nama_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) + + self.show_repetisi_latihan = QLabel(self.label) + if (repetisi_latihan[0] == None): + self.show_repetisi_latihan.setText("Duration: " + str(durasi_latihan[0]) + " seconds") + else: + self.show_repetisi_latihan.setText("Repetition: " + str(repetisi_latihan[0])) + self.show_repetisi_latihan.setStyleSheet(f'color: {card_color};') + self.show_repetisi_latihan.move(10, 145) + self.show_repetisi_latihan.setFont(repetisiFont) + self.show_repetisi_latihan.setAlignment(Qt.AlignmentFlag.AlignLeft) + + self.gif = "img/exercise-unscreen.gif" + self.gif2 = QMovie(self.gif) + self.gif2.setScaledSize(QSize(90, 90)) + self.gif2.start() + self.show_gambar_latihan = QLabel(self.label) + self.show_gambar_latihan.setMovie(self.gif2) + self.show_gambar_latihan.move(25, 20) + self.scrollLayout.addLayout(self.hbox) + self.scroll.setWidget(self.scrollWidget) + + + + def next(self, historyDate): + if (self.index_history == len(historyDate)-1): + self.kanan.hide() + else: + self.historyElement(historyDate, self.index_history+1) - def listLatihann(self): - self.switch.emit(self, "listLatihan") + def planWindow(self): + self.label = QLabel("") + self.label.setParent(self) + # self.window = plan(self.user) + # self.window.show() + # self.close() + + def boxdelete(self, box): + for i in range(self.vlayout.count()): + layout_item = self.vlayout.itemAt(i) + if layout_item.layout() == box: + deleteItemsOfLayout(layout_item.layout()) + self.vlayout.removeItem(layout_item) + break + def clear_item(self, item): + if hasattr(item, "layout"): + if callable(item.layout): + layout = item.layout() + else: + layout = None + + if hasattr(item, "widget"): + if callable(item.widget): + widget = item.widget() + else: + widget = None + if widget: + widget.setParent(None) + elif layout: + for i in reversed(range(layout.count())): + self.clear_item(layout.itemAt(i))