summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-09-22 13:22:51 (UTC)
committer llornkcor <llornkcor>2002-09-22 13:22:51 (UTC)
commit0816ba0c42df8074d698b60041993dbda5591e27 (patch) (unidiff)
treec8688bedc4bf5a87e967b0ede8218997dbdd4071
parent2778d4b110b6b9106da568eb10568af18e482900 (diff)
downloadopie-0816ba0c42df8074d698b60041993dbda5591e27.zip
opie-0816ba0c42df8074d698b60041993dbda5591e27.tar.gz
opie-0816ba0c42df8074d698b60041993dbda5591e27.tar.bz2
delete button so I dont have to explain so much about the hold-menu delete
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/notesapplet/notes.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/noncore/applets/notesapplet/notes.cpp b/noncore/applets/notesapplet/notes.cpp
index a4aa093..cc5245c 100644
--- a/noncore/applets/notesapplet/notes.cpp
+++ b/noncore/applets/notesapplet/notes.cpp
@@ -82,13 +82,13 @@ NotesControl::NotesControl( QWidget *parent, const char *name )
82{ 82{
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 ); 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);
@@ -105,30 +105,39 @@ NotesControl::NotesControl( QWidget *parent, const char *name )
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
112 deleteButton= new QPushButton( this, "deleteButton" );
113 deleteButton->setText(tr("Delete"));
114 hbox->addWidget( deleteButton);
115
111 vbox->addItem(hbox); 116 vbox->addItem(hbox);
112 117
113 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), 118 connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)),
114 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); 119 this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) );
115 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); 120 connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &)));
116 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); 121 connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) );
117 122
118 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); 123 connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) );
119 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); 124 connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton()));
125 connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButton()));
120 populateBox(); 126 populateBox();
121 load(); 127 load();
122 setCaption("Notes"); 128 setCaption("Notes");
123 // parent->setFocus(); 129 // parent->setFocus();
124} 130}
125 131
126void NotesControl::slotDeleteButton() { 132void NotesControl::slotDeleteButton() {
133
127 QString selectedText = box->currentText(); 134 QString selectedText = box->currentText();
128 qDebug("deleting "+selectedText); 135 qDebug("deleting "+selectedText);
136
137 if( !selectedText.isEmpty()) {
129 Config cfg("Notes"); 138 Config cfg("Notes");
130 cfg.setGroup("Docs"); 139 cfg.setGroup("Docs");
131 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); 140 int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 );
132 QString entryName, entryName2;; 141 QString entryName, entryName2;;
133 for ( int i = 0; i < noOfFiles; i++ ) { 142 for ( int i = 0; i < noOfFiles; i++ ) {
134 entryName.sprintf( "File%i", i + 1 ); 143 entryName.sprintf( "File%i", i + 1 );
@@ -148,12 +157,13 @@ void NotesControl::slotDeleteButton() {
148 cfg.write(); 157 cfg.write();
149 DocLnk nf(selectedText); 158 DocLnk nf(selectedText);
150 nf.removeFiles(); 159 nf.removeFiles();
151 } 160 }
152 } 161 }
153 populateBox(); 162 populateBox();
163 }
154} 164}
155 165
156void NotesControl::slotNewButton() { 166void NotesControl::slotNewButton() {
157 if(edited) save(); 167 if(edited) save();
158 view->clear(); 168 view->clear();
159 view->setFocus(); 169 view->setFocus();
@@ -244,19 +254,20 @@ void NotesControl::save() {
244 FileManager fm; 254 FileManager fm;
245 if ( !fm.saveFile( *doc, rt ) ) { 255 if ( !fm.saveFile( *doc, rt ) ) {
246 } 256 }
247 257
248 oldDocName=docname; 258 oldDocName=docname;
249 edited=false; 259 edited=false;
260 qDebug("save");
261 if (doPopulate)
262 populateBox();
250 } 263 }
251 qDebug("save");
252 if (doPopulate)
253 populateBox();
254 }
255 cfg.writeEntry( "LastDoc",oldDocName ); 264 cfg.writeEntry( "LastDoc",oldDocName );
256 cfg.write(); 265 cfg.write();
266
267 }
257} 268}
258 269
259void NotesControl::populateBox() { 270void NotesControl::populateBox() {
260 box->clear(); 271 box->clear();
261 qDebug("populate"); 272 qDebug("populate");
262 Config cfg("Notes"); 273 Config cfg("Notes");
@@ -272,26 +283,26 @@ void NotesControl::populateBox() {
272 box->insertStringList(list,-1); 283 box->insertStringList(list,-1);
273 doPopulate=false; 284 doPopulate=false;
274} 285}
275 286
276void NotesControl::load() { 287void NotesControl::load() {
277 288
278 Config cfg("Notes");
279 cfg.setGroup("Docs");
280 if(!loaded) { 289 if(!loaded) {
290 Config cfg("Notes");
291 cfg.setGroup("Docs");
281 QString lastDoc=cfg.readEntry( "LastDoc",""); 292 QString lastDoc=cfg.readEntry( "LastDoc","");
282 DocLnk nf; 293 DocLnk nf;
283 nf.setType("text/plain"); 294 nf.setType("text/plain");
284 nf.setFile(lastDoc); 295 nf.setFile(lastDoc);
285 296
286 loadDoc(nf); 297 loadDoc(nf);
287 loaded=true; 298 loaded=true;
288 oldDocName=lastDoc; 299 oldDocName=lastDoc;
289 } 300 cfg.writeEntry( "LastDoc",oldDocName );
290 cfg.writeEntry( "LastDoc",oldDocName ); 301 cfg.write();
291 cfg.write(); 302 }
292} 303}
293 304
294void NotesControl::load(const QString & file) { 305void NotesControl::load(const QString & file) {
295 qDebug("loading "+file); 306 qDebug("loading "+file);
296 if(!loaded) { 307 if(!loaded) {
297 DocLnk nf; 308 DocLnk nf;
@@ -346,12 +357,13 @@ void NotesApplet::mousePressEvent( QMouseEvent *) {
346// QPoint curPos = mapToGlobal( rect().topLeft() ); 357// QPoint curPos = mapToGlobal( rect().topLeft() );
347 vc->show(); 358 vc->show();
348 vc->move( 5, 18); 359 vc->move( 5, 18);
349 vc->doPopulate=true; 360 vc->doPopulate=true;
350 vc->populateBox(); 361 vc->populateBox();
351 vc->doPopulate=false; 362 vc->doPopulate=false;
363 vc->loaded=false;
352 364
353 vc->load(); 365 vc->load();
354// this->setFocus(); 366// this->setFocus();
355 vc->view->setFocus(); 367 vc->view->setFocus();
356 } 368 }
357} 369}