Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

templatedialogimpl.cpp

Go to the documentation of this file.
00001 /*
00002                              This file is part of the Opie Project
00003 
00004                              Copyright (C) Opie Team <opie-devel@handhelds.org>
00005               =.
00006             .=l.
00007            .>+-=
00008  _;:,     .>    :=|.         This program is free software; you can
00009 .> <`_,   >  .   <=          redistribute it and/or  modify it under
00010 :`=1 )Y*s>-.--   :           the terms of the GNU Library General Public
00011 .="- .-=="i,     .._         License as published by the Free Software
00012  - .   .-<_>     .<>         Foundation; either version 2 of the License,
00013      ._= =}       :          or (at your option) any later version.
00014     .%`+i>       _;_.
00015     .i_,=:_.      -<s.       This program is distributed in the hope that
00016      +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00017     : ..    .:,     . . .    without even the implied warranty of
00018     =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00019   _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00020 ..}^=.=       =       ;      Library General Public License for more
00021 ++=   -.     .`     .:       details.
00022 :     =  ...= . :.=-
00023  -.   .:....=;==+<;          You should have received a copy of the GNU
00024   -_. . .   )=.  =           Library General Public License along with
00025     --        :-=`           this library; see the file COPYING.LIB.
00026                              If not, write to the Free Software Foundation,
00027                              Inc., 59 Temple Place - Suite 330,
00028                              Boston, MA 02111-1307, USA.
00029 */
00030 
00031 #include <qlineedit.h>
00032 
00033 #include "mainwindow.h"
00034 #include "todoeditor.h"
00035 #include "todotemplatemanager.h"
00036 #include "templatedialogimpl.h"
00037 
00038 
00039 using namespace Todo;
00040 
00041 /* TRANSLATOR Todo::TemplateDialogImpl */
00042 
00043 namespace {
00044     class TemplateListItem : public QListViewItem {
00045     public:
00046         TemplateListItem( QListView*,
00047                           const QString& name,
00048                           const OPimTodo& );
00049         ~TemplateListItem();
00050 
00051         OPimTodo event()const;
00052         QString text()const;
00053         void setText(const QString& str );
00054         void setEvent( const OPimTodo& );
00055     private:
00056         QString m_name;
00057         OPimTodo m_ev;
00058     };
00059 
00060     /* implementation */
00061     TemplateListItem::TemplateListItem( QListView* view,
00062                                         const QString& text,
00063                                         const OPimTodo& ev )
00064         : QListViewItem( view ), m_name( text ), m_ev( ev )
00065     {
00066         QListViewItem::setText(0, m_name );
00067     }
00068     TemplateListItem::~TemplateListItem() {}
00069     OPimTodo TemplateListItem::event() const {
00070         return m_ev;
00071     }
00072     QString TemplateListItem::text()const {
00073         return m_name;
00074     }
00075     void TemplateListItem::setText( const QString& str ) {
00076         QListViewItem::setText(0, str );
00077         m_name = str;
00078     }
00079     void TemplateListItem::setEvent( const OPimTodo& ev) {
00080         m_ev = ev;
00081     }
00082 }
00083 
00084 TemplateDialogImpl::TemplateDialogImpl( MainWindow* win,
00085                                         TemplateManager* man )
00086     : TemplateDialog( win ), m_win( win), m_man( man )
00087 {
00088     /* fill the listview */
00089     /* not the fastest way.... */
00090     QStringList list = man->templates();
00091     for (QStringList::Iterator it = list.begin();
00092          it != list.end(); ++it  ) {
00093         new TemplateListItem( listView(), (*it), man->templateEvent( (*it) ) );
00094     }
00095     listView()->addColumn( QWidget::tr("Name") );
00096 
00097     connect( listView(), SIGNAL(clicked(QListViewItem*) ),
00098              this, SLOT(slotClicked(QListViewItem*) ) );
00099 }
00100 TemplateDialogImpl::~TemplateDialogImpl() {
00101 
00102 }
00103 void TemplateDialogImpl::slotAdd() {
00104     QString str = QWidget::tr("New Template %1").arg( listView()->childCount() );
00105     OPimTodo ev;
00106     m_man->addEvent(str, ev);
00107     new TemplateListItem( listView(), str, ev );
00108 }
00109 void TemplateDialogImpl::slotRemove() {
00110     if (!listView()->currentItem() )
00111         return;
00112 
00113     TemplateListItem* item = static_cast<TemplateListItem*>(  listView()->currentItem() );
00114     listView()->takeItem( item );
00115 
00116     m_man->removeEvent( item->text() );
00117 
00118     delete item;
00119 }
00120 void TemplateDialogImpl::slotEdit() {
00121     if ( !listView()->currentItem() )
00122         return;
00123 
00124     TemplateListItem* item = static_cast<TemplateListItem*>( listView()->currentItem() );
00125     OPimTodo ev = m_win->currentEditor()->edit( m_win, item->event() );
00126     if ( m_win->currentEditor()->accepted() ) {
00127         item->setEvent( ev );
00128         m_man->removeEvent( item->text() );
00129         m_man->addEvent( item->text(), ev );
00130     }
00131 }
00132 /*
00133  * we need to update
00134  * the text
00135  */
00136 
00137 void TemplateDialogImpl::slotReturn() {
00138     if ( !listView()->currentItem() )
00139         return;
00140 
00141     TemplateListItem* tbl = static_cast<TemplateListItem*>( listView()->currentItem() );
00142 
00143     if (tbl->text() != edit()->text() ) {
00144         m_man->removeEvent( tbl->text() );
00145         tbl->setText( edit()->text() );
00146         m_man->addEvent( tbl->text(), tbl->event() );
00147     }
00148 }
00149 /* update the lineedit when changing */
00150 void TemplateDialogImpl::slotClicked( QListViewItem* item) {
00151     if (!item)
00152         return;
00153 
00154     TemplateListItem* tbl = static_cast<TemplateListItem*>(item);
00155     edit()->setText( tbl->text() );
00156 }
00157 

Generated on Sat Nov 5 16:15:56 2005 for OPIE by  doxygen 1.4.2