Пример #1
0
/******************************************************************************
*  Initialise the controls with a specified time period.
*  The time unit combo-box is initialised to 'defaultUnits', but if 'dateOnly'
*  is true, it will never be initialised to minutes or hours/minutes.
*/
void TimePeriod::setPeriod(const Duration& perod, bool dateOnly, TimePeriod::Units defaultUnits)
{
	Duration oldinterval = period();
	if (!dateOnly  &&  mNoHourMinute)
		dateOnly = true;
	int item;
	if (perod)
	{
		int count = perod.value();
		if (perod.isDaily())
		{
			if (count % 7)
				item = Days;
			else
			{
				item = Weeks;
				count /= 7;
			}
		}
		else
		{
			count /= 60;   // minutes
			item = (defaultUnits == Minutes && count <= mSpinBox->maximum()) ? Minutes : HoursMinutes;
		}
		if (item < mDateOnlyOffset)
			item = mDateOnlyOffset;
		else if (item > mMaxUnitShown)
			item = mMaxUnitShown;
		mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
		if (item == HoursMinutes)
			mTimeSpinBox->setValue(count);
		else
			mSpinBox->setValue(count);
		item = setDateOnly(perod, dateOnly, false);
	}
	else
	{
		item = defaultUnits;
		if (item < mDateOnlyOffset)
			item = mDateOnlyOffset;
		else if (item > mMaxUnitShown)
			item = mMaxUnitShown;
		mUnitsCombo->setCurrentIndex(item - mDateOnlyOffset);
		if ((dateOnly && !mDateOnlyOffset)  ||  (!dateOnly && mDateOnlyOffset))
			item = setDateOnly(perod, dateOnly, false);
	}
	setUnitRange();
	showHourMin(item == HoursMinutes  &&  !mNoHourMinute);

	Duration newinterval = period();
	if (newinterval != oldinterval)
		emit valueChanged(newinterval);
}
Пример #2
0
Period::Period( const KDateTime &start, const Duration &duration )
  : d( new KCalCore::Period::Private( start, duration.end( start ), true ) )
{
  d->mDailyDuration = duration.isDaily();
}