📄 ktablistbox.h
字号:
/* This file is part of the KDE libraries Copyright (C) 1997 The KDE Team This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.*//* Written by Stefan Taferner <taferner@kde.org> * Alessandro Russo <axela@bigfoot.com> * A multi column listbox. Requires the Qt widget set. */#ifndef KTabListBox_h#define KTabListBox_h#undef del_item#include <qdict.h>#include <qtableview.h>#include <qcolor.h>#include <qpixmap.h>#include <drag.h>#include <stdlib.h>#define MAX_SEP_CHARS 16class KTabListBoxColumn;class KTabListBoxTable;class KTabListBoxItem;class KTabListBox;class KNumCheckButton;typedef QDict<QPixmap> KTabListBoxDict;//-----------------------------------------------------/*** Provides a different type of Check button.* */class KNumCheckButton : public QWidget{ Q_OBJECTpublic: KNumCheckButton( QWidget *_parent = 0L, const char *name = 0L ); ~KNumCheckButton() {}; void setText( const char * ); signals: void selected(); void deselected(); /** leftbutton=true if is a leftbutton, =false if is a rightbutton * centerbutton doubleclick events aren't emitted. */ void doubleclick(bool leftbutton);protected: virtual void leaveEvent( QEvent *_ev ); virtual void enterEvent( QEvent *_ev ); virtual void mousePressEvent( QMouseEvent * ); virtual void mouseDoubleClickEvent( QMouseEvent * ); virtual void paintEvent( QPaintEvent *event); private: bool raised; QString btext;};//--------------------------------------------------#define KTabListBoxTableInherited QTableViewclass KTabListBoxTable: public QTableView{ Q_OBJECT friend KTabListBox;public: KTabListBoxTable(KTabListBox *owner=0); virtual ~KTabListBoxTable(); void enableKey(); int findRealCol(int x);protected: virtual void focusInEvent(QFocusEvent*); virtual void focusOutEvent(QFocusEvent*); virtual void mouseDoubleClickEvent (QMouseEvent*); virtual void mousePressEvent (QMouseEvent*); virtual void mouseReleaseEvent (QMouseEvent*); virtual void mouseMoveEvent (QMouseEvent*); virtual void doItemSelection (QMouseEvent*, int idx); virtual void paintCell (QPainter*, int row, int col); virtual int cellWidth (int col); void reconnectSBSignals (void); QPoint dragStartPos; int dragCol, dragRow; int selIdx; bool dragging;};//--------------------------------------------------#define KTabListBoxInherited KDNDWidget/** A multi column listbox * Features: * - User resizeable columns. * - The order of columns can be changed with drag&drop. (Alex) * - 3 modes: Standard, SimpleOrder, ComplexOrder. (Alex) * ToDo: * - Configurable vertical column divisor lines. * - Save all setting to config file. * - fix flickering into column headers. */class KTabListBox : public KDNDWidget{ Q_OBJECT friend KTabListBoxTable; friend KTabListBoxColumn;public: enum ColumnType { TextColumn, PixmapColumn, MixedColumn }; enum OrderMode { Ascending, Descending }; enum OrderType { NoOrder, SimpleOrder, ComplexOrder }; KTabListBox (QWidget *parent=0, const char *name=0, int columns=1, WFlags f=0); virtual ~KTabListBox(); /** This enable the key-bindings (and set StrongFocus!) * if you don't want StrongFocus you can implement your own keyPressEvent * and send an event to KTabListBox from there... */ void enableKey(void) { lbox.enableKey(); } /** Returns the number of rows */ uint count (void) const { return numRows(); }; /** Insert a line before given index, using the separator character to separate the fields. If no index is given the line is appended at the end. Returns index of inserted item. */ virtual void insertItem (const char* string, int itemIndex=-1); /** Append a QStrList */ void appendStrList( QStrList const *strLst ); /** Same as insertItem, but always appends the new item. */ void appendItem (const char* string) { insertItem(string); } /** Change contents of a line using the separator character to separate the fields. */ virtual void changeItem (const char* string, int itemIndex); /** Change part of the contents of a line. */ virtual void changeItemPart (const char* string, int itemIndex, int column); /** Change color of line. Changes last inserted item when itemIndex==-1 */ virtual void changeItemColor (const QColor& color, int itemIndex=-1); /** Get number of pixels one tab character stands for. Default: 10 */ int tabWidth(void) const { return tabPixels; } /** Set number of pixels one tab character stands for. Default: 10 */ virtual void setTabWidth(int); /** Returns contents of given row/column. If col is not set the contents of the whole row is returned, seperated with the current seperation character. In this case the string returned is a temporary string that will change on the next text() call on any KTabListBox object. */ const QString& text(int idx, int col=-1) const; /** Remove one item from the list. */ virtual void removeItem (int itemIndex); /** Remove contents of listbox */ virtual void clear (void); /** Return index of current item */ int currentItem (void) const { return current; } /** Set the current (selected) column. colId is the value that is transfered with the selected() signal that is emited. */ virtual void setCurrentItem (int idx, int colId=-1); /** Unmark all items */ virtual void unmarkAll (void); /** Mark/unmark item with index idx. */ virtual void markItem (int idx, int colId=-1); virtual void unmarkItem (int idx); /** Returns TRUE if item with given index is marked. */ virtual bool isMarked (int idx) const; /** Find item at given screen y position. */ int findItem (int yPos) const { return (itemShowList[lbox.findRow(yPos)]); } /** Returns first item that is currently displayed in the widget. */ int topItem (void) const { return (itemShowList[lbox.topCell()]); } /** Change first displayed item by repositioning the visible part of the list. */ void setTopItem (int idx) { lbox.setTopCell(itemPosList(idx)); } /** Set number of columns. Warning: this *deletes* the contents of the listbox. */ virtual void setNumCols (int); /** Set number of rows in the listbox. The contents stays as it is. */ virtual void setNumRows (int); /** See the docs for the QTableView class. */ int numRows (void) const { return lbox.numRows(); } /** See the docs for the QTableView class. */ int numCols (void) const { return lbox.numCols(); } /** See the docs for the QTableView class. */ int cellWidth (int col) { return lbox.cellWidth(col); } /** See the docs for the QTableView class. */ int totalWidth (void) { return lbox.totalWidth(); } /** See the docs for the QTableView class. */ int cellHeight (int row) { return lbox.cellHeight(row); } /** See the docs for the QTableView class. */ int totalHeight (void) { return lbox.totalHeight(); } /** See the docs for the QTableView class. */ int topCell (void) const { return itemShowList[lbox.topCell()]; } /** See the docs for the QTableView class. */ int leftCell (void) const { return colShowList[lbox.leftCell()]; } /** See the docs for the QTableView class. */ int lastColVisible (void) const { return colShowList[lbox.lastColVisible()]; } /** See the docs for the QTableView class. */ int lastRowVisible (void) const { return itemShowList[lbox.lastRowVisible()]; } /** See the docs for the QTableView class. */ bool autoUpdate (void) const { return lbox.autoUpdate(); } /** See the docs for the QTableView class. */ void setAutoUpdate (bool upd) { lbox.setAutoUpdate(upd); } /** See the docs for the QTableView class. */ void clearTableFlags(uint f=~0) { lbox.clearTableFlags(f); } /** See the docs for the QTableView class. */ uint tableFlags(void) { return lbox.tableFlags(); } /** See the docs for the QTableView class. */ bool testTableFlags(uint f) { return lbox.testTableFlags(f); } /** See the docs for the QTableView class. */ void setTableFlags(uint f) { lbox.setTableFlags(f); } /** See the docs for the QTableView class. */ int findCol(int x) { return lbox.findRealCol(x); } /** See the docs for the QTableView class. */ int findRow(int y) { return itemShowList[lbox.findRow(y)]; } /** See the docs for the QTableView class. */ bool colXPos(int col, int* x) { return lbox.colXPos(colPosList(col),x); } /** See the docs for the QTableView class. */ bool rowYPos(int row, int* y) { return lbox.rowYPos(itemPosList(row),y); } /** This call the 'compar' functions if they were been defined in * setColumn or else use strcmp. (i.e. if you want a case-insensitive sort * put strcasecmp in setColumn call). * That compar function must take as arguments two char *, and must return * an integer less than, equal to, or greater than zero if the first
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -