📄 repeatentry.cpp
字号:
/************************************************************************ Copyright (C) 2000-2002 Trolltech AS. All rights reserved.**** This file is part of the Qtopia Environment.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** 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 <qdatetime.h>#include <qlabel.h>#include <qwidgetstack.h>#include <qtoolbutton.h>#include <qradiobutton.h>#include <qlayout.h>#include <qsimplerichtext.h>#include <qpainter.h>int 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 }};class WeekGroup : public QButtonGroup{ Q_OBJECTpublic: WeekGroup(int oM, QWidget *parent = 0); ~WeekGroup() {} void toggleDay(int, bool);public slots: void setStartOnMonday(bool b);signals: void dayToggled(int, bool);private slots: void setDay(int);private: //int firstDayOfWeek; QToolButton *first; QToolButton *last;};WeekGroup::WeekGroup(int oM, QWidget *parent) : QButtonGroup(QString("Repeat On"), parent){ setColumnLayout(0, Qt::Vertical); layout()->setSpacing(0); layout()->setMargin(0); QHBoxLayout *fe = new QHBoxLayout(layout()); fe->setAlignment( Qt::AlignTop ); fe->setSpacing(0); fe->setMargin(6); setExclusive(FALSE); layout()->setSpacing(0); /* first = new QToolButton(this); first->setText(tr("Sun")); first->setToggleButton(TRUE); fe->addWidget(first); */ QToolButton *b1; for (int i = 0; i < 7; i++) { b1 = new QToolButton(this); b1->setToggleButton(TRUE); if (!i) { b1->setEnabled(FALSE); //b1->setOn(TRUE); } b1->setText(Calendar::nameOfDay(oM)); insert(b1, oM); fe->addWidget(b1); oM++; if (oM > 7) oM = 1; b1->setFocusPolicy(QWidget::StrongFocus); } /* QToolButton *b1 = new QToolButton(this); b1->setText(tr("Mon")); b1->setToggleButton(TRUE); fe->addWidget(b1); b1 = new QToolButton(this); b1->setText(tr("Tue")); b1->setToggleButton(TRUE); fe->addWidget(b1); b1 = new QToolButton(this); b1->setText(tr("Wed")); b1->setToggleButton(TRUE); fe->addWidget(b1); b1 = new QToolButton(this); b1->setText(tr("Thu")); b1->setToggleButton(TRUE); fe->addWidget(b1); b1 = new QToolButton(this); b1->setText(tr("Fri")); b1->setToggleButton(TRUE); fe->addWidget(b1); b1 = new QToolButton(this); b1->setText(tr("Sat")); b1->setToggleButton(TRUE); fe->addWidget(b1); last = new QToolButton(this); last->setText(tr("Sun")); last->setToggleButton(TRUE); fe->addWidget(last); if (onMonday) first->hide(); else last->hide();*/ 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); //} }}QString RepeatEntry::trSmallOrdinal(int n) const{ if ( n == 1 ) return tr("first","eg. first Friday of month"); else if ( n == 2 ) return tr("second"); else if ( n == 3 ) return tr("third"); else if ( n == 4 ) return tr("fourth"); else if ( n == 5 ) return tr("fifth"); else return QString::number(n);}RepeatEntry::RepeatEntry( bool /* startOnMonday */, const PimEvent &rp, QWidget *parent, const char *name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl), mEvent(rp){ setCaption(tr("Repeating Event")); // RepeatType QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(6); layout->setSpacing(6); QHBoxLayout *buttonLayout = new QHBoxLayout(layout); buttonLayout->setSpacing(0); typeSelector = new QButtonGroup(this); typeSelector->hide(); typeSelector->setExclusive(TRUE); QPushButton *pb = new QPushButton(tr("Day","Day, not date"), this); pb->setToggleButton(TRUE); pb->setFocusPolicy(StrongFocus); pb->setAutoDefault(FALSE); buttonLayout->addWidget(pb); typeSelector->insert(pb, 0); pb = new QPushButton(tr("Week"), this); pb->setToggleButton(TRUE); pb->setFocusPolicy(StrongFocus); pb->setAutoDefault(FALSE); buttonLayout->addWidget(pb); typeSelector->insert(pb, 1); pb = new QPushButton(tr("Month"), this); pb->setToggleButton(TRUE); buttonLayout->addWidget(pb); pb->setFocusPolicy(StrongFocus); pb->setAutoDefault(FALSE); typeSelector->insert(pb, 2); pb = new QPushButton(tr("Year"), this); pb->setToggleButton(TRUE); pb->setFocusPolicy(StrongFocus); pb->setAutoDefault(FALSE); buttonLayout->addWidget(pb); typeSelector->insert(pb, 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); QWidget *freqBox = new QWidget(fStack); QVBoxLayout *subLayout = new QVBoxLayout(freqBox); QHBoxLayout *subLayout2 = new QHBoxLayout(subLayout); subLayout2->setSpacing(6); 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(), subStack); subStack->addWidget(weekGroup, 1); monthGroup = new QVButtonGroup(tr("Repeat On"), subStack); monthGroup->setExclusive(TRUE); 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::Long));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -