author | zecke <zecke> | 2003-09-12 19:58:28 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-09-12 19:58:28 (UTC) |
commit | 14db240e82c6208277946c6a76fe1d41615d6804 (patch) (side-by-side diff) | |
tree | d895f6fa948644ca484f04609c3b1a7c06f59894 | |
parent | 730d32e606642b37c30a9cb28d6728543a2b6c89 (diff) | |
download | opie-14db240e82c6208277946c6a76fe1d41615d6804.zip opie-14db240e82c6208277946c6a76fe1d41615d6804.tar.gz opie-14db240e82c6208277946c6a76fe1d41615d6804.tar.bz2 |
Add the implementation for non template objects
And only 10 and 1/2 methods to implement
-rw-r--r-- | libopie/big-screen/omodalhelper.cpp | 160 | ||||
-rw-r--r-- | libopie/big-screen/omodalhelper.h | 121 |
2 files changed, 263 insertions, 18 deletions
diff --git a/libopie/big-screen/omodalhelper.cpp b/libopie/big-screen/omodalhelper.cpp new file mode 100644 index 0000000..e3d1c70 --- a/dev/null +++ b/libopie/big-screen/omodalhelper.cpp @@ -0,0 +1,160 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org> + .>+-= + _;:, .> :=|. This library 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 library 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 <qpushbutton.h> +#include <qvbox.h> +#include <qlayout.h> +#include <qlabel.h> + +#include "omodalhelper.h" + + +/* SIgnal handling */ +OModalHelperSignal::OModalHelperSignal( OModalHelperBase* base, QObject* parent ) + : QObject( parent, "OModal Helper Signal" ), m_base( base ) { +} + +OModalHelperSignal::~OModalHelperSignal() { + /* special the ancestor deletes its creator */ + delete m_base; +} + + +/* Helper Controler */ +/* + * the dialogs signal will be slotted here + * and we will call into m_base + */ +OModalHelperControler::OModalHelperControler( OModalHelperBase* base, QObject* parent ) + : QObject(parent, "OModal Helper Controler" ), m_base( base ), m_dia( 0 ), m_id( -1 ) +{ +} + +TransactionID OModalHelperControler::transactionID()const { + return m_id; +} + +void OModalHelperControler::setTransactionID( TransactionID id ) { + m_dia = 0; + m_id = id; +} + +QDialog* OModalHelperControler::dialog()const { + return m_dia; +} + +/* + * If we're in the New mode we will map the QDialog + * to the TransactionID + */ +void OModalHelperControler::done( int result ) { + if ( sender() && !sender()->isA("OModalQueuedDialog") ) + m_dia = static_cast<QDialog*>( sender() ); + + m_base->done( m_id ); +} + +void OModalHelperControler::next() { + m_base->next( m_id ); +} + +void OModalHelperControler::prev() { + m_base->prev( m_id ); +} + +/* The Queued Dialog inclusive QueuedBar */ +struct OModalQueueBar : public QHBox { + QPushButton* next; + QPushButton* prev; + QLabel * label; + + OModalQueueBar( QWidget* parent ); + void setText( const QString& str ); +}; + +OModalQueueBar::OModalQueueBar( QWidget* parent ) + : QWidget( parent, "OModal Queue Bar" ) { + prev = new QPushButton( this ); + prev->setText( OModalQueuedDialog::tr("Prev") ); + + label = new QLabel(this); + + next = new QPushButton( this ); + next->setText( OModalQueuedDialog::tr("Next") ); +} + +void OModalQueueBar::setText( const QString& str ) { + label->setText( str ); +} + + +OModalQueuedDialog::OModalQueuedDialog( QDialog* mainWidget ) + : QDialog(0, "OModal Queued Dialog" ) +{ + QVBoxLayout *lay = new QVBoxLayout( this ); + + m_bar = new OModalQueueBar( this ); + lay->addWidget( m_bar ); + + m_center = mainWidget; + m_center->reparent(this, 0, QPoint(0, 0) ); + lay->addWidget( m_center ); + + + connect(m_bar->next, SIGNAL(clicked() ), this, + SIGNAL(next() ) ); + connect(m_bar->prev, SIGNAL(clicked() ), this, + SIGNAL(prev() ) ); + +} + +OModalQueuedDialog::~OModalQueuedDialog() { +} + +QDialog* OModalQueuedDialog::centerDialog()const { + return m_center; +} + +void OModalQueuedDialog::setQueueBarEnabled( bool b) { + /* in Qt3 use setEnabled( bool ) */ + if (b) + m_bar->show(); + else + m_bar->hide(); +} + +void OModalQueuedDialog::setRecord( int record, int count ) { + if (!record && !count ) { + hide(); + return; + }else + show(); + + m_bar->setText( tr("Editing record %1 out of %2", + "Shows the current edited record out of an array of records").arg( record ). arg( count ) ); +} diff --git a/libopie/big-screen/omodalhelper.h b/libopie/big-screen/omodalhelper.h index c483403..bc20d10 100644 --- a/libopie/big-screen/omodalhelper.h +++ b/libopie/big-screen/omodalhelper.h @@ -56,3 +56,6 @@ struct OModalHelperBase { * the signals contains the status and id of the item and then you - * can fetch it. + * need fetch it. + * Handled Records will stay available until the first call to retrieve + * either the record via the TransactionID or via the QValueList<Record>. Note + * that most functions do not take handled records into account. * Also if you edit an record external you can tell this class and it'll @@ -81,2 +84,3 @@ public: bool handles( Id id)const; + TransactionID transactionID( Id id)const; @@ -96,5 +100,5 @@ public: private: - virtual void done( TransactionID, QDialog* ); - virtual void next( TransactionID, OModalHelperControler * ); - virtual void prev( TransactionID, OModalHelperControler * ); + virtual void done( TransactionID ); + virtual void next( TransactionID ); + virtual void prev( TransactionID ); @@ -109,2 +113,3 @@ private: IdMap m_ids; // maps ids (uids) to a record + IdMap m_doneIds; TransactionMap m_transactions; // activate transactions @@ -135,2 +140,3 @@ public: OModalHelperSignal(OModalHelperBase* base, QObject* parent); + ~OModalHelperSignal(); @@ -155,3 +161,5 @@ public: public slots: - virtual done(int result ); + virtual void done(int result ); + virtual void next(); + virtual void prev(); private: @@ -162,3 +170,3 @@ private: -class OModalQueueBar; +struct OModalQueueBar; class OModalQueuedDialog : public QDialog { @@ -166,3 +174,3 @@ class OModalQueuedDialog : public QDialog { public: - OModalQueuedDialog(QWidget *mainWidget); + OModalQueuedDialog(QDialog *mainWidget); ~OModalQueuedDialog(); @@ -173,4 +181,10 @@ public: void setRecord( int record, int count ); + +signals: + void next(); + void prev(); + private: OModalQueueBar *m_bar; + QDialog *m_center; }; @@ -196,2 +210,3 @@ OModalHelper<Dialog, Record, Id>::OModalHelper( enum Mode mode, QObject* parent m_controler = new OModalHelperControler( this, m_signal ); + } @@ -201,5 +216,4 @@ OModalHelper<Dialog, Record, Id>::OModalHelper( enum Mode mode, QObject* parent * This functions looks for your record and sees if it is - * handled with this helper. Note that done and edited records - * will not be returned. But if you edit an already edited record - * the done record will be used + * handled with this helper. Note that done records + * will not be returned. * @@ -222,2 +236,19 @@ bool OModalHelper<Dialog, Record, Id>::handles( Id id )const { + +/** + * just like handles( Id ) but returns the TransactionId + */ +template<class Dialog, class Record, typename Id> +TransactionID OModalHelper<Dialog, Record, Id>::transactionID( Id id)const { + if ( m_transactions.isEmpty() ) + return false; + + TransactionMap::ConstIterator it = m_transactions.begin(); + for ( ; it != m_transactions.end(); ++it ) + if ( it.data() == id ) + return true; + + return false; +} + /** @@ -225,2 +256,3 @@ bool OModalHelper<Dialog, Record, Id>::handles( Id id )const { * of done operations as well. + * This also clears all done operations you did not popped */ @@ -229,2 +261,3 @@ void OModalHelper<Dialog, Record, Id>::cancel() { m_ids.clear(); + m_doneIds.clear(); m_done.clear(); @@ -241,3 +274,3 @@ void OModalHelper<Dialog, Record, Id>::cancel() { - + m_controler->setTransactionID( -1 ); } @@ -280,6 +313,11 @@ void OModalHelper::cancel( TransactionID tid ) { queuedDialog()->setRecord( pos, m_transactions.count() ); + m_controler->setTransactionID( tid ); } } - /* now remove from the various maps */ - m_ids.remove( m_transactions.contains( tid ) ? m_transactions[tid] : m_done[tid ] ); + /* now remove from the various maps done and currently editing map*/ + if (m_transactions.contains( tid ) ) + m_ids.remove( m_transactions[tid] ); + if (m_done.contains( tid ) ) + m_doneIds.remove( m_done[tid ] ); + @@ -303,4 +341,4 @@ void OModalHelper<Dialog, Record, Id>::connectDone( QObject* rec, const char* sl /** - * Connect to the accepted Signal. SIGNAL( done(int, TransactionID ) ) - * This signal gets emitted whenever a Record was accepted or rejected + * Connect to the accepted Signal. SIGNAL( accepted(TransactionID ) ) + * This signal gets emitted whenever a Record was accepted * @@ -310,11 +348,58 @@ void OModalHelper<Dialog, Record, Id>::connectDone( QObject* rec, const char* sl template<class Dialog, class Record, typename Id> -void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) { - +void OModalHelper<Dialog, Record, Id>::connectAccepted( QObject* rec, const char* slot ) { + QObject::connect(m_signal, SIGNAL(accepted(TransactionID) ), + rec, slot ); } +/** + * Same as the accepted method but this one gets emitted if the dialog + * got rejected. + * SIGNAL( rejected(TransactionID) ) + * + * @param rec The QObject of the slot + * @param slot The slot make sure the signature is correct + */ +template<class Dialog, class Record, typename Id> +void OModalHelper<Dialog, Record, Id>::connectRejected( QObject* rec, const char* slot ) { + QObject::connect(m_signal, SIGNAL(rejected(TransactionID) ), + rec, slot ); +} +/** + * Tell the helper to handle a record. If the record is currently handled + * it will be made active. + * Already handled record which are waiting getting popped are not taken into account + * Otherwise this helpers make the record editable. + * The record supplied needs to have a valid copy operator and constructor. + * In the case where the record is already present the parameter gets discarded. + * If you want the new record to be taken you need to cancel the Transaction first + * + * @param id The Identification of the Record. For PIM it would uid() + * @param rec The record we want to be edited + * + * @returns This functions returns the TransactionId assigned to the record + * + */ template<class Dialog, class Record, typename Id> -void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) { +TransactionID OModalHelper<Dialog, Record, Id>::handle( Id id, const Record& rec ) { + static TransactionID t_id = 0; + t_id++; + /* + *this method consists out of two parts divided each into New and Queued Mode. + * Either we have the dialog already, in this case we need to highlight the widget + * Or we need to add it. + */ + TransactionID tid = 0; + /* we already have the record lets see if it was done or not */ + if ( m_ids.contains( id ) ) { + + } + + /* fall through if the record is in the done list */ + tid = t_id; + + return; } + #endif |