author | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-09-24 01:53:27 (UTC) |
commit | ef40f0d781c904723d7842fc8be8f7dbad0614da (patch) (side-by-side diff) | |
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 @@ -51,176 +51,187 @@ static char * notes_xpm[] = { ". c #000000", "+ c #7F7F7F", "@ c #BFBFBF", "# c #BFC1FF", "$ c #FF0000", "% c #FFFFFF", "& c #00037F", "* c #0006FF", "= c #0005BF", "- c #7F0000", " .. ", " .. ", " ... ", " .+ ", " .@. ", " . .+ ", " ..#.@. ", " ..###.+.. ", " ..###$...##.. ", "..###$$$%+$$##&.", ".*=####$-###&=&.", ".=**=###==&=&=..", " ..=**=#&=&=.. ", " ..=*=&=.. ", " ..=.. ", " . "}; NotesControl::NotesControl( QWidget *parent, const char *name ) : QFrame( parent, name,/* WDestructiveClose | */WStyle_StaysOnTop ) // : QFrame( parent, name, WDestructiveClose | WStyle_StaysOnTop | WType_Popup ) { setFrameStyle( QFrame::PopupPanel | QFrame::Raised ); loaded=false; edited=false; doPopulate=true; QVBoxLayout *vbox = new QVBoxLayout( this,0, -1, "Vlayout" ); QHBoxLayout *hbox = new QHBoxLayout( this, 0, -1, "HLayout" ); view = new QMultiLineEdit(this, "OpieNotesView"); box = new QListBox(this, "OpieNotesBox"); QPEApplication::setStylusOperation( box->viewport(),QPEApplication::RightOnHold); box->setFixedHeight(50); vbox->setMargin( 6 ); vbox->setSpacing( 3 ); vbox->addWidget( view); vbox->addWidget( box); setFixedHeight(180); QWidget *wid = QPEApplication::desktop(); setFixedWidth( wid->width()-10 /*200*/); setFocusPolicy(QWidget::StrongFocus); newButton= new QPushButton( this, "newButton" ); newButton->setText(tr("New")); hbox->addWidget( newButton); deleteButton= new QPushButton( this, "deleteButton" ); deleteButton->setText(tr("Delete")); hbox->addWidget( deleteButton); - + vbox->addItem(hbox); connect( box, SIGNAL( mouseButtonPressed( int, QListBoxItem *, const QPoint&)), this,SLOT( boxPressed(int, QListBoxItem *, const QPoint&)) ); connect(box, SIGNAL(highlighted(const QString&)), this, SLOT(slotBoxSelected(const QString &))); connect( &menuTimer, SIGNAL( timeout() ), SLOT( showMenu() ) ); connect(view,SIGNAL( textChanged() ), this, SLOT(slotViewEdited() ) ); connect(newButton, SIGNAL(clicked()), this, SLOT(slotNewButton())); - connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButton())); + connect(deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteButtonClicked())); + populateBox(); load(); setCaption("Notes"); // parent->setFocus(); } +void NotesControl::slotDeleteButtonClicked() { + switch ( QMessageBox::warning(this,tr("Delete?"),tr("Do you really want to<BR><B> delete</B> this note ?") + ,tr("Yes"),tr("No"),0,1,1) ) { + case 0: + slotDeleteButton(); + break; + }; +} + void NotesControl::slotDeleteButton() { QString selectedText = box->currentText(); qDebug("deleting "+selectedText); if( !selectedText.isEmpty()) { - Config cfg("Notes"); - cfg.setGroup("Docs"); - int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); - QString entryName, entryName2;; - for ( int i = 0; i < noOfFiles; i++ ) { - entryName.sprintf( "File%i", i + 1 ); - if(selectedText == cfg.readEntry( entryName )) { - qDebug("removing %s, %d", selectedText.latin1(), i); - for ( int j = i; j < noOfFiles; j++ ) { - entryName.sprintf( "File%i", i + 1 ); - entryName2.sprintf( "File%i", i + 2 ); - QString temp = cfg.readEntry(entryName2); - qDebug("move "+temp); - cfg.writeEntry(entryName, temp); - i++; + + Config cfg("Notes"); + cfg.setGroup("Docs"); + int noOfFiles = cfg.readNumEntry("NumberOfFiles", 0 ); + QString entryName, entryName2;; + for ( int i = 0; i < noOfFiles; i++ ) { + entryName.sprintf( "File%i", i + 1 ); + if(selectedText == cfg.readEntry( entryName )) { + qDebug("removing %s, %d", selectedText.latin1(), i); + for ( int j = i; j < noOfFiles; j++ ) { + entryName.sprintf( "File%i", i + 1 ); + entryName2.sprintf( "File%i", i + 2 ); + QString temp = cfg.readEntry(entryName2); + qDebug("move "+temp); + cfg.writeEntry(entryName, temp); + i++; + } + cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); + entryName.sprintf( "File%i", noOfFiles ); + cfg.removeEntry(entryName); + cfg.write(); + DocLnk nf(selectedText); + nf.removeFiles(); } - cfg.writeEntry("NumberOfFiles", noOfFiles-1 ); - entryName.sprintf( "File%i", noOfFiles ); - cfg.removeEntry(entryName); - cfg.write(); - DocLnk nf(selectedText); - nf.removeFiles(); } - } - populateBox(); + populateBox(); } } void NotesControl::slotNewButton() { if(edited) save(); view->clear(); view->setFocus(); } void NotesControl::boxPressed(int mouse, QListBoxItem *item, const QPoint&) { switch (mouse) { case 1:{ } break; case 2: menuTimer.start( 500, TRUE ); break; }; } void NotesControl::slotBoxSelected(const QString &itemString) { if(edited) { save(); } loaded=false; edited=false; load(itemString); } void NotesControl::showMenu() { QPopupMenu *m = new QPopupMenu(0); m->insertItem( tr( "Delete" ), this, SLOT( slotDeleteButton() )); m->setFocus(); m->exec( QCursor::pos() ); if(m) delete m; } void NotesControl::focusOutEvent ( QFocusEvent * e) { if( e->reason() == QFocusEvent::Popup) save(); else { if(!loaded) { populateBox(); load(); } } QWidget::focusOutEvent(e); } void NotesControl::save() { Config cfg("Notes"); cfg.setGroup("Docs"); if( edited) { QString rt = view->text(); if(!rt.isEmpty()) { QString pt = rt.simplifyWhiteSpace(); int i = pt.find( ' ' ); QString docname = pt; if ( i > 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 @@ -1,84 +1,85 @@ /********************************************************************** ** Copyright (C) 2002 L.J. Potter ljp@llornkcor.com ** All rights reserved. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** **********************************************************************/ #ifndef __NOTES_APPLET_H__ #define __NOTES_APPLET_H__ #include <qwidget.h> #include <qframe.h> #include <qpixmap.h> #include <qguardedptr.h> #include <qtimer.h> #include <qpe/filemanager.h> #include <qstring.h> class QComboBox; class QCheckBox; class QSpinBox; class QPushButton; class QMultiLineEdit; class QListBox; class QListBoxItem; class NotesControl : public QFrame { Q_OBJECT public: NotesControl( QWidget *parent=0, const char *name=0 ); void performGrab(); QPixmap notes; QMultiLineEdit *view; QListBox *box; QPushButton *saveButton, *deleteButton, *newButton; QString FileNamePath; bool loaded, edited, doPopulate; void save(); void populateBox(); void load(); private: QTimer menuTimer; DocLnk *doc; QString oldDocName; void focusOutEvent( QFocusEvent * ); void load(const QString&); private slots: void slotDeleteButton(); + void slotDeleteButtonClicked(); void slotNewButton(); void boxPressed(int, QListBoxItem *, const QPoint&); void showMenu(); void loadDoc( const DocLnk &); void slotViewEdited(); void slotBoxSelected(const QString &); }; class NotesApplet : public QWidget { Q_OBJECT public: NotesApplet( QWidget *parent = 0, const char *name=0 ); ~NotesApplet(); NotesControl *vc; public slots: private: void mousePressEvent( QMouseEvent * ); void paintEvent( QPaintEvent* ); private: QPixmap notesPixmap; private slots: }; #endif // __NOTES_APPLET_H__ |