-rw-r--r-- | core/pim/datebook/datebookday.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/core/pim/datebook/datebookday.cpp b/core/pim/datebook/datebookday.cpp index f4008e9..4d64099 100644 --- a/core/pim/datebook/datebookday.cpp +++ b/core/pim/datebook/datebookday.cpp @@ -1,270 +1,270 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of 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 <qmessagebox.h> #include "datebookday.h" #include "datebookdayheaderimpl.h" #include "datebookdayallday.h" -#include <qpe/datebookdb.h> #include <qpe/resource.h> -#include <qpe/event.h> #include <qpe/qpeapplication.h> -#include <qpe/timestring.h> -#include <qpe/qpedebug.h> #include <qpe/ir.h> -#include <qheader.h> -#include <qdatetime.h> -#include <qpainter.h> #include <qsimplerichtext.h> #include <qpopupmenu.h> -#include <qtextcodec.h> -#include <qpalette.h> -#include <qlineedit.h> #include <qtimer.h> DateBookDayView::DateBookDayView( bool whichClock, QWidget *parent, const char *name ) : QTable( 24, 1, parent, name ), ampm( whichClock ), currDate( QDate::currentDate() ) { enableClipper(TRUE); setTopMargin( 0 ); horizontalHeader()->hide(); setLeftMargin(38); setColumnStretchable( 0, TRUE ); setHScrollBarMode( QScrollView::AlwaysOff ); verticalHeader()->setPalette(white); verticalHeader()->setResizeEnabled(FALSE); setSelectionMode( Single ); // get rid of being able to edit things... QTableItem *tmp; int row; for ( row = 0; row < numRows(); row++ ) { tmp = new QTableItem( this, QTableItem::Never, QString::null); setItem( row, 0, tmp ); //setRowHeight( row, 40); } initHeader(); QObject::connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(slotChangeClock(bool)) ); } void DateBookDayView::initHeader() { QString strTmp; + int preferredWidth = 0; for ( int i = 0; i < 24; ++i ) { if ( ampm ) { if ( i == 0 ) strTmp = QString::number(12) + ":00"; else if ( i == 12 ) strTmp = QString::number(12) + tr(":00p"); else if ( i > 12 ) strTmp = QString::number( i - 12 ) + tr(":00p"); else strTmp = QString::number(i) + ":00"; } else { if ( i < 10 ) strTmp = "0" + QString::number(i) + ":00"; else strTmp = QString::number(i) + ":00"; } strTmp = strTmp.rightJustify( 6, ' ' ); verticalHeader()->setLabel( i, strTmp ); + + // Compute correct width for current Font (Add some space right) + int actWidth = QFontMetrics( QFont::defaultFont() ).width( strTmp + QString(" ") ); + if ( preferredWidth < actWidth ) + preferredWidth = actWidth; setRowStretchable( i, FALSE ); } + + // It seems as if the header has a bug. It does not resize + // correct horizontally if it is used vertical.. + // Thus, we do it manually.. + setLeftMargin( preferredWidth ); } void DateBookDayView::slotDateChanged( int y, int m, int d ) { currDate.setYMD(y,m,d); } void DateBookDayView::slotChangeClock( bool newClock ) { ampm = newClock; initHeader(); } bool DateBookDayView::whichClock() const { return ampm; } void DateBookDayView::moveUp() { scrollBy(0, -20); } void DateBookDayView::moveDown() { scrollBy(0, 20); } void DateBookDayView::paintCell( QPainter *p, int, int, const QRect &cr, bool ) { int w = cr.width(); int h = cr.height(); p->fillRect( 0, 0, w, h, colorGroup().brush( QColorGroup::Base ) ); if ( showGrid() ) { // Draw our lines int x2 = w - 1; int y2 = h - 1; QPen pen( p->pen() ); p->setPen( colorGroup().dark() ); p->drawLine( x2, 0, x2, y2 ); p->drawLine( 0, y2, x2, y2 ); p->setPen( colorGroup().midlight() ); p->drawLine( 0, y2 - h/2, x2, y2 - h/2); p->setPen( pen ); } } void DateBookDayView::paintFocus( QPainter *, const QRect & ) { } void DateBookDayView::resizeEvent( QResizeEvent *e ) { QTable::resizeEvent( e ); columnWidthChanged( 0 ); emit sigColWidthChanged(); } void DateBookDayView::keyPressEvent( QKeyEvent *e ) { QString txt = e->text(); if ( !txt.isNull() && txt[0] > ' ' && e->key() < 0x1000 ) { // we this is some sort of thing we know about... e->accept(); emit sigCapturedKey( txt ); } else { // I don't know what this key is, do you? e->ignore(); } } void DateBookDayView::setRowStyle( int style ) { if (style<0) style = 0; for (int i=0; i<numRows(); i++) setRowHeight(i, style*10+20); } -void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent *e ) +void DateBookDayView::contentsMouseReleaseEvent( QMouseEvent* /* e */ ) { int sh=99,eh=-1; for(int i=0;i<this->numSelections();i++) { QTableSelection sel = this->selection( i ); sh = QMIN(sh,sel.topRow()); eh = QMAX(sh,sel.bottomRow()+1); } if (sh > 23 || eh < 1) { sh=8; eh=9; } quickLineEdit=new DateBookDayViewQuickLineEdit(QDateTime(currDate,QTime(sh,0,0,0)),QDateTime(currDate,QTime(eh,0,0,0)),this->viewport(),"quickedit"); quickLineEdit->setGeometry(0,0,this->columnWidth(0)-1,this->rowHeight(0)); this->moveChild(quickLineEdit,0,sh*this->rowHeight(0)); quickLineEdit->setFocus(); quickLineEdit->show(); } //=========================================================================== DateBookDayViewQuickLineEdit::DateBookDayViewQuickLineEdit(const QDateTime &start, const QDateTime &end,QWidget * parent, const char *name) : QLineEdit(parent,name) { active=1; quickEvent.setStart(start); quickEvent.setEnd(end); connect(this,SIGNAL(returnPressed()),this,SLOT(slotReturnPressed())); } void DateBookDayViewQuickLineEdit::slotReturnPressed() { if(active && (!this->text().isEmpty())) { // Fix to avoid having this event beeing added multiple times. quickEvent.setDescription(this->text()); connect(this,SIGNAL(insertEvent(const Event &)),this->topLevelWidget(),SLOT(insertEvent(const Event &))); emit(insertEvent(quickEvent)); active=0; } /* we need to return to this object.. */ QTimer::singleShot(500, this, SLOT(finallyCallClose()) ); // Close and also delete this widget } void DateBookDayViewQuickLineEdit::finallyCallClose() { close(true); // also deletes this widget... } -void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent * e ) +void DateBookDayViewQuickLineEdit::focusOutEvent ( QFocusEvent* /* e */) { slotReturnPressed(); // Reuse code to add event and close this widget. } //=========================================================================== DateBookDay::DateBookDay( bool ampm, bool startOnMonday, DateBookDB *newDb, QWidget *parent, const char *name ) : QVBox( parent, name ), currDate( QDate::currentDate() ), db( newDb ), startTime( 0 ) { widgetList.setAutoDelete( true ); header = new DateBookDayHeader( startOnMonday, this, "day header" ); header->setDate( currDate.year(), currDate.month(), currDate.day() ); m_allDays = new DatebookdayAllday(newDb, this, "all day event list" ); m_allDays->hide(); view = new DateBookDayView( ampm, this, "day view" ); connect( header, SIGNAL( dateChanged( int, int, int ) ), this, SLOT( dateChanged( int, int, int ) ) ); connect( header, SIGNAL( dateChanged( int, int, int ) ), view, SLOT( slotDateChanged( int, int, int ) ) ); connect( view, SIGNAL( sigColWidthChanged() ), this, SLOT( slotColWidthChanged() ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChanged(bool)) ); connect( view, SIGNAL(sigCapturedKey(const QString &)), this, SIGNAL(sigNewEvent(const QString&)) ); QTimer *timer = new QTimer( this ); connect( timer, SIGNAL(timeout()), this, SLOT(updateView()) ); //connect timer for updating timeMarker & daywidgetcolors timer->start( 1000*60*5, FALSE ); //update every 5min selectedWidget = 0; timeMarker = new DateBookDayTimeMarker( this ); timeMarker->setTime( QTime::currentTime() ); rowStyle = -1; // initialize with bogus values jumpToCurTime = false; } void DateBookDay::setJumpToCurTime( bool bJump ) { jumpToCurTime = bJump; } void DateBookDay::setRowStyle( int style ) { if (rowStyle != style) view->setRowStyle( style ); rowStyle = style; } |