00001 #include "imageview.h"
00002
00003 #include <opie2/odebug.h>
00004 #include <opie2/oconfig.h>
00005 #include <opie2/okeyconfigwidget.h>
00006 #include <opie2/oresource.h>
00007
00008 #include <qpe/qpeapplication.h>
00009 #include <qpe/qcopenvelope_qws.h>
00010
00011 #include <qpopupmenu.h>
00012 #include <qtimer.h>
00013 #include <qaction.h>
00014
00015 using namespace Opie::Core;
00016
00017 ImageView::ImageView(Opie::Core::OConfig *cfg, QWidget* parent, const char* name, WFlags fl )
00018 : Opie::MM::OImageScrollView(parent,name,fl)
00019 {
00020 m_viewManager = 0;
00021 focus_in_count = 0;
00022 m_cfg = cfg;
00023 m_isFullScreen = false;
00024 m_ignore_next_in = false;
00025 m_slideTimer = 0;
00026 QPEApplication::setStylusOperation(viewport(),QPEApplication::RightOnHold);
00027 initKeys();
00028 m_slideValue = 5;
00029 m_gDisplayType = 0;
00030 m_gPrevNext = 0;
00031 m_hGroup = 0;
00032 m_gBright = 0;
00033 m_Rotated = false;
00034 closeIfHide = false;
00035 int min = QApplication::desktop()->size().width()>QApplication::desktop()->size().height()?
00036 QApplication::desktop()->size().height():QApplication::desktop()->size().width();
00037 if (min>320) {
00038
00039 setMinimumSize(min/3,min/3);
00040 } else {
00041 setMinimumSize(10,10);
00042 }
00043 connect(this,SIGNAL(incBrightness()),this,SLOT(slotIncBrightness()));
00044 connect(this,SIGNAL(decBrightness()),this,SLOT(slotDecBrightness()));
00045
00046 m_sysChannel = new QCopChannel( "QPE/System", this );
00047 connect( m_sysChannel, SIGNAL( received(const QCString&,const QByteArray&) ),
00048 this, SLOT( systemMessage(const QCString&,const QByteArray&) ) );
00049 setKeyCompression(true);
00050 }
00051
00052 void ImageView::slotIncBrightness()
00053 {
00054 int lb = Intensity()+5;
00055 if (lb>100) lb=100;
00056 setIntensity(lb,true);
00057 }
00058
00059 void ImageView::slotDecBrightness()
00060 {
00061 int lb = Intensity()-5;
00062 if (lb<-100) lb=-100;
00063 setIntensity(lb,true);
00064 }
00065
00066 void ImageView::systemMessage( const QCString& msg, const QByteArray& data )
00067 {
00068 int _newrotation;
00069 QDataStream stream( data, IO_ReadOnly );
00070 if ( msg == "setCurrentRotation(int)" )
00071 {
00072 stream >> _newrotation;
00073 if (!fullScreen()) {
00074 m_rotation = _newrotation;
00075 return;
00076 }
00077 }
00078 }
00079
00080 void ImageView::setMenuActions(QActionGroup*hGroup,QActionGroup*nextprevGroup, QActionGroup*disptypeGroup,QActionGroup*brightGroup)
00081 {
00082 m_gDisplayType = disptypeGroup;
00083 m_gPrevNext = nextprevGroup;
00084 m_hGroup = hGroup;
00085 m_gBright = brightGroup;
00086 }
00087
00088 ImageView::~ImageView()
00089 {
00090 odebug << "Destructor imageview" << oendl;
00091 delete m_viewManager;
00092 }
00093
00094 Opie::Core::OKeyConfigManager* ImageView::manager()
00095 {
00096 if (!m_viewManager) {
00097 initKeys();
00098 }
00099 return m_viewManager;
00100 }
00101
00102 void ImageView::startSlide(int value)
00103 {
00104 if (!m_slideTimer) {
00105 m_slideTimer = new QTimer(this);
00106 }
00107 m_slideValue=value;
00108 connect(m_slideTimer,SIGNAL(timeout()),SLOT(nextSlide()));
00109
00110
00111
00112 m_slideTimer->start(m_slideValue*1000+1,true);
00113 }
00114
00115 void ImageView::stopSlide()
00116 {
00117 if (!m_slideTimer) {
00118 return;
00119 }
00120 m_slideTimer->stop();
00121 delete m_slideTimer;
00122 m_slideTimer = 0;
00123 }
00124
00125 void ImageView::nextSlide()
00126 {
00127 if (!m_slideTimer) {
00128 return;
00129 }
00130 #if 0
00131 if (isHidden()) {
00132 delete m_slideTimer;
00133 m_slideTimer = 0;
00134 return;
00135 }
00136 #endif
00137 emit dispNext();
00138 m_slideTimer->start(m_slideValue*1000,true);
00139 }
00140 void ImageView::initKeys()
00141 {
00142 odebug << "init imageview keys" << oendl;
00143 if (!m_cfg) {
00144 m_cfg = new Opie::Core::OConfig("opie-eye");
00145 m_cfg->setGroup("image_view_keys" );
00146 }
00147 Opie::Core::OKeyPair::List lst;
00148 lst.append( Opie::Core::OKeyPair(Qt::Key_Escape,0));
00149
00150 m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "image_view_keys",
00151 lst, false,this, "image_view_keys" );
00152
00159 m_viewManager->setEventMask( Opie::Core::OKeyConfigManager::MaskPressed );
00160
00161 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("View Image Info"), "imageviewinfo",
00162 Opie::Core::OResource::loadPixmap("1to1", Opie::Core::OResource::SmallIcon),
00163 ViewInfo, Opie::Core::OKeyPair(Qt::Key_I,0),
00164 this, SLOT(slotShowImageInfo())));
00165
00166 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autorotate"), "imageautorotate",
00167 Opie::Core::OResource::loadPixmap("rotate", Opie::Core::OResource::SmallIcon),
00168 Autorotate, Opie::Core::OKeyPair(Qt::Key_R,0),
00169 this, SIGNAL(toggleAutorotate())));
00170 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle autoscale"), "imageautoscale",
00171 Opie::Core::OResource::loadPixmap("1to1", Opie::Core::OResource::SmallIcon),
00172 Autoscale, Opie::Core::OKeyPair(Qt::Key_S,0),
00173 this, SIGNAL(toggleAutoscale())));
00174
00175 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to next image"), "imageshownext",
00176 Opie::Core::OResource::loadPixmap("forward", Opie::Core::OResource::SmallIcon),
00177 ShowNext, Opie::Core::OKeyPair(Qt::Key_Return,0),
00178 this, SIGNAL(dispNext())));
00179 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Switch to previous image"), "imageshowprev",
00180 Opie::Core::OResource::loadPixmap("back", Opie::Core::OResource::SmallIcon),
00181 ShowPrevious, Opie::Core::OKeyPair(Qt::Key_P,0),
00182 this, SIGNAL(dispPrev())));
00183 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle fullscreen"), "imagefullscreen",
00184 Opie::Core::OResource::loadPixmap("fullscreen", Opie::Core::OResource::SmallIcon),
00185 FullScreen, Opie::Core::OKeyPair(Qt::Key_F,0),
00186 this, SIGNAL(toggleFullScreen())));
00187 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Toggle thumbnail"), "imagezoomer",
00188 Opie::Core::OResource::loadPixmap("mag", Opie::Core::OResource::SmallIcon),
00189 Zoomer, Opie::Core::OKeyPair(Qt::Key_T,0),
00190 this, SIGNAL(toggleZoomer())));
00191
00192 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Increase brightness"), "incbrightness",
00193 Opie::Core::OResource::loadPixmap("up", Opie::Core::OResource::SmallIcon),
00194 Incbrightness, Opie::Core::OKeyPair(Qt::Key_B,0),
00195 this, SIGNAL(incBrightness())));
00196 m_viewManager->addKeyConfig( Opie::Core::OKeyConfigItem(tr("Decrease brightness"), "decbrightness",
00197 Opie::Core::OResource::loadPixmap("down", Opie::Core::OResource::SmallIcon),
00198 Decbrightness, Opie::Core::OKeyPair(Qt::Key_D,0),
00199 this, SIGNAL(decBrightness())));
00200 m_viewManager->handleWidget( this );
00201 m_viewManager->load();
00202 }
00203
00204 void ImageView::keyReleaseEvent(QKeyEvent * e)
00205 {
00206 if (!e || e->state()!=0) {
00207 return;
00208 }
00209 if (e->key()==Qt::Key_Escape) {
00210 if (fullScreen()) {
00211 emit hideMe();
00212 }
00213 if (closeIfHide) {
00214 QTimer::singleShot(0, qApp, SLOT(closeAllWindows()));
00215 }
00216 }
00217 }
00218
00219 void ImageView::setCloseIfHide(bool how)
00220 {
00221 closeIfHide = how;
00222 }
00223
00224 void ImageView::slotShowImageInfo()
00225 {
00226 emit dispImageInfo(m_lastName);
00227 }
00228
00229 void ImageView::contentsMousePressEvent ( QMouseEvent * e)
00230 {
00231 if (e->button()==1) {
00232 return OImageScrollView::contentsMousePressEvent(e);
00233 }
00234 QPopupMenu *m = new QPopupMenu(this);
00235 if (!m) return;
00236 if (m_hGroup) {
00237 m_hGroup->addTo(m);
00238 }
00239 if (fullScreen()) {
00240 if (m_gPrevNext) {
00241 m->insertSeparator();
00242 m_gPrevNext->addTo(m);
00243 }
00244 if (m_gDisplayType) {
00245 m->insertSeparator();
00246 m_gDisplayType->addTo(m);
00247 }
00248 if (m_gBright) {
00249 m->insertSeparator();
00250 m_gBright->addTo(m);
00251 }
00252 }
00253 m->setFocus();
00254 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
00255 if (m_hGroup) {
00256 m_hGroup->removeFrom(m);
00257 }
00258 if (m_gPrevNext) {
00259 m_gPrevNext->removeFrom(m);
00260 }
00261 if (m_gDisplayType) {
00262 m_gDisplayType->removeFrom(m);
00263 }
00264 if (m_gBright) {
00265 m_gBright->removeFrom(m);
00266 }
00267 delete m;
00268 }
00269
00270 void ImageView::setFullScreen(bool how,bool force)
00271 {
00272 m_isFullScreen = how;
00273 if (how) {
00274 m_ignore_next_in = true;
00275
00276 setGeometry(0,0,qApp->desktop()->size().width(),qApp->desktop()->size().height());
00277 if (force) showFullScreen();
00278 } else {
00279
00280 }
00281 }
00282
00283 void ImageView::focusInEvent(QFocusEvent *)
00284 {
00285
00286
00287 if (m_ignore_next_in){m_ignore_next_in=false;return;}
00288 if (fullScreen()) enableFullscreen();
00289 }
00290
00291 void ImageView::hide()
00292 {
00293 if (fullScreen()) {
00294 m_ignore_next_in = true;
00295 showNormal();
00296 }
00297 QWidget::hide();
00298 }
00299 void ImageView::enableFullscreen()
00300 {
00301 if (!fullScreen()) return;
00302 if (m_ignore_next_in) {m_ignore_next_in = false;return;}
00303
00304 setUpdatesEnabled(false);
00305
00306
00307 reparent(0, WStyle_Customize | WStyle_NoBorderEx, QPoint(0,0));
00308
00309
00310
00311 m_ignore_next_in = true;
00312 showFullScreen();
00313 setUpdatesEnabled(true);
00314 }