author | zecke <zecke> | 2002-10-07 11:39:30 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-07 11:39:30 (UTC) |
commit | f11d4bda64b58abfebf77485d5d77143a10dc8c9 (patch) (unidiff) | |
tree | a4e80550c4abe867303553de608316941dd943f1 /core/pim/todo/templatedialogimpl.cpp | |
parent | c2cd5470fa3ec69394fa65ad16ab29a6cadab56f (diff) | |
download | opie-f11d4bda64b58abfebf77485d5d77143a10dc8c9.zip opie-f11d4bda64b58abfebf77485d5d77143a10dc8c9.tar.gz opie-f11d4bda64b58abfebf77485d5d77143a10dc8c9.tar.bz2 |
Re add files
for todo
Diffstat (limited to 'core/pim/todo/templatedialogimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/todo/templatedialogimpl.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/core/pim/todo/templatedialogimpl.cpp b/core/pim/todo/templatedialogimpl.cpp new file mode 100644 index 0000000..77c5363 --- a/dev/null +++ b/core/pim/todo/templatedialogimpl.cpp | |||
@@ -0,0 +1,119 @@ | |||
1 | #include <qlistview.h> | ||
2 | #include <qlineedit.h> | ||
3 | |||
4 | #include "mainwindow.h" | ||
5 | #include "todoeditor.h" | ||
6 | #include "todotemplatemanager.h" | ||
7 | #include "templatedialogimpl.h" | ||
8 | |||
9 | |||
10 | using namespace Todo; | ||
11 | |||
12 | namespace { | ||
13 | class TemplateListItem : public QListViewItem { | ||
14 | public: | ||
15 | TemplateListItem( QListView*, | ||
16 | const QString& name, | ||
17 | const OTodo& ); | ||
18 | ~TemplateListItem(); | ||
19 | |||
20 | OTodo event()const; | ||
21 | QString text()const; | ||
22 | void setText(const QString& str ); | ||
23 | void setEvent( const OTodo& ); | ||
24 | private: | ||
25 | QString m_name; | ||
26 | OTodo m_ev; | ||
27 | }; | ||
28 | |||
29 | /* implementation */ | ||
30 | TemplateListItem::TemplateListItem( QListView* view, | ||
31 | const QString& text, | ||
32 | const OTodo& ev ) | ||
33 | : QListViewItem( view ), m_name( text ), m_ev( ev ) | ||
34 | { | ||
35 | QListViewItem::setText(0, m_name ); | ||
36 | } | ||
37 | TemplateListItem::~TemplateListItem() {} | ||
38 | OTodo TemplateListItem::event() const { | ||
39 | return m_ev; | ||
40 | } | ||
41 | QString TemplateListItem::text()const { | ||
42 | return m_name; | ||
43 | } | ||
44 | void TemplateListItem::setText( const QString& str ) { | ||
45 | QListViewItem::setText(0, str ); | ||
46 | m_name = str; | ||
47 | } | ||
48 | void TemplateListItem::setEvent( const OTodo& ev) { | ||
49 | m_ev = ev; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | TemplateDialogImpl::TemplateDialogImpl( MainWindow* win, | ||
54 | TemplateManager* man ) | ||
55 | : TemplateDialog( win ), m_win( win), m_man( man ) | ||
56 | { | ||
57 | /* fill the listview */ | ||
58 | /* not the fastest way.... */ | ||
59 | QStringList list = man->templates(); | ||
60 | for (QStringList::Iterator it = list.begin(); | ||
61 | it != list.end(); ++it ) { | ||
62 | new TemplateListItem( listView(), (*it), man->templateEvent( (*it) ) ); | ||
63 | } | ||
64 | listView()->addColumn( tr("Name") ); | ||
65 | |||
66 | connect( listView(), SIGNAL(clicked(QListViewItem*) ), | ||
67 | this, SLOT(slotClicked(QListViewItem*) ) ); | ||
68 | } | ||
69 | TemplateDialogImpl::~TemplateDialogImpl() { | ||
70 | |||
71 | } | ||
72 | void TemplateDialogImpl::slotAdd() { | ||
73 | QString str = tr("New Template %1").arg( listView()->childCount() ); | ||
74 | OTodo ev; | ||
75 | m_man->addEvent(str, ev); | ||
76 | new TemplateListItem( listView(), str, ev ); | ||
77 | } | ||
78 | void TemplateDialogImpl::slotRemove() { | ||
79 | TemplateListItem* item = (TemplateListItem*) listView()->currentItem(); | ||
80 | listView()->takeItem( item ); | ||
81 | |||
82 | m_man->removeEvent( item->text() ); | ||
83 | |||
84 | delete item; | ||
85 | } | ||
86 | void TemplateDialogImpl::slotEdit() { | ||
87 | TemplateListItem* item = (TemplateListItem*)listView()->currentItem(); | ||
88 | OTodo ev = m_win->currentEditor()->edit( m_win, item->event() ); | ||
89 | if ( m_win->currentEditor()->accepted() ) { | ||
90 | qWarning("accepted"); | ||
91 | item->setEvent( ev ); | ||
92 | qWarning("Priority %d", ev.priority() ); | ||
93 | m_man->removeEvent( item->text() ); | ||
94 | m_man->addEvent( item->text(), ev ); | ||
95 | } | ||
96 | } | ||
97 | /* | ||
98 | * we need to update | ||
99 | * the text | ||
100 | */ | ||
101 | |||
102 | void TemplateDialogImpl::slotReturn() { | ||
103 | TemplateListItem* tbl = (TemplateListItem*)listView()->currentItem(); | ||
104 | |||
105 | if (tbl->text() != edit()->text() ) { | ||
106 | m_man->removeEvent( tbl->text() ); | ||
107 | tbl->setText( edit()->text() ); | ||
108 | m_man->addEvent( tbl->text(), tbl->event() ); | ||
109 | } | ||
110 | } | ||
111 | /* update the lineedit when changing */ | ||
112 | void TemplateDialogImpl::slotClicked( QListViewItem* item) { | ||
113 | if (!item) | ||
114 | return; | ||
115 | |||
116 | TemplateListItem* tbl = (TemplateListItem*)item; | ||
117 | edit()->setText( tbl->text() ); | ||
118 | } | ||
119 | |||