#ifndef CLOCK_WIDGET_H #define CLOCK_WIDGET_H #include #include #include #include #include #include #include #include class ConfigManager; // QLabel that paints its text with an optional outline (border around the // glyphs, not a box). QSS cannot stroke text, so we use a QPainterPath. class ClockLabel : public QLabel { Q_OBJECT public: explicit ClockLabel(QWidget *parent = nullptr); void setDisplayColors(const QColor &textColor, const QColor &outlineColor, qreal outlineWidth); protected: void paintEvent(QPaintEvent *event) override; private: QColor m_textColor; QColor m_outlineColor; qreal m_outlineWidth; }; class ClockWidget : public QWidget { Q_OBJECT public: explicit ClockWidget(QWidget *parent = nullptr); ~ClockWidget(); QMenu *menu() const { return m_contextMenu; } protected: void mousePressEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; void mouseReleaseEvent(QMouseEvent *event) override; void contextMenuEvent(QContextMenuEvent *event) override; void paintEvent(QPaintEvent *event) override; private slots: void updateTime(); void toggleAlwaysOnTop(); void changeFontColor(); void changeBackgroundColor(); void changeBorderColor(); void changeFontSize(); void changeLocationFontSize(); void changePrimaryTimeZone(); void changeSecondaryTimeZone(); void resetSettings(); void quitApplication(); private: void setupUI(); void createMenu(); void loadSettings(); void saveSettings(); void updateStyleSheet(); void changeTimeZone(bool primaryClock); QString formattedTime(const QString &timeZoneId) const; QString locationName(const QString &timeZoneId) const; std::optional pickColor(const QString &title, const QColor ¤t, QWidget *parent); ClockLabel *m_primaryTimeLabel; ClockLabel *m_primaryLocationLabel; ClockLabel *m_secondaryTimeLabel; ClockLabel *m_secondaryLocationLabel; QTimer *m_timer; QMenu *m_contextMenu; // Drag related QPoint m_dragPosition; bool m_dragging; // Resize related bool m_resizing; QPoint m_resizeStartPos; QSize m_resizeStartSize; int m_resizeBorder; // Settings ConfigManager *m_configManager; QColor m_fontColor; QColor m_backgroundColor; QColor m_borderColor; int m_fontSize; int m_locationFontSize; bool m_alwaysOnTop; QString m_primaryTimeZoneId; QString m_secondaryTimeZoneId; // Helper methods bool isInResizeArea(const QPoint &pos) const; void positionAtBottomRight(); #ifdef Q_OS_MAC void setupMacOSWindowProperties(); #endif }; #endif // CLOCK_WIDGET_H