-rw-r--r-- | korganizer/komonthview.cpp | 146 | ||||
-rw-r--r-- | korganizer/komonthview.h | 5 |
2 files changed, 90 insertions, 61 deletions
diff --git a/korganizer/komonthview.cpp b/korganizer/komonthview.cpp index e66ddce..4dfb9df 100644 --- a/korganizer/komonthview.cpp +++ b/korganizer/komonthview.cpp @@ -83,60 +83,64 @@ KNoScrollListBox::KNoScrollListBox(QWidget *parent,const char *name) QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold ); #endif mWT = new KNOWhatsThis(this); resetOnFocusIn = true; setVScrollBarMode(QScrollView::AlwaysOff); setHScrollBarMode(QScrollView::AlwaysOff); } KNoScrollListBox::~KNoScrollListBox() { } void KNoScrollListBox::focusInEvent ( QFocusEvent * e ) { QListBox::focusInEvent ( e ); - QListBoxItem * i = item ( 0 ); - if ( i && resetOnFocusIn ) { - setCurrentItem( i ); - setSelected ( 0, true ); - } - resetOnFocusIn = true; - - if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { - QListBoxItem *fi = firstItem (); - if (fi ) { - int ihei = fi->height( this ); - int hei = numRows () * ihei; - if ( hei < height() - horizontalScrollBar()->height () ) { - setVScrollBarMode(QScrollView::AlwaysOff); - } - else + if ( count() ){ + int ci = currentItem(); + if ( ci < 0 ) ci = 0; + + setCurrentItem( ci ); + setSelected ( ci, true ); + emit highlighted( item ( ci ) ); + + resetOnFocusIn = true; + + if ( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) { + QListBoxItem *fi = firstItem (); + if (fi ) { + int ihei = fi->height( this ); + int hei = numRows () * ihei; + if ( hei < height() - horizontalScrollBar()->height () ) { + setVScrollBarMode(QScrollView::AlwaysOff); + } + else + setVScrollBarMode(QScrollView::Auto); + if ( ihei *3 > height() ) { + setHScrollBarMode(QScrollView::AlwaysOff); + } + else { + setHScrollBarMode(QScrollView::Auto); + } + } else { setVScrollBarMode(QScrollView::Auto); - if ( ihei *3 > height() ) { - setHScrollBarMode(QScrollView::AlwaysOff); - } - else { setHScrollBarMode(QScrollView::Auto); } - } else { - setVScrollBarMode(QScrollView::Auto); - setHScrollBarMode(QScrollView::Auto); - } - } + } + } } void KNoScrollListBox::focusOutEvent ( QFocusEvent * e ) { int i = currentItem (); if ( i >= 0 ) { setSelected ( i, false ); } QListBox::focusOutEvent ( e ); setVScrollBarMode(QScrollView::AlwaysOff); setHScrollBarMode(QScrollView::AlwaysOff); } QString KNoScrollListBox::getWhatsThisText(QPoint p) { QListBoxItem* item = itemAt ( p ); if ( ! item ) { @@ -159,93 +163,105 @@ void KNoScrollListBox::keyPressEvent(QKeyEvent *e) } scrollBy(10,0); break; case Key_Left: if (e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton ) { e->ignore(); return; } scrollBy(-10,0); break; case Key_Up: if( e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { e->ignore(); break; } - if ( count() ) { - setCurrentItem((currentItem()+count()-1)%count()); - if(!itemVisible(currentItem())) { - if((unsigned int) currentItem() == (count()-1)) { - setTopItem(currentItem()-numItemsVisible()+1); - } else { - setTopItem(topItem()-1); + if ( count() ) { + if ( currentItem() == 0 ) { + emit prevCell(); + } else { + setCurrentItem((currentItem()+count()-1)%count()); + if(!itemVisible(currentItem())) { + if((unsigned int) currentItem() == (count()-1)) { + setTopItem(currentItem()-numItemsVisible()+1); + } else { + setTopItem(topItem()-1); + } } } } break; case Key_Down: if(e->state() == Qt::ControlButton|| e->state() == Qt::ShiftButton) { e->ignore(); break; } - if ( count () ) { - setCurrentItem((currentItem()+1)%count()); - if(!itemVisible(currentItem())) { - if(currentItem() == 0) { - setTopItem(0); - } else { - setTopItem(topItem()+1); + if ( count () ) { + if ( currentItem()+1 == count () ) { + emit nextCell(); + } else { + setCurrentItem((currentItem()+1)%count()); + if(!itemVisible(currentItem())) { + if(currentItem() == 0) { + setTopItem(0); + } else { + setTopItem(topItem()+1); + } } } } break; case Key_I: QTimer::singleShot( 1, this, SLOT ( oneDown() ) ); e->ignore(); break; case Key_Return: case Key_Enter: { if ( currentItem() >= 0 ) { emit doubleClicked( item( currentItem() ) ); e->accept(); } else { e->ignore(); } } break; case Key_Shift: emit shiftDown(); break; default: e->ignore(); break; } } void KNoScrollListBox::oneDown() { - if ( count () ) { - resetOnFocusIn = false; - setCurrentItem((currentItem()+1)%count()); - if(!itemVisible(currentItem())) { - if(currentItem() == 0) { - setTopItem(0); - } else { - setTopItem(topItem()+1); + if ( count () ) { + if ( currentItem()+1 == count () ) { + emit nextCell(); + } else { + resetOnFocusIn = false; + setCurrentItem((currentItem()+1)%count()); + if(!itemVisible(currentItem())) { + if(currentItem() == 0) { + setTopItem(0); + } else { + setTopItem(topItem()+1); + } } } } } void KNoScrollListBox::keyReleaseEvent(QKeyEvent *e) { switch(e->key()) { case Key_Shift: emit shiftUp(); break; default: break; } } void KNoScrollListBox::mousePressEvent(QMouseEvent *e) @@ -460,36 +476,37 @@ MonthViewCell::MonthViewCell( KOMonthView *parent,QWidget* par ) mLabel->raise(); // QColor( 0,0,255 ) QColor( 160,1600,255 ) mStandardPalette = palette(); mStandardPalette.setColor(QColorGroup::Base, mStandardPalette.color( QPalette::Normal, QColorGroup::Background ) ); enableScrollBars( false ); updateConfig(); //connect( mLabel, SIGNAL( clicked( )), SLOT( newEvent() )); connect( mLabel, SIGNAL( clicked( )), SLOT( showDay() )); connect( this , SIGNAL( doubleClicked( QListBoxItem *) ), SLOT( defaultAction( QListBoxItem * ) ) ); connect( this, SIGNAL( rightButtonPressed( QListBoxItem *, const QPoint &) ), SLOT( contextMenu( QListBoxItem * ) ) ); connect( this, SIGNAL( highlighted( QListBoxItem *) ), SLOT( selection( QListBoxItem * ) ) ); - connect( this, SIGNAL( clicked( QListBoxItem * ) ), - SLOT( cellClicked( QListBoxItem * ) ) ); + + /* connect( this, SIGNAL( clicked( QListBoxItem * ) ), SLOT( selection( QListBoxItem * ) ) ); + */ } #ifdef DESKTOP_VERSION QToolTipGroup *MonthViewCell::toolTipGroup() { if (!mToolTipGroup) mToolTipGroup = new QToolTipGroup(0); return mToolTipGroup; } #endif void MonthViewCell::setDate( const QDate &date ) { // kdDebug() << "MonthViewCell::setDate(): " << date.toString() << endl; mDate = date; @@ -976,69 +993,61 @@ void MonthViewCell::resizeEvent ( QResizeEvent * e ) int size = height() - mLabel->height() - lineWidth()-1; //qDebug("LW %d ", lineWidth()); if ( size > 0 ) verticalScrollBar()->setMaximumHeight( size ); size = width() - mLabel->width() -lineWidth()-1; if ( size > 0 ) horizontalScrollBar()->setMaximumWidth( size ); mLabel->move( width()-lineWidth() - mLabel->width(), height()-lineWidth() - mLabel->height() ); //mLabel->setMaximumWidth( width() - mItemList->lineWidth()*2); // mItemList->resize ( width(), height () ); if ( e ) KNoScrollListBox::resizeEvent ( e ); } void MonthViewCell::defaultAction( QListBoxItem *item ) { + if ( !item ) { QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); emit newEventSignal( dt ); return; } MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); Incidence *incidence = eventItem->incidence(); if ( incidence ) mMonthView->defaultAction( incidence ); } void MonthViewCell::showDay() { emit showDaySignal( date() ); } void MonthViewCell::newEvent() { QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); emit newEventSignal( dt ); } void MonthViewCell::cellClicked( QListBoxItem *item ) { + qDebug("CELL "); if ( item == 0 ) { QDateTime dt( date(), QTime( KOPrefs::instance()->mStartTime, 0 ) ); emit newEventSignal( dt ); return; } - /* - if ( lastClicked ) - if ( ! item ) { - if ( lastClicked->listBox() != item->listBox() ) - lastClicked->listBox()->clearSelection(); - } - */ - - mMonthView->setSelectedCell( this ); - if( KOPrefs::instance()->mEnableMonthScroll || KOPrefs::instance()->mMonthViewWeek ) enableScrollBars( true ); - select(); + } void MonthViewCell::contextMenu( QListBoxItem *item ) { if ( !item ) return; MonthViewItem *eventItem = static_cast<MonthViewItem *>( item ); Incidence *incidence = eventItem->incidence(); if ( incidence ) mMonthView->showContextMenu( incidence ); } void MonthViewCell::selection( QListBoxItem *item ) { if ( !item ) return; mMonthView->setSelectedCell( this ); @@ -1138,45 +1147,53 @@ KOMonthView::KOMonthView(Calendar *calendar, QWidget *parent, const char *name) mWeekLabelsW[1]->setFocusPolicy(WheelFocus); int row, col; mCells.resize( mNumCells ); for( row = 0; row < mNumWeeks; ++row ) { for( col = 0; col < mDaysPerWeek; ++col ) { MonthViewCell *cell = new MonthViewCell( this, mMonthView ); mCells.insert( row * mDaysPerWeek + col, cell ); connect( cell, SIGNAL( defaultAction( Incidence * ) ), SLOT( defaultAction( Incidence * ) ) ); connect( cell, SIGNAL( newEventSignal( QDateTime ) ), SIGNAL( newEventSignal( QDateTime ) ) ); connect( cell, SIGNAL( showDaySignal( QDate ) ), SIGNAL( showDaySignal( QDate ) ) ); + connect( cell, SIGNAL( nextCell() ), + SLOT( nextCell() ) ); + connect( cell, SIGNAL( prevCell() ), + SLOT( prevCell() ) ); } } mCellsW.resize( mDaysPerWeek ); for( col = 0; col < mDaysPerWeek; ++col ) { MonthViewCell *cell = new MonthViewCell( this, mWeekView ); mCellsW.insert( col, cell ); connect( cell, SIGNAL( defaultAction( Incidence * ) ), SLOT( defaultAction( Incidence * ) ) ); connect( cell, SIGNAL( newEventSignal( QDateTime ) ), SIGNAL( newEventSignal( QDateTime ) ) ); connect( cell, SIGNAL( showDaySignal( QDate ) ), SIGNAL( showDaySignal( QDate ) ) ); + connect( cell, SIGNAL( nextCell() ), + SLOT( nextCell() ) ); + connect( cell, SIGNAL( prevCell() ), + SLOT( prevCell() ) ); cell->updateConfig(KOPrefs::instance()->mMonthViewUsesBigFont ); } //connect( mWeekLabels[mNumWeeks], SIGNAL( clicked() ), SLOT( switchView() ) ); mContextMenu = eventPopup(); // updateConfig(); //useless here... // ... but we need mWidthLongDayLabel computed QFontMetrics fontmetric(mDayLabels[0]->font()); mWidthLongDayLabel = 0; for (int i = 0; i < 7; i++) { int width = fontmetric.width(KOGlobals::self()->calendarSystem()->weekDayName(i+1)); if ( width > mWidthLongDayLabel ) mWidthLongDayLabel = width; } //mWeekLabels[mNumWeeks]->setText( i18n("W")); @@ -1961,16 +1978,25 @@ void KOMonthView::keyPressEvent ( QKeyEvent * e ) } e->accept(); break; case Key_D: if ( mSelectedCell ) { mSelectedCell->showDay(); e->accept(); } else { e->ignore(); } break; default: e->ignore(); break; } } + +void KOMonthView::nextCell() +{ + bool res = focusNextPrevChild ( true ); +} +void KOMonthView::prevCell() +{ + focusNextPrevChild ( false ); +} diff --git a/korganizer/komonthview.h b/korganizer/komonthview.h index e39eeb0..c6b6b5e 100644 --- a/korganizer/komonthview.h +++ b/korganizer/komonthview.h @@ -70,32 +70,34 @@ private: private slots : void bottonClicked() { if ( mNumber > 0 ) emit selectWeekNum ( mNumber ); } }; class KNoScrollListBox: public QListBox { Q_OBJECT public: KNoScrollListBox(QWidget *parent=0, const char *name=0); ~KNoScrollListBox(); QString getWhatsThisText(QPoint p) ; signals: void shiftDown(); void shiftUp(); void rightClick(); + void nextCell(); + void prevCell(); protected slots: void oneDown(); void keyPressEvent(QKeyEvent *); void keyReleaseEvent(QKeyEvent *); void mousePressEvent(QMouseEvent *); void focusInEvent ( QFocusEvent * ); void focusOutEvent ( QFocusEvent * ); private: bool resetOnFocusIn; KNOWhatsThis * mWT; }; class MonthViewItem: public QListBoxItem @@ -175,33 +177,32 @@ class MonthViewCell : public KNoScrollListBox QPushButton * dateLabel() { return mLabel; } void deselect(); void select(); #ifdef DESKTOP_VERSION static QToolTipGroup *toolTipGroup(); #endif signals: void defaultAction( Incidence * ); void newEventSignal( QDateTime ); void showDaySignal( QDate ); protected: QStringList mToolTip; void resizeEvent( QResizeEvent * ); - public slots: void showDay(); protected slots: void defaultAction( QListBoxItem * ); void contextMenu( QListBoxItem * ); void selection( QListBoxItem * ); void cellClicked( QListBoxItem * ); void newEvent(); private: int mdayCount; QPtrList <MonthViewItem> mAvailItemList; KOMonthView *mMonthView; int currentPalette; @@ -243,32 +244,34 @@ class KOMonthView: public KOEventView /** returns the currently selected events */ virtual QPtrList<Incidence> selectedIncidences(); /** returns dates of the currently selected events */ virtual DateList selectedDates(); virtual void printPreview(CalPrinter *calPrinter, const QDate &, const QDate &); bool isMonthView() { return !mShowWeekView; } bool isUpdatePossible() { return updatePossible; } MonthViewCell * selectedCell(); bool skipResize; NavigatorBar* navigatorBar() { return mNavigatorBar ;} public slots: + void nextCell(); + void prevCell(); virtual void updateView(); virtual void updateConfig(); virtual void showDates(const QDate &start, const QDate &end); virtual void showEvents(QPtrList<Event> eventList); void changeEventDisplay(Event *, int); void clearSelection(); void showContextMenu( Incidence * ); void setSelectedCell( MonthViewCell * ); void switchView(); void setKeyBoardFocus(); void setKeyBFocus(); |