From 78211642003f70797a5faa1767a5ab2f5f83606f Mon Sep 17 00:00:00 2001 From: hakan Date: Tue, 26 Mar 2002 19:05:31 +0000 Subject: Added shortcut buttons to set the start time --- (limited to 'core') diff --git a/core/pim/datebook/clickablelabel.cpp b/core/pim/datebook/clickablelabel.cpp index 6912c34..1dd0d15 100644 --- a/core/pim/datebook/clickablelabel.cpp +++ b/core/pim/datebook/clickablelabel.cpp @@ -1,31 +1,88 @@ #include "clickablelabel.h" +#include ClickableLabel::ClickableLabel(QWidget* parent = 0, const char* name = 0, WFlags fl = 0) : QLabel(parent,name,fl) { - setFrameShape(NoFrame); + textInverted=false; + isToggle=false; + isDown=false; + showState(false); setFrameShadow(Sunken); } +void ClickableLabel::setToggleButton(bool t) { + isToggle=t; +} + void ClickableLabel::mousePressEvent( QMouseEvent *e ) { - setFrameShape(Panel); - repaint(); + if (isToggle && isDown) { + showState(false); + } else { + showState(true); + } } void ClickableLabel::mouseReleaseEvent( QMouseEvent *e ) { - setFrameShape(NoFrame); - repaint(); + if (rect().contains(e->pos()) && isToggle) isDown=!isDown; + + if (isToggle && isDown) { + showState(true); + } else { + showState(false); + } + if (rect().contains(e->pos())) { + if (isToggle) { + emit toggled(isDown); + } emit clicked(); } } void ClickableLabel::mouseMoveEvent( QMouseEvent *e ) { if (rect().contains(e->pos())) { - setFrameShape(Panel); + if (isToggle && isDown) { + showState(false); + } else { + showState(true); + } } else { - setFrameShape(NoFrame); + if (isToggle && isDown) { + showState(true); + } else { + showState(false); + } } } + +void ClickableLabel::showState(bool on) { + if (on) { + //setFrameShape(Panel); + setInverted(true); + setBackgroundMode(PaletteHighlight); + } else { + //setFrameShape(NoFrame); + setInverted(false); + setBackgroundMode(PaletteBackground); + } + repaint(); +} + +void ClickableLabel::setInverted(bool on) { + if ( (!textInverted && on) || (textInverted && !on) ) { + QPalette pal=palette(); + QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground); + col.setRgb(255-col.red(),255-col.green(),255-col.blue()); + pal.setColor(QPalette::Normal, QColorGroup::Foreground, col); + setPalette(pal); + textInverted=!textInverted; + } +} + +void ClickableLabel::setOn(bool on) { + isDown=on; + showState(isDown); +} diff --git a/core/pim/datebook/clickablelabel.h b/core/pim/datebook/clickablelabel.h index b6d33ad..d00fee6 100644 --- a/core/pim/datebook/clickablelabel.h +++ b/core/pim/datebook/clickablelabel.h @@ -9,12 +9,22 @@ class ClickableLabel: public QLabel public: ClickableLabel(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); + void setToggleButton(bool t); protected: void mousePressEvent( QMouseEvent *e ); void mouseReleaseEvent( QMouseEvent *e ); void mouseMoveEvent( QMouseEvent *e ); + public slots: + void setOn(bool on); signals: void clicked(); + void toggled(bool on); + private: + bool isToggle; + bool isDown; + void showState(bool on); + bool textInverted; + void setInverted(bool on); }; #endif diff --git a/core/pim/datebook/datebook.cpp b/core/pim/datebook/datebook.cpp index 92dbdc8..2deb96f 100644 --- a/core/pim/datebook/datebook.cpp +++ b/core/pim/datebook/datebook.cpp @@ -207,6 +207,9 @@ DateBook::DateBook( QWidget *parent, const char *, WFlags f ) QCopChannel *channel = new QCopChannel( "QPE/System", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); + channel = new QCopChannel( "QPE/Datebook", this ); + connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), + this, SLOT(receive(const QCString&, const QByteArray&)) ); #endif #endif @@ -226,6 +229,14 @@ void DateBook::receive( const QCString &msg, const QByteArray &data ) else if ( monthAction->isOn() ) viewMonth(); } + else if (msg == "editEvent(int)") { + /* Not yet working... + int uid; + stream >> uid; + Event e=db->getEvent(uid); + editEvent(e); + */ + } } DateBook::~DateBook() diff --git a/core/pim/datebook/datebook.pro b/core/pim/datebook/datebook.pro index 314a56a..09d5c2d 100644 --- a/core/pim/datebook/datebook.pro +++ b/core/pim/datebook/datebook.pro @@ -11,7 +11,8 @@ HEADERS = datebookday.h \ datebookweeklst.h \ datebookweekheaderimpl.h \ repeatentry.h \ - clickablelabel.h + clickablelabel.h \ + timepicker.h SOURCES = main.cpp \ datebookday.cpp \ @@ -23,7 +24,8 @@ SOURCES = main.cpp \ datebookweeklst.cpp \ datebookweekheaderimpl.cpp \ repeatentry.cpp \ - clickablelabel.cpp + clickablelabel.cpp \ + timepicker.cpp INTERFACES = dateentry.ui \ datebookdayheader.ui \ diff --git a/core/pim/datebook/dateentry.ui b/core/pim/datebook/dateentry.ui index eac4e23..22ff32d 100644 --- a/core/pim/datebook/dateentry.ui +++ b/core/pim/datebook/dateentry.ui @@ -230,308 +230,19 @@ - QComboBox - - - text - 00:00 - - - - - text - 00:30 - - - - - text - 01:00 - - - - - text - 01:30 - - - - - text - 02:00 - - - - - text - 02:30 - - - - - text - 03:00 - - - - - text - 03:30 - - - - - text - 04:00 - - - - - text - 04:30 - - - - - text - 05:00 - - - - - text - 05:30 - - - - - text - 06:00 - - - - - text - 06:30 - - - - - text - 07:00 - - - - - text - 07:30 - - - - - text - 08:00 - - - - - text - 08:30 - - - - - text - 09:00 - - - - - text - 09:30 - - - - - text - 10:00 - - - - - text - 10:30 - - - - - text - 11:00 - - - - - text - 11:30 - - - - - text - 12:00 - - - - - text - 12:30 - - - - - text - 13:00 - - - - - text - 13:30 - - - - - text - 14:00 - - - - - text - 14:30 - - - - - text - 15:00 - - - - - text - 15:30 - - - - - text - 16:00 - - - - - text - 16:30 - - - - - text - 17:00 - - - - - text - 17:30 - - - - - text - 18:00 - - - - - text - 18:30 - - - - - text - 19:00 - - - - - text - 19:30 - - - - - text - 20:00 - - - - - text - 20:30 - - - - - text - 21:00 - - - - - text - 21:30 - - - - - text - 22:00 - - - - - text - 22:30 - - - - - text - 23:00 - - - - - text - 23:30 - - + QLineEdit name comboStart + + + TimePicker - editable - true - - - duplicatesEnabled - false + name + timePickerStart - + QPushButton @@ -544,307 +255,11 @@ - QComboBox - - - text - 00:00 - - - - - text - 00:30 - - - - - text - 01:00 - - - - - text - 01:30 - - - - - text - 02:00 - - - - - text - 02:30 - - - - - text - 03:00 - - - - - text - 03:30 - - - - - text - 04:00 - - - - - text - 04:30 - - - - - text - 05:00 - - - - - text - 05:30 - - - - - text - 06:00 - - - - - text - 06:30 - - - - - text - 07:00 - - - - - text - 07:30 - - - - - text - 08:00 - - - - - text - 08:30 - - - - - text - 09:00 - - - - - text - 09:30 - - - - - text - 10:00 - - - - - text - 10:30 - - - - - text - 11:00 - - - - - text - 11:30 - - - - - text - 12:00 - - - - - text - 12:30 - - - - - text - 13:00 - - - - - text - 13:30 - - - - - text - 14:00 - - - - - text - 14:30 - - - - - text - 15:00 - - - - - text - 15:30 - - - - - text - 16:00 - - - - - text - 16:30 - - - - - text - 17:00 - - - - - text - 17:30 - - - - - text - 18:00 - - - - - text - 18:30 - - - - - text - 19:00 - - - - - text - 19:30 - - - - - text - 20:00 - - - - - text - 20:30 - - - - - text - 21:00 - - - - - text - 21:30 - - - - - text - 22:00 - - - - - text - 22:30 - - - - - text - 23:00 - - - - - text - 23:30 - - + QLineEdit name comboEnd - - editable - true - - - duplicatesEnabled - false - QLabel @@ -857,7 +272,7 @@ End - + QCheckBox name @@ -868,7 +283,7 @@ All day - + QLabel name @@ -879,14 +294,14 @@ Time zone: - + TimeZoneSelector name timezone - + QCheckBox name @@ -909,7 +324,7 @@ false - + QSpinBox name @@ -940,7 +355,7 @@ 5 - + QComboBox @@ -963,7 +378,7 @@ false - + QLabel name @@ -974,7 +389,7 @@ Repeat - + QToolButton name @@ -989,7 +404,7 @@ No Repeat... - + QMultiLineEdit name @@ -1027,6 +442,20 @@ image1 + + TimePicker +
timepicker.h
+ + -1 + -1 + + 0 + + 7 + 1 + + image1 +
@@ -1047,7 +476,7 @@ comboEnd - activated(const QString&) + textChanged(const QString&) DateEntryBase endTimeChanged( const QString & ) @@ -1059,9 +488,9 @@ comboStart - activated(int) + textChanged(const QString &) DateEntryBase - startTimeChanged( int ) + startTimeEdited( const QString & ) checkAllDay @@ -1088,7 +517,7 @@ slotWait( int ) startDateChanged( const QString & ) startDateChanged(int, int, int) - startTimeChanged( int ) + startTimeEdited( const QString & ) typeChanged( const QString & ) tzexecute(void) diff --git a/core/pim/datebook/dateentryimpl.cpp b/core/pim/datebook/dateentryimpl.cpp index b2e3e3a..1c43363 100644 --- a/core/pim/datebook/dateentryimpl.cpp +++ b/core/pim/datebook/dateentryimpl.cpp @@ -39,6 +39,8 @@ #include #include +#include "timepicker.h" + #include #include @@ -60,18 +62,22 @@ DateEntry::DateEntry( bool startOnMonday, const QDateTime &start, { init(); setDates(start,end); - setFocusProxy(comboDescription); + setFocusProxy(comboDescription); } static void addOrPick( QComboBox* combo, const QString& t ) { + // Pick an item if one excists for (int i=0; icount(); i++) { if ( combo->text(i) == t ) { combo->setCurrentItem(i); return; } } - combo->setEditText(t); + + // Else add one + combo->insertItem(t); + combo->setCurrentItem(combo->count()-1); } DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, @@ -103,45 +109,50 @@ DateEntry::DateEntry( bool startOnMonday, const Event &event, bool whichClock, void DateEntry::setDates( const QDateTime& s, const QDateTime& e ) { - int shour, - ehour; - QString strStart, - strEnd; startDate = s.date(); endDate = e.date(); startTime = s.time(); endTime = e.time(); startDateChanged( s.date().year(), s.date().month(), s.date().day() ); + endDateChanged( e.date().year(), e.date().month(), e.date().day() ); + updateTimeEdit(true,true); +} + +void DateEntry::updateTimeEdit(bool s, bool e) { + + // Comboboxes + QString strStart, strEnd; + int shour, ehour; if ( ampm ) { - shour = s.time().hour(); - ehour = e.time().hour(); + shour = startTime.hour(); + ehour = endTime.hour(); if ( shour >= 12 ) { if ( shour > 12 ) shour -= 12; - strStart.sprintf( "%d:%02d PM", shour, s.time().minute() ); + strStart.sprintf( "%d:%02d PM", shour, startTime.minute() ); } else { if ( shour == 0 ) shour = 12; - strStart.sprintf( "%d:%02d AM", shour, s.time().minute() ); + strStart.sprintf( "%d:%02d AM", shour, startTime.minute() ); } - if ( ehour == 24 && e.time().minute() == 0 ) { + if ( ehour == 24 && endTime.minute() == 0 ) { strEnd = "11:59 PM"; // or "midnight" } else if ( ehour >= 12 ) { if ( ehour > 12 ) ehour -= 12; - strEnd.sprintf( "%d:%02d PM", ehour, e.time().minute() ); + strEnd.sprintf( "%d:%02d PM", ehour, endTime.minute() ); } else { if ( ehour == 0 ) ehour = 12; - strEnd.sprintf( "%d:%02d AM", ehour, e.time().minute() ); + strEnd.sprintf( "%d:%02d AM", ehour, endTime.minute() ); } } else { - strStart.sprintf( "%02d:%02d", s.time().hour(), s.time().minute() ); - strEnd.sprintf( "%02d:%02d", e.time().hour(), e.time().minute() ); + strStart.sprintf( "%02d:%02d", startTime.hour(), startTime.minute() ); + strEnd.sprintf( "%02d:%02d", endTime.hour(), endTime.minute() ); } - addOrPick(comboStart, strStart ); - endDateChanged( e.date().year(), e.date().month(), e.date().day() ); - addOrPick(comboEnd, strEnd ); + + if (s) comboStart->setText(strStart); + if (e) comboEnd->setText(strEnd); } void DateEntry::init() @@ -171,6 +182,10 @@ void DateEntry::init() buttonEnd->setPopup( m2 ); connect( endPicker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( endDateChanged( int, int, int ) ) ); + + connect(timePickerStart, SIGNAL( timeChanged(const QTime &) ), + this, SLOT( startTimePicked(const QTime &) )); + editNote->setFixedVisibleLines(3); } /* @@ -240,8 +255,12 @@ void DateEntry::endTimeChanged( const QString &s ) endTime = tmpTime; } else { endTime = startTime; - comboEnd->setCurrentItem( comboStart->currentItem() ); + //comboEnd->setCurrentItem( comboStart->currentItem() ); } + +} + +void DateEntry::endTimeChanged( const QTime &t ) { } /* @@ -270,12 +289,25 @@ void DateEntry::startDateChanged( int y, int m, int d ) /* * public slot */ -void DateEntry::startTimeChanged( int index ) +void DateEntry::startTimeEdited( const QString &s ) { - startTime = parseTime(comboStart->text(index),ampm); - changeEndCombo( index ); - //cout << "Start: " << comboStart->currentText() << endl; + startTimeChanged(parseTime(s,ampm)); + updateTimeEdit(false,true); + timePickerStart->setHour(startTime.hour()); + timePickerStart->setMinute(startTime.minute()); } + +void DateEntry::startTimeChanged( const QTime &t ) +{ + int duration=startTime.secsTo(endTime); + startTime = t; + endTime=t.addSecs(duration); +} +void DateEntry::startTimePicked( const QTime &t ) { + startTimeChanged(t); + updateTimeEdit(true,true); +} + /* * public slot */ @@ -286,16 +318,6 @@ void DateEntry::typeChanged( const QString &s ) comboStart->setEnabled( b ); comboEnd->setEnabled( b ); } -/* - * public slot - */ -void DateEntry::changeEndCombo( int change ) -{ - if ( change + 2 < comboEnd->count() ) - change += 2; - comboEnd->setCurrentItem( change ); - endTimeChanged( comboEnd->currentText() ); -} void DateEntry::slotRepeat() { @@ -336,8 +358,11 @@ Event DateEntry::event() endDate = startDate; startDate = tmp; } - startTime = parseTime( comboStart->currentText(), ampm ); - endTime = parseTime( comboEnd->currentText(), ampm ); + + // This is now done in the changed slots + // startTime = parseTime( comboStart->text(), ampm ); + //endTime = parseTime( comboEnd->text(), ampm ); + if ( startTime > endTime && endDate == startDate ) { QTime tmp = endTime; endTime = startTime; @@ -427,6 +452,7 @@ void DateEntry::setAlarmEnabled( bool alarmPreset, int presetTime, Event::SoundT void DateEntry::initCombos() { + /* comboStart->clear(); comboEnd->clear(); if ( ampm ) { @@ -472,6 +498,7 @@ void DateEntry::initCombos() } } } + */ } void DateEntry::slotChangeClock( bool whichClock ) diff --git a/core/pim/datebook/dateentryimpl.h b/core/pim/datebook/dateentryimpl.h index 785af7a..bde3119 100644 --- a/core/pim/datebook/dateentryimpl.h +++ b/core/pim/datebook/dateentryimpl.h @@ -46,10 +46,12 @@ public: public slots: void endDateChanged( int, int, int ); void endTimeChanged( const QString & ); + void endTimeChanged( const QTime & ); void startDateChanged(int, int, int); - void startTimeChanged( int index ); + void startTimeEdited( const QString & ); + void startTimeChanged( const QTime & ); + void startTimePicked( const QTime & ); void typeChanged( const QString & ); - void changeEndCombo( int change ); void slotRepeat(); void slotChangeClock( bool ); void slotChangeStartOfWeek( bool ); @@ -59,6 +61,7 @@ private: void initCombos(); void setDates( const QDateTime& s, const QDateTime& e ); void setRepeatLabel(); + void updateTimeEdit(bool,bool); DateBookMonth *startPicker, *endPicker; QDate startDate, endDate; diff --git a/core/pim/datebook/timepicker.cpp b/core/pim/datebook/timepicker.cpp new file mode 100644 index 0000000..5f08a05 --- a/dev/null +++ b/core/pim/datebook/timepicker.cpp @@ -0,0 +1,119 @@ +#include "timepicker.h" + +#include +#include +#include +#include "clickablelabel.h" +#include + +TimePicker::TimePicker(QWidget* parent = 0, const char* name = 0, + WFlags fl = 0) : + QWidget(parent,name,fl) +{ + QVBoxLayout *vbox=new QVBoxLayout(this); + + ClickableLabel *r; + QString s; + + // Hour Row + QWidget *row=new QWidget(this); + QHBoxLayout *l=new QHBoxLayout(row); + vbox->addWidget(row); + + + for (int i=0; i<24; i++) { + r=new ClickableLabel(row); + hourLst.append(r); + s.sprintf("%.2d",i); + r->setText(s); + r->setToggleButton(true); + r->setAlignment(AlignHCenter | AlignVCenter); + l->addWidget(r); + connect(r, SIGNAL(toggled(bool)), + this, SLOT(slotHour(bool))); + + if (i==11) { // Second row + row=new QWidget(this); + l=new QHBoxLayout(row); + vbox->addWidget(row); + } + } + + // Minute Row + row=new QWidget(this); + l=new QHBoxLayout(row); + vbox->addWidget(row); + + for (int i=0; i<60; i+=5) { + r=new ClickableLabel(row); + minuteLst.append(r); + s.sprintf("%.2d",i); + r->setText(s); + r->setToggleButton(true); + r->setAlignment(AlignHCenter | AlignVCenter); + l->addWidget(r); + connect(r, SIGNAL(toggled(bool)), + this, SLOT(slotMinute(bool))); + } +} + +void TimePicker::slotHour(bool b) { + + ClickableLabel *r = (ClickableLabel *) sender(); + + if (b) { + QValueListIterator it; + for (it=hourLst.begin(); it!=hourLst.end(); it++) { + if (*it != r) (*it)->setOn(false); + else tm.setHMS((*it)->text().toInt(), tm.minute(), 0); + } + emit timeChanged(tm); + } else { + r->setOn(true); + } + +} + +void TimePicker::slotMinute(bool b) { + + ClickableLabel *r = (ClickableLabel *) sender(); + + if (b) { + QValueListIterator it; + for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { + if (*it != r) (*it)->setOn(false); + else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0); + } + emit timeChanged(tm); + } else { + r->setOn(true); + } + +} + +void TimePicker::setMinute(int m) { + + QString minute; + minute.sprintf("%.2d",m); + + QValueListIterator it; + for (it=minuteLst.begin(); it!=minuteLst.end(); it++) { + if ((*it)->text() == minute) (*it)->setOn(true); + else (*it)->setOn(false); + } + + tm.setHMS(tm.hour(),m,0); +} + +void TimePicker::setHour(int h) { + + QString hour; + hour.sprintf("%.2d",h); + + QValueListIterator it; + for (it=hourLst.begin(); it!=hourLst.end(); it++) { + if ((*it)->text() == hour) (*it)->setOn(true); + else (*it)->setOn(false); + } + tm.setHMS(h,tm.minute(),0); +} diff --git a/core/pim/datebook/timepicker.h b/core/pim/datebook/timepicker.h new file mode 100644 index 0000000..0acadcb --- a/dev/null +++ b/core/pim/datebook/timepicker.h @@ -0,0 +1,32 @@ +#ifndef TIMEPICKER_H +#define TIMEPICKER_H + +#include +#include +#include "clickablelabel.h" +#include + +class TimePicker: public QWidget { + Q_OBJECT + + public: + TimePicker(QWidget* parent = 0, const char* name = 0, + WFlags fl = 0); + void setHour(int h); + void setMinute(int m); + + private: + QValueList hourLst; + QValueList minuteLst; + QTime tm; + + private slots: + void slotHour(bool b); + void slotMinute(bool b); + + signals: + void timeChanged(const QTime &); +}; + + +#endif -- cgit v0.9.0.2