00001 #include "imageinfoui.h"
00002
00003 #include <qframe.h>
00004 #include <qlabel.h>
00005 #include <qpushbutton.h>
00006 #include <qtextview.h>
00007 #include <qlayout.h>
00008 #include <qvariant.h>
00009 #include <qtooltip.h>
00010 #include <qwhatsthis.h>
00011 #include <qimage.h>
00012 #include <qpixmap.h>
00013 #include <qstring.h>
00014 #include <qfileinfo.h>
00015
00016 #include "lib/slavemaster.h"
00017 #include "lib/imagecache.h"
00018
00019 #include <opie2/oconfig.h>
00020 #include <opie2/okeyconfigwidget.h>
00021 #include <opie2/odebug.h>
00022 #include <opie2/oresource.h>
00023
00024 #include <qpe/qcopenvelope_qws.h>
00025
00026 static const int THUMBSIZE = 128;
00027
00028 using namespace Opie::Core;
00029
00030 imageinfo::imageinfo(Opie::Core::OConfig *cfg,QWidget* parent, const char* name, WFlags fl )
00031 : QWidget( parent, name, fl )
00032 {
00033 m_viewManager = 0;
00034 m_cfg = cfg;
00035 init(name);
00036 initKeys();
00037 }
00038
00039 imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WFlags fl )
00040 : QWidget( parent, name, fl ),currentFile(_path)
00041 {
00042 m_viewManager = 0;
00043 m_cfg = 0;
00044 init(name);
00045 initKeys();
00046 slotChangeName(_path);
00047 }
00048
00049 Opie::Core::OKeyConfigManager* imageinfo::manager()
00050 {
00051 if (!m_viewManager) {
00052 initKeys();
00053 }
00054 return m_viewManager;
00055 }
00056
00057 void imageinfo::initKeys()
00058 {
00059 #if 0
00060 if (!m_cfg) {
00061 m_cfg = new Opie::Core::OConfig("phunkview");
00062 m_cfg->setGroup("imageinfo_keys" );
00063 }
00064 #endif
00065 Opie::Core::OKeyPair::List lst;
00066 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "imageinfo_keys",
00067 lst, false,this, "keyconfig name" );
00068 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Full Image"), "infoview",
00069 Opie::Core::OResource::loadPixmap("1to1", Opie::Core::OResource::SmallIcon),
00070 ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton),
00071 this, SLOT(slotShowImage())));
00072 m_viewManager->load();
00073 m_viewManager->handleWidget( this );
00074 m_viewManager->handleWidget( TextView1 );
00075 }
00076
00077 void imageinfo::slotShowImage()
00078 {
00079 emit dispImage(currentFile);
00080 }
00081
00082 void imageinfo::init(const char* name) {
00083 {
00084 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
00085 }
00086 if ( !name )
00087 setName( "imageinfo" );
00088 resize( 289, 335 );
00089 setCaption( tr( "Image info" ) );
00090 imageinfoLayout = new QVBoxLayout( this );
00091 imageinfoLayout->setSpacing(2);
00092 imageinfoLayout->setMargin(4);
00093
00094 PixmapLabel1 = new QLabel( this, "PixmapLabel1" );
00095 PixmapLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, PixmapLabel1->sizePolicy().hasHeightForWidth() ) );
00096 QWhatsThis::add( PixmapLabel1, tr("Displays an thumbnail of the image") );
00097
00098 imageinfoLayout->addWidget( PixmapLabel1 );
00099
00100 Line1 = new QFrame( this, "Line1" );
00101 Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
00102 imageinfoLayout->addWidget( Line1 );
00103
00104 fnameLabel = new QLabel( this, "FnameLabel" );
00105 imageinfoLayout->addWidget( fnameLabel);
00106
00107 TextView1 = new QTextView( this, "TextView1" );
00108 TextView1->setFrameShadow( QTextView::Sunken );
00109 TextView1->setResizePolicy( QTextView::AutoOneFit );
00110 TextView1->setBackgroundOrigin( QTextView::ParentOrigin );
00111 TextView1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, TextView1->sizePolicy().hasHeightForWidth() ) );
00112
00113 QWhatsThis::add( TextView1, tr("Displays info of selected image") );
00114 imageinfoLayout->addWidget( TextView1 );
00115
00116 SlaveMaster* master = SlaveMaster::self();
00117 connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)),
00118 this, SLOT(slot_fullInfo(const QString&, const QString&)) );
00119 connect(master, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)),
00120 this, SLOT(slotThumbNail(const QString&, const QPixmap&)));
00121 }
00122
00123 void imageinfo::slotChangeName(const QString&_path)
00124 {
00125 currentFile=_path;
00126 QFileInfo fi(_path);
00127 fnameLabel->setText("<qt><center><b>"+fi.fileName()+"</b></center></qt>");
00128 SlaveMaster::self()->imageInfo( currentFile );
00129
00130 QPixmap*m_pix = PPixmapCache::self()->cachedImage( _path, THUMBSIZE,THUMBSIZE );
00131 if (!m_pix) {
00132 PixmapLabel1->setPixmap(QPixmap( Opie::Core::OResource::loadPixmap( "UnknownDocument", Opie::Core::OResource::SmallIcon )));
00133 SlaveMaster::self()->thumbNail(currentFile,THUMBSIZE,THUMBSIZE);
00134 } else {
00135 PixmapLabel1->setPixmap(*m_pix);
00136 }
00137 }
00138
00139 imageinfo::~imageinfo()
00140 {
00141 {
00142 QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
00143 }
00144 if (m_viewManager) {
00145 delete m_viewManager;
00146 }
00147 }
00148
00149 void imageinfo::slot_fullInfo(const QString&_path, const QString&_t)
00150 {
00151 if (_path == currentFile) {
00152 odebug << _t << oendl;
00153 QString t = _t;
00154 t.replace(QRegExp("\n"),"<br>");
00155 TextView1->setText(t);
00156 }
00157 }
00158
00159 void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix)
00160 {
00161 if (_path == currentFile) {
00162 if (_pix.width()>0) {
00163 PPixmapCache::self()->insertImage( _path, _pix, THUMBSIZE, THUMBSIZE );
00164 PixmapLabel1->setPixmap( _pix );
00165 PixmapLabel1->resize(QSize(_pix.width(),_pix.height()));
00166 }
00167 }
00168 }
00169
00170 void imageinfo::setPath( const QString& str ) {
00171 slotChangeName( str );
00172 }
00173
00174 void imageinfo::setDestructiveClose() {
00175 WFlags fl = getWFlags();
00176
00177 fl &= ~WDestructiveClose;
00178 fl |= WDestructiveClose;
00179 setWFlags( fl );
00180 }
00181
00182
00183
00184 infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name)
00185 :QDialog(parent,name,true,WStyle_ContextHelp)
00186 {
00187 QVBoxLayout*dlglayout = new QVBoxLayout(this);
00188 dlglayout->setSpacing(2);
00189 dlglayout->setMargin(1);
00190 imageinfo*inf = new imageinfo(fname,this);
00191 dlglayout->addWidget(inf);
00192 }
00193
00194 infoDlg::~infoDlg()
00195 {
00196 }
00197
00198