From b00ba7b9cdf02a4512f70694e2262ce6e3ebcb98 Mon Sep 17 00:00:00 2001 From: eilers Date: Tue, 20 Aug 2002 09:26:48 +0000 Subject: Added nice timepicker widget and dialog --- (limited to 'libopie') diff --git a/libopie/libopie.pro b/libopie/libopie.pro index 1596c9a..463fce2 100644 --- a/libopie/libopie.pro +++ b/libopie/libopie.pro @@ -1,12 +1,14 @@ TEMPLATE = lib CONFIG += qte warn_on release -HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h odevice.h -SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp odevice.cpp +HEADERS = ofontmenu.h ofileselector.h ofiledialog.h ofileview.h tododb.h todoevent.h todoresource.h todovcalresource.h xmltree.h colordialog.h colorpopupmenu.h oclickablelabel.h oprocctrl.h oprocess.h odevice.h otimepicker.h +SOURCES = ofontmenu.cc ofileselector.cc ofiledialog.cc xmltree.cc tododb.cpp todoevent.cpp todovcalresource.cpp colordialog.cpp colorpopupmenu.cpp oclickablelabel.cpp oprocctrl.cpp oprocess.cpp odevice.cpp otimepicker.cpp TARGET = opie INCLUDEPATH += $(OPIEDIR)/include DESTDIR = $(QTDIR)/lib$(PROJMAK) #VERSION = 1.0.0 +INTERFACES = otimepickerbase.ui + TRANSLATIONS = ../i18n/de/libopie.ts \ ../i18n/en/libopie.ts \ ../i18n/es/libopie.ts \ diff --git a/libopie/otimepicker.cpp b/libopie/otimepicker.cpp new file mode 100644 index 0000000..8e8a4e7 --- a/dev/null +++ b/libopie/otimepicker.cpp @@ -0,0 +1,175 @@ +#include "otimepicker.h" + +#include +#include +#include +#include +#include +#include + +OTimePicker::OTimePicker(QWidget* parent, const char* name, + WFlags fl) : + QWidget(parent,name,fl) +{ + QVBoxLayout *vbox=new QVBoxLayout(this); + + OClickableLabel *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 OClickableLabel(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 OClickableLabel(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 OTimePicker::slotHour(bool b) { + + OClickableLabel *r = (OClickableLabel *) 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 OTimePicker::slotMinute(bool b) { + + OClickableLabel *r = (OClickableLabel *) 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 OTimePicker::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 OTimePicker::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); +} + + +OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl ) + : OTimePickerDialogBase (parent , name, true , fl) +{ + + connect ( m_timePicker, SIGNAL( timeChanged( const QTime& ) ), + this, SLOT( setTime ( const QTime& ) ) ); + connect ( minuteField, SIGNAL( textChanged ( const QString& ) ), + this, SLOT ( setMinute ( const QString& ) ) ); + connect ( hourField, SIGNAL( textChanged ( const QString& ) ), + this, SLOT ( setHour ( const QString& ) ) ); + +} + +QTime& OTimePickerDialog::time() +{ + return m_time; +} +void OTimePickerDialog::setTime( const QTime& time ) +{ + m_time = time; + + m_timePicker->setHour ( time.hour() ); + m_timePicker->setMinute( time.minute() ); + + // Set Textfields + if ( time.hour() < 10 ) + hourField->setText( "0" + QString::number( time.hour() ) ); + else + hourField->setText( QString::number( time.hour() ) ); + + if ( time.minute() < 10 ) + minuteField->setText( "0" + QString::number( time.minute() ) ); + else + minuteField->setText( QString::number( time.minute() ) ); + +} + +void OTimePickerDialog::setHour ( const QString& hour ) +{ + if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) ){ + m_time.setHMS ( hour.toInt(), m_time.minute() , 00 ); + setTime ( m_time ); + } + +} + +void OTimePickerDialog::setMinute ( const QString& minute ) +{ + if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) ){ + m_time.setHMS ( m_time.hour(), minute.toInt(), 00 ); + setTime ( m_time ); + } +} diff --git a/libopie/otimepicker.h b/libopie/otimepicker.h new file mode 100644 index 0000000..3de6698 --- a/dev/null +++ b/libopie/otimepicker.h @@ -0,0 +1,51 @@ +#ifndef OTIMEPICKER_H +#define OTIMEPICKER_H + +#include +#include +#include +#include + +#include +#include + +class OTimePicker: public QWidget { + Q_OBJECT + + public: + OTimePicker(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 &); +}; + +class OTimePickerDialog: public OTimePickerDialogBase { + Q_OBJECT + + public: + OTimePickerDialog ( QWidget* parent = 0, const char* name = NULL, WFlags fl = 0 ); + ~OTimePickerDialog() { }; + + QTime& time(); + + public slots: + void setTime( const QTime& time ); + void setHour( const QString& hour ); + void setMinute( const QString& minute ); + + private: + QTime m_time; +}; +#endif diff --git a/libopie/otimepickerbase.h b/libopie/otimepickerbase.h new file mode 100644 index 0000000..bac2b06 --- a/dev/null +++ b/libopie/otimepickerbase.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** Form interface generated from reading ui file 'otimepickerbase.ui' +** +** Created: Tue Aug 20 10:04:21 2002 +** by: The User Interface Compiler (uic) +** +** WARNING! All changes made in this file will be lost! +****************************************************************************/ +#ifndef OTIMEPICKERDIALOGBASE_H +#define OTIMEPICKERDIALOGBASE_H + +#include +#include +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; +class OTimePicker; +class QFrame; +class QGroupBox; +class QLabel; +class QLineEdit; + +class OTimePickerDialogBase : public QDialog +{ + Q_OBJECT + +public: + OTimePickerDialogBase( QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags fl = 0 ); + ~OTimePickerDialogBase(); + + QFrame* Frame10; + QFrame* Frame4; + QLabel* TextLabel1; + QLineEdit* hourField; + QLabel* TextLabel1_2; + QLineEdit* minuteField; + QGroupBox* GroupBox1; + OTimePicker* m_timePicker; + +protected: + QVBoxLayout* OTimePickerDialogBaseLayout; + QHBoxLayout* Frame10Layout; + QHBoxLayout* Frame4Layout; + bool event( QEvent* ); +}; + +#endif // OTIMEPICKERDIALOGBASE_H diff --git a/libopie/otimepickerbase.ui b/libopie/otimepickerbase.ui new file mode 100644 index 0000000..150545b --- a/dev/null +++ b/libopie/otimepickerbase.ui @@ -0,0 +1,284 @@ + +OTimePickerDialogBase + + QDialog + + name + OTimePickerDialogBase + + + geometry + + 0 + 0 + 210 + 146 + + + + sizePolicy + + 1 + 1 + + + + caption + TimePicker + + + layoutMargin + + + + margin + 5 + + + spacing + 6 + + + QFrame + + name + Frame10 + + + sizePolicy + + 1 + 7 + + + + frameShape + NoFrame + + + frameShadow + Raised + + + layoutMargin + + + + margin + 2 + + + spacing + 6 + + + + name + Spacer4 + + + orientation + Horizontal + + + sizeType + MinimumExpanding + + + sizeHint + + 20 + 20 + + + + + QFrame + + name + Frame4 + + + sizePolicy + + 4 + 5 + + + + frameShape + Box + + + frameShadow + Sunken + + + layoutMargin + + + layoutSpacing + + + + margin + 11 + + + spacing + 6 + + + QLabel + + name + TextLabel1 + + + text + Time: + + + + QLineEdit + + name + hourField + + + sizePolicy + + 4 + 0 + + + + alignment + AlignHCenter + + + hAlign + + + + QLabel + + name + TextLabel1_2 + + + font + + 1 + + + + text + : + + + + QLineEdit + + name + minuteField + + + alignment + AlignHCenter + + + hAlign + + + + + + + name + Spacer5 + + + orientation + Horizontal + + + sizeType + MinimumExpanding + + + sizeHint + + 20 + 20 + + + + + + + QGroupBox + + name + GroupBox1 + + + sizePolicy + + 1 + 1 + + + + title + Pick Time: + + + OTimePicker + + name + m_timePicker + + + geometry + + 10 + 10 + 180 + 61 + + + + sizePolicy + + 7 + 4 + + + + + + + + + OTimePicker +
otimepicker.h
+ + -1 + -1 + + 0 + + 7 + 1 + + image0 +
+
+ + + image0 + 789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753 + + +
-- cgit v0.9.0.2