author | zautrix <zautrix> | 2005-03-30 23:17:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-03-30 23:17:42 (UTC) |
commit | 529c0fb8a8bf15e7bd375ddeb355c5802baf4c93 (patch) (side-by-side diff) | |
tree | 72ebca6de7e54f2cf89d3d6df61d3b40aa66a444 /kaddressbook | |
parent | 28ac86e2efbc10f210dbd2d5ac0053f4e6198d57 (diff) | |
download | kdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.zip kdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.tar.gz kdepimpi-529c0fb8a8bf15e7bd375ddeb355c5802baf4c93.tar.bz2 |
key fix
-rw-r--r-- | kaddressbook/kaddressbookview.cpp | 2 | ||||
-rw-r--r-- | kaddressbook/kaddressbookview.h | 2 | ||||
-rw-r--r-- | kaddressbook/views/cardview.cpp | 31 | ||||
-rw-r--r-- | kaddressbook/views/cardview.h | 5 | ||||
-rw-r--r-- | kaddressbook/views/contactlistview.cpp | 29 | ||||
-rw-r--r-- | kaddressbook/views/contactlistview.h | 4 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbookcardview.cpp | 4 | ||||
-rw-r--r-- | kaddressbook/views/kaddressbooktableview.cpp | 4 |
8 files changed, 79 insertions, 2 deletions
diff --git a/kaddressbook/kaddressbookview.cpp b/kaddressbook/kaddressbookview.cpp index 09859c2..86898e2 100644 --- a/kaddressbook/kaddressbookview.cpp +++ b/kaddressbook/kaddressbookview.cpp @@ -160,27 +160,29 @@ KAddressBookView::DefaultFilterType KAddressBookView::defaultFilterType() const } const QString &KAddressBookView::defaultFilterName() const { return mDefaultFilterName; } KABC::AddressBook *KAddressBookView::addressBook() const { return mAddressBook; } QWidget *KAddressBookView::viewWidget() { return mViewWidget; } ViewConfigureWidget *ViewFactory::configureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name ) { return new ViewConfigureWidget( ab, parent, name ); } + + #ifndef KAB_EMBEDDED #include "kaddressbookview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/kaddressbookview.h b/kaddressbook/kaddressbookview.h index 6bbb9c2..3a3f71a 100644 --- a/kaddressbook/kaddressbookview.h +++ b/kaddressbook/kaddressbookview.h @@ -210,48 +210,49 @@ class KAddressBookView : public QWidget is executed. This is defined by the KDE system wide config, but it either means single or doubleclicked. @param ui The uid of the selected addressee @see KListView */ void executed( const QString &uid ); /** This signal is emitted whenever a user attempts to start a drag in the view. The slot connected to this signal would usually want to create a QDragObject. */ void startDrag(); /** This signal is emitted whenever the user drops something on the view. The individual view should handle checking if the item is droppable (ie: if it is a vcard). */ void dropped( QDropEvent* ); protected: + /** Returns a list of the addressees that should be displayed. This method should always be used by the subclass to get a list of addressees. This method internally takes many factors into account, including the current filter. */ KABC::Addressee::List addressees(); /** This method returns the widget that should be used as the parent for all view components. By using this widget as the parent and not 'this', the view subclass has the option of placing other widgets around the view (ie: search fields, etc). Do not delete this widget! */ QWidget *viewWidget(); QRegExp getRegExp( const QString ); private: void initGUI(); DefaultFilterType mDefaultFilterType; Filter mFilter; QString mDefaultFilterName; KABC::AddressBook *mAddressBook; @@ -285,28 +286,29 @@ class ViewFactory describing the features offered by the view. */ virtual QString description() const = 0; /** Creates a config dialog for the view type. The default implementation will return a ViewConfigDialog. This default dialog will allow the user to set the visible fields only. If you need more config options (as most views will), this method can be overloaded to return your sublcass of ViewConfigDialog. If this method is over loaded the base classes method should <B>not</B> be called. */ virtual ViewConfigureWidget *configureWidget( KABC::AddressBook *ab, QWidget *parent, const char *name = 0 ); protected: virtual QObject* createObject( QObject*, const char*, const char*, const QStringList & ) { return 0; } + }; #endif diff --git a/kaddressbook/views/cardview.cpp b/kaddressbook/views/cardview.cpp index 03df444..84d3116 100644 --- a/kaddressbook/views/cardview.cpp +++ b/kaddressbook/views/cardview.cpp @@ -12,48 +12,49 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ //BEGIN Includes #include "cardview.h" #include <limits.h> #include <qpainter.h> #include <qtimer.h> #include <qdatetime.h> #include <qlabel.h> #include <qstyle.h> #include <qcursor.h> #include <qtooltip.h> +#include <qapplication.h> #include "kabprefs.h" #include <kdebug.h> #include <kglobalsettings.h> //END includes #define MIN_ITEM_WIDTH 80 //BEGIN Helpers ////////////////////////////////////// // CardViewTip class CardViewTip : public QLabel { public: CardViewTip(QWidget *parent=0, const char *name=0) : QLabel( parent, name ) { setPalette( QToolTip::palette() ); setFrameStyle( Panel|Plain ); setMidLineWidth(0); setIndent(1); } ~CardViewTip() {}; protected: void leaveEvent( QEvent * ) @@ -618,48 +619,50 @@ CardViewItem::Field *CardViewItem::fieldAt( const QPoint & itempos ) const if ( iy <= ypos ) return 0; // try find a field bool showEmpty = mView->showEmptyFields(); int fh = mView->d->mFm->height(); int maxLines = mView->maxFieldLines(); Field *f; for ( f = d->mFieldList.first(); f; f = d->mFieldList.next() ) { if ( showEmpty || !f->second.isEmpty() ) ypos += ( QMIN( f->second.contains('\n')+1, maxLines ) *fh)+2; if ( iy <= ypos ) break; } return f ? f : 0; } //END CardViewItem //BEGIN CardView CardView::CardView(QWidget *parent, const char *name) : QScrollView(parent, name), d(new CardViewPrivate()) { + mFlagKeyPressed = false; + mFlagBlockKeyPressed = false; d->mItemList.setAutoDelete(true); d->mSeparatorList.setAutoDelete(true); QFont f = font(); d->mFm = new QFontMetrics(f); f.setBold(true); d->mHeaderFont = f; d->mBFm = new QFontMetrics(f); d->mTip = ( new CardViewTip( viewport() ) ), d->mTip->hide(); d->mTimer = ( new QTimer(this, "mouseTimer") ), viewport()->setMouseTracking( true ); viewport()->setFocusProxy(this); viewport()->setFocusPolicy(WheelFocus); viewport()->setBackgroundMode(PaletteBase); connect( d->mTimer, SIGNAL(timeout()), this, SLOT(tryShowFullText()) ); //US setBackgroundMode(PaletteBackground, PaletteBase); setBackgroundMode(PaletteBackground); // no reason for a vertical scrollbar setVScrollBarMode(AlwaysOff); @@ -1330,49 +1333,57 @@ void CardView::focusInEvent( QFocusEvent * ) { if (!d->mCurrentItem && d->mItemList.count() ) { setCurrentItem( d->mItemList.first() ); } else if ( d->mCurrentItem ) { d->mCurrentItem->repaintCard(); } } void CardView::focusOutEvent( QFocusEvent * ) { if (d->mCurrentItem) d->mCurrentItem->repaintCard(); } void CardView::keyPressEvent( QKeyEvent *e ) { if ( ! ( childCount() && d->mCurrentItem ) ) { e->ignore(); return; } - + if ( mFlagBlockKeyPressed ) + return; + qApp->processEvents(); + if ( e->isAutoRepeat() && !mFlagKeyPressed ) { + e->accept(); + return; + } + if (! e->isAutoRepeat() ) + mFlagKeyPressed = true; uint pos = d->mItemList.findRef( d->mCurrentItem ); CardViewItem *aItem = 0L; // item that gets the focus CardViewItem *old = d->mCurrentItem; switch ( e->key() ) { case Key_Up: if ( pos > 0 ) { aItem = d->mItemList.at( pos - 1 ); setCurrentItem( aItem ); } break; case Key_Down: if ( pos < d->mItemList.count() - 1 ) { aItem = d->mItemList.at( pos + 1 ); setCurrentItem( aItem ); } break; case Key_Left: { // look for an item in the previous/next column, starting from // the vertical middle of the current item. @@ -1694,29 +1705,47 @@ void CardView::setFont( const QFont &fnt ) d->mFm = new QFontMetrics( fnt ); } int CardView::separatorWidth() { return d->mSepWidth; } void CardView::setSeparatorWidth( int width ) { d->mSepWidth = width; setLayoutDirty( true ); // hmm, actually I could just adjust the x'es... } int CardView::maxFieldLines() const { return d->mMaxFieldLines; } void CardView::setMaxFieldLines( int howmany ) { d->mMaxFieldLines = howmany ? howmany : INT_MAX; // FIXME update, forcing the items to recalc height!! } + +void CardView::keyReleaseEvent ( QKeyEvent * e ) +{ + if ( mFlagBlockKeyPressed ) + return; + if ( !e->isAutoRepeat() ) { + mFlagBlockKeyPressed = true; + qApp->processEvents(); + mFlagBlockKeyPressed = false; + mFlagKeyPressed = false; + } + QScrollView::keyReleaseEvent ( e ); +} + + + + + //END Cardview #ifndef KAB_EMBEDDED #include "cardview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/views/cardview.h b/kaddressbook/views/cardview.h index 37dddb6..2ea3771 100644 --- a/kaddressbook/views/cardview.h +++ b/kaddressbook/views/cardview.h @@ -385,87 +385,90 @@ class CardView : public QScrollView /** This method is emitted whenever an item is clicked. */ void clicked(CardViewItem *); /** Emitted whenever the user 'executes' an item. This is dependant on * the KDE global config. This could be a single click or a doubleclick. * Also emitted when the return key is pressed on an item. */ void executed(CardViewItem *); /** Emitted whenever the user double clicks on an item. */ void doubleClicked(CardViewItem *); /** Emitted when the current item changes */ void currentChanged( CardViewItem * ); /** Emitted when the return key is pressed in an item. */ void returnPressed( CardViewItem * ); protected: + bool mFlagKeyPressed; + bool mFlagBlockKeyPressed; + virtual void keyPressEvent ( QKeyEvent * ); + virtual void keyReleaseEvent ( QKeyEvent * ); /** Determines which cards intersect that region and tells them to paint * themselves. */ void drawContents(QPainter *p, int clipx, int clipy, int clipw, int cliph); /** Sets the layout to dirty and repaints. */ void resizeEvent(QResizeEvent *e); /** Changes the direction the canvas scolls. */ void contentsWheelEvent(QWheelEvent *e); /** Sets the layout to dirty and calls for a repaint. */ void setLayoutDirty(bool dirty); /** Does the math based on the bounding rect of the cards to properly * lay the cards out on the screen. This is only done if the layout is * marked as dirty. */ void calcLayout(); // virtual void mousePressEvent(QMouseEvent *e); // virtual void mouseReleaseEvent(QMouseEvent *e); // virtual void mouseMoveEvent(QMouseEvent *e); virtual void contentsMousePressEvent(QMouseEvent *e); virtual void contentsMouseMoveEvent(QMouseEvent *e); virtual void contentsMouseReleaseEvent(QMouseEvent *e); virtual void contentsMouseDoubleClickEvent(QMouseEvent *e); virtual void enterEvent( QEvent * ); virtual void leaveEvent( QEvent * ); virtual void focusInEvent( QFocusEvent * ); virtual void focusOutEvent( QFocusEvent * ); - virtual void keyPressEvent( QKeyEvent * ); /** Overload this method to be told when a drag should be started. * In most cases you will want to start a drag event with the currently * selected item. */ virtual void startDrag(); private slots: /** Called by a timer to display a label with truncated text. * Pop up a label, if there is a field with obscured text or * label at the cursor position. */ void tryShowFullText(); private: /** draws and erases the rubber bands while columns are resized. * @p pos is the horizontal position inside the viewport to use as * the anchor. * If pos is 0, only erase is done. */ void drawRubberBands( int pos ); CardViewPrivate *d; }; diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp index e75810e..09d9c03 100644 --- a/kaddressbook/views/contactlistview.cpp +++ b/kaddressbook/views/contactlistview.cpp @@ -8,48 +8,49 @@ (at your option) any later version. 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include <qheader.h> #include <qiconset.h> #include <qimage.h> #include <qdragobject.h> #include <qcombobox.h> #include <qpainter.h> #include <qbrush.h> #include <qevent.h> +#include <qapplication.h> #include <klocale.h> #include <kglobalsettings.h> #include <kiconloader.h> #include <kdebug.h> #include <kconfig.h> #include <kapplication.h> #include <kurl.h> #include "kaddressbooktableview.h" #include "contactlistview.h" ///////////////////////////////// // DynamicTip Methods DynamicTip::DynamicTip( ContactListView *parent) : QToolTip( parent ) { } void DynamicTip::maybeTip( const QPoint &pos ) { static bool ishidden = true; @@ -227,48 +228,50 @@ void ContactListViewItem::refresh() { // Update our addressee, since it may have changed else were mAddressee = mDocument->findByUid(mAddressee.uid()); if (mAddressee.isEmpty()) return; int i = 0; KABC::Field::List::ConstIterator it; for( it = mFields.begin(); it != mFields.end(); ++it ) { setText( i++, (*it)->value( mAddressee ) ); } } /////////////////////////////// // ContactListView ContactListView::ContactListView(KAddressBookTableView *view, KABC::AddressBook* /* doc */, QWidget *parent, const char *name ) : KListView( parent, name ), pabWidget( view ), oldColumn( 0 ) { + mFlagBlockKeyPressed = false; + mFlagKeyPressed = false; mABackground = true; mSingleLine = false; mToolTips = true; #ifndef KAB_EMBEDDED mAlternateColor = KGlobalSettings::alternateBackgroundColor(); #else //KAB_EMBEDDED mAlternateColor = QColor(240, 240, 240); #endif //KAB_EMBEDDED setAlternateBackgroundEnabled(mABackground); setAcceptDrops( true ); viewport()->setAcceptDrops( true ); setAllColumnsShowFocus( true ); setShowSortIndicator(true); setSelectionModeExt( KListView::Extended ); setDropVisualizer(false); // setFrameStyle(QFrame::NoFrame); //setLineWidth ( 0 ); //setMidLineWidth ( 0 ); //setMargin ( 0 ); #ifndef KAB_EMBEDDED connect(this, SIGNAL(dropped(QDropEvent*)), this, SLOT(itemDropped(QDropEvent*))); @@ -374,27 +377,53 @@ void ContactListView::setAlternateBackgroundEnabled(bool enabled) if (mABackground) { setAlternateBackground(mAlternateColor); } else { setAlternateBackground(QColor()); } } void ContactListView::setBackgroundPixmap(const QString &filename) { if (filename.isEmpty()) { unsetPalette(); } else { qDebug("ContactListView::setBackgroundPixmap has to be verified"); //US setPaletteBackgroundPixmap(QPixmap(filename)); KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); } } + +void ContactListView::keyPressEvent ( QKeyEvent * e ) +{ + if ( mFlagBlockKeyPressed ) + return; + qApp->processEvents(); + if ( e->isAutoRepeat() && !mFlagKeyPressed ) { + e->accept(); + return; + } + if (! e->isAutoRepeat() ) + mFlagKeyPressed = true; + KListView::keyPressEvent ( e ); +} +void ContactListView::keyReleaseEvent ( QKeyEvent * e ) +{ + if ( mFlagBlockKeyPressed ) + return; + if ( !e->isAutoRepeat() ) { + mFlagBlockKeyPressed = true; + qApp->processEvents(); + mFlagBlockKeyPressed = false; + mFlagKeyPressed = false; + } + KListView::keyReleaseEvent ( e ); +} #ifndef KAB_EMBEDDED #include "contactlistview.moc" #endif //KAB_EMBEDDED diff --git a/kaddressbook/views/contactlistview.h b/kaddressbook/views/contactlistview.h index 9d1a672..46477e1 100644 --- a/kaddressbook/views/contactlistview.h +++ b/kaddressbook/views/contactlistview.h @@ -71,48 +71,52 @@ public: virtual ~ContactListView() {} //void resort(); /** Returns true if tooltips should be displayed, false otherwise */ bool tooltips() const { return mToolTips; } void setToolTipsEnabled(bool enabled) { mToolTips = enabled; } bool alternateBackground() const { return mABackground; } void setAlternateBackgroundEnabled(bool enabled); bool singleLine() const { return mSingleLine; } void setSingleLineEnabled(bool enabled) { mSingleLine = enabled; } const QColor &alternateColor() const { return mAlternateColor; } void setAlternateColor(const QColor &mAlternateColor); /** Sets the background pixmap to <i>filename</i>. If the * QString is empty (QString::isEmpty()), then the background * pixmap will be disabled. */ void setBackgroundPixmap(const QString &filename); protected: + bool mFlagKeyPressed; + bool mFlagBlockKeyPressed; + virtual void keyPressEvent ( QKeyEvent * ); + virtual void keyReleaseEvent ( QKeyEvent * ); /** Paints the background pixmap in the empty area. This method is needed * since Qt::FixedPixmap will not scroll with the list view. */ virtual void paintEmptyArea( QPainter * p, const QRect & rect ); virtual void contentsMousePressEvent(QMouseEvent*); void contentsMouseMoveEvent( QMouseEvent *e ); void contentsDropEvent( QDropEvent *e ); virtual bool acceptDrag(QDropEvent *e) const; protected slots: void itemDropped(QDropEvent *e); public slots: void printMe(); signals: void startAddresseeDrag(); void addresseeDropped(QDropEvent *); private: KAddressBookTableView *pabWidget; int oldColumn; int column; bool ascending; diff --git a/kaddressbook/views/kaddressbookcardview.cpp b/kaddressbook/views/kaddressbookcardview.cpp index cce68b9..9c35fd6 100644 --- a/kaddressbook/views/kaddressbookcardview.cpp +++ b/kaddressbook/views/kaddressbookcardview.cpp @@ -187,54 +187,58 @@ KAddressBookCardView::KAddressBookCardView( KABC::AddressBook *ab, this, SLOT(addresseeExecuted(CardViewItem *))); connect(mCardView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); connect(mCardView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); connect(mCardView, SIGNAL(startAddresseeDrag()), this, SIGNAL(startDrag())); connect(this, SIGNAL(printView()), mCardView , SLOT(printMe())); } KAddressBookCardView::~KAddressBookCardView() { } void KAddressBookCardView::setFocusAV() { if ( mCardView ) mCardView->setFocus(); } void KAddressBookCardView::scrollUP() { QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); QApplication::postEvent( mCardView, ev ); + ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mCardView, ev ); } void KAddressBookCardView::scrollDOWN() { QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); QApplication::postEvent( mCardView, ev ); + ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mCardView, ev ); } void KAddressBookCardView::readConfig(KConfig *config) { KAddressBookView::readConfig(config); // costum colors? if ( config->readBoolEntry( "EnableCustomColors", false ) ) { QPalette p( mCardView->palette() ); QColor c = p.color(QPalette::Normal, QColorGroup::Base ); p.setColor( QPalette::Normal, QColorGroup::Base, config->readColorEntry( "BackgroundColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Text ); p.setColor( QPalette::Normal, QColorGroup::Text, config->readColorEntry( "TextColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Button ); p.setColor( QPalette::Normal, QColorGroup::Button, config->readColorEntry( "HeaderColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::ButtonText ); p.setColor( QPalette::Normal, QColorGroup::ButtonText, config->readColorEntry( "HeaderTextColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::Highlight ); p.setColor( QPalette::Normal, QColorGroup::Highlight, config->readColorEntry( "HighlightColor", &c ) ); c = p.color(QPalette::Normal, QColorGroup::HighlightedText ); p.setColor( QPalette::Normal, QColorGroup::HighlightedText, config->readColorEntry( "HighlightedTextColor", &c ) ); mCardView->viewport()->setPalette( p ); } else diff --git a/kaddressbook/views/kaddressbooktableview.cpp b/kaddressbook/views/kaddressbooktableview.cpp index f4b008c..e322473 100644 --- a/kaddressbook/views/kaddressbooktableview.cpp +++ b/kaddressbook/views/kaddressbooktableview.cpp @@ -40,53 +40,57 @@ KAddressBookTableView::KAddressBookTableView( KABC::AddressBook *ab, QWidget *parent, const char *name ) : KAddressBookView( ab, parent, name ) { mainLayout = new QVBoxLayout( viewWidget(), 2 ); // The list view will be created when the config is read. mListView = 0; } KAddressBookTableView::~KAddressBookTableView() { } void KAddressBookTableView::setFocusAV() { if ( mListView ) mListView->setFocus(); } void KAddressBookTableView::scrollUP() { QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Up, 0,0 ); QApplication::postEvent( mListView, ev ); + ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Up, 0,0 ); + QApplication::postEvent( mListView, ev ); } void KAddressBookTableView::scrollDOWN() { QKeyEvent * ev = new QKeyEvent ( QEvent::KeyPress, Qt::Key_Down, 0,0 ); QApplication::postEvent( mListView, ev ); + ev = new QKeyEvent ( QEvent::KeyRelease, Qt::Key_Down, 0,0 ); + QApplication::postEvent( mListView, ev ); } void KAddressBookTableView::reconstructListView() { if (mListView) { disconnect(mListView, SIGNAL(selectionChanged()), this, SLOT(addresseeSelected())); disconnect(mListView, SIGNAL(executed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(doubleClicked(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(startAddresseeDrag()), this, SIGNAL(startDrag())); disconnect(mListView, SIGNAL(returnPressed(QListViewItem*)), this, SLOT(addresseeExecuted(QListViewItem*))); disconnect(mListView, SIGNAL(addresseeDropped(QDropEvent*)), this, SIGNAL(dropped(QDropEvent*))); delete mListView; } mListView = new ContactListView( this, addressBook(), viewWidget() ); connect(this, SIGNAL(printView()), |