summaryrefslogtreecommitdiff
authorzecke <zecke>2004-04-05 20:01:22 (UTC)
committer zecke <zecke>2004-04-05 20:01:22 (UTC)
commitecdd2845abeb5f3d00f58540e9b222799d6610e8 (patch) (side-by-side diff)
tree7199007b1dc296bb4572f2c96178d47d2f36bc02
parentcb3097d5249b6bd576d0212394ab57e885f9e9da (diff)
downloadopie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.zip
opie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.tar.gz
opie-ecdd2845abeb5f3d00f58540e9b222799d6610e8.tar.bz2
Make use of OWidgetStack
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp61
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.h4
-rw-r--r--noncore/graphics/opie-eye/gui/imageinfoui.cpp29
-rw-r--r--noncore/graphics/opie-eye/gui/imageinfoui.h20
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.cpp20
-rw-r--r--noncore/graphics/opie-eye/gui/imagescrollview.h6
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.cpp109
-rw-r--r--noncore/graphics/opie-eye/gui/mainwindow.h24
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
@@ -1,235 +1,257 @@
/*
* 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::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;
QString path()const { return m_path; }
bool isDir()const { return m_isDir; }
void setText( const QString& );
private:
mutable QPixmap* m_pix;
QString m_path;
bool m_isDir : 1;
bool m_noInfo :1;
};
/*
* 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 ),
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();
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*)) );
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::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() );
lst.append( Opie::Ui::OKeyPair::leftArrowKey() );
lst.append( Opie::Ui::OKeyPair::rightArrowKey() );
lst.append( Opie::Ui::OKeyPair::returnKey() );
m_viewManager = new Opie::Ui::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::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton),
this, SLOT(slotBeam())) );
m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete",
Resource::loadPixmap("trash"), DeleteItem,
Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton),
this, SLOT(slotTrash())) );
m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view",
Resource::loadPixmap("1to1"), ViewItem,
Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton),
this, SLOT(slotShowImage())));
m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info",
Resource::loadPixmap("DocumentTypeWord"), InfoItem,
Opie::Ui::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;
lister->setStartPath( path );
m_path = lister->currentPath();
m_view->viewport()->setUpdatesEnabled( false );
m_view->clear();
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 ) );
}
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
@@ -239,158 +261,157 @@ void PIconView::slotTrash() {
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());
}
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 );
}
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) {
QStringList::ConstIterator it;
for (it=lst.begin(); it!= lst.end(); ++it )
(void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) );
}
void PIconView::slotClicked(QIconViewItem* _it) {
if(!_it )
return;
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];
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 );
}
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 );
}
void PIconView::slotRename() {
}
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" ) );
}
void PIconView::slotBeamDone( Ir* ir) {
delete 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
@@ -1,80 +1,84 @@
/*
* 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;
}
namespace Ui {
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::Ui::OKeyConfigManager* manager();
+signals:
+ void sig_showInfo( const QString& );
+ void sig_display( const QString& );
+
private:
void initKeys();
QString currentFileName(bool &isDir)const;
void loadViews();
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&);
private:
Opie::Ui::OKeyConfigManager *m_viewManager;
Opie::Core::OConfig *m_cfg;
QComboBox* m_views;
QIconView* m_view;
QString m_path;
bool m_updatet : 1;
};
#endif
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
@@ -1,127 +1,152 @@
#include "imageinfoui.h"
#include <qframe.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtextview.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include <qstring.h>
#include <qfileinfo.h>
#include <lib/slavemaster.h>
#include <lib/imagecache.h>
#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 )
setName( "imageinfo" );
resize( 289, 335 );
setCaption( tr( "Image info" ) );
imageinfoLayout = new QVBoxLayout( this );
imageinfoLayout->setSpacing(2);
imageinfoLayout->setMargin(4);
PixmapLabel1 = new QLabel( this, "PixmapLabel1" );
PixmapLabel1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)5, PixmapLabel1->sizePolicy().hasHeightForWidth() ) );
QWhatsThis::add( PixmapLabel1, tr("Displays an thumbnail of the image") );
imageinfoLayout->addWidget( PixmapLabel1 );
Line1 = new QFrame( this, "Line1" );
Line1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
imageinfoLayout->addWidget( Line1 );
fnameLabel = new QLabel( this, "FnameLabel" );
imageinfoLayout->addWidget( fnameLabel);
TextView1 = new QTextView( this, "TextView1" );
TextView1->setFrameShadow( QTextView::Sunken );
TextView1->setResizePolicy( QTextView::AutoOneFit );
TextView1->setBackgroundOrigin( QTextView::ParentOrigin );
TextView1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)3, TextView1->sizePolicy().hasHeightForWidth() ) );
// TextView1->setVScrollBarMode(QScrollView::AlwaysOn);
QWhatsThis::add( TextView1, tr("Displays info of selected image") );
imageinfoLayout->addWidget( TextView1 );
SlaveMaster* master = SlaveMaster::self();
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)
{
currentFile=_path;
QFileInfo fi(_path);
fnameLabel->setText("<qt><center><b>"+fi.fileName()+"</b></center></qt>");
SlaveMaster::self()->imageInfo( currentFile );
QPixmap*m_pix = PPixmapCache::self()->cachedImage( _path, THUMBSIZE,THUMBSIZE );
if (!m_pix) {
PixmapLabel1->setPixmap(QPixmap( Resource::loadPixmap( "UnknownDocument" )));
SlaveMaster::self()->thumbNail(currentFile,THUMBSIZE,THUMBSIZE);
} else {
PixmapLabel1->setPixmap(*m_pix);
}
}
imageinfo::~imageinfo()
{
{
QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" );
}
}
void imageinfo::slot_fullInfo(const QString&_path, const QString&_t)
{
if (_path == currentFile) {
qDebug(_t);
QString t = _t;
t.replace(QRegExp("\n"),"<br>");
/* t.replace(QRegeExp("<qt>","");
t.replace(QRegeExp("</qt>","");*/
TextView1->setText(t);
}
}
void imageinfo::slotThumbNail(const QString&_path, const QPixmap&_pix)
{
if (_path == currentFile) {
if (_pix.width()>0) {
PPixmapCache::self()->insertImage( _path, _pix, THUMBSIZE, THUMBSIZE );
PixmapLabel1->setPixmap( _pix );
PixmapLabel1->resize(QSize(_pix.width(),_pix.height()));
}
}
}
+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)
{
QVBoxLayout*dlglayout = new QVBoxLayout(this);
dlglayout->setSpacing(2);
dlglayout->setMargin(1);
imageinfo*inf = new imageinfo(fname,this);
dlglayout->addWidget(inf);
}
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
@@ -1,48 +1,58 @@
#ifndef IMAGEINFO_H
#define IMAGEINFO_H
#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;
protected:
QVBoxLayout* imageinfoLayout;
QString currentFile;
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 */
class infoDlg:public QDialog
{
Q_OBJECT
public:
infoDlg(const QString&,QWidget * parent=0, const char * name=0);
virtual ~infoDlg();
};
#endif // IMAGEINFO_H
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
@@ -1,79 +1,90 @@
#include "imagescrollview.h"
#include <opie2/odebug.h>
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)
{
init();
}
ImageScrollView::ImageScrollView (const QString&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)
{
init();
}
void ImageScrollView::setImage(const QImage&img)
{
_image_data = QImage();
_original_data=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);
if (_original_data.size().isValid()) {
resizeContents(_original_data.width(),_original_data.height());
}
last_rot = Rotate0;
}
ImageScrollView::~ImageScrollView()
{
}
void ImageScrollView::rescaleImage(int w, int h)
{
if (_image_data.width()==w && _image_data.height()==h) {
return;
}
double hs = (double)h / (double)_image_data.height() ;
double ws = (double)w / (double)_image_data.width() ;
double scaleFactor = (hs > ws) ? ws : hs;
int smoothW = (int)(scaleFactor * _image_data.width());
int smoothH = (int)(scaleFactor * _image_data.height());
_image_data = _image_data.smoothScale(smoothW,smoothH);
}
void ImageScrollView::rotate_into_data(Rotation r)
{
/* realy - we must do this that way, 'cause when acting direct on _image_data the app will
segfault :( */
QImage dest;
int x, y;
if ( _original_data.depth() > 8 )
{
unsigned int *srcData, *destData;
switch ( r )
{
case Rotate90:
dest.create(_original_data.height(), _original_data.width(), _original_data.depth());
for ( y=0; y < _original_data.height(); ++y )
{
srcData = (unsigned int *)_original_data.scanLine(y);
for ( x=0; x < _original_data.width(); ++x )
{
destData = (unsigned int *)dest.scanLine(x);
destData[_original_data.height()-y-1] = srcData[x];
}
@@ -214,63 +225,72 @@ void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw
p->fillRect(clipx,clipy,clipw,cliph,white);
return;
}
if (w>_image_data.width()) {
w=_image_data.width();
x = 0;
erase = true;
} else if (x+w>_image_data.width()){
x = _image_data.width()-w;
}
if (h>_image_data.height()) {
h=_image_data.height();
y = 0;
erase = true;
} else if (y+h>_image_data.height()){
y = _image_data.height()-h;
}
if (erase||_image_data.hasAlphaBuffer()) {
p->fillRect(clipx,clipy,clipw,cliph,white);
}
p->drawImage(clipx,clipy,_image_data,x,y,w,h);
}
/* using the real geometry points and not the translated points is wanted! */
void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e)
{
int mx, my;
mx = e->x();
my = e->y();
int diffx = _mouseStartPosX-mx;
int diffy = _mouseStartPosY-my;
scrollBy(diffx,diffy);
_mouseStartPosX=mx;
_mouseStartPosY=my;
}
void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e)
{
_mouseStartPosX = e->x();
_mouseStartPosY = e->y();
}
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)
{
QVBoxLayout*dlglayout = new QVBoxLayout(this);
dlglayout->setSpacing(2);
dlglayout->setMargin(1);
ImageScrollView*inf = new ImageScrollView(fname,this);
dlglayout->addWidget(inf);
odebug << "Imagedlg constructor end" << oendl;
}
ImageDlg::~ImageDlg()
{
}
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
@@ -1,62 +1,68 @@
#ifndef _IMAGE_SCROLL_VIEW_H
#define _IMAGE_SCROLL_VIEW_H
#include <qscrollview.h>
#include <qimage.h>
#include <qstring.h>
#include <qdialog.h>
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();
QImage _image_data;
QImage _original_data;
int _mouseStartPosX,_mouseStartPosY;
bool scale_to_fit;
bool rotate_to_fit;
bool first_resize_done;
Rotation last_rot;
void rescaleImage(int w, int h);
void rotate_into_data(Rotation r);
protected slots:
virtual void viewportMouseMoveEvent(QMouseEvent* e);
virtual void contentsMousePressEvent ( QMouseEvent * e);
virtual void contentsMouseReleaseEvent ( QMouseEvent * e);
virtual void resizeEvent(QResizeEvent * e);
};
/* for testing */
class ImageDlg:public QDialog
{
Q_OBJECT
public:
ImageDlg(const QString&,QWidget * parent=0, const char * name=0);
virtual ~ImageDlg();
};
#endif
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
@@ -1,138 +1,229 @@
/*
* GPLv2 zecke@handhelds.org
* No WArranty...
*/
#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>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpe/ir.h>
#include <qtoolbar.h>
#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" );
/*
* Initialize ToolBar and IconView
* And Connect Them
*/
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()),
m_view, SLOT(slotDirUp()) );
btn = new PFileSystem( bar );
connect( btn, SIGNAL( changeDir( const QString& ) ),
m_view, SLOT(slotChangeDir( const QString& ) ) );
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "edit" ) );
connect( btn, SIGNAL(clicked()),
m_view, SLOT(slotRename()) );
if ( Ir::supported() ) {
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "beam" ) );
connect( btn, SIGNAL(clicked()),
m_view, SLOT(slotBeam()) );
}
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "trash" ) );
connect( btn, SIGNAL(clicked() ),
m_view, SLOT(slotTrash() ) );
btn = new QToolButton( bar );
btn->setIconSet( Resource::loadIconSet( "SettingsIcon" ) );
connect( btn, SIGNAL(clicked() ),
this, SLOT(slotConfig() ) );
}
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);
Opie::Ui::OTabWidget *wid = new Opie::Ui::OTabWidget(&dlg );
lay->addWidget( wid );
ViewMap *vM = viewMap();
ViewMap::Iterator _it = vM->begin();
QMap<PDirView*, QWidget*> lst;
for( ; _it != vM->end(); ++_it ) {
PDirView *view = (_it.data())(*m_cfg);
PInterfaceInfo *inf = view->interfaceInfo();
QWidget *_wid = inf->configWidget( *m_cfg );
_wid->reparent(wid, QPoint() );
lst.insert( view, _wid );
wid->addTab( _wid, "fileopen", inf->name() );
}
/*
* Add the KeyConfigWidget
*/
Opie::Ui::OKeyConfigWidget* keyWid = new Opie::Ui::OKeyConfigWidget( wid, "key config" );
keyWid->setChangeMode( Opie::Ui::OKeyConfigWidget::Queue );
keyWid->insert( tr("Browser Keyboard Actions"), m_view->manager() );
keyWid->load();
wid->addTab( keyWid, QString::fromLatin1("AppsIcon" ), tr("Keyboard Configuration") );
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
@@ -1,38 +1,62 @@
/*
* GPLv2 zecke@handhelds.org
* No WArranty...
*/
#ifndef PHUNK_MAIN_WINDOW_H
#define PHUNK_MAIN_WINDOW_H
#include <opie2/oconfig.h>
#include <qmainwindow.h>
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();
};
#endif