author | zecke <zecke> | 2005-02-05 15:47:16 (UTC) |
---|---|---|
committer | zecke <zecke> | 2005-02-05 15:47:16 (UTC) |
commit | 8ba13dd38e7da296177719dcc8fddbbe978a4b9a (patch) (side-by-side diff) | |
tree | fdba0d440e7b462faa2b845a0f4364cff134166f | |
parent | 28c5c88c3535c035bd26abd988ef7fb0e098143f (diff) | |
download | opie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.zip opie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.tar.gz opie-8ba13dd38e7da296177719dcc8fddbbe978a4b9a.tar.bz2 |
Add a special MessageBox to squeeze the path to fit onto the screen.
This is a fix for #1539
-rw-r--r-- | noncore/graphics/opie-eye/gui/gui.pro | 6 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/iconview.cpp | 13 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/messagebox.cpp | 119 | ||||
-rw-r--r-- | noncore/graphics/opie-eye/gui/messagebox.h | 57 |
4 files changed, 185 insertions, 10 deletions
diff --git a/noncore/graphics/opie-eye/gui/gui.pro b/noncore/graphics/opie-eye/gui/gui.pro index 2759dd5..250c8b1 100644 --- a/noncore/graphics/opie-eye/gui/gui.pro +++ b/noncore/graphics/opie-eye/gui/gui.pro @@ -1,17 +1,19 @@ HEADERS += gui/filesystem.h \ gui/iconview.h \ gui/imageinfoui.h \ gui/imageview.h \ gui/mainwindow.h \ gui/viewmodebutton.h \ - gui/basesetup.h + gui/basesetup.h \ + gui/messagebox.h SOURCES += gui/filesystem.cpp \ gui/iconview.cpp \ gui/imageinfoui.cpp \ gui/imageview.cpp \ gui/mainwindow.cpp \ gui/viewmodebutton.cpp \ - gui/basesetup.cpp + gui/basesetup.cpp \ + gui/messagebox.cpp diff --git a/noncore/graphics/opie-eye/gui/iconview.cpp b/noncore/graphics/opie-eye/gui/iconview.cpp index 138e661..b2443e8 100644 --- a/noncore/graphics/opie-eye/gui/iconview.cpp +++ b/noncore/graphics/opie-eye/gui/iconview.cpp @@ -1,134 +1,135 @@ /* * GPLv2 zecke@handhelds.org * No WArranty... */ #include "iconview.h" +#include "messagebox.h" #include <lib/imagecache.h> #include <gui/imageinfoui.h> #include <iface/dirview.h> #include <iface/dirlister.h> #include <opie2/oconfig.h> #include <opie2/okeyconfigwidget.h> #include <opie2/odebug.h> #include <opie2/oimagescrollview.h> #include <qpe/resource.h> #include <qpe/qpemessagebox.h> #include <qpe/ir.h> #include <qpe/qcopenvelope_qws.h> #include <qpe/qpeapplication.h> #include <qiconview.h> #include <qlabel.h> #include <qhbox.h> #include <qcombobox.h> #include <qdir.h> #include <qapplication.h> #include <qmainwindow.h> #include <qtimer.h> #include <qstyle.h> using Opie::Core::OKeyConfigItem; /* * The Icons, Request Cache and IconViewItem for the IconView */ namespace { static QPixmap* _dirPix = 0; static QPixmap* _unkPix = 0; static QPixmap* _cpyPix = 0; static QPixmap* _emptyPix = 0; class IconViewItem : public QIconViewItem { public: IconViewItem( QIconView*, const QString& path, const QString& name,int a_iconsize, bool isDir = false); QPixmap* pixmap()const; QString path()const { return m_path; } bool isDir()const { return m_isDir; } void setText( const QString& ); bool textOnly()const{return m_textOnly;} void setTextOnly(bool how){m_textOnly=how;} /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon, bool recalc, bool redraw = TRUE ); /* just for starting recalc of item rect! */ virtual void setPixmap( const QPixmap & icon); protected: mutable QPixmap* m_pix; int m_iconsize; void check_pix()const; private: QString m_path; bool m_isDir : 1; bool m_noInfo :1; bool m_textOnly:1; bool m_NameOnly:1; bool m_Pixset:1; }; class TextViewItem : public IconViewItem { TextViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize , bool isDir = false); QPixmap *pixmap()const; void setText( const QString& ); }; class ThumbViewItem : public IconViewItem { ThumbViewItem( QIconView*, const QString& path, const QString& name, int a_iconsize, bool isDir = false ); QPixmap *pixmap()const; void setText( const QString& ); }; /* * If we request an Image or String * we add it to the map */ static QMap<QString, IconViewItem*> g_stringInf; static QMap<QString, IconViewItem*> g_stringPix; IconViewItem::IconViewItem( QIconView* view,const QString& path, const QString& name, int a_iconsize, bool isDir) : QIconViewItem( view, name ), m_path( path ), m_isDir( isDir ), m_noInfo( false ),m_textOnly(false),m_Pixset(false) { m_iconsize = a_iconsize; if ( isDir ) { if (!_dirPix ) { _dirPix = new QPixmap( Resource::loadPixmap("advancedfm/FileBrowser")); } } else { if (!_unkPix ) { _unkPix = new QPixmap( Resource::loadPixmap( "UnknownDocument" ) ); } } check_pix(); } inline void IconViewItem::check_pix()const { if (_dirPix && _dirPix->width()>m_iconsize) { QImage Pix = _dirPix->convertToImage(); *_dirPix = Pix.smoothScale(m_iconsize,m_iconsize); } if (!_cpyPix && _unkPix) { if (_unkPix->width()>=m_iconsize) { QImage Pix = _unkPix->convertToImage(); _cpyPix = new QPixmap(); if (_unkPix->width()>m_iconsize) { *_cpyPix = Pix.smoothScale(m_iconsize,m_iconsize); } else { _cpyPix->convertFromImage(Pix); } } else { _cpyPix = new QPixmap(m_iconsize,m_iconsize); _cpyPix->fill(); QPainter pa(_cpyPix); int offset = (m_iconsize-_unkPix->width())/2; int offy = (m_iconsize-_unkPix->height())/2; if (offy<0) offy=0; pa.drawPixmap(offset,offy,*_unkPix); pa.end(); @@ -252,312 +253,308 @@ Opie::Core::OKeyConfigManager* PIconView::manager() { /* * init the KeyBoard Shortcuts * called from the c'tor */ void PIconView::initKeys() { Opie::Core::OKeyPair::List lst; lst.append( Opie::Core::OKeyPair::upArrowKey() ); lst.append( Opie::Core::OKeyPair::downArrowKey() ); lst.append( Opie::Core::OKeyPair::leftArrowKey() ); lst.append( Opie::Core::OKeyPair::rightArrowKey() ); lst.append( Opie::Core::OKeyPair::returnKey() ); m_viewManager = new Opie::Core::OKeyConfigManager(m_cfg, "View-KeyBoard-Config", lst, false,this, "keyconfig name" ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Beam Current Item") , "beam", Resource::loadPixmap("beam"), BeamItem, Opie::Core::OKeyPair(Qt::Key_B, Qt::ShiftButton), this, SLOT(slotBeam())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Delete Current Item"), "delete", Resource::loadPixmap("trash"), DeleteItem, Opie::Core::OKeyPair(Qt::Key_D, Qt::ShiftButton), this, SLOT(slotTrash())) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("View Current Item"), "view", Resource::loadPixmap("1to1"), ViewItem, Opie::Core::OKeyPair(Qt::Key_V, Qt::ShiftButton), this, SLOT(slotShowImage()))); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Show Image Info") , "info", Resource::loadPixmap("DocumentTypeWord"), InfoItem, Opie::Core::OKeyPair(Qt::Key_I, Qt::ShiftButton ), this, SLOT(slotImageInfo()) ) ); m_viewManager->addKeyConfig( OKeyConfigItem(tr("Start slideshow"), "slideshow", Resource::loadPixmap("1to1"), SlideItem, Opie::Core::OKeyPair(Qt::Key_S, Qt::ShiftButton), this, SLOT(slotStartSlide()))); m_viewManager->load(); m_viewManager->handleWidget( m_view ); } /* * change one dir up */ void PIconView::slotDirUp() { slotChangeDir( currentView()->dirLister()->dirUp( m_path ) ); } /* * change the dir */ void PIconView::slotChangeDir(const QString& path) { if ( !currentView() ) return; PDirLister *lister = currentView()->dirLister(); if (!lister ) return; /* * Say what we want and take what we get */ lister->setStartPath( path ); m_path = lister->currentPath(); m_view->viewport()->setUpdatesEnabled( false ); m_view->clear(); // Also invalidate the cache. We can't cancel the operations anyway g_stringPix.clear(); g_stringInf.clear(); /* * add files and folders */ addFolders( lister->folders() ); addFiles( lister->files() ); m_view->viewport()->setUpdatesEnabled( true ); // looks ugly static_cast<QMainWindow*>(parent())->setCaption( QObject::tr("%1 - O View", "Name of the dir").arg( m_path ) ); } /** * get the current file name * @param isDir see if this is a dir or real file */ QString PIconView::currentFileName(bool &isDir)const { isDir = false; QIconViewItem* _it = m_view->currentItem(); if ( !_it ) return QString::null; IconViewItem* it = static_cast<IconViewItem*>( _it ); isDir = it->isDir(); return it->path(); } QString PIconView::nextFileName(bool &isDir)const { isDir = false; QIconViewItem* _it1 = m_view->currentItem(); if ( !_it1 ) return QString::null; QIconViewItem* _it = _it1->nextItem(); if ( !_it ) return QString::null; IconViewItem* it = static_cast<IconViewItem*>( _it ); isDir = it->isDir(); return it->path(); } QString PIconView::prevFileName(bool &isDir)const{ isDir = false; QIconViewItem* _it = m_view->currentItem(); if ( !_it ) return QString::null; _it = _it->prevItem(); 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() ) + if ( isDir || pa.isEmpty() ) return; - if (!QPEMessageBox::confirmDelete( this, - tr("Delete Image" ), - tr("the Image %1" ).arg(pa))) - return + if (!OMessageBox::confirmDelete( this, tr("the Image"), + pa, tr("Delete Image" ))) + return; currentView()->dirLister()->deleteImage( pa ); delete m_view->currentItem(); } /* * see what views are available */ void PIconView::loadViews() { ViewMap::Iterator it; ViewMap* map = viewMap(); for ( it = map->begin(); it != map->end(); ++it ) m_views->insertItem( it.key() ); } void PIconView::resetView() { m_internalReset = true; // Also invalidate the cache. We can't cancel the operations anyway g_stringPix.clear(); g_stringInf.clear(); if (m_mode>1) { int osize = m_iconsize; m_iconsize = m_cfg->readNumEntry("iconsize", 32); if (m_iconsize<12)m_iconsize = 12; if (m_iconsize>64)m_iconsize = 64; if (osize != m_iconsize) { if (_dirPix){ delete _dirPix; _dirPix = 0; } if (_cpyPix){ delete _cpyPix; _cpyPix = 0; } calculateGrid(); } } else { m_iconsize = 64; } slotViewChanged(m_views->currentItem()); m_internalReset = false; } void PIconView::polish() { - odebug << "===\n" - << "PIconView::polish()\n" - << "====" << oendl; QVBox::polish(); QString lastView = m_cfg->readEntry("LastView",""); int cc=0; for (; cc<m_views->count();++cc) { if (m_views->text(cc)==lastView) { break; } } if (cc<m_views->count()) { m_views->setCurrentItem(cc); slotViewChanged(cc); } else { slotViewChanged(m_views->currentItem()); } connect( m_views, SIGNAL(activated(int)), this, SLOT(slotViewChanged(int)) ); } /* *swicth view reloadDir and connect signals */ void PIconView::slotViewChanged( int i) { if (!m_views->count() ) { setCurrentView( 0l); return; } if (m_customWidget) { delete m_customWidget; m_customWidget = 0; } PDirView* cur = currentView(); if (cur) { delete cur; } QString str = m_views->text(i); ViewMap* map = viewMap(); if (!map) { setCurrentView(0l); return; } if (map->find(str) == map->end()) { owarn << "Key not found" << oendl; setCurrentView(0l); return; } m_cfg->writeEntry("LastView",str); m_cfg->write(); cur = (*(*map)[str])(*m_cfg); setCurrentView( cur ); m_customWidget = cur->widget(m_hbox); if (m_customWidget) { odebug << "Got a widget" << oendl; m_customWidget->show(); } /* 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()) ); connect(lis,SIGNAL(sig_reloadDir()),this,SLOT(slotReloadDir())); /* reload now with default Path * but only if it isn't a reset like from setupdlg */ if (!m_internalReset) { m_path = lis->defaultPath(); } QTimer::singleShot( 0, this, SLOT(slotReloadDir())); } void PIconView::slotReloadDir() { slotChangeDir( m_path ); } /* * add files and folders */ void PIconView::addFolders( const QStringList& lst) { QStringList::ConstIterator it; IconViewItem * _iv; for(it=lst.begin(); it != lst.end(); ++it ) { _iv = new IconViewItem( m_view, m_path+"/"+(*it), (*it),m_iconsize, true ); if (m_mode==3) _iv->setTextOnly(true); } } void PIconView::addFiles( const QStringList& lst) { QStringList::ConstIterator it; IconViewItem * _iv; QPixmap*m_pix = 0; QString pre = ""; if (!m_path.isEmpty()) { pre = m_path+"/"; } QString s = ""; int pos; for (it=lst.begin(); it!= lst.end(); ++it ) { s = (*it); pos = s.find(char(0)); m_pix = PPixmapCache::self()->cachedImage( pre+(*it), m_iconsize, m_iconsize ); if (pos>-1) { _iv = new IconViewItem( m_view, s.mid(pos+1), s.left(pos),m_iconsize ); } else { _iv = new IconViewItem( m_view, pre+(*it), (*it),m_iconsize ); } if (m_mode==3) { _iv->setTextOnly(true); _iv->setPixmap(QPixmap()); } else { if (m_pix) _iv->setPixmap(*m_pix); } } } diff --git a/noncore/graphics/opie-eye/gui/messagebox.cpp b/noncore/graphics/opie-eye/gui/messagebox.cpp new file mode 100644 index 0000000..c84e4e1 --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/messagebox.cpp @@ -0,0 +1,119 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (c) 2004 Holger Hans Peter <freyther@handhelds.org> + .>+-= + _;:, .> :=|. This library is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This library is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#include "messagebox.h" + +#include <qapplication.h> +#include <qmessagebox.h> + +/* + * LGPLv2 KDE Project kstringhandler.cpp + */ +template<class T> +inline const T& kClamp( const T& x, const T& low, const T& high ) +{ + if ( x < low ) return low; + else if ( high < x ) return high; + else return x; +} + +/** + * dependant on the screen rotation place the dots + */ +static QString g_insert_ldot( const QString& name, const QFontMetrics& fontMetrics ) { + uint maxPixels = qApp->desktop()->width()-90; + uint nameWidth = fontMetrics.width(name); + + if (maxPixels < nameWidth) { + QString tmp = name; + const uint em = fontMetrics.maxWidth(); + maxPixels -= fontMetrics.width("..."); + + while (maxPixels < nameWidth && !tmp.isEmpty()) { + int delta = (nameWidth - maxPixels) / em; + delta = kClamp(delta, 1, delta); // no max + + tmp.remove(0, delta); + nameWidth = fontMetrics.width(tmp); + } + + return ("..." + tmp); + } + + return name; +} + +/** + * + * #FIXME Write Own message box to be more independant on sizes + * #FIXME Ask translator how to make the sentence more robust + * + * \brief replacement for QPEMessageBox::confirmDelete + * + * If you want to delete a file and the path is too long to fit + * on the screen \ldots is inserted in the middle of the string + * to fit on the screen. This allows the user still to identify + * the file. + * + * @param parent The parent of this MessageBox + * @param type The type of the object to delte. i.e 'the image' + * @param object The 'object' to be deleted + * @param caption An optional caption for the box + * + */ +bool OMessageBox::confirmDelete( QWidget* parent, const QString& type, const QString& object, + const QString& _caption ) { + /* + * create a messagebox to get the font metrics + */ + QMessageBox msg( QString::null, QString::null, + QMessageBox::Warning, QMessageBox::Yes, + QMessageBox::No|QMessageBox::Default|QMessageBox::Escape, + QMessageBox::NoButton, + parent, "OMessageBox::confirmDelete" ); + + /* + * Create the Message and Caption + */ + QString msga = QObject::tr("<qt>Are you sure you want to delete %1<br> %2?</qt>" ) + .arg( type ) + .arg( g_insert_ldot( object, msg.fontMetrics() ) ); + QString caption = _caption.isEmpty() ? + QObject::tr( "Confirm Deletion" ) : _caption; + + msg.setText( msga ); + msg.setCaption( caption ); + msg.setIcon( QMessageBox::Warning ); + msg.adjustSize(); + + /* + * Warn the user that he will delete + */ + int ret = msg.exec(); + return ( ret == QMessageBox::Yes ); +} diff --git a/noncore/graphics/opie-eye/gui/messagebox.h b/noncore/graphics/opie-eye/gui/messagebox.h new file mode 100644 index 0000000..a0e6fa0 --- a/dev/null +++ b/noncore/graphics/opie-eye/gui/messagebox.h @@ -0,0 +1,57 @@ +/* + =. This file is part of the OPIE Project + .=l. Copyright (c) 2004 Holger Hans Peter <freyther@handhelds.org> + .>+-= + _;:, .> :=|. This library is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU Library General Public +.="- .-=="i, .._ License as published by the Free Software + - . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This library is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU +..}^=.= = ; Library General Public License for more +++= -. .` .: details. + : = ...= . :.=- + -. .:....=;==+<; You should have received a copy of the GNU + -_. . . )=. = Library General Public License along with + -- :-=` this library; see the file COPYING.LIB. + If not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + +*/ + +#ifndef OPIE_UI_OMESSAGE_BOX_H +#define OPIE_UI_OMEESAGE_BOX_H + +#include <qstring.h> + +class QWidget; + +/* + * ### to be moved to OpieUI + * ### move KDEs KStringHandler to OpieCore + * ### once done + * FIXME + */ + +/** + * \brief Custom and common Opie MessageBoxes + * + * A set of static methods to open special MessageBoxes. + */ +class OMessageBox { +public: + static bool confirmDelete(QWidget *parent, + const QString& type, + const QString& object, + const QString & caption = QString::null); + +}; + +#endif |