mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 18:32:28 -05:00
ClockSettings: Add 'show seconds' toggle to time format settings
This commit is contained in:
parent
b2ef7ee531
commit
0a92dbd390
3 changed files with 34 additions and 5 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "ClockSettingsWidget.h"
|
||||
#include <Applications/ClockSettings/ClockSettingsWidgetGML.h>
|
||||
#include <LibConfig/Client.h>
|
||||
#include <LibGUI/CheckBox.h>
|
||||
#include <LibGUI/RadioButton.h>
|
||||
#include <LibGUI/TextBox.h>
|
||||
|
||||
|
@ -16,6 +17,7 @@ ClockSettingsWidget::ClockSettingsWidget()
|
|||
|
||||
m_24_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("24hour_radio");
|
||||
auto& twelve_hour_radio = *find_descendant_of_type_named<GUI::RadioButton>("12hour_radio");
|
||||
m_show_seconds_checkbox = *find_descendant_of_type_named<GUI::CheckBox>("seconds_checkbox");
|
||||
auto& custom_radio = *find_descendant_of_type_named<GUI::RadioButton>("custom_radio");
|
||||
custom_radio.set_checked(true);
|
||||
|
||||
|
@ -23,16 +25,23 @@ ClockSettingsWidget::ClockSettingsWidget()
|
|||
m_custom_format_input->set_text(Config::read_string("Taskbar", "Clock", "TimeFormat"));
|
||||
|
||||
m_24_hour_radio->on_checked = [&](bool) {
|
||||
m_show_seconds_checkbox->set_enabled(true);
|
||||
m_custom_format_input->set_enabled(false);
|
||||
m_custom_format_input->set_text("%T");
|
||||
update_time_format_string();
|
||||
};
|
||||
|
||||
twelve_hour_radio.on_checked = [&](bool) {
|
||||
m_show_seconds_checkbox->set_enabled(true);
|
||||
m_custom_format_input->set_enabled(false);
|
||||
m_custom_format_input->set_text("%I:%M %p");
|
||||
update_time_format_string();
|
||||
};
|
||||
|
||||
m_show_seconds_checkbox->on_checked = [&](bool) {
|
||||
update_time_format_string();
|
||||
};
|
||||
|
||||
custom_radio.on_checked = [&](bool) {
|
||||
m_show_seconds_checkbox->set_enabled(false);
|
||||
m_custom_format_input->set_enabled(true);
|
||||
};
|
||||
}
|
||||
|
@ -45,5 +54,15 @@ void ClockSettingsWidget::apply_settings()
|
|||
void ClockSettingsWidget::reset_default_values()
|
||||
{
|
||||
m_24_hour_radio->set_checked(true);
|
||||
m_show_seconds_checkbox->set_checked(true);
|
||||
Config::write_string("Taskbar", "Clock", "TimeFormat", "%T");
|
||||
}
|
||||
|
||||
void ClockSettingsWidget::update_time_format_string()
|
||||
{
|
||||
bool show_seconds = m_show_seconds_checkbox->is_checked();
|
||||
if (m_24_hour_radio->is_checked())
|
||||
m_custom_format_input->set_text(show_seconds ? "%T" : "%R");
|
||||
else
|
||||
m_custom_format_input->set_text(show_seconds ? "%r" : "%I:%M %p");
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
@GUI::GroupBox {
|
||||
title: "Time Format"
|
||||
shrink_to_fit: false
|
||||
fixed_height: 160
|
||||
fixed_height: 200
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [16, 8, 8]
|
||||
}
|
||||
|
@ -26,14 +26,21 @@
|
|||
|
||||
@GUI::RadioButton {
|
||||
name: "24hour_radio"
|
||||
text: "24-hour (12:34:56)"
|
||||
text: "24-hour"
|
||||
}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "12hour_radio"
|
||||
text: "12-hour (12:34 a.m)"
|
||||
text: "12-hour"
|
||||
}
|
||||
|
||||
@GUI::CheckBox {
|
||||
name: "seconds_checkbox"
|
||||
text: "Show seconds"
|
||||
}
|
||||
|
||||
@GUI::HorizontalSeparator {}
|
||||
|
||||
@GUI::RadioButton {
|
||||
name: "custom_radio"
|
||||
text: "Custom:"
|
||||
|
|
|
@ -18,7 +18,10 @@ private:
|
|||
virtual void apply_settings() override;
|
||||
virtual void reset_default_values() override;
|
||||
|
||||
void update_time_format_string();
|
||||
|
||||
RefPtr<GUI::RadioButton> m_24_hour_radio;
|
||||
RefPtr<GUI::CheckBox> m_show_seconds_checkbox;
|
||||
RefPtr<GUI::TextBox> m_custom_format_input;
|
||||
|
||||
String m_date_format;
|
||||
|
|
Loading…
Add table
Reference in a new issue