Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

readonlyformbase.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   readonlyformbase.cpp                                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   Read the file COPYING for details.                                    *
00011  *                                                                         *
00012  *   copyright: (C) 2003 by Jan Mueller                                    *
00013  *   email: janmueller7@hotmail.com                                        *
00014  *                                                                         *
00015  ***************************************************************************/
00016 
00017 #include "readonlyformbase.h"
00018 #include <qsettings.h>
00019 #include <qaction.h>
00020 #include <qtoolbar.h>
00021 #include <qlabel.h>
00022 #include <qpixmap.h>
00023 #include <qfiledialog.h>
00024 #include <qmessagebox.h>
00025 #include <qmainwindow.h>
00026 #include <qpopupmenu.h>
00027 #include <qmenubar.h>
00028 #include "global.h"
00029 
00030 void ReadOnlyFormBase::initToolBar() {
00031   rotoolbar=new QToolBar(mainWindow());
00032   
00033   selBackgrAction=new QAction("Select Background", QIconSet(loadPixmap("imagegallery.png")), "Select Background", 0, this, "selbackgr");
00034   connect(selBackgrAction, SIGNAL(activated()), this, SLOT(selBackgr()));
00035   selBackgrAction->addTo(rotoolbar);
00036   
00037   reloadRecAction=new QAction("Reload Record", QIconSet(loadPixmap("reload.png")), "Reload Record", 0, this, "reloadrec");
00038   connect(reloadRecAction, SIGNAL(activated()), this, SLOT(reloadRec()));
00039   reloadRecAction->addTo(rotoolbar);
00040   
00041   rotoolbar->show();
00042   
00043   reloadRecAction->addTo(roMenu());
00044   selBackgrAction->addTo(roMenu());
00045   int c=mainWindow()->menuBar()->count();
00046   mainWindow()->menuBar()->insertItem("Form", roMenu(), -1, (c>2?c-2:c));
00047 }
00048 
00049 QPopupMenu *ReadOnlyFormBase::roMenu() {
00050   if(!romenu)
00051     romenu=new QPopupMenu(this);
00052   ASSERT(romenu);
00053   return romenu;
00054 }
00055 
00056 class Preview : public QLabel, public QFilePreview {
00057  public:
00058   Preview( QWidget *parent=0 ) : QLabel( parent ) {}
00059   void previewUrl( const QUrl &u )
00060   {
00061     QString path = u.path();
00062     QPixmap pix( path );
00063     if ( pix.isNull() )
00064       setText( "This is not a pixmap" );
00065     else
00066       setPixmap( pix );
00067   }
00068 };
00069 
00070 
00071 void ReadOnlyFormBase::selBackgr() {
00072     Preview* p = new Preview;
00073     QFileDialog* fd = new QFileDialog( this );
00074     fd->setContentsPreviewEnabled( TRUE );
00075     fd->setContentsPreview( p, p );
00076     fd->setPreviewMode( QFileDialog::Contents );
00077     QString filename;
00078     if ( fd->exec() == QDialog::Accepted ) {
00079         filename = fd->selectedFile();
00080         QSettings settings;
00081         settings.setPath("www.test.de", "Literature");
00082         settings.writeEntry(QString("/literature/backgr_")+name(), filename);
00083     }
00084 }
00085 
00086 void ReadOnlyFormBase::reloadRec() {
00087     if(QMessageBox::information(this, "Literature", "Do you want to revert the record?",  "&Yes", "&No")!=0) return;
00088     
00089     ASSERT(url().isValid());
00090     setData();
00091 }
00092 
00093 QString ReadOnlyFormBase::no(LitUrl o) {
00094   QSqlQuery q("select no from "+o.table()+" where "+o.query());
00095   q.first();
00096   return q.value(0).toString();
00097 }
00098 
00099 QString ReadOnlyFormBase::tab(LitUrl o) {
00100   return "tabid('"+o.table()+"')";
00101 }
00102 
00103 QString ReadOnlyFormBase::buildLinkWhereClause(QString target, QString source, QString no) {
00104   return QString(" ("+target+".no=link.obj_1 and link.tab_1=tabid('"+target+"') and " \
00105                  " link.obj_2="+no+" and link.tab_2=tabid('"+source+"')) or "\
00106                  "("+target+".no=link.obj_2 and link.tab_2=tabid('"+target+"') " \
00107                  " and link.obj_1="+no+" and link.tab_1=tabid('"+source+"'))"); 
00108 }

Generated on Sat Mar 27 19:20:43 2004 for Literature by doxygen 1.3.6-20040222