-rw-r--r-- | library/config.cpp | 12 | ||||
-rw-r--r-- | library/config.h | 3 | ||||
-rw-r--r-- | library/datebookmonth.cpp | 12 | ||||
-rw-r--r-- | library/datebookmonth.h | 15 | ||||
-rw-r--r-- | library/qpemenubar.cpp | 9 | ||||
-rw-r--r-- | library/qpemenubar.h | 7 |
6 files changed, 58 insertions, 0 deletions
diff --git a/library/config.cpp b/library/config.cpp index 1121cd4..b47c620 100644 --- a/library/config.cpp +++ b/library/config.cpp @@ -1,558 +1,570 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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 <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qmessagebox.h> #if QT_VERSION <= 230 && defined(QT_NO_CODECS) #include <qtextcodec.h> #endif #include <qtextstream.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #define QTOPIA_INTERNAL_LANGLIST #include "config.h" #include "global.h" /*! \internal */ QString Config::configFilename(const QString& name, Domain d) { switch (d) { case File: return name; case User: { QDir dir = (QString(getenv("HOME")) + "/Settings"); if ( !dir.exists() ) mkdir(dir.path().local8Bit(),0700); return dir.path() + "/" + name + ".conf"; } } return name; } /*! \class Config config.h \brief The Config class provides for saving application cofniguration state. You should keep a Config in existence only while you do not want others to be able to change the state. There is no locking currently, but there may be in the future. */ /*! \enum Config::ConfigGroup \internal */ /*! \enum Config::Domain \value File \value User See Config for details. */ /*! Constructs a config that will load or create a configuration with the given \a name in the given \a domain. You must call setGroup() before doing much else with the Config. In the default Domain, \e User, the configuration is user-specific. \a name should not contain "/" in this case, and in general should be the name of the C++ class that is primarily responsible for maintaining the configuration. In the File Domain, \a name is an absolute filename. */ Config::Config( const QString &name, Domain domain ) : filename( configFilename(name,domain) ) { git = groups.end(); read(); QStringList l = Global::languageList(); lang = l[0]; glang = l[1]; } + +// Sharp ROM compatibility +Config::Config ( const QString &name, bool what ) + : filename( configFilename(name,what ? User : File) ) +{ + git = groups.end(); + read(); + QStringList l = Global::languageList(); + lang = l[0]; + glang = l[1]; +} + /*! Writes any changes to disk and destroys the in-memory object. */ Config::~Config() { if ( changed ) write(); } /*! Returns whether the current group has an entry called \a key. */ bool Config::hasKey( const QString &key ) const { if ( groups.end() == git ) return FALSE; ConfigGroup::ConstIterator it = ( *git ).find( key ); return it != ( *git ).end(); } /*! Sets the current group for subsequent reading and writing of entries to \a gname. Grouping allows the application to partition the namespace. This function must be called prior to any reading or writing of entries. The \a gname must not be empty. */ void Config::setGroup( const QString &gname ) { QMap< QString, ConfigGroup>::Iterator it = groups.find( gname ); if ( it == groups.end() ) { git = groups.insert( gname, ConfigGroup() ); changed = TRUE; return; } git = it; } /*! Writes a (\a key, \a value) entry to the current group. \sa readEntry() */ void Config::writeEntry( const QString &key, const char* value ) { writeEntry(key,QString(value)); } /*! Writes a (\a key, \a value) entry to the current group. \sa readEntry() */ void Config::writeEntry( const QString &key, const QString &value ) { if ( git == groups.end() ) { qWarning( "no group set" ); return; } if ( (*git)[key] != value ) { ( *git ).insert( key, value ); changed = TRUE; } } /* Note that the degree of protection offered by the encryption here is only sufficient to avoid the most casual observation of the configuration files. People with access to the files can write down the contents and decrypt it using this source code. Conceivably, and at some burden to the user, this encryption could be improved. */ static QString encipher(const QString& plain) { // mainly, we make it long QString cipher; int mix=28730492; for (int i=0; i<(int)plain.length(); i++) { int u = plain[i].unicode(); int c = u ^ mix; QString x = QString::number(c,36); cipher.append(QChar('a'+x.length())); cipher.append(x); mix *= u; } return cipher; } static QString decipher(const QString& cipher) { QString plain; int mix=28730492; for (int i=0; i<(int)cipher.length();) { int l = cipher[i].unicode()-'a'; QString x = cipher.mid(i+1,l); i+=l+1; int u = x.toInt(0,36) ^ mix; plain.append(QChar(u)); mix *= u; } return plain; } /*! Writes an encrypted (\a key, \a value) entry to the current group. Note that the degree of protection offered by the encryption is only sufficient to avoid the most casual observation of the configuration files. \sa readEntry() */ void Config::writeEntryCrypt( const QString &key, const QString &value ) { if ( git == groups.end() ) { qWarning( "no group set" ); return; } QString evalue = encipher(value); if ( (*git)[key] != evalue ) { ( *git ).insert( key, evalue ); changed = TRUE; } } /*! Writes a (\a key, \a num) entry to the current group. \sa readNumEntry() */ void Config::writeEntry( const QString &key, int num ) { QString s; s.setNum( num ); writeEntry( key, s ); } #ifdef Q_HAS_BOOL_TYPE /*! Writes a (\a key, \a b) entry to the current group. This is equivalent to writing a 0 or 1 as an integer entry. \sa readBoolEntry() */ void Config::writeEntry( const QString &key, bool b ) { QString s; s.setNum( ( int )b ); writeEntry( key, s ); } #endif /*! Writes a (\a key, \a lst) entry to the current group. The list is separated by \a sep, so the strings must not contain that character. \sa readListEntry() */ void Config::writeEntry( const QString &key, const QStringList &lst, const QChar &sep ) { QString s; QStringList::ConstIterator it = lst.begin(); for ( ; it != lst.end(); ++it ) s += *it + sep; writeEntry( key, s ); } /*! Removes the \a key entry from the current group. Does nothing if there is no such entry. */ void Config::removeEntry( const QString &key ) { if ( git == groups.end() ) { qWarning( "no group set" ); return; } ( *git ).remove( key ); changed = TRUE; } /*! \fn bool Config::operator == ( const Config & other ) const Tests for equality with \a other. Config objects are equal if they refer to the same filename. */ /*! \fn bool Config::operator != ( const Config & other ) const Tests for inequality with \a other. Config objects are equal if they refer to the same filename. */ /*! \fn QString Config::readEntry( const QString &key, const QString &deflt ) const Reads a string entry stored with \a key, defaulting to \a deflt if there is no entry. */ /*! \internal For compatibility, non-const version. */ QString Config::readEntry( const QString &key, const QString &deflt ) { QString res = readEntryDirect( key+"["+lang+"]" ); if ( !res.isNull() ) return res; if ( !glang.isEmpty() ) { res = readEntryDirect( key+"["+glang+"]" ); if ( !res.isNull() ) return res; } return readEntryDirect( key, deflt ); } /*! \fn QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const Reads an encrypted string entry stored with \a key, defaulting to \a deflt if there is no entry. */ /*! \internal For compatibility, non-const version. */ QString Config::readEntryCrypt( const QString &key, const QString &deflt ) { QString res = readEntryDirect( key+"["+lang+"]" ); if ( res.isNull() && glang.isEmpty() ) res = readEntryDirect( key+"["+glang+"]" ); if ( res.isNull() ) res = readEntryDirect( key, QString::null ); if ( res.isNull() ) return deflt; return decipher(res); } /*! \fn QString Config::readEntryDirect( const QString &key, const QString &deflt ) const \internal */ /*! \internal For compatibility, non-const version. */ QString Config::readEntryDirect( const QString &key, const QString &deflt ) { if ( git == groups.end() ) { //qWarning( "no group set" ); return deflt; } ConfigGroup::ConstIterator it = ( *git ).find( key ); if ( it != ( *git ).end() ) return *it; else return deflt; } /*! \fn int Config::readNumEntry( const QString &key, int deflt ) const Reads a numeric entry stored with \a key, defaulting to \a deflt if there is no entry. */ /*! \internal For compatibility, non-const version. */ int Config::readNumEntry( const QString &key, int deflt ) { QString s = readEntry( key ); if ( s.isEmpty() ) return deflt; else return s.toInt(); } /*! \fn bool Config::readBoolEntry( const QString &key, bool deflt ) const Reads a bool entry stored with \a key, defaulting to \a deflt if there is no entry. */ /*! \internal For compatibility, non-const version. */ bool Config::readBoolEntry( const QString &key, bool deflt ) { QString s = readEntry( key ); if ( s.isEmpty() ) return deflt; else return (bool)s.toInt(); } /*! \fn QStringList Config::readListEntry( const QString &key, const QChar &sep ) const Reads a string list entry stored with \a key, and with \a sep as the separator. */ /*! \internal For compatibility, non-const version. */ QStringList Config::readListEntry( const QString &key, const QChar &sep ) { QString s = readEntry( key ); if ( s.isEmpty() ) return QStringList(); else return QStringList::split( sep, s ); } /*! Removes all entries from the current group. */ void Config::clearGroup() { if ( git == groups.end() ) { qWarning( "no group set" ); return; } if ( !(*git).isEmpty() ) { ( *git ).clear(); changed = TRUE; } } /*! \internal */ void Config::write( const QString &fn ) { QString strNewFile; if ( !fn.isEmpty() ) filename = fn; strNewFile = filename + ".new"; QFile f( strNewFile ); if ( !f.open( IO_WriteOnly|IO_Raw ) ) { qWarning( "could not open for writing `%s'", strNewFile.latin1() ); git = groups.end(); return; } QString str; QCString cstr; QMap< QString, ConfigGroup >::Iterator g_it = groups.begin(); for ( ; g_it != groups.end(); ++g_it ) { str += "[" + g_it.key() + "]\n"; ConfigGroup::Iterator e_it = ( *g_it ).begin(); for ( ; e_it != ( *g_it ).end(); ++e_it ) str += e_it.key() + " = " + *e_it + "\n"; } cstr = str.utf8(); int total_length; total_length = f.writeBlock( cstr.data(), cstr.length() ); if ( total_length != int(cstr.length()) ) { QMessageBox::critical( 0, QObject::tr("Out of Space"), QObject::tr("There was a problem creating\nConfiguration Information \nfor this program.\n\nPlease free up some space and\ntry again.") ); f.close(); QFile::remove( strNewFile ); return; } f.close(); // now rename the file... if ( rename( strNewFile, filename ) < 0 ) { qWarning( "problem renaming the file %s to %s", strNewFile.latin1(), filename.latin1() ); QFile::remove( strNewFile ); } } /*! Returns whether the Config is in a valid state. */ bool Config::isValid() const { return groups.end() != git; } /*! \internal */ void Config::read() { changed = FALSE; if ( !QFileInfo( filename ).exists() ) { git = groups.end(); return; } QFile f( filename ); if ( !f.open( IO_ReadOnly ) ) { git = groups.end(); return; } QTextStream s( &f ); #if QT_VERSION <= 230 && defined(QT_NO_CODECS) // The below should work, but doesn't in Qt 2.3.0 s.setCodec( QTextCodec::codecForMib( 106 ) ); #else s.setEncoding( QTextStream::UnicodeUTF8 ); #endif QStringList list = QStringList::split('\n', s.read() ); f.close(); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { if ( !parse( *it ) ) { git = groups.end(); return; } } } /*! \internal */ bool Config::parse( const QString &l ) { QString line = l.stripWhiteSpace(); if ( line [0] == QChar ( '#' )) return true; // ignore comments if ( line[ 0 ] == QChar( '[' ) ) { QString gname = line; gname = gname.remove( 0, 1 ); if ( gname[ (int)gname.length() - 1 ] == QChar( ']' ) ) gname = gname.remove( gname.length() - 1, 1 ); git = groups.insert( gname, ConfigGroup() ); } else if ( !line.isEmpty() ) { if ( git == groups.end() ) return FALSE; int eq = line.find( '=' ); if ( eq == -1 ) return FALSE; QString key = line.left(eq).stripWhiteSpace(); QString value = line.mid(eq+1).stripWhiteSpace(); ( *git ).insert( key, value ); } return TRUE; } diff --git a/library/config.h b/library/config.h index 1dc32fa..0bab7ca 100644 --- a/library/config.h +++ b/library/config.h @@ -1,102 +1,105 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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. ** **********************************************************************/ #ifndef CONFIG_H #define CONFIG_H // ##### could use QSettings with Qt 3.0 #include <qmap.h> #include <qstringlist.h> class ConfigPrivate; class Config { public: typedef QMap< QString, QString > ConfigGroup; enum Domain { File, User }; Config( const QString &name, Domain domain=User ); ~Config(); bool operator == ( const Config & other ) const { return (filename == other.filename); } bool operator != ( const Config & other ) const { return (filename != other.filename); } bool isValid() const; bool hasKey( const QString &key ) const; void setGroup( const QString &gname ); void writeEntry( const QString &key, const char* value ); void writeEntry( const QString &key, const QString &value ); void writeEntryCrypt( const QString &key, const QString &value ); void writeEntry( const QString &key, int num ); #ifdef Q_HAS_BOOL_TYPE void writeEntry( const QString &key, bool b ); #endif void writeEntry( const QString &key, const QStringList &lst, const QChar &sep ); void removeEntry( const QString &key ); QString readEntry( const QString &key, const QString &deflt = QString::null ) const; QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const; QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const; int readNumEntry( const QString &key, int deflt = -1 ) const; bool readBoolEntry( const QString &key, bool deflt = FALSE ) const; QStringList readListEntry( const QString &key, const QChar &sep ) const; // For compatibility, non-const versions. QString readEntry( const QString &key, const QString &deflt ); QString readEntryCrypt( const QString &key, const QString &deflt ); QString readEntryDirect( const QString &key, const QString &deflt ); int readNumEntry( const QString &key, int deflt ); bool readBoolEntry( const QString &key, bool deflt ); QStringList readListEntry( const QString &key, const QChar &sep ); void clearGroup(); void write( const QString &fn = QString::null ); protected: void read(); bool parse( const QString &line ); QMap< QString, ConfigGroup > groups; QMap< QString, ConfigGroup >::Iterator git; QString filename; QString lang; QString glang; bool changed; ConfigPrivate *d; static QString configFilename(const QString& name, Domain); + +private: // Sharp ROM compatibility + Config( const QString &name, bool what ); }; inline QString Config::readEntry( const QString &key, const QString &deflt ) const { return ((Config*)this)->readEntry(key,deflt); } inline QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const { return ((Config*)this)->readEntryCrypt(key,deflt); } inline QString Config::readEntryDirect( const QString &key, const QString &deflt ) const { return ((Config*)this)->readEntryDirect(key,deflt); } inline int Config::readNumEntry( const QString &key, int deflt ) const { return ((Config*)this)->readNumEntry(key,deflt); } inline bool Config::readBoolEntry( const QString &key, bool deflt ) const { return ((Config*)this)->readBoolEntry(key,deflt); } inline QStringList Config::readListEntry( const QString &key, const QChar &sep ) const { return ((Config*)this)->readListEntry(key,sep); } #endif diff --git a/library/datebookmonth.cpp b/library/datebookmonth.cpp index 4a9dcbd..e8be313 100644 --- a/library/datebookmonth.cpp +++ b/library/datebookmonth.cpp @@ -1,750 +1,762 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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 "config.h" #include "datebookmonth.h" #include "datebookdb.h" #include <qtopia/private/event.h> #include "resource.h" #include <qpe/qpeapplication.h> #include "timestring.h" #include <qtoolbutton.h> #include <qspinbox.h> #include <qcombobox.h> #include <qdatetime.h> #include <qpainter.h> #include <qpopupmenu.h> #include <qvaluestack.h> #include <qwhatsthis.h> DateBookMonthHeader::DateBookMonthHeader( QWidget *parent, const char *name ) : QHBox( parent, name ) { setBackgroundMode( PaletteButton ); begin = new QToolButton( this ); begin->setFocusPolicy(NoFocus); begin->setPixmap( Resource::loadPixmap( "start" ) ); begin->setAutoRaise( TRUE ); begin->setFixedSize( begin->sizeHint() ); QWhatsThis::add( begin, tr("Show January in the selected year") ); back = new QToolButton( this ); back->setFocusPolicy(NoFocus); back->setPixmap( Resource::loadPixmap( "back" ) ); back->setAutoRaise( TRUE ); back->setFixedSize( back->sizeHint() ); QWhatsThis::add( back, tr("Show the previous month") ); month = new QComboBox( FALSE, this ); for ( int i = 0; i < 12; ++i ) month->insertItem( Calendar::nameOfMonth( i + 1 ) ); year = new QSpinBox( 1752, 8000, 1, this ); next = new QToolButton( this ); next->setFocusPolicy(NoFocus); next->setPixmap( Resource::loadPixmap( "forward" ) ); next->setAutoRaise( TRUE ); next->setFixedSize( next->sizeHint() ); QWhatsThis::add( next, tr("Show the next month") ); end = new QToolButton( this ); end->setFocusPolicy(NoFocus); end->setPixmap( Resource::loadPixmap( "finish" ) ); end->setAutoRaise( TRUE ); end->setFixedSize( end->sizeHint() ); QWhatsThis::add( end, tr("Show December in the selected year") ); connect( month, SIGNAL( activated( int ) ), this, SLOT( updateDate() ) ); connect( year, SIGNAL( valueChanged( int ) ), this, SLOT( updateDate() ) ); connect( begin, SIGNAL( clicked() ), this, SLOT( firstMonth() ) ); connect( end, SIGNAL( clicked() ), this, SLOT( lastMonth() ) ); connect( back, SIGNAL( clicked() ), this, SLOT( monthBack() ) ); connect( next, SIGNAL( clicked() ), this, SLOT( monthForward() ) ); back->setAutoRepeat( TRUE ); next->setAutoRepeat( TRUE ); } DateBookMonthHeader::~DateBookMonthHeader() { } void DateBookMonthHeader::updateDate() { emit dateChanged( year->value(), month->currentItem() + 1 ); } void DateBookMonthHeader::firstMonth() { emit dateChanged( year->value(), 1 ); month->setCurrentItem( 0 ); } void DateBookMonthHeader::lastMonth() { emit dateChanged( year->value(), 12 ); month->setCurrentItem( 11 ); } void DateBookMonthHeader::monthBack() { if ( month->currentItem() > 0 ) { emit dateChanged( year->value(), month->currentItem() ); month->setCurrentItem( month->currentItem() - 1 ); } else { emit dateChanged( year->value() - 1, 12 ); // we have a signal set to a changed value in year so we only need to change // year to get the result... month->setCurrentItem( 11 ); year->setValue( year->value() - 1 ); } } void DateBookMonthHeader::monthForward() { if ( month->currentItem() < 11 ) { emit dateChanged( year->value(), month->currentItem() + 2 ); month->setCurrentItem( month->currentItem() + 1 ); } else { // we have a signal set to a changed value in year so we only need to change // year to get the result... month->setCurrentItem( 0 ); year->setValue( year->value() + 1 ); } } void DateBookMonthHeader::setDate( int y, int m ) { year->setValue( y ); month->setCurrentItem( m - 1 ); } //--------------------------------------------------------------------------- class DateBookMonthTablePrivate { public: DateBookMonthTablePrivate() {}; ~DateBookMonthTablePrivate() { mMonthEvents.clear(); }; QValueList<EffectiveEvent> mMonthEvents; bool onMonday; }; DateBookMonthTable::DateBookMonthTable( QWidget *parent, const char *name, DateBookDB *newDb ) : QTable( 6, 7, parent, name ), db( newDb ) { d = new DateBookMonthTablePrivate(); selYear = -1; selMonth = -1; selDay = -1; Config cfg( "qpe" ); cfg.setGroup( "Time" ); d->onMonday = cfg.readBoolEntry( "MONDAY" ); horizontalHeader()->setResizeEnabled( FALSE ); // we have to do this here... or suffer the consequences later... for ( int i = 0; i < 7; i++ ){ horizontalHeader()->resizeSection( i, 30 ); setColumnStretchable( i, TRUE ); } setupLabels(); verticalHeader()->hide(); setLeftMargin( 0 ); for ( int i = 0; i < 6; ++i ) setRowStretchable( i, TRUE ); setSelectionMode( NoSelection ); connect( this, SIGNAL( clicked( int, int, int, const QPoint & ) ), this, SLOT( dayClicked( int, int ) ) ); connect( this, SIGNAL( currentChanged( int, int ) ), this, SLOT( dragDay( int, int ) ) ); setVScrollBarMode( AlwaysOff ); setHScrollBarMode( AlwaysOff ); } DateBookMonthTable::~DateBookMonthTable() { monthsEvents.clear(); delete d; } void DateBookMonthTable::setDate(int y, int m, int d) { if (month == m && year == y) { if ( selYear == -1 ) year = selYear; if ( selMonth == -1 ) month = selMonth; int r1, c1, r2, c2; findDay(selDay, r1, c1); selDay = day = d; findDay(selDay, r2, c2); setCurrentCell( r2, c2 ); //updateCell(r1,c1); //updateCell(r2,c2); } else { selYear = year = y; selMonth = month = m; selDay = day = d; setupTable(); } } void DateBookMonthTable::redraw() { setupLabels(); setupTable(); } void DateBookMonthTable::setWeekStart( bool onMonday ) { d->onMonday = onMonday; setupLabels(); setupTable(); } void DateBookMonthTable::setupTable() { QValueList<Calendar::Day> days = Calendar::daysOfMonth( year, month, d->onMonday ); QValueList<Calendar::Day>::Iterator it = days.begin(); int row = 0, col = 0; int crow = 0; int ccol = 0; for ( ; it != days.end(); ++it ) { DayItemMonth *i = (DayItemMonth *)item( row, col ); if ( !i ) { i = new DayItemMonth( this, QTableItem::Never, "" ); setItem( row, col, i ); } Calendar::Day calDay = *it; i->clearEffEvents(); i->setDay( calDay.date ); i->setType( calDay.type ); if ( i->day() == day && calDay.type == Calendar::Day::ThisMonth ) { crow = row; ccol = col; } updateCell( row, col ); if ( col == 6 ) { ++row; col = 0; } else { ++col; } } setCurrentCell( crow, ccol ); getEvents(); } void DateBookMonthTable::findDay( int day, int &row, int &col ) { QDate dtBegin( year, month, 1 ); int skips = dtBegin.dayOfWeek(); int effective_day = day + skips - 1; // row/columns begin at 0 // make an extra adjustment if we start on Mondays. if ( d->onMonday ) effective_day--; row = effective_day / 7; col = effective_day % 7; } void DateBookMonthTable::dayClicked( int row, int col ) { changeDaySelection( row, col ); emit dateClicked( selYear, selMonth, selDay ); } void DateBookMonthTable::dragDay( int row, int col ) { changeDaySelection( row, col ); } void DateBookMonthTable::changeDaySelection( int row, int col ) { DayItemMonth *i = (DayItemMonth*)item( row, col ); if ( !i ) return; switch ( i->type() ) { case Calendar::Day::ThisMonth: selMonth = month; break; case Calendar::Day::PrevMonth: selMonth = month-1; break; default: selMonth = month+1; } selYear = year; if ( selMonth <= 0 ) { selMonth = 12; selYear--; } else if ( selMonth > 12 ) { selMonth = 1; selYear++; } selDay = i->day(); } void DateBookMonthTable::viewportMouseReleaseEvent( QMouseEvent * ) { dayClicked( currentRow(), currentColumn() ); } void DateBookMonthTable::getEvents() { if ( !db ) return; QDate dtStart( year, month, 1 ); d->mMonthEvents = db->getEffectiveEvents( dtStart, QDate( year, month, dtStart.daysInMonth() ) ); QValueListIterator<EffectiveEvent> it = d->mMonthEvents.begin(); // now that the events are sorted, basically go through the list, make // a small list for every day and set it for each item... // clear all the items... while ( it != d->mMonthEvents.end() ) { QValueList<EffectiveEvent> dayEvent; EffectiveEvent e = *it; ++it; dayEvent.append( e ); while ( it != d->mMonthEvents.end() && e.date() == (*it).date() ) { dayEvent.append( *it ); ++it; } int row, col; findDay( e.date().day(), row, col ); DayItemMonth* w = static_cast<DayItemMonth*>( item( row, col ) ); w->setEvents( dayEvent ); updateCell( row, col ); dayEvent.clear(); } } void DateBookMonthTable::setupLabels() { for ( int i = 0; i < 7; ++i ) { // horizontalHeader()->resizeSection( i, 30 ); // setColumnStretchable( i, TRUE ); if ( d->onMonday ) horizontalHeader()->setLabel( i, Calendar::nameOfDay( i + 1 ) ); else { if ( i == 0 ) horizontalHeader()->setLabel( i, Calendar::nameOfDay( 7 ) ); else horizontalHeader()->setLabel( i, Calendar::nameOfDay( i ) ); } } } //--------------------------------------------------------------------------- DateBookMonth::DateBookMonth( QWidget *parent, const char *name, bool ac, DateBookDB *data ) : QVBox( parent, name ), autoClose( ac ) { setFocusPolicy(StrongFocus); year = QDate::currentDate().year(); month = QDate::currentDate().month(); day = QDate::currentDate().day(); header = new DateBookMonthHeader( this, "DateBookMonthHeader" ); table = new DateBookMonthTable( this, "DateBookMonthTable", data ); header->setDate( year, month ); table->setDate( year, month, QDate::currentDate().day() ); header->setFocusPolicy(NoFocus); table->setFocusPolicy(NoFocus); connect( header, SIGNAL( dateChanged( int, int ) ), this, SLOT( setDate( int, int ) ) ); connect( table, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( finalDate(int, int, int) ) ); connect( qApp, SIGNAL(weekChanged(bool)), this, SLOT(slotWeekChange(bool)) ); table->setFocus(); } DateBookMonth::~DateBookMonth() { } void DateBookMonth::setDate( int y, int m ) { /* only change the date if this is a different date, * other wise we may mistakenly overide the day */ if ( (y != year) || (m != month) ) { year = y; month = m; QDate nd( y, m, 1 ); if ( nd.daysInMonth() < day ) day = nd.daysInMonth(); table->setDate( year, month, day ); } } void DateBookMonth::setDate( int y, int m, int d ) { header->setDate( y, m); table->setDate( y, m, d); year = y; month = m; day = d; } /* called when we wish to close or pass back the date */ void DateBookMonth::finalDate(int y, int m, int d) { setDate( y, m, d ); emit dateClicked(y, m, d); // emit dateClicked(QDate(y, m, d).toString()); if ( autoClose && parentWidget() ) parentWidget()->close(); } void DateBookMonth::setDate( QDate d) { setDate(d.year(), d.month(), d.day()); } void DateBookMonth::redraw() { table->setDate( year, month, day ); table->redraw(); } QDate DateBookMonth::selectedDate() const { if ( !table ) return QDate::currentDate(); int y, m, d; table->getDate( y, m, d ); return QDate( y, m, d ); } void DateBookMonth::slotWeekChange( bool startOnMonday ) { table->setWeekStart( startOnMonday ); } void DateBookMonth::keyPressEvent( QKeyEvent *e ) { switch(e->key()) { case Key_Up: setDate(QDate(year, month, day).addDays(-7)); break; case Key_Down: setDate(QDate(year, month, day).addDays(7)); break; case Key_Left: setDate(QDate(year, month, day).addDays(-1)); break; case Key_Right: setDate(QDate(year, month, day).addDays(1)); break; case Key_Space: qWarning("space"); emit dateClicked(year, month, day); if ( autoClose && parentWidget() ) parentWidget()->close(); break; default: qWarning("ignore"); e->ignore(); break; } } //--------------------------------------------------------------------------- class DayItemMonthPrivate { public: DayItemMonthPrivate() {}; ~DayItemMonthPrivate() { mDayEvents.clear(); }; QValueList<EffectiveEvent> mDayEvents; }; DayItemMonth::DayItemMonth( QTable *table, EditType et, const QString &t ) : QTableItem( table, et, t ) { d = new DayItemMonthPrivate(); } DayItemMonth::~DayItemMonth() { daysEvents.clear(); delete d; } void DayItemMonth::setEvents( const QValueList<EffectiveEvent> &effEv ) { d->mDayEvents = effEv; } void DayItemMonth::clearEffEvents() { d->mDayEvents.clear(); } void DayItemMonth::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ) { p->save(); QColorGroup g( cg ); g.setBrush( QColorGroup::Base, back ); g.setColor( QColorGroup::Text, forg ); if ( selected ) p->setPen( g.highlightedText() ); else p->setPen( g.text() ); QValueStack<int> normalLine; QValueStack<int> repeatLine; QValueStack<int> travelLine; bool normalAllDay = FALSE; bool repeatAllDay = FALSE; bool travelAllDay = FALSE; QValueListIterator<EffectiveEvent> itDays = d->mDayEvents.begin(); for ( ; itDays != d->mDayEvents.end(); ++itDays ) { int w = cr.width(); Event ev = (*itDays).event(); int f = (*itDays).start().hour(); // assume Effective event int t = (*itDays).end().hour(); // is truncated. if (ev.isAllDay()) { if (!ev.hasRepeat()) normalAllDay = TRUE; else repeatAllDay = TRUE; } else { int sLine, eLine; if (f == 0) sLine = 0; else if (f < 8 ) sLine = 1; else if (f >= 17) sLine = w - 4; else { sLine = (f - 8) * (w - 8); if (sLine) sLine /= 8; sLine += 4; } if (t == 23) eLine = w; else if (t < 8) eLine = 4; else if (t >= 17) eLine = w - 1; else { eLine = (t - 8) * (w - 8); if (eLine) eLine /= 8; eLine += 4; } if (!ev.hasRepeat()) { normalLine.push(sLine); normalLine.push(eLine); } else { repeatLine.push(sLine); repeatLine.push(eLine); } } } // draw the background if (normalAllDay || repeatAllDay || travelAllDay) { p->save(); if (normalAllDay) if (repeatAllDay) { p->fillRect( 0, 0, cr.width(), cr.height() / 2, colorNormalLight ); p->fillRect( 0, cr.height() / 2, cr.width(), cr.height() / 2, colorRepeatLight ); } else p->fillRect( 0, 0, cr.width(), cr.height(), colorNormalLight ); else if (repeatAllDay) p->fillRect( 0, 0, cr.width(), cr.height(), colorRepeatLight ); } else { p->fillRect( 0, 0, cr.width(), cr.height(), selected ? g.brush( QColorGroup::Highlight ) : g.brush( QColorGroup::Base ) ); } // The lines // now for the lines. int h = 5; int y = cr.height() / 2 - h; while(normalLine.count() >= 2) { int x2 = normalLine.pop(); int x1 = normalLine.pop(); if (x2 < x1 + 2) x2 = x1 + 2; p->fillRect(x1, y, x2 - x1, h, colorNormal); } y += h; while(repeatLine.count() >= 2) { int x2 = repeatLine.pop(); int x1 = repeatLine.pop(); if (x2 < x1 + 2) x2 = x1 + 2; p->fillRect(x1, y, x2 - x1, h, colorRepeat); } // Finally, draw the number. QFont f = p->font(); f.setPointSize( ( f.pointSize() / 3 ) * 2 ); p->setFont( f ); QFontMetrics fm( f ); p->drawText( 1, 1 + fm.ascent(), QString::number( day() ) ); p->restore(); } void DayItemMonth::setType( Calendar::Day::Type t ) { switch ( t ) { case Calendar::Day::PrevMonth: case Calendar::Day::NextMonth: back = QBrush( QColor( 224, 224, 224 ) ); forg = black; break; case Calendar::Day::ThisMonth: back = QBrush( white ); forg = black; break; } typ = t; } DateButton::DateButton( bool longDate, QWidget *parent, const char * name ) :QPushButton( parent, name ) { longFormat = longDate; df = DateFormat('/', DateFormat::MonthDayYear, DateFormat::MonthDayYear); setDate( QDate::currentDate() ); connect(this,SIGNAL(pressed()),this,SLOT(pickDate())); } void DateButton::pickDate() { static QPopupMenu *m1 = 0; static DateBookMonth *picker = 0; if ( !m1 ) { m1 = new QPopupMenu( this ); picker = new DateBookMonth( m1, 0, TRUE ); m1->insertItem( picker ); connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SLOT( setDate( int, int, int ) ) ); connect( picker, SIGNAL( dateClicked( int, int, int ) ), this, SIGNAL( dateSelected( int, int, int ) ) ); connect( m1, SIGNAL( aboutToHide() ), this, SLOT( gotHide() ) ); } picker->slotWeekChange( weekStartsMonday ); picker->setDate( currDate.year(), currDate.month(), currDate.day() ); m1->popup(mapToGlobal(QPoint(0,height()))); picker->setFocus(); } void DateButton::gotHide() { // we have to redo the button... setDown( false ); } // void dateSelected( int year, int month, int day ); void DateButton::setWeekStartsMonday( int b ) { weekStartsMonday = b; } void DateButton::setDate( int y, int m, int d ) { setDate( QDate( y,m,d) ); } void DateButton::setDate( QDate d ) { currDate = d; setText( longFormat ? TimeString::longDateString( d, df ) : TimeString::shortDate( d, df ) ); } void DateButton::setDateFormat( DateFormat f ) { df = f; setDate( currDate ); } bool DateButton::customWhatsThis() const { return TRUE; } + +// this class is only here for Sharp ROM compatibility +// I have reverse engineered this class and it seems to +// work (only qtmail seems to use it) - sandman +// DO NOT USE IT IN NEW CODE !! + +DateBookMonthPopup::DateBookMonthPopup ( QWidget *w ) + : QPopupMenu ( w ) +{ + m_dbm = new DateBookMonth( this, 0, TRUE ); + insertItem( m_dbm ); +} diff --git a/library/datebookmonth.h b/library/datebookmonth.h index 3c57c19..cb436a8 100644 --- a/library/datebookmonth.h +++ b/library/datebookmonth.h @@ -1,213 +1,228 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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. ** **********************************************************************/ #ifndef DATEBOOKMONTH #define DATEBOOKMONTH #include <qtopia/private/event.h> #include <qvbox.h> #include <qhbox.h> #include <qdatetime.h> #include <qvaluelist.h> #include <qtable.h> #include <qpushbutton.h> +#include <qpopupmenu.h> #include "calendar.h" #include "timestring.h" class QToolButton; class QComboBox; class QSpinBox; class Event; class DateBookDB; class DateBookMonthHeaderPrivate; class DateBookMonthHeader : public QHBox { Q_OBJECT public: DateBookMonthHeader( QWidget *parent = 0, const char *name = 0 ); ~DateBookMonthHeader(); void setDate( int year, int month ); signals: void dateChanged( int year, int month ); protected slots: void keyPressEvent(QKeyEvent *e ) { e->ignore(); } private slots: void updateDate(); void firstMonth(); void lastMonth(); void monthBack(); void monthForward(); private: QToolButton *begin, *back, *next, *end; QComboBox *month; QSpinBox *year; DateBookMonthHeaderPrivate *d; int focus; }; class DayItemMonthPrivate; class DayItemMonth : public QTableItem { public: DayItemMonth( QTable *table, EditType et, const QString &t ); ~DayItemMonth(); void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected ); void setDay( int d ) { dy = d; } void setEvents( const QValueList<Event> &events ) { daysEvents = events; }; void setEvents( const QValueList<EffectiveEvent> &effEvents ); void clearEvents() { daysEvents.clear(); }; void clearEffEvents(); int day() const { return dy; } void setType( Calendar::Day::Type t ); Calendar::Day::Type type() const { return typ; } private: QBrush back; QColor forg; int dy; Calendar::Day::Type typ; QValueList<Event> daysEvents; // not used anymore... DayItemMonthPrivate *d; }; class DateBookMonthTablePrivate; class DateBookMonthTable : public QTable { Q_OBJECT public: DateBookMonthTable( QWidget *parent = 0, const char *name = 0, DateBookDB *newDb = 0 ); ~DateBookMonthTable(); void setDate( int y, int m, int d ); void redraw(); QSize minimumSizeHint() const { return sizeHint(); } QSize minimumSize() const { return sizeHint(); } void getDate( int& y, int &m, int &d ) const {y=selYear;m=selMonth;d=selDay;} void setWeekStart( bool onMonday ); signals: void dateClicked( int year, int month, int day ); protected: void viewportMouseReleaseEvent( QMouseEvent * ); protected slots: void keyPressEvent(QKeyEvent *e ) { e->ignore(); } private slots: void dayClicked( int row, int col ); void dragDay( int row, int col ); private: void setupTable(); void setupLabels(); void findDay( int day, int &row, int &col ); void getEvents(); void changeDaySelection( int row, int col ); int year, month, day; int selYear, selMonth, selDay; QValueList<Event> monthsEvents; // not used anymore... DateBookDB *db; DateBookMonthTablePrivate *d; }; class DateBookMonthPrivate; class DateBookMonth : public QVBox { Q_OBJECT public: DateBookMonth( QWidget *parent = 0, const char *name = 0, bool ac = FALSE, DateBookDB *data = 0 ); ~DateBookMonth(); QDate selectedDate() const; signals: void dateClicked( int year, int month, int day ); public slots: void setDate( int y, int m ); void setDate( int y, int m, int d ); void setDate( QDate ); void redraw(); void slotWeekChange( bool ); protected slots: virtual void keyPressEvent(QKeyEvent *e); private slots: void forwardDateClicked( int y, int m, int d ) { emit dateClicked( y, m, d ); } void finalDate(int, int, int); private: DateBookMonthHeader *header; DateBookMonthTable *table; int year, month, day; bool autoClose; class DateBookMonthPrivate *d; }; class DateButton : public QPushButton { Q_OBJECT public: DateButton( bool longDate, QWidget *parent, const char * name = 0 ); QDate date() const { return currDate; } bool customWhatsThis() const; signals: void dateSelected( int year, int month, int day ); public slots: void setDate( int y, int m, int d ); void setDate( QDate ); void setWeekStartsMonday( int ); void setDateFormat( DateFormat ); private slots: void pickDate(); void gotHide(); private: bool longFormat; bool weekStartsMonday; QDate currDate; DateFormat df; }; +// this class is only here for Sharp ROM compatibility +// I have reverse engineered this class and it seems to +// work (only qtmail seems to use it) - sandman +// DO NOT USE IT IN NEW CODE !! + +class DateBookMonthPopup : public QPopupMenu +{ + Q_OBJECT +public: + DateBookMonthPopup ( QWidget *w ); + +private: + DateBookMonth *m_dbm; +}; #endif diff --git a/library/qpemenubar.cpp b/library/qpemenubar.cpp index c658d10..4aa0bf3 100644 --- a/library/qpemenubar.cpp +++ b/library/qpemenubar.cpp @@ -1,325 +1,334 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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. ** **********************************************************************/ #define INCLUDE_MENUITEM_DEF #include "qpemenubar.h" #include <qapplication.h> #include <qguardedptr.h> #include <qtimer.h> class QMenuBarHack : public QMenuBar { public: int activeItem() const { return actItem; } void goodbye() { activateItemAt(-1); for ( unsigned int i = 0; i < count(); i++ ) { QMenuItem *mi = findItem( idAt(i) ); if ( mi->popup() ) { mi->popup()->hide(); } } } }; +// Sharp ROM compatibility +void QPEMenuToolFocusManager::setMenukeyEnabled ( bool ) +{ +} +int QPEMenuBar::getOldFocus ( ) +{ + return 0; +} + QPEMenuToolFocusManager *QPEMenuToolFocusManager::me = 0; QPEMenuToolFocusManager::QPEMenuToolFocusManager() : QObject() { qApp->installEventFilter( this ); } void QPEMenuToolFocusManager::addWidget( QWidget *w ) { list.append( GuardedWidget(w) ); } void QPEMenuToolFocusManager::removeWidget( QWidget *w ) { list.remove( GuardedWidget(w) ); } void QPEMenuToolFocusManager::setActive( bool a ) { if ( a ) { oldFocus = qApp->focusWidget(); QValueList<GuardedWidget>::Iterator it; it = list.begin(); while ( it != list.end() ) { QWidget *w = (*it); if ( w && w->isEnabled() && w->isVisible() && w->topLevelWidget() == qApp->activeWindow() ) { setFocus( w ); return; } ++it; } } else { if ( inFocus ) { if ( inFocus->inherits( "QMenuBar" ) ) ((QMenuBarHack *)(QWidget *)inFocus)->goodbye(); if ( inFocus->hasFocus() ) { if ( oldFocus && oldFocus->isVisible() && oldFocus->isEnabled() ) { oldFocus->setFocus(); } else { inFocus->clearFocus(); } } } inFocus = 0; oldFocus = 0; } } bool QPEMenuToolFocusManager::isActive() const { return !inFocus.isNull(); } void QPEMenuToolFocusManager::moveFocus( bool next ) { if ( !isActive() ) return; int n = list.count(); QValueList<GuardedWidget>::Iterator it; it = list.find( inFocus ); if ( it == list.end() ) it = list.begin(); while ( --n ) { if ( next ) { ++it; if ( it == list.end() ) it = list.begin(); } else { if ( it == list.begin() ) it = list.end(); --it; } QWidget *w = (*it); if ( w && w->isEnabled() && w->isVisible() && !w->inherits("QToolBarSeparator") && w->topLevelWidget() == qApp->activeWindow() ) { setFocus( w, next ); return; } } } void QPEMenuToolFocusManager::initialize() { if ( !me ) me = new QPEMenuToolFocusManager; } QPEMenuToolFocusManager *QPEMenuToolFocusManager::manager() { if ( !me ) me = new QPEMenuToolFocusManager; return me; } void QPEMenuToolFocusManager::setFocus( QWidget *w, bool next ) { inFocus = w; // qDebug( "Set focus on %s", w->className() ); if ( inFocus->inherits( "QMenuBar" ) ) { QMenuBar *mb = (QMenuBar *)(QWidget *)inFocus; if ( next ) mb->activateItemAt( 0 ); else mb->activateItemAt( mb->count()-1 ); } inFocus->setFocus(); } bool QPEMenuToolFocusManager::eventFilter( QObject *object, QEvent *event ) { if ( event->type() == QEvent::KeyPress ) { QKeyEvent *ke = (QKeyEvent *)event; if ( isActive() ) { if ( object->inherits( "QButton" ) ) { switch ( ke->key() ) { case Key_Left: moveFocus( FALSE ); return TRUE; case Key_Right: moveFocus( TRUE ); return TRUE; case Key_Up: case Key_Down: return TRUE; } } else if ( object->inherits( "QPopupMenu" ) ) { // Deactivate when a menu item is selected if ( ke->key() == Key_Enter || ke->key() == Key_Return || ke->key() == Key_Escape ) { QTimer::singleShot( 0, this, SLOT(deactivate()) ); } } else if ( object->inherits( "QMenuBar" ) ) { int dx = 0; switch ( ke->key() ) { case Key_Left: dx = -1; break; case Key_Right: dx = 1; break; } QMenuBarHack *mb = (QMenuBarHack *)object; if ( dx && mb->activeItem() >= 0 ) { int i = mb->activeItem(); int c = mb->count(); int n = c; while ( n-- ) { i = i + dx; if ( i == c ) { mb->goodbye(); moveFocus( TRUE ); return TRUE; } else if ( i < 0 ) { mb->goodbye(); moveFocus( FALSE ); return TRUE; } QMenuItem *mi = mb->findItem( mb->idAt(i) ); if ( mi->isEnabled() && !mi->isSeparator() ) { break; } } } } } if ( ke->key() == Key_F11 ) { setActive( !isActive() ); return TRUE; } } else if ( event->type() == QEvent::KeyRelease ) { QKeyEvent *ke = (QKeyEvent *)event; if ( isActive() ) { if ( object->inherits( "QButton" ) ) { // Deactivate when a button is selected if ( ke->key() == Key_Space ) QTimer::singleShot( 0, this, SLOT(deactivate()) ); } } } else if ( event->type() == QEvent::FocusIn ) { if ( isActive() ) { // A non-menu/tool widget has been selected - we're deactivated QWidget *w = (QWidget *)object; if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { inFocus = 0; } } } else if ( event->type() == QEvent::Hide ) { if ( isActive() ) { // Deaticvate if a menu/tool has been hidden QWidget *w = (QWidget *)object; if ( !w->isPopup() && !list.contains( GuardedWidget( w ) ) ) { setActive( FALSE ); } } } else if ( event->type() == QEvent::ChildInserted ) { QChildEvent *ce = (QChildEvent *)event; if ( ce->child()->isWidgetType() ) { if ( ce->child()->inherits( "QMenuBar" ) ) { addWidget( (QWidget *)ce->child() ); ce->child()->installEventFilter( this ); } else if ( object->inherits( "QToolBar" ) ) { addWidget( (QWidget *)ce->child() ); } } } else if ( event->type() == QEvent::ChildRemoved ) { QChildEvent *ce = (QChildEvent *)event; if ( ce->child()->isWidgetType() ) { if ( ce->child()->inherits( "QMenuBar" ) ) { removeWidget( (QWidget *)ce->child() ); ce->child()->removeEventFilter( this ); } else if ( object->inherits( "QToolBar" ) ) { removeWidget( (QWidget *)ce->child() ); } } } return FALSE; } void QPEMenuToolFocusManager::deactivate() { setActive( FALSE ); } /*! \class QPEMenuBar qpemenubar.h \brief The QPEMenuBar class is obsolete. Use QMenuBar instead. \obsolete This class is obsolete. Use QMenuBar instead. */ /*! Constructs a QPEMenuBar just as you would construct a QMenuBar, passing \a parent and \a name. */ QPEMenuBar::QPEMenuBar( QWidget *parent, const char *name ) : QMenuBar( parent, name ) { } /*! \reimp */ QPEMenuBar::~QPEMenuBar() { } /*! \internal */ void QPEMenuBar::keyPressEvent( QKeyEvent *e ) { QMenuBar::keyPressEvent( e ); } /*! \internal */ void QPEMenuBar::activateItem( int index ) { activateItemAt( index ); } void QPEMenuBar::goodbye() { activateItemAt(-1); for ( uint i = 0; i < count(); i++ ) { QMenuItem* mi = findItem( idAt(i) ); if (mi->popup() ) mi->popup()->hide(); } } diff --git a/library/qpemenubar.h b/library/qpemenubar.h index 05abc4e..66d0c85 100644 --- a/library/qpemenubar.h +++ b/library/qpemenubar.h @@ -1,78 +1,85 @@ /********************************************************************** ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** 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. ** **********************************************************************/ #ifndef QPEMENUBAR_H #define QPEMENUBAR_H #include <qmenubar.h> #include <qguardedptr.h> #include <qvaluelist.h> class QPEMenuToolFocusManager : public QObject { Q_OBJECT public: QPEMenuToolFocusManager(); void addWidget( QWidget *w ); void removeWidget( QWidget *w ); void setActive( bool a ); bool isActive() const; void moveFocus( bool next ); static QPEMenuToolFocusManager *manager(); static void initialize(); protected: void setFocus( QWidget *w, bool next=TRUE ); bool eventFilter( QObject *object, QEvent *event ); private slots: void deactivate(); private: typedef QGuardedPtr<QWidget> GuardedWidget; QValueList<GuardedWidget> list; GuardedWidget inFocus; GuardedWidget oldFocus; static QPEMenuToolFocusManager *me; + +private: // Sharp ROM compatibility + void setMenukeyEnabled ( bool b ); }; class QPEMenuBar : public QMenuBar { Q_OBJECT public: QPEMenuBar( QWidget *parent=0, const char* name=0 ); ~QPEMenuBar(); protected: virtual void keyPressEvent( QKeyEvent *e ); /* Patch from Mickey * Sharp Qtopia1.5 seems to have these functions * TO BE RESOLVED - zecke */ void activateItem( int index ); void goodbye(); + + // This is a special "lineo" add-on for the Sharp ROM + // nobody knows, what it does, though ... + int getOldFocus ( ); }; #endif |