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

📄 datepicker.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 <qtopia/config.h>#include <qtopia/resource.h>#include <qtopia/qpeapplication.h>#include <qtopia/timestring.h>#include <qtopia/global.h>#include <qtoolbutton.h>#include <qdatetime.h>#include <qspinbox.h>#include <qcombobox.h>#include <qlabel.h>#include <qpainter.h>#include <qpopupmenu.h>#include <qwhatsthis.h>#include <qlayout.h>#include <qstyle.h>#include "datepicker.h"#include <qtopia/calendar.h>#ifdef QTOPIA_PHONEextern bool mousePreferred; // can't call Global::mousePreferred in libqtopia2 from libqtopia1#endifclass DatePickerHeader : public QHBox{    Q_OBJECTpublic:    DatePickerHeader( QWidget *parent = 0, const char *name = 0 );    ~DatePickerHeader();    void setDate( int year, int month );signals:    void dateChanged( int year, int month );protected slots:    //void keyPressEvent(QKeyEvent *e ) {	//e->ignore();    //}private slots:    void updateDate();    void firstMonth();    void lastMonth();    void monthBack();    void monthForward();private:#ifndef QTOPIA_PHONE    QToolButton *begin, *back, *next, *end;#endif    QComboBox *month;    QSpinBox *year;    QLabel *currentMonth;    int focus;};class DatePickerTable : public QTable{    Q_OBJECTpublic:    DatePickerTable( QWidget *parent = 0, const char *name = 0);    ~DatePickerTable();    QSize minimumSizeHint() const { return sizeHint(); }    QSize minimumSize() const { return sizeHint(); }    void setWeekStartsMonday( bool monday );    bool weekStartsMonday() const { return onMonday; }    void paintCell(QPainter * p, int row, int col,	    const QRect & cr, bool selected);#ifdef QTOPIA_PHONE    void paintFocus(QPainter *p, const QRect &r);#endif    void updateContents()    {	QScrollView::updateContents(0,0,contentsWidth(), contentsHeight());    }signals:    void clickedPos(int, int);public slots:    void timeStringChanged();protected:    void keyPressEvent( QKeyEvent *e );    QSize sizeHint() const;    void contentsMousePressEvent(QMouseEvent *e)    {	pressedCol = columnAt(e->x());	pressedRow = rowAt(e->y());    }    void contentsMouseReleaseEvent(QMouseEvent *e)    {	int c = columnAt(e->x());	int r = rowAt(e->y());	if (c == pressedCol && r == pressedRow)	    emit clickedPos(r, c);	pressedCol = pressedRow = -1;    }    QWidget *createEditor(int,int,bool) const { return 0; }private:    void setupLabels();    bool onMonday;    int pressedRow, pressedCol;};void DatePickerTable::timeStringChanged(){    setupLabels();}DatePickerHeader::DatePickerHeader( QWidget *parent, const char *name )    : QHBox( parent, name ){    setBackgroundMode( PaletteButton );#ifdef QTOPIA_PHONE    if (!mousePreferred) {	currentMonth = new QLabel(this);	currentMonth->setAlignment(AlignHCenter);    } else {#endif#ifndef QTOPIA_PHONE    begin = new QToolButton( this );    begin->setIconSet( Resource::loadIconSet( "start" ) );    begin->setAutoRaise( TRUE );    begin->setFixedSize( begin->sizeHint() );    QWhatsThis::add( begin, tr("Show January in the selected year") );    back = new QToolButton( this );    back->setIconSet( Resource::loadIconSet( "back" ) );    back->setAutoRaise( TRUE );    back->setFixedSize( back->sizeHint() );    QWhatsThis::add( back, tr("Show the previous month") );#endif    month = new QComboBox( FALSE, this );    for ( int i = 0; i < 12; ++i )	month->insertItem( Calendar::nameOfMonth( i + 1 ) );    // this is almost certainly wrong on the other end.    // date is a uint + 1752 some day.  Thats a lot of days, 11 M years or so.    year = new QSpinBox( 1753, 3000, 1, this );#ifndef QTOPIA_PHONE    next = new QToolButton( this );    next->setIconSet( Resource::loadIconSet( "forward" ) );    next->setAutoRaise( TRUE );    next->setFixedSize( next->sizeHint() );    QWhatsThis::add( next, tr("Show the next month") );    end = new QToolButton( this );    end->setIconSet( Resource::loadIconSet( "finish" ) );    end->setAutoRaise( TRUE );    end->setFixedSize( end->sizeHint() );    QWhatsThis::add( end, tr("Show December in the selected year") );#endif    connect( month, SIGNAL( activated(int) ),	     this, SLOT( updateDate() ) );    connect( year, SIGNAL( valueChanged(int) ),	     this, SLOT( updateDate() ) );#ifndef QTOPIA_PHONE    connect( begin, SIGNAL( clicked() ),	     this, SLOT( firstMonth() ) );    connect( end, SIGNAL( clicked() ),	     this, SLOT( lastMonth() ) );    connect( back, SIGNAL( clicked() ),	     this, SLOT( monthBack() ) );    connect( next, SIGNAL( clicked() ),	     this, SLOT( monthForward() ) );    back->setAutoRepeat( TRUE );    next->setAutoRepeat( TRUE );#endif#ifdef QTOPIA_PHONE    }#endif}DatePickerHeader::~DatePickerHeader(){}void DatePickerHeader::updateDate(){#ifdef QTOPIA_PHONE    if (mousePreferred)#endif    emit dateChanged( year->value(), month->currentItem() + 1 );}void DatePickerHeader::firstMonth(){#ifdef QTOPIA_PHONE    if (mousePreferred)#endif	emit dateChanged( year->value(), 1 );}void DatePickerHeader::lastMonth(){#ifdef QTOPIA_PHONE    if (mousePreferred)#endif	emit dateChanged( year->value(), 12 );}// don't set values.. this will be done on the return hit from monthview.void DatePickerHeader::monthBack(){#ifdef QTOPIA_PHONE    if (mousePreferred) {#endif	if ( month->currentItem() > 0 ) {	    emit dateChanged( year->value(), month->currentItem() );	} else {	    emit dateChanged( year->value() - 1, 12 );	}#ifdef QTOPIA_PHONE    }#endif}void DatePickerHeader::monthForward(){#ifdef QTOPIA_PHONE    if (mousePreferred) {#endif	if ( month->currentItem() < 11 ) {	    emit dateChanged( year->value(), month->currentItem() + 2 );	} else {	    emit dateChanged( year->value() + 1, 1);	}#ifdef QTOPIA_PHONE    }#endif}void DatePickerHeader::setDate( int y, int m ){#ifdef QTOPIA_PHONE    if (!mousePreferred) {	currentMonth->setText(		tr( QString("%1 %2").arg(Calendar::nameOfMonth( m )).arg(y),		    "Header for monthview in phone, 1=month name (full), 2=year" ));    } else {#endif    blockSignals(TRUE);    year->setValue( y );    month->setCurrentItem( m - 1 );    blockSignals(FALSE);#ifdef QTOPIA_PHONE    }#endif}//---------------------------------------------------------------------------DatePickerTable::DatePickerTable( QWidget *parent, const char *name)    : QTable( 6, 7, parent, name ){    pressedRow = pressedCol = -1;    Config cfg( "qpe" );    cfg.setGroup( "Time" );    onMonday = cfg.readBoolEntry( "MONDAY" );    horizontalHeader()->setResizeEnabled( FALSE );    // we have to do this here... or suffer the consequences later...    int i;    for ( i = 0; i < 7; i++ ){	// 30 should be replaced with something dependent	// on size needed to show label text.	horizontalHeader()->resizeSection( i, 30 );	setColumnStretchable( i, TRUE );    }    setupLabels();    verticalHeader()->hide();    setLeftMargin( 0 );    for ( i = 0; i < 6; ++i )	    setRowStretchable( i, TRUE );    setSelectionMode( NoSelection );    setVScrollBarMode( AlwaysOff );    setHScrollBarMode( AlwaysOff );}DatePickerTable::~DatePickerTable(){}QSize DatePickerTable::sizeHint() const{    return QSize( columnWidth(0) * 7 + 4, rowHeight(0)*6 + horizontalHeader()->sizeHint().height());}void DatePickerTable::setWeekStartsMonday( bool monday ){    onMonday = monday;    setupLabels();}void DatePickerTable::paintCell(QPainter * p, int row, int col,	const QRect & cr, bool selected){#if defined(Q_WS_WIN)    const QColorGroup &cg = ( style().styleHint( QStyle::SH_ItemView_ChangeHighlightOnFocus ) ? palette().inactive() : colorGroup() );#else    const QColorGroup &cg = colorGroup();#endif    ((QPEDatePicker *)parentWidget())->paintCell(row, col, p, cr, selected, cg);#ifdef QTOPIA_DESKTOP    if ( currentRow() == row && currentColumn() == col ) {	p->drawRect( 0, 0, cr.width()-1, cr.height()-1 );    }

⌨️ 快捷键说明

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