1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 21:27:45 +00:00

ClockSettings+Taskbar: Add settings for taskbar clock format

This commit is contained in:
cflip 2022-04-03 17:13:52 -06:00 committed by Andreas Kling
parent 36b6356ce5
commit 5bb0b6ba7a
13 changed files with 334 additions and 179 deletions

View file

@ -5,6 +5,7 @@
*/
#include "ClockWidget.h"
#include <LibConfig/Client.h>
#include <LibCore/Process.h>
#include <LibGUI/Painter.h>
#include <LibGUI/SeparatorWidget.h>
@ -20,9 +21,7 @@ ClockWidget::ClockWidget()
set_frame_shadow(Gfx::FrameShadow::Sunken);
set_frame_thickness(1);
m_time_width = font().width("22:22:22");
set_fixed_size(m_time_width + 20, 21);
update_format(Config::read_string("Taskbar", "Clock", "TimeFormat", "%T"));
m_timer = add<Core::Timer>(1000, [this] {
static time_t last_update_time;
@ -159,10 +158,17 @@ ClockWidget::ClockWidget()
};
}
void ClockWidget::update_format(String const& format)
{
m_time_format = format;
m_time_width = font().width(Core::DateTime::create(122, 2, 22, 22, 22, 22).to_string(format));
set_fixed_size(m_time_width + 20, 21);
}
void ClockWidget::paint_event(GUI::PaintEvent& event)
{
GUI::Frame::paint_event(event);
auto time_text = Core::DateTime::now().to_string("%T");
auto time_text = Core::DateTime::now().to_string(m_time_format);
GUI::Painter painter(*this);
painter.add_clip_rect(frame_inner_rect());

View file

@ -24,6 +24,8 @@ class ClockWidget final : public GUI::Frame {
public:
virtual ~ClockWidget() override = default;
void update_format(String const&);
private:
ClockWidget();
@ -42,6 +44,7 @@ private:
void position_calendar_window();
void jump_to_current_date();
String m_time_format;
RefPtr<GUI::Window> m_calendar_window;
RefPtr<GUI::Calendar> m_calendar;
RefPtr<GUI::Button> m_next_date;

View file

@ -85,7 +85,7 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu)
m_applet_area_container->set_frame_shape(Gfx::FrameShape::Box);
m_applet_area_container->set_frame_shadow(Gfx::FrameShadow::Sunken);
main_widget.add<Taskbar::ClockWidget>();
m_clock_widget = main_widget.add<Taskbar::ClockWidget>();
m_show_desktop_button = GUI::Button::construct();
m_show_desktop_button->set_tooltip("Show Desktop");
@ -99,6 +99,15 @@ TaskbarWindow::TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu)
m_assistant_app_file = Desktop::AppFile::open(af_path);
}
void TaskbarWindow::config_string_did_change(String const& domain, String const& group, String const& key, String const& value)
{
VERIFY(domain == "Taskbar");
if (group == "Clock" && key == "TimeFormat") {
m_clock_widget->update_format(value);
update_applet_area();
}
}
void TaskbarWindow::show_desktop_button_clicked(unsigned)
{
GUI::ConnectionToWindowMangerServer::the().async_toggle_show_desktop();

View file

@ -6,6 +6,7 @@
#pragma once
#include "ClockWidget.h"
#include "WindowList.h"
#include <LibConfig/Listener.h>
#include <LibDesktop/AppFile.h>
@ -14,7 +15,8 @@
#include <LibGfx/ShareableBitmap.h>
#include <Services/WindowServer/ScreenLayout.h>
class TaskbarWindow final : public GUI::Window {
class TaskbarWindow final : public GUI::Window
, public Config::Listener {
C_OBJECT(TaskbarWindow);
public:
@ -23,6 +25,8 @@ public:
static int taskbar_height() { return 27; }
static int taskbar_icon_size() { return 16; }
virtual void config_string_did_change(String const&, String const&, String const&, String const&) override;
private:
explicit TaskbarWindow(NonnullRefPtr<GUI::Menu> start_menu);
static void show_desktop_button_clicked(unsigned);
@ -53,6 +57,7 @@ private:
RefPtr<GUI::Frame> m_applet_area_container;
RefPtr<GUI::Button> m_start_button;
RefPtr<GUI::Button> m_show_desktop_button;
RefPtr<Taskbar::ClockWidget> m_clock_widget;
RefPtr<Desktop::AppFile> m_assistant_app_file;