author | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
commit | ef40f0d781c904723d7842fc8be8f7dbad0614da (patch) (unidiff) | |
tree | 3c90068d73e19cf1fea43de570d7cd08c7ef6c33 | |
parent | a2c7b045c9a3ff9e275858b66e7fe29bdf4d8e31 (diff) | |
download | opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.zip opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.tar.gz opie-ef40f0d781c904723d7842fc8be8f7dbad0614da.tar.bz2 |
added delete confirm to button
-rw-r--r-- | noncore/applets/notesapplet/notes.cpp | 61 | ||||
-rw-r--r-- | noncore/applets/notesapplet/notes.h | 1 |
2 files changed, 37 insertions, 25 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp index cc5245c..81864c6 100644 --- a/noncore/applets/notesapplet/notes.cpp +++ b/noncore/applets/notesapplet/notes.cpp | |||
@@ -83,112 +83,123 @@ NotesControl::NotesControl( QWidget *parent, const char *name ) | |||
83 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); | 83 | setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); |
84 | loaded=false; | 84 | loaded=false; |
85 | edited=false; | 85 | edited=false; |
86 | doPopulate=true; | 86 | doPopulate=true; |
87 | QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); | 87 | QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); |
88 | QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); | 88 | QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); |
89 | 89 | ||
90 | view = new QMultiLineEdit(this, "OpieNotesView"); | 90 | view = new QMultiLineEdit(this, "OpieNotesView"); |
91 | 91 | ||
92 | box = new QListBox(this, "OpieNotesBox"); | 92 | box = new QListBox(this, "OpieNotesBox"); |
93 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); | 93 | QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); |
94 | box->setFixedHeight(50); | 94 | box->setFixedHeight(50); |
95 | 95 | ||
96 | vbox->setMargin( 6 ); | 96 | vbox->setMargin( 6 ); |
97 | vbox->setSpacing( 3 ); | 97 | vbox->setSpacing( 3 ); |
98 | 98 | ||
99 | vbox->addWidget( view); | 99 | vbox->addWidget( view); |
100 | vbox->addWidget( box); | 100 | vbox->addWidget( box); |
101 | 101 | ||
102 | setFixedHeight(180); | 102 | setFixedHeight(180); |
103 | QWidget *wid = QPEApplication::desktop(); | 103 | QWidget *wid = QPEApplication::desktop(); |
104 | setFixedWidth( wid->width()-10 /*200*/); | 104 | setFixedWidth( wid->width()-10 /*200*/); |
105 | 105 | ||
106 | setFocusPolicy(QWidget::StrongFocus); | 106 | setFocusPolicy(QWidget::StrongFocus); |
107 | 107 | ||
108 | newButton= new QPushButton( this, "newButton" ); | 108 | newButton= new QPushButton( this, "newButton" ); |
109 | newButton->setText(tr("New")); | 109 | newButton->setText(tr("New")); |
110 | hbox->addWidget( newButton); | 110 | hbox->addWidget( newButton); |
111 | 111 | ||
112 | deleteButton= new QPushButton( this, "deleteButton" ); | 112 | deleteButton= new QPushButton( this, "deleteButton" ); |
113 | deleteButton->setText(tr("Delete")); | 113 | deleteButton->setText(tr("Delete")); |
114 | hbox->addWidget( deleteButton); | 114 | hbox->addWidget( deleteButton); |
115 | 115 | ||
116 | vbox->addItem(hbox); | 116 | vbox->addItem(hbox); |
117 | 117 | ||
118 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), | 118 | connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), |
119 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); | 119 | this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); |
120 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); | 120 | connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); |
121 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); | 121 | connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); |
122 | 122 | ||
123 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); | 123 | connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); |
124 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); | 124 | connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); |
125 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButton())); | 125 | connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); |
126 | |||
126 | populateBox(); | 127 | populateBox(); |
127 | load(); | 128 | load(); |
128 | setCaption("Notes"); | 129 | setCaption("Notes"); |
129 | // parent->setFocus(); | 130 | // parent->setFocus(); |
130 | } | 131 | } |
131 | 132 | ||
133 | void NotesControl::slotDeleteButtonClicked() { | ||
134 | switch ( QMessageBox::warning(this,tr("Delete?"),tr("Do you really want to<BR><B> delete</B> this note ?") | ||
135 | ,tr("Yes"),tr("No"),0,1,1) ) { | ||
136 | case 0: | ||
137 | slotDeleteButton(); | ||
138 | break; | ||
139 | }; | ||
140 | } | ||
141 | |||
132 | void NotesControl::slotDeleteButton() { | 142 | void NotesControl::slotDeleteButton() { |
133 | 143 | ||
134 | QString selectedText = box->currentText(); | 144 | QString selectedText = box->currentText(); |
135 | qDebug("deleting "+selectedText); | 145 | qDebug("deleting "+selectedText); |
136 | 146 | ||
137 | if( !selectedText.isEmpty()) { | 147 | if( !selectedText.isEmpty()) { |
138 | Config cfg("Notes"); | 148 | |
139 | cfg.setGroup("Docs"); | 149 | Config cfg("Notes"); |
140 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); | 150 | cfg.setGroup("Docs"); |
141 | QString entryName, entryName2;; | 151 | int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); |
142 | for ( int i = 0; i < noOfFiles; i++ ) { | 152 | QString entryName, entryName2;; |
143 | entryName.sprintf( "File%i", i + 1 ); | 153 | for ( int i = 0; i < noOfFiles; i++ ) { |
144 | if(selectedText == cfg.readEntry( entryName )) { | 154 | entryName.sprintf( "File%i", i + 1 ); |
145 | qDebug("removing %s, %d", selectedText.latin1(), i); | 155 | if(selectedText == cfg.readEntry( entryName )) { |
146 | for ( int j = i; j < noOfFiles; j++ ) { | 156 | qDebug("removing %s, %d", selectedText.latin1(), i); |
147 | entryName.sprintf( "File%i", i + 1 ); | 157 | for ( int j = i; j < noOfFiles; j++ ) { |
148 | entryName2.sprintf( "File%i", i + 2 ); | 158 | entryName.sprintf( "File%i", i + 1 ); |
149 | QString temp = cfg.readEntry(entryName2); | 159 | entryName2.sprintf( "File%i", i + 2 ); |
150 | qDebug("move "+temp); | 160 | QString temp = cfg.readEntry(entryName2); |
151 | cfg.writeEntry(entryName, temp); | 161 | qDebug("move "+temp); |
152 | i++; | 162 | cfg.writeEntry(entryName, temp); |
163 | i++; | ||
164 | } | ||
165 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | ||
166 | entryName.sprintf( "File%i", noOfFiles ); | ||
167 | cfg.removeEntry(entryName); | ||
168 | cfg.write(); | ||
169 | DocLnk nf(selectedText); | ||
170 | nf.removeFiles(); | ||
153 | } | 171 | } |
154 | cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); | ||
155 | entryName.sprintf( "File%i", noOfFiles ); | ||
156 | cfg.removeEntry(entryName); | ||
157 | cfg.write(); | ||
158 | DocLnk nf(selectedText); | ||
159 | nf.removeFiles(); | ||
160 | } | 172 | } |
161 | } | 173 | populateBox(); |
162 | populateBox(); | ||
163 | } | 174 | } |
164 | } | 175 | } |
165 | 176 | ||
166 | void NotesControl::slotNewButton() { | 177 | void NotesControl::slotNewButton() { |
167 | if(edited) save(); | 178 | if(edited) save(); |
168 | view->clear(); | 179 | view->clear(); |
169 | view->setFocus(); | 180 | view->setFocus(); |
170 | } | 181 | } |
171 | 182 | ||
172 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { | 183 | void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { |
173 | switch (mouse) { | 184 | switch (mouse) { |
174 | case 1:{ | 185 | case 1:{ |
175 | } | 186 | } |
176 | break; | 187 | break; |
177 | case 2: | 188 | case 2: |
178 | menuTimer.start( 500, TRUE ); | 189 | menuTimer.start( 500, TRUE ); |
179 | break; | 190 | break; |
180 | }; | 191 | }; |
181 | } | 192 | } |
182 | 193 | ||
183 | void NotesControl::slotBoxSelected(const QString &itemString) { | 194 | void NotesControl::slotBoxSelected(const QString &itemString) { |
184 | if(edited) { | 195 | if(edited) { |
185 | save(); | 196 | save(); |
186 | } | 197 | } |
187 | loaded=false; | 198 | loaded=false; |
188 | edited=false; | 199 | edited=false; |
189 | load(itemString); | 200 | load(itemString); |
190 | } | 201 | } |
191 | 202 | ||
192 | 203 | ||
193 | void NotesControl::showMenu() { | 204 | void NotesControl::showMenu() { |
194 | QPopupMenu *m = new QPopupMenu(0); | 205 | QPopupMenu *m = new QPopupMenu(0); |
diff --git a/noncore/applets/notesapplet/notes.h b/noncore/applets/notesapplet/notes.h index c589f81..473a89a 100644 --- a/noncore/applets/notesapplet/notes.h +++ b/noncore/applets/notesapplet/notes.h | |||
@@ -25,60 +25,61 @@ | |||
25 | 25 | ||
26 | class QComboBox; | 26 | class QComboBox; |
27 | class QCheckBox; | 27 | class QCheckBox; |
28 | class QSpinBox; | 28 | class QSpinBox; |
29 | class QPushButton; | 29 | class QPushButton; |
30 | class QMultiLineEdit; | 30 | class QMultiLineEdit; |
31 | class QListBox; | 31 | class QListBox; |
32 | class QListBoxItem; | 32 | class QListBoxItem; |
33 | class NotesControl : public QFrame { | 33 | class NotesControl : public QFrame { |
34 | Q_OBJECT | 34 | Q_OBJECT |
35 | public: | 35 | public: |
36 | NotesControl( QWidget *parent=0, const char *name=0 ); | 36 | NotesControl( QWidget *parent=0, const char *name=0 ); |
37 | void performGrab(); | 37 | void performGrab(); |
38 | 38 | ||
39 | QPixmap notes; | 39 | QPixmap notes; |
40 | QMultiLineEdit *view; | 40 | QMultiLineEdit *view; |
41 | QListBox *box; | 41 | QListBox *box; |
42 | QPushButton *saveButton, *deleteButton, *newButton; | 42 | QPushButton *saveButton, *deleteButton, *newButton; |
43 | QString FileNamePath; | 43 | QString FileNamePath; |
44 | bool loaded, edited, doPopulate; | 44 | bool loaded, edited, doPopulate; |
45 | void save(); | 45 | void save(); |
46 | void populateBox(); | 46 | void populateBox(); |
47 | void load(); | 47 | void load(); |
48 | 48 | ||
49 | private: | 49 | private: |
50 | QTimer menuTimer; | 50 | QTimer menuTimer; |
51 | DocLnk *doc; | 51 | DocLnk *doc; |
52 | QString oldDocName; | 52 | QString oldDocName; |
53 | void focusOutEvent( QFocusEvent * ); | 53 | void focusOutEvent( QFocusEvent * ); |
54 | void load(const QString&); | 54 | void load(const QString&); |
55 | private slots: | 55 | private slots: |
56 | void slotDeleteButton(); | 56 | void slotDeleteButton(); |
57 | void slotDeleteButtonClicked(); | ||
57 | void slotNewButton(); | 58 | void slotNewButton(); |
58 | void boxPressed(int, QListBoxItem *, const QPoint&); | 59 | void boxPressed(int, QListBoxItem *, const QPoint&); |
59 | void showMenu(); | 60 | void showMenu(); |
60 | void loadDoc( const DocLnk &); | 61 | void loadDoc( const DocLnk &); |
61 | void slotViewEdited(); | 62 | void slotViewEdited(); |
62 | void slotBoxSelected(const QString &); | 63 | void slotBoxSelected(const QString &); |
63 | }; | 64 | }; |
64 | 65 | ||
65 | class NotesApplet : public QWidget { | 66 | class NotesApplet : public QWidget { |
66 | Q_OBJECT | 67 | Q_OBJECT |
67 | public: | 68 | public: |
68 | NotesApplet( QWidget *parent = 0, const char *name=0 ); | 69 | NotesApplet( QWidget *parent = 0, const char *name=0 ); |
69 | ~NotesApplet(); | 70 | ~NotesApplet(); |
70 | NotesControl *vc; | 71 | NotesControl *vc; |
71 | public slots: | 72 | public slots: |
72 | private: | 73 | private: |
73 | void mousePressEvent( QMouseEvent * ); | 74 | void mousePressEvent( QMouseEvent * ); |
74 | void paintEvent( QPaintEvent* ); | 75 | void paintEvent( QPaintEvent* ); |
75 | 76 | ||
76 | private: | 77 | private: |
77 | QPixmap notesPixmap; | 78 | QPixmap notesPixmap; |
78 | private slots: | 79 | private slots: |
79 | 80 | ||
80 | 81 | ||
81 | }; | 82 | }; |
82 | 83 | ||
83 | #endif // __NOTES_APPLET_H__ | 84 | #endif // __NOTES_APPLET_H__ |
84 | 85 | ||