/src/libreoffice/vcl/source/weld/TimeFormatter.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <vcl/vclenum.hxx> |
11 | | #include <vcl/weld/TimeFormatter.hxx> |
12 | | |
13 | | namespace weld |
14 | | { |
15 | | TimeFormatter::TimeFormatter(weld::Entry& rEntry) |
16 | 0 | : EntryFormatter(rEntry) |
17 | 0 | , m_eFormat(TimeFieldFormat::F_NONE) |
18 | 0 | , m_eTimeFormat(TimeFormat::Hour24) |
19 | 0 | , m_bDuration(false) |
20 | 0 | { |
21 | 0 | Init(); |
22 | 0 | } |
23 | | |
24 | | TimeFormatter::TimeFormatter(weld::FormattedSpinButton& rSpinButton) |
25 | 0 | : EntryFormatter(rSpinButton) |
26 | 0 | , m_eFormat(TimeFieldFormat::F_NONE) |
27 | 0 | , m_eTimeFormat(TimeFormat::Hour24) |
28 | 0 | , m_bDuration(false) |
29 | 0 | { |
30 | 0 | Init(); |
31 | 0 | } |
32 | | |
33 | | void TimeFormatter::Init() |
34 | 0 | { |
35 | 0 | DisableRemainderFactor(); //so with hh::mm::ss, incrementing mm will not reset ss |
36 | |
|
37 | 0 | SetFormatValueHdl(LINK(this, TimeFormatter, FormatOutputHdl)); |
38 | 0 | SetParseTextHdl(LINK(this, TimeFormatter, ParseInputHdl)); |
39 | |
|
40 | 0 | SetMin(tools::Time(0, 0)); |
41 | 0 | SetMax(tools::Time(23, 59, 59, 999999999)); |
42 | | |
43 | | // so the spin size can depend on which zone the cursor is in |
44 | 0 | get_widget().connect_cursor_position(LINK(this, TimeFormatter, CursorChangedHdl)); |
45 | | // and set the initial spin size |
46 | 0 | CursorChangedHdl(get_widget()); |
47 | 0 | } |
48 | | |
49 | | void TimeFormatter::SetExtFormat(ExtTimeFieldFormat eFormat) |
50 | 0 | { |
51 | 0 | switch (eFormat) |
52 | 0 | { |
53 | 0 | case ExtTimeFieldFormat::Short24H: |
54 | 0 | { |
55 | 0 | m_eTimeFormat = TimeFormat::Hour24; |
56 | 0 | m_bDuration = false; |
57 | 0 | m_eFormat = TimeFieldFormat::F_NONE; |
58 | 0 | } |
59 | 0 | break; |
60 | 0 | case ExtTimeFieldFormat::Long24H: |
61 | 0 | { |
62 | 0 | m_eTimeFormat = TimeFormat::Hour24; |
63 | 0 | m_bDuration = false; |
64 | 0 | m_eFormat = TimeFieldFormat::F_SEC; |
65 | 0 | } |
66 | 0 | break; |
67 | 0 | case ExtTimeFieldFormat::Short12H: |
68 | 0 | { |
69 | 0 | m_eTimeFormat = TimeFormat::Hour12; |
70 | 0 | m_bDuration = false; |
71 | 0 | m_eFormat = TimeFieldFormat::F_NONE; |
72 | 0 | } |
73 | 0 | break; |
74 | 0 | case ExtTimeFieldFormat::Long12H: |
75 | 0 | { |
76 | 0 | m_eTimeFormat = TimeFormat::Hour12; |
77 | 0 | m_bDuration = false; |
78 | 0 | m_eFormat = TimeFieldFormat::F_SEC; |
79 | 0 | } |
80 | 0 | break; |
81 | 0 | case ExtTimeFieldFormat::ShortDuration: |
82 | 0 | { |
83 | 0 | m_bDuration = true; |
84 | 0 | m_eFormat = TimeFieldFormat::F_NONE; |
85 | 0 | } |
86 | 0 | break; |
87 | 0 | case ExtTimeFieldFormat::LongDuration: |
88 | 0 | { |
89 | 0 | m_bDuration = true; |
90 | 0 | m_eFormat = TimeFieldFormat::F_SEC; |
91 | 0 | } |
92 | 0 | break; |
93 | 0 | } |
94 | | |
95 | 0 | ReFormat(); |
96 | 0 | } |
97 | | |
98 | | void TimeFormatter::SetDuration(bool bDuration) |
99 | 0 | { |
100 | 0 | m_bDuration = bDuration; |
101 | 0 | ReFormat(); |
102 | 0 | } |
103 | | |
104 | | void TimeFormatter::SetTimeFormat(TimeFieldFormat eTimeFormat) |
105 | 0 | { |
106 | 0 | m_eFormat = eTimeFormat; |
107 | 0 | ReFormat(); |
108 | 0 | } |
109 | | |
110 | 0 | TimeFormatter::~TimeFormatter() = default; |
111 | | } |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |