📄 q3listview.cpp
字号:
}/*! Sets this item's height to \a height pixels. This implicitly changes totalHeight(), too. Note that a font change causes this height to be overwritten unless you reimplement setup(). For best results in Windows style we suggest using an even number of pixels. \sa height() totalHeight() isOpen()*/void Q3ListViewItem::setHeight(int height){ if (ownHeight != height) { if (visible) ownHeight = height; else ownHeight = 0; invalidateHeight(); }}/*! Invalidates the cached total height of this item, including all open children. \sa setHeight() height() totalHeight()*/void Q3ListViewItem::invalidateHeight(){ if (maybeTotalHeight < 0) return; maybeTotalHeight = -1; if (parentItem && parentItem->isOpen()) parentItem->invalidateHeight();}/*! Opens or closes an item, i.e. shows or hides an item's children. If \a o is true all child items are shown initially. The user can hide them by clicking the \bold{-} icon to the left of the item. If \a o is false, the children of this item are initially hidden. The user can show them by clicking the \bold{+} icon to the left of the item. \sa height() totalHeight() isOpen()*/void Q3ListViewItem::setOpen(bool o){ if (o == (bool)open || !enabled) return; open = o; // If no children to show simply emit signals and return if (!nChildren) { Q3ListView *lv = listView(); if (lv && this != lv->d->r) { if (o) emit lv->expanded(this); else emit lv->collapsed(this);#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged);#endif } return; } invalidateHeight(); if (!configured) { Q3ListViewItem * l = this; QStack<Q3ListViewItem *> s; while(l) { if (l->open && l->childItem) { s.push(l->childItem); } else if (l->childItem) { // first invisible child is unconfigured Q3ListViewItem * c = l->childItem; while(c) { c->configured = false; c = c->siblingItem; } } l->configured = true; l->setup(); l = (l == this) ? 0 : l->siblingItem; if (!l && !s.isEmpty()) l = s.pop(); } } Q3ListView *lv = listView(); if (open && lv) enforceSortOrder(); if (isVisible() && lv && lv->d && !lv->d->drawables.isEmpty()) lv->buildDrawableList(); if (lv && this != lv->d->r) { if (o) emit lv->expanded(this); else emit lv->collapsed(this);#ifndef QT_NO_ACCESSIBILITY QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::StateChanged);#endif }}/*! This virtual function is called before the first time Q3ListView needs to know the height or any other graphical attribute of this object, and whenever the font, GUI style, or colors of the list view change. The default calls widthChanged() and sets the item's height to the height of a single line of text in the list view's font. (If you use icons, multi-line text, etc., you will probably need to call setHeight() yourself or reimplement it.)*/void Q3ListViewItem::setup(){ widthChanged(); Q3ListView *lv = listView(); int ph = 0; int h = 0; if (lv) { for (int i = 0; i < lv->d->column.size(); ++i) { if (pixmap(i)) ph = qMax(ph, pixmap(i)->height()); } if (mlenabled) { h = ph; for (int c = 0; c < lv->columns(); ++c) { int lines = text(c).count(QChar('\n')) + 1; int tmph = lv->d->fontMetricsHeight + lv->fontMetrics().lineSpacing() * (lines - 1); h = qMax(h, tmph); } h += 2*lv->itemMargin(); } else { h = qMax(lv->d->fontMetricsHeight, ph) + 2*lv->itemMargin(); } } h = qMax(h, QApplication::globalStrut().height()); if (h % 2 > 0) h++; setHeight(h);}/*! This virtual function is called whenever the user presses the mouse on this item or presses Space on it. \sa activatedPos()*/void Q3ListViewItem::activate(){}/*! When called from a reimplementation of activate(), this function gives information on how the item was activated. Otherwise the behavior is undefined. If activate() was caused by a mouse press, the function sets \a pos to where the user clicked and returns true; otherwise it returns false and does not change \a pos. \a pos is relative to the top-left corner of this item. \sa activate()*/bool Q3ListViewItem::activatedPos(QPoint &pos){ if (activatedByClick) pos = activatedP; return activatedByClick;}/*! \fn bool Q3ListViewItem::isSelectable() const Returns true if the item is selectable (as it is by default); otherwise returns false \sa setSelectable()*//*! Sets this items to be selectable if \a enable is true (the default) or not to be selectable if \a enable is false. The user is not able to select a non-selectable item using either the keyboard or the mouse. The application programmer still can though, e.g. using setSelected(). \sa isSelectable()*/void Q3ListViewItem::setSelectable(bool enable){ selectable = enable;}/*! \fn bool Q3ListViewItem::isExpandable() const Returns true if this item is expandable even when it has no children; otherwise returns false.*//*! Sets this item to be expandable even if it has no children if \a enable is true, and to be expandable only if it has children if \a enable is false (the default). The dirview example uses this in the canonical fashion. It checks whether the directory is empty in setup() and calls setExpandable(true) if not; in setOpen() it reads the contents of the directory and inserts items accordingly. This strategy means that dirview can display the entire file system without reading very much at startup. Note that root items are not expandable by the user unless Q3ListView::setRootIsDecorated() is set to true. \sa setSelectable()*/void Q3ListViewItem::setExpandable(bool enable){ expandable = enable;}/*! Makes sure that this object's children are sorted appropriately. This only works if every item from the root item down to this item is already sorted. \sa sortChildItems()*/void Q3ListViewItem::enforceSortOrder() const{ Q3ListView *lv = listView(); if (!lv || lv && (lv->d->clearing || lv->d->sortcolumn == Unsorted)) return; if (parentItem && (parentItem->lsc != lsc || parentItem->lso != lso)) ((Q3ListViewItem *)this)->sortChildItems((int)parentItem->lsc, (bool)parentItem->lso); else if (!parentItem && ((int)lsc != lv->d->sortcolumn || (bool)lso != lv->d->ascending)) ((Q3ListViewItem *)this)->sortChildItems(lv->d->sortcolumn, lv->d->ascending);}/*! \fn bool Q3ListViewItem::isSelected() const Returns true if this item is selected; otherwise returns false. \sa setSelected() Q3ListView::setSelected() Q3ListView::selectionChanged()*//*! If \a s is true this item is selected; otherwise it is deselected. This function does not maintain any invariants or repaint anything -- Q3ListView::setSelected() does that. \sa height() totalHeight()*/void Q3ListViewItem::setSelected(bool s){ bool old = selected; Q3ListView *lv = listView(); if (lv && lv->selectionMode() != Q3ListView::NoSelection) { if (s && isSelectable()) selected = true; else selected = false;#ifndef QT_NO_ACCESSIBILITY if (old != (bool)selected) { int ind = indexOfItem(this); QAccessible::updateAccessibility(lv->viewport(), ind, QAccessible::StateChanged); QAccessible::updateAccessibility(lv->viewport(), ind, selected ? QAccessible::SelectionAdd : QAccessible::SelectionRemove); }#else Q_UNUSED(old);#endif }}/*! Returns the total height of this object, including any visible children. This height is recomputed lazily and cached for as long as possible. Functions which can affect the total height are, setHeight() which is used to set an item's height, setOpen() to show or hide an item's children, and invalidateHeight() to invalidate the cached height. \sa height()*/int Q3ListViewItem::totalHeight() const{ if (!visible) return 0; if (maybeTotalHeight >= 0) return maybeTotalHeight; Q3ListViewItem * that = (Q3ListViewItem *)this; if (!that->configured) { that->configured = true; that->setup(); // ### virtual non-const function called in const } that->maybeTotalHeight = that->ownHeight; if (!that->isOpen() || !that->childCount()) return that->ownHeight; Q3ListViewItem * child = that->childItem; while (child != 0) { that->maybeTotalHeight += child->totalHeight(); child = child->siblingItem; } return that->maybeTotalHeight;}/*! Returns the text in column \a column, or an empty string if there is no text in that column. \sa key() paintCell()*/QString Q3ListViewItem::text(int column) const{ Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*) columns; while(column && l) { l = l->next; column--; } return l ? l->text : QString();}/*! Sets the text in column \a column to \a text, if \a column is a valid column number and \a text is different from the existing text. If the text() function has been reimplemented, this function may be a no-op. \sa text() key()*/void Q3ListViewItem::setText(int column, const QString &text){ if (column < 0) return; Q3ListViewPrivate::ItemColumnInfo * l = (Q3ListViewPrivate::ItemColumnInfo*) columns; if (!l) { l = new Q3ListViewPrivate::ItemColumnInfo; columns = (void*)l; } for(int c = 0; c < column; c++) { if (!l->next) l->next = new Q3ListViewPrivate::ItemColumnInfo; l = l->next; } if (l->text == text) return; int oldLc = 0; int newLc = 0; if (mlenabled) { if (!l->text.isEmpty()) oldLc = l->text.count(QChar('\n')) + 1; if (!text.isEmpty()) newLc = text.count(QChar('\n')) + 1; } l->dirty = true; l->text = text; if (column == (int)lsc) lsc = Unsorted; if (mlenabled && oldLc != newLc) setup(); else widthChanged(column); Q3ListView * lv = listView(); if (lv) { lv->triggerUpdate();#ifndef QT_NO_ACCESSIBILITY if (lv->isVisible()) QAccessible::updateAccessibility(lv->viewport(), indexOfItem(this), QAccessible::NameChanged);#endif }}/*! Sets the pixmap in column \a column to \a pm, if \a pm is non-null and different from the current pixmap, and if \a column is non-negative. \sa pixmap() setText()*/void Q3ListViewItem::setPixmap(int column, const QPixmap & pm){ if (column < 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -