From 0863478038df43d5ab3de734263b5b2f4b224984 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 10 May 2020 15:17:55 +0200 Subject: Show duration with a green orange red color --- src/gui/color.py | 4 ++++ src/gui/tasks/duration.py | 13 ++++++++++++- src/gui/tasks/table/model.py | 11 +++++++---- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/color.py b/src/gui/color.py index fa7df8e..f02fbae 100644 --- a/src/gui/color.py +++ b/src/gui/color.py @@ -12,3 +12,7 @@ hard_difficulty = red low_priority = green middle_priority = orange high_priority = red + +short_duration = green +medium_duration = orange +long_duration = red diff --git a/src/gui/tasks/duration.py b/src/gui/tasks/duration.py index e863914..3ce8203 100644 --- a/src/gui/tasks/duration.py +++ b/src/gui/tasks/duration.py @@ -1,6 +1,9 @@ -import re +from PyQt5 import QtGui from typing import Optional import math +import re + +import gui.color def format(minutes: int): if minutes >= 60 * 24: @@ -37,3 +40,11 @@ def parse(duration: str) -> Optional[int]: return None else: return 0 + +def color(minutes: int): + if minutes <= 15: + return gui.color.short_duration + elif minutes < 60: + return gui.color.medium_duration + else: + return gui.color.long_duration diff --git a/src/gui/tasks/table/model.py b/src/gui/tasks/table/model.py index 062ded6..8374d03 100644 --- a/src/gui/tasks/table/model.py +++ b/src/gui/tasks/table/model.py @@ -48,10 +48,13 @@ class TableModel(QtCore.QAbstractTableModel): return priority.format(task.priority) elif index.column() == 5: return task.tag - elif role == Qt.ForegroundRole and index.column() == 3: - return QtGui.QBrush(difficulty_color(task.difficulty)) - elif role == Qt.ForegroundRole and index.column() == 4: - return QtGui.QBrush(priority_color(task.priority)) + elif role == Qt.ForegroundRole: + if index.column() == 2: + return QtGui.QBrush(gui.tasks.duration.color(task.duration)) + elif index.column() == 3: + return QtGui.QBrush(difficulty_color(task.difficulty)) + elif index.column() == 4: + return QtGui.QBrush(priority_color(task.priority)) else: return QtCore.QVariant() -- cgit v1.2.3