Skip to content

Commit

Permalink
spectrum_clock plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolcha committed Aug 27, 2024
1 parent 185360e commit 7a6d419
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ add_subdirectory(date)
add_subdirectory(quick_note)
add_subdirectory(random_position)
add_subdirectory(sample)
add_subdirectory(spectrum_clock)
add_subdirectory(var_translucency)

if (TARGET Qt6::Multimedia)
Expand Down
18 changes: 18 additions & 0 deletions plugins/spectrum_clock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later

project(spectrum_clock VERSION 3.0.0 LANGUAGES CXX)

qt_add_plugin(${PROJECT_NAME} CLASS_NAME SpectrumClockPluginFactory
spectrum_clock_plugin.cpp
spectrum_clock_plugin.hpp
)

add_win_rc_file(${PROJECT_NAME} ${PROJECT_NAME}.rc)

set_clock_plugin_common_properties(${PROJECT_NAME})
target_link_libraries(${PROJECT_NAME} PRIVATE PluginCore)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Gui)

configure_file(${PROJECT_NAME}.json.in ${PROJECT_NAME}.json @ONLY)
6 changes: 6 additions & 0 deletions plugins/spectrum_clock/spectrum_clock.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@PROJECT_NAME@",
"version": "@PROJECT_VERSION@",
"settings_notifier": true,
"author": "Nick Korotysh"
}
30 changes: 30 additions & 0 deletions plugins/spectrum_clock/spectrum_clock.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
1 VERSIONINFO
FILEVERSION ${PROJECT_VERSION_MAJOR},${PROJECT_VERSION_MINOR},${PROJECT_VERSION_PATCH},${BUILD_NUMBER}
PRODUCTVERSION ${CLOCK_VERSION_MAJOR},${CLOCK_VERSION_MINOR},${CLOCK_VERSION_PATCH},0
FILEFLAGSMASK 0x3F
FILEFLAGS 0x0
FILEOS 0x40004
FILETYPE 0x2
FILESUBTYPE 0x0
{
BLOCK "StringFileInfo"
{
BLOCK "040904E4"
{
VALUE "Comments", "${PROJECT_DESCRIPTION}"
VALUE "CompanyName", "Nick Korotysh"
VALUE "FileDescription", "Digital Clock Plugin"
VALUE "FileVersion", "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${BUILD_NUMBER}"
VALUE "InternalName", "${PROJECT_NAME}.dll"
VALUE "LegalCopyright", "(c) 2013-2024 Nick Korotysh"
VALUE "OriginalFilename", "${PROJECT_NAME}.dll"
VALUE "ProductName", "Digital Clock"
VALUE "ProductVersion", "${CLOCK_VERSION}"
}
}

BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409, 0x04E4
}
}
52 changes: 52 additions & 0 deletions plugins/spectrum_clock/spectrum_clock_plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#include "spectrum_clock_plugin.hpp"

void SpectrumClockPlugin::initSharedSettings(const SharedSettings& s)
{
_last_texture = s[cs::Texture].value<QBrush>();
}

void SpectrumClockPlugin::init()
{
_is_active = true;
tick();
}

void SpectrumClockPlugin::shutdown()
{
_is_active = false;
emit optionChanged(cs::Texture, _last_texture);
}

void SpectrumClockPlugin::tick()
{
if (!_is_active) return;

auto color = QColor::fromHsv(_hue, 255, 255);

if (++_hue == 360) _hue = 0;

emit optionChanged(cs::Texture, color);
}

void SpectrumClockPlugin::onOptionChanged(clock_settings::SharedConfigKeys opt, const QVariant& val)
{
Q_UNUSED(opt);
Q_UNUSED(val);
}


std::unique_ptr<ClockPluginBase> SpectrumClockPluginFactory::create() const
{
return std::make_unique<SpectrumClockPlugin>();
}

QString SpectrumClockPluginFactory::description() const
{
return tr("Changes clock color during time.");
}
48 changes: 48 additions & 0 deletions plugins/spectrum_clock/spectrum_clock_plugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* SPDX-FileCopyrightText: 2024 Nick Korotysh <[email protected]>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/

#pragma once

#include "clock_plugin.hpp"

#include <QBrush>

class SpectrumClockPlugin : public SettingsPlugin
{
Q_OBJECT

public:
void initSharedSettings(const SharedSettings& s) override;

public slots:
void init() override;
void shutdown() override;

void tick() override;

void onOptionChanged(cs::SharedConfigKeys opt, const QVariant& val) override;

private:
bool _is_active = false;
QBrush _last_texture;
int _hue = 0;
};


class SpectrumClockPluginFactory : public ClockPluginFactory
{
Q_OBJECT
Q_PLUGIN_METADATA(IID ClockPluginFactory_iid FILE "spectrum_clock.json")
Q_INTERFACES(ClockPluginFactory)

public:
std::unique_ptr<ClockPluginBase> create() const override;

QString title() const override { return tr("\"Spectrum clock\""); }
QString description() const override;

bool perClockInstance() const override { return true; }
};

0 comments on commit 7a6d419

Please sign in to comment.