author | mickeyl <mickeyl> | 2004-01-15 15:04:23 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-01-15 15:04:23 (UTC) |
commit | ac1e2b945965ee8caabd658e90f9e234fc622619 (patch) (side-by-side diff) | |
tree | d787cb386c6b1b5f69cb00809636299e66c56833 /libopie2 | |
parent | dde789ef19fa3a3913805e452ac1e3400688e8a0 (diff) | |
download | opie-ac1e2b945965ee8caabd658e90f9e234fc622619.zip opie-ac1e2b945965ee8caabd658e90f9e234fc622619.tar.gz opie-ac1e2b945965ee8caabd658e90f9e234fc622619.tar.bz2 |
libopie1 --> libopie2 + namespace cleanups, code layout, etc.
-rw-r--r-- | libopie2/opieui/.cvsignore | 3 | ||||
-rw-r--r-- | libopie2/opieui/ofontselector.cpp | 429 | ||||
-rw-r--r-- | libopie2/opieui/ofontselector.h | 104 | ||||
-rw-r--r-- | libopie2/opieui/opieui.pro | 14 | ||||
-rw-r--r-- | libopie2/opieui/otabbar.cpp | 83 | ||||
-rw-r--r-- | libopie2/opieui/otabbar.h | 85 | ||||
-rw-r--r-- | libopie2/opieui/otabinfo.h | 140 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 423 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.h | 295 | ||||
-rw-r--r-- | libopie2/opieui/otimepicker.cpp | 295 | ||||
-rw-r--r-- | libopie2/opieui/otimepicker.h | 125 | ||||
-rw-r--r-- | libopie2/opieui/otimepickerbase.ui | 292 |
12 files changed, 2285 insertions, 3 deletions
diff --git a/libopie2/opieui/.cvsignore b/libopie2/opieui/.cvsignore index b1559c0..1244207 100644 --- a/libopie2/opieui/.cvsignore +++ b/libopie2/opieui/.cvsignore @@ -1,7 +1,8 @@ Makefile* obj moc* *moc *.o ~* - +*base.cpp +*base.h diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp new file mode 100644 index 0000000..49628c9 --- a/dev/null +++ b/libopie2/opieui/ofontselector.cpp @@ -0,0 +1,429 @@ +/* + This file is part of the Opie Project + Copyright (C) Robert Griebl <sandman@handhelds.org> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/* OPIE */ +#include <opie2/ofontselector.h> +#include <qpe/fontdatabase.h> + +/* QT */ +#include <qlayout.h> +#include <qlistbox.h> +#include <qcombobox.h> +#include <qlabel.h> +#include <qfont.h> +#include <qmultilineedit.h> + +using namespace Opie; + +namespace Opie +{ + +class OFontSelectorPrivate +{ +public: + QListBox * m_font_family_list; + QComboBox * m_font_style_list; + QComboBox * m_font_size_list; + QMultiLineEdit *m_preview; + + bool m_pointbug : 1; + + FontDatabase m_fdb; +}; + +}; + +namespace +{ + +class FontListItem : public QListBoxText +{ +public: + FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText() + { + m_name = t; + m_styles = styles; + m_sizes = sizes; + + QString str = t; + str [0] = str [0]. upper(); + setText ( str ); + } + + QString family() const + { + return m_name; + } + + const QStringList &styles() const + { + return m_styles; + } + + const QValueList<int> &sizes() const + { + return m_sizes; + } + +private: + QStringList m_styles; + QValueList<int> m_sizes; + QString m_name; +}; + + +static int findItemCB( QComboBox *box, const QString &str ) +{ + for ( int i = 0; i < box->count(); i++ ) + { + if ( box->text ( i ) == str ) + return i; + } + return -1; +} + +} +/* static same as anon. namespace */ +static int qt_version() +{ + const char *qver = qVersion(); + + return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' ); +} + +/** + * Constructs the Selector object + * @param withpreview If a font preview should be given + * @param parent The parent of the Font Selector + * @param name The name of the object + * @param fl WidgetFlags + */ +OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl ) +{ + d = new OFontSelectorPrivate(); + + QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 ); + gridLayout->setRowStretch( 4, 10 ); + + d->m_font_family_list = new QListBox( this, "FontListBox" ); + gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 ); + connect( d->m_font_family_list, SIGNAL( highlighted( int ) ), this, SLOT( fontFamilyClicked( int ) ) ); + + QLabel *label = new QLabel( tr( "Style" ), this ); + gridLayout->addWidget( label, 0, 1 ); + + d->m_font_style_list = new QComboBox( this, "StyleListBox" ); + connect( d->m_font_style_list, SIGNAL( activated( int ) ), this, SLOT( fontStyleClicked( int ) ) ); + gridLayout->addWidget( d->m_font_style_list, 1, 1 ); + + label = new QLabel( tr( "Size" ), this ); + gridLayout->addWidget( label, 2, 1 ); + + d->m_font_size_list = new QComboBox( this, "SizeListBox" ); + connect( d->m_font_size_list, SIGNAL( activated( int ) ), + this, SLOT( fontSizeClicked( int ) ) ); + gridLayout->addWidget( d->m_font_size_list, 3, 1 ); + + d->m_pointbug = ( qt_version() <= 233 ); + + if ( withpreview ) + { + d->m_preview = new QMultiLineEdit ( this, "Preview" ); + d->m_preview->setAlignment ( AlignCenter ); + d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth ); + d->m_preview->setMargin ( 3 ); + d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" )); + gridLayout->addRowSpacing ( 5, 4 ); + gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 ); + gridLayout->setRowStretch ( 6, 5 ); + } + else + d->m_preview = 0; + + loadFonts ( d->m_font_family_list ); +} + +OFontSelector::~OFontSelector() +{ + delete d; +} + +/** + * This methods tries to set the font + * @param f The wishes font + * @return success or failure + */ +bool OFontSelector::setSelectedFont ( const QFont &f ) +{ + return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet())); +} + + +/** + * This is an overloaded method @see setSelectedFont + * @param familyStr The family of the font + * @param styleStr The style of the font + * @param sizeVal The size of font + * @param charset The charset to be used. Will be deprecated by QT3 + */ +bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset ) +{ + QString sizeStr = QString::number ( sizeVal ); + + QListBoxItem *family = d->m_font_family_list->findItem ( familyStr ); + if ( !family ) + family = d->m_font_family_list->findItem ( "Helvetica" ); + if ( !family ) + family = d->m_font_family_list->firstItem(); + d->m_font_family_list->setCurrentItem ( family ); + fontFamilyClicked ( d->m_font_family_list->index ( family )); + + int style = findItemCB ( d->m_font_style_list, styleStr ); + if ( style < 0 ) + style = findItemCB ( d->m_font_style_list, "Regular" ); + if ( style < 0 && d->m_font_style_list->count() > 0 ) + style = 0; + d->m_font_style_list->setCurrentItem ( style ); + fontStyleClicked ( style ); + + int size = findItemCB ( d->m_font_size_list, sizeStr ); + if ( size < 0 ) + size = findItemCB ( d->m_font_size_list, "10" ); + if ( size < 0 && d->m_font_size_list->count() > 0 ) + size = 0; + d->m_font_size_list->setCurrentItem ( size ); + fontSizeClicked ( size ); + + return (( family ) && ( style >= 0 ) && ( size >= 0 )); +} + +/** + * This method returns the name, style and size of the currently selected + * font or false if no font is selected + * @param family The font family will be written there + * @param style The style will be written there + * @param size The size will be written there + * @return success or failure + */ +bool OFontSelector::selectedFont ( QString &family, QString &style, int &size ) +{ + QString dummy; + return selectedFont ( family, style, size, dummy ); +} + + +/** + * This method does return the font family or QString::null if there is + * no font item selected + * @return the font family + */ +QString OFontSelector::fontFamily() const +{ + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); + + return fli ? fli->family() : QString::null; +} + +/** + * This method will return the style of the font or QString::null + * @return the style of the font + */ +QString OFontSelector::fontStyle() const +{ + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); + int fst = d->m_font_style_list->currentItem(); + + return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null; +} + +/** + * This method will return the font size or 10 if no font size is available + */ +int OFontSelector::fontSize() const +{ + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); + int fsi = d->m_font_size_list->currentItem(); + + return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10; +} + +/** + * returns the charset of the font or QString::null + */ +QString OFontSelector::fontCharSet() const +{ + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem()); + + return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null; +} + +/** + * Overloaded member function see above + * @see selectedFont + */ +bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset ) +{ + int ffa = d->m_font_family_list->currentItem(); + int fst = d->m_font_style_list->currentItem(); + int fsi = d->m_font_size_list->currentItem(); + + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); + + if ( fli ) + { + family = fli->family(); + style = fst >= 0 ? fli->styles() [fst] : QString::null; + size = fsi >= 0 ? fli->sizes() [fsi] : 10; + charset = d->m_fdb. charSets ( fli->family()) [0]; + + return true; + } + else + return false; +} + +void OFontSelector::loadFonts ( QListBox *list ) +{ + QStringList f = d->m_fdb. families(); + + for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it ) + { + QValueList <int> ps = d->m_fdb. pointSizes ( *it ); + + if ( d->m_pointbug ) + { + for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ ) + *it /= 10; + } + + list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps )); + } +} + +void OFontSelector::fontFamilyClicked ( int index ) +{ + QString oldstyle = d->m_font_style_list->currentText(); + QString oldsize = d->m_font_size_list->currentText(); + + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index ); + + d->m_font_style_list->clear(); + d->m_font_style_list->insertStringList ( fli->styles()); + d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty()); + + int i; + + i = findItemCB ( d->m_font_style_list, oldstyle ); + if ( i < 0 ) + i = findItemCB ( d->m_font_style_list, "Regular" ); + if (( i < 0 ) && ( d->m_font_style_list->count() > 0 )) + i = 0; + + if ( i >= 0 ) + { + d->m_font_style_list->setCurrentItem ( i ); + fontStyleClicked ( i ); + } + + d->m_font_size_list->clear(); + QValueList<int> sl = fli->sizes(); + + for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it ) + d->m_font_size_list->insertItem ( QString::number ( *it )); + + i = findItemCB ( d->m_font_size_list, oldsize ); + if ( i < 0 ) + i = findItemCB ( d->m_font_size_list, "10" ); + if (( i < 0 ) && ( d->m_font_size_list->count() > 0 )) + i = 0; + + if ( i >= 0 ) + { + d->m_font_size_list->setCurrentItem ( i ); + fontSizeClicked ( i ); + } + changeFont(); +} + +void OFontSelector::fontStyleClicked ( int /*index*/ ) +{ + changeFont(); +} + +void OFontSelector::fontSizeClicked ( int /*index*/ ) +{ + changeFont(); +} + +void OFontSelector::changeFont() +{ + QFont f = selectedFont(); + + if ( d->m_preview ) + d->m_preview->setFont ( f ); + + emit fontSelected ( f ); +} + +/** + * Return the selected font + */ +QFont OFontSelector::selectedFont() +{ + int ffa = d->m_font_family_list->currentItem(); + int fst = d->m_font_style_list->currentItem(); + int fsi = d->m_font_size_list->currentItem(); + + FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa ); + + if ( fli ) + { + return d->m_fdb. font ( fli->family(), \ + fst >= 0 ? fli->styles() [fst] : QString::null, \ + fsi >= 0 ? fli->sizes() [fsi] : 10, \ + d->m_fdb. charSets ( fli->family()) [0] ); + } + else + return QFont(); +} + +void OFontSelector::resizeEvent ( QResizeEvent *re ) +{ + if ( d->m_preview ) + { + d->m_preview->setMinimumHeight ( 1 ); + d->m_preview->setMaximumHeight ( 32767 ); + } + + QWidget::resizeEvent ( re ); + + if ( d->m_preview ) + d->m_preview->setFixedHeight ( d->m_preview->height()); + +} diff --git a/libopie2/opieui/ofontselector.h b/libopie2/opieui/ofontselector.h new file mode 100644 index 0000000..ad51819 --- a/dev/null +++ b/libopie2/opieui/ofontselector.h @@ -0,0 +1,104 @@ +/* + This file is part of the Opie Project + Copyright (C) Robert Griebl <sandman@handhelds.org> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OFONTSELECTOR_H +#define OFONTSELECTOR_H + +/* QT */ +#include <qwidget.h> + +class QListBox; + +namespace Opie +{ + +class OFontSelectorPrivate; + +/** + * This class lets you chose a Font out of a list of Fonts. + * It can show a preview too. This selector will use all available + * fonts + * + * + * @short A widget to select a font + * @see QWidget + * @see QFont + * @author Rober Griebl + */ +class OFontSelector : public QWidget +{ + Q_OBJECT + +public: + OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); + virtual ~OFontSelector ( ); + + bool selectedFont ( QString &family, QString &style, int &size ); + bool selectedFont ( QString &family, QString &style, int &size, QString &charset ); + + QFont selectedFont ( ); + + bool setSelectedFont ( const QFont & ); + bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 ); + + QString fontFamily ( ) const; + QString fontStyle ( ) const; + int fontSize ( ) const; + QString fontCharSet ( ) const; + +signals: + /** + * This signal gets emitted when a font got chosen + */ + void fontSelected ( const QFont & ); + +protected slots: + /** @internal */ + virtual void fontFamilyClicked ( int ); + /** @internal */ + virtual void fontStyleClicked ( int ); + /** @internal */ + virtual void fontSizeClicked ( int ); + +protected: + virtual void resizeEvent ( QResizeEvent *re ); + +private: + void loadFonts ( QListBox * ); + + void changeFont ( ); + +private: + OFontSelectorPrivate *d; +}; + +}; + +#endif + diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro index 41db153..b9bf203 100644 --- a/libopie2/opieui/opieui.pro +++ b/libopie2/opieui/opieui.pro @@ -1,55 +1,65 @@ TEMPLATE = lib CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/lib HEADERS = ocheckitem.h \ oclickablelabel.h \ odialog.h \ ofileselector.h \ ofileselector_p.h \ ofiledialog.h \ ofileview.h \ + ofontselector.h \ oimageeffect.h \ olistview.h \ opixmapeffect.h \ opopupmenu.h \ opixmapprovider.h \ oselector.h \ + otabinfo.h \ + otabbar.h \ + otabwidget.h \ + otimepicker.h \ oversatileview.h \ oversatileviewitem.h \ omessagebox.h \ oresource.h \ otaskbarapplet.h \ oseparator.h SOURCES = ocheckitem.cpp \ oclickablelabel.cpp \ ofileselector.cpp \ ofiledialog.cpp \ + ofontselector.cpp \ oimageeffect.cpp \ olistview.cpp \ opixmapeffect.cpp \ opopupmenu.cpp \ opixmapprovider.cpp \ oselector.cpp \ + otabbar.cpp \ + otabwidget.cpp \ + otimepicker.cpp \ oversatileview.cpp \ oversatileviewitem.cpp \ odialog.cpp \ oresource.cpp \ otaskbarapplet.cpp \ oseparator.cpp -INTERFACES = +INTERFACES = otimepickerbase.ui + TARGET = opieui2 -VERSION = 1.8.3 +VERSION = 1.8.4 INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lopiecore2 !contains( platform, x11 ) { include ( $(OPIEDIR)/include.pro ) } contains( platform, x11 ) { LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib diff --git a/libopie2/opieui/otabbar.cpp b/libopie2/opieui/otabbar.cpp new file mode 100644 index 0000000..cd3a34b --- a/dev/null +++ b/libopie2/opieui/otabbar.cpp @@ -0,0 +1,83 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include <opie2/otabbar.h> + +using namespace Opie; + +OTabBar::OTabBar( QWidget *parent , const char *name ) + :QTabBar( parent, name ) +{} + +void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const +{ + + QRect r = br; + if ( t->iconset) + { + QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled; + if ( mode == QIconSet::Normal && has_focus ) + { + mode = QIconSet::Active; + } + QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode ); + int pixw = pixmap.width(); + int pixh = pixmap.height(); + r.setLeft( r.left() + pixw + 2 ); + p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap ); + } + + QRect tr = r; + if ( t->id == currentTab() ) + { + tr.setBottom( tr.bottom() - style().defaultFrameWidth() ); + } + + if ( t->enabled && isEnabled() ) + { + p->setPen( colorGroup().foreground() ); + p->drawText( tr, AlignCenter | ShowPrefix, t->label ); + } + else if ( style() == MotifStyle ) + { + p->setPen( palette().disabled().foreground() ); + p->drawText( tr, AlignCenter | ShowPrefix, t->label ); + } + else + { + p->setPen( colorGroup().light() ); + QRect wr = tr; + wr.moveBy( 1, 1 ); + p->drawText( wr, AlignCenter | ShowPrefix, t->label ); + p->setPen( palette().disabled().foreground() ); + p->drawText( tr, AlignCenter | ShowPrefix, t->label ); + } +} diff --git a/libopie2/opieui/otabbar.h b/libopie2/opieui/otabbar.h new file mode 100644 index 0000000..2f35c85 --- a/dev/null +++ b/libopie2/opieui/otabbar.h @@ -0,0 +1,85 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef OTABBAR_H +#define OTABBAR_H + +/* QT */ +#include <qtabbar.h> + +namespace Opie +{ + +/** + * @class OTabBar + * @brief The OTabBar class is a derivative of QTabBar. + * + * OTabBar is a derivation of TrollTech's QTabBar which provides + * a row of tabs for selection. The only difference between this + * class and QTabBar is that there is no dotted line box around + * the label of the tab with the current focus. + */ +class OTabBar : public QTabBar +{ + Q_OBJECT + +public: + /** + * @fn OTabBar( QWidget *parent = 0, const char *name = 0 ) + * @brief Object constructor. + * + * @param parent Pointer to parent of this control. + * @param name Name of control. + * + * Constructs a new OTabBar control with parent and name. + */ + OTabBar( QWidget * = 0, const char * = 0 ); + +protected: + /** + * @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const + * @brief Internal function to draw a tab's label. + * + * @param p Pointer to QPainter used for drawing. + * @param br QRect providing region to draw label in. + * @param t Tab to draw label for. + * @param has_focus Boolean value not used, retained for compatibility reasons. + */ + void paintLabel( QPainter *, const QRect &, QTab *, bool ) const; + +private: + class Private; + Private *d; +}; + +}; + +#endif diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h new file mode 100644 index 0000000..4a6ce14 --- a/dev/null +++ b/libopie2/opieui/otabinfo.h @@ -0,0 +1,140 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef OTABINFO_H +#define OTABINFO_H + +/* QT */ +#include <qlist.h> +#include <qstring.h> + +class QWidget; + +namespace Opie +{ + +/** + * @class OTabInfo + * @brief The OTabInfo class is used internally by OTabWidget to keep track + * of widgets added to the control. + * + * OTabInfo provides the following information about a widget added to an + * OTabWidget control: + * + * ID - integer tab bar ID + * Control - QWidget pointer to child widget + * Label - QString text label for OTabWidget selection control + * Icon - QString name of icon file + */ +class OTabInfo +{ +public: + /** + * @fn OTabInfo() + * @brief Object constructor. + * + * @param parent Pointer to parent of this control. + * @param name Name of control. + * @param s Style of widget selection control. + * @param p Position of the widget selection control. + */ + OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {} + + /** + * @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) + * @brief Object constructor. + * + * @param id TabBar identifier for widget. + * @param control QWidget pointer to widget. + * @param icon QString name of icon file. + * @param label QString text label for OTabWidget selection control. + */ + OTabInfo( int id, QWidget *control, const QString &icon, const QString &label ) + : i( id ), c( control ), p( icon ), l( label ) {} + + /** + * @fn id()const + * @brief Returns TabBar ID. + */ + int id() const { return i; } + + /** + * @fn label()const + * @brief Returns text label for widget. + */ + const QString &label() const { return l; } + + /** + * @fn setLabel( const QString &label ) + * @brief Set label for tab. + * + * @param label QString text label for OTabWidget selection control. + */ + void setLabel( const QString &label ) { l = label; } + + /** + * @fn control()const + * @brief Returns pointer to widget. + */ + QWidget *control() const { return c; } + + /** + * @fn icon()const + * @brief Returns name of icon file. + */ + const QString &icon() const { return p; } + + /** + * @fn setIcon( const QString &icon ) + * @brief Set icon for tab. + * + * @param icon QString name of icon file. + */ + void setIcon( const QString &icon ) { p = icon; } + +private: + int i; + QWidget *c; + QString p; + QString l; + class Private; + Private *d; +}; + +/** + * @class OTabInfoList + * @brief A list of OTabInfo objects used by OTabWidget. + */ +typedef QList<OTabInfo> OTabInfoList; + +}; + +#endif diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp new file mode 100644 index 0000000..ec6af9d --- a/dev/null +++ b/libopie2/opieui/otabwidget.cpp @@ -0,0 +1,423 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include <opie2/otabwidget.h> + +/* OPIE */ +#include <qpe/applnk.h> +#include <qpe/config.h> +#include <qpe/resource.h> +#include <opie2/otabbar.h> + +/* QT */ +#include <qcombobox.h> +#include <qwidgetstack.h> + +using namespace Opie; + +OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) + : QWidget( parent, name ) +{ + if ( s == Global ) + { + Config config( "qpe" ); + config.setGroup( "Appearance" ); + s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); + if ( s <= Global || s > IconList) + { + s = IconTab; + } + QString pos = config.readEntry( "TabPosition", "Top"); + if ( pos == "Bottom" ) + { + p = Bottom; + } + else + { + p = Top; + } + } + + widgetStack = new QWidgetStack( this, "widgetstack" ); + widgetStack->setFrameStyle( QFrame::NoFrame ); + widgetStack->setLineWidth( style().defaultFrameWidth() ); + + tabBarStack = new QWidgetStack( this, "tabbarstack" ); + + tabBar = new OTabBar( tabBarStack, "tabbar" ); + tabBarStack->addWidget( tabBar, 0 ); + connect( tabBar, SIGNAL( selected( int ) ), this, SLOT( slotTabBarSelected( int ) ) ); + + tabList = new QComboBox( false, tabBarStack, "tablist" ); + tabBarStack->addWidget( tabList, 1 ); + connect( tabList, SIGNAL( activated( int ) ), this, SLOT( slotTabListSelected( int ) ) ); + + tabBarPosition = p; + setTabStyle( s ); + setTabPosition( p ); + + currTab= 0x0; +} + +OTabWidget::~OTabWidget() +{} + +void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) +{ + QPixmap iconset = loadSmooth( icon ); + + QTab *tab = new QTab(); + if ( tabBarStyle == IconTab ) + { + tab->label = QString::null; + } + else + { + tab->label = label; + } + if ( tabBarStyle == IconTab || tabBarStyle == IconList ) + { + tab->iconset = new QIconSet( iconset ); + } + int tabid = tabBar->addTab( tab ); + + if ( tabBarStyle == IconTab || tabBarStyle == IconList ) + { + tabList->insertItem( iconset, label, -1 ); + } + else + { + tabList->insertItem( label ); + } + + widgetStack->addWidget( child, tabid ); + widgetStack->raiseWidget( child ); + widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); + + OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); + tabs.append( tabinfo ); + selectTab( tabinfo ); +} + +void OTabWidget::removePage( QWidget *childwidget ) +{ + if ( childwidget ) + { + OTabInfo *tab = tabs.first(); + while ( tab && tab->control() != childwidget ) + { + tab = tabs.next(); + } + if ( tab && tab->control() == childwidget ) + { + tabBar->setTabEnabled( tab->id(), FALSE ); + tabBar->removeTab( tabBar->tab( tab->id() ) ); + int i = 0; + while ( i < tabList->count() && tabList->text( i ) != tab->label() ) + { + i++; + } + if ( tabList->text( i ) == tab->label() ) + { + tabList->removeItem( i ); + } + widgetStack->removeWidget( childwidget ); + tabs.remove( tab ); + delete tab; + currTab = tabs.current(); + if ( !currTab ) + { + widgetStack->setFrameStyle( QFrame::NoFrame ); + } + + setUpLayout(); + } + } +} + +void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) +{ + OTabInfo *currtab = tabs.first(); + while ( currtab && currtab->control() != widget ) + { + currtab = tabs.next(); + } + if ( currtab && currtab->control() == widget ) + { + QTab *tab = tabBar->tab( currtab->id() ); + QPixmap icon( loadSmooth( iconset ) ); + tab->setText( label ); + if ( tabBarStyle == IconTab ) + tab->setIconSet( icon ); + int i = 0; + while ( i < tabList->count() && tabList->text( i ) != currtab->label() ) + { + i++; + } + if ( i < tabList->count() && tabList->text( i ) == currtab->label() ) + { + if ( tabBarStyle == IconTab || tabBarStyle == IconList ) + { + tabList->changeItem( icon, label, i ); + } + else + { + tabList->changeItem( label, i ); + } + } + currtab->setLabel( label ); + currtab->setIcon( iconset ); + } + setUpLayout(); +} + +void OTabWidget::setCurrentTab( QWidget *childwidget ) +{ + OTabInfo *currtab = tabs.first(); + while ( currtab && currtab->control() != childwidget ) + { + currtab = tabs.next(); + } + if ( currtab && currtab->control() == childwidget ) + { + selectTab( currtab ); + } +} + +void OTabWidget::setCurrentTab( const QString &tabname ) +{ + OTabInfo *newtab = tabs.first(); + while ( newtab && newtab->label() != tabname ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->label() == tabname ) + { + selectTab( newtab ); + } +} + +void OTabWidget::setCurrentTab(int tabindex) +{ + OTabInfo *newtab = tabs.first(); + while ( newtab && newtab->id() != tabindex ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->id() == tabindex ) + { + selectTab( newtab ); + } +} + + +OTabWidget::TabStyle OTabWidget::tabStyle() const +{ + return tabBarStyle; +} + +void OTabWidget::setTabStyle( TabStyle s ) +{ + tabBarStyle = s; + if ( tabBarStyle == TextTab || tabBarStyle == IconTab ) + { + QTab *currtab; + for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) + { + currtab = tabBar->tab( tabinfo->id() ); + if ( tabBarStyle == IconTab ) + { + currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); + if ( tabinfo == currTab ) + currtab->setText( tabinfo->label() ); + else + currtab->setText( QString::null ); + } + else + { + currtab->iconset = 0x0; + currtab->setText( tabinfo->label() ); + } + } + tabBarStack->raiseWidget( tabBar ); + } + else if ( tabBarStyle == TextList || tabBarStyle == IconList ) + { + tabList->clear(); + for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() ) + { + if ( tabBarStyle == IconList ) + { + tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); + } + else + { + tabList->insertItem( tabinfo->label() ); + } + } + tabBarStack->raiseWidget( tabList ); + } + setUpLayout(); +} + +OTabWidget::TabPosition OTabWidget::tabPosition() const +{ + return tabBarPosition; +} + +void OTabWidget::setTabPosition( TabPosition p ) +{ + tabBarPosition = p; + if ( tabBarPosition == Top ) + { + tabBar->setShape( QTabBar::RoundedAbove ); + } + else + { + tabBar->setShape( QTabBar::RoundedBelow ); + } + setUpLayout(); +} + +void OTabWidget::slotTabBarSelected( int id ) +{ + OTabInfo *newtab = tabs.first(); + while ( newtab && newtab->id() != id ) + { + newtab = tabs.next(); + } + if ( newtab && newtab->id() == id ) + { + selectTab( newtab ); + } +} + +void OTabWidget::slotTabListSelected( int index ) +{ + OTabInfo *newtab = tabs.at( index ); + if ( newtab ) + { + selectTab( newtab ); + } +} + +QPixmap OTabWidget::loadSmooth( const QString &name ) +{ + QPixmap p; + p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); + return p; +} + +void OTabWidget::selectTab( OTabInfo *tab ) +{ + if ( tabBarStyle == IconTab ) + { + if ( currTab ) + { + tabBar->tab( currTab->id() )->setText( QString::null ); + setUpLayout(); + } + tabBar->tab( tab->id() )->setText( tab->label() ); + tabBar->setCurrentTab( tab->id() ); + setUpLayout(); + tabBar->update(); + } + else + { + tabBar->setCurrentTab( tab->id() ); + } + + widgetStack->raiseWidget( tab->control() ); + + emit currentChanged( tab->control() ); + + currTab = tab; +} + +void OTabWidget::setUpLayout() +{ + tabBar->layoutTabs(); + QSize t( tabBarStack->sizeHint() ); + if ( tabBarStyle == IconTab ) + { + if ( t.width() > width() ) + t.setWidth( width() ); + } + else + { + t.setWidth( width() ); + } + int lw = widgetStack->lineWidth(); + if ( tabBarPosition == Bottom ) + { + tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); + widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); + } + else + { + tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); + widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); + } + + if ( autoMask() ) + updateMask(); +} + +QSize OTabWidget::sizeHint() const +{ + QSize s( widgetStack->sizeHint() ); + QSize t( tabBarStack->sizeHint() ); + return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() ); +} + +void OTabWidget::resizeEvent( QResizeEvent * ) +{ + setUpLayout(); +} + +int OTabWidget::currentTab() +{ + if ( currTab ) + { + return currTab->id(); + } + return -1; +} + +QWidget* OTabWidget::currentWidget()const +{ + if ( currTab ) + { + return currTab->control(); + } + + return 0; +} diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h new file mode 100644 index 0000000..51d1c6d --- a/dev/null +++ b/libopie2/opieui/otabwidget.h @@ -0,0 +1,295 @@ +/* + This file is part of the Opie Project + + Copyright (c) 2002 Dan Williams <williamsdr@acm.org> + =. + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef OTABWIDGET_H +#define OTABWIDGET_H + +/* OPIE */ +#include <opie2/otabinfo.h> + +/* QT */ +#include <qwidget.h> +#include <qlist.h> + +using namespace Opie; + +class QComboBox; +class QPixmap; +class QTabBar; +class QWidgetStack; + +namespace Opie +{ + +class OTabBar; + +/** + * @class OTabWidget + * @brief The OTabWidget class provides a stack of widgets. + * + * OTabWidget is a derivation of TrollTech's QTabWidget which provides + * a stack of widgets. Widgets can be selected using either a tab bar or + * drop down list box. + * + * The normal way to use OTabWidget is to do the following in the + * constructor: + * - Create a OTabWidget. + * - Create a QWidget for each of the pages in the control, insert + * children into it, set up geometry management for it, and use addTab() + * to add the widget. + */ +class OTabWidget : public QWidget +{ + Q_OBJECT +public: + +/** + * @enum TabStyle + * @brief Defines how the widget selection control is displayed. + * + * Valid values: + * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) + * - TextTab: Tabbed widget selection with text labels + * - IconTab: Tabbed widget selection with icon labels, text label for active widget + * (similar to Opie launcher) + * - TextList: Drop down list widget selection with text labels + * - IconList: Drop down list widget selection with icon & text labels + */ + enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; + +/** + * @enum TabPosition + * @brief Defines where the widget selection control is drawn. + * + * Valid values: + * - Top: Widget selection control is drawn above widgets + * - Bottom: Widget selection control is drawn below widgets + */ + enum TabPosition { Top, Bottom }; + +/** + * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) + * @brief Object constructor. + * + * @param parent Pointer to parent of this control. + * @param name Name of control. + * @param s Style of widget selection control. + * @param p Position of the widget selection control. + * + * Constructs a new OTabWidget control with parent and name. The style and position parameters + * determine how the widget selection control will be displayed. + */ + // FIXME WFlags? -zecke + OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); + +/** + * @fn ~OTabWidget() + * @brief Object destructor. + */ + ~OTabWidget(); + +/** + * @fn addTab( QWidget *child, const QString &icon, const QString &label ) + * @brief Add new widget to control. + * + * @param child Widget control. + * @param icon Path to icon. + * @param label Text label. + */ + void addTab( QWidget *, const QString &, const QString & ); + +/** + * @fn removePage( QWidget *widget ) + * @brief Remove widget from control. Does not delete widget. + * + * @param widget Widget control to be removed. + */ + /* ### Page vs. Tab.. yes the widget is a Page but then is addTab wrong -zecke */ + void removePage( QWidget * ); + +/** + * @fn changeTab( QWidget *widget, const QString &icon, const QString &label ) + * @brief Change text and/or icon for existing tab + * + * @param child Widget control. + * @param icon Path to icon. + * @param label Text label. + */ + void changeTab( QWidget *, const QString &, const QString & ); + +/** + * @fn tabStyle()const + * @brief Returns current widget selection control style. + */ + TabStyle tabStyle() const; + +/** + * @fn setTabStyle( TabStyle s ) + * @brief Set the current widget selection control style. + * + * @param s New style to be used. + */ + void setTabStyle( TabStyle ); + +/** + * @fn tabPosition()const + * @brief Returns current widget selection control position. + */ + TabPosition tabPosition() const; + +/** + * @fn setTabPosition( TabPosition p ) + * @brief Set the current widget selection control position. + * + * @param p New position of widget selection control. + */ + void setTabPosition( TabPosition ); + +/** + * @fn setCurrentTab( QWidget *childwidget ) + * @brief Selects and brings to top the desired widget by using widget pointer. + * + * @param childwidget Widget to select. + */ + void setCurrentTab( QWidget * ); + +/** + * @fn setCurrentTab( const QString &tabname ) + * @brief Selects and brings to top the desired widget, by using label. + * + * @param tabname Text label for widget to select. + */ + void setCurrentTab( const QString & ); + +/** + * @fn setCurrentTab( int ) + * @brief Selects and brings to top the desired widget, by using id. + * + * @param tab id for widget to select. + */ + void setCurrentTab(int); + +/** + * @fn sizeHint()const + * @brief Reimplemented for internal purposes. + */ + QSize sizeHint() const; + +/** + * @fn currentTab( ) + * @brief returns current tab id. + */ + // ### make const + int currentTab()/* const */; +/** + * @brief returns the current page of the active tab + * + * @since 1.2 + */ + QWidget* currentWidget()const; + +protected: + +/** + * @fn resizeEvent( QResizeEvent * ) + * @brief Reimplemented for internal purposes. + */ + void resizeEvent( QResizeEvent * ); + +private: + OTabInfoList tabs; + OTabInfo *currTab; + + TabStyle tabBarStyle; + TabPosition tabBarPosition; + + QWidgetStack *tabBarStack; + OTabBar *tabBar; + QComboBox *tabList; + + QWidgetStack *widgetStack; + class Private; + Private* d; + +/** + * @fn loadSmooth( const QString &name ) + * @brief Loads icon for widget. + * + * @param name Name of icon image file. + */ + QPixmap loadSmooth( const QString & ); + +/** + * @fn selectTab( OTabInfo *tab ) + * @brief Internal function to select desired widget. + * + * @param tab Pointer to data for widget. + */ + void selectTab( OTabInfo * ); + +/** + * @fn setUpLayout() + * @brief Internal function to adjust layout. + */ + void setUpLayout(); + + +signals: +/** + * @fn currentChanegd( QWidget *widget ) + * @brief This signal is emitted whenever the widget has changed. + * + * @param widget Pointer to new current widget. + */ + void currentChanged( QWidget * ); + +private slots: + +/** + * @fn slotTabBarSelected( int id ) + * @brief Slot which is called when a tab is selected. + * + * @param id ID of widget selected. + */ + void slotTabBarSelected( int ); + +/** + * @fn slotTabListSelected( int index ) + * @brief Slot which is called when a drop down selection is made. + * + * @param id Index of widget selected. + */ + void slotTabListSelected( int ); +}; + +}; + +#endif diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp new file mode 100644 index 0000000..9f9f2c2 --- a/dev/null +++ b/libopie2/opieui/otimepicker.cpp @@ -0,0 +1,295 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/* QT */ +#include <qbuttongroup.h> +#include <qlayout.h> +#include <qlineedit.h> +#include <qstring.h> +#include <qtoolbutton.h> + +/* OPIE */ +#include <opie2/otimepicker.h> + +using namespace Opie; + +/** + * Constructs the widget + * @param parent The parent of the OTimePicker + * @param name The name of the object + * @param fl Window Flags + */ +OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::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))); + } +} + +/** + * This method return the current time + * @return the time + */ +QTime OTimePicker::time()const +{ + return tm; +} + +void OTimePicker::slotHour(bool b) +{ + + OClickableLabel *r = (OClickableLabel *) sender(); + + if (b) + { + QValueListIterator<OClickableLabel *> 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<OClickableLabel *> 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); + } + +} + +/** + * Method to set the time. No signal gets emitted during this method call + * Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... ) + * @param t The time to be set + */ +void OTimePicker::setTime( const QTime& t) +{ + setTime( t.hour(), t.minute() ); +} + +/** + * Method to set the time. No signal gets emitted during this method call + * @param h The hour + * @param m The minute. Minutes need to set by 5 minute steps + */ +void OTimePicker::setTime( int h, int m ) +{ + setHour(h); + setMinute(m); +} + +/* + * FIXME round minutes to the 5 minute arrangement -zecke + */ +/** + * Method to set the minutes + * @param m minutes + */ +void OTimePicker::setMinute(int m) +{ + + QString minute; + minute.sprintf("%.2d",m); + + QValueListIterator<OClickableLabel *> 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); +} + +/** + * Method to set the hour + */ +void OTimePicker::setHour(int h) +{ + + QString hour; + hour.sprintf("%.2d",h); + + QValueListIterator<OClickableLabel *> 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); +} + + +/** + * This is a modal Dialog. + * + * @param parent The parent widget + * @param name The name of the object + * @param fl Possible window flags + */ +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& ) ) ); + +} + +/** + * @return the time + */ +QTime OTimePickerDialog::time()const +{ + return m_time; +} + +/** + * Set the time to time + * @param time The time to be set + */ +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() ) ); + +} + +/** + * This method takes the current minute and tries to set hour + * to hour. This succeeds if the resulting date is valid + * @param hour The hour as a string + */ +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 ); + } + +} + +/** + * Method to set a new minute. It tries to convert the string to int and + * if the resulting date is valid a new date is set. + * @see setHour + */ +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/libopie2/opieui/otimepicker.h b/libopie2/opieui/otimepicker.h new file mode 100644 index 0000000..2da7773 --- a/dev/null +++ b/libopie2/opieui/otimepicker.h @@ -0,0 +1,125 @@ +/* + This file is part of the Opie Project + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> + =. Copyright (C) The Opie Team <opie-devel@handhelds.org> + .=l. + .>+-= + _;:, .> :=|. This program is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. 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 +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef OTIMEPICKER_H +#define OTIMEPICKER_H + +/* OPIE */ +#include <opie2/oclickablelabel.h> +#include "otimepickerbase.h" + +/* QT */ +#include <qwidget.h> +#include <qvaluelist.h> +#include <qdatetime.h> +#include <qdialog.h> + +using namespace Opie; + +// namespace Opie +// { + +/** + * A class to pick time. It uses clickable labels + * internally to allow a quick selection of a time. + * A time can be selected by two clicks of a user + * + * @short A widget to quickly pick a QTime + * @version 1.0 + * @see QWidget + * @see QTime + * @author Hakan Ardo, Stefan Eilers + */ +class OTimePicker: public QWidget +{ + Q_OBJECT + +public: + OTimePicker(QWidget* parent = 0, const char* name = 0, WFlags fl = 0); + +public slots: + void setHour(int h); + void setMinute(int m); + void setTime( const QTime& ); + void setTime( int h, int m ); + +public: + QTime time()const; + +private: + QValueList<OClickableLabel *> hourLst; + QValueList<OClickableLabel *> minuteLst; + QTime tm; + struct Private; + Private *d; + +private slots: + void slotHour(bool b); + void slotMinute(bool b); + +signals: + /** + * gets emitted when the time got changed by the user + */ + void timeChanged(const QTime &); +}; + +/** + * + * @short A small dialog to pick a time + * @version 1.0 + * @author Stefan Eilers + * + **/ + +class OTimePickerDialog: public OTimePickerDialogBase +{ + Q_OBJECT + +public: + OTimePickerDialog ( QWidget* parent = 0, const char* name = NULL, WFlags fl = 0 ); + ~OTimePickerDialog() { }; + + QTime time()const; + +public slots: + void setTime( const QTime& time ); + void setHour( const QString& hour ); + void setMinute( const QString& minute ); + +private: + QTime m_time; + class Private; + Private* d; +}; + +// }; + +#endif + diff --git a/libopie2/opieui/otimepickerbase.ui b/libopie2/opieui/otimepickerbase.ui new file mode 100644 index 0000000..3e7f2fb --- a/dev/null +++ b/libopie2/opieui/otimepickerbase.ui @@ -0,0 +1,292 @@ +<!DOCTYPE UI><UI> +<class>OTimePickerDialogBase</class> +<widget> + <class>QDialog</class> + <property stdset="1"> + <name>name</name> + <cstring>OTimePickerDialogBase</cstring> + </property> + <property stdset="1"> + <name>geometry</name> + <rect> + <x>0</x> + <y>0</y> + <width>210</width> + <height>137</height> + </rect> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>1</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>caption</name> + <string>OTimePickerDialogBase</string> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <vbox> + <property stdset="1"> + <name>margin</name> + <number>5</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>4</number> + </property> + <widget> + <class>QFrame</class> + <property stdset="1"> + <name>name</name> + <cstring>Frame10</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>1</hsizetype> + <vsizetype>7</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>NoFrame</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Raised</enum> + </property> + <property> + <name>layoutMargin</name> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>2</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer> + <property> + <name>name</name> + <cstring>Spacer4</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>MinimumExpanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget> + <class>QFrame</class> + <property stdset="1"> + <name>name</name> + <cstring>Frame4</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>4</hsizetype> + <vsizetype>4</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>frameShape</name> + <enum>Box</enum> + </property> + <property stdset="1"> + <name>frameShadow</name> + <enum>Sunken</enum> + </property> + <property> + <name>layoutMargin</name> + </property> + <property> + <name>layoutSpacing</name> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>4</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Time:</string> + </property> + </widget> + <widget> + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>hourField</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>4</hsizetype> + <vsizetype>0</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignHCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1_2</cstring> + </property> + <property stdset="1"> + <name>font</name> + <font> + <bold>1</bold> + </font> + </property> + <property stdset="1"> + <name>text</name> + <string>:</string> + </property> + </widget> + <widget> + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>minuteField</cstring> + </property> + <property stdset="1"> + <name>alignment</name> + <set>AlignHCenter</set> + </property> + <property> + <name>hAlign</name> + </property> + </widget> + </hbox> + </widget> + <spacer> + <property> + <name>name</name> + <cstring>Spacer5</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Horizontal</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>MinimumExpanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </hbox> + </widget> + <widget> + <class>QGroupBox</class> + <property stdset="1"> + <name>name</name> + <cstring>GroupBox1</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + </sizepolicy> + </property> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>title</name> + <string>Pick Time:</string> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" > + <class>OTimePicker</class> + <property stdset="1"> + <name>name</name> + <cstring>m_timePicker</cstring> + </property> + <property stdset="1"> + <name>sizePolicy</name> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + </sizepolicy> + </property> + </widget> + </grid> + </widget> + </vbox> +</widget> +<customwidgets> + <customwidget> + <class>OTimePicker</class> + <header location="local">otimepicker.h</header> + <sizehint> + <width>-1</width> + <height>-1</height> + </sizehint> + <container>0</container> + <sizepolicy> + <hordata>7</hordata> + <verdata>1</verdata> + </sizepolicy> + <pixmap>image0</pixmap> + </customwidget> +</customwidgets> +<images> + <image> + <name>image0</name> + <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data> + </image> +</images> +</UI> |