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-2006 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 #include <qscrollview.h>
00031 #include <qvariant.h>
00032 #include <qptrlist.h>
00033 #include <qheader.h>
00034 #include <qtooltip.h>
00035 
00036 #include <kdebug.h>
00037 
00038 #include "kexitableviewdata.h"
00039 #include "kexitableedit.h"
00040 #include <kexiutils/tristate.h>
00041 #include <widget/utils/kexirecordnavigator.h>
00042 #include <widget/utils/kexisharedactionclient.h>
00043 #include "kexidataawareobjectiface.h"
00044 
00045 class KPopupMenu;
00046 class KPrinter;
00047 class KAction;
00048 
00049 class KexiTableHeader;
00050 class KexiTableItem;
00051 class KexiTableView;
00052 class KexiTableEdit;
00053 class KexiTableViewPrivate;
00054 class KActionCollection;
00055 
00056 namespace KexiDB {
00057     class RowEditBuffer;
00058 }
00059 
00061 #define KEXITV_MINIMUM_COLUMN_WIDTH 10
00062 
00064 
00066 class KEXIDATATABLE_EXPORT KexiTableView :
00067     public QScrollView,
00068     public KexiRecordNavigatorHandler,
00069     public KexiSharedActionClient,
00070     public KexiDataAwareObjectInterface
00071 {
00072 Q_OBJECT
00073 KEXI_DATAAWAREOBJECTINTERFACE
00074 public:
00075 
00077     class KEXIDATATABLE_EXPORT Appearance {
00078     public:
00079         Appearance(QWidget *widget = 0);
00080 
00083         QColor baseColor;
00084 
00087         QColor textColor;
00088 
00090         QColor borderColor;
00091 
00094         QColor emptyAreaColor;
00095 
00097         QColor alternateBackgroundColor;
00098 
00100         bool backgroundAltering : 1;
00101 
00107         bool fullRowSelection : 1;
00108 
00112         bool gridEnabled : 1;
00113 
00116         bool navigatorEnabled : 1;
00117 
00119         bool rowHighlightingEnabled : 1;
00120 
00122         bool rowMouseOverHighlightingEnabled : 1;
00123 
00128         bool persistentSelections : 1;
00129 
00132         QColor rowHighlightingColor;
00133 
00136         QColor rowHighlightingTextColor;
00137 
00140         QColor rowMouseOverHighlightingColor;
00141 
00144         QColor rowMouseOverHighlightingTextColor;
00145 
00148         QColor rowMouseOverAlternateHighlightingColor;
00149     };
00150     
00151     KexiTableView(KexiTableViewData* data=0, QWidget* parent=0, const char* name=0);
00152     virtual ~KexiTableView();
00153 
00155     const Appearance& appearance() const;
00156 
00158     void setAppearance(const Appearance& a);
00159 
00161     QString columnCaption(int colNum) const;
00162 
00165     KexiDB::Field* field(int colNum) const;
00166 
00168     virtual void setSpreadSheetMode();
00169 
00171 //moved bool scrollbarToolTipsEnabled() const;
00172 
00174 //moved void setScrollbarToolTipsEnabled(bool set);
00175 
00178     virtual int rowsPerPage() const;
00179 
00180     QRect cellGeometry(int row, int col) const;
00181     int columnWidth(int col) const;
00182     int rowHeight() const;
00183     int columnPos(int col) const;
00184     int rowPos(int row) const;
00185     int columnAt(int pos) const;
00186     int rowAt(int pos, bool ignoreEnd=false) const;
00187 
00191     virtual int lastVisibleRow() const;
00192 
00194     virtual void updateCell(int row, int col);
00195 
00197     virtual void updateCurrentCell();
00198 
00200     virtual void updateRow(int row);
00201 
00202     bool editableOnDoubleClick() const;
00203     void setEditableOnDoubleClick(bool set);
00204 
00206     bool verticalHeaderVisible() const;
00207 
00209     void setVerticalHeaderVisible(bool set);
00210 
00212     bool horizontalHeaderVisible() const;
00213 
00215     void setHorizontalHeaderVisible(bool set);
00216 
00217 #ifndef KEXI_NO_PRINT
00218     // printing
00219 //  void        setupPrinter(KPrinter &printer);
00220     void        print(KPrinter &printer);
00221 #endif
00222 
00223     // reimplemented for internal reasons
00224     virtual QSizePolicy sizePolicy() const;
00225     virtual QSize sizeHint() const;
00226     virtual QSize minimumSizeHint() const;
00227 
00229     void setFont(const QFont &f);
00230 
00231     virtual QSize tableSize() const;
00232 
00233     void emitSelected();
00234 
00236     void triggerUpdate();
00237 
00238     typedef enum ScrollDirection
00239     {
00240         ScrollUp,
00241         ScrollDown,
00242         ScrollLeft,
00243         ScrollRight
00244     };
00245 
00246     virtual bool eventFilter( QObject *o, QEvent *e );
00247 
00249     static void initCellEditorFactories();
00250 
00254     int highlightedRow() const;
00255 
00256     KexiTableItem *highlightedItem() const;
00257 
00259     virtual QScrollBar* verticalScrollBar() const { return QScrollView::verticalScrollBar(); }
00260 
00261 public slots:
00262     virtual void setData( KexiTableViewData *data, bool owner = true )
00263         { KexiDataAwareObjectInterface::setData( data, owner ); }
00264 
00265     virtual void clearColumnsInternal(bool repaint);
00266 
00269     void adjustColumnWidthToContents(int colNum = -1);
00270 
00272     void setColumnWidth(int col, int width);
00273 
00278     void setColumnStretchEnabled( bool set, int colNum );
00279 
00284     void maximizeColumnsWidth( const QValueList<int> &columnList );
00285 
00289     void adjustHorizontalHeaderSize();
00290 
00294     void setHighlightedRow(int row);
00295 
00297     inline void clearHighlightedRow() { setHighlightedRow(-1); }
00298 
00302     virtual void ensureCellVisible(int row, int col/*=-1*/);
00303 
00304 //  void            gotoNext();
00305 //js    int         findString(const QString &string);
00306     
00310     virtual void deleteCurrentRow() { KexiDataAwareObjectInterface::deleteCurrentRow(); }
00311 
00320     virtual KexiTableItem *insertEmptyRow(int row = -1) 
00321         { return KexiDataAwareObjectInterface::insertEmptyRow(row); }
00322 
00328     virtual void startEditCurrentCell(const QString& setText = QString::null)
00329         { KexiDataAwareObjectInterface::startEditCurrentCell(setText); }
00330 
00333     virtual void deleteAndStartEditCurrentCell() 
00334         { KexiDataAwareObjectInterface::deleteAndStartEditCurrentCell(); }
00335 
00339     virtual bool cancelRowEdit() { return KexiDataAwareObjectInterface::cancelRowEdit(); }
00340 
00345     virtual bool acceptRowEdit() { return KexiDataAwareObjectInterface::acceptRowEdit(); }
00346 
00350     virtual void setAcceptsRowEditAfterCellAccepting(bool set) 
00351         { KexiDataAwareObjectInterface::setAcceptsRowEditAfterCellAccepting(set); }
00352 
00359     virtual void setDropsAtRowEnabled(bool set) { KexiDataAwareObjectInterface::setDropsAtRowEnabled(set); }
00360 
00361     virtual bool cancelEditor() { return KexiDataAwareObjectInterface::cancelEditor(); }
00362     virtual bool acceptEditor() { return KexiDataAwareObjectInterface::acceptEditor(); }
00363 
00364 signals:
00365     virtual void dataSet( KexiTableViewData *data );
00366 
00367     virtual void itemSelected(KexiTableItem *);
00368     virtual void cellSelected(int col, int row);
00369 
00370     void itemReturnPressed(KexiTableItem *, int row, int col);
00371     void itemDblClicked(KexiTableItem *, int row, int col);
00372     void itemMouseReleased(KexiTableItem *, int row, int col);
00373 
00374     void dragOverRow(KexiTableItem *item, int row, QDragMoveEvent* e);
00375     void droppedAtRow(KexiTableItem *item, int row, QDropEvent *e, KexiTableItem*& newItem);
00376 
00378     virtual void dataRefreshed();
00379 
00380     virtual void itemChanged(KexiTableItem *, int row, int col);
00381     virtual void itemChanged(KexiTableItem *, int row, int col, QVariant oldValue);
00382     virtual void itemDeleteRequest(KexiTableItem *, int row, int col);
00383     virtual void currentItemDeleteRequest();
00385     virtual void newItemAppendedForAfterDeletingInSpreadSheetMode();
00386 //  void addRecordRequest();
00387 //  void contextMenuRequested(KexiTableItem *,  int row, int col, const QPoint &);
00388     void sortedColumnChanged(int col);
00389 
00391     void rowEditStarted(int row);
00392 
00395     void rowEditTerminated(int row);
00396 
00399     void reloadActions();
00400 
00401 protected slots:
00402     void slotSettingsChanged(int category);
00403 
00404     virtual void slotDataDestroying() { KexiDataAwareObjectInterface::slotDataDestroying(); }
00405 
00406     virtual void slotRowsDeleted( const QValueList<int> & ); 
00407 
00409     void slotColumnWidthChanged( int col, int os, int ns );
00410 
00411     void slotSectionHandleDoubleClicked( int section );
00412 
00413     void slotUpdate();
00415     virtual void sortColumnInternal(int col, int order = 0)
00416         { KexiDataAwareObjectInterface::sortColumnInternal(col, order); }
00417 
00418     void slotAutoScroll();
00419 
00421     void slotTopHeaderSizeChange( int section, int oldSize, int newSize );
00422 
00424     void slotEditRequested();
00425 
00428     virtual void reloadData();
00429 
00431     virtual void slotRowRepaintRequested(KexiTableItem& item);
00432 
00434     virtual void slotAboutToDeleteRow(KexiTableItem& item, KexiDB::ResultInfo* result, bool repaint)
00435     { KexiDataAwareObjectInterface::slotAboutToDeleteRow(item, result, repaint); }
00436 
00438     virtual void slotRowDeleted() { KexiDataAwareObjectInterface::slotRowDeleted(); }
00439 
00441     virtual void slotRowInserted(KexiTableItem *item, bool repaint)
00442     { KexiDataAwareObjectInterface::slotRowInserted(item, repaint); }
00443 
00445     virtual void slotRowInserted(KexiTableItem *item, uint row, bool repaint)
00446     { KexiDataAwareObjectInterface::slotRowInserted(item, row, repaint); }
00447 
00450     virtual void vScrollBarValueChanged(int v) { KexiDataAwareObjectInterface::vScrollBarValueChanged(v); }
00451 
00453     virtual void vScrollBarSliderReleased() { KexiDataAwareObjectInterface::vScrollBarSliderReleased(); }
00454 
00458     virtual void scrollBarTipTimeout() { KexiDataAwareObjectInterface::scrollBarTipTimeout(); }
00459 
00460 protected:
00465     virtual void initDataContents();
00466 
00470     virtual void updateWidgetContentsSize();
00471 
00473     virtual void clearVariables();
00474 
00476     virtual int currentLocalSortingOrder() const;
00477 
00479     virtual int currentLocalSortColumn() const;
00480 
00482     virtual void setLocalSortingOrder(int col, int order);
00483 
00485     virtual void updateGUIAfterSorting();
00486 
00488     virtual void updateWidgetScrollBars() { updateScrollBars(); }
00489 
00490 //  /*! Implementation for KexiDataAwareObjectInterface */
00491 //  virtual void emitSortedColumnChanged(int col) { emit sortedColumnChanged(col); }
00492 
00493 //  /*! Implementation for KexiDataAwareObjectInterface */
00494 //  virtual void emitRowEditTerminated(int row) { emit rowEditTerminated(row); }
00495 
00498     virtual void addHeaderColumn(const QString& caption, const QString& description, 
00499         const QIconSet& icon, int size);
00500 
00504     bool isDefaultValueDisplayed(KexiTableItem *item, int col, QVariant* value = 0);
00505 
00507     void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
00508     void createBuffer(int width, int height);
00509     void paintCell(QPainter* p, KexiTableItem *item, int col, int row, const QRect &cr, bool print=false);
00510     void paintEmptyArea(QPainter *p, int cx, int cy, int cw, int ch);
00511     void updateGeometries();
00512 
00513     QPoint contentsToViewport2( const QPoint &p );
00514     void contentsToViewport2( int x, int y, int& vx, int& vy );
00515     QPoint viewportToContents2( const QPoint& vp );
00516 
00517     // event handling
00518     virtual void contentsMousePressEvent(QMouseEvent* e);
00519     virtual void contentsMouseReleaseEvent(QMouseEvent* e);
00521     bool handleContentsMousePressOrRelease(QMouseEvent* e, bool release);
00522     virtual void contentsMouseMoveEvent(QMouseEvent* e);
00523     virtual void contentsMouseDoubleClickEvent(QMouseEvent* e);
00524     virtual void keyPressEvent(QKeyEvent* e);
00525     virtual void focusInEvent(QFocusEvent* e);
00526     virtual void focusOutEvent(QFocusEvent* e);
00527     virtual void resizeEvent(QResizeEvent* e);
00528     virtual void viewportResizeEvent(QResizeEvent *e);
00529     virtual void showEvent(QShowEvent *e);
00530     virtual void contentsDragMoveEvent(QDragMoveEvent *e);
00531     virtual void contentsDropEvent(QDropEvent *e);
00532     virtual void viewportDragLeaveEvent(QDragLeaveEvent *e);
00533     virtual void paletteChange( const QPalette &oldPalette );
00534     
00536     virtual KexiDataItemInterface *editor( int col, bool ignoreMissingEditor = false );
00537 
00538     inline KexiTableEdit *tableEditorWidget(  int col, bool ignoreMissingEditor = false )
00539     { return dynamic_cast<KexiTableEdit*>( editor( col, ignoreMissingEditor ) ); }
00540 
00542     virtual void editorShowFocus( int row, int col );
00543 
00545     virtual void createEditor(int row, int col, const QString& addText = QString::null, 
00546         bool removeOld = false);
00547 
00548     bool focusNextPrevChild(bool next);
00549 
00555     bool shortCutPressed( QKeyEvent *e, const QCString &action_name );
00556 
00557 #if 0 //we have now KexiActionProxy
00558 
00560     bool updateContextMenu();
00561 #endif
00562 
00570     void showContextMenu( const QPoint& pos = QPoint(-1,-1) );
00571 
00573     inline void paintRow(KexiTableItem *item,
00574         QPainter *pb, int r, int rowp, int cx, int cy, 
00575         int colfirst, int collast, int maxwc);
00576 
00577     virtual void setHBarGeometry( QScrollBar & hbar, int x, int y, int w, int h );
00578 
00580     void setupNavigator();
00581 
00583     int validRowNumber(const QString& text);
00584 
00587     virtual void removeEditor();
00588 
00590     void updateFonts(bool repaint = false);
00591 
00594     void setBottomMarginInternal(int pixels);
00595 
00596     virtual void updateWidgetContents() { update(); }
00597 
00599     virtual void moveToRecordRequested(uint r);
00600     virtual void moveToLastRecordRequested();
00601     virtual void moveToPreviousRecordRequested();
00602     virtual void moveToNextRecordRequested();
00603     virtual void moveToFirstRecordRequested();
00604     virtual void addNewRecordRequested() { KexiDataAwareObjectInterface::addNewRecordRequested(); }
00605 
00607     virtual void copySelection();
00608 
00610     virtual void cutSelection();
00611 
00613     virtual void paste();
00614 
00617     virtual void updateAllVisibleRowsBelow(int row);
00618 
00619     void updateAfterCancelRowEdit();
00620     void updateAfterAcceptRowEdit();
00621 
00625     bool getVisibleLookupValue(QVariant& cellValue, KexiTableEdit *edit, 
00626         KexiTableItem *item, KexiTableViewColumn *tvcol) const;
00627 
00628 //  //! Called to repaint contents after a row is deleted.
00629 //  void repaintAfterDelete();
00630 
00631     KexiTableViewPrivate *d;
00632 
00633     class WhatsThis;
00634     friend class KexiTableItem;
00635     friend class WhatsThis;
00636     friend class KexiTableViewCellToolTip;
00637 };
00638 
00639 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys