summaryrefslogtreecommitdiff
path: root/core/launcher/launcherview.cpp
authorsandman <sandman>2002-10-01 22:44:28 (UTC)
committer sandman <sandman>2002-10-01 22:44:28 (UTC)
commit8f904d99e7b6e04b6043226a63f6c417171a7cad (patch) (side-by-side diff)
tree07d5f2b7e1338cf1035fe92436328a9c74208b03 /core/launcher/launcherview.cpp
parent895280b5ff189fff2e77d6f5f27668e7dad0d88d (diff)
downloadopie-8f904d99e7b6e04b6043226a63f6c417171a7cad.zip
opie-8f904d99e7b6e04b6043226a63f6c417171a7cad.tar.gz
opie-8f904d99e7b6e04b6043226a63f6c417171a7cad.tar.bz2
busyindicator type can now be changed at run-time
Diffstat (limited to 'core/launcher/launcherview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--core/launcher/launcherview.cpp23
1 files changed, 21 insertions, 2 deletions
diff --git a/core/launcher/launcherview.cpp b/core/launcher/launcherview.cpp
index e15b150..fa46543 100644
--- a/core/launcher/launcherview.cpp
+++ b/core/launcher/launcherview.cpp
@@ -7,186 +7,196 @@
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "launcherview.h"
#include <qpe/qpeapplication.h>
#include <qpe/applnk.h>
#include <qpe/qpedebug.h>
#include <qpe/categories.h>
#include <qpe/categoryselect.h>
#include <qpe/menubutton.h>
#include <qpe/mimetype.h>
#include <qpe/resource.h>
#include <qpe/qpetoolbar.h>
//#include <qtopia/private/palmtoprecord.h>
#include <qtimer.h>
#include <qtextstream.h>
#include <qdict.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qhbox.h>
#include <qiconview.h>
#include <qpainter.h>
#include <qregexp.h>
#include <qtoolbutton.h>
#include <qimage.h>
class BgPixmap
{
public:
BgPixmap( const QPixmap &p ) : pm(p), ref(1) {}
QPixmap pm;
int ref;
};
+enum BusyIndicatorType {
+ BIT_Normal = 0,
+ BIT_Blinking
+};
+
static QMap<QString,BgPixmap*> *bgCache = 0;
class LauncherIconView : public QIconView {
public:
LauncherIconView( QWidget* parent, const char* name=0 ) :
QIconView(parent,name),
tf(""),
cf(0),
bsy(0),
bigIcns(TRUE),
bgColor(white)
{
sortmeth = Name;
hidden.setAutoDelete(TRUE);
ike = FALSE;
busytimer = 0;
calculateGrid( Bottom );
}
~LauncherIconView()
{
#if 0 // debuggery
QListIterator<AppLnk> it(hidden);
AppLnk* l;
while ((l=it.current())) {
++it;
//qDebug("%p: hidden (should remove)",l);
}
#endif
}
+ void setBusyIndicatorType ( BusyIndicatorType t ) { busyType = t; }
+
QPixmap* busyPixmap() const { return (QPixmap*)&bpm[::abs(busystate)]; }
QIconViewItem* busyItem() const { return bsy; }
void setBigIcons( bool bi ) { bigIcns = bi; }
void updateCategoriesAndMimeTypes();
void doAutoScroll()
{
// We don't want rubberbanding (yet)
}
void setBusy(bool on)
{
QIconViewItem *c = on ? currentItem() : 0;
- qDebug ( "set busy %d -> %s", on, c ? c-> text ().latin1() : "(null)" );
if ( bsy != c ) {
QIconViewItem *oldbsy = bsy;
bsy = c;
if ( oldbsy )
oldbsy-> repaint ( );
if ( bsy ) {
QPixmap *src = bsy-> QIconViewItem::pixmap();
for ( int i = 0; i <= 5; i++ ) {
QImage img = src->convertToImage();
QRgb* rgb;
int count;
if ( img.depth() == 32 ) {
rgb = (QRgb*)img.bits();
count = img.bytesPerLine()/sizeof(QRgb)*img.height();
} else {
rgb = img.colorTable();
count = img.numColors();
}
int rc, gc, bc;
int bs = ::abs ( i * 10 ) + 25;
colorGroup().highlight().rgb( &rc, &gc, &bc );
rc = rc * bs / 100;
gc = gc * bs / 100;
bc = bc * bs / 100;
for ( int r = 0; r < count; r++, rgb++ ) {
int ri = rc + qRed ( *rgb ) * ( 100 - bs ) / 100;
int gi = gc + qGreen ( *rgb ) * ( 100 - bs ) / 100;
int bi = bc + qBlue ( *rgb ) * ( 100 - bs ) / 100;
int ai = qAlpha ( *rgb );
*rgb = qRgba ( ri, gi, bi, ai );
}
bpm [i].convertFromImage( img );
}
+ if ( busyType == BIT_Blinking ) {
busystate = 0;
if ( busytimer )
killTimer ( busytimer );
- timerEvent ( 0 );
busytimer = startTimer ( 200 );
}
+ else
+ busystate = 3;
+ timerEvent ( 0 );
+ }
else {
killTimer ( busytimer );
busytimer = 0;
}
}
}
virtual void timerEvent ( QTimerEvent *te )
{
if ( !te || ( te-> timerId ( ) == busytimer )) {
if ( bsy ) {
busystate++;
if ( busystate > 5 )
busystate = -4;
QScrollView::updateContents ( bsy-> pixmapRect ( false ));
}
}
}
bool inKeyEvent() const { return ike; }
void keyPressEvent(QKeyEvent* e)
{
ike = TRUE;
if ( e->key() == Key_F33 /* OK button */ || e->key() == Key_Space )
returnPressed(currentItem());
QIconView::keyPressEvent(e);
ike = FALSE;
}
void addItem(AppLnk* app, bool resort=TRUE);
bool removeLink(const QString& linkfile);
QStringList mimeTypes() const;
QStringList categories() const;
void clear()
{
mimes.clear();
cats.clear();
QIconView::clear();
hidden.clear();
}
void addCatsAndMimes(AppLnk* app)
{
// QStringList c = app->categories();
// for (QStringList::ConstIterator cit=c.begin(); cit!=c.end(); ++cit) {
@@ -292,96 +302,97 @@ public:
protected:
void styleChange( QStyle &old )
{
QIconView::styleChange( old );
calculateGrid( itemTextPos() );
}
void calculateGrid( ItemTextPos pos )
{
int dw = QApplication::desktop()->width();
int viewerWidth = dw-style().scrollBarExtent().width();
if ( pos == Bottom ) {
int cols = 3;
if ( viewerWidth <= 200 )
cols = 2;
else if ( viewerWidth >= 400 )
cols = viewerWidth/96;
setSpacing( 4 );
setGridX( (viewerWidth-(cols+1)*spacing())/cols );
setGridY( fontMetrics().height()*2+24 );
} else {
int cols = 2;
if ( viewerWidth < 150 )
cols = 1;
else if ( viewerWidth >= 400 )
cols = viewerWidth/150;
setSpacing( 2 );
setGridX( (viewerWidth-(cols+1)*spacing())/cols );
setGridY( fontMetrics().height()+2 );
}
}
private:
QList<AppLnk> hidden;
QDict<void> mimes;
QDict<void> cats;
SortMethod sortmeth;
QRegExp tf;
int cf;
QIconViewItem* bsy;
bool ike;
bool bigIcns;
QPixmap bgPixmap;
QPixmap bpm [6];
QColor bgColor;
int busytimer;
int busystate;
+ BusyIndicatorType busyType;
};
bool LauncherView::bsy=FALSE;
void LauncherView::setBusy(bool on)
{
icons->setBusy(on);
}
class LauncherItem : public QIconViewItem
{
public:
LauncherItem( QIconView *parent, AppLnk* applnk, bool bigIcon=TRUE );
~LauncherItem()
{
LauncherIconView* liv = (LauncherIconView*)iconView();
if ( liv->busyItem() == this )
liv->setBusy(FALSE);
delete app;
}
AppLnk* appLnk() const { return app; }
AppLnk* takeAppLnk() { AppLnk* r=app; app=0; return r; }
virtual int compare ( QIconViewItem * i ) const;
void paintItem( QPainter *p, const QColorGroup &cg )
{
LauncherIconView* liv = (LauncherIconView*)iconView();
QBrush oldBrush( liv->itemTextBackground() );
QColorGroup mycg( cg );
if ( liv->currentItem() == this ) {
liv->setItemTextBackground( cg.brush( QColorGroup::Highlight ) );
mycg.setColor( QColorGroup::Text, cg.color( QColorGroup::HighlightedText ) );
}
QIconViewItem::paintItem(p,mycg);
if ( liv->currentItem() == this )
liv->setItemTextBackground( oldBrush );
}
virtual QPixmap* pixmap () const
{
const LauncherIconView* liv = (LauncherIconView*)iconView();
if ( (const LauncherItem *)liv->busyItem() == this )
return liv->busyPixmap();
return QIconViewItem::pixmap();
}
@@ -868,48 +879,56 @@ void LauncherView::internalPopulate( AppLnkSet *folder, const QString& typefilte
icons->setTypeFilter(typefilter,FALSE);
while ( it.current() ) {
// show only the icons for existing files
if (QFile(it.current()->file()).exists() || ( it.current()->file().left(4) == "http" )) {
icons->addItem(*it,FALSE);
}
else {
//maybe insert some .desktop file deletion code later
//maybe dir specific
}
++it;
}
icons->sort();
}
bool LauncherView::removeLink(const QString& linkfile)
{
return icons->removeLink(linkfile);
}
void LauncherView::sort()
{
icons->sort();
}
void LauncherView::addItem(AppLnk* app, bool resort)
{
icons->addItem(app,resort);
}
void LauncherView::setFileSystems(const QList<FileSystem> &)
{
// ### does nothing now...
}
void LauncherView::paletteChange( const QPalette &p )
{
icons->unsetPalette();
QVBox::paletteChange( p );
if ( bgType == Ruled )
setBackgroundType( Ruled, QString::null );
QColorGroup cg = icons->colorGroup();
cg.setColor( QColorGroup::Text, textCol );
icons->setPalette( QPalette(cg,cg,cg) );
}
+
+void LauncherView::setBusyIndicatorType ( const QString &type )
+{
+ if ( type. lower ( ) == "blink" )
+ icons-> setBusyIndicatorType ( BIT_Blinking );
+ else
+ icons-> setBusyIndicatorType ( BIT_Normal );
+}