-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 8 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.cpp | 97 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/imagescrollview.h | 43 |
3 files changed, 147 insertions, 1 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index ac4b899..de2cdf0 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp | |||
@@ -1,390 +1,396 @@ | |||
1 | /* | 1 | /* |
2 | * GPLv2 zecke@handhelds.org | 2 | * GPLv2 zecke@handhelds.org |
3 | * No WArranty... | 3 | * No WArranty... |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include "iconview.h" | 6 | #include "iconview.h" |
7 | 7 | ||
8 | #include <lib/imagecache.h> | 8 | #include <lib/imagecache.h> |
9 | #include <gui/imageinfoui.h> | 9 | #include <gui/imageinfoui.h> |
10 | #include <gui/imagescrollview.h> | ||
10 | 11 | ||
11 | #include <iface/dirview.h> | 12 | #include <iface/dirview.h> |
12 | #include <iface/dirlister.h> | 13 | #include <iface/dirlister.h> |
13 | 14 | ||
14 | #include <opie2/oconfig.h> | 15 | #include <opie2/oconfig.h> |
15 | #include <opie2/okeyconfigwidget.h> | 16 | #include <opie2/okeyconfigwidget.h> |
16 | #include <opie2/odebug.h> | 17 | #include <opie2/odebug.h> |
17 | 18 | ||
18 | #include <qpe/resource.h> | 19 | #include <qpe/resource.h> |
19 | #include <qpe/qpemessagebox.h> | 20 | #include <qpe/qpemessagebox.h> |
20 | #include <qpe/ir.h> | 21 | #include <qpe/ir.h> |
21 | #include <qpe/qcopenvelope_qws.h> | 22 | #include <qpe/qcopenvelope_qws.h> |
22 | #include <qpe/qpeapplication.h> | 23 | #include <qpe/qpeapplication.h> |
23 | 24 | ||
24 | #include <qiconview.h> | 25 | #include <qiconview.h> |
25 | #include <qlabel.h> | 26 | #include <qlabel.h> |
26 | #include <qhbox.h> | 27 | #include <qhbox.h> |
27 | #include <qcombobox.h> | 28 | #include <qcombobox.h> |
28 | #include <qdir.h> | 29 | #include <qdir.h> |
29 | #include <qapplication.h> | 30 | #include <qapplication.h> |
30 | #include <qmainwindow.h> | 31 | #include <qmainwindow.h> |
31 | #include <qtimer.h> | 32 | #include <qtimer.h> |
32 | #include <qstyle.h> | 33 | #include <qstyle.h> |
33 | 34 | ||
34 | 35 | ||
35 | using Opie::Ui::OKeyConfigItem; | 36 | using Opie::Ui::OKeyConfigItem; |
36 | 37 | ||
37 | namespace { | 38 | namespace { |
38 | QPixmap* _dirPix = 0; | 39 | QPixmap* _dirPix = 0; |
39 | QPixmap* _unkPix = 0; | 40 | QPixmap* _unkPix = 0; |
40 | class IconViewItem : public QIconViewItem { | 41 | class IconViewItem : public QIconViewItem { |
41 | public: | 42 | public: |
42 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); | 43 | IconViewItem( QIconView*, const QString& path, const QString& name, bool isDir = false); |
43 | QPixmap* pixmap()const; | 44 | QPixmap* pixmap()const; |
44 | QString path()const { return m_path; } | 45 | QString path()const { return m_path; } |
45 | bool isDir()const { return m_isDir; } | 46 | bool isDir()const { return m_isDir; } |
46 | void setText( const QString& ); | 47 | void setText( const QString& ); |
47 | 48 | ||
48 | 49 | ||
49 | private: | 50 | private: |
50 | mutable QPixmap* m_pix; | 51 | mutable QPixmap* m_pix; |
51 | QString m_path; | 52 | QString m_path; |
52 | bool m_isDir : 1; | 53 | bool m_isDir : 1; |
53 | bool m_noInfo :1; | 54 | bool m_noInfo :1; |
54 | }; | 55 | }; |
55 | 56 | ||
56 | 57 | ||
57 | /* | 58 | /* |
58 | * If we request an Image or String | 59 | * If we request an Image or String |
59 | * we add it to the map | 60 | * we add it to the map |
60 | */ | 61 | */ |
61 | QMap<QString, IconViewItem*> g_stringInf; | 62 | QMap<QString, IconViewItem*> g_stringInf; |
62 | QMap<QString, IconViewItem*> g_stringPix; | 63 | QMap<QString, IconViewItem*> g_stringPix; |
63 | 64 | ||
64 | IconViewItem::IconViewItem( QIconView* view,const QString& path, | 65 | IconViewItem::IconViewItem( QIconView* view,const QString& path, |
65 | const QString& name, bool isDir ) | 66 | const QString& name, bool isDir ) |
66 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), | 67 | : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), |
67 | m_noInfo( false ) | 68 | m_noInfo( false ) |
68 | { | 69 | { |
69 | if ( isDir && !_dirPix ) | 70 | if ( isDir && !_dirPix ) |
70 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); | 71 | _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); |
71 | else if ( !isDir && !_unkPix ) | 72 | else if ( !isDir && !_unkPix ) |
72 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); | 73 | _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); |
73 | } | 74 | } |
74 | inline QPixmap* IconViewItem::pixmap()const { | 75 | inline QPixmap* IconViewItem::pixmap()const { |
75 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", | 76 | // qWarning( "Name is " + m_path.right( 15 ) + " rect is %d %d %d %d | %d %d", |
76 | // rect().x(),rect().y(),rect().width(),rect().height(), | 77 | // rect().x(),rect().y(),rect().width(),rect().height(), |
77 | // iconView()->contentsX(), iconView()->contentsY()); | 78 | // iconView()->contentsX(), iconView()->contentsY()); |
78 | 79 | ||
79 | if ( m_isDir ) | 80 | if ( m_isDir ) |
80 | return _dirPix; | 81 | return _dirPix; |
81 | else{ | 82 | else{ |
82 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { | 83 | if (!m_noInfo && !g_stringInf.contains( m_path ) ) { |
83 | currentView()->dirLister()->imageInfo( m_path ); | 84 | currentView()->dirLister()->imageInfo( m_path ); |
84 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); | 85 | g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); |
85 | } | 86 | } |
86 | 87 | ||
87 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); | 88 | m_pix = PPixmapCache::self()->cachedImage( m_path, 64, 64 ); |
88 | if ( !m_pix && !g_stringPix.contains( m_path )) { | 89 | if ( !m_pix && !g_stringPix.contains( m_path )) { |
89 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); | 90 | currentView()->dirLister()->thumbNail( m_path, 64, 64 ); |
90 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); | 91 | g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); |
91 | } | 92 | } |
92 | return m_pix ? m_pix : _unkPix; | 93 | return m_pix ? m_pix : _unkPix; |
93 | } | 94 | } |
94 | } | 95 | } |
95 | inline void IconViewItem::setText( const QString& str ) { | 96 | inline void IconViewItem::setText( const QString& str ) { |
96 | QString text = QIconViewItem::text()+"\n"+str; | 97 | QString text = QIconViewItem::text()+"\n"+str; |
97 | m_noInfo = true; | 98 | m_noInfo = true; |
98 | QIconViewItem::setText( text ); | 99 | QIconViewItem::setText( text ); |
99 | } | 100 | } |
100 | } | 101 | } |
101 | 102 | ||
102 | 103 | ||
103 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) | 104 | PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) |
104 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) | 105 | : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) |
105 | { | 106 | { |
106 | { | 107 | { |
107 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); | 108 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); |
108 | } | 109 | } |
109 | m_path = QDir::homeDirPath(); | 110 | m_path = QDir::homeDirPath(); |
110 | 111 | ||
111 | QHBox *hbox = new QHBox( this ); | 112 | QHBox *hbox = new QHBox( this ); |
112 | QLabel* lbl = new QLabel( hbox ); | 113 | QLabel* lbl = new QLabel( hbox ); |
113 | lbl->setText( tr("View as" ) ); | 114 | lbl->setText( tr("View as" ) ); |
114 | 115 | ||
115 | m_views = new QComboBox( hbox, "View As" ); | 116 | m_views = new QComboBox( hbox, "View As" ); |
116 | connect( m_views, SIGNAL(activated(int)), | 117 | connect( m_views, SIGNAL(activated(int)), |
117 | this, SLOT(slotViewChanged(int)) ); | 118 | this, SLOT(slotViewChanged(int)) ); |
118 | 119 | ||
119 | m_view= new QIconView( this ); | 120 | m_view= new QIconView( this ); |
120 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), | 121 | connect(m_view, SIGNAL(clicked(QIconViewItem*) ), |
121 | this, SLOT(slotClicked(QIconViewItem*)) ); | 122 | this, SLOT(slotClicked(QIconViewItem*)) ); |
122 | 123 | ||
123 | m_view->setArrangement( QIconView::LeftToRight ); | 124 | m_view->setArrangement( QIconView::LeftToRight ); |
124 | m_view->setItemTextPos( QIconView::Right ); | 125 | m_view->setItemTextPos( QIconView::Right ); |
125 | 126 | ||
126 | int dw = QApplication::desktop()->width(); | 127 | int dw = QApplication::desktop()->width(); |
127 | int viewerWidth = dw-style().scrollBarExtent().width(); | 128 | int viewerWidth = dw-style().scrollBarExtent().width(); |
128 | m_view->setGridX( viewerWidth-3*m_view->spacing()); | 129 | m_view->setGridX( viewerWidth-3*m_view->spacing()); |
129 | m_view->setGridY( fontMetrics().height()*2+40 ); | 130 | m_view->setGridY( fontMetrics().height()*2+40 ); |
130 | 131 | ||
131 | 132 | ||
132 | initKeys(); | 133 | initKeys(); |
133 | 134 | ||
134 | loadViews(); | 135 | loadViews(); |
135 | slotViewChanged( m_views->currentItem() ); | 136 | slotViewChanged( m_views->currentItem() ); |
136 | } | 137 | } |
137 | 138 | ||
138 | PIconView::~PIconView() { | 139 | PIconView::~PIconView() { |
139 | { | 140 | { |
140 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); | 141 | QCopEnvelope( "QPE/Application/opie-eye_slave", "refDown()" ); |
141 | } | 142 | } |
142 | m_viewManager->save(); | 143 | m_viewManager->save(); |
143 | delete m_viewManager; | 144 | delete m_viewManager; |
144 | } | 145 | } |
145 | 146 | ||
146 | Opie::Ui::OKeyConfigManager* PIconView::manager() { | 147 | Opie::Ui::OKeyConfigManager* PIconView::manager() { |
147 | return m_viewManager; | 148 | return m_viewManager; |
148 | } | 149 | } |
149 | 150 | ||
150 | void PIconView::initKeys() { | 151 | void PIconView::initKeys() { |
151 | Opie::Ui::OKeyPair::List lst; | 152 | Opie::Ui::OKeyPair::List lst; |
152 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); | 153 | lst.append( Opie::Ui::OKeyPair::upArrowKey() ); |
153 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); | 154 | lst.append( Opie::Ui::OKeyPair::downArrowKey() ); |
154 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); | 155 | lst.append( Opie::Ui::OKeyPair::leftArrowKey() ); |
155 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); | 156 | lst.append( Opie::Ui::OKeyPair::rightArrowKey() ); |
156 | lst.append( Opie::Ui::OKeyPair::returnKey() ); | 157 | lst.append( Opie::Ui::OKeyPair::returnKey() ); |
157 | 158 | ||
158 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", | 159 | m_viewManager = new Opie::Ui::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", |
159 | lst, false,this, "keyconfig name" ); | 160 | lst, false,this, "keyconfig name" ); |
160 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", | 161 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", |
161 | Resource::loadPixmap("beam"), BeamItem, | 162 | Resource::loadPixmap("beam"), BeamItem, |
162 | Opie::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton), | 163 | Opie::Ui::OKeyPair(Qt::Key_B, Qt::ShiftButton), |
163 | this, SLOT(slotBeam())) ); | 164 | this, SLOT(slotBeam())) ); |
164 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", | 165 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", |
165 | Resource::loadPixmap("trash"), DeleteItem, | 166 | Resource::loadPixmap("trash"), DeleteItem, |
166 | Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton), | 167 | Opie::Ui::OKeyPair(Qt::Key_D, Qt::ShiftButton), |
167 | this, SLOT(slotTrash())) ); | 168 | this, SLOT(slotTrash())) ); |
168 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", | 169 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", |
169 | Resource::loadPixmap("1to1"), ViewItem, | 170 | Resource::loadPixmap("1to1"), ViewItem, |
170 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), | 171 | Opie::Ui::OKeyPair(Qt::Key_V, Qt::ShiftButton), |
171 | this, SLOT(slotShowImage()))); | 172 | this, SLOT(slotShowImage()))); |
172 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", | 173 | m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", |
173 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, | 174 | Resource::loadPixmap("DocumentTypeWord"), InfoItem, |
174 | Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ), | 175 | Opie::Ui::OKeyPair(Qt::Key_I, Qt::ShiftButton ), |
175 | this, SLOT(slotImageInfo()) ) ); | 176 | this, SLOT(slotImageInfo()) ) ); |
176 | m_viewManager->load(); | 177 | m_viewManager->load(); |
177 | m_viewManager->handleWidget( m_view ); | 178 | m_viewManager->handleWidget( m_view ); |
178 | } | 179 | } |
179 | 180 | ||
180 | void PIconView::slotDirUp() { | 181 | void PIconView::slotDirUp() { |
181 | QDir dir( m_path ); | 182 | QDir dir( m_path ); |
182 | dir.cdUp(); | 183 | dir.cdUp(); |
183 | slotChangeDir( dir.absPath() ); | 184 | slotChangeDir( dir.absPath() ); |
184 | 185 | ||
185 | } | 186 | } |
186 | 187 | ||
187 | void PIconView::slotChangeDir(const QString& path) { | 188 | void PIconView::slotChangeDir(const QString& path) { |
188 | if ( !currentView() ) | 189 | if ( !currentView() ) |
189 | return; | 190 | return; |
190 | 191 | ||
191 | PDirLister *lister = currentView()->dirLister(); | 192 | PDirLister *lister = currentView()->dirLister(); |
192 | if (!lister ) | 193 | if (!lister ) |
193 | return; | 194 | return; |
194 | 195 | ||
195 | lister->setStartPath( path ); | 196 | lister->setStartPath( path ); |
196 | m_path = lister->currentPath(); | 197 | m_path = lister->currentPath(); |
197 | 198 | ||
198 | m_view->viewport()->setUpdatesEnabled( false ); | 199 | m_view->viewport()->setUpdatesEnabled( false ); |
199 | m_view->clear(); | 200 | m_view->clear(); |
200 | addFolders( lister->folders() ); | 201 | addFolders( lister->folders() ); |
201 | addFiles( lister->files() ); | 202 | addFiles( lister->files() ); |
202 | m_view->viewport()->setUpdatesEnabled( true ); | 203 | m_view->viewport()->setUpdatesEnabled( true ); |
203 | 204 | ||
204 | // Also invalidate the cache. We can't cancel the operations anyway | 205 | // Also invalidate the cache. We can't cancel the operations anyway |
205 | g_stringPix.clear(); | 206 | g_stringPix.clear(); |
206 | g_stringInf.clear(); | 207 | g_stringInf.clear(); |
207 | 208 | ||
208 | // looks ugly | 209 | // looks ugly |
209 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); | 210 | static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); |
210 | } | 211 | } |
211 | 212 | ||
212 | QString PIconView::currentFileName(bool &isDir)const { | 213 | QString PIconView::currentFileName(bool &isDir)const { |
213 | isDir = false; | 214 | isDir = false; |
214 | QIconViewItem* _it = m_view->currentItem(); | 215 | QIconViewItem* _it = m_view->currentItem(); |
215 | if ( !_it ) | 216 | if ( !_it ) |
216 | return QString::null; | 217 | return QString::null; |
217 | 218 | ||
218 | IconViewItem* it = static_cast<IconViewItem*>( _it ); | 219 | IconViewItem* it = static_cast<IconViewItem*>( _it ); |
219 | isDir = it->isDir(); | 220 | isDir = it->isDir(); |
220 | return it->path(); | 221 | return it->path(); |
221 | } | 222 | } |
222 | 223 | ||
223 | void PIconView::slotTrash() { | 224 | void PIconView::slotTrash() { |
224 | bool isDir; | 225 | bool isDir; |
225 | QString pa = currentFileName( isDir ); | 226 | QString pa = currentFileName( isDir ); |
226 | if ( isDir && pa.isEmpty() ) | 227 | if ( isDir && pa.isEmpty() ) |
227 | return; | 228 | return; |
228 | 229 | ||
229 | if (!QPEMessageBox::confirmDelete( this, | 230 | if (!QPEMessageBox::confirmDelete( this, |
230 | tr("Delete Image" ), | 231 | tr("Delete Image" ), |
231 | tr("the Image %1" ).arg(pa))) | 232 | tr("the Image %1" ).arg(pa))) |
232 | return | 233 | return |
233 | 234 | ||
234 | 235 | ||
235 | currentView()->dirLister()->deleteImage( pa ); | 236 | currentView()->dirLister()->deleteImage( pa ); |
236 | delete m_view->currentItem(); | 237 | delete m_view->currentItem(); |
237 | } | 238 | } |
238 | void PIconView::loadViews() { | 239 | void PIconView::loadViews() { |
239 | ViewMap::Iterator it; | 240 | ViewMap::Iterator it; |
240 | ViewMap* map = viewMap(); | 241 | ViewMap* map = viewMap(); |
241 | for ( it = map->begin(); it != map->end(); ++it ) | 242 | for ( it = map->begin(); it != map->end(); ++it ) |
242 | m_views->insertItem( QObject::tr(it.key() ) ); | 243 | m_views->insertItem( QObject::tr(it.key() ) ); |
243 | } | 244 | } |
244 | 245 | ||
245 | void PIconView::resetView() { | 246 | void PIconView::resetView() { |
246 | slotViewChanged(m_views->currentItem()); | 247 | slotViewChanged(m_views->currentItem()); |
247 | } | 248 | } |
248 | 249 | ||
249 | void PIconView::slotViewChanged( int i) { | 250 | void PIconView::slotViewChanged( int i) { |
250 | if (!m_views->count() ) { | 251 | if (!m_views->count() ) { |
251 | setCurrentView( 0l); | 252 | setCurrentView( 0l); |
252 | return; | 253 | return; |
253 | } | 254 | } |
254 | 255 | ||
255 | PDirView* cur = currentView(); | 256 | PDirView* cur = currentView(); |
256 | delete cur; | 257 | delete cur; |
257 | QString str = m_views->text(i); | 258 | QString str = m_views->text(i); |
258 | cur = (*(*viewMap())[str])(*m_cfg); | 259 | cur = (*(*viewMap())[str])(*m_cfg); |
259 | setCurrentView( cur ); | 260 | setCurrentView( cur ); |
260 | 261 | ||
261 | /* connect to the signals of the lister */ | 262 | /* connect to the signals of the lister */ |
262 | PDirLister* lis = cur->dirLister(); | 263 | PDirLister* lis = cur->dirLister(); |
263 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), | 264 | connect(lis, SIGNAL(sig_thumbInfo(const QString&, const QString& )), |
264 | this, SLOT( slotThumbInfo(const QString&, const QString&))); | 265 | this, SLOT( slotThumbInfo(const QString&, const QString&))); |
265 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), | 266 | connect(lis, SIGNAL( sig_thumbNail(const QString&, const QPixmap&)), |
266 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); | 267 | this, SLOT(slotThumbNail(const QString&, const QPixmap&))); |
267 | connect(lis, SIGNAL(sig_start()), | 268 | connect(lis, SIGNAL(sig_start()), |
268 | this, SLOT(slotStart())); | 269 | this, SLOT(slotStart())); |
269 | connect(lis, SIGNAL(sig_end()) , | 270 | connect(lis, SIGNAL(sig_end()) , |
270 | this, SLOT(slotEnd()) ); | 271 | this, SLOT(slotEnd()) ); |
271 | 272 | ||
272 | 273 | ||
273 | /* reload now */ | 274 | /* reload now */ |
274 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); | 275 | QTimer::singleShot( 0, this, SLOT(slotReloadDir())); |
275 | } | 276 | } |
276 | 277 | ||
277 | 278 | ||
278 | void PIconView::slotReloadDir() { | 279 | void PIconView::slotReloadDir() { |
279 | slotChangeDir( m_path ); | 280 | slotChangeDir( m_path ); |
280 | } | 281 | } |
281 | 282 | ||
282 | 283 | ||
283 | void PIconView::addFolders( const QStringList& lst) { | 284 | void PIconView::addFolders( const QStringList& lst) { |
284 | QStringList::ConstIterator it; | 285 | QStringList::ConstIterator it; |
285 | 286 | ||
286 | for(it=lst.begin(); it != lst.end(); ++it ) { | 287 | for(it=lst.begin(); it != lst.end(); ++it ) { |
287 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); | 288 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it), true ); |
288 | } | 289 | } |
289 | 290 | ||
290 | } | 291 | } |
291 | 292 | ||
292 | void PIconView::addFiles( const QStringList& lst) { | 293 | void PIconView::addFiles( const QStringList& lst) { |
293 | QStringList::ConstIterator it; | 294 | QStringList::ConstIterator it; |
294 | for (it=lst.begin(); it!= lst.end(); ++it ) | 295 | for (it=lst.begin(); it!= lst.end(); ++it ) |
295 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); | 296 | (void)new IconViewItem( m_view, m_path+"/"+(*it), (*it) ); |
296 | 297 | ||
297 | } | 298 | } |
298 | 299 | ||
299 | void PIconView::slotClicked(QIconViewItem* _it) { | 300 | void PIconView::slotClicked(QIconViewItem* _it) { |
300 | if(!_it ) | 301 | if(!_it ) |
301 | return; | 302 | return; |
302 | 303 | ||
303 | IconViewItem* it = static_cast<IconViewItem*>(_it); | 304 | IconViewItem* it = static_cast<IconViewItem*>(_it); |
304 | if( it->isDir() ) | 305 | if( it->isDir() ) |
305 | slotChangeDir( it->path() ); | 306 | slotChangeDir( it->path() ); |
306 | else // view image | 307 | else // view image |
307 | ; | 308 | ; |
308 | } | 309 | } |
309 | 310 | ||
310 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { | 311 | void PIconView::slotThumbInfo( const QString& _path, const QString& str ) { |
311 | IconViewItem* item = g_stringInf[_path]; | 312 | IconViewItem* item = g_stringInf[_path]; |
312 | if (!item ) | 313 | if (!item ) |
313 | return; | 314 | return; |
314 | 315 | ||
315 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 316 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
316 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 317 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
317 | m_updatet = true; | 318 | m_updatet = true; |
318 | 319 | ||
319 | item->setText( str ); | 320 | item->setText( str ); |
320 | g_stringInf.remove( _path ); | 321 | g_stringInf.remove( _path ); |
321 | } | 322 | } |
322 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { | 323 | void PIconView::slotThumbNail(const QString& _path, const QPixmap &pix) { |
323 | IconViewItem* item = g_stringPix[_path]; | 324 | IconViewItem* item = g_stringPix[_path]; |
324 | if (!item ) | 325 | if (!item ) |
325 | return; | 326 | return; |
326 | 327 | ||
327 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), | 328 | if ( item->intersects(QRect( m_view->contentsX(),m_view->contentsY(), |
328 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) | 329 | m_view->contentsWidth(), m_view->contentsHeight() ) ) ) |
329 | m_updatet = true; | 330 | m_updatet = true; |
330 | 331 | ||
331 | if (pix.width()>0) | 332 | if (pix.width()>0) |
332 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); | 333 | PPixmapCache::self()->insertImage( _path, pix, 64, 64 ); |
333 | 334 | ||
334 | 335 | ||
335 | g_stringPix.remove( _path ); | 336 | g_stringPix.remove( _path ); |
336 | } | 337 | } |
337 | 338 | ||
338 | 339 | ||
339 | void PIconView::slotRename() { | 340 | void PIconView::slotRename() { |
340 | 341 | ||
341 | } | 342 | } |
342 | 343 | ||
343 | void PIconView::slotBeam() { | 344 | void PIconView::slotBeam() { |
344 | bool isDir; | 345 | bool isDir; |
345 | QString pa = currentFileName( isDir ); | 346 | QString pa = currentFileName( isDir ); |
346 | if ( isDir && pa.isEmpty() ) | 347 | if ( isDir && pa.isEmpty() ) |
347 | return; | 348 | return; |
348 | 349 | ||
349 | Ir* ir = new Ir( this ); | 350 | Ir* ir = new Ir( this ); |
350 | connect( ir, SIGNAL(done(Ir*)), | 351 | connect( ir, SIGNAL(done(Ir*)), |
351 | this, SLOT(slotBeamDone(Ir*))); | 352 | this, SLOT(slotBeamDone(Ir*))); |
352 | ir->send(pa, tr( "Image" ) ); | 353 | ir->send(pa, tr( "Image" ) ); |
353 | 354 | ||
354 | } | 355 | } |
355 | 356 | ||
356 | void PIconView::slotBeamDone( Ir* ir) { | 357 | void PIconView::slotBeamDone( Ir* ir) { |
357 | delete ir; | 358 | delete ir; |
358 | } | 359 | } |
359 | 360 | ||
360 | void PIconView::slotStart() { | 361 | void PIconView::slotStart() { |
361 | m_view->viewport()->setUpdatesEnabled( false ); | 362 | m_view->viewport()->setUpdatesEnabled( false ); |
362 | qWarning( "Sig Start" ); | 363 | qWarning( "Sig Start" ); |
363 | } | 364 | } |
364 | 365 | ||
365 | void PIconView::slotEnd() { | 366 | void PIconView::slotEnd() { |
366 | qWarning( "SLot End" ); | 367 | qWarning( "SLot End" ); |
367 | if ( m_updatet ) | 368 | if ( m_updatet ) |
368 | m_view->arrangeItemsInGrid( ); | 369 | m_view->arrangeItemsInGrid( ); |
369 | m_view->viewport()->setUpdatesEnabled( true ); | 370 | m_view->viewport()->setUpdatesEnabled( true ); |
370 | m_updatet = false; | 371 | m_updatet = false; |
371 | } | 372 | } |
372 | 373 | ||
373 | void PIconView::slotShowImage() { | 374 | void PIconView::slotShowImage() { |
374 | 375 | qDebug("image show"); | |
376 | bool isDir = false; | ||
377 | QString name = currentFileName(isDir); | ||
378 | if (isDir) return; | ||
379 | ImageDlg dlg(name); | ||
380 | QPEApplication::execDialog(&dlg); | ||
375 | } | 381 | } |
376 | void PIconView::slotShowImage( const QString& ) { | 382 | void PIconView::slotShowImage( const QString& ) { |
377 | 383 | ||
378 | } | 384 | } |
379 | void PIconView::slotImageInfo() { | 385 | void PIconView::slotImageInfo() { |
380 | qDebug("image info"); | 386 | qDebug("image info"); |
381 | bool isDir = false; | 387 | bool isDir = false; |
382 | QString name = currentFileName(isDir); | 388 | QString name = currentFileName(isDir); |
383 | if (isDir) return; | 389 | if (isDir) return; |
384 | infoDlg dlg(name); | 390 | infoDlg dlg(name); |
385 | QPEApplication::execDialog(&dlg); | 391 | QPEApplication::execDialog(&dlg); |
386 | } | 392 | } |
387 | 393 | ||
388 | void PIconView::slotImageInfo( const QString& ) { | 394 | void PIconView::slotImageInfo( const QString& ) { |
389 | 395 | ||
390 | } | 396 | } |
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.cpp b/noncore/graphics/opie-eye/gui/imagescrollview.cpp new file mode 100644 index 0000000..f36b717 --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/imagescrollview.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | #include "imagescrollview.h" | ||
2 | |||
3 | #include <qimage.h> | ||
4 | #include <qlayout.h> | ||
5 | |||
6 | ImageScrollView::ImageScrollView (const QImage&img, QWidget * parent, const char * name, WFlags f) | ||
7 | :QScrollView(parent,name,f|Qt::WRepaintNoErase),_image_data(img) | ||
8 | { | ||
9 | init(); | ||
10 | } | ||
11 | |||
12 | ImageScrollView::ImageScrollView (const QString&img, QWidget * parent, const char * name, WFlags f) | ||
13 | :QScrollView(parent,name,f/*|Qt::WRepaintNoErase*/),_image_data(img) | ||
14 | { | ||
15 | init(); | ||
16 | } | ||
17 | |||
18 | void ImageScrollView::setImage(const QImage&img) | ||
19 | { | ||
20 | _image_data = img; | ||
21 | init(); | ||
22 | } | ||
23 | |||
24 | /* should be called every time the QImage changed it content */ | ||
25 | void ImageScrollView::init() | ||
26 | { | ||
27 | viewport()->setBackgroundColor(white); | ||
28 | resizeContents(_image_data.width(),_image_data.height()); | ||
29 | } | ||
30 | |||
31 | ImageScrollView::~ImageScrollView() | ||
32 | { | ||
33 | } | ||
34 | |||
35 | void ImageScrollView::drawContents(QPainter * p, int clipx, int clipy, int clipw, int cliph) | ||
36 | { | ||
37 | int w = clipw; | ||
38 | int h = cliph; | ||
39 | int x = clipx; | ||
40 | int y = clipy; | ||
41 | bool erase = false; | ||
42 | |||
43 | if (w>_image_data.width()) { | ||
44 | w=_image_data.width(); | ||
45 | x = 0; | ||
46 | erase = true; | ||
47 | } else if (x+w>_image_data.width()){ | ||
48 | x = _image_data.width()-w; | ||
49 | } | ||
50 | if (h>_image_data.height()) { | ||
51 | h=_image_data.height(); | ||
52 | y = 0; | ||
53 | erase = true; | ||
54 | } else if (y+h>_image_data.height()){ | ||
55 | y = _image_data.height()-h; | ||
56 | } | ||
57 | if (erase) { | ||
58 | p->fillRect(clipx,clipy,clipw,cliph,white); | ||
59 | } | ||
60 | p->drawImage(clipx,clipy,_image_data,x,y,w,h); | ||
61 | } | ||
62 | |||
63 | void ImageScrollView::viewportMouseMoveEvent(QMouseEvent* e) | ||
64 | { | ||
65 | int mx, my; | ||
66 | viewportToContents( e->x(), e->y(), mx, my ); | ||
67 | |||
68 | scrollBy(_mouseStartPosX-mx,my-_mouseStartPosY); | ||
69 | |||
70 | _mouseStartPosX=mx; | ||
71 | _mouseStartPosY=my; | ||
72 | } | ||
73 | |||
74 | void ImageScrollView::contentsMouseReleaseEvent ( QMouseEvent * e) | ||
75 | { | ||
76 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | ||
77 | } | ||
78 | |||
79 | void ImageScrollView::contentsMousePressEvent ( QMouseEvent * e) | ||
80 | { | ||
81 | viewportToContents( e->x(), e->y(), _mouseStartPosX,_mouseStartPosY ); | ||
82 | } | ||
83 | |||
84 | /* for testing */ | ||
85 | ImageDlg::ImageDlg(const QString&fname,QWidget * parent, const char * name) | ||
86 | :QDialog(parent,name,true,WStyle_ContextHelp) | ||
87 | { | ||
88 | QVBoxLayout*dlglayout = new QVBoxLayout(this); | ||
89 | dlglayout->setSpacing(2); | ||
90 | dlglayout->setMargin(1); | ||
91 | ImageScrollView*inf = new ImageScrollView(fname,this); | ||
92 | dlglayout->addWidget(inf); | ||
93 | } | ||
94 | |||
95 | ImageDlg::~ImageDlg() | ||
96 | { | ||
97 | } | ||
diff --git a/noncore/graphics/opie-eye/gui/imagescrollview.h b/noncore/graphics/opie-eye/gui/imagescrollview.h new file mode 100644 index 0000000..5836c8d --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/imagescrollview.h | |||
@@ -0,0 +1,43 @@ | |||
1 | #ifndef __IMAGE_SCROLL_VIEW_H | ||
2 | #define __IMAGE_SCROLL_VIEW_H | ||
3 | |||
4 | #include <qscrollview.h> | ||
5 | #include <qimage.h> | ||
6 | #include <qstring.h> | ||
7 | #include <qdialog.h> | ||
8 | |||
9 | class QPainter; | ||
10 | |||
11 | class ImageScrollView:public QScrollView | ||
12 | { | ||
13 | Q_OBJECT | ||
14 | public: | ||
15 | ImageScrollView (const QImage&, QWidget * parent=0, const char * name=0, WFlags f=0 ); | ||
16 | ImageScrollView (const QString&, QWidget * parent=0, const char * name=0, WFlags f=0 ); | ||
17 | virtual ~ImageScrollView(); | ||
18 | |||
19 | void setImage(const QImage&); | ||
20 | protected: | ||
21 | virtual void drawContents ( QPainter * p, int clipx, int clipy, int clipw, int cliph ); | ||
22 | void init(); | ||
23 | |||
24 | QImage _image_data; | ||
25 | |||
26 | int _mouseStartPosX,_mouseStartPosY; | ||
27 | |||
28 | protected slots: | ||
29 | virtual void viewportMouseMoveEvent(QMouseEvent* e); | ||
30 | virtual void contentsMousePressEvent ( QMouseEvent * e); | ||
31 | virtual void contentsMouseReleaseEvent ( QMouseEvent * e); | ||
32 | }; | ||
33 | |||
34 | /* for testing */ | ||
35 | class ImageDlg:public QDialog | ||
36 | { | ||
37 | Q_OBJECT | ||
38 | public: | ||
39 | ImageDlg(const QString&,QWidget * parent=0, const char * name=0); | ||
40 | virtual ~ImageDlg(); | ||
41 | }; | ||
42 | |||
43 | #endif | ||