Add consts arguments
This commit is contained in:
parent
ccc210e989
commit
328600b777
@ -10,30 +10,26 @@ CircularProgressBar::CircularProgressBar(QWidget *parent)
|
|||||||
setFixedSize(220, 220);
|
setFixedSize(220, 220);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgressBar::setValue(int value)
|
void CircularProgressBar::setValue(const int value) {
|
||||||
{
|
if (const int clampedValue = qBound(0, value, m_maximum); clampedValue != m_value) {
|
||||||
int clampedValue = qBound(0, value, m_maximum);
|
|
||||||
if (clampedValue != m_value) {
|
|
||||||
m_value = clampedValue;
|
m_value = clampedValue;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgressBar::setMaximum(int maximum)
|
void CircularProgressBar::setMaximum(int maximum){
|
||||||
{
|
|
||||||
m_maximum = maximum;
|
m_maximum = maximum;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgressBar::paintEvent(QPaintEvent *event)
|
void CircularProgressBar::paintEvent(QPaintEvent *event){
|
||||||
{
|
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
int side = qMin(width(), height());
|
const int side = qMin(width(), height());
|
||||||
QRect rect((width() - side) / 2 + 20, (height() - side) / 2 + 20,
|
const QRect rect((width() - side) / 2 + 20, (height() - side) / 2 + 20,
|
||||||
side - 40, side - 40);
|
side - 40, side - 40);
|
||||||
|
|
||||||
// Background circle
|
// Background circle
|
||||||
@ -48,19 +44,17 @@ void CircularProgressBar::paintEvent(QPaintEvent *event)
|
|||||||
progressPen.setCapStyle(Qt::RoundCap);
|
progressPen.setCapStyle(Qt::RoundCap);
|
||||||
painter.setPen(progressPen);
|
painter.setPen(progressPen);
|
||||||
|
|
||||||
int angle = (360 * m_value) / m_maximum;
|
const int angle = (360 * m_value) / m_maximum;
|
||||||
painter.drawArc(rect, 90 * 16, -angle * 16);
|
painter.drawArc(rect, 90 * 16, -angle * 16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgressBar::resizeEvent(QResizeEvent *event)
|
void CircularProgressBar::resizeEvent(QResizeEvent *event){
|
||||||
{
|
|
||||||
QWidget::resizeEvent(event);
|
QWidget::resizeEvent(event);
|
||||||
updateChildPositions();
|
updateChildPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircularProgressBar::updateChildPositions()
|
void CircularProgressBar::updateChildPositions() const {
|
||||||
{
|
|
||||||
const auto children = findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
const auto children = findChildren<QWidget*>(QString(), Qt::FindDirectChildrenOnly);
|
||||||
for (QWidget *child : children) {
|
for (QWidget *child : children) {
|
||||||
child->resize(width(), 40);
|
child->resize(width(), 40);
|
||||||
|
|||||||
@ -3,8 +3,7 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class CircularProgressBar : public QWidget
|
class CircularProgressBar final : public QWidget {
|
||||||
{
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -12,8 +11,8 @@ public:
|
|||||||
|
|
||||||
void setValue(int value);
|
void setValue(int value);
|
||||||
void setMaximum(int maximum);
|
void setMaximum(int maximum);
|
||||||
int value() const { return m_value; }
|
[[nodiscard]] int value() const { return m_value; }
|
||||||
int maximum() const { return m_maximum; }
|
[[nodiscard]] int maximum() const { return m_maximum; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) override;
|
void paintEvent(QPaintEvent *event) override;
|
||||||
@ -23,7 +22,7 @@ private:
|
|||||||
int m_value;
|
int m_value;
|
||||||
int m_maximum;
|
int m_maximum;
|
||||||
|
|
||||||
void updateChildPositions();
|
void updateChildPositions() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CIRCULARPROGRESSBAR_H
|
#endif // CIRCULARPROGRESSBAR_H
|
||||||
|
|||||||
@ -1,11 +1,10 @@
|
|||||||
#include "KeyboardShortcuts.h"
|
#include "KeyboardShortcuts.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
KeyboardShortcuts::KeyboardShortcuts(QWidget *parent)
|
KeyboardShortcuts::KeyboardShortcuts(QWidget *parent) : QObject(parent) {
|
||||||
: QObject(parent)
|
|
||||||
{
|
|
||||||
setupShortcuts(parent);
|
setupShortcuts(parent);
|
||||||
}
|
}
|
||||||
|
KeyboardShortcuts::~KeyboardShortcuts() = default;
|
||||||
|
|
||||||
void KeyboardShortcuts::setupShortcuts(QWidget *parent)
|
void KeyboardShortcuts::setupShortcuts(QWidget *parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#ifndef KEYBOARDSHORTCUTS_H
|
#ifndef KEYBOARDSHORTCUTS_H
|
||||||
#define KEYBOARDSHORTCUTS_H
|
#define KEYBOARDSHORTCUTS_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
|
|
||||||
class KeyboardShortcuts : public QObject
|
class KeyboardShortcuts : public QObject
|
||||||
@ -10,7 +9,7 @@ class KeyboardShortcuts : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit KeyboardShortcuts(QWidget *parent = nullptr);
|
explicit KeyboardShortcuts(QWidget *parent = nullptr);
|
||||||
~KeyboardShortcuts() = default;
|
~KeyboardShortcuts() override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void startPauseRequested();
|
void startPauseRequested();
|
||||||
@ -22,11 +21,11 @@ signals:
|
|||||||
private:
|
private:
|
||||||
void setupShortcuts(QWidget *parent);
|
void setupShortcuts(QWidget *parent);
|
||||||
|
|
||||||
QShortcut *m_startShortcut;
|
QShortcut *m_startShortcut{};
|
||||||
QShortcut *m_pauseShortcut;
|
QShortcut *m_pauseShortcut{};
|
||||||
QShortcut *m_resetShortcut;
|
QShortcut *m_resetShortcut{};
|
||||||
QShortcut *m_settingsShortcut;
|
QShortcut *m_settingsShortcut{};
|
||||||
QShortcut *m_skipShortcut;
|
QShortcut *m_skipShortcut{};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEYBOARDSHORTCUTS_H
|
#endif // KEYBOARDSHORTCUTS_H
|
||||||
|
|||||||
@ -4,12 +4,9 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
NotificationManager::NotificationManager(QWidget *parent)
|
NotificationManager::NotificationManager(QWidget *parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_parent(parent), m_trayManager(nullptr),
|
||||||
, m_parent(parent)
|
m_notificationsEnabled(true) {}
|
||||||
, m_trayManager(nullptr)
|
NotificationManager::~NotificationManager() {}
|
||||||
, m_notificationsEnabled(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotificationManager::setSystemTrayManager(SystemTrayManager *trayManager)
|
void NotificationManager::setSystemTrayManager(SystemTrayManager *trayManager)
|
||||||
{
|
{
|
||||||
@ -21,8 +18,7 @@ void NotificationManager::setNotificationsEnabled(bool enabled)
|
|||||||
m_notificationsEnabled = enabled;
|
m_notificationsEnabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationManager::showNotification(const QString &message)
|
void NotificationManager::showNotification(const QString &message) const {
|
||||||
{
|
|
||||||
if (!m_notificationsEnabled) return;
|
if (!m_notificationsEnabled) return;
|
||||||
|
|
||||||
if (m_trayManager && m_trayManager->isVisible()) {
|
if (m_trayManager && m_trayManager->isVisible()) {
|
||||||
|
|||||||
@ -13,11 +13,11 @@ class NotificationManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NotificationManager(QWidget *parent = nullptr);
|
explicit NotificationManager(QWidget *parent = nullptr);
|
||||||
~NotificationManager() = default;
|
~NotificationManager() override;
|
||||||
|
|
||||||
void setSystemTrayManager(SystemTrayManager *trayManager);
|
void setSystemTrayManager(SystemTrayManager *trayManager);
|
||||||
void setNotificationsEnabled(bool enabled);
|
void setNotificationsEnabled(bool enabled);
|
||||||
void showNotification(const QString &message);
|
void showNotification(const QString &message) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_parent;
|
QWidget *m_parent;
|
||||||
|
|||||||
@ -8,10 +8,8 @@
|
|||||||
#include "TimerState.h"
|
#include "TimerState.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCloseEvent>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QHBoxLayout>
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
@ -104,8 +102,8 @@ void PomodoroTimer::createButtons()
|
|||||||
m_statsButton = new QPushButton("Statistics", m_mainFrame);
|
m_statsButton = new QPushButton("Statistics", m_mainFrame);
|
||||||
|
|
||||||
// Set button sizes
|
// Set button sizes
|
||||||
const QSize mainButtonSize(MAIN_BUTTON_WIDTH, MAIN_BUTTON_HEIGHT);
|
constexpr QSize mainButtonSize(MAIN_BUTTON_WIDTH, MAIN_BUTTON_HEIGHT);
|
||||||
const QSize smallButtonSize(SMALL_BUTTON_WIDTH, SMALL_BUTTON_HEIGHT);
|
constexpr QSize smallButtonSize(SMALL_BUTTON_WIDTH, SMALL_BUTTON_HEIGHT);
|
||||||
|
|
||||||
m_startButton->setFixedSize(mainButtonSize);
|
m_startButton->setFixedSize(mainButtonSize);
|
||||||
m_pauseButton->setFixedSize(mainButtonSize);
|
m_pauseButton->setFixedSize(mainButtonSize);
|
||||||
@ -165,8 +163,7 @@ void PomodoroTimer::createLayouts()
|
|||||||
setLayout(frameLayout);
|
setLayout(frameLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PomodoroTimer::applyStyles()
|
void PomodoroTimer::applyStyles() const {
|
||||||
{
|
|
||||||
QFont timeFont = m_timeLabel->font();
|
QFont timeFont = m_timeLabel->font();
|
||||||
timeFont.setPointSize(TIME_FONT_SIZE);
|
timeFont.setPointSize(TIME_FONT_SIZE);
|
||||||
timeFont.setBold(true);
|
timeFont.setBold(true);
|
||||||
@ -325,13 +322,14 @@ void PomodoroTimer::updateTimerState(TimerState newState)
|
|||||||
m_currentState = newState;
|
m_currentState = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PomodoroTimer::formatTime(int seconds) const
|
QString PomodoroTimer::formatTime(int seconds) {
|
||||||
{
|
|
||||||
const int minutes = seconds / 60;
|
const int minutes = seconds / 60;
|
||||||
const int secs = seconds % 60;
|
const int secs = seconds % 60;
|
||||||
return QString("%1:%2").arg(minutes, 2, 10, QChar('0'))
|
return QString("%1:%2")
|
||||||
|
.arg(minutes, 2, 10, QChar('0'))
|
||||||
.arg(secs, 2, 10, QChar('0'));
|
.arg(secs, 2, 10, QChar('0'));
|
||||||
}
|
}
|
||||||
|
void PomodoroTimer::needsDisplayUpdate() {}
|
||||||
|
|
||||||
void PomodoroTimer::updateDisplay()
|
void PomodoroTimer::updateDisplay()
|
||||||
{
|
{
|
||||||
@ -350,16 +348,14 @@ void PomodoroTimer::updateDisplay()
|
|||||||
currentSession, SESSIONS_BEFORE_LONG_BREAK);
|
currentSession, SESSIONS_BEFORE_LONG_BREAK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PomodoroTimer::updateSessionCounter()
|
void PomodoroTimer::updateSessionCounter() const {
|
||||||
{
|
|
||||||
const int currentSession = (m_completedSessions % SESSIONS_BEFORE_LONG_BREAK) + 1;
|
const int currentSession = (m_completedSessions % SESSIONS_BEFORE_LONG_BREAK) + 1;
|
||||||
m_sessionLabel->setText(QString("Session %1 of %2")
|
m_sessionLabel->setText(QString("Session %1 of %2")
|
||||||
.arg(currentSession)
|
.arg(currentSession)
|
||||||
.arg(SESSIONS_BEFORE_LONG_BREAK));
|
.arg(SESSIONS_BEFORE_LONG_BREAK));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PomodoroTimer::updateButtonStates()
|
void PomodoroTimer::updateButtonStates() const {
|
||||||
{
|
|
||||||
m_startButton->setEnabled(!m_isRunning);
|
m_startButton->setEnabled(!m_isRunning);
|
||||||
m_pauseButton->setEnabled(m_isRunning);
|
m_pauseButton->setEnabled(m_isRunning);
|
||||||
|
|
||||||
@ -377,14 +373,14 @@ void PomodoroTimer::updateButtonStates()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PomodoroTimer::updateWindowTitle()
|
void PomodoroTimer::updateWindowTitle() {
|
||||||
{
|
|
||||||
const QString timeRemaining = formatTime(m_currentTime);
|
const QString timeRemaining = formatTime(m_currentTime);
|
||||||
const QString emoji = TimerStateHelper::getStateEmoji(m_currentState);
|
const QString emoji = TimerStateHelper::getStateEmoji(m_currentState);
|
||||||
|
|
||||||
QString title;
|
QString title;
|
||||||
if (m_isRunning) {
|
if (m_isRunning) {
|
||||||
const QString stateText = (m_currentState == TimerState::Work) ? "Focus" : "Break";
|
const QString stateText =
|
||||||
|
(m_currentState == TimerState::Work) ? "Focus" : "Break";
|
||||||
title = QString("%1 %2: %3").arg(emoji, stateText, timeRemaining);
|
title = QString("%1 %2: %3").arg(emoji, stateText, timeRemaining);
|
||||||
} else {
|
} else {
|
||||||
title = "🍅 Pomodoro Timer";
|
title = "🍅 Pomodoro Timer";
|
||||||
@ -392,6 +388,7 @@ void PomodoroTimer::updateWindowTitle()
|
|||||||
|
|
||||||
setWindowTitle(title);
|
setWindowTitle(title);
|
||||||
}
|
}
|
||||||
|
void PomodoroTimer::updateTrayTooltip() {}
|
||||||
|
|
||||||
void PomodoroTimer::onShowSettings()
|
void PomodoroTimer::onShowSettings()
|
||||||
{
|
{
|
||||||
@ -459,8 +456,7 @@ void PomodoroTimer::loadSettings()
|
|||||||
m_totalBreakTime = settings.value("totalBreakTime", 0).toInt();
|
m_totalBreakTime = settings.value("totalBreakTime", 0).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PomodoroTimer::saveSettings()
|
void PomodoroTimer::saveSettings() const {
|
||||||
{
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
settings.setValue("workDuration", m_workDuration);
|
settings.setValue("workDuration", m_workDuration);
|
||||||
settings.setValue("shortBreakDuration", m_shortBreakDuration);
|
settings.setValue("shortBreakDuration", m_shortBreakDuration);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#ifndef POMODOROTIMER_H
|
#ifndef POMODOROTIMER_H
|
||||||
#define POMODOROTIMER_H
|
#define POMODOROTIMER_H
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -61,11 +60,11 @@ private:
|
|||||||
void createLabels();
|
void createLabels();
|
||||||
void createButtons();
|
void createButtons();
|
||||||
void createLayouts();
|
void createLayouts();
|
||||||
void applyStyles();
|
void applyStyles() const;
|
||||||
|
|
||||||
// Settings management
|
// Settings management
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
void saveSettings();
|
void saveSettings() const;
|
||||||
|
|
||||||
// Timer state management
|
// Timer state management
|
||||||
void resetTimerState();
|
void resetTimerState();
|
||||||
@ -73,14 +72,14 @@ private:
|
|||||||
|
|
||||||
// Display update methods - optimized to avoid unnecessary updates
|
// Display update methods - optimized to avoid unnecessary updates
|
||||||
void updateDisplay();
|
void updateDisplay();
|
||||||
void updateSessionCounter();
|
void updateSessionCounter() const;
|
||||||
void updateButtonStates();
|
void updateButtonStates() const;
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
void updateTrayTooltip();
|
static void updateTrayTooltip();
|
||||||
|
|
||||||
// Utility methods
|
// Utility methods
|
||||||
QString formatTime(int seconds) const;
|
static QString formatTime(int seconds);
|
||||||
bool needsDisplayUpdate() const;
|
static void needsDisplayUpdate();
|
||||||
|
|
||||||
// UI elements - use raw pointers for Qt objects with parent ownership
|
// UI elements - use raw pointers for Qt objects with parent ownership
|
||||||
QTimer *m_timer;
|
QTimer *m_timer;
|
||||||
|
|||||||
@ -82,16 +82,15 @@ bool SettingsDialog::minimizeToTray() const { return m_minimizeToTrayCheck->isCh
|
|||||||
bool SettingsDialog::showNotifications() const { return m_showNotificationsCheck->isChecked(); }
|
bool SettingsDialog::showNotifications() const { return m_showNotificationsCheck->isChecked(); }
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
void SettingsDialog::setWorkDuration(int minutes) { m_workDurationSpin->setValue(minutes); }
|
void SettingsDialog::setWorkDuration(int minutes) const { m_workDurationSpin->setValue(minutes); }
|
||||||
void SettingsDialog::setShortBreakDuration(int minutes) { m_shortBreakSpin->setValue(minutes); }
|
void SettingsDialog::setShortBreakDuration(int minutes) const { m_shortBreakSpin->setValue(minutes); }
|
||||||
void SettingsDialog::setLongBreakDuration(int minutes) { m_longBreakSpin->setValue(minutes); }
|
void SettingsDialog::setLongBreakDuration(int minutes) const { m_longBreakSpin->setValue(minutes); }
|
||||||
void SettingsDialog::setAutoStartBreaks(bool enabled) { m_autoStartBreaksCheck->setChecked(enabled); }
|
void SettingsDialog::setAutoStartBreaks(bool enabled) const { m_autoStartBreaksCheck->setChecked(enabled); }
|
||||||
void SettingsDialog::setAutoStartWork(bool enabled) { m_autoStartWorkCheck->setChecked(enabled); }
|
void SettingsDialog::setAutoStartWork(bool enabled) const { m_autoStartWorkCheck->setChecked(enabled); }
|
||||||
void SettingsDialog::setMinimizeToTray(bool enabled) { m_minimizeToTrayCheck->setChecked(enabled); }
|
void SettingsDialog::setMinimizeToTray(bool enabled) const { m_minimizeToTrayCheck->setChecked(enabled); }
|
||||||
void SettingsDialog::setShowNotifications(bool enabled) { m_showNotificationsCheck->setChecked(enabled); }
|
void SettingsDialog::setShowNotifications(bool enabled) const { m_showNotificationsCheck->setChecked(enabled); }
|
||||||
|
|
||||||
void SettingsDialog::resetToDefaults()
|
void SettingsDialog::resetToDefaults() const {
|
||||||
{
|
|
||||||
setWorkDuration(25);
|
setWorkDuration(25);
|
||||||
setShortBreakDuration(5);
|
setShortBreakDuration(5);
|
||||||
setLongBreakDuration(15);
|
setLongBreakDuration(15);
|
||||||
|
|||||||
@ -26,19 +26,19 @@ public:
|
|||||||
bool showNotifications() const;
|
bool showNotifications() const;
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
void setWorkDuration(int minutes);
|
void setWorkDuration(int minutes) const;
|
||||||
void setShortBreakDuration(int minutes);
|
void setShortBreakDuration(int minutes) const;
|
||||||
void setLongBreakDuration(int minutes);
|
void setLongBreakDuration(int minutes) const;
|
||||||
void setAutoStartBreaks(bool enabled);
|
void setAutoStartBreaks(bool enabled) const;
|
||||||
void setAutoStartWork(bool enabled);
|
void setAutoStartWork(bool enabled) const;
|
||||||
void setMinimizeToTray(bool enabled);
|
void setMinimizeToTray(bool enabled) const;
|
||||||
void setShowNotifications(bool enabled);
|
void setShowNotifications(bool enabled) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void resetToDefaults();
|
void resetToDefaults() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupUI();
|
void setupUI();
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
#include "StatisticsDialog.h"
|
#include "StatisticsDialog.h"
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include <QScrollArea>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QTextStream>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#include "TimerState.h"
|
#include "TimerState.h"
|
||||||
@ -52,7 +49,7 @@ void StatisticsChart::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
constexpr int LABEL_SKIP_INTERVAL = 3;
|
constexpr int LABEL_SKIP_INTERVAL = 3;
|
||||||
const int margin = 40;
|
constexpr int margin = 40;
|
||||||
const int chartWidth = width() - 2 * margin;
|
const int chartWidth = width() - 2 * margin;
|
||||||
const int chartHeight = height() - 2 * margin;
|
const int chartHeight = height() - 2 * margin;
|
||||||
|
|
||||||
@ -305,8 +302,8 @@ void StatisticsDialog::setStatistics(int totalSessions, int totalWorkTime, int t
|
|||||||
.arg(m_totalWorkTime / 3600).arg((m_totalWorkTime % 3600) / 60)
|
.arg(m_totalWorkTime / 3600).arg((m_totalWorkTime % 3600) / 60)
|
||||||
.arg(m_totalBreakTime / 3600).arg((m_totalBreakTime % 3600) / 60)
|
.arg(m_totalBreakTime / 3600).arg((m_totalBreakTime % 3600) / 60)
|
||||||
.arg(m_totalSessions > 0 ? m_totalWorkTime / (m_totalSessions * 60) : 0)
|
.arg(m_totalSessions > 0 ? m_totalWorkTime / (m_totalSessions * 60) : 0)
|
||||||
.arg(m_totalBreakTime > 0 ? QString::number(double(m_totalWorkTime) / m_totalBreakTime, 'f', 2) : "N/A")
|
.arg(m_totalBreakTime > 0 ? QString::number(static_cast<double>(m_totalWorkTime) / m_totalBreakTime, 'f', 2) : "N/A")
|
||||||
.arg(m_totalSessions > 0 ? QString::number(double(m_totalSessions) / 7, 'f', 1) : "0")
|
.arg(m_totalSessions > 0 ? QString::number(static_cast<double>(m_totalSessions) / 7, 'f', 1) : "0")
|
||||||
.arg(m_dailyWorkTime.value(QDate::currentDate(), 0))
|
.arg(m_dailyWorkTime.value(QDate::currentDate(), 0))
|
||||||
.arg(m_dailyWorkTime.value(QDate::currentDate().addDays(-1), 0))
|
.arg(m_dailyWorkTime.value(QDate::currentDate().addDays(-1), 0))
|
||||||
.arg(m_dailyWorkTime.value(QDate::currentDate(), 0)) // This week calculation can be improved
|
.arg(m_dailyWorkTime.value(QDate::currentDate(), 0)) // This week calculation can be improved
|
||||||
@ -323,28 +320,27 @@ void StatisticsDialog::loadDailyStatistics()
|
|||||||
QDate today = QDate::currentDate();
|
QDate today = QDate::currentDate();
|
||||||
for (int i = 0; i < 30; ++i) {
|
for (int i = 0; i < 30; ++i) {
|
||||||
QDate date = today.addDays(-i);
|
QDate date = today.addDays(-i);
|
||||||
QSettings settings;
|
QSettings settings1;
|
||||||
QVariantMap dailyStats = settings.value("dailyStats").toMap();
|
auto dailyStats = settings1.value("dailyStats").toMap();
|
||||||
|
|
||||||
for (auto it = dailyStats.begin(); it != dailyStats.end(); ++it) {
|
for (auto it = dailyStats.begin(); it != dailyStats.end(); ++it) {
|
||||||
QDate date = QDate::fromString(it.key(), "yyyy-MM-dd");
|
QDate date1 = QDate::fromString(it.key(), "yyyy-MM-dd");
|
||||||
if (date.isValid()) {
|
if (date1.isValid()) {
|
||||||
QVariantMap dayData = it.value().toMap();
|
QVariantMap dayData = it.value().toMap();
|
||||||
m_dailyWorkTime[date] = dayData["workTime"].toInt();
|
m_dailyWorkTime[date1] = dayData["workTime"].toInt();
|
||||||
m_dailySessions[date] = dayData["sessions"].toInt();
|
m_dailySessions[date1] = dayData["sessions"].toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString sessionKey = QString("dailyStats/sessions_%1").arg(date.toString("yyyy-MM-dd"));
|
QString sessionKey = QString("dailyStats/sessions_%1").arg(date.toString("yyyy-MM-dd"));
|
||||||
int sessions = settings.value(sessionKey, 0).toInt();
|
int sessions = settings1.value(sessionKey, 0).toInt();
|
||||||
if (sessions > 0) {
|
if (sessions > 0) {
|
||||||
m_dailySessions[date] = sessions;
|
m_dailySessions[date] = sessions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatisticsDialog::updateOverview()
|
void StatisticsDialog::updateOverview() const {
|
||||||
{
|
|
||||||
m_totalSessionsLabel->setText(QString::number(m_totalSessions));
|
m_totalSessionsLabel->setText(QString::number(m_totalSessions));
|
||||||
|
|
||||||
// Правильное форматирование времени
|
// Правильное форматирование времени
|
||||||
@ -380,8 +376,7 @@ void StatisticsDialog::updateOverview()
|
|||||||
m_monthLabel->setText(TimerStateHelper::formatDuration(monthTotal * 60));
|
m_monthLabel->setText(TimerStateHelper::formatDuration(monthTotal * 60));
|
||||||
}
|
}
|
||||||
|
|
||||||
void StatisticsDialog::updateChart()
|
void StatisticsDialog::updateChart() const {
|
||||||
{
|
|
||||||
QMap<QDate, int> chartData;
|
QMap<QDate, int> chartData;
|
||||||
QDate today = QDate::currentDate();
|
QDate today = QDate::currentDate();
|
||||||
|
|
||||||
|
|||||||
@ -43,8 +43,8 @@ private:
|
|||||||
void setupChartTab();
|
void setupChartTab();
|
||||||
void setupDetailsTab();
|
void setupDetailsTab();
|
||||||
void loadDailyStatistics();
|
void loadDailyStatistics();
|
||||||
void updateOverview();
|
void updateOverview() const;
|
||||||
void updateChart();
|
void updateChart() const;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
QTabWidget *m_tabWidget;
|
QTabWidget *m_tabWidget;
|
||||||
|
|||||||
@ -3,10 +3,7 @@
|
|||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
SystemTrayManager::SystemTrayManager(QObject *parent)
|
SystemTrayManager::SystemTrayManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent), m_trayIcon(nullptr), m_trayMenu(nullptr) {
|
||||||
, m_trayIcon(nullptr)
|
|
||||||
, m_trayMenu(nullptr)
|
|
||||||
{
|
|
||||||
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
qWarning("System tray is not available on this system.");
|
qWarning("System tray is not available on this system.");
|
||||||
return;
|
return;
|
||||||
@ -17,9 +14,12 @@ SystemTrayManager::SystemTrayManager(QObject *parent)
|
|||||||
|
|
||||||
setupTrayMenu();
|
setupTrayMenu();
|
||||||
|
|
||||||
connect(m_trayIcon, QOverload<QSystemTrayIcon::ActivationReason>::of(&QSystemTrayIcon::activated),
|
connect(m_trayIcon,
|
||||||
|
QOverload<QSystemTrayIcon::ActivationReason>::of(
|
||||||
|
&QSystemTrayIcon::activated),
|
||||||
this, &SystemTrayManager::onTrayIconActivated);
|
this, &SystemTrayManager::onTrayIconActivated);
|
||||||
}
|
}
|
||||||
|
SystemTrayManager::~SystemTrayManager() {}
|
||||||
|
|
||||||
void SystemTrayManager::setupTrayMenu()
|
void SystemTrayManager::setupTrayMenu()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
#ifndef SYSTEMTRAYMANAGER_H
|
#ifndef SYSTEMTRAYMANAGER_H
|
||||||
#define SYSTEMTRAYMANAGER_H
|
#define SYSTEMTRAYMANAGER_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include "TimerState.h"
|
#include "TimerState.h"
|
||||||
@ -12,7 +11,7 @@ class SystemTrayManager : public QObject
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SystemTrayManager(QObject *parent = nullptr);
|
explicit SystemTrayManager(QObject *parent = nullptr);
|
||||||
~SystemTrayManager() = default;
|
~SystemTrayManager() override;
|
||||||
|
|
||||||
void show();
|
void show();
|
||||||
void hide();
|
void hide();
|
||||||
|
|||||||
2
main.cpp
2
main.cpp
@ -1,11 +1,9 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QIcon>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QRadialGradient>
|
#include <QRadialGradient>
|
||||||
#include <QPen>
|
#include <QPen>
|
||||||
#include <QBrush>
|
|
||||||
#include "PomodoroTimer.h"
|
#include "PomodoroTimer.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user