📄 datetimeedit.cpp
字号:
\fn bool QPEDateEdit::longFormat() const; Returns TRUE if dates are displayed in long format. \sa setLongFormat(), setDateFormat()*//*! Constructs QPEDateEdit with the current date selected. If \a longDate is TRUE the push button will show the selected date in long format. If \a allowNullDate is TRUE it is possible to select no date. The \a parent and \a name parameters are the standard Qt parent parameters.*/QPEDateEdit::QPEDateEdit( QWidget *parent, const char * name, bool longDate, bool allowNullDate ) :QPushButton( parent, name ), longFmt(longDate), mAllowNullButton(allowNullDate), d(0){ df = TimeString::currentDateFormat(); noneButton = 0; init(); setLongFormat(longDate); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(setWeekStartsMonday(bool)) );}/*! Constructs QPEDateEdit with the date \a dt. If \a longDate is TRUE the push button will show the selected date in long format. If \a allowNullDate is TRUE it is possible to select no date. The \a parent and \a name parameters are the standard Qt parent parameters.*/QPEDateEdit::QPEDateEdit( const QDate &dt, QWidget *parent, const char * name, bool longDate, bool allowNullDate ) :QPushButton( parent, name ), longFmt(longDate), mAllowNullButton(allowNullDate), d(0){ currDate = dt; noneButton = 0; init(); setLongFormat(longDate);}/*! \internal*/void QPEDateEdit::clockChanged(){ df = TimeString::currentDateFormat(); updateButtonText();}/*! If \a l is TRUE, display the date in long format. \sa longFormat(), setDateFormat()*/void QPEDateEdit::setLongFormat( bool l ){ longFmt = l; updateButtonText();}//// Ensure the date is changed when the popup is hidden. This catches// changes of year in QPEDatePicker without altering it's behaviour// (ie. date displayed in the pushbutton only changes when the monthview// is hidden).//void QPEDateEdit::hidingMonthView(void){ setDate(d->popup->selectedDate());}QPEDatePickerPopup::QPEDatePickerPopup( bool showNullButton, QWidget *parent, const char *name, int wflags) : QFrame(parent, name, WType_Popup#ifdef QTOPIA_PHONE | WStyle_NormalBorder#endif | wflags), mShowNull(showNullButton), monthView(0), nullButton(0), wsm(FALSE){ setFocusPolicy(NoFocus);#ifdef QTOPIA_PHONE setCaption(tr("Select Date")); ContextBar::setLabel(this, Key_Back, ContextBar::Cancel); setFrameStyle(NoFrame);#else setFrameStyle(StyledPanel | Raised);#endif}QDate QPEDatePickerPopup::selectedDate() const{ if (monthView) return monthView->selectedDate(); return mdt;}void QPEDatePickerPopup::setDate(const QDate &dt){ mdt = dt; if (monthView) monthView->setDate(dt);}void QPEDatePickerPopup::passOnNullDate(){ emit dateClicked(QDate());}void QPEDatePickerPopup::setWeekStartsMonday(bool b){ wsm = b; if (monthView) monthView->setWeekStartsMonday(b);}void QPEDatePickerPopup::keyPressEvent( QKeyEvent *e ){#ifdef QTOPIA_PHONE if (e->key() == Key_Back || e->key() == Key_No) { e->accept(); close(); }#else Q_UNUSED(*e);#endif}void QPEDatePickerPopup::closeEvent( QCloseEvent *e ){ e->accept(); if (!parentWidget()) return; // remember that we (as a popup) might recieve the mouse release // event instead of the popupParent. This is due to the fact that // the popupParent popped us up in its mousePressEvent handler. To // avoid the button remaining in pressed state we simply send a // faked mouse button release event to it. QMouseEvent me( QEvent::MouseButtonRelease, QPoint(0,0), QPoint(0,0), QMouseEvent::LeftButton, QMouseEvent::NoButton); QApplication::sendEvent( parentWidget(), &me );}void QPEDatePickerPopup::popup(){ populate();#ifndef Q_WS_QWS QRect qt_maxWindowRect = qApp->desktop()->geometry();#endif#ifdef QTOPIA_PHONE showMaximized(); monthView->setFocus(); if( !mousePreferred ) monthView->setModalEditing(TRUE);#else // base of parents geometry. QWidget *p = parentWidget(); if (p) { //want to show just above, or just below, //want to show fully inside window rect. // which is greater width, above or below. QRect pg(p->mapToGlobal(QPoint(0,0)), p->size()); QRect geo; geo.setSize(QSize(sizeHint().width()+2*frameWidth(), sizeHint().height()+2*frameWidth())); if (pg.y() > qt_maxWindowRect.height() - (pg.y() + pg.height())) { // above, geo.moveTopLeft( QPoint(QMIN(pg.x(), qt_maxWindowRect.width() - geo.width()), QMAX(qt_maxWindowRect.y(), pg.y() - geo.height()))); } else {// // below. geo.moveTopLeft(QPoint(QMIN(pg.x(), qt_maxWindowRect.width() - geo.width()), QMIN(qt_maxWindowRect.height() - geo.height(), pg.bottom() ))); } setGeometry(geo); } else { // um.... full screen? setGeometry(qt_maxWindowRect); }#endif show();}void QPEDatePickerPopup::populate(){ if (!monthView) { QVBoxLayout *vbl = new QVBoxLayout(this); vbl->setMargin(frameWidth()); monthView = new QPEDatePicker(this); connect(monthView, SIGNAL(dateClicked(const QDate &)), this, SIGNAL(dateClicked(const QDate &))); connect(monthView, SIGNAL(dateClicked(const QDate &)), this, SLOT(close())); vbl->addWidget(monthView); if (mdt.isValid()) monthView->setDate(mdt); else monthView->setDate(QDate::currentDate()); monthView->setWeekStartsMonday(wsm); if (mShowNull) { nullButton = new QPushButton(tr("None", "no date selected"), this); connect(nullButton, SIGNAL( clicked() ), this, SLOT(passOnNullDate())); connect(nullButton, SIGNAL( clicked() ), this, SLOT(close())); vbl->addWidget(nullButton); } }}void QPEDateEdit::init(){ d = new QPEDateEditPrivate(); d->popup = new QPEDatePickerPopup( mAllowNullButton, this ); connect(this, SIGNAL(pressed()), d->popup, SLOT(popup())); connect( d->popup, SIGNAL( dateClicked(const QDate&) ), this, SLOT( setDate(const QDate&) ) ); connect( d->popup, SIGNAL( dateClicked(const QDate&) ), this, SIGNAL( valueChanged(const QDate&) ) ); TimeString::connectChange(this,SLOT(clockChanged())); // This is the size policy for the button, not the popup setSizePolicy( QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed) ); { Config config( "qpe" ); config.setGroup("Time"); bool onMonday = config.readBoolEntry( "MONDAY" ); setWeekStartsMonday( onMonday ); } connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(setWeekStartsMonday(bool)) );}/*! Returns TRUE if it is possible to select a null date.*/bool QPEDateEdit::allowNullDate() const{ return mAllowNullButton;}/*! Display the calendar with weeks starting on Monday if \a startMonday is TRUE, otherwise weeks start with Sunday.*/void QPEDateEdit::setWeekStartsMonday( bool startMonday ){ weekStartsMonday = startMonday; d->popup->setWeekStartsMonday( weekStartsMonday );}void QPEDateEdit::setNull(){ d->popup->close(); setDate( QDate() ); emit valueChanged( QDate() );}void QPEDateEdit::updateButtonText(){ if ( currDate.isValid() ) {#ifdef QTOPIA_PHONE setText( TimeString::shortDate(currDate,df) );#else setText( longFmt ? TimeString::longDateString(currDate,df) : TimeString::dateString(currDate,df) );#endif d->popup->setDate( currDate ); } else { setText( tr("None", "no date selected") ); }}/*! Return the currently selected date.*/QDate QPEDateEdit::date() const{ return currDate;}/*! Set the current date to \a d.*/void QPEDateEdit::setDate( const QDate &d ){ if (isDown()) setDown(FALSE); if ( d != currDate ) { currDate = d; updateButtonText(); }}/*! Set the long date format to \a format. \sa setLongFormat()*/void QPEDateEdit::setDateFormat( DateFormat format ){ df = format; updateButtonText();}/*=====================================*//*! \class QPEDateTimeEdit datetimeedit.h \brief The QPEDateTimeEdit class provides a compact widget for selecting a date and time. QPEDateTimeEdit displays a QPEDateEdit and QPETimeEdit above each other. \ingroup qtopiaemb*//*! \fn QPEDateTimeEdit::valueChanged( const QDateTime &dt ); This signal is emitted when the date or time is changed to \a dt.*//*! Constructs a QPEDateTimeEdit with the date set to today and the time set to 00:00. The \a parent and \a name parameters are the standard Qt parent parameters.*/QPEDateTimeEdit::QPEDateTimeEdit( QWidget *parent, const char *name) : QHBox(parent, name){ de = new QPEDateEdit(this, "date"); // No tr te = new QPETimeEdit(this, "time"); // No tr connect(de, SIGNAL(valueChanged(const QDate&)), this, SLOT(setDate(const QDate&))); connect(te, SIGNAL(valueChanged(const QTime&)), this, SLOT(setTime(const QTime&)));}/*! Constructs QPEDateTimeEdit with the date and time \a dt. The \a parent and \a name parameters are the standard Qt parent parameters.*/QPEDateTimeEdit::QPEDateTimeEdit( const QDateTime &dt, QWidget *parent, const char *name ) : QHBox(parent, name){ de = new QPEDateEdit(dt.date(), this, "date"); // No tr te = new QPETimeEdit(dt.time(), this, "time"); // No tr connect(de, SIGNAL(valueChanged(const QDate&)), this, SLOT(setDate(const QDate&))); connect(te, SIGNAL(valueChanged(const QTime&)), this, SLOT(setTime(const QTime&)));}/*! Destructs QPEDateTimeEdit.*/QPEDateTimeEdit::~QPEDateTimeEdit() {}/*! Sets the current date to \a dt. \sa setDateTime()*/void QPEDateTimeEdit::setDate( const QDate &dt ){ de->setDate(dt); emit valueChanged(dateTime());}/*! Sets the current time to \a dt. \sa setDateTime()*/void QPEDateTimeEdit::setTime( const QTime &dt ){ te->setTime(dt); emit valueChanged(dateTime());}/*! Sets the current date and time to \a dt. \sa setDate(), setTime()*/void QPEDateTimeEdit::setDateTime( const QDateTime &dt ){ de->setDate(dt.date()); te->setTime(dt.time()); emit valueChanged(dateTime());}/*! Returns the currently selected date.*/QDate QPEDateTimeEdit::date() const{ return de->date();}/*! Returns the currently selected time.*/QTime QPEDateTimeEdit::time() const{ return te->time();}/*! Returns the currently selected date and time.*/QDateTime QPEDateTimeEdit::dateTime() const{ return QDateTime(de->date(), te->time());}/*! Enables changing the date if \a b is TRUE, otherwise disables input. \sa dateIsEnabled(), setTimeEnabled()*/void QPEDateTimeEdit::setDateEnabled(bool b){ de->setEnabled(b);}/*! Enables changing the time if \a b is TRUE, otherwise disables input. \sa timeIsEnabled(), setDateEnabled()*/void QPEDateTimeEdit::setTimeEnabled(bool b){ te->setEnabled(b);}/*! Returns TRUE if changing the date is enabled, otherwise FALSE. \sa setDateEnabled()*/bool QPEDateTimeEdit::dateIsEnabled() const{ return de->isEnabled();}/*! Returns TRUE if changing the time is enabled, otherwise FALSE. \sa setTimeEnabled()*/bool QPEDateTimeEdit::timeIsEnabled() const{ return te->isEnabled();}#include "datetimeedit.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -