/*************************************************************************** * Copyright (C) 2004 by Johan Maes - ON4QZ * * on4qz@telenet.be * * http://users.telenet.be/on4qz * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "thumbimage.h" #include "qsstvglobal.h" #include #include "utils.h" #include #include "imageview.h" #include "rxmainwindow.h" #include "txmainwindow.h" #include "configdialog.h" #include "editor.h" #include "mcanvas.h" #include #include /*! \class thumbImage \brief class to handle editable images and templates Thumbnail images are scaled representations of image and template files. They are identified by the filename they are referring to. The thumbImage is only a reference and a representation of the data. The data must still be stored on disk. @author Johan Maes - ON4QZ */ /*! \fn thumbImage::thumbImage(QWidget *parent,const char *name) \brief thumbImage constructor Every thumbnail is identified and referenced by its \a name. */ thumbImage::thumbImage(QWidget *parent,const char *name): QFrame(parent,name) { setFrameStyle(QFrame::Panel|QFrame::Sunken); setLineWidth( 2 ); filename=""; path=""; localName=name; ttype=RXTHUMB; popup=new QPopupMenu (this,"popup"); popup->insertItem("New",this,SLOT(slotNew())); popup->insertItem("Load",this,SLOT(slotLoadDialog())); popup->insertItem("To TX",this,SLOT(slotToTX())); // popup->insertItem("To RX",this,SLOT(slotToRX())); popup->insertItem("Edit",this,SLOT(slotEdit())); popup->insertItem("Print",this,SLOT(slotPrint())); popup->insertSeparator(); popup->insertItem("Delete",this,SLOT(slotDelete())); popup->insertSeparator(); popup->insertItem("Properties",this,SLOT(slotProperties())); ed=NULL; } thumbImage::~thumbImage() { } void thumbImage::setFilename(QString fn,QString ipath) { filename=fn; path=ipath; } void thumbImage::readSettings(QSettings *qs) { qs->beginGroup(APP_KEY+"/THUMB/"+localName+"/"); filename =qs->readEntry("filename",""); qs->endGroup(); load(); } void thumbImage::setType(thumbType t) { ttype=t; switch(t) { case RXTHUMB: path=rxImagePath; break; case TXTHUMB: path=txImagePath; break; case TEMPLATETHUMB: path=templatePath; break; } } void thumbImage::writeSettings(QSettings *qs) { qs->beginGroup(APP_KEY+"/THUMB/"+localName+"/"); qs->writeEntry("filename",filename); qs->endGroup(); } void thumbImage::load() { if (filename.isEmpty()) return; QFile f(filename); mcanvas mCanvas(340,256); if(!mCanvas.load(f)) { QMessageBox::warning(this,"Image Properties","Error while loading\n" + filename +"\nfor: " + localName); filename=""; // reset filename return; } origImage=mCanvas.getImage(QSize(0,0))->copy(); resizeEvent(NULL); } void thumbImage::paintEvent(QPaintEvent *e) { QString temp; QFrame::paintEvent(e); if (!filename.isEmpty()) { //debug("thumb repaint"); bitBlt(this, 0,0,&scaledImage); } else { //debug("thumb erased"); erase(contentsRect()); } } void thumbImage::resizeEvent(QResizeEvent *) { if(origImage.isNull()) return; if((origImage.width()==0) || (origImage.height()==0)) { scaledImage.reset(); return; } scaledImage=origImage.smoothScale(width(),height()); repaint(FALSE); } void thumbImage::mousePressEvent( QMouseEvent *e ) { QString temp; QString fn; if (( e->button() == LeftButton )&&(!filename.isEmpty())) { } else if (e->button() == RightButton) { popup->popup(QCursor::pos()); } } void thumbImage::slotLoadDialog() { // load image in thumbnail dirDialog d(this,0,TRUE); QString s=d.openFileName(path,"*"); if (s==QString::null) return ; if (s.isEmpty()) return ; filename=s; load(); } void thumbImage::slotNew() { if (ed!=NULL) delete ed; ed=new editor(this); connect(ed,SIGNAL(imageAvailable(QImage *)),SLOT(setImage(QImage *))); ed->show(); } void thumbImage::slotDelete() { filename=""; origImage.reset(); repaint(TRUE); } void thumbImage::slotToTX() { txMW->setImage(&origImage); } void thumbImage::slotEdit() { if(filename.isEmpty()) { slotLoadDialog(); if (filename.isEmpty()) return; } QFile f(filename); if (ed!=NULL) delete ed; ed=new editor(this); ed->openFile(f); connect(ed,SIGNAL(imageAvailable(QImage *)),SLOT(setImage(QImage *))); ed->show(); } void thumbImage::slotPrint() { if ( printer->setup(this) ) { QPixmap t; t=origImage; QPainter paint( printer ); paint.drawPixmap(30,30,t); } } void thumbImage::setImage(QImage *) { load(); // simply relaod from disk } /*! \fn thumbImage::slotProperties() */ void thumbImage::slotProperties() { QFileInfo fi(filename); QMessageBox::information(this,"Image Properties", "File: " + filename + "\n File size: " + QString::number(fi.size()) + "\n Image width: " +QString::number(origImage.width()) + "\n Image heigth: " +QString::number(origImage.height()) + "\n Last Modified: " +fi.lastModified().toString() ,QMessageBox::Ok); // QMessageBox::information(0,"Image Properties","File: " ,0,0,0); }