⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 repeatentry.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "repeatentry.h"#include <qtopia/datepicker.h>#include <qtopia/calendar.h>#include <qtopia/qpeapplication.h>#include <qtabbar.h>#include <qspinbox.h>#include <qcheckbox.h>#include <qhbuttongroup.h>#include <qvbuttongroup.h>#include <qtoolbutton.h>#include <qdatetime.h>#include <qlabel.h>#include <qwidgetstack.h>#include <qradiobutton.h>#include <qlayout.h>#include <qsimplerichtext.h>#include <qpainter.h>#include <qfocusdata.h>#ifdef QTOPIA_PHONEstatic const TimeString::Length TIMESTRING_LENGTH = TimeString::Medium;#elsestatic const TimeString::Length TIMESTRING_LENGTH = TimeString::Long;#endifint currentID( QButtonGroup *group ){    for (int i = 0; i < group->count(); i++) {	if (group->find(i)->isOn())	    return i;    }    return -1;}class RichLabel : public QLabel{public:    RichLabel(QWidget *p) : QLabel(p) { }protected:    void drawContents(QPainter *p)    {	QSimpleRichText rt(text(), p->font());	rt.setWidth(width());#if (QT_VERSION-0 >= 0x030000)	rt.draw(p, pos().x(),pos().y(), geometry(), colorGroup());#else	rt.draw(p, 0,0, QRegion(geometry()), palette());#endif    }};static void nextButton( QWidget **btns, int size, bool prev = FALSE ){    int move = 1;    if ( prev )	move = size - 1;    for ( int i = 0; i < size; i++ ) {	if ( btns[i]->hasFocus() ) {	    int index = i;	    do {		index = (index + move) % size;	    } while ( !btns[index]->isEnabled() );	    btns[index]->setFocus();	    break;	}    }}// ====================================================================class WeekGroup : public QButtonGroup{    Q_OBJECTpublic:    WeekGroup(int dayOfWeek, bool startOnMonday, QWidget *parent = 0);    ~WeekGroup() {}    void toggleDay(int, bool);public slots:    void setStartOnMonday(bool b);signals:    void dayToggled(int, bool);protected:    void keyPressEvent( QKeyEvent *e );private slots:    void setDay(int);private:    QToolButton *dayBtn[7];};// ====================================================================WeekGroup::WeekGroup(int dayOfWeek, bool startOnMonday, QWidget *parent)    : QButtonGroup(tr("Repeat On"), parent){    setColumnLayout(0, Qt::Vertical);    layout()->setSpacing(0);    layout()->setMargin(0);    setExclusive(FALSE);    layout()->setSpacing(0);    QHBoxLayout *fe = new QHBoxLayout(layout());    fe->setAlignment( Qt::AlignTop );    fe->setSpacing(0);    fe->setMargin(6);    TimeString::Length len = TimeString::Short;    int approxSize = QFontMetrics(QFont()).width(" Wed ") * 7;    if ( QApplication::desktop()->width() > approxSize )	len = TimeString::Medium;    int j = 0;    if ( !startOnMonday )	j = 6;    for (int i = 0; i <= 6; i++) {	dayBtn[i] = new QToolButton(this);	dayBtn[i]->setToggleButton(TRUE);	if ( j == (dayOfWeek - 1) ) {	    dayBtn[i]->setEnabled(FALSE);	    //b1->setOn(TRUE);	}	dayBtn[i]->setText(TimeString::localDayOfWeek(j + 1, len));	insert(dayBtn[i], j + 1);	fe->addWidget(dayBtn[i]);	dayBtn[i]->setFocusPolicy(QWidget::StrongFocus);	if ( ++j == 7 )	    j = 0;    }    connect(this, SIGNAL(clicked(int)), this, SLOT(setDay(int)));}void WeekGroup::setStartOnMonday(bool /* b */){    /*    if (onMonday == b)	return;    onMonday = b;    if (onMonday) {	first->hide();	last->show();    } else {	last->hide();	first->show();    }    */}void WeekGroup::toggleDay(int i, bool b){    /*    if (i < 1 || i > 6) {	// toggle sundays;	first->setOn(b);	last->setOn(b);    } else {    */	if (find(i))	    ((QToolButton *)find(i))->setOn(b);    //}}// internalvoid WeekGroup::setDay(int i){    QToolButton *bt = (QToolButton *)find(i);    if (bt) {	bool on = bt->isOn();	/*	if (i < 1 || i > 6) {	    first->setOn(on);	    last->setOn(on);	    emit dayToggled(7, on);	} else {	*/	    emit dayToggled(i, on);	//}    }}void WeekGroup::keyPressEvent( QKeyEvent *e ){    //qDebug( "key %d (up %d, down %d)", e->key(), Key_Up, Key_Down );#ifdef QTOPIA_PHONE    switch ( e->key() ) {	case Key_Left:	    nextButton( (QWidget**)dayBtn, 7, TRUE );	    break;	case Key_Right:	    nextButton( (QWidget**)dayBtn, 7 );	    break;	default:	    QButtonGroup::keyPressEvent( e );	    break;    }#else    QButtonGroup::keyPressEvent( e );#endif}// ====================================================================RepeatEntry::RepeatEntry( bool startOnMonday, const PimEvent &rp,	QWidget *parent, const char *name, bool modal, WFlags fl)    : QDialog(parent, "event-repeat", modal, fl), mEvent(rp){    Q_UNUSED( name );#ifdef QTOPIA_PHONE    setCaption(tr("Repeat"));#else    setCaption(tr("Repeating Event"));#endif    // RepeatType    QVBoxLayout *layout = new QVBoxLayout(this);#ifdef QTOPIA_PHONE    layout->setMargin(0);    layout->setSpacing(0);#else    layout->setMargin(6);    layout->setSpacing(6);#endif    QHBoxLayout *buttonLayout = new QHBoxLayout(layout);    buttonLayout->setSpacing(0);    typeSelector = new QButtonGroup(this);    typeSelector->hide();    typeSelector->setExclusive(TRUE);    typeBtn[0] = new QPushButton(tr("Day","Day, not date"), this);    typeBtn[0]->setToggleButton(TRUE);    typeBtn[0]->setFocusPolicy(StrongFocus);    typeBtn[0]->setAutoDefault(FALSE);    buttonLayout->addWidget(typeBtn[0]);    typeSelector->insert(typeBtn[0], 0);    typeBtn[1] = new QPushButton(tr("Week"), this);    typeBtn[1]->setToggleButton(TRUE);    typeBtn[1]->setFocusPolicy(StrongFocus);    typeBtn[1]->setAutoDefault(FALSE);    buttonLayout->addWidget(typeBtn[1]);    typeSelector->insert(typeBtn[1], 1);    typeBtn[2] = new QPushButton(tr("Month"), this);    typeBtn[2]->setToggleButton(TRUE);    typeBtn[2]->setFocusPolicy(StrongFocus);    typeBtn[2]->setAutoDefault(FALSE);    buttonLayout->addWidget(typeBtn[2]);    typeSelector->insert(typeBtn[2], 2);    typeBtn[3] = new QPushButton(tr("Year"), this);    typeBtn[3]->setToggleButton(TRUE);    typeBtn[3]->setFocusPolicy(StrongFocus);    typeBtn[3]->setAutoDefault(FALSE);    buttonLayout->addWidget(typeBtn[3]);    typeSelector->insert(typeBtn[3], 3);    switch(mEvent.repeatType()) {	case PimEvent::NoRepeat:	case PimEvent::Daily:	    typeSelector->find(0)->toggle();	    break;	case PimEvent::Weekly:	    typeSelector->find(1)->toggle();	    break;	case PimEvent::MonthlyDate:	case PimEvent::MonthlyDay:	case PimEvent::MonthlyEndDay:	    typeSelector->find(2)->toggle();	    break;	case PimEvent::Yearly:	    typeSelector->find(3)->toggle();	    break;    }    layout->addWidget(typeSelector);    // Frequency and end date    fStack = new QWidgetStack(this);    fStack->addWidget(new QWidget(fStack), 0);#ifdef QTOPIA_PHONE    fStack->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding));#endif    QWidget *freqBox = new QWidget(fStack);    QVBoxLayout *subLayout = new QVBoxLayout(freqBox);    QHBoxLayout *subLayout2 = new QHBoxLayout(subLayout);#ifndef QTOPIA_PHONE    subLayout2->setSpacing(6);#endif    everyLabel = new QLabel("", freqBox);    subLayout2->addWidget(everyLabel);    everyLabel->setAlignment(AlignRight|AlignVCenter);    freqSelector = new QSpinBox(freqBox);    freqSelector->setMinValue(1);    subLayout2->addWidget(freqSelector);    typeLabel = new QLabel(freqBox);    subLayout2->addWidget(typeLabel);    freqSelector->setValue(mEvent.frequency());    freqSelector->setValue(mEvent.frequency());    /*    endSelect->setDate(mEvent.repeatTill());    if (mEvent.hasRepeat()) {	endSelect->setEnabled(!mEvent.repeatForever());	hasEndCheck->setChecked(mEvent.repeatForever());    } else {	endSelect->setEnabled(FALSE);	hasEndCheck->setChecked(TRUE);    }    */    fStack->addWidget(freqBox, 1);    layout->addWidget(fStack);    // Now for the day select/ month type select part    subStack = new QWidgetStack(this);    subStack->addWidget(new QWidget(subStack), 0);    weekGroup = new WeekGroup(mEvent.start().date().dayOfWeek(), startOnMonday, subStack);    subStack->addWidget(weekGroup, 1);    monthGroup = new QVButtonGroup(tr("Repeat On"), subStack);    monthGroup->setExclusive(TRUE);#ifdef QTOPIA_PHONE    monthGroup->layout()->setSpacing(0);    monthGroup->layout()->setMargin(6);#endif    QString strEndWeekDay1 = tr("the last %1.","eg. %1 = Friday");    strEndWeekDay = tr("the %1 last %2.","eg. %1 last %2 = 2nd last Friday");    strDate = tr("day %1 of the month.","eg. %1 = 3")	.arg(mEvent.start().date().day());    strWeekDay = tr("the %1 %2.","eg. %1 %2 = 2nd Friday")	.arg(trSmallOrdinal(		    Calendar::weekInMonth(mEvent.start().date())))	.arg(TimeString::localDayOfWeek(mEvent.start().date(), TIMESTRING_LENGTH));    int fromEndOfWeek = mEvent.start().date().daysInMonth()	- mEvent.start().date().day();    fromEndOfWeek = fromEndOfWeek > 0 ? fromEndOfWeek / 7 + 1 : 1;    strEndWeekDay =	((fromEndOfWeek > 1)	    ? strEndWeekDay.arg( trSmallOrdinal(fromEndOfWeek) )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -