summaryrefslogtreecommitdiff
path: root/libopie/big-screen
authorzecke <zecke>2003-09-12 17:43:22 (UTC)
committer zecke <zecke>2003-09-12 17:43:22 (UTC)
commit730d32e606642b37c30a9cb28d6728543a2b6c89 (patch) (unidiff)
tree87409d891cba5885152c6d000e0ec4b3b8e400f0 /libopie/big-screen
parent420565dbf396c813e2e657ddf725af075564e59f (diff)
downloadopie-730d32e606642b37c30a9cb28d6728543a2b6c89.zip
opie-730d32e606642b37c30a9cb28d6728543a2b6c89.tar.gz
opie-730d32e606642b37c30a9cb28d6728543a2b6c89.tar.bz2
More implementation and thoughts
Diffstat (limited to 'libopie/big-screen') (more/less context) (show whitespace changes)
-rw-r--r--libopie/big-screen/omodalhelper.h199
1 files changed, 190 insertions, 9 deletions
diff --git a/libopie/big-screen/omodalhelper.h b/libopie/big-screen/omodalhelper.h
index 32d921d..c483403 100644
--- a/libopie/big-screen/omodalhelper.h
+++ b/libopie/big-screen/omodalhelper.h
@@ -29,6 +29,7 @@
29#ifndef HAZE_OMODAL_HELPER_H 29#ifndef HAZE_OMODAL_HELPER_H
30#define HAZE_OMODAL_HELPER_H 30#define HAZE_OMODAL_HELPER_H
31 31
32#include <qdialog.h>
32#include <qwidget.h> 33#include <qwidget.h>
33#include <qvaluelist.h> 34#include <qvaluelist.h>
34#include <qmap.h> 35#include <qmap.h>
@@ -40,9 +41,9 @@ class OModalHelperSignal;
40class QDialog; 41class QDialog;
41 42
42struct OModalHelperBase { 43struct OModalHelperBase {
43 virtual void done( TransactionID id, QWidget* ) = 0; 44 virtual void done( TransactionID ) = 0;
44 virtual void next( TransactionID, OModalHelperControler * ); 45 virtual void next( TransactionID ) = 0;
45 virtual void prev( TransactionID, OModalHelperControler * ); 46 virtual void prev( TransactionID ) = 0;
46}; 47};
47 48
48/** 49/**
@@ -65,7 +66,7 @@ struct OModalHelperBase {
65 * @author hOlgAr 66 * @author hOlgAr
66 * @version 0.01 67 * @version 0.01
67 */ 68 */
68template<class Dialog, class Record, typename Id = QString> 69template<class Dialog, class Record, typename Id = int>
69class OModalHelper : private OModalHelperBase{ 70class OModalHelper : private OModalHelperBase{
70 friend class OModalHelperSignal; 71 friend class OModalHelperSignal;
71 friend class OModalHelperControler; 72 friend class OModalHelperControler;
@@ -82,15 +83,34 @@ public:
82 void cancel(); 83 void cancel();
83 void cancel( TransactionID ); 84 void cancel( TransactionID );
84 85
85 void connect( QObject* rec, const char* slot ); 86 void connectDone( QObject* rec, const char* slot );
87 void connectAccepted( QObject* rec, const char* slot );
88 void connectRejected( QObject* rec, const char* slot );
86 89
87 TransactionID handle( const Record& rec = Record() ); 90 TransactionID handle( Id id, const Record& rec = Record() );
88 91
89 void edited( TransactionID, int what, const QString& data ); 92 void edited( TransactionID, int what, const QString& data );
90 93
91 Record record( TransactionID )const; 94 Record record( TransactionID )const;
92 RecordList done()const; 95 RecordList done()const;
93private: 96private:
97 virtual void done( TransactionID, QDialog* );
98 virtual void next( TransactionID, OModalHelperControler * );
99 virtual void prev( TransactionID, OModalHelperControler * );
100
101 Record nextRecord( TransactionID, int * )const;
102 Record prevRecord( TransactionID, int * )const;
103
104private:
105 OModalHelperDialog *queuedDialog()const; // generate or recycle
106 OModalHelperDialog *m_dialog;
107 OModalHelperSignal *m_signal; // our signal
108 OModalHelperControler *m_controler;
109 IdMap m_ids; // maps ids (uids) to a record
110 TransactionMap m_transactions; // activate transactions
111 TransactionMap m_done; // done and waiting for getting picked
112 DialogMap m_editing; // only used for New Mode
113 enum Mode m_mode; // the mode we're in
94}; 114};
95 115
96 116
@@ -112,19 +132,22 @@ private:
112class OModalHelperSignal : public QObject { 132class OModalHelperSignal : public QObject {
113 Q_OBJECT 133 Q_OBJECT
114public: 134public:
115 OModalHelperSignal(); 135 OModalHelperSignal(OModalHelperBase* base, QObject* parent);
116 136
117signals: 137signals:
118 done( int status, TransactionID transaction ); 138 done( int status, TransactionID transaction );
119 accpeted( TransactionID transaction ); 139 accepted( TransactionID transaction );
120 rejected( TransactionID transaction ); 140 rejected( TransactionID transaction );
141
142private:
143 OModalHelperBase* m_base;
121}; 144};
122 145
123 146
124class OModalHelperControler : public QObject { 147class OModalHelperControler : public QObject {
125 Q_OBJECT 148 Q_OBJECT
126public: 149public:
127 OModalHelperControler( TransactionID id ); 150 OModalHelperControler( OModalHelperBase* , QObject* parent);
128 virtual TransactionID transactionID()const; 151 virtual TransactionID transactionID()const;
129 void setTransactionID( TransactionID id ); 152 void setTransactionID( TransactionID id );
130 QDialog* dialog()const; 153 QDialog* dialog()const;
@@ -134,6 +157,164 @@ public slots:
134private: 157private:
135 QDialog *m_dia; 158 QDialog *m_dia;
136 TransactionID m_id; 159 TransactionID m_id;
160 OModalHelperBase *m_base;
161}
162
163class OModalQueueBar;
164class OModalQueuedDialog : public QDialog {
165 Q_OBJECT
166public:
167 OModalQueuedDialog(QWidget *mainWidget);
168 ~OModalQueuedDialog();
169
170 QDialog* centerDialog()const;
171
172 void setQueueBarEnabled( bool = true );
173 void setRecord( int record, int count );
174private:
175 OModalQueueBar *m_bar;
176};
177
178
179/*
180 * Tcpp Template Implementation
181 */
182
183/**
184 * This is the simple Template c'tor. It takes the mode
185 * this helper should operate in and the parent object.
186 * This helper will be deleted when the parent gets deleted
187 * or you delete it yourself.
188 *
189 * @param mode The mode this dialog should be in
190 * @param parent The parent QObject of this helper.
191 */
192template<class Dialog, class Record, typename Id>
193OModalHelper<Dialog, Record, Id>::OModalHelper( enum Mode mode, QObject* parent ) {
194 m_mode = mode;
195 m_signal = new OModalHelperSignal( this, parent );
196 m_controler = new OModalHelperControler( this, m_signal );
197}
198
199
200/**
201 * This functions looks for your record and sees if it is
202 * handled with this helper. Note that done and edited records
203 * will not be returned. But if you edit an already edited record
204 * the done record will be used
205 *
206 * @return true if the record is currenlty edited otherwise false
207 *
208 * @param Id The id which might be handled
209 */
210template<class Dialog, class Record, typename Id>
211bool OModalHelper<Dialog, Record, Id>::handles( Id id )const {
212 if ( m_transactions.isEmpty() )
213 return false;
214
215 TransactionMap::ConstIterator it = m_transactions.begin();
216 for ( ; it != m_transactions.end(); ++it )
217 if ( it.data() == id )
218 return true;
219
220 return false;
137} 221}
138 222
223/**
224 * Cancel will cancel all current operations and clear the list
225 * of done operations as well.
226 */
227template<class Dialog, class Record, typename Id>
228void OModalHelper<Dialog, Record, Id>::cancel() {
229 m_ids.clear();
230 m_done.clear();
231 m_transactions.clear();
232
233 /* we also need to remove the QDialogs */
234 /* and hide the queue dialog if present */
235 if (m_mode == New && !m_editing.isEmpty() ) {
236 for (DialogMap::Iterator it = m_editing.begin(); it != m_editing.end(); ++it )
237 delete it.key();
238 m_editing.clear();
239 }else if (m_dialog )
240 queuedDialog()->setRecord( 0, 0 );
241
242
243}
244
245
246/**
247 * This cancels editing of the record behind the Transaction Number
248 * Note that if editing is already done it will also be removed from this list
249 */
250template<class Dialog, class Record, typename Id>
251void OModalHelper::cancel( TransactionID tid ) {
252 /* wrong tid */
253 if (!m_transactions.contains( tid ) && !m_done.contains( tid) )
254 return;
255
256 if (m_mode == New )
257 /* reverse map eek */
258 for (DialogMap::Iterator it = m_editing.begin(); it != m_editing.end(); ++it )
259 if ( it.data() == tid ) {
260 it.key()->hide();
261 delete it.key();
262 it = m_editing.remove( it );
263 break;
264 }
265 else if ( m_transactions.contains( tid ) ) {
266 /* need to stop editing from the queue block */
267 /* if we're currently editing actiavte the previous */
268#if 0
269 if (tid == m_controler->transactionID() ) {
270
271 }
272#endif
273 /* now either activate the previous again or hide */
274 if (! m_transactions.count() -1 )
275 queuedDialog()->setRecord( 0, 0 );
276 else {
277 int pos;
278 Record rec = prevRecord( tid, &pos );
279 static_cast<Dialog*>( queuedDialog()->centerDialog() )->setRecord( rec );
280 queuedDialog()->setRecord( pos, m_transactions.count() );
281 }
282 }
283 /* now remove from the various maps */
284 m_ids.remove( m_transactions.contains( tid ) ? m_transactions[tid] : m_done[tid ] );
285
286 m_done.remove( tid );
287 m_transactions.remove( tid );
288}
289
290/**
291 * Connect to the done Signal. SIGNAL( done(int, TransactionID ) )
292 * This signal gets emitted whenever a Record was accepted or rejected
293 *
294 * @param rec The object where the slot belongs to
295 * @param slot The slot which should be called. See the needed parameter above
296 */
297template<class Dialog, class Record, typename Id>
298void OModalHelper<Dialog, Record, Id>::connectDone( QObject* rec, const char* slot ) {
299 QObject::connect(m_signal, SIGNAL(done(int, TransactionID) ),
300 rec, slot );
301}
302
303/**
304 * Connect to the accepted Signal. SIGNAL( done(int, TransactionID ) )
305 * This signal gets emitted whenever a Record was accepted or rejected
306 *
307 * @param rec The object where the slot belongs to
308 * @param slot The slot which should be called. See the needed parameter above
309 */
310template<class Dialog, class Record, typename Id>
311void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) {
312
313}
314
315
316template<class Dialog, class Record, typename Id>
317void OModalHelper<Dialog, Record, Id>::( QObject* rec, const char* slot ) {
318
319}
139#endif 320#endif