author | zecke <zecke> | 2004-04-05 20:01:22 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-04-05 20:01:22 (UTC) |
commit | ecdd2845abeb5f3d00f58540e9b222799d6610e8 (patch) (side-by-side diff) | |
tree | 7199007b1dc296bb4572f2c96178d47d2f36bc02 | |
parent | cb3097d5249b6bd576d0212394ab57e885f9e9da (diff) | |
download | opie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.zip opie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.tar.gz opie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.tar.bz2 |
Make use of OWidgetStack
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 61 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.h | 4 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.cpp | 29 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imageinfoui.h | 20 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 20 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.cpp | 109 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/mainwindow.h | 24 |
8 files changed, 237 insertions, 36 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index de2cdf0..4ced52d 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -34,11 +34,14 @@ using Opie::Ui::OKeyConfigItem; +/* + * The Icons, Request Cache and IconViewItem for the IconView + */ namespace { - QPixmap* _dirPix = 0; - QPixmap* _unkPix = 0; + static QPixmap* _dirPix = 0; + static QPixmap* _unkPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); QPixmap* pixmap()const; @@ -58,10 +61,10 @@ namespace { /* * If we request an Image or String * we add it to the map */ - QMap<QString, IconViewItem*> g_stringInf; - QMap<QString, IconViewItem*> g_stringPix; + 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 ), @@ -100,8 +103,12 @@ namespace { } } +/* + * 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 ) { { @@ -135,8 +142,11 @@ PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) loadViews(); slotViewChanged( m_views->currentItem() ); } +/* + * Unref the slave and save the keyboard manager + */ PIconView::~PIconView() { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); } @@ -147,8 +157,13 @@ PIconView::~PIconView() { Opie::Ui::OKeyConfigManager* PIconView::manager() { return m_viewManager; } + +/* + * init the KeyBoard Shortcuts + * called from the c'tor + */ void PIconView::initKeys() { Opie::Ui::OKeyPair::List lst; lst.append( Opie::Ui::OKeyPair::upArrowKey() ); lst.append( Opie::Ui::OKeyPair::downArrowKey() ); @@ -177,15 +192,22 @@ void PIconView::initKeys() { 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; @@ -283,11 +305,11 @@ void PIconView::slotReloadDir() { void PIconView::addFolders( const QStringList& lst) { QStringList::ConstIterator it; - for(it=lst.begin(); it != lst.end(); ++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) { @@ -304,9 +326,9 @@ void PIconView::slotClicked(QIconViewItem* _it) { IconViewItem* it = static_cast<IconViewItem*>(_it); if( it->isDir() ) slotChangeDir( it->path() ); else // view image - ; + slotShowImage(); } void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { IconViewItem* item = g_stringInf[_path]; @@ -359,38 +381,37 @@ void PIconView::slotBeamDone( Ir* ir) { } void PIconView::slotStart() { m_view->viewport()->setUpdatesEnabled( false ); - qWarning( "Sig Start" ); } void PIconView::slotEnd() { - qWarning( "SLot End" ); if ( m_updatet ) m_view->arrangeItemsInGrid( ); m_view->viewport()->setUpdatesEnabled( true ); m_updatet = false; } -void PIconView::slotShowImage() { - qDebug("image show"); +void PIconView::slotShowImage() +{ + qWarning( "SLotShowImage" ); bool isDir = false; QString name = currentFileName(isDir); if (isDir) return; - ImageDlg dlg(name); - QPEApplication::execDialog(&dlg); -} -void PIconView::slotShowImage( const QString& ) { + slotShowImage( name ); +} +void PIconView::slotShowImage( const QString& name) { + emit sig_display( name ); } void PIconView::slotImageInfo() { - qDebug("image info"); + qWarning( "SlotImageInfo" ); bool isDir = false; QString name = currentFileName(isDir); if (isDir) return; - infoDlg dlg(name); - QPEApplication::execDialog(&dlg); + + slotImageInfo( name ); } -void PIconView::slotImageInfo( const QString& ) { - +void PIconView::slotImageInfo( const QString& name) { + emit sig_showInfo( name ); } diff --git a/noncore/graphics/opie-eye/gui/iconview.h b/noncore/graphics/opie-eye/gui/iconview.h index 7ddb023..a4ca0bc 100644 --- a/noncore/graphics/opie-eye/gui/iconview.h +++ b/noncore/graphics/opie-eye/gui/iconview.h @@ -36,8 +36,12 @@ public: ~PIconView(); void resetView(); Opie::Ui::OKeyConfigManager* manager(); +signals: + void sig_showInfo( const QString& ); + void sig_display( const QString& ); + private: void initKeys(); QString currentFileName(bool &isDir)const; void loadViews(); diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.cpp b/noncore/graphics/opie-eye/gui/imageinfoui.cpp index 3463ba6..74a9ea4 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.cpp +++ b/noncore/graphics/opie-eye/gui/imageinfoui.cpp @@ -18,13 +18,24 @@ #include <qpe/qcopenvelope_qws.h> #include <qpe/resource.h> -#define THUMBSIZE 128 +static const int THUMBSIZE = 128; + + +imageinfo::imageinfo(QWidget* parent, const char* name, WFlags fl ) + : QWidget( parent, name, fl ) +{ + init(name); +} imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WFlags fl ) : QWidget( parent, name, fl ),currentFile(_path) { + init(name); + slotChangeName(_path); +} +void imageinfo::init(const char* name) { { QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); } if ( !name ) @@ -61,9 +72,8 @@ imageinfo::imageinfo(const QString&_path, QWidget* parent, const char* name, WF connect( master, SIGNAL(sig_fullInfo(const QString&, const QString&)), this, SLOT(slot_fullInfo(const QString&, const QString&)) ); connect(master, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), this, SLOT(slotThumbNail(const QString&, const QPixmap&))); - slotChangeName(_path); } void imageinfo::slotChangeName(const QString&_path) { @@ -110,8 +120,21 @@ void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix) } } } +void imageinfo::setPath( const QString& str ) { + slotChangeName( str ); +} + +void imageinfo::setDestructiveClose() { + WFlags fl = getWFlags(); + /* clear it just in case */ + fl &= ~WDestructiveClose; + fl |= WDestructiveClose; + setWFlags( fl ); +} + + /* for testing */ infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name) :QDialog(parent,name,true,WStyle_ContextHelp) { @@ -124,4 +147,6 @@ infoDlg::infoDlg(const QString&fname,QWidget * parent, const char * name) infoDlg::~infoDlg() { } + + diff --git a/noncore/graphics/opie-eye/gui/imageinfoui.h b/noncore/graphics/opie-eye/gui/imageinfoui.h index 34ec937..300c92a 100644 --- a/noncore/graphics/opie-eye/gui/imageinfoui.h +++ b/noncore/graphics/opie-eye/gui/imageinfoui.h @@ -4,23 +4,33 @@ #include <qvariant.h> #include <qwidget.h> #include <qdialog.h> -class QVBoxLayout; -class QHBoxLayout; -class QGridLayout; +class QVBoxLayout; +class QHBoxLayout; +class QGridLayout; class QFrame; class QLabel; class QTextView; class imageinfo : public QWidget -{ +{ Q_OBJECT public: + imageinfo( QWidget* parent = 0, const char* name = 0, WFlags fl =0); imageinfo(const QString&_path, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); ~imageinfo(); + void setDestructiveClose(); + +public slots: + void setPath( const QString& path ); + +private: + void init(const char* name); + +protected: QLabel* PixmapLabel1; QLabel* fnameLabel; QFrame* Line1; QTextView* TextView1; @@ -31,9 +41,9 @@ protected: protected slots: virtual void slot_fullInfo(const QString&, const QString&); virtual void slotThumbNail(const QString&, const QPixmap&); - + virtual void slotChangeName(const QString&); }; /* for testing purpose */ diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp index 0d35354..7d83e29 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.cpp +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp @@ -6,8 +6,15 @@ using namespace Opie::Core; #include <qimage.h> #include <qlayout.h> +ImageScrollView::ImageScrollView( QWidget* parent, const char* name, WFlags f ) + :QScrollView(parent,name,f|Qt::WRepaintNoErase ),_image_data(),_original_data(),scale_to_fit(true), + rotate_to_fit(true),first_resize_done(false) +{ + init(); +} + ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f,bool always_scale,bool rfit) :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(),_original_data(img),scale_to_fit(always_scale), rotate_to_fit(rfit),first_resize_done(false) { @@ -28,8 +35,12 @@ void ImageScrollView::setImage(const QImage&img) first_resize_done = false; init(); } +void ImageScrollView::setImage( const QString& path ) { + +} + /* should be called every time the QImage changed it content */ void ImageScrollView::init() { viewport()->setBackgroundColor(white); @@ -258,8 +269,17 @@ void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) _mouseStartPosX = e->x(); _mouseStartPosY = e->y(); } +void ImageScrollView::setDestructiveClose() { + WFlags fl = getWFlags(); + /* clear it just in case */ + fl &= ~WDestructiveClose; + fl |= WDestructiveClose; + setWFlags( fl ); +} + + /* for testing */ ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) :QDialog(parent,name,true,WStyle_ContextHelp) { diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h index e25f955..864a015 100644 --- a/noncore/graphics/opie-eye/gui/imagescrollview.h +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h @@ -11,21 +11,27 @@ class QPainter; class ImageScrollView:public QScrollView { Q_OBJECT public: + ImageScrollView( QWidget* parent, const char* name = 0, WFlags fl = 0 ); ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0,bool always_scale=false,bool rfit=false ); virtual ~ImageScrollView(); void setImage(const QImage&); + void setImage( const QString& path ); + void setDestructiveClose(); enum Rotation { Rotate0, Rotate90, Rotate180, Rotate270 }; +signals: + void sig_return(); + protected: virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); void init(); diff --git a/noncore/graphics/opie-eye/gui/mainwindow.cpp b/noncore/graphics/opie-eye/gui/mainwindow.cpp index 83ff4f1..7f384bd 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.cpp +++ b/noncore/graphics/opie-eye/gui/mainwindow.cpp @@ -5,12 +5,16 @@ #include "mainwindow.h" #include "iconview.h" #include "filesystem.h" +#include "imageinfoui.h" +#include "imagescrollview.h" #include <iface/ifaceinfo.h> #include <iface/dirview.h> +#include <opie2/odebug.h> +#include <opie2/owidgetstack.h> #include <opie2/oapplicationfactory.h> #include <opie2/otabwidget.h> #include <opie2/okeyconfigwidget.h> @@ -23,17 +27,17 @@ #include <qtoolbutton.h> #include <qlayout.h> #include <qdialog.h> #include <qmap.h> - +#include <qtimer.h> OPIE_EXPORT_APP( Opie::Core::OApplicationFactory<PMainWindow> ) PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) - : QMainWindow( wid, name, style ) + : QMainWindow( wid, name, style ), m_info( 0 ), m_disp( 0 ) { setCaption( QObject::tr("Opie Eye Caramba" ) ); m_cfg = new Opie::Core::OConfig("phunkview"); m_cfg->setGroup("Zecke_view" ); @@ -46,10 +50,18 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) QToolBar *bar = new QToolBar( this ); bar->setHorizontalStretchable( true ); setToolBarsMovable( false ); - m_view = new PIconView( this, m_cfg ); - setCentralWidget( m_view ); + m_stack = new Opie::Ui::OWidgetStack( this ); + setCentralWidget( m_stack ); + + m_view = new PIconView( m_stack, m_cfg ); + m_stack->addWidget( m_view, IconView ); + m_stack->raiseWidget( IconView ); + connect(m_view, SIGNAL(sig_display(const QString&)), + this, SLOT(slotDisplay(const QString&))); + connect(m_view, SIGNAL(sig_showInfo(const QString&)), + this, SLOT(slotShowInfo(const QString&)) ); QToolButton *btn = new QToolButton( bar ); btn->setIconSet( Resource::loadIconSet( "up" ) ); connect( btn, SIGNAL(clicked()), @@ -83,17 +95,18 @@ PMainWindow::PMainWindow(QWidget* wid, const char* name, WFlags style) } PMainWindow::~PMainWindow() { + odebug << "Shutting down" << oendl; } void PMainWindow::slotConfig() { -/* - * have a tab with the possible views - * a tab for globals image cache size.. scaled loading - * and one tab for the KeyConfigs - */ + /* + * have a tab with the possible views + * a tab for globals image cache size.. scaled loading + * and one tab for the KeyConfigs + */ QDialog dlg(this, 0, true); dlg.setCaption( tr("Phunk View - Config" ) ); QHBoxLayout *lay = new QHBoxLayout(&dlg); @@ -123,16 +136,94 @@ void PMainWindow::slotConfig() { bool act = ( QPEApplication::execDialog( &dlg ) == QDialog::Accepted ); +/* + * clean up + *apply changes + */ + QMap<PDirView*, QWidget*>::Iterator it; for ( it = lst.begin(); it != lst.end(); ++it ) { if ( act ) it.key()->interfaceInfo()->writeConfig(it.data(), *m_cfg); delete it.key(); } + if ( act ) { m_view->resetView(); keyWid->save(); } } + +/* + * create a new image info component + * and detach the current one + * we will make the other delete on exit + */ +template<class T> +void PMainWindow::initT( const char* name, T** ptr, int id) { + if ( *ptr ) { + (*ptr)->disconnect(this, SLOT(slotReturn())); + (*ptr)->setDestructiveClose(); + m_stack->removeWidget( *ptr ); + } + *ptr = new T( m_stack, name ); + m_stack->addWidget( *ptr, id ); + + connect(*ptr, SIGNAL(sig_return()), + this,SLOT(slotReturn())); + +} +void PMainWindow::initInfo() { + initT<imageinfo>( "Image Info", &m_info, ImageInfo ); +} +void PMainWindow::initDisp() { + initT<ImageScrollView>( "Image ScrollView", &m_disp, ImageDisplay ); +} + +/** + * With big Screen the plan could be to 'detach' the image + * window if visible and to create a ne wone + * init* already supports it but I make no use of it for + * now. We set filename and raise + * + * ### FIXME and talk to alwin + */ +void PMainWindow::slotShowInfo( const QString& inf ) { + if ( !m_info ) + initInfo(); + m_info->setPath( inf ); + m_stack->raiseWidget( ImageInfo ); +} + +void PMainWindow::slotDisplay( const QString& inf ) { + if ( !m_disp ) + initDisp(); + m_disp->setImage( inf ); + m_stack->raiseWidget( ImageDisplay ); +} + +void PMainWindow::slotReturn() { + raiseIconView(); +} + + +void PMainWindow::closeEvent( QCloseEvent* ev ) { + /* + * return from view + * or properly quit + */ + if ( m_stack->visibleWidget() == m_info || + m_stack->visibleWidget() == m_disp ) { + raiseIconView(); + ev->ignore(); + return; + } + ev->accept(); + QTimer::singleShot(0, qApp, SLOT(closeAllWindows())); +} + +void PMainWindow::raiseIconView() { + m_stack->raiseWidget( IconView ); +} diff --git a/noncore/graphics/opie-eye/gui/mainwindow.h b/noncore/graphics/opie-eye/gui/mainwindow.h index 317a51e..35116ae 100644 --- a/noncore/graphics/opie-eye/gui/mainwindow.h +++ b/noncore/graphics/opie-eye/gui/mainwindow.h @@ -14,22 +14,46 @@ namespace Opie { namespace Ui{ class OKeyConfigManager; + class OWidgetStack; } } class PIconView; +class imageinfo; +class ImageScrollView; class PMainWindow : public QMainWindow { Q_OBJECT + enum Views { IconView, ImageInfo, ImageDisplay }; public: static QString appName() { return QString::fromLatin1("opie-eye" ); } PMainWindow(QWidget*, const char*, WFlags ); ~PMainWindow(); +signals: + void configChanged(); + +public slots: + void slotShowInfo( const QString& inf ); + void slotDisplay( const QString& inf ); + void slotReturn(); + +protected: + void raiseIconView(); + void closeEvent( QCloseEvent* ); + +private: + template<class T> void initT( const char* name, T**, int ); + void initInfo(); + void initDisp(); + private: Opie::Core::OConfig *m_cfg; + Opie::Ui::OWidgetStack *m_stack; PIconView* m_view; + imageinfo *m_info; + ImageScrollView *m_disp; private slots: void slotConfig(); |