-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 20 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.h | 4 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/viewmodebutton.cpp | 29 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/viewmodebutton.h | 2 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/lib/oimagezoomer.cpp | 9 |
5 files changed, 56 insertions, 8 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index a06844a..e61f9d9 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -1,491 +1,503 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #include "iconview.h" #include <lib/imagecache.h> #include <gui/imageinfoui.h> #include <gui/imagescrollview.h> #include <iface/dirview.h> #include <iface/dirlister.h> #include <opie2/oconfig.h> #include <opie2/okeyconfigwidget.h> #include <opie2/odebug.h> #include <qpe/resource.h> #include <qpe/qpemessagebox.h> #include <qpe/ir.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qiconview.h> #include <qlabel.h> #include <qhbox.h> #include <qcombobox.h> #include <qdir.h> #include <qapplication.h> #include <qmainwindow.h> #include <qtimer.h> #include <qstyle.h> using Opie::Core::OKeyConfigItem; /* * The Icons, Request Cache and IconViewItem for the IconView */ namespace { static QPixmap* _dirPix = 0; static QPixmap* _unkPix = 0; static QPixmap* _picPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); QPixmap* pixmap()const; QString path()const { return m_path; } bool isDir()const { return m_isDir; } void setText( const QString& ); protected: mutable QPixmap* m_pix; private: QString m_path; bool m_isDir : 1; bool m_noInfo :1; }; class TextViewItem : public IconViewItem { TextViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; class ThumbViewItem : public IconViewItem { ThumbViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; /* * If we request an Image or String * we add it to the map */ static QMap<QString, IconViewItem*> g_stringInf; static QMap<QString, IconViewItem*> g_stringPix; IconViewItem::IconViewItem( QIconView* view,const QString& path, const QString& name, bool isDir ) : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), m_noInfo( false ) { if ( isDir && !_dirPix ) _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); else if ( !isDir && !_unkPix ) _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } inline QPixmap* IconViewItem::pixmap()const { // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", // rect().x(),rect().y(),rect().width(),rect().height(), // iconView()->contentsX(), iconView()->contentsY()); if ( m_isDir ) return _dirPix; else{ if (!m_noInfo && !g_stringInf.contains( m_path ) ) { currentView()->dirLister()->imageInfo( m_path ); g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); } m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); if ( !m_pix && !g_stringPix.contains( m_path )) { currentView()->dirLister()->thumbNail( m_path, 64, 64 ); g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); } return m_pix ? m_pix : _unkPix; } } inline void IconViewItem::setText( const QString& str ) { QString text = QIconViewItem::text()+"\n"+str; m_noInfo = true; QIconViewItem::setText( text ); } } /* * Set up the GUI.. initialize the slave set up gui * and also load a dir */ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } m_path = QDir::homeDirPath(); m_mode = 0; QHBox *hbox = new QHBox( this ); QLabel* lbl = new QLabel( hbox ); lbl->setText( tr("View as" ) ); m_views = new QComboBox( hbox, "View As" ); connect( m_views, SIGNAL(activated(int)), this, SLOT(slotViewChanged(int)) ); m_view= new QIconView( this ); connect(m_view, SIGNAL(clicked(QIconViewItem*) ), this, SLOT(slotClicked(QIconViewItem*)) ); connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), this, SLOT(slotClicked(QIconViewItem*)) ); m_view->setArrangement( QIconView::LeftToRight ); m_view->setItemTextPos( QIconView::Right ); int dw = QApplication::desktop()->width(); int viewerWidth = dw-style().scrollBarExtent().width(); m_view->setGridX( viewerWidth-3*m_view->spacing()); m_view->setGridY( fontMetrics().height()*2+40 ); initKeys(); loadViews(); slotViewChanged( m_views->currentItem() ); } /* * Unref the slave and save the keyboard manager */ PIconView::~PIconView() { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); } m_viewManager->save(); delete m_viewManager; } Opie::Core::OKeyConfigManager* PIconView::manager() { return m_viewManager; } /* * init the KeyBoard Shortcuts * called from the c'tor */ void PIconView::initKeys() { Opie::Core::OKeyPair::List lst; lst.append( Opie::Core::OKeyPair::upArrowKey() ); lst.append( Opie::Core::OKeyPair::downArrowKey() ); lst.append( Opie::Core::OKeyPair::leftArrowKey() ); lst.append( Opie::Core::OKeyPair::rightArrowKey() ); lst.append( Opie::Core::OKeyPair::returnKey() ); m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", lst, false,this, "keyconfig name" ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", Resource::loadPixmap("beam"), BeamItem, Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), this, SLOT(slotBeam())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", Resource::loadPixmap("trash"), DeleteItem, Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), this, SLOT(slotTrash())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", Resource::loadPixmap("1to1"), ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), this, SLOT(slotShowImage()))); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", Resource::loadPixmap("DocumentTypeWord"), InfoItem, Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), this, SLOT(slotImageInfo()) ) ); m_viewManager->load(); m_viewManager->handleWidget( m_view ); } /* * change one dir up */ void PIconView::slotDirUp() { QDir dir( m_path ); dir.cdUp(); slotChangeDir( dir.absPath() ); } /* * change the dir */ void PIconView::slotChangeDir(const QString& path) { if ( !currentView() ) return; PDirLister *lister = currentView()->dirLister(); if (!lister ) return; /* * Say what we want and take what we get */ lister->setStartPath( path ); m_path = lister->currentPath(); m_view->viewport()->setUpdatesEnabled( false ); m_view->clear(); /* * add files and folders */ addFolders( lister->folders() ); addFiles( lister->files() ); m_view->viewport()->setUpdatesEnabled( true ); // Also invalidate the cache. We can't cancel the operations anyway g_stringPix.clear(); g_stringInf.clear(); // looks ugly static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); } /** * get the current file name * @param isDir see if this is a dir or real file */ QString PIconView::currentFileName(bool &isDir)const { isDir = false; QIconViewItem* _it = m_view->currentItem(); if ( !_it ) return QString::null; IconViewItem* it = static_cast<IconViewItem*>( _it ); isDir = it->isDir(); return it->path(); } void PIconView::slotTrash() { bool isDir; QString pa = currentFileName( isDir ); if ( isDir && pa.isEmpty() ) return; if (!QPEMessageBox::confirmDelete( this, tr("Delete Image" ), tr("the Image %1" ).arg(pa))) return currentView()->dirLister()->deleteImage( pa ); delete m_view->currentItem(); } /* * see what views are available */ void PIconView::loadViews() { ViewMap::Iterator it; ViewMap* map = viewMap(); for ( it = map->begin(); it != map->end(); ++it ) m_views->insertItem( QObject::tr(it.key() ) ); } void PIconView::resetView() { slotViewChanged(m_views->currentItem()); } /* *swicth view reloadDir and connect signals */ void PIconView::slotViewChanged( int i) { if (!m_views->count() ) { setCurrentView( 0l); return; } PDirView* cur = currentView(); delete cur; QString str = m_views->text(i); cur = (*(*viewMap())[str])(*m_cfg); setCurrentView( cur ); /* connect to the signals of the lister */ PDirLister* lis = cur->dirLister(); connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), this, SLOT( slotThumbInfo(const QString&, const QString&))); connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), this, SLOT(slotThumbNail(const QString&, const QPixmap&))); connect(lis, SIGNAL(sig_start()), this, SLOT(slotStart())); connect(lis, SIGNAL(sig_end()) , this, SLOT(slotEnd()) ); /* reload now */ QTimer::singleShot( 0, this, SLOT(slotReloadDir())); } void PIconView::slotReloadDir() { slotChangeDir( m_path ); } /* * add files and folders */ void PIconView::addFolders( const QStringList& lst) { QStringList::ConstIterator it; for(it=lst.begin(); it != lst.end(); ++it ) (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); } void PIconView::addFiles( const QStringList& lst) { QStringList::ConstIterator it; for (it=lst.begin(); it!= lst.end(); ++it ) (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); } /* * user clicked on the item. Change dir or view */ void PIconView::slotClicked(QIconViewItem* _it) { if(!_it ) return; IconViewItem* it = static_cast<IconViewItem*>(_it); if( it->isDir() ) slotChangeDir( it->path() ); else // view image slotShowImage(); } /* * got thumb info add to the cache if items is visible * we later need update after processing of slave is done */ void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { IconViewItem* item = g_stringInf[_path]; if (!item ) return; if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), m_view->contentsWidth(), m_view->contentsHeight() ) ) ) m_updatet = true; item->setText( str ); g_stringInf.remove( _path ); } /* * got thumbnail and see if it is visible so we need to update later */ void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { IconViewItem* item = g_stringPix[_path]; if (!item ) return; if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), m_view->contentsWidth(), m_view->contentsHeight() ) ) ) m_updatet = true; if (pix.width()>0) PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); g_stringPix.remove( _path ); } /* * FIXME rename */ void PIconView::slotRename() { } /* * BEAM the current file */ void PIconView::slotBeam() { bool isDir; QString pa = currentFileName( isDir ); if ( isDir && pa.isEmpty() ) return; Ir* ir = new Ir( this ); connect( ir, SIGNAL(done(Ir*)), this, SLOT(slotBeamDone(Ir*))); ir->send(pa, tr( "Image" ) ); } /* * BEAM done clean up */ void PIconView::slotBeamDone( Ir* ir) { delete ir; } void PIconView::slotStart() { m_view->viewport()->setUpdatesEnabled( false ); } void PIconView::slotEnd() { if ( m_updatet ) m_view->arrangeItemsInGrid( ); m_view->viewport()->setUpdatesEnabled( true ); m_updatet = false; } void PIconView::slotShowImage() { bool isDir = false; QString name = currentFileName(isDir); if (isDir) return; slotShowImage( name ); } void PIconView::slotShowImage( const QString& name) { emit sig_display( name ); } void PIconView::slotImageInfo() { bool isDir = false; QString name = currentFileName(isDir); if (isDir) return; slotImageInfo( name ); } void PIconView::slotImageInfo( const QString& name) { emit sig_showInfo( name ); } void PIconView::slotChangeMode( int mode ) { - if ( mode >= 0 && mode <= 3 ) + if ( mode >= 1 && mode <= 3 ) m_mode = mode; QIconView::ItemTextPos pos; switch( m_mode ) { - case 1: + case 2: pos = QIconView::Bottom; break; - case 2: - case 0: + case 3: + case 1: default: pos = QIconView::Right; break; } m_view->setItemTextPos( pos ); + calculateGrid(); slotReloadDir(); } + + +void PIconView::resizeEvent( QResizeEvent* re ) { + QVBox::resizeEvent( re ); + calculateGrid(); +} + + +void PIconView::calculateGrid() { + +} diff --git a/noncore/graphics/opie-eye/gui/iconview.h b/noncore/graphics/opie-eye/gui/iconview.h index af41aef..903c4fd 100644 --- a/noncore/graphics/opie-eye/gui/iconview.h +++ b/noncore/graphics/opie-eye/gui/iconview.h @@ -1,85 +1,89 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #ifndef PHUNK_ICON_VIEW_H #define PHUNK_ICON_VIEW_H #include <qvbox.h> class QIconView; class QIconViewItem; class QComboBox; class PIconViewItem; class PDirLister; class Ir; namespace Opie { namespace Core{ class OConfig; class OKeyConfigManager; } } class PIconView : public QVBox { Q_OBJECT friend class PIconViewItem; enum ActionIds { BeamItem, DeleteItem, ViewItem, InfoItem }; public: PIconView( QWidget* wid, Opie::Core::OConfig *cfg ); ~PIconView(); void resetView(); Opie::Core::OKeyConfigManager* manager(); signals: void sig_showInfo( const QString& ); void sig_display( const QString& ); +protected: + void resizeEvent( QResizeEvent* ); + private: void initKeys(); QString currentFileName(bool &isDir)const; void loadViews(); + void calculateGrid(); private slots: void slotDirUp(); void slotChangeDir(const QString&); void slotTrash(); void slotViewChanged( int ); void slotReloadDir(); void slotRename(); void slotBeam(); void slotBeamDone( Ir* ); void slotShowImage(); void slotShowImage( const QString& ); void slotImageInfo(); void slotImageInfo( const QString& ); void slotStart(); void slotEnd(); /* for performance reasons make it inline in the future */ void addFolders( const QStringList& ); void addFiles( const QStringList& ); void slotClicked(QIconViewItem* ); /**/ void slotThumbInfo(const QString&, const QString&); void slotThumbNail(const QString&, const QPixmap&); void slotChangeMode( int ); private: Opie::Core::OKeyConfigManager *m_viewManager; Opie::Core::OConfig *m_cfg; QComboBox* m_views; QIconView* m_view; QString m_path; bool m_updatet : 1; int m_mode; }; #endif diff --git a/noncore/graphics/opie-eye/gui/viewmodebutton.cpp b/noncore/graphics/opie-eye/gui/viewmodebutton.cpp index fdf4e77..0e4a7cb 100644 --- a/noncore/graphics/opie-eye/gui/viewmodebutton.cpp +++ b/noncore/graphics/opie-eye/gui/viewmodebutton.cpp @@ -1,24 +1,45 @@ #include "viewmodebutton.h" +#include <opie2/odebug.h> + #include <qtoolbar.h> #include <qpopupmenu.h> ViewModeButton::ViewModeButton( QToolBar* bar ) : QToolButton( bar ) { - setIconSet( Resource::loadIconSet( "toys" ) ); + slotChange( 1 ); QPopupMenu *pop= new QPopupMenu( this ); pop->setCheckable( true ); - pop->insertItem( tr("Thumbnail and Imageinfo"), 0 ); - pop->insertItem( tr("Thumbnail and Name" ), 1 ); - pop->insertItem( tr("Name Only" ), 2 ); + pop->insertItem( tr("Thumbnail and Imageinfo"), 1 ); + pop->insertItem( tr("Thumbnail and Name" ), 2 ); + pop->insertItem( tr("Name Only" ), 3 ); connect(pop, SIGNAL(activated(int)), this, SIGNAL(changeMode(int)) ); + connect(pop, SIGNAL(activated(int)), + this, SLOT(slotChange(int)) ); setPopup( pop ); } ViewModeButton::~ViewModeButton() { +} + +void ViewModeButton::slotChange( int i ) { + QString name; + switch( i ) { + case 1: + name = "opie-eye/opie-eye-thumb"; + break; + case 2: + name = "opie-eye/opie-eye-thumbonly"; + break; + case 3: + name = "opie-eye/opie-eye-textview"; + break; + } + qWarning("foo %d" +name, i ); + setIconSet( Resource::loadIconSet( name ) ); } diff --git a/noncore/graphics/opie-eye/gui/viewmodebutton.h b/noncore/graphics/opie-eye/gui/viewmodebutton.h index 44f2228..3247114 100644 --- a/noncore/graphics/opie-eye/gui/viewmodebutton.h +++ b/noncore/graphics/opie-eye/gui/viewmodebutton.h @@ -1,23 +1,25 @@ /* * GPLv2 only * zecke@handhelds.org */ #ifndef PHUNK_VIEW_MODE_BUTTON_H #define PHUNK_VIEW_MODE_BUTTON_H #include <qpe/resource.h> #include <qtoolbutton.h> class ViewModeButton : public QToolButton { Q_OBJECT public: ViewModeButton( QToolBar* ); ~ViewModeButton(); signals: void changeMode( int ); +private slots: + void slotChange( int i ); }; #endif diff --git a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp index 4df5dcc..00b93e2 100644 --- a/noncore/graphics/opie-eye/lib/oimagezoomer.cpp +++ b/noncore/graphics/opie-eye/lib/oimagezoomer.cpp @@ -1,210 +1,219 @@ #include "oimagezoomer.h" #include <qimage.h> #include <qpixmap.h> #include <qpainter.h> #include <qrect.h> #include <qpoint.h> #include <qsize.h> namespace Opie { namespace MM { /** * \brief The most simple c'tor * The main c'tor. You still need to set a QPixmap/QIMage, * setImageSize,setViewPortSize,setVisiblePoint * * @param parent The parent widget * @param name A name for this widget * @param fl The widget flags * */ OImageZoomer::OImageZoomer( QWidget* parent, const char* name, WFlags fl ) : QFrame( parent, name, fl ) { init(); } /** * \brief This c'tor takes a QPixmap additional * * You initially set the QPixmap but you still need to provide * the additional data to make this widget useful * * @param pix A Pixmap it'll be converted to a QImage later! * @param par The parent widget * @param name The name of this widget * @param fl The widget flags */ OImageZoomer::OImageZoomer( const QPixmap& pix, QWidget* par, const char* name, WFlags fl ) : QFrame( par, name, fl ) { init(); setImage( pix ); } /** * \brief This c'tor takes a QImage instead * You just provide a QImage which is saved. It behaves the same as the others. * * @param img A Image which will be used for the zoomer content * @param par The parent of the widget * @param name The name of the widget * @param fl The widgets flags */ OImageZoomer::OImageZoomer( const QImage& img, QWidget* par, const char* name, WFlags fl) : QFrame( par, name, fl ) { init(); setImage( img ); } /** * \brief overloaded c'tor * * This differs only in the arguments it takes * * * @param pSize The size of the Page you show * @param vSize The size of the viewport. The size of the visible part of the widget * @param par The parent of the widget * @param name The name * @param fl The window flags */ OImageZoomer::OImageZoomer( const QSize& pSize, const QSize& vSize, QWidget* par, const char* name, WFlags fl ) : QFrame( par, name, fl ), m_imgSize( pSize ),m_visSize( vSize ) { init(); } /** * d'tor */ OImageZoomer::~OImageZoomer() { } void OImageZoomer::init() { setFrameStyle( Panel | Sunken ); } /** * \brief set the page/image size * Tell us the QSize of the Data you show to the user. We need this * to do the calculations * * @param size The size of the stuff you want to zoom on */ void OImageZoomer::setImageSize( const QSize& size ) { m_imgSize = size; repaint(); } /** * \brief Set the size of the viewport * Tell us the QSize of the viewport. The viewport is the part * of the widget which is exposed on the screen * * @param size Te size of the viewport * * @see QScrollView::viewport() */ void OImageZoomer::setViewPortSize( const QSize& size ) { m_visSize = size; repaint(); } /** * \brief the point in the topleft corner which is currently visible * Set the visible point. This most of the times relate to QScrollView::contentsX() * and QScrollView::contentsY() * * @see setVisiblePoint(int,int) */ void OImageZoomer::setVisiblePoint( const QPoint& pt ) { m_visPt = pt; repaint(); } /** * Set the Image. The image will be resized on resizeEvent * and it'll set the QPixmap background * * @param img The image will be stored internally and used as the background */ void OImageZoomer::setImage( const QImage& img) { m_img = img; resizeEvent( 0 ); repaint(); } /** * overloaded function it calls the QImage version */ void OImageZoomer::setImage( const QPixmap& pix) { setImage( pix.convertToImage() ); } void OImageZoomer::resizeEvent( QResizeEvent* ev ) { QFrame::resizeEvent( ev ); setBackgroundOrigin( QWidget::WidgetOrigin ); // TODO Qt3 use PalettePixmap and use size QPixmap pix; pix.convertFromImage( m_img.smoothScale( size().width(), size().height() ) ); setBackgroundPixmap( pix); } void OImageZoomer::drawContents( QPainter* p ) { /* * if the page size */ if ( m_imgSize.isEmpty() ) return; /* * paint a red rect which represents the visible size * * We need to recalculate x,y and width and height of the * rect. So image size relates to contentRect * */ QRect c( contentsRect() ); p->setPen( Qt::red ); + /* + * the contentRect is set equal to the size of the image + * Rect/Original = NewRectORWidth/OriginalVisibleStuff and then simply we + * need to add the c.y/x due usage of QFrame + * For x and y we use the visiblePoint + * For height and width we use the size of the viewport + * if width/height would be bigger than our widget we use this width/height + * + */ int len = m_imgSize.width(); int x = (c.width()*m_visPt.x())/len + c.x(); int w = (c.width()*m_visSize.width() )/len + c.x(); if ( w > c.width() ) w = c.width(); len = m_imgSize.height(); int y = (c.height()*m_visPt.y() )/len + c.y(); int h = (c.height()*m_visSize.height() )/len + c.y(); if ( h > c.height() ) h = c.height(); p->drawRect( x, y, w, h ); } void OImageZoomer::mousePressEvent( QMouseEvent* ) { m_mouseX = m_mouseY = -1; } void OImageZoomer::mouseMoveEvent( QMouseEvent* ev ) { int mx, my; mx = ev->x(); my = ev->y(); if ( m_mouseX != -1 && m_mouseY != -1 ) { int diffx = ( mx - m_mouseX ) * m_imgSize.width() / width(); int diffy = ( my - m_mouseY ) * m_imgSize.height() / height(); emit zoomAreaRel( diffx, diffy ); emit zoomArea(m_visPt.x()+diffx, m_visPt.y()+diffy ); } m_mouseX = mx; m_mouseY = my; } } } |