⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3listbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt3Support module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qglobal.h"#if defined(Q_CC_BOR)// needed for qsort() because of a std namespace problem on Borland#include "qplatformdefs.h"#endif#include "q3listbox.h"#ifndef QT_NO_LISTBOX#include "qapplication.h"#include "qevent.h"#include "qfontmetrics.h"#include "qpainter.h"#include "qpixmap.h"#include "qstringlist.h"#include "qstyle.h"#include "qstyleoption.h"#include "qtimer.h"#include "qvector.h"#include "qpointer.h"#ifndef QT_NO_ACCESSIBILITY#include "qaccessible.h"#endif#include <stdlib.h>class Q3ListBoxPrivate{public:    Q3ListBoxPrivate(Q3ListBox *lb):        head(0), last(0), cache(0), cacheIndex(-1), current(0),        highlighted(0), tmpCurrent(0), columnPos(1), rowPos(1), rowPosCache(0),        columnPosOne(0), rowMode(Q3ListBox::FixedNumber),        columnMode(Q3ListBox::FixedNumber), numRows(1), numColumns(1),        currentRow(0), currentColumn(0),        mousePressRow(-1), mousePressColumn(-1),        mouseMoveRow(-1), mouseMoveColumn(-1), mouseInternalPress(false),        scrollTimer(0), updateTimer(0), visibleTimer(0),        selectionMode(Q3ListBox::Single),        count(0),        listBox(lb), currInputString(QString()),        rowModeWins(false),        ignoreMoves(false),        layoutDirty(true),        mustPaintAll(true),        dragging(false),        dirtyDrag (false),        variableHeight(true /* !!! ### false */),        variableWidth(false),        inMenuMode(false)    {}    int findItemByName(int item, const QString &text);    ~Q3ListBoxPrivate();    Q3ListBoxItem * head, *last, *cache;    int cacheIndex;    Q3ListBoxItem * current, *highlighted, *tmpCurrent;    QVector<int> columnPos;    QVector<int> rowPos;    int rowPosCache;    int columnPosOne;    Q3ListBox::LayoutMode rowMode;    Q3ListBox::LayoutMode columnMode;    int numRows;    int numColumns;    int currentRow;    int currentColumn;    int mousePressRow;    int mousePressColumn;    int mouseMoveRow;    int mouseMoveColumn;    bool mouseInternalPress;    QTimer * scrollTimer;    QTimer * updateTimer;    QTimer * visibleTimer;    QTimer * resizeTimer;    QPoint scrollPos;    Q3ListBox::SelectionMode selectionMode;    int count;    Q3ListBox *listBox;    QString currInputString;    QTimer *inputTimer;    Q3ListBoxItem *pressedItem, *selectAnchor;    uint select :1;    uint pressedSelected :1;    uint rowModeWins :1;    uint ignoreMoves :1;    uint clearing :1;    uint layoutDirty :1;    uint mustPaintAll :1;    uint dragging :1;    uint dirtyDrag :1;    uint variableHeight :1;    uint variableWidth :1;    uint inMenuMode :1;    QRect *rubber;    struct SortableItem {        Q3ListBoxItem *item;    };};Q3ListBoxPrivate::~Q3ListBoxPrivate(){    Q_ASSERT(!head);}/*!    \class Q3ListBoxItem qlistbox.h    \brief The Q3ListBoxItem class is the base class of all list box items.    \compat    This class is an abstract base class used for all list box items.    If you need to insert customized items into a Q3ListBox you must    inherit this class and reimplement paint(), height() and width().    \sa Q3ListBox*//*!    Constructs an empty list box item in the list box \a listbox.*/Q3ListBoxItem::Q3ListBoxItem(Q3ListBox* listbox){    lbox = listbox;    s = false;    dirty = true;    custom_highlight = false;    selectable = true;    p = n = 0;    if (listbox)        listbox->insertItem(this);}/*!    Constructs an empty list box item in the list box \a listbox and    inserts it after the item \a after or at the beginning if \a after    is 0.*/Q3ListBoxItem::Q3ListBoxItem(Q3ListBox* listbox, Q3ListBoxItem *after){    lbox = listbox;    s = false;    dirty = true;    custom_highlight = false;    selectable = true;    p = n = 0;    if (listbox)        listbox->insertItem(this, after);}/*!    Destroys the list box item.*/Q3ListBoxItem::~Q3ListBoxItem(){    if (lbox)        lbox->takeItem(this);}/*!    Defines whether the list box item is responsible for drawing    itself in a highlighted state when being selected.    If \a b is false (the default), the list box will draw some    default highlight indicator before calling paint().    \sa isSelected(), paint()*/void Q3ListBoxItem::setCustomHighlighting(bool b){    custom_highlight = b;}/*!    \fn void Q3ListBoxItem::paint(QPainter *p)    Implement this function to draw your item. The painter, \a p, is    already open for painting.    \sa height(), width()*//*!    \fn int Q3ListBoxItem::width(const Q3ListBox* lb) const    Reimplement this function to return the width of your item. The \a    lb parameter is the same as listBox() and is provided for    convenience and compatibility.    The default implementation returns    \l{QApplication::globalStrut()}'s width.    \sa paint(), height()*/int Q3ListBoxItem::width(const Q3ListBox*)  const{    return QApplication::globalStrut().width();}/*!    \fn int Q3ListBoxItem::height(const Q3ListBox* lb) const    Implement this function to return the height of your item. The \a    lb parameter is the same as listBox() and is provided for    convenience and compatibility.    The default implementation returns    \l{QApplication::globalStrut()}'s height.    \sa paint(), width()*/int Q3ListBoxItem::height(const Q3ListBox*)  const{    return QApplication::globalStrut().height();}/*!    Returns the text of the item. This text is also used for sorting.    \sa setText()*/QString Q3ListBoxItem::text() const{    return txt;}/*!    Returns the pixmap associated with the item, or 0 if there isn't    one.    The default implementation returns 0.*/const QPixmap *Q3ListBoxItem::pixmap() const{    return 0;}/*! \fn void Q3ListBoxItem::setSelectable(bool b)    If \a b is true (the default) then this item can be selected by    the user; otherwise this item cannot be selected by the user.    \sa isSelectable()*//*! \fn bool Q3ListBoxItem::isSelectable() const    Returns true if this item is selectable (the default); otherwise    returns false.    \sa setSelectable()*//*!    \fn void Q3ListBoxItem::setText(const QString &text)    Sets the text of the Q3ListBoxItem to \a text. This \a text is also    used for sorting. The text is not shown unless explicitly drawn in    paint().    \sa text()*//*!    \class Q3ListBoxText qlistbox.h    \brief The Q3ListBoxText class provides list box items that display text.    \compat    The text is drawn in the widget's current font. If you need    several different fonts, you must implement your own subclass of    Q3ListBoxItem.    \sa Q3ListBox, Q3ListBoxItem*//*!    Constructs a list box item in list box \a listbox showing the text    \a text.*/Q3ListBoxText::Q3ListBoxText(Q3ListBox *listbox, const QString &text)    :Q3ListBoxItem(listbox){    setText(text);}/*!    Constructs a list box item showing the text \a text.*/Q3ListBoxText::Q3ListBoxText(const QString &text)    :Q3ListBoxItem(){    setText(text);}/*!    Constructs a list box item in list box \a listbox showing the text    \a text. The item is inserted after the item \a after, or at the    beginning if \a after is 0.*/Q3ListBoxText::Q3ListBoxText(Q3ListBox* listbox, const QString &text, Q3ListBoxItem *after)    : Q3ListBoxItem(listbox, after){    setText(text);}/*!    Destroys the item.*/Q3ListBoxText::~Q3ListBoxText(){}/*!    Draws the text using \a painter.*/void Q3ListBoxText::paint(QPainter *painter){    int itemHeight = height(listBox());    QFontMetrics fm = painter->fontMetrics();    int yPos = ((itemHeight - fm.height()) / 2) + fm.ascent();    painter->drawText(3, yPos, text());}/*!    Returns the height of a line of text in list box \a lb.    \sa paint(), width()*/int Q3ListBoxText::height(const Q3ListBox* lb) const{    int h = lb ? lb->fontMetrics().lineSpacing() + 2 : 0;    return qMax(h, QApplication::globalStrut().height());}/*!    Returns the width of this line in list box \a lb.    \sa paint(), height()*/int Q3ListBoxText::width(const Q3ListBox* lb) const{    int w = lb ? lb->fontMetrics().width(text()) + 6 : 0;    return qMax(w, QApplication::globalStrut().width());}/*!    \fn int Q3ListBoxText::rtti() const    \reimp    Returns 1.    Make your derived classes return their own values for rtti(), and    you can distinguish between listbox items. You should use values    greater than 1000 preferably a large random number, to allow for    extensions to this class.*/int Q3ListBoxText::rtti() const{    return RTTI;}/*!    \class Q3ListBoxPixmap qlistbox.h    \brief The Q3ListBoxPixmap class provides list box items with a    pixmap and optional text.    \compat    Items of this class are drawn with the pixmap on the left with the    optional text to the right of the pixmap.    \sa Q3ListBox, Q3ListBoxItem*//*!    Constructs a new list box item in list box \a listbox showing the    pixmap \a pixmap.*/Q3ListBoxPixmap::Q3ListBoxPixmap(Q3ListBox* listbox, const QPixmap &pixmap)    : Q3ListBoxItem(listbox){    pm = pixmap;}/*!    Constructs a new list box item showing the pixmap \a pixmap.*/Q3ListBoxPixmap::Q3ListBoxPixmap(const QPixmap &pixmap)    : Q3ListBoxItem(){    pm = pixmap;}/*!    Constructs a new list box item in list box \a listbox showing the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -