Files
DualFloatingClock/clock_widget.h
T
sebastian db02df7ca2 feat: menu-bar-only app (no Dock icon) + macOS app icon
- NSApplicationActivationPolicyAccessory: app hidden from Dock and
  app switcher; lives only in the menu bar tray
- resources/clouck.icns: programmatic icon (green gradient rounded
  square, white dial, 10:10 hands), all sizes 16-1024 incl @2x
- CMake: MACOSX_BUNDLE_ICON_FILE wired, icns shipped in Resources/
2026-08-27 22:31:06 +03:00

117 lines
2.9 KiB
C++

#ifndef CLOCK_WIDGET_H
#define CLOCK_WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QTimer>
#include <QMouseEvent>
#include <QMenu>
#include <QAction>
#include <QColor>
#include <optional>
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; }
QString primaryTimeZoneId() const { return m_primaryTimeZoneId; }
QString secondaryTimeZoneId() const { return m_secondaryTimeZoneId; }
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<QColor> pickColor(const QString &title, const QColor &current, 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