summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/graphics/opie-eye/gui/iconview.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp
index f173ecc..5472ead 100644
--- a/noncore/graphics/opie-eye/gui/iconview.cpp
+++ b/noncore/graphics/opie-eye/gui/iconview.cpp
@@ -1,250 +1,253 @@
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 10
11#include <iface/dirview.h> 11#include <iface/dirview.h>
12#include <iface/dirlister.h> 12#include <iface/dirlister.h>
13 13
14#include <opie2/oconfig.h> 14#include <opie2/oconfig.h>
15#include <opie2/okeyconfigwidget.h> 15#include <opie2/okeyconfigwidget.h>
16#include <opie2/odebug.h> 16#include <opie2/odebug.h>
17#include <opie2/oimagescrollview.h> 17#include <opie2/oimagescrollview.h>
18 18
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20#include <qpe/qpemessagebox.h> 20#include <qpe/qpemessagebox.h>
21#include <qpe/ir.h> 21#include <qpe/ir.h>
22#include <qpe/qcopenvelope_qws.h> 22#include <qpe/qcopenvelope_qws.h>
23#include <qpe/qpeapplication.h> 23#include <qpe/qpeapplication.h>
24 24
25#include <qiconview.h> 25#include <qiconview.h>
26#include <qlabel.h> 26#include <qlabel.h>
27#include <qhbox.h> 27#include <qhbox.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qapplication.h> 30#include <qapplication.h>
31#include <qmainwindow.h> 31#include <qmainwindow.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qstyle.h> 33#include <qstyle.h>
34 34
35 35
36using Opie::Core::OKeyConfigItem; 36using Opie::Core::OKeyConfigItem;
37 37
38/* 38/*
39 * The Icons, Request Cache and IconViewItem for the IconView 39 * The Icons, Request Cache and IconViewItem for the IconView
40 */ 40 */
41namespace { 41namespace {
42 static QPixmap* _dirPix = 0; 42 static QPixmap* _dirPix = 0;
43 static QPixmap* _unkPix = 0; 43 static QPixmap* _unkPix = 0;
44 static QPixmap* _cpyPix = 0; 44 static QPixmap* _cpyPix = 0;
45 static QPixmap* _emptyPix = 0; 45 static QPixmap* _emptyPix = 0;
46 class IconViewItem : public QIconViewItem { 46 class IconViewItem : public QIconViewItem {
47 public: 47 public:
48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false); 48 IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false);
49 QPixmap* pixmap()const; 49 QPixmap* pixmap()const;
50 QString path()const { return m_path; } 50 QString path()const { return m_path; }
51 bool isDir()const { return m_isDir; } 51 bool isDir()const { return m_isDir; }
52 void setText( const QString& ); 52 void setText( const QString& );
53 bool textOnly()const{return m_textOnly;} 53 bool textOnly()const{return m_textOnly;}
54 void setTextOnly(bool how){m_textOnly=how;} 54 void setTextOnly(bool how){m_textOnly=how;}
55 /* just for starting recalc of item rect! */ 55 /* just for starting recalc of item rect! */
56 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); 56 virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE );
57 /* just for starting recalc of item rect! */ 57 /* just for starting recalc of item rect! */
58 virtual void setPixmap( const QPixmap & icon); 58 virtual void setPixmap( const QPixmap & icon);
59 59
60 protected: 60 protected:
61 mutable QPixmap* m_pix; 61 mutable QPixmap* m_pix;
62 int m_iconsize; 62 int m_iconsize;
63 void check_pix()const; 63 void check_pix()const;
64 64
65 private: 65 private:
66 QString m_path; 66 QString m_path;
67 bool m_isDir : 1; 67 bool m_isDir : 1;
68 bool m_noInfo :1; 68 bool m_noInfo :1;
69 bool m_textOnly:1; 69 bool m_textOnly:1;
70 bool m_NameOnly:1; 70 bool m_NameOnly:1;
71 bool m_Pixset:1; 71 bool m_Pixset:1;
72 }; 72 };
73 class TextViewItem : public IconViewItem { 73 class TextViewItem : public IconViewItem {
74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); 74 TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false);
75 QPixmap *pixmap()const; 75 QPixmap *pixmap()const;
76 void setText( const QString& ); 76 void setText( const QString& );
77 }; 77 };
78 class ThumbViewItem : public IconViewItem { 78 class ThumbViewItem : public IconViewItem {
79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); 79 ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false );
80 QPixmap *pixmap()const; 80 QPixmap *pixmap()const;
81 void setText( const QString& ); 81 void setText( const QString& );
82 }; 82 };
83 83
84 84
85/* 85/*
86 * If we request an Image or String 86 * If we request an Image or String
87 * we add it to the map 87 * we add it to the map
88 */ 88 */
89 static QMap<QString, IconViewItem*> g_stringInf; 89 static QMap<QString, IconViewItem*> g_stringInf;
90 static QMap<QString, IconViewItem*> g_stringPix; 90 static QMap<QString, IconViewItem*> g_stringPix;
91 91
92 IconViewItem::IconViewItem( QIconView* view,const QString& path, 92 IconViewItem::IconViewItem( QIconView* view,const QString& path,
93 const QString& name, int a_iconsize, bool isDir) 93 const QString& name, int a_iconsize, bool isDir)
94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), 94 : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ),
95 m_noInfo( false ),m_textOnly(false),m_Pixset(false) 95 m_noInfo( false ),m_textOnly(false),m_Pixset(false)
96 { 96 {
97 m_iconsize = a_iconsize; 97 m_iconsize = a_iconsize;
98 if ( isDir ) { 98 if ( isDir ) {
99 if (!_dirPix ) { 99 if (!_dirPix ) {
100 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); 100 _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser"));
101 } 101 }
102 } else { 102 } else {
103 if (!_unkPix ) { 103 if (!_unkPix ) {
104 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); 104 _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) );
105 } 105 }
106 } 106 }
107 check_pix(); 107 check_pix();
108 } 108 }
109 109
110 inline void IconViewItem::check_pix()const 110 inline void IconViewItem::check_pix()const
111 { 111 {
112 if (_dirPix && _dirPix->width()>m_iconsize) { 112 if (_dirPix && _dirPix->width()>m_iconsize) {
113 QPixmap*Pix = new QPixmap(*_dirPix); 113 QImage Pix = _dirPix->convertToImage();
114 Pix->resize(m_iconsize,m_iconsize); 114 *_dirPix = Pix.smoothScale(m_iconsize,m_iconsize);
115 delete _dirPix;
116 _dirPix = Pix;
117 } 115 }
118 if (!_cpyPix && _unkPix) { 116 if (!_cpyPix && _unkPix) {
119 if (_unkPix->width()>=m_iconsize) { 117 if (_unkPix->width()>=m_iconsize) {
120 _cpyPix = new QPixmap(*_unkPix); 118 QImage Pix = _unkPix->convertToImage();
121 if (_unkPix->width()>m_iconsize) 119 _cpyPix = new QPixmap();
122 _cpyPix->resize(m_iconsize,m_iconsize); 120 if (_unkPix->width()>m_iconsize) {
121 *_cpyPix = Pix.smoothScale(m_iconsize,m_iconsize);
122 } else {
123 _cpyPix->convertFromImage(Pix);
124 }
125
123 } else { 126 } else {
124 _cpyPix = new QPixmap(m_iconsize,m_iconsize); 127 _cpyPix = new QPixmap(m_iconsize,m_iconsize);
125 _cpyPix->fill(); 128 _cpyPix->fill();
126 QPainter pa(_cpyPix); 129 QPainter pa(_cpyPix);
127 int offset = (m_iconsize-_unkPix->width())/2; 130 int offset = (m_iconsize-_unkPix->width())/2;
128 int offy = (m_iconsize-_unkPix->height())/2; 131 int offy = (m_iconsize-_unkPix->height())/2;
129 if (offy<0) offy=0; 132 if (offy<0) offy=0;
130 pa.drawPixmap(offset,offy,*_unkPix); 133 pa.drawPixmap(offset,offy,*_unkPix);
131 pa.end(); 134 pa.end();
132 } 135 }
133 } 136 }
134 } 137 }
135 138
136 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool ) 139 inline void IconViewItem::setPixmap( const QPixmap & , bool, bool )
137 { 140 {
138 m_Pixset = true; 141 m_Pixset = true;
139 calcRect(text()); 142 calcRect(text());
140 } 143 }
141 inline void IconViewItem::setPixmap( const QPixmap & ) 144 inline void IconViewItem::setPixmap( const QPixmap & )
142 { 145 {
143 m_Pixset = true; 146 m_Pixset = true;
144 calcRect(text()); 147 calcRect(text());
145 } 148 }
146 149
147 inline QPixmap* IconViewItem::pixmap()const { 150 inline QPixmap* IconViewItem::pixmap()const {
148// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y() 151// owarn << "Name is " << m_path.right( 15 ) << " rect is " << rect().x() << " " << rect().y()
149// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX() 152// << " " << rect().width() << " " << rect().height() << " | " << iconView()->contentsX()
150// << " " << iconView()->contentsY() << oendl; 153// << " " << iconView()->contentsY() << oendl;
151 154
152 if (textOnly()&&!m_isDir) { 155 if (textOnly()&&!m_isDir) {
153 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1); 156 if (!_emptyPix) _emptyPix = new QPixmap(0,0,1);
154 return _emptyPix; 157 return _emptyPix;
155 } 158 }
156 if ( m_isDir ) 159 if ( m_isDir )
157 return _dirPix; 160 return _dirPix;
158 else{ 161 else{
159 if (!m_noInfo && !g_stringInf.contains( m_path ) ) { 162 if (!m_noInfo && !g_stringInf.contains( m_path ) ) {
160 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this)); 163 g_stringInf.insert( m_path, const_cast<IconViewItem*>(this));
161 currentView()->dirLister()->imageInfo( m_path ); 164 currentView()->dirLister()->imageInfo( m_path );
162 } 165 }
163 166
164 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize ); 167 m_pix = PPixmapCache::self()->cachedImage( m_path, m_iconsize, m_iconsize );
165 if (!m_pix && !g_stringPix.contains( m_path )) { 168 if (!m_pix && !g_stringPix.contains( m_path )) {
166 check_pix(); 169 check_pix();
167 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this)); 170 g_stringPix.insert( m_path, const_cast<IconViewItem*>(this));
168 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize); 171 currentView()->dirLister()->thumbNail( m_path, m_iconsize, m_iconsize);
169 } 172 }
170 return m_pix ? m_pix : _cpyPix; 173 return m_pix ? m_pix : _cpyPix;
171 } 174 }
172 } 175 }
173 inline void IconViewItem::setText( const QString& str ) { 176 inline void IconViewItem::setText( const QString& str ) {
174 QString text = QIconViewItem::text()+"\n"+str; 177 QString text = QIconViewItem::text()+"\n"+str;
175 m_noInfo = true; 178 m_noInfo = true;
176 QIconViewItem::setText( text ); 179 QIconViewItem::setText( text );
177 } 180 }
178} 181}
179 182
180 183
181/* 184/*
182 * Set up the GUI.. initialize the slave set up gui 185 * Set up the GUI.. initialize the slave set up gui
183 * and also load a dir 186 * and also load a dir
184 */ 187 */
185PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg ) 188PIconView::PIconView( QWidget* wid, Opie::Core::OConfig* cfg )
186 : QVBox( wid ), m_cfg( cfg ), m_updatet( false ) 189 : QVBox( wid ), m_cfg( cfg ), m_updatet( false )
187{ 190{
188 { 191 {
189 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" ); 192 QCopEnvelope( "QPE/Application/opie-eye_slave", "refUp()" );
190 } 193 }
191 m_path = QDir::homeDirPath(); 194 m_path = QDir::homeDirPath();
192 m_mode = 0; 195 m_mode = 0;
193 m_iconsize = 32; 196 m_iconsize = 32;
194 m_internalReset = false; 197 m_internalReset = false;
195 198
196 QHBox *hbox = new QHBox( this ); 199 QHBox *hbox = new QHBox( this );
197 QLabel* lbl = new QLabel( hbox ); 200 QLabel* lbl = new QLabel( hbox );
198 lbl->setText( tr("View as" ) ); 201 lbl->setText( tr("View as" ) );
199 202
200 m_views = new QComboBox( hbox, "View As" ); 203 m_views = new QComboBox( hbox, "View As" );
201 204
202 m_view= new QIconView( this ); 205 m_view= new QIconView( this );
203 connect(m_view, SIGNAL(clicked(QIconViewItem*) ), 206 connect(m_view, SIGNAL(clicked(QIconViewItem*) ),
204 this, SLOT(slotClicked(QIconViewItem*)) ); 207 this, SLOT(slotClicked(QIconViewItem*)) );
205 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)), 208 connect(m_view, SIGNAL(returnPressed(QIconViewItem*)),
206 this, SLOT(slotClicked(QIconViewItem*)) ); 209 this, SLOT(slotClicked(QIconViewItem*)) );
207 210
208 m_view->setArrangement( QIconView::LeftToRight ); 211 m_view->setArrangement( QIconView::LeftToRight );
209 212
210 m_mode = m_cfg->readNumEntry("ListViewMode", 1); 213 m_mode = m_cfg->readNumEntry("ListViewMode", 1);
211 QString lastView = m_cfg->readEntry("LastView",""); 214 QString lastView = m_cfg->readEntry("LastView","");
212 215
213 if (m_mode < 1 || m_mode>3) m_mode = 1; 216 if (m_mode < 1 || m_mode>3) m_mode = 1;
214 217
215 m_view->setItemTextPos( QIconView::Right ); 218 m_view->setItemTextPos( QIconView::Right );
216 if (m_mode >1) { 219 if (m_mode >1) {
217 m_view->setResizeMode(QIconView::Adjust); 220 m_view->setResizeMode(QIconView::Adjust);
218 } else { 221 } else {
219 m_view->setResizeMode(QIconView::Fixed); 222 m_view->setResizeMode(QIconView::Fixed);
220 } 223 }
221 m_iconsize = m_cfg->readNumEntry("iconsize", 32); 224 m_iconsize = m_cfg->readNumEntry("iconsize", 32);
222 if (m_iconsize<12)m_iconsize = 12; 225 if (m_iconsize<12)m_iconsize = 12;
223 if (m_iconsize>64)m_iconsize = 64; 226 if (m_iconsize>64)m_iconsize = 64;
224 227
225 calculateGrid(); 228 calculateGrid();
226 229
227 initKeys(); 230 initKeys();
228 231
229 loadViews(); 232 loadViews();
230 int cc=0; 233 int cc=0;
231 for (; cc<m_views->count();++cc) { 234 for (; cc<m_views->count();++cc) {
232 if (m_views->text(cc)==lastView) { 235 if (m_views->text(cc)==lastView) {
233 break; 236 break;
234 } 237 }
235 } 238 }
236 if (cc<m_views->count()) { 239 if (cc<m_views->count()) {
237 m_views->setCurrentItem(cc); 240 m_views->setCurrentItem(cc);
238 slotViewChanged(cc); 241 slotViewChanged(cc);
239 } else { 242 } else {
240 slotViewChanged(m_views->currentItem()); 243 slotViewChanged(m_views->currentItem());
241 } 244 }
242 connect( m_views, SIGNAL(activated(int)), 245 connect( m_views, SIGNAL(activated(int)),
243 this, SLOT(slotViewChanged(int)) ); 246 this, SLOT(slotViewChanged(int)) );
244} 247}
245 248
246/* 249/*
247 * Unref the slave and save the keyboard manager 250 * Unref the slave and save the keyboard manager
248 */ 251 */
249PIconView::~PIconView() { 252PIconView::~PIconView() {
250 { 253 {