-rw-r--r-- | core/pim/addressbook/abtable.cpp | 26 | ||||
-rw-r--r-- | core/pim/addressbook/abtable.h | 2 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.cpp | 12 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.h | 3 | ||||
-rw-r--r-- | core/pim/addressbook/addressbook.pro | 6 | ||||
-rw-r--r-- | core/pim/addressbook/picker.cpp | 234 | ||||
-rw-r--r-- | core/pim/addressbook/picker.h | 65 |
7 files changed, 344 insertions, 4 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 17277b4..759cb48 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp @@ -105,96 +105,97 @@ QWidget *AbPickItem::createEditor() const if ( *it == text() ) cur = combo->count(); combo->insertItem(*it); } combo->setCurrentItem(cur); return combo; } void AbPickItem::setContentFromEditor( QWidget *w ) { if ( w->inherits("QComboBox") ) setText( ( (QComboBox*)w )->currentText() ); else QTableItem::setContentFromEditor( w ); } /*! \class AbTable abtable.h \brief QTable based class for showing a list of entries */ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR // : QTable( 0, 0, parent, name, TRUE ), // #else : QTable( parent, name ), // #endif lastSortCol( -1 ), asc( TRUE ), intFields( order ), currFindRow( -2 ), mCat( 0 ) { mCat.load( categoryFileName() ); setSelectionMode( NoSelection ); init(); setSorting( TRUE ); connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), this, SLOT(itemClicked(int,int)) ); } AbTable::~AbTable() { } void AbTable::init() { + showChar = '\0'; setNumRows( 0 ); setNumCols( 2 ); horizontalHeader()->setLabel( 0, tr( "Full Name" )); horizontalHeader()->setLabel( 1, tr( "Contact" )); setLeftMargin( 0 ); verticalHeader()->hide(); } void AbTable::columnClicked( int col ) { if ( !sorting() ) return; if ( lastSortCol == -1 ) lastSortCol = col; if ( col == lastSortCol ) { asc = !asc; } else { lastSortCol = col; asc = TRUE; } resort(); } void AbTable::resort() { if ( sorting() ) { if ( lastSortCol == -1 ) lastSortCol = 0; sortColumn( lastSortCol, asc, TRUE ); updateVisible(); } } Contact AbTable::currentEntry() { Contact cnt; AbTableItem *abItem; abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); if ( abItem ) { cnt = contactList[abItem]; } return cnt; } void AbTable::replaceCurrentEntry( const Contact &newContact ) @@ -407,102 +408,103 @@ QString AbTable::findContactContact( const Contact &entry ) case Qtopia::Profession: value = entry.profession(); break; case Qtopia::Assistant: value = entry.assistant(); break; case Qtopia::Manager: value = entry.manager(); break; case Qtopia::Spouse: value = entry.spouse(); break; case Qtopia::Gender: value = entry.gender(); break; case Qtopia::Birthday: value = entry.birthday(); break; case Qtopia::Anniversary: value = entry.anniversary(); break; case Qtopia::Nickname: value = entry.nickname(); break; case Qtopia::Children: value = entry.children(); break; case Qtopia::Notes: value = entry.notes(); break; } if ( !value.isEmpty() ) break; } return value; } void AbTable::addEntry( const Contact &newCnt ) { int row = numRows(); setNumRows( row + 1 ); updateJournal( newCnt, Contact::ACTION_ADD ); insertIntoTable( newCnt, row ); setCurrentCell( row, 0 ); updateVisible(); } void AbTable::resizeRows( int size ) { - +/* if (numRows()) { for (int i = 0; i < numRows(); i++) { setRowHeight( i, size ); } - } + }*/ + updateVisible(); } void AbTable::updateJournal( const Contact &cnt, Contact::journal_action action, int row ) { QFile f( journalFileName() ); if ( !f.open(IO_WriteOnly|IO_Append) ) return; QString buf; QCString str; buf = "<Contact "; cnt.save( buf ); buf += " action=\"" + QString::number( (int)action ) + "\" "; if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) buf += " actionrow=\"" + QString::number(row) + "\" "; buf += "/>\n"; QCString cstr = buf.utf8(); f.writeBlock( cstr.data(), cstr.length() ); QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); } bool AbTable::save( const QString &fn ) { // QTime t; // t.start(); QString strNewFile = fn + ".new"; QFile f( strNewFile ); if ( !f.open( IO_WriteOnly|IO_Raw ) ) return false; int total_written; QString out; out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" " <Groups>\n" " </Groups>\n" " <Contacts>\n"; QMapIterator<AbTableItem*, Contact> it; for ( it = contactList.begin(); it != contactList.end(); ++it ) { out += "<Contact "; it.data().save( out ); out += "/>\n"; QCString cstr = out.utf8(); total_written = f.writeBlock( cstr.data(), cstr.length() ); if ( total_written != int(cstr.length()) ) { f.close(); QFile::remove( strNewFile ); return false; @@ -963,140 +965,160 @@ void AbTable::itemClicked(int,int col) QStringList AbTable::choiceNames() const { return choicenames; } void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) { /* ###### QString selname = choicenames.at(index); for (each row) { Contact *c = contactForRow(row); if ( list.contains(c->email) ) { list.remove(c->email); setText(row, 2, selname); } } for (remaining list items) { Contact *c = new contact(item); setText(newrow, 2, selname); } */ } QStringList AbTable::choiceSelection(int /*index*/) const { QStringList r; /* ###### QString selname = choicenames.at(index); for (each row) { Contact *c = contactForRow(row); if ( text(row,2) == selname ) { r.append(c->email); } } */ return r; } void AbTable::setShowCategory( const QString &c ) { showCat = c; updateVisible(); } +void AbTable::setShowByLetter( char c ) +{ + showChar = tolower(c); + qDebug( "AbTable::setShowByLetter %c", showChar); + updateVisible(); +} + QString AbTable::showCategory() const { return showCat; } QStringList AbTable::categories() { mCat.load( categoryFileName() ); QStringList categoryList = mCat.labels( "Contacts" ); return categoryList; } void AbTable::updateVisible() { int visible, totalRows, id, totalCats, it, row; bool hide; AbTableItem *ati; Contact *cnt; + QString fileAsName; + QString tmpStr; visible = 0; setPaintingEnabled( FALSE ); totalRows = numRows(); id = mCat.id( "Contacts", showCat ); QArray<int> cats; for ( row = 0; row < totalRows; row++ ) { ati = static_cast<AbTableItem*>( item(row, 0) ); cnt = &contactList[ati]; cats = cnt->categories(); + fileAsName = cnt->fileAs(); hide = false; if ( !showCat.isEmpty() ) { if ( showCat == tr( "Unfiled" ) ) { if ( cats.count() > 0 ) hide = true; } else { // do some comparing if ( !hide ) { hide = true; totalCats = int(cats.count()); for ( it = 0; it < totalCats; it++ ) { if ( cats[it] == id ) { hide = false; break; } } } } } + if ( showChar != '\0' ) { + tmpStr = fileAsName.left(1); + tmpStr = tmpStr.lower(); + qDebug( "updateVisible "); + qDebug( tmpStr ); + qDebug( "updateVisible2 %c", showChar ); + if ( tmpStr != QString(QChar(showChar)) ) { + hide = true; + } + } if ( hide ) { if ( currentRow() == row ) setCurrentCell( -1, 0 ); if ( rowHeight(row) > 0 ) hideRow( row ); } else { if ( rowHeight(row) == 0 ) { showRow( row ); adjustRow( row ); } visible++; } } if ( !visible ) setCurrentCell( -1, 0 ); setPaintingEnabled( TRUE ); } void AbTable::setPaintingEnabled( bool e ) { if ( e != enablePainting ) { if ( !enablePainting ) { enablePainting = true; rowHeightChanged( 0 ); viewport()->update(); } else { enablePainting = false; } } } void AbTable::rowHeightChanged( int row ) { if ( enablePainting ) QTable::rowHeightChanged( row ); } diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h index 53635ee..d5ff279 100644 --- a/core/pim/addressbook/abtable.h +++ b/core/pim/addressbook/abtable.h @@ -39,103 +39,105 @@ public: virtual int alignment() const; virtual QString key() const; void setItem( const QString &txt, const QString &secondKey ); private: QString sortKey; }; class AbPickItem : public QTableItem { public: AbPickItem( QTable *t ); QWidget *createEditor() const; void setContentFromEditor( QWidget *w ); private: QGuardedPtr<QComboBox> cb; }; class AbTable : public QTable { Q_OBJECT public: AbTable( const QValueList<int> *ordered, QWidget *parent, const char *name=0 ); ~AbTable(); // NEW void addEntry( const Contact &newContact ); Contact currentEntry(); void replaceCurrentEntry( const Contact &newContact ); void init(); void deleteCurrentEntry(); void clear(); void clearFindRow() { currFindRow = -2; } void loadFields(); void refresh(); bool save( const QString &fn ); void load( const QString &fn ); // addresspicker mode void setChoiceNames( const QStringList& list); QStringList choiceNames() const; void setChoiceSelection(int index, const QStringList& list); QStringList choiceSelection(int index) const; void setShowCategory( const QString &c ); + void setShowByLetter( char c ); QString showCategory() const; QStringList categories(); void resizeRows( int size ); void show(); void setPaintingEnabled( bool e ); public slots: void slotDoFind( const QString &str, bool caseSensitive, bool backwards, int category ); signals: void empty( bool ); void details(); void signalNotFound(); void signalWrapAround(); protected: virtual void keyPressEvent( QKeyEvent *e ); // int rowHeight( int ) const; // int rowPos( int row ) const; // virtual int rowAt( int pos ) const; protected slots: void moveTo( char ); virtual void columnClicked( int col ); void itemClicked(int,int col); void rowHeightChanged( int row ); private: void loadFile( const QString &strFile, bool journalFile ); void fitColumns(); void resort(); void updateJournal( const Contact &contact, Contact::journal_action action, int row = -1 ); void insertIntoTable( const Contact &contact, int row ); void internalAddEntries( QList<Contact> &list ); QString findContactName( const Contact &entry ); QString findContactContact( const Contact &entry ); void journalFreeReplace( const Contact &cnt, int row ); void journalFreeRemove( int row ); void realignTable( int ); void updateVisible(); int lastSortCol; bool asc; + char showChar; QMap<AbTableItem*, Contact> contactList; const QValueList<int> *intFields; int currFindRow; QString showCat; QStringList choicenames; bool enablePainting; Categories mCat; }; #endif // ABTABLE_H diff --git a/core/pim/addressbook/addressbook.cpp b/core/pim/addressbook/addressbook.cpp index 360aa7e..e502cf6 100644 --- a/core/pim/addressbook/addressbook.cpp +++ b/core/pim/addressbook/addressbook.cpp @@ -18,238 +18,244 @@ ** **********************************************************************/ #define QTOPIA_INTERNAL_FD #include "contacteditor.h" #include "ablabel.h" #include "abtable.h" #include "addresssettings.h" #include "addressbook.h" #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/contact.h> #ifndef MAKE_FOR_SHARP_ROM #include <qpe/finddialog.h> #endif #include <qpe/global.h> #include <qpe/resource.h> #include <qpe/ir.h> #include <qpe/qpemessagebox.h> #include <qpe/qcopenvelope_qws.h> #include <qaction.h> #include <qdialog.h> #include <qdir.h> #include <qfile.h> #include <qimage.h> #include <qlayout.h> #include <qpe/qpemenubar.h> #include <qmessagebox.h> #include <qpixmap.h> #include <qpopupmenu.h> #include <qpe/qpetoolbar.h> #include <qstringlist.h> #include <qtoolbutton.h> #include <qwhatsthis.h> #include <stdlib.h> #include <sys/stat.h> #include <sys/types.h> #include <fcntl.h> #include <unistd.h> #include <qdatetime.h> +#include "picker.h" static QString addressbookOldXMLFilename() { QString filename = QPEApplication::documentDir() + "addressbook.xml"; return filename; } static QString addressbookXMLFilename() { QString filename = Global::applicationFileName("addressbook", "addressbook.xml"); return filename; } static QString addressbookPersonalVCardName() { QString filename = Global::applicationFileName("addressbook", "businesscard.vcf"); return filename; } AddressbookWindow::AddressbookWindow( QWidget *parent, const char *name, WFlags f ) : QMainWindow( parent, name, f ), abEditor(0), bAbEditFirstTime(TRUE), syncing(FALSE) { initFields(); setCaption( tr("Contacts") ); setIcon( Resource::loadPixmap( "AddressBook" ) ); setToolBarsMovable( FALSE ); + QBoxLayout *vb = new QVBoxLayout( this, 0, 0 ); // Create Toolbars QPEToolBar *bar = new QPEToolBar( this ); bar->setHorizontalStretchable( TRUE ); QPEMenuBar *mbList = new QPEMenuBar( bar ); mbList->setMargin( 0 ); QPopupMenu *edit = new QPopupMenu( this ); mbList->insertItem( tr( "Contact" ), edit ); listTools = new QPEToolBar( this, "list operations" ); QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 ); actionNew = a; connect( a, SIGNAL( activated() ), this, SLOT( slotListNew() ) ); a->addTo( edit ); a->addTo( listTools ); a = new QAction( tr( "Edit" ), Resource::loadPixmap( "edit" ), QString::null, 0, this, 0 ); actionEdit = a; connect( a, SIGNAL( activated() ), this, SLOT( slotViewEdit() ) ); a->addTo( edit ); a->addTo( listTools ); a = new QAction( tr( "Delete" ), Resource::loadPixmap( "trash" ), QString::null, 0, this, 0 ); actionTrash = a; connect( a, SIGNAL( activated() ), this, SLOT( slotListDelete() ) ); a->addTo( edit ); a->addTo( listTools ); #ifndef MAKE_FOR_SHARP_ROM a = new QAction( tr( "Find" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 ); actionFind = a; connect( a, SIGNAL(activated()), this, SLOT(slotFind()) ); a->addTo( edit ); a->addTo( listTools ); #endif a = new QAction( tr( "Write Mail To" ), Resource::loadPixmap( "qtmail/reply" ), QString::null, 0, this, 0 ); //a->setEnabled( FALSE ); we got support for it now :) zecke actionMail = a; connect( a, SIGNAL( activated() ), this, SLOT( writeMail() ) ); a->addTo( edit ); a->addTo( listTools ); if ( Ir::supported() ) { a = new QAction( tr ("Beam Entry" ), Resource::loadPixmap( "beam" ), QString::null, 0, this, 0 ); actionBeam = a; connect( a, SIGNAL( activated() ), this, SLOT( slotBeam() ) ); a->addTo( edit ); a->addTo( listTools ); } edit->insertSeparator(); a = new QAction( tr("My Personal Details"), QString::null, 0, 0, 0, TRUE ); actionPersonal = a; connect( a, SIGNAL( activated() ), this, SLOT( slotPersonalView() ) ); a->addTo( edit ); a = new QAction( tr( "Arrange Edit Fields"), QString::null, 0, 0 ); connect( a, SIGNAL( activated() ), this, SLOT( slotSettings() ) ); a->addTo( edit ); // Create Views // This is safe to call without checking to see if it exists... // not to mention it also does the necessary stuff for the // journaling... QString str = addressbookXMLFilename(); if ( str.isNull() ) { QMessageBox::warning( this, tr("Out of Space"), tr("There is not enough space to create\n" "neccessary startup files.\n" "\nFree up some space before\nentering data!") ); } abList = new AbTable( &orderedFields, this, "table" ); + vb->insertWidget(0,abList); abList->setHScrollBarMode( QScrollView::AlwaysOff ); connect( abList, SIGNAL( empty( bool ) ), this, SLOT( listIsEmpty( bool ) ) ); connect( abList, SIGNAL( details() ), this, SLOT( slotListView() ) ); connect( abList, SIGNAL(currentChanged(int,int)), this, SLOT(slotUpdateToolbar()) ); mView = 0; abList->load( addressbookXMLFilename() ); if ( QFile::exists(addressbookOldXMLFilename()) ) { abList->load( addressbookOldXMLFilename() ); QFile::remove(addressbookOldXMLFilename()); } + pLabel = new LetterPicker( abList ); + connect(pLabel, SIGNAL(letterClicked(char)), this, SLOT(slotSetLetter(char))); + vb->insertWidget(1,pLabel); catMenu = new QPopupMenu( this ); catMenu->setCheckable( TRUE ); connect( catMenu, SIGNAL(activated(int)), this, SLOT(slotSetCategory(int)) ); populateCategories(); mbList->insertItem( tr("View"), catMenu ); setCentralWidget( abList ); fontMenu = new QPopupMenu(this); fontMenu->setCheckable( true ); connect( fontMenu, SIGNAL(activated(int)), this, SLOT(slotSetFont(int))); fontMenu->insertItem(tr( "Small" ), 0); fontMenu->insertItem(tr( "Normal" ), 1); fontMenu->insertItem(tr( "Large" ), 2); defaultFont = new QFont( abList->font() ); slotSetFont(startFontSize); mbList->insertItem( tr("Font"), fontMenu); setCentralWidget(abList); // qDebug("adressbook contrsuction: t=%d", t.elapsed() ); } void AddressbookWindow::slotSetFont( int size ) { if (size > 2 || size < 0) size = 1; startFontSize = size; QFont *currentFont; switch (size) { case 0: fontMenu->setItemChecked(0, true); fontMenu->setItemChecked(1, false); fontMenu->setItemChecked(2, false); abList->setFont( QFont( defaultFont->family(), defaultFont->pointSize() - 2 ) ); currentFont = new QFont (abList->font()); abList->resizeRows(currentFont->pixelSize() + 7); break; case 1: fontMenu->setItemChecked(0, false); fontMenu->setItemChecked(1, true); fontMenu->setItemChecked(2, false); abList->setFont( *defaultFont ); @@ -839,70 +845,76 @@ AbLabel *AddressbookWindow::abView() { if ( !mView ) { mView = new AbLabel( this, "viewer" ); mView->init( Contact() ); connect( mView, SIGNAL( okPressed() ), this, SLOT( slotListView() ) ); } return mView; } void AddressbookWindow::slotFind() { #ifndef MAKE_FOR_SHARP_ROM if ( centralWidget() == abView() ) showList(); FindDialog frmFind( "Contacts", this ); QObject::connect( &frmFind, SIGNAL(signalFindClicked(const QString &, bool, bool, int)), abList, SLOT(slotDoFind( const QString&,bool,bool,int))); QObject::connect( abList, SIGNAL(signalNotFound()), &frmFind, SLOT(slotNotFound()) ); QObject::connect( abList, SIGNAL(signalWrapAround()), &frmFind, SLOT(slotWrapAround()) ); frmFind.exec(); if ( abList->numSelections() ) abList->clearSelection(); abList->clearFindRow(); #endif } void AddressbookWindow::slotSetCategory( int c ) { if ( c <= 0 ) return; for ( unsigned int i = 1; i < catMenu->count(); i++ ) catMenu->setItemChecked( i, c == (int)i ); if ( c == 1 ) { abList->setShowCategory( QString::null ); setCaption( tr("Contacts") + " - " + tr ( "All" ) ); } else if ( c == (int)catMenu->count() ) { abList->setShowCategory( tr( "Unfiled" ) ); setCaption( tr("Contacts") + " - " + tr( "Unfiled" ) ); } else { QString cat = abList->categories()[c - 2]; abList->setShowCategory( cat ); setCaption( tr("Contacts") + " - " + cat ); } } +void AddressbookWindow::slotSetLetter( char c ) { + + abList->setShowByLetter( c ); + +} + void AddressbookWindow::populateCategories() { catMenu->clear(); int id, rememberId; id = 1; catMenu->insertItem( tr( "All" ), id++ ); QStringList categories = abList->categories(); categories.append( tr( "Unfiled" ) ); for ( QStringList::Iterator it = categories.begin(); it != categories.end(); ++it ) { catMenu->insertItem( *it, id ); if ( *it == abList->showCategory() ) rememberId = id; ++id; } if ( abList->showCategory().isEmpty() ) slotSetCategory( 1 ); else slotSetCategory( rememberId ); } diff --git a/core/pim/addressbook/addressbook.h b/core/pim/addressbook/addressbook.h index e2a7100..31c4660 100644 --- a/core/pim/addressbook/addressbook.h +++ b/core/pim/addressbook/addressbook.h @@ -1,101 +1,104 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qt Palmtop 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 Addressbook_H #define Addressbook_H #include <qmainwindow.h> class ContactEditor; class AbLabel; class AbTable; class QPEToolBar; class QPopupMenu; class QToolButton; class QDialog; class Ir; class QAction; +class LetterPicker; class AddressbookWindow: public QMainWindow { Q_OBJECT public: AddressbookWindow( QWidget *parent = 0, const char *name = 0, WFlags f = 0 ); ~AddressbookWindow(); protected: void resizeEvent( QResizeEvent * e ); void showList(); void showView(); enum EntryMode { NewEntry=0, EditEntry }; void editPersonal(); void editEntry( EntryMode ); void closeEvent( QCloseEvent *e ); bool save(); public slots: void flush(); void reload(); void appMessage(const QCString &, const QByteArray &); void setDocument( const QString & ); private slots: void slotListNew(); void slotListView(); void slotListDelete(); void slotViewBack(); void slotViewEdit(); void slotPersonalView(); void listIsEmpty( bool ); void slotSettings(); void writeMail(); void slotBeam(); void beamDone( Ir * ); void slotFind(); void slotSetCategory( int ); + void slotSetLetter( char ); void slotUpdateToolbar(); void slotSetFont(int); private: void initFields(); // inititialize our fields... AbLabel *abView(); void populateCategories(); QPopupMenu *catMenu, *fontMenu; QPEToolBar *listTools; QToolButton *deleteButton; QValueList<int> allFields, orderedFields; QStringList slOrderedFields; enum Panes { paneList=0, paneView, paneEdit }; ContactEditor *abEditor; AbLabel *mView; + LetterPicker *pLabel; AbTable *abList; QAction *actionNew, *actionEdit, *actionTrash, *actionFind, *actionBeam, *actionPersonal, *actionMail; bool bAbEditFirstTime; int viewMargin; bool syncing; QFont *defaultFont; int startFontSize; }; #endif diff --git a/core/pim/addressbook/addressbook.pro b/core/pim/addressbook/addressbook.pro index 53cf030..0d65c74 100644 --- a/core/pim/addressbook/addressbook.pro +++ b/core/pim/addressbook/addressbook.pro @@ -1,33 +1,35 @@ TEMPLATE = app CONFIG = qt warn_on release DESTDIR = $(OPIEDIR)/bin HEADERS = addressbook.h \ contacteditor.h \ ablabel.h \ abtable.h \ - addresssettings.h + addresssettings.h \ + picker.h SOURCES = main.cpp \ addressbook.cpp \ contacteditor.cpp \ ablabel.cpp \ abtable.cpp \ - addresssettings.cpp + addresssettings.cpp \ + picker.cpp INTERFACES = addresssettingsbase.ui TARGET = addressbook INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe TRANSLATIONS = ../../i18n/pt_BR/addressbook.ts TRANSLATIONS += ../../i18n/de/addressbook.ts TRANSLATIONS += ../../i18n/en/addressbook.ts TRANSLATIONS += ../../i18n/hu/addressbook.ts TRANSLATIONS += ../../i18n/sl/addressbook.ts TRANSLATIONS += ../../i18n/ja/addressbook.ts TRANSLATIONS += ../../i18n/ko/addressbook.ts TRANSLATIONS += ../../i18n/pl/addressbook.ts TRANSLATIONS += ../../i18n/no/addressbook.ts TRANSLATIONS += ../../i18n/zh_CN/addressbook.ts TRANSLATIONS += ../../i18n/zh_TW/addressbook.ts TRANSLATIONS += ../../i18n/fr/addressbook.ts diff --git a/core/pim/addressbook/picker.cpp b/core/pim/addressbook/picker.cpp new file mode 100644 index 0000000..06dcc7d --- a/dev/null +++ b/core/pim/addressbook/picker.cpp @@ -0,0 +1,234 @@ +#include "picker.h" + +#include <qfont.h> +#include <qstring.h> +#include <qtimer.h> +#include <qlayout.h> + +char PickerLabel::lastLetter = '\0'; + +PickerLabel::PickerLabel( QWidget *parent, const char *name ) + : QLabel ( parent, name ) +{ + currentLetter = 0; + //lastLetter = 0; + + letter1 = '\0'; + letter2 = '\0'; + letter3 = '\0'; + + setFont( QFont( "smallsmooth", 9 ) ); + setTextFormat( Qt::RichText ); + +} + +PickerLabel::~PickerLabel() +{ + +} + +void PickerLabel::setLetters( char ch1, char ch2, char ch3 ) +{ + QString tmpStr; + + if (ch1 != '\0') + letter1 = ch1; + else + letter1 = ' '; + + if (ch2 != '\0') + letter2 = ch2; + else + letter2 = ' '; + + if (ch3 != '\0') + letter3 = ch3; + else + letter3 = ' '; + + tmpStr = "<qt>"; + tmpStr += letter1; + tmpStr += letter2; + tmpStr += letter3; + tmpStr += "</qt>"; + + setText(tmpStr); + + currentLetter = 0; + +} + +void PickerLabel::clearLetter() +{ + + QString tmpStr; + + tmpStr = "<qt>"; + tmpStr += letter1; + tmpStr += letter2; + tmpStr += letter3; + tmpStr += "</qt>"; + + setText(tmpStr); + + currentLetter = 0; + +} + +void PickerLabel::mouseReleaseEvent( QMouseEvent *e ) +{ + QString tmpStr; + + if (lastLetter != letter1 && lastLetter != letter2 && lastLetter != letter3) + QTimer::singleShot( 0, this, SLOT(emitClearSignal()) ); + + qDebug( "a" ); + switch (currentLetter) { + case 0: + tmpStr = "<qt><font color=\"#7F0000\">"; + tmpStr += letter1; + tmpStr += "</font>"; + tmpStr += letter2; + tmpStr += letter3; + tmpStr += "</qt>"; + + setText(tmpStr); + + currentLetter++; + lastLetter = letter1; + emit selectedLetter( letter1 ); + qDebug( "PickerLabel::mouseReleaseEvent %c", letter1 ); + break; + + case 1: + tmpStr = "<qt>"; + tmpStr += letter1; + tmpStr += "<font color=\"#7F0000\">"; + tmpStr += letter2; + tmpStr += "</font>"; + tmpStr += letter3; + tmpStr += "</qt>"; + + setText(tmpStr); + + currentLetter++; + lastLetter = letter2; + emit selectedLetter( letter2 ); + qDebug( "PickerLabel::mouseReleaseEvent %c", letter2 ); + break; + + case 2: + tmpStr = "<qt>"; + tmpStr += letter1; + tmpStr += letter2; + tmpStr += "<font color=\"#7F0000\">"; + tmpStr += letter3; + tmpStr += "</font></qt>"; + + setText(tmpStr); + + currentLetter++; + lastLetter = letter3; + emit selectedLetter( letter3 ); + qDebug( "PickerLabel::mouseReleaseEvent %c", letter3 ); + break; + + default: + clearLetter(); + lastLetter = '\0'; + emit selectedLetter( '\0' ); + + + } +} + +void PickerLabel::emitClearSignal() { + emit clearAll(); +} + +LetterPicker::LetterPicker( QWidget *parent, const char *name ) + : QFrame( parent, name ) +{ + QHBoxLayout *l = new QHBoxLayout(this); + + lblABC = new PickerLabel( this ); + l->addWidget( lblABC ); + + lblDEF = new PickerLabel( this ); + l->addWidget( lblDEF ); + + lblGHI = new PickerLabel( this ); + l->addWidget( lblGHI ); + + lblJKL = new PickerLabel( this ); + l->addWidget( lblJKL ); + + lblMNO = new PickerLabel( this ); + l->addWidget( lblMNO ); + + lblPQR = new PickerLabel( this ); + l->addWidget( lblPQR ); + + lblSTU = new PickerLabel( this ); + l->addWidget( lblSTU ); + + lblVWX = new PickerLabel( this ); + l->addWidget( lblVWX ); + + lblYZ = new PickerLabel( this ); + l->addWidget( lblYZ ); + + lblABC->setLetters( 'A', 'B', 'C' ); + lblDEF->setLetters( 'D', 'E', 'F' ); + lblGHI->setLetters( 'G', 'H', 'I' ); + lblJKL->setLetters( 'J', 'K', 'L' ); + lblMNO->setLetters( 'M', 'N', 'O' ); + lblPQR->setLetters( 'P', 'Q', 'R' ); + lblSTU->setLetters( 'S', 'T', 'U' ); + lblVWX->setLetters( 'V', 'W', 'X' ); + lblYZ->setLetters( 'Y', 'Z', '#' ); + + connect(lblABC, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblDEF, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblGHI, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblJKL, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblMNO, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblPQR, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblSTU, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblVWX, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblYZ, SIGNAL(selectedLetter(char)), this, SLOT(newLetter(char))); + connect(lblABC, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblDEF, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblGHI, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblJKL, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblMNO, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblPQR, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblSTU, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblVWX, SIGNAL(clearAll()), this, SLOT(clear())); + connect(lblYZ, SIGNAL(clearAll()), this, SLOT(clear())); + +} + +LetterPicker::~LetterPicker() +{ +} + +void LetterPicker::clear() +{ + lblABC->clearLetter(); + lblDEF->clearLetter(); + lblGHI->clearLetter(); + lblJKL->clearLetter(); + lblMNO->clearLetter(); + lblPQR->clearLetter(); + lblSTU->clearLetter(); + lblVWX->clearLetter(); + lblYZ->clearLetter(); +} + +void LetterPicker::newLetter( char letter ) +{ + qDebug( "LetterPicker::newLetter %c", letter ); + emit letterClicked( letter ); + +} diff --git a/core/pim/addressbook/picker.h b/core/pim/addressbook/picker.h new file mode 100644 index 0000000..de5bd9d --- a/dev/null +++ b/core/pim/addressbook/picker.h @@ -0,0 +1,65 @@ +/* + * Letter Chooser Widget. + * + * (c) 2002 Mike Crawford + * + * This file is FREE SOFTWARE covered under the GUN General Public License. + * + * +*/ +#ifndef PICKER_H +#define PICKER_H + +#include <qlabel.h> +#include <qframe.h> +#include <qevent.h> + +class PickerLabel: public QLabel { +Q_OBJECT + public: + PickerLabel( QWidget *parent = 0, const char *name = 0 ); + ~PickerLabel(); + + void setLetters( char ch1, char ch2, char ch3 ); + void clearLetter(); + + signals: + + void selectedLetter( char ); + void clearAll(); + + protected: + + void mouseReleaseEvent( QMouseEvent *e ); + + private: + + int currentLetter; + static char lastLetter; + char letter1, letter2, letter3; + + private slots: + + void emitClearSignal(); + +}; +class LetterPicker: public QFrame { +Q_OBJECT + public: + LetterPicker( QWidget *parent = 0, const char *name = 0 ); + ~LetterPicker(); + + public slots: + void clear(); + + signals: + void letterClicked( char ); + + private: + PickerLabel *lblABC, *lblDEF, *lblGHI, *lblJKL, *lblMNO, *lblPQR, *lblSTU, *lblVWX, *lblYZ; + + private slots: + void newLetter( char letter ); +}; + +#endif |