Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » first try on a own (simple) widget...
first try on a own (simple) widget... [message #34570] Wed, 30 November 2011 16:04 Go to previous message
Wolfgang is currently offline  Wolfgang
Messages: 146
Registered: November 2011
Location: Germany
Experienced Member
Hi there,

I'm trying myself on a own widget, a input field just for time (HH:MM)... found some piece of code in the forum but nothing fits exactly my needs.

Please note thats really my first try for such a thing..
class TimeInput : public EditString
{
	public:
	Value Format(const Value& q) const
	{
		//TimeInput::setTime(15,7);
		
		String mq = q.ToString();
		String rt = "";
		int sep = mq.Find(':');
		if (sep < 0)
		{ /* no : */
			int x = StrInt(mq);
			if (x < 0 || x > 23) return "00:00";
			if (mq.GetLength() == 1)
			{
				rt << "0" << mq << ":00";
				return rt;
			}
			rt << mq << ":00";
			return rt;
		}
		String x1 = mq.Mid(0,sep);
		String x2 = mq.Mid(sep);
		while ((sep = x1.Find(':')) != -1) x1.Remove(sep);
		while ((sep = x2.Find(':')) != -1) x2.Remove(sep);

		int hrs = StrInt(x1);
		int min = StrInt(x2);
		if (hrs < 0 || hrs > 23) x1 = "00";
		else if (x1.GetLength() == 1) x1.Insert(0,'0');

		if (min < 0 || min > 59)
		{
			rt << x1 << ":00";
			return rt;
		}
		if (x2.GetLength() == 1) x2.Insert(0,'0');
		rt << x1 << ":" << x2;
		return rt;
	}
	int Filter(int chr) const
	{ /* only accept digits and ':' */
		if(IsDigit(chr) || chr == ':') return chr;
		return 0;
	}
	String increaseMin()
	{
		if (++min > 59)
		{
			min = 0;
			if (++hour>23)
			{
				hour = 0;
				return "00:00";
			}
			if (hour < 10)
			{
				String rt = 0;
				rt << hour << ":00";
				return rt;
			}
			String rt;
			rt << hour << ":00";
			return rt;
		}
		String rt;
		if (hour < 10) rt << "0";
		rt << hour << ":";
		if (min < 10) rt << "0";
		rt << min;
		return rt;
	}
	private:
		int min;
		int hour;
		void setTime(int m, int h) { min = m; hour = h; }
};
typedef TimeInput EditTimeHM;


If I uncomment the TimeInput::setTime(15,7); in the Format procedure, it failes to compile.

d:\ultimate++\myapps\countdown\Countdown.h(13) : error C2662: 'TimeInput::setTime' : cannot convert 'this' pointer from 'const TimeInput' to 'TimeInput
	 &'
        Conversion loses qualifiers


please be patient, help and tipps always welcome!
This piece of code (with commented setTime part) compiles and works as I expect it to do..

best regards
Wolfgang
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Own TimeInput widget.... problem with spinbuttons etc.
Next Topic: IMAP?
Goto Forum:
  


Current Time: Sun Jun 02 11:30:11 CEST 2024

Total time taken to generate the page: 0.01800 seconds