00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "note.h"
00018 #include "liturl.h"
00019 #include <qlayout.h>
00020 #include <qtoolbar.h>
00021 #include <qaction.h>
00022 #include <qmessagebox.h>
00023 #include <qlineedit.h>
00024 #include <qlabel.h>
00025 #include <qapplication.h>
00026 #include <qsqldatabase.h>
00027 #include <qsqlcursor.h>
00028 #include <qevent.h>
00029 #include <qcombobox.h>
00030 #include <qsettings.h>
00031 #include <qpixmap.h>
00032 #include "error.h"
00033 #include "editorhelper.h"
00034 #include "global.h"
00035 #include "linklistbox.h"
00036 #include "linklistboxitem.h"
00037 #include "filllinklistbox.h"
00038 #include "mainwindowimpl.h"
00039 #include <qlayout.h>
00040 #include <selectnote.h>
00041
00042 Note::Note(LitUrl url, QObject *receiver, QString slot, MainWindow *parent, const char *name): ReadWriteFormBase(url, receiver, slot, parent, name), toolbar(0L) {
00043 noteform=new NoteForm(this, "noteform");
00044 QHBoxLayout *l=new QHBoxLayout(this);
00045 l->addWidget(noteform);
00046 QSettings settings;
00047 QString backgr = settings.readEntry(QString("/literature/backgr_")+name, "");
00048 if(!backgr.isEmpty()) noteform->setErasePixmap(QPixmap(backgr));
00049 initToolBar();
00050 new EditorHelper(this, noteform->memo);
00051 setData();
00052 }
00053
00054 void Note::initToolBar() {
00055 toolbar=new QToolBar(mainWindow());
00056
00057 insertNoteAction=new QAction("Insert Note", QIconSet(loadPixmap("insnote.png")), "Insert Note", 0, this, "insertnote");
00058 connect(insertNoteAction, SIGNAL(activated()), this, SLOT(insertNote()));
00059 deleteNoteAction=new QAction("Delete Note", QIconSet(loadPixmap("delnote.png")), "Delete Note", 0, this, "deletenote");
00060 connect(deleteNoteAction, SIGNAL(activated()), this, SLOT(deleteNote()));
00061
00062 insertNoteAction->addTo(toolbar);
00063 deleteNoteAction->addTo(toolbar);
00064 toolbar->show();
00065
00066 insertNoteAction->addTo(roMenu());
00067 deleteNoteAction->addTo(roMenu());
00068
00069 }
00070
00071 Note::~Note() {
00072 write();
00073 delete toolbar;
00074 }
00075
00076 QListViewItem *Note::addNoteTree(QString where, QListViewItem *par, bool emph) {
00077 QSqlQuery q("select title, no from note where "+where);
00078 LinkListBoxItem *parentitem=0L;
00079 while(q.next()) {
00080 QString s=q.value(0).toString();
00081 LitUrl u("lit://note/note?no="+q.value(1).toString());
00082 if(par) parentitem = new LinkListBoxItem(par, s, u, loadPixmap("shownote.png")); else parentitem = new LinkListBoxItem(noteform->links, s, u, loadPixmap("shownote.png"));
00083 parentitem->setTextColor(Qt::black);
00084 if(emph) parentitem->setBackgroundColor(Qt::blue);
00085 else parentitem->setBackgroundColor(Qt::lightGray);
00086 parentitem->setOrderPrefix("b");
00087 parentitem->setOpen(true);
00088 }
00089 return parentitem;
00090 }
00091
00092 bool Note::setData()
00093 {
00094 try {
00095 ReadWriteFormBase::setData();
00096 LitUrl u=url();
00097 setWorkingGui(true);
00098 form.clear();
00099 formcursor.clear();
00100 formcursor.setMode(QSqlCursor::Writable);
00101 formcursor.setName("note");
00102 if(!formcursor.select(u.query()))
00103 throw(Error(formcursor.lastError()));
00104 qDebug("count:"+QString().setNum(formcursor.size()));
00105 if(formcursor.size()!=1) throw Error("Invalid Record!");
00106 formcursor.first();
00107 QString no=formcursor.value("no").toString();
00108 form.setRecord(formcursor.primeUpdate());
00109 form.insert(noteform->title, "title");
00110 form.insert(noteform->memo, "memo");
00111 form.insert(noteform->modified, "modified");
00112 form.insert(noteform->created, "created");
00113 form.readFields();
00114
00115 noteform->links->setEnabled(false);
00116 noteform->links->clear();
00117 int type=formcursor.value("type").toInt();
00118 QString parent=formcursor.value("parent").toString();
00119
00120 QListViewItem *parentitem=0L;
00121 QSqlQuery q;
00122 if(type==0) {
00123 noteform->links->setRootIsDecorated(true);
00124 if(parent!="0") parentitem=addNoteTree("no="+parent);
00125 parentitem=addNoteTree("no="+no, parentitem, true);
00126 parentitem=addNoteTree("parent="+no,parentitem);
00127 }
00128
00129 filllink_note=new FillLinkListBox(this, "linknotefllb", noteform->links, "select note.no, note.title from note, link where "+buildLinkWhereClause("note", "note", no), "note/note", loadPixmap("shownote.png"));
00130 filllink_note->start();
00131 threads.append(filllink_note);
00132
00133 filllink_author=new FillLinkListBox(this, "linkauthorfllb", noteform->links, "select author.no, author.firstname, author.lastname from author, link where"+buildLinkWhereClause("author", "note", no), "author/author", loadPixmap("showauthor.png"));
00134 filllink_author->start();
00135 threads.append(filllink_author);
00136
00137 if(type==1) {
00138 filllink_publ=new FillLinkListBox(this, "linkpublfllb", noteform->links, "select publication.no, publication.title from publication, link where "+buildLinkWhereClause("publication", "note", no), "publication/publication", loadPixmap("showpubl.png"));
00139 filllink_publ->start();
00140 threads.append(filllink_publ);
00141
00142 filllink_part=new FillLinkListBox(this, "linkpartfllb", noteform->links, "select part.no, part.title from part, link where"+buildLinkWhereClause("part", "note", no), "part/part", loadPixmap("showpart.png"));
00143 filllink_part->start();
00144 threads.append(filllink_part);
00145
00146 filllink_partdata=new FillLinkListBox(this, "linkpartdatafllb", noteform->links, "select partdata.no, partdata.filename from partdata, link where"+buildLinkWhereClause("partdata", "note", no), "file/partdata", loadPixmap("showfile.png"));
00147 filllink_partdata->start();
00148 threads.append(filllink_partdata);
00149 }
00150
00151 setValid(true);
00152 } catch(Error &e) {
00153 setValid(false);
00154 setReadonlyGui(true);
00155 QMessageBox::warning(this, "Error", e.message());
00156 return false;
00157 }
00158 setValid(true);
00159 return true;
00160 }
00161
00162 void Note::setWorkingGui(bool work) {
00163 ReadWriteFormBase::setWorkingGui(work);
00164 noteform->links->setEnabled(!work);
00165 }
00166
00167 void Note::setReadonlyGui(bool ro) {
00168 ReadWriteFormBase::setReadonlyGui(ro);
00169 noteform->title->setEnabled(!ro);
00170 noteform->memo->setEnabled(!ro);
00171 }
00172
00173 void Note::setInvalidGui(bool inv) {
00174 ReadWriteFormBase::setInvalidGui(inv);
00175 setWorkingGui(false);
00176 setReadonlyGui(inv);
00177 }
00178
00179 void Note::deleteRec()
00180 {
00181 if(!isValid()) return;
00182 QSqlQuery query( "select count(*) from note where parent="+no(url()));
00183 query.first();
00184 if(query.value(0).toInt()>0)
00185 QMessageBox::warning(this, "Error", "Can't delete note since one or more notes are child notes of this note. Please delete them first.");
00186 else
00187 ReadWriteFormBase::deleteRec();
00188 }
00189
00190
00191 void Note::insertNote() {
00192 SelectNote *s=new SelectNote(this, "selnote");
00193 Q_ASSERT(s);
00194 if(s->exec()==QDialog::Accepted)
00195 createLink(s->url(), url());
00196 }
00197
00198 void Note::deleteNote() {
00199 deleteLink(noteform->links->url(), url());
00200 }