PageRenderTime 24ms CodeModel.GetById 11ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/lltimectrl.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 131 lines | 77 code | 29 blank | 25 comment | 0 complexity | 3328ad3d09e5be7d926e4feae01d2d78 MD5 | raw file
  1/**
  2 * @file lltimectrl.h
  3 * @brief Time control
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2011, Linden Research, Inc.
  8 *
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 *
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 *
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 *
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LLTIMECTRL_H_
 28#define LLTIMECTRL_H_
 29
 30#include "stdtypes.h"
 31#include "llbutton.h"
 32#include "v4color.h"
 33#include "llrect.h"
 34
 35class LLLineEditor;
 36
 37class LLTimeCtrl
 38: public LLUICtrl
 39{
 40	LOG_CLASS(LLTimeCtrl);
 41public:
 42	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
 43	{
 44		Optional<S32> label_width;
 45		Optional<S32> snap_to;
 46		Optional<bool> allow_text_entry;
 47
 48		Optional<LLUIColor> text_enabled_color;
 49		Optional<LLUIColor> text_disabled_color;
 50
 51		Optional<LLButton::Params> up_button;
 52		Optional<LLButton::Params> down_button;
 53
 54		Params();
 55	};
 56
 57	F32 getTime24() const;		// 0.0 - 24.0
 58	U32 getHours24() const;		// 0 - 23
 59	U32 getMinutes() const;		// 0 - 59
 60
 61	void setTime24(F32 time);	// 0.0 - 23.98(3)
 62
 63protected:
 64	LLTimeCtrl(const Params&);
 65	friend class LLUICtrlFactory;
 66
 67private:
 68
 69	enum EDayPeriod
 70	{
 71		AM,
 72		PM
 73	};
 74
 75	enum EEditingPart
 76	{
 77		HOURS,
 78		MINUTES,
 79		DAYPART,
 80		NONE
 81	};
 82
 83	virtual void	onFocusLost();
 84	virtual BOOL	handleKeyHere(KEY key, MASK mask);
 85
 86	void	onUpBtn();
 87	void	onDownBtn();
 88	void	onTextEntry(LLLineEditor* line_editor);
 89
 90	bool	isTimeStringValid(const LLWString& wstr);
 91
 92	void increaseMinutes();
 93	void increaseHours();
 94
 95	void decreaseMinutes();
 96	void decreaseHours();
 97
 98	bool isPM() const;
 99	void switchDayPeriod();
100
101	void updateText();
102
103	EEditingPart getEditingPart();
104
105	static std::string getHoursString(const std::string& str);
106	static std::string getMinutesString(const std::string& str);
107	static std::string getAMPMString(const std::string& str);
108
109	static bool isHoursStringValid(const std::string& str);
110	static bool isMinutesStringValid(const std::string& str);
111	static bool isPMAMStringValid(const std::string& str);
112
113	static U32		parseHours(const std::string& str);
114	static U32		parseMinutes(const std::string& str);
115	static bool		parseAMPM(const std::string& str);
116
117	class LLTextBox*	mLabelBox;
118
119	class LLLineEditor*	mEditor;
120	LLUIColor			mTextEnabledColor;
121	LLUIColor			mTextDisabledColor;
122
123	class LLButton*		mUpBtn;
124	class LLButton*		mDownBtn;
125
126	U32				mTime;				// minutes since midnight: 0 - 1439
127	U32				mSnapToMin;			// interval in minutes to snap to
128
129	BOOL			mAllowEdit;
130};
131#endif /* LLTIMECTRL_H_ */