kexi

kexitableview.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Till Busch <till@bux.at>
00003    Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at>
00004    Copyright (C) 2003 Daniel Molkentin <molkentin@kde.org>
00005    Copyright (C) 2003 Joseph Wenninger <jowenn@kde.org>
00006    Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
00007 
00008    This program is free software; you can redistribute it and,or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public License
00019    along with this program; see the file COPYING.  If not, write to
00020    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022 
00023    Original Author:  Till Busch <till@bux.at>
00024    Original Project: buX (www.bux.at)
00025 */
00026 
00027 #ifndef KEXITABLEVIEW_H
00028 #define KEXITABLEVIEW_H
00029 
00030 //we want to have kde-support:
00031 #define USE_KDE
00032 
00033 #include <qscrollview.h>
00034 #include <qtimer.h>
00035 #include <qvariant.h>
00036 #include <qptrlist.h>
00037 #include <qheader.h>
00038 
00039 #include <kdebug.h>
00040 
00041 #include "kexitableviewdata.h"
00042 #include "kexitableedit.h"
00043 #include <kexiutils/tristate.h>
00044 #include <widget/utils/kexirecordnavigator.h>
00045 #include <widget/utils/kexisharedactionclient.h>
00046 #include "kexidataawareobjectiface.h"
00047 
00048 class KPopupMenu;
00049 class KPrinter;
00050 class KAction;
00051 
00052 class KexiTableHeader;
00053 class KexiTableItem;
00054 class KexiTableEdit;
00055 class KexiTableViewPrivate;
00056 class KActionCollection;
00057 
00058 namespace KexiDB {
00059     class RowEditBuffer;
00060 }
00061 
00063 #define KEXITV_MINIMUM_COLUMN_WIDTH 10
00064 
00066 
00068 class KEXIDATATABLE_EXPORT KexiTableView :
00069     public QScrollView,
00070     public KexiRecordNavigatorHandler,
00071     public KexiSharedActionClient,
00072     public KexiDataAwareObjectInterface
00073 {
00074 Q_OBJECT
00075 KEXI_DATAAWAREOBJECTINTERFACE
00076 public:
00077 
00079     class KEXIDATATABLE_EXPORT Appearance {
00080     public:
00081         Appearance(QWidget *widget = 0);
00082 
00085         QColor baseColor;
00086 
00089         QColor textColor;
00090 
00092         QColor borderColor;
00093 
00096         QColor emptyAreaColor;
00097 
00099         QColor alternateBackgroundColor;
00100 
00102         bool backgroundAltering : 1;
00103 
00109         bool fullRowSelection : 1;
00110 
00114         bool gridEnabled : 1;
00115 
00118         bool navigatorEnabled : 1;
00119 
00121         bool rowHighlightingEnabled : 1;
00122 
00124         bool rowMouseOverHighlightingEnabled : 1;
00125 
00130         bool persistentSelections : 1;
00131 
00134         QColor rowHighlightingColor;
00135 
00138         QColor rowHighlightingTextColor;
00139 
00142         QColor rowMouseOverHighlightingColor;
00143 
00146         QColor rowMouseOverHighlightingTextColor;
00147 
00150         QColor rowMouseOverAlternateHighlightingColor;
00151     };
00152     
00153     KexiTableView(KexiTableViewData* data=0, QWidget* parent=0, const char* name=0);
00154     virtual ~KexiTableView();
00155 
00157     Appearance appearance() const;
00158 
00160     void setAppearance(const Appearance& a);
00161 
00163     QString columnCaption(int colNum) const;
00164 
00167     KexiDB::Field* field(int colNum) const;
00168 
00170     virtual void setSpreadSheetMode();
00171 
00173     bool scrollbarToolTipsEnabled() const;
00174 
00176     void setScrollbarToolTipsEnabled(bool set);
00177 
00180     virtual int rowsPerPage() const;
00181 
00182     QRect cellGeometry(int row, int col) const;
00183     int columnWidth(int col) const;
00184     int rowHeight() const;
00185     int columnPos(int col) const;
00186     int rowPos(int row) const;
00187     int columnAt(int pos) const;
00188     int rowAt(int pos, bool ignoreEnd=false) const;
00189 
00191     virtual void updateCell(int row, int col);
00192 
00194     virtual void updateRow(int row);
00195 
00196     bool editableOnDoubleClick() const;
00197     void setEditableOnDoubleClick(bool set);
00198 
00200     bool verticalHeaderVisible() const;
00202     void setVerticalHeaderVisible(bool set);
00203 
00205     bool horizontalHeaderVisible() const;
00206 
00208     void setHorizontalHeaderVisible(bool set);
00209 
00210 #ifndef KEXI_NO_PRINT
00211     // printing
00212 //  void        setupPrinter(KPrinter &printer);
00213     void        print(KPrinter &printer);
00214 #endif
00215 
00216     // reimplemented for internal reasons
00217     virtual QSizePolicy sizePolicy() const;
00218     virtual QSize sizeHint() const;
00219     virtual QSize minimumSizeHint() const;
00220 
00222     void setFont(const QFont &f);
00223 
00224     virtual QSize tableSize() const;
00225 
00226     void emitSelected();
00227 
00229     void triggerUpdate();
00230 
00231     typedef enum ScrollDirection
00232     {
00233         ScrollUp,
00234         ScrollDown,
00235         ScrollLeft,
00236         ScrollRight
00237     };
00238 
00239     virtual bool eventFilter( QObject *o, QEvent *e );
00240 
00242     static void initCellEditorFactories();
00243 
00247     int highlightedRow() const;
00248 
00249     KexiTableItem *highlightedItem() const;
00250 
00251 
00252 public slots:
00253     virtual void setData( KexiTableViewData *data, bool owner = true )
00254         { KexiDataAwareObjectInterface::setData( data, owner ); }
00255 
00256     virtual void clearColumnsInternal(bool repaint);
00257 
00260     void adjustColumnWidthToContents(int colNum = -1);
00261 
00263     void setColumnWidth(int col, int width);
00264 
00269     void setColumnStretchEnabled( bool set, int colNum );
00270 
00275     void maximizeColumnsWidth( const QValueList<int> &columnList );
00276 
00280     void adjustHorizontalHeaderSize();
00281 
00285     void setHighlightedRow(int row);
00286 
00288     inline void clearHighlightedRow() { setHighlightedRow(-1); }
00289 
00293     virtual void ensureCellVisible(int row, int col/*=-1*/);
00294 
00295 //  void            gotoNext();
00296 //js    int         findString(const QString &string);
00297     
00301     void deleteCurrentRow() { KexiDataAwareObjectInterface::deleteCurrentRow(); }
00302 
00311     KexiTableItem *insertEmptyRow(int row = -1) 
00312         { return KexiDataAwareObjectInterface::insertEmptyRow(row); }
00313 
00319     void startEditCurrentCell(const QString& setText = QString::null)
00320         { KexiDataAwareObjectInterface::startEditCurrentCell(setText); }
00321 
00324     void deleteAndStartEditCurrentCell() 
00325         { KexiDataAwareObjectInterface::deleteAndStartEditCurrentCell(); }
00326 
00329     void cancelRowEdit() { KexiDataAwareObjectInterface::cancelRowEdit(); }
00330 
00335     bool acceptRowEdit() { return KexiDataAwareObjectInterface::acceptRowEdit(); }
00336 
00340     void setAcceptsRowEditAfterCellAccepting(bool set) 
00341         { KexiDataAwareObjectInterface::setAcceptsRowEditAfterCellAccepting(set); }
00342 
00349     void setDropsAtRowEnabled(bool set) { KexiDataAwareObjectInterface::setDropsAtRowEnabled(set); }
00350 
00351     void cancelEditor() { KexiDataAwareObjectInterface::cancelEditor(); }
00352     virtual bool acceptEditor() { return KexiDataAwareObjectInterface::acceptEditor(); }
00353 
00354 signals:
00355     virtual void dataSet( KexiTableViewData *data );
00356 
00357     virtual void itemSelected(KexiTableItem *);
00358     virtual void cellSelected(int col, int row);
00359 
00360     void itemReturnPressed(KexiTableItem *, int row, int col);
00361     void itemDblClicked(KexiTableItem *, int row, int col);
00362     void itemMouseReleased(KexiTableItem *, int row, int col);
00363 
00364     void dragOverRow(KexiTableItem *item, int row, QDragMoveEvent* e);
00365     void droppedAtRow(KexiTableItem *item, int row, QDropEvent *e, KexiTableItem*& newItem);
00366 
00368     virtual void dataRefreshed();
00369 
00370     virtual void itemChanged(KexiTableItem *, int row, int col);
00371     virtual void itemChanged(KexiTableItem *, int row, int col, QVariant oldValue);
00372     virtual void itemDeleteRequest(KexiTableItem *, int row, int col);
00373     virtual void currentItemDeleteRequest();
00374     void addRecordRequest();
00375 //  void contextMenuRequested(KexiTableItem *,  int row, int col, const QPoint &);
00376     void sortedColumnChanged(int col);
00377 
00379     void rowEditStarted(int row);
00380 
00383     void rowEditTerminated(int row);
00384 
00387     void reloadActions();
00388 
00389 protected slots:
00390     void slotSettingsChanged(int category);
00391 
00392     virtual void slotDataDestroying() { KexiDataAwareObjectInterface::slotDataDestroying(); }
00393 
00394     virtual void slotRowsDeleted( const QValueList<int> & ); 
00395 
00397     void slotColumnWidthChanged( int col, int os, int ns );
00398 
00399     void slotSectionHandleDoubleClicked( int section );
00400 
00401     void slotUpdate();
00403     virtual void sortColumnInternal(int col, int order = 0)
00404         { KexiDataAwareObjectInterface::sortColumnInternal(col, order); }
00405 
00406     void slotAutoScroll();
00407 
00409     void vScrollBarValueChanged(int v);
00410     void vScrollBarSliderReleased();
00411     void scrollBarTipTimeout();
00413     void slotTopHeaderSizeChange( int section, int oldSize, int newSize );
00414 
00416     void slotEditRequested();
00417 
00420     virtual void reloadData() { KexiDataAwareObjectInterface::reloadData(); }
00421 
00423     virtual void slotRowRepaintRequested(KexiTableItem& item);
00424 
00426     virtual void slotAboutToDeleteRow(KexiTableItem& item, KexiDB::ResultInfo* result, bool repaint)
00427     { KexiDataAwareObjectInterface::slotAboutToDeleteRow(item, result, repaint); }
00428 
00430     virtual void slotRowDeleted() { KexiDataAwareObjectInterface::slotRowDeleted(); }
00431 
00433     virtual void slotRowInserted(KexiTableItem *item, bool repaint)
00434     { KexiDataAwareObjectInterface::slotRowInserted(item, repaint); }
00435 
00437     virtual void slotRowInserted(KexiTableItem *item, uint row, bool repaint)
00438     { KexiDataAwareObjectInterface::slotRowInserted(item, row, repaint); }
00439 
00440 protected:
00445     virtual void initDataContents();
00446 
00450     virtual void updateWidgetContentsSize();
00451 
00453     virtual void clearVariables();
00454 
00456     virtual int currentLocalSortingOrder() const;
00457 
00459     virtual int currentLocalSortColumn() const;
00460 
00462     virtual void setLocalSortingOrder(int col, int order);
00463 
00465     virtual void updateGUIAfterSorting();
00466 
00468     virtual void updateWidgetScrollBars() { updateScrollBars(); }
00469 
00470 //  /*! Implementation for KexiDataAwareObjectInterface */
00471 //  virtual void emitSortedColumnChanged(int col) { emit sortedColumnChanged(col); }
00472 
00473 //  /*! Implementation for KexiDataAwareObjectInterface */
00474 //  virtual void emitRowEditTerminated(int row) { emit rowEditTerminated(row); }
00475 
00478     virtual void addHeaderColumn(const QString& caption, const QString& description, int size);
00479 
00481     void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
00482     void createBuffer(int width, int height);
00483     void paintCell(QPainter* p, KexiTableItem *item, int col, int row, const QRect &cr, bool print=false);
00484     void paintEmptyArea(QPainter *p, int cx, int cy, int cw, int ch);
00485     void updateGeometries();
00486 
00487     QPoint contentsToViewport2( const QPoint &p );
00488     void contentsToViewport2( int x, int y, int& vx, int& vy );
00489     QPoint viewportToContents2( const QPoint& vp );
00490 
00491     // event handling
00492     virtual void contentsMousePressEvent(QMouseEvent*);
00493     virtual void contentsMouseReleaseEvent(QMouseEvent*);
00494     bool handleContentsMousePressOrRelease(QMouseEvent* e, bool release);
00495     virtual void contentsMouseMoveEvent(QMouseEvent*);
00496     virtual void contentsMouseDoubleClickEvent(QMouseEvent*);
00497     virtual void keyPressEvent(QKeyEvent*);
00498     virtual void focusInEvent(QFocusEvent*);
00499     virtual void focusOutEvent(QFocusEvent*);
00500     virtual void resizeEvent(QResizeEvent *);
00501     virtual void viewportResizeEvent( QResizeEvent *e );//js
00502     virtual void showEvent(QShowEvent *e);
00503     virtual void contentsDragMoveEvent(QDragMoveEvent *e);
00504     virtual void contentsDropEvent(QDropEvent *ev);
00505     virtual void viewportDragLeaveEvent( QDragLeaveEvent * );
00506     virtual void paletteChange( const QPalette & );
00507     
00509     virtual KexiDataItemInterface *editor( int col, bool ignoreMissingEditor = false );
00510 
00512     virtual void editorShowFocus( int row, int col );
00513 
00515     virtual void createEditor(int row, int col, const QString& addText = QString::null, 
00516         bool removeOld = false);
00517 
00518     bool focusNextPrevChild(bool next);
00519 
00525     bool shortCutPressed( QKeyEvent *e, const QCString &action_name );
00526 
00527 #if 0 //we have now KexiActionProxy
00528 
00530     bool updateContextMenu();
00531 #endif
00532 
00540     void showContextMenu( const QPoint& pos = QPoint(-1,-1) );
00541 
00543     inline void paintRow(KexiTableItem *item,
00544         QPainter *pb, int r, int rowp, int cx, int cy, 
00545         int colfirst, int collast, int maxwc);
00546 
00547     virtual void setHBarGeometry( QScrollBar & hbar, int x, int y, int w, int h );
00548 
00550     void setupNavigator();
00551 
00553     int validRowNumber(const QString& text);
00554 
00557     virtual void removeEditor();
00558 
00560     void updateFonts(bool repaint = false);
00561 
00564     void setBottomMarginInternal(int pixels);
00565 
00566     virtual void updateWidgetContents() { update(); }
00567 
00569     virtual void moveToRecordRequested(uint r);
00570     virtual void moveToLastRecordRequested();
00571     virtual void moveToPreviousRecordRequested();
00572     virtual void moveToNextRecordRequested();
00573     virtual void moveToFirstRecordRequested();
00574     virtual void addNewRecordRequested() { KexiDataAwareObjectInterface::addNewRecordRequested(); }
00575 
00578     virtual void updateAllVisibleRowsBelow(int row);
00579 
00580     void updateAfterCancelRowEdit();
00581     void updateAfterAcceptRowEdit();
00582 
00583 //  //! Called to repaint contents after a row is deleted.
00584 //  void repaintAfterDelete();
00585 
00586     inline KexiRecordMarker* verticalHeader() const { return m_verticalHeader; }
00587 
00588     //--------------------------
00589 
00590     KexiTableViewPrivate *d;
00591 
00592     class WhatsThis;
00593     friend class KexiTableItem;
00594     friend class WhatsThis;
00595 };
00596 
00603 class KEXIDATATABLE_EXPORT TableViewHeader : public QHeader
00604 {
00605     Q_OBJECT
00606 
00607     public:
00608         TableViewHeader(QWidget * parent = 0, const char * name = 0);
00609 
00610         int addLabel ( const QString & s, int size = -1 );
00611 
00612         int addLabel ( const QIconSet & iconset, const QString & s, int size = -1 );
00613 
00614         void removeLabel( int section );
00615 
00617         void setToolTip( int section, const QString & toolTip );
00618 
00619         virtual bool eventFilter(QObject * watched, QEvent * e);
00620 
00621     protected slots:
00622         void slotSizeChange(int section, int oldSize, int newSize );
00623 
00624     protected:
00625         int m_lastToolTipSection;
00626         QRect m_toolTipRect;
00627 
00628         QStringList m_toolTips;
00629 };
00630 
00631 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys