author | drw <drw> | 2005-04-05 22:38:32 (UTC) |
---|---|---|
committer | drw <drw> | 2005-04-05 22:38:32 (UTC) |
commit | 0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d (patch) (side-by-side diff) | |
tree | 27fb276e59b1eab586d029feaf21f45ddf1cb96a | |
parent | 327e938f58125a52482b9a6543dd1aa4243bb5d3 (diff) | |
download | opie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.zip opie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.tar.gz opie-0f7b159f0a4972b6ffdc292f5eb4d2169c7fa75d.tar.bz2 |
Use OResource for loading images
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.cpp | 81 | ||||
-rw-r--r-- | libopie2/opieui/fileselector/ofileselector.h | 46 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.cpp | 66 | ||||
-rw-r--r-- | libopie2/opieui/otabwidget.h | 50 | ||||
-rw-r--r-- | libopie2/opieui/owait.cpp | 50 | ||||
-rw-r--r-- | libopie2/opieui/owait.h | 47 |
6 files changed, 162 insertions, 178 deletions
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp index 8b53038..f3e7501 100644 --- a/libopie2/opieui/fileselector/ofileselector.cpp +++ b/libopie2/opieui/fileselector/ofileselector.cpp @@ -1,1256 +1,1251 @@ - /* - =. This file is part of the OPIE Project - .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@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. +         This file is part of the Opie Project + + Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> + =. + .=l. +      .>+-= + _;:,   .>   :=|. This program 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 program 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. - */ /* hacky but we need to get FileSelector::filter */ #define private public #include <qpe/fileselector.h> #undef private #include "ofileselector_p.h" /* OPIE */ -#include <opie2/ofileselector.h> #include <opie2/odebug.h> +#include <opie2/ofileselector.h> +#include <opie2/oresource.h> #include <qpe/qpeapplication.h> #include <qpe/mimetype.h> -#include <qpe/resource.h> #include <qpe/storage.h> /* QT */ #include <qcombobox.h> #include <qdir.h> #include <qhbox.h> #include <qheader.h> #include <qlabel.h> #include <qlayout.h> #include <qlineedit.h> #include <qlistview.h> #include <qpopupmenu.h> #include <qwidgetstack.h> #include <qregexp.h> #include <qobjectlist.h> using namespace Opie::Ui::Internal; namespace Opie { namespace Ui { namespace Internal { /* * Create a path by adding a '/'/QDir::seperator in between * base and ending, but only if base is not empty */ static inline QString createNewPath(const QString& base, const QString &ending) { return base == QString::fromLatin1("/") ? base + ending : base + "/" + ending; } OFileViewInterface::OFileViewInterface( OFileSelector* _selector ) : m_selector( _selector ) { selector()->registerView( this ); } OFileViewInterface::~OFileViewInterface() {} QString OFileViewInterface::name()const { return m_name; } void OFileViewInterface::setName( const QString& name ) { m_name = name; } OFileSelector* OFileViewInterface::selector()const { return m_selector; } DocLnk OFileViewInterface::selectedDocument()const { return DocLnk( selectedName() ); } bool OFileViewInterface::showNew()const { return selector()->showNew(); } bool OFileViewInterface::showClose()const { return selector()->showClose(); } MimeTypes OFileViewInterface::mimeTypes()const { return selector()->mimeTypes(); } QStringList OFileViewInterface::currentMimeType()const { return selector()->currentMimeType(); } void OFileViewInterface::activate( const QString& ) { // not implemented here } void OFileViewInterface::ok() { emit selector()->ok(); } void OFileViewInterface::cancel() { emit selector()->cancel(); } void OFileViewInterface::closeMe() { emit selector()->closeMe(); } void OFileViewInterface::fileSelected( const QString& str) { emit selector()->fileSelected( str); } void OFileViewInterface::fileSelected( const DocLnk& lnk) { emit selector()->fileSelected( lnk ); } void OFileViewInterface::setCurrentFileName( const QString& str ) { selector()->m_lneEdit->setText( str ); } QString OFileViewInterface::currentFileName()const { return selector()->m_lneEdit->text(); } QString OFileViewInterface::startDirectory()const { return selector()->m_startDir; } bool OFileViewInterface::allItem( const QString& item )const { return selector()->m_allList.contains( item ); } ODocumentFileView::ODocumentFileView( OFileSelector* selector ) :OFileViewInterface( selector ) { m_selector = 0; setName( QObject::tr("Documents") ); } ODocumentFileView::~ODocumentFileView() { } QString ODocumentFileView::selectedName()const { if (!m_selector) return QString::null; return m_selector->selectedDocument().file(); } QString ODocumentFileView::selectedPath()const { return QPEApplication::documentDir(); } QString ODocumentFileView::directory()const { return selectedPath(); } void ODocumentFileView::reread() { if (!m_selector) return; m_selector->setNewVisible( showNew() ); m_selector->setCloseVisible( showClose() ); m_selector->filter = currentMimeType().join(";"); m_selector->reread(); } int ODocumentFileView::fileCount()const { if (!m_selector) return -1; return m_selector->fileCount(); } DocLnk ODocumentFileView::selectedDocument()const { if (!m_selector) return DocLnk(); return m_selector->selectedDocument(); } QWidget* ODocumentFileView::widget( QWidget* parent ) { if (!m_selector ) { m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() ); QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ), selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) ); QObject::connect(m_selector, SIGNAL(closeMe() ), selector(), SIGNAL(closeMe() ) ); QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ), selector(), SIGNAL(newSelected(const DocLnk&) ) ); } return m_selector; } /* * This is the file system view used * we use a QListView + QListViewItems for it */ OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap, const QString& path, const QString& date, const QString& size, const QString& dir, bool isLocked, bool isDir ) : QListViewItem( view ), m_dir(dir), m_isDir(isDir), m_locked(isLocked) { setPixmap(0, pixmap ); setText(1, path ); setText(2, size ); setText(3, date ); } OFileSelectorItem::~OFileSelectorItem() { } bool OFileSelectorItem::isLocked()const { return m_locked; } QString OFileSelectorItem::directory()const { return m_dir; } bool OFileSelectorItem::isDir()const { return m_isDir; } QString OFileSelectorItem::path()const { return text( 1 ); } QString OFileSelectorItem::key( int id, bool )const { QString ke; /* * id = 0 ||id == 1 : Sort By Name but Directories at Top * id = 2 : Sort By Size: Prepend '0' to the key */ if( id == 0 || id == 1 ) { // name if( m_isDir ) { ke.append("0" ); ke.append( text(1) ); } else { ke.append("1" ); ke.append( text(1) ); } return ke; }else if(id == 2) { return text(2).rightJustify(20, '0'); }else return text( id ); } OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel) :QWidget( parent ), m_sel( sel ) { m_all = false; QVBoxLayout* lay = new QVBoxLayout( this ); m_currentDir = startDir; /* * now we add a special bar * One Button For Up * Home * Doc * And a dropdown menu with FileSystems * FUTURE: one to change dir with lineedit * Bookmarks * Create Dir */ QHBox* box = new QHBox(this ); box->setBackgroundMode( PaletteButton ); box->setSpacing( 0 ); - QPixmap pic; QToolButton *btn = new QToolButton( box ); btn->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "up" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - btn->setPixmap( pic ); + btn->setPixmap( Opie::Core::OResource::loadPixmap( "up", Opie::Core::OResource::SmallIcon ) ); connect(btn, SIGNAL(clicked() ), this, SLOT( cdUP() ) ); btn = new QToolButton( box ); btn->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "home" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - btn->setPixmap( pic ); + btn->setPixmap( Opie::Core::OResource::loadPixmap( "home", Opie::Core::OResource::SmallIcon ) ); connect(btn, SIGNAL(clicked() ), this, SLOT( cdHome() ) ); btn = new QToolButton( box ); btn->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "DocsIcon" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - btn->setPixmap( pic ); + btn->setPixmap( Opie::Core::OResource::loadPixmap( "DocsIcon", Opie::Core::OResource::SmallIcon ) ); connect(btn, SIGNAL(clicked() ), this, SLOT(cdDoc() ) ); m_btnNew = new QToolButton( box ); m_btnNew->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "new" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - m_btnNew->setPixmap( pic ); + m_btnNew->setPixmap( Opie::Core::OResource::loadPixmap( "new", Opie::Core::OResource::SmallIcon ) ); connect(m_btnNew, SIGNAL(clicked() ), this, SLOT(slotNew() ) ); m_btnClose = new QToolButton( box ); m_btnClose->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "close" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - m_btnClose->setPixmap( pic ); + m_btnClose->setPixmap( Opie::Core::OResource::loadPixmap( "close", Opie::Core::OResource::SmallIcon ) ); connect(m_btnClose, SIGNAL(clicked() ), selector(), SIGNAL(closeMe() ) ); btn = new QToolButton( box ); btn->setUsesBigPixmap( true ); - pic.convertFromImage( Resource::loadImage( "cardmon/pcmcia" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - btn->setPixmap( pic ); + btn->setPixmap( Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ) ); m_fsButton = btn; /* let's fill device parts */ QPopupMenu* pop = new QPopupMenu(this); connect(pop, SIGNAL( activated(int) ), this, SLOT(slotFSActivated(int) ) ); StorageInfo storage; const QList<FileSystem> &fs = storage.fileSystems(); QListIterator<FileSystem> it(fs); for ( ; it.current(); ++it ) { const QString disk = (*it)->name(); const QString path = (*it)->path(); m_dev.insert( disk, path ); pop->insertItem( disk ); } m_fsPop = pop; connect(btn,SIGNAL(pressed()),this,SLOT(slotFSpressed())); lay->addWidget( box ); m_view = new QListView( this ); m_view->installEventFilter(this); QPEApplication::setStylusOperation( m_view->viewport(), QPEApplication::RightOnHold); m_view->addColumn(" " ); m_view->addColumn(tr("Name"), 135 ); m_view->addColumn(tr("Size"), -1 ); m_view->addColumn(tr("Date"), 60 ); m_view->addColumn(tr("Mime Type"), -1 ); m_view->setSorting( 1 ); m_view->setAllColumnsShowFocus( TRUE ); lay->addWidget( m_view, 1000 ); connectSlots(); } void OFileViewFileListView::slotFSpressed() { m_fsPop->exec(QPoint( QCursor::pos().x(), QCursor::pos().y())); m_fsButton->setDown(false); } OFileViewFileListView::~OFileViewFileListView() { } void OFileViewFileListView::slotNew() { DocLnk lnk; emit selector()->newSelected( lnk ); } OFileSelectorItem* OFileViewFileListView::currentItem()const { QListViewItem* item = m_view->currentItem(); if (!item ) return 0l; return static_cast<OFileSelectorItem*>(item); } void OFileViewFileListView::reread( bool all ) { m_view->clear(); if (selector()->showClose() ) m_btnClose->show(); else m_btnClose->hide(); if (selector()->showNew() ) m_btnNew->show(); else m_btnNew->hide(); m_mimes = selector()->currentMimeType(); m_all = all; QDir dir( m_currentDir ); if (!dir.exists() ) return; dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed ); int filter; filter = QDir::Dirs; if ( selector()->mode() != OFileSelector::DIRECTORYSELECTOR ) filter = filter | QDir::Files | QDir::All; if ( m_all ) filter = filter | QDir::Hidden; dir.setFilter( filter ); // now go through all files const QFileInfoList *list = dir.entryInfoList(); if (!list) { cdUP(); return; } QFileInfoListIterator it( *list ); QFileInfo *fi; while( (fi=it.current() ) ) { if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") ) { ++it; continue; } /* * It is a symlink we try to resolve it now but don't let us attack by DOS * */ if( fi->isSymLink() ) { QString file = createNewPath(fi->dirPath( true ),fi->readLink()); for( int i = 0; i<=4; i++) { // 5 tries to prevent dos QFileInfo info( file ); if( !info.exists() ) { addSymlink( fi, TRUE ); break; } else if( info.isDir() ) { addDir( fi, TRUE ); break; } else if( info.isFile() ) { addFile( fi, TRUE ); break; } else if( info.isSymLink() ) { file = createNewPath(info.dirPath(true ),info.readLink()); break; } else if( i == 4) { // couldn't resolve symlink add it as symlink addSymlink( fi ); } } // off for loop for symlink resolving } else if( fi->isDir() ) addDir( fi ); else if( fi->isFile() ) addFile( fi ); ++it; } // of while loop m_view->sort(); } int OFileViewFileListView::fileCount()const { return m_view->childCount(); } QString OFileViewFileListView::currentDir()const { return m_currentDir; } OFileSelector* OFileViewFileListView::selector() { return m_sel; } bool OFileViewFileListView::eventFilter (QObject *, QEvent *e) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *k = (QKeyEvent *)e; if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0); return true; } } return false; } void OFileViewFileListView::connectSlots() { connect(m_view, SIGNAL(clicked(QListViewItem*) ), this, SLOT(slotCurrentChanged(QListViewItem*) ) ); connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ), this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) ); } void OFileViewFileListView::slotCurrentChanged( QListViewItem* item) { if (!item) return; #if 0 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); if (!sel->isDir() ) { selector()->m_lneEdit->setText( sel->text(1) ); // if in fileselector mode we will emit selected if ( selector()->mode() == OFileSelector::FileSelector ) { odebug << "slot Current Changed" << oendl; QStringList str = QStringList::split("->", sel->text(1) ); QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); emit selector()->fileSelected( path ); DocLnk lnk( path ); emit selector()->fileSelected( lnk ); } } #endif } void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int ) { if (!item || ( button != Qt::LeftButton) ) return; OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item); if (!sel->isLocked() ) { QStringList str = QStringList::split("->", sel->text(1) ); if (sel->isDir() ) { m_currentDir = createNewPath(sel->directory(),str[0].stripWhiteSpace()); emit selector()->dirSelected( m_currentDir ); reread( m_all ); } else { // file odebug << "slot Clicked" << oendl; selector()->m_lneEdit->setText( str[0].stripWhiteSpace() ); QString path = createNewPath(sel->directory(),str[0].stripWhiteSpace()); emit selector()->fileSelected( path ); DocLnk lnk( path ); emit selector()->fileSelected( lnk ); } } // not locked } void OFileViewFileListView::addFile( QFileInfo* info, bool symlink ) { MimeType type( info->absFilePath() ); if (!compliesMime( type.id() ) ) return; QPixmap pix = type.pixmap(); QString dir, name; bool locked; if ( pix.isNull() ) { QWMatrix matrix; - QPixmap pixer(Resource::loadPixmap("UnknownDocument") ); + QPixmap pixer( Opie::Core::OResource::loadPixmap( "UnknownDocument" ) ); matrix.scale( .4, .4 ); pix = pixer.xForm( matrix ); } dir = info->dirPath( true ); locked = false; if ( symlink ) name = info->fileName() + " -> " + createNewPath(info->dirPath(),info->readLink()); else { name = info->fileName(); if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) || ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) ) { - locked = true; pix = Resource::loadPixmap("locked"); + locked = true; + pix = Opie::Core::OResource::loadPixmap( "locked" ); } } (void)new OFileSelectorItem( m_view, pix, name, info->lastModified().toString(), QString::number( info->size() ), dir, locked ); } void OFileViewFileListView::addDir( QFileInfo* info, bool symlink ) { bool locked = false; QString name; QPixmap pix; if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) || ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) ) { locked = true; if ( symlink ) - pix = Resource::loadPixmap( "opie/symlink" ); + pix = Opie::Core::OResource::loadPixmap( "opie/symlink" ); else - pix = Resource::loadPixmap( "lockedfolder" ); + pix = Opie::Core::OResource::loadPixmap( "lockedfolder" ); } else - pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder"); + pix = symlink ? Opie::Core::OResource::loadPixmap( "opie/symlink" ) : Opie::Core::OResource::loadPixmap( "folder" ); name = symlink ? info->fileName() + " -> " + createNewPath(info->dirPath(true),info->readLink()) : info->fileName(); (void)new OFileSelectorItem( m_view, pix, name, info->lastModified().toString(), QString::number( info->size() ), info->dirPath( true ), locked, true ); } void OFileViewFileListView::addSymlink( QFileInfo* , bool ) { } void OFileViewFileListView::cdUP() { QDir dir( m_currentDir ); dir.cdUp(); if (!dir.exists() ) m_currentDir = "/"; else m_currentDir = dir.absPath(); emit selector()->dirSelected( m_currentDir ); reread( m_all ); } void OFileViewFileListView::cdHome() { m_currentDir = QDir::homeDirPath(); emit selector()->dirSelected( m_currentDir ); reread( m_all ); } void OFileViewFileListView::cdDoc() { m_currentDir = QPEApplication::documentDir(); emit selector()->dirSelected( m_currentDir ); reread( m_all ); } void OFileViewFileListView::changeDir( const QString& dir ) { m_currentDir = dir; emit selector()->dirSelected( m_currentDir ); reread( m_all ); } void OFileViewFileListView::slotFSActivated( int id ) { changeDir ( m_dev[m_fsPop->text(id)] ); } /* check if the mimetype in mime * complies with the one which is current */ /* * We've the mimetype of the file * We need to get the stringlist of the current mimetype * * mime = image@slashjpeg * QStringList = 'image@slash*' * or QStringList = image/jpeg;image/png;application/x-ogg * or QStringList = application/x-ogg;image@slash*; * with all these mime filters it should get acceptes * to do so we need to look if mime is contained inside * the stringlist * if it's contained return true * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*' * is contained in the mimefilter and then we will * look if both are equal until the '/' */ bool OFileViewFileListView::compliesMime( const QString& str) { if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() ) return true; for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it ) { QRegExp reg( (*it) ); reg.setWildcard( true ); if ( str.find( reg ) != -1 ) return true; } return false; } /* * The listView giving access to the file system! */ class OFileViewFileSystem : public OFileViewInterface { public: OFileViewFileSystem( OFileSelector* ); ~OFileViewFileSystem(); QString selectedName() const; QString selectedPath() const; QString directory()const; void reread(); int fileCount()const; QWidget* widget( QWidget* parent ); void activate( const QString& ); private: OFileViewFileListView* m_view; bool m_all : 1; }; OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel) : OFileViewInterface( sel ) { m_view = 0; m_all = false; } OFileViewFileSystem::~OFileViewFileSystem() { } QString OFileViewFileSystem::selectedName()const { if (!m_view ) return QString::null; QString cFN=currentFileName(); if (cFN.startsWith("/")) return cFN; return createNewPath(m_view->currentDir(),cFN); } QString OFileViewFileSystem::selectedPath()const { return QString::null; } QString OFileViewFileSystem::directory()const { if (!m_view) return QString::null; OFileSelectorItem* item = m_view->currentItem(); if (!item ) return QString::null; return QDir(item->directory() ).absPath(); } void OFileViewFileSystem::reread() { if (!m_view) return; m_view->reread( m_all ); } int OFileViewFileSystem::fileCount()const { if (!m_view ) return -1; return m_view->fileCount(); } QWidget* OFileViewFileSystem::widget( QWidget* parent ) { if (!m_view ) { m_view = new OFileViewFileListView( parent, startDirectory(), selector() ); } return m_view; } void OFileViewFileSystem::activate( const QString& str ) { m_all = allItem( str ); } } /* Selector */ /** * @short new and complete c'tor * * Create a OFileSelector to let the user select a file. It can * either be used to open a file, select a save name in a dir or * as a dropin for the FileSelector. * * <pre> * QMap<QString, QStringList> mimeTypes; * QStringList types; * types << "text@slash* "; * types << "audio@slash*"; * mimeTypes.insert( tr("Audio and Text"), types ); * mimeTypes.insert( tr("All"), "*@slash*); * * now you could create your fileselector * </pre> * * * @param parent the parent of this widget * @param mode The mode from the enum Mode (Open,Save,FILESELECTOR) * @param sel The selector to be used * @param dirName The name of the dir to start int * @param fileName The fileName placed in the fileselector lineedit * @param mimetypes The MimeType map of used mimetypes * @param showNew Show a New Button. Most likely to be used in the FileSelector view. * @param showClose Show a Close Button. Most likely to be used in FileSelector view. * */ OFileSelector::OFileSelector( QWidget* parent, int mode, int sel, const QString& dirName, const QString& fileName, const MimeTypes& mimetypes, bool showNew, bool showClose) :QWidget( parent, "OFileSelector" ) { m_current = 0; m_shNew = showNew; m_shClose = showClose; m_mimeType = mimetypes; m_startDir = dirName; m_mode = mode; m_selector = sel; m_allList = QStringList(); initUI(); m_lneEdit->setText( fileName ); initMime(); initViews(); QString str; switch ( m_selector ) { default: case Normal: if ( m_mode == DIRECTORYSELECTOR ) str = QObject::tr("Directories"); else str = QObject::tr("Documents"); m_cmbView->setCurrentItem( 0 ); break; case Extended: if ( m_mode == DIRECTORYSELECTOR ) { str = QObject::tr("Directories"); m_cmbView->setCurrentItem( 0 ); } else { str = QObject::tr("Files"); m_cmbView->setCurrentItem( 1 ); } break; case ExtendedAll: if ( m_mode == DIRECTORYSELECTOR ) { str = QObject::tr("All Directories"); m_cmbView->setCurrentItem( 1 ); } else { str = QObject::tr("All Files"); m_cmbView->setCurrentItem( 2 ); } break; } slotViewChange( str ); } /** * This a convience c'tor to just substitute the use of FileSelector */ OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name, bool showNew, bool showClose ) : QWidget( parent, name ) { m_current = 0; m_shNew = showNew; m_shClose = showClose; m_startDir = QPEApplication::documentDir(); if (!mimeFilter.isEmpty() ) m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) ); m_mode = OFileSelector::FileSelector; m_selector = OFileSelector::Normal; initUI(); initMime(); initViews(); m_cmbView->setCurrentItem( 0 ); slotViewChange( QObject::tr("Documents") ); } /* * INIT UI will set up the basic GUI * Layout: Simple VBoxLayout * On top a WidgetStack containing the Views... * - List View * - Document View * Below we will have a Label + LineEdit * Below we will have two ComoBoxes one for choosing the view one for * choosing the mimetype */ void OFileSelector::initUI() { QVBoxLayout* lay = new QVBoxLayout( this ); m_stack = new QWidgetStack( this ); lay->addWidget( m_stack, 1000 ); m_nameBox = new QHBox( this ); (void)new QLabel( tr("Name:"), m_nameBox ); m_lneEdit = new QLineEdit( m_nameBox ); m_lneEdit ->installEventFilter(this); lay->addWidget( m_nameBox ); m_cmbBox = new QHBox( this ); m_cmbView = new QComboBox( m_cmbBox ); m_cmbMime = new QComboBox( m_cmbBox ); lay->addWidget( m_cmbBox ); } /* * This will make sure that the return key in the name edit causes dialogs to close */ bool OFileSelector::eventFilter (QObject *, QEvent *e) { if ( e->type() == QEvent::KeyPress ) { QKeyEvent *k = (QKeyEvent *)e; if ( (k->key()==Key_Enter) || (k->key()==Key_Return)) { emit ok(); return true; } } return false; } /* * This will insert the MimeTypes into the Combo Box * And also connect the changed signal * * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes */ void OFileSelector::initMime() { MimeTypes::Iterator it; for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it ) { m_cmbMime->insertItem( it.key() ); } m_cmbMime->setCurrentItem( 0 ); connect( m_cmbMime, SIGNAL(activated(int) ), this, SLOT(slotMimeTypeChanged() ) ); } void OFileSelector::initViews() { if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) { m_cmbView->insertItem( QObject::tr("Directories") ); m_cmbView->insertItem( QObject::tr("All Directories") ); } else { m_cmbView->insertItem( QObject::tr("Documents") ); m_cmbView->insertItem( QObject::tr("Files") ); m_cmbView->insertItem( QObject::tr("All Files") ); } connect(m_cmbView, SIGNAL(activated(const QString&) ), this, SLOT(slotViewChange(const QString&) ) ); /* see above why add both */ OFileViewInterface* in = new OFileViewFileSystem( this ); if ( m_mode == OFileSelector::DIRECTORYSELECTOR ) { m_views.insert( QObject::tr("Directories"), in ); m_views.insert( QObject::tr("All Directories"), in ); m_allList.append( QObject::tr("All Directories") ); } else { m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) ); m_views.insert( QObject::tr("Files"), in ); m_views.insert( QObject::tr("All Files"), in ); m_allList.append( QObject::tr("All Files") ); } } void OFileSelector::registerView( const Internal::OFileViewInterface* iface ) { m_viewsPtr.append( iface ); } /** * d'tor */ OFileSelector::~OFileSelector() { m_viewsPtr.setAutoDelete( true ); m_viewsPtr.clear(); } /** * Convience function for the fileselector * make sure to delete the DocLnk * * @see DocLnk * @todo remove in ODP */ const DocLnk* OFileSelector::selected() { DocLnk* lnk = new DocLnk( currentView()->selectedDocument() ); return lnk; } /** * * @return the name of the selected file */ QString OFileSelector::selectedName()const { return currentView()->selectedName(); } /** * @return the selected path */ QString OFileSelector::selectedPath()const { return currentView()->selectedPath(); } /** * @return the directory name */ QString OFileSelector::directory()const { return currentView()->directory(); } /** * @return a DocLnk for the selected document */ DocLnk OFileSelector::selectedDocument()const { return currentView()->selectedDocument(); } /** * @return the number of items for the current view */ int OFileSelector::fileCount()const { return currentView()->fileCount(); } /** * @return reparse the file content */ void OFileSelector::reread() { return currentView()->reread(); } OFileViewInterface* OFileSelector::currentView()const { return m_current; } bool OFileSelector::showNew()const { return m_shNew; } bool OFileSelector::showClose()const { return m_shClose; } MimeTypes OFileSelector::mimeTypes()const { return m_mimeType; } /** * @return the Mode of the OFileSelector */ int OFileSelector::mode()const { return m_mode; } /** * @return the Selector of the OFileSelector */ int OFileSelector::selector()const { return m_selector; } QStringList OFileSelector::currentMimeType()const { return m_mimeType[m_cmbMime->currentText()]; } void OFileSelector::slotMimeTypeChanged() { reread(); } void OFileSelector::slotDocLnkBridge( const DocLnk& lnk) { m_lneEdit->setText( lnk.name() ); emit fileSelected( lnk ); emit fileSelected( lnk.name() ); } void OFileSelector::slotFileBridge( const QString& str) { DocLnk lnk( str ); emit fileSelected( lnk ); } void OFileSelector::slotViewChange( const QString& view ) { OFileViewInterface* interface = m_views[view]; if (!interface) return; if (m_current) m_stack->removeWidget( m_current->widget( m_stack ) ); static int id = 1; m_stack->addWidget( interface->widget(m_stack), id ); m_stack->raiseWidget( id ); interface->activate( view ); interface->reread(); m_current = interface; id++; } void OFileSelector::setNewVisible( bool b ) { m_shNew = b; currentView()->reread(); } void OFileSelector::setCloseVisible( bool b ) { m_shClose = b; currentView()->reread(); } void OFileSelector::setNameVisible( bool b ) { if ( b ) m_nameBox->show(); else m_nameBox->hide(); } } } diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h index d166afd..f32e3ed 100644 --- a/libopie2/opieui/fileselector/ofileselector.h +++ b/libopie2/opieui/fileselector/ofileselector.h @@ -1,235 +1,237 @@ /* - =. This file is part of the OPIE Project - .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@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. +         This file is part of the Opie Project + + Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org> + =. + .=l. +      .>+-= + _;:,   .>   :=|. This program 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 program 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. - */ /* This is based on code and ideas of L. J. Potter ljp@llornkcor.com Thanks a lot */ #ifndef OFILESELECTOR_H #define OFILESELECTOR_H /* OPIE */ #include <qpe/applnk.h> /* QT */ #include <qlist.h> #include <qwidget.h> #include <qmap.h> #include <qvaluelist.h> #include <qstringlist.h> #include <qlist.h> class QLineEdit; class QComboBox; class QWidgetStack; class QHBox; typedef QMap<QString, QStringList> MimeTypes; namespace Opie { namespace Ui { namespace Internal { class OFileViewInterface; class OFileViewFileListView; } /** * @short a dropin replacement for the FileSelector * * This class is first used insert the OFileDialog. * It supports multiple view and mimetype filtering for now. * * @see OFileDialog * @see FileSelector * @author zecke * @version 0.1 */ class OFileSelector : public QWidget { Q_OBJECT friend class Internal::OFileViewInterface; friend class Internal::OFileViewFileListView; public: /** * The Mode of the Fileselector * Open = Open A File * Save = Save a File * FILESELECTOR = As A GUI in a screen to select a file * SelectDir = Select a Directory */ enum Mode { Open = 1, Save = 2, DirectorySelector = 3, FileSelector = 4, OPEN = 1, SAVE = 2, DIRECTORYSELECTOR = 3, FILESELECTOR = 4 }; // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 }; /** * Normal = The old FileSelector * Extended = Dir View * ExtendedAll = Dir View with all hidden files * Default = What the vendor considers best */ enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 }; // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2}; OFileSelector(QWidget* parent, int mode, int selector, const QString& dirName, const QString& fileName, const MimeTypes& mimetypes = MimeTypes(), bool newVisible = FALSE, bool closeVisible = FALSE ); OFileSelector(const QString& mimeFilter, QWidget* parent, const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE ); ~OFileSelector(); const DocLnk* selected(); QString selectedName()const; QString selectedPath()const; QString directory()const; DocLnk selectedDocument()const; int fileCount()const; void reread(); int mode()const; int selector()const; /** * Set the Icon visible * @param b Show or Hide the New Button */ void setNewVisible( bool b ); /** * Set the Icon visible */ void setCloseVisible( bool b ); /** * Set the Name Line visible */ void setNameVisible( bool b ); signals: /** * dirSelected is emitted whenever changed into a different dir */ void dirSelected( const QString& ); /** * fileSelected is emitted when a file is selected * it uses a DocLnk as parameter */ void fileSelected( const DocLnk& ); /** * fileSelected is emitted when a file is selected * the complete path is a parameter */ void fileSelected( const QString& ); /** * Create a new File with a DocLnk */ void newSelected( const DocLnk& ); void closeMe(); /** * Ok is emitted on a Qt::Key_Return or Q::Key_Enter * in the line edit */ void ok(); void cancel(); /* used by the ViewInterface */ private: bool showNew()const; bool showClose()const; MimeTypes mimeTypes()const; QStringList currentMimeType()const; private: /* inits the Widgets */ void initUI(); /* inits the MimeType ComboBox content + connects signals and slots */ void initMime(); /* init the Views :) */ void initViews(); /* * register a view for deletion. * This happens on creation of a OFileViewInterface */ void registerView( const Internal::OFileViewInterface* ); private: QLineEdit* m_lneEdit; // the LineEdit for the Name QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType QWidgetStack* m_stack; // our widget stack which will contain the views Internal::OFileViewInterface* currentView() const; // returns the currentView Internal::OFileViewInterface* m_current; // here is the view saved bool m_shNew : 1; // should we show New? bool m_shClose : 1; // should we show Close? MimeTypes m_mimeType; // list of mimetypes QMap<QString, Internal::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr /* views register themselves automatically */ QList<Internal::OFileViewInterface> m_viewsPtr; QHBox* m_nameBox; // the LineEdit + Label is hold here QHBox* m_cmbBox; // this holds the two combo boxes QString m_startDir; int m_mode; int m_selector; QStringList m_allList; struct Data; // used for future versions Data *d; private slots: void slotMimeTypeChanged(); /* will set the text of the lineedit and emit a fileChanged signal */ void slotDocLnkBridge( const DocLnk& ); void slotFileBridge( const QString& ); void slotViewChange( const QString& ); bool eventFilter (QObject *o, QEvent *e); }; } } #endif diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp index 8d7806c..7333f5e 100644 --- a/libopie2/opieui/otabwidget.cpp +++ b/libopie2/opieui/otabwidget.cpp @@ -1,482 +1,476 @@ /* - This file is part of the Opie Project +         This file is part of the Opie Project - Copyright (c) 2002, 2005 Dan Williams <drw@handhelds.org> + Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org> =. .=l. - .>+-= -_;:, .> :=|. This program 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 program 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. +      .>+-= + _;:,   .>   :=|. This program 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 program 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 <opie2/otabwidget.h> /* OPIE */ +#include <opie2/oresource.h> +#include <opie2/otabbar.h> + #include <qpe/applnk.h> #include <qpe/config.h> -#include <qpe/resource.h> -#include <opie2/otabbar.h> /* QT */ #include <qcombobox.h> #include <qwidgetstack.h> using namespace Opie::Ui; OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p ) : QWidget( parent, name ) , m_currTab( 0l ) , m_tabBarStyle( Global ) , m_tabBarPosition( Top ) , m_usingTabs( true ) , m_tabBar( 0l ) , m_tabList( 0l ) { if ( s == Global ) { // Read Opie global settings for style and position Config config( "qpe" ); config.setGroup( "Appearance" ); // Style s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab ); if ( s <= Global || s > IconList) s = IconTab; // Position ( config.readEntry( "TabPosition", "Top" ) == "Bottom" ) ? p = Bottom : p = Top; } // Initialize widget stack for tab widgets m_widgetStack = new QWidgetStack( this ); m_widgetStack->setFrameStyle( QFrame::NoFrame ); m_widgetStack->setLineWidth( style().defaultFrameWidth() ); // Set initial selector control style and position setTabStyle( s ); setTabPosition( p ); } OTabWidget::~OTabWidget() { m_tabs.setAutoDelete( true ); m_tabs.clear(); } void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label ) { int tabid = -1; if ( m_usingTabs ) { // Create new tab in tab bar QTab *tab = new QTab(); // Set label (and icon if necessary) if ( m_tabBarStyle == IconTab ) { tab->label = QString::null; - tab->iconset = new QIconSet( loadSmooth( icon ) ); + tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ); } else tab->label = label; tabid = m_tabBar->addTab( tab ); } else { // Insert entry (with icon if necessary) into drop down list if ( m_tabBarStyle == IconList ) - m_tabList->insertItem( loadSmooth( icon ), label, -1 ); + m_tabList->insertItem( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ), label, -1 ); else m_tabList->insertItem( label ); } // Add widget to stack m_widgetStack->addWidget( child, tabid ); m_widgetStack->raiseWidget( child ); m_widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised ); // Keep track of tab information OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label ); m_tabs.append( tabinfo ); // Make newly added tab the current one displayed selectTab( tabinfo ); } void OTabWidget::removePage( QWidget *childwidget ) { if ( childwidget ) { // Find tab information for desired widget OTabInfo *tab = m_tabs.first(); while ( tab && tab->control() != childwidget ) tab = m_tabs.next(); if ( tab && tab->control() == childwidget ) { if ( m_usingTabs ) { // Remove tab from tab bar m_tabBar->setTabEnabled( tab->id(), false ); m_tabBar->removeTab( m_tabBar->tab( tab->id() ) ); } else { // Remove entry from drop down list int i = 0; while ( i < m_tabList->count() && m_tabList->text( i ) != tab->label() ) i++; if ( m_tabList->text( i ) == tab->label() ) m_tabList->removeItem( i ); } // Remove widget from stack m_widgetStack->removeWidget( childwidget ); // Get rid of tab information m_tabs.remove( tab ); delete tab; // Reset current tab m_currTab = m_tabs.current(); if ( !m_currTab ) m_widgetStack->setFrameStyle( QFrame::NoFrame ); // Redraw widget setUpLayout(); } } } void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label) { // Find tab information for desired widget OTabInfo *currtab = m_tabs.first(); while ( currtab && currtab->control() != widget ) currtab = m_tabs.next(); if ( currtab && currtab->control() == widget ) { - QPixmap icon( loadSmooth( iconset ) ); + QPixmap icon( Opie::Core::OResource::loadPixmap( iconset, Opie::Core::OResource::SmallIcon ) ); if ( m_usingTabs ) { // Update tab label and icon (if necessary) QTab *tab = m_tabBar->tab( currtab->id() ); tab->setText( label ); if ( m_tabBarStyle == IconTab ) tab->setIconSet( icon ); } else { // Update entry label and icon (if necessary) int i = 0; while ( i < m_tabList->count() && m_tabList->text( i ) != currtab->label() ) i++; if ( i < m_tabList->count() && m_tabList->text( i ) == currtab->label() ) { if ( m_tabBarStyle == IconList ) m_tabList->changeItem( icon, label, i ); else m_tabList->changeItem( label, i ); } } // Update tab information currtab->setLabel( label ); currtab->setIcon( iconset ); // Redraw widget setUpLayout(); } } void OTabWidget::setCurrentTab( QWidget *childwidget ) { OTabInfo *currtab = m_tabs.first(); while ( currtab && currtab->control() != childwidget ) { currtab = m_tabs.next(); } if ( currtab && currtab->control() == childwidget ) { selectTab( currtab ); } } void OTabWidget::setCurrentTab( const QString &tabname ) { OTabInfo *newtab = m_tabs.first(); while ( newtab && newtab->label() != tabname ) { newtab = m_tabs.next(); } if ( newtab && newtab->label() == tabname ) { selectTab( newtab ); } } void OTabWidget::setCurrentTab(int tabindex) { OTabInfo *newtab = m_tabs.first(); while ( newtab && newtab->id() != tabindex ) { newtab = m_tabs.next(); } if ( newtab && newtab->id() == tabindex ) { selectTab( newtab ); } } OTabWidget::TabStyle OTabWidget::tabStyle() const { return m_tabBarStyle; } void OTabWidget::setTabStyle( TabStyle s ) { // Get out if new and current styles are the same if ( s == m_tabBarStyle ) return; // Delete current selector control if ( m_usingTabs ) { delete m_tabBar; m_tabBar = 0l; } else { delete m_tabList; m_tabList = 0l; } // Set new style information m_tabBarStyle = s; m_usingTabs = ( m_tabBarStyle == TextTab || m_tabBarStyle == IconTab ); // Create new selector control and populate with tab information if ( m_usingTabs ) { // Create new tab bar selector m_tabBar = new OTabBar( this ); connect( m_tabBar, SIGNAL(selected(int)), this, SLOT(slotTabBarSelected(int)) ); // Add all current tabs to tab bar for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) { // Create new tab in tab bar QTab *tab = new QTab(); // Set label (and icon if necessary) if ( m_tabBarStyle == IconTab ) { tab->label = QString::null; - tab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) ); + tab->iconset = new QIconSet( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ) ); } else tab->label = tabinfo->label(); // Add tab and save its Id int tabid = m_tabBar->addTab( tab ); tabinfo->setId( tabid ); } } else { // Create new drop down list selector m_tabList = new QComboBox( false, this ); connect( m_tabList, SIGNAL(activated(int)), this, SLOT(slotTabListSelected(int)) ); // Add all current tabs to drop down list for ( OTabInfo *tabinfo = m_tabs.first(); tabinfo; tabinfo = m_tabs.next() ) { if ( m_tabBarStyle == IconList ) - m_tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() ); + m_tabList->insertItem( Opie::Core::OResource::loadPixmap( tabinfo->icon(), Opie::Core::OResource::SmallIcon ), + tabinfo->label() ); else m_tabList->insertItem( tabinfo->label() ); } } // Redraw widget setUpLayout(); } OTabWidget::TabPosition OTabWidget::tabPosition() const { return m_tabBarPosition; } void OTabWidget::setTabPosition( TabPosition p ) { m_tabBarPosition = p; // If using the tab bar selector, set its shape if ( m_usingTabs ) { ( m_tabBarPosition == Top ) ? m_tabBar->setShape( QTabBar::RoundedAbove ) : m_tabBar->setShape( QTabBar::RoundedBelow ); } // Redraw widget setUpLayout(); } void OTabWidget::slotTabBarSelected( int id ) { OTabInfo *newtab = m_tabs.first(); while ( newtab && newtab->id() != id ) newtab = m_tabs.next(); if ( newtab && newtab->id() == id ) selectTab( newtab ); } void OTabWidget::slotTabListSelected( int index ) { OTabInfo *newtab = m_tabs.at( index ); if ( newtab ) selectTab( newtab ); } -QPixmap OTabWidget::loadSmooth( const QString &name ) -{ - QPixmap p; - p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) ); - return p; -} - void OTabWidget::selectTab( OTabInfo *tab ) { if ( m_tabBarStyle == IconTab ) { // Remove text label from currently selected tab if ( m_currTab ) { m_tabBar->tab( m_currTab->id() )->setText( QString::null ); //setUpLayout(); } // Set text label for newly selected tab m_tabBar->tab( tab->id() )->setText( tab->label() ); m_tabBar->setCurrentTab( tab->id() ); setUpLayout(); QSize t; t = m_tabBar->sizeHint(); if ( t.width() > width() ) t.setWidth( width() ); int lw = m_widgetStack->lineWidth(); if ( m_tabBarPosition == Bottom ) m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); else m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); } else if ( m_tabBarStyle == TextTab ) { m_tabBar->setCurrentTab( tab->id() ); } m_widgetStack->raiseWidget( tab->control() ); emit currentChanged( tab->control() ); m_currTab = tab; } void OTabWidget::setUpLayout() { if ( m_usingTabs ) { m_tabBar->update(); m_tabBar->layoutTabs(); } } void OTabWidget::resizeEvent( QResizeEvent * ) { QSize t; if ( m_usingTabs ) { m_tabBar->layoutTabs(); t = m_tabBar->sizeHint(); if ( t.width() > width() ) t.setWidth( width() ); } else { t = m_tabList->sizeHint(); t.setWidth( width() ); } int lw = m_widgetStack->lineWidth(); if ( m_tabBarPosition == Bottom ) { if ( m_usingTabs ) m_tabBar->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); else m_tabList->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() ); m_widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) ); } else { if ( m_usingTabs ) m_tabBar->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); else m_tabList->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() ); m_widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) ); } if ( autoMask() ) updateMask(); } int OTabWidget::currentTab() { if ( m_currTab ) { return m_currTab->id(); } return -1; } QWidget* OTabWidget::currentWidget()const { if ( m_currTab ) { return m_currTab->control(); } return 0; } diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h index e925592..3af8fac 100644 --- a/libopie2/opieui/otabwidget.h +++ b/libopie2/opieui/otabwidget.h @@ -1,287 +1,279 @@ /* - This file is part of the Opie Project +         This file is part of the Opie Project + Copyright (C) 2002, 2005 Dan Williams <drw@handhelds.org> =. .=l. - .>+-= -_;:, .> :=|. This program 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 program 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. +      .>+-= + _;:,   .>   :=|. This program 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 program 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 OTABWIDGET_H #define OTABWIDGET_H /* OPIE */ #include <opie2/otabinfo.h> /* QT */ #include <qwidget.h> #include <qlist.h> class QComboBox; class QPixmap; class QTabBar; class QWidgetStack; namespace Opie { namespace Ui { class OTabBar; /** * @class OTabWidget * @brief The OTabWidget class provides a stack of widgets. * * OTabWidget is a derivation of TrollTech's QTabWidget which provides * a stack of widgets. Widgets can be selected using either a tab bar or * drop down list box. * * The normal way to use OTabWidget is to do the following in the * constructor: * - Create a OTabWidget. * - Create a QWidget for each of the pages in the control, insert * children into it, set up geometry management for it, and use addTab() * to add the widget. */ class OTabWidget : public QWidget { Q_OBJECT public: /** * @enum TabStyle * @brief Defines how the widget selection control is displayed. * * Valid values: * - Global: use globally selected options (qpe.conf - TabStyle & TabPosition) * - TextTab: Tabbed widget selection with text labels * - IconTab: Tabbed widget selection with icon labels, text label for active widget * (similar to Opie launcher) * - TextList: Drop down list widget selection with text labels * - IconList: Drop down list widget selection with icon & text labels */ enum TabStyle { Global, TextTab, IconTab, TextList, IconList }; /** * @enum TabPosition * @brief Defines where the widget selection control is drawn. * * Valid values: * - Top: Widget selection control is drawn above widgets * - Bottom: Widget selection control is drawn below widgets */ enum TabPosition { Top, Bottom }; /** * @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top ) * @brief Object constructor. * * @param parent Pointer to parent of this control. * @param name Name of control. * @param s Style of widget selection control. * @param p Position of the widget selection control. * * Constructs a new OTabWidget control with parent and name. The style and position parameters * determine how the widget selection control will be displayed. */ OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top ); /** * @fn ~OTabWidget() * @brief Object destructor. */ ~OTabWidget(); /** * @fn addTab( QWidget *child, const QString &icon, const QString &label ) * @brief Add new widget to control. * * @param child Widget control. * @param icon Path to icon. * @param label Text label. */ void addTab( QWidget *, const QString &, const QString & ); /** * @fn removePage( QWidget *widget ) * @brief Remove widget from control. Does not delete widget. * * @param widget Widget control to be removed. */ void removePage( QWidget * ); /** * @fn changeTab( QWidget *widget, const QString &icon, const QString &label ) * @brief Change text and/or icon for existing tab * * @param child Widget control. * @param icon Path to icon. * @param label Text label. */ void changeTab( QWidget *, const QString &, const QString & ); /** * @fn tabStyle()const * @brief Returns current widget selection control style. */ TabStyle tabStyle() const; /** * @fn setTabStyle( TabStyle s ) * @brief Set the current widget selection control style. * * @param s New style to be used. */ void setTabStyle( TabStyle ); /** * @fn tabPosition()const * @brief Returns current widget selection control position. */ TabPosition tabPosition() const; /** * @fn setTabPosition( TabPosition p ) * @brief Set the current widget selection control position. * * @param p New position of widget selection control. */ void setTabPosition( TabPosition ); /** * @fn setCurrentTab( QWidget *childwidget ) * @brief Selects and brings to top the desired widget by using widget pointer. * * @param childwidget Widget to select. */ void setCurrentTab( QWidget * ); /** * @fn setCurrentTab( const QString &tabname ) * @brief Selects and brings to top the desired widget, by using label. * * @param tabname Text label for widget to select. */ void setCurrentTab( const QString & ); /** * @fn setCurrentTab( int ) * @brief Selects and brings to top the desired widget, by using id. * * @param tab id for widget to select. */ void setCurrentTab(int); /** * @fn currentTab( ) * @brief returns current tab id. */ // ### make const int currentTab()/* const */; /** * @brief returns the current page of the active tab * * @since 1.2 */ QWidget* currentWidget()const; protected: /** * @fn resizeEvent( QResizeEvent * ) * @brief Reimplemented for internal purposes. */ void resizeEvent( QResizeEvent * ); private: OTabInfoList m_tabs; // List of information for tabs OTabInfo *m_currTab; // Current tab displayed TabStyle m_tabBarStyle; // Current style of control TabPosition m_tabBarPosition; // Position of selector control bool m_usingTabs; // Indicates whether style is either TextTab or IconTab // (saves from having to always check for these 2 values) // UI components OTabBar *m_tabBar; QComboBox *m_tabList; QWidgetStack *m_widgetStack; class Private; Private* d; /** - * @fn loadSmooth( const QString &name ) - * @brief Loads icon for widget. - * - * @param name Name of icon image file. - */ - QPixmap loadSmooth( const QString & ); - -/** * @fn selectTab( OTabInfo *tab ) * @brief Internal function to select desired widget. * * @param tab Pointer to data for widget. */ void selectTab( OTabInfo * ); /** * @fn setUpLayout() * @brief Internal function to adjust layout. */ void setUpLayout(); signals: /** * @fn currentChanged( QWidget *widget ) * @brief This signal is emitted whenever the widget has changed. * * @param widget Pointer to new current widget. */ void currentChanged( QWidget * ); private slots: /** * @fn slotTabBarSelected( int id ) * @brief Slot which is called when a tab is selected. * * @param id ID of widget selected. */ void slotTabBarSelected( int ); /** * @fn slotTabListSelected( int index ) * @brief Slot which is called when a drop down selection is made. * * @param id Index of widget selected. */ void slotTabListSelected( int ); }; } } #endif diff --git a/libopie2/opieui/owait.cpp b/libopie2/opieui/owait.cpp index ec1f25a..5f89ad2 100644 --- a/libopie2/opieui/owait.cpp +++ b/libopie2/opieui/owait.cpp @@ -1,113 +1,115 @@ /* - This file is part of the Opie Project - Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> +         This file is part of the Opie Project + + Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> =. .=l. - .>+-= - _;:, .> :=|. This program 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 program 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. +      .>+-= + _;:,   .>   :=|. This program 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 program 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 "owait.h" /* OPIE */ +#include <opie2/oresource.h> + + #include <qpe/qpeapplication.h> -#include <qpe/resource.h> /* QT */ #include <qlayout.h> #include <qpainter.h> using namespace Opie::Ui; static int frame = 0; /** * This will construct a modal dialog. * * The default timer length is 10. * * @param parent The parent of the widget * @param msg The name of the object * @param dispIcon Display Icon? */ OWait::OWait( QWidget *parent, const char* msg, bool dispIcon ) :QDialog( parent, msg, TRUE, WStyle_Customize ) { Q_UNUSED( dispIcon ) QHBoxLayout * hbox = new QHBoxLayout( this ); m_lb = new QLabel( this ); m_lb->setBackgroundMode ( NoBackground ); hbox->addWidget( m_lb ); hbox->activate(); - m_pix = Resource::loadPixmap( "BigBusy" ); + m_pix = Opie::Core::OResource::loadPixmap( "BigBusy" ); m_aniSize = m_pix.height(); resize( m_aniSize, m_aniSize ); m_timerLength = 10; m_waitTimer = new QTimer( this ); connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) ); } void OWait::timerEvent( QTimerEvent * ) { frame = ( ++frame ) % 4; repaint(); } void OWait::paintEvent( QPaintEvent * ) { QPainter p( m_lb ); p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize ); } void OWait::show() { move( ( ( qApp->desktop() ->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop() ->height() ) / 2 ) - ( m_aniSize / 2 ) ); startTimer( 300 ); m_waitTimer->start( m_timerLength * 1000, true ); QDialog::show(); } void OWait::hide() { killTimers(); m_waitTimer->stop(); frame = 0; QDialog::hide(); } void OWait::setTimerLength( int length ) { m_timerLength = length; } OWait::~OWait() {} diff --git a/libopie2/opieui/owait.h b/libopie2/opieui/owait.h index 03c33e4..0036bb1 100644 --- a/libopie2/opieui/owait.h +++ b/libopie2/opieui/owait.h @@ -1,90 +1,89 @@ /* - This file is part of the Opie Project - Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> +         This file is part of the Opie Project + + Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org> =. .=l. - .>+-= - _;:, .> :=|. This program 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 program 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. +      .>+-= + _;:,   .>   :=|. This program 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 program 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 OWAIT_H #define OWAIT_H /* QT */ #include <qdialog.h> #include <qlabel.h> #include <qpixmap.h> #include <qtimer.h> namespace Opie { namespace Ui { /** * This class displays a animated waiting icon in the middle of the screen. * * @short modal hour glass dialog * @see QDialog - * @author Maximilian Reiß - */ + * @author Maximilian Rei� */ class OWait : public QDialog { Q_OBJECT public: OWait( QWidget *parent = 0, const char* name = 0, bool dispIcon = TRUE ); ~OWait(); /** * reimplemented for control reasons */ void show(); /** * Set the time before the icon will be automaticly hidden * The timer will be started once the widget will be shown. * @param length - time in seconds */ void setTimerLength( int length ); public slots: /** * reimplemented for control reasons */ void hide(); private: void timerEvent( QTimerEvent * ); void paintEvent( QPaintEvent * ); QPixmap m_pix; QLabel *m_lb; QTimer *m_waitTimer; int m_timerLength; int m_aniSize; class Private; Private *d; }; } } #endif |