1 /**************************************************************************** 2 ** 3 ** DQt - D bindings for the Qt Toolkit 4 ** 5 ** GNU Lesser General Public License Usage 6 ** This file may be used under the terms of the GNU Lesser 7 ** General Public License version 3 as published by the Free Software 8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 9 ** packaging of this file. Please review the following information to 10 ** ensure the GNU Lesser General Public License version 3 requirements 11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 12 ** 13 ****************************************************************************/ 14 module qt.widgets.listwidget; 15 extern(C++): 16 17 import qt.config; 18 import qt.core.abstractitemmodel; 19 import qt.core.coreevent; 20 import qt.core.itemselectionmodel; 21 import qt.core.list; 22 import qt.core.mimedata; 23 import qt.core.namespace; 24 import qt.core.point; 25 import qt.core.rect; 26 import qt.core.size; 27 import qt.core.string; 28 import qt.core.stringlist; 29 import qt.core.variant; 30 import qt.core.vector; 31 import qt.gui.brush; 32 import qt.gui.color; 33 import qt.gui.event; 34 import qt.gui.font; 35 import qt.gui.icon; 36 import qt.helpers; 37 import qt.widgets.abstractitemview; 38 import qt.widgets.listview; 39 import qt.widgets.widget; 40 version(QT_NO_DATASTREAM){}else 41 import qt.core.datastream; 42 43 /+ QT_REQUIRE_CONFIG(listwidget); 44 45 46 class QListWidget; +/ 47 extern(C++, class) struct QListModel; 48 extern(C++, class) struct QListWidgetItemPrivate; 49 50 class /+ Q_WIDGETS_EXPORT +/ QListWidgetItem 51 { 52 private: 53 /+ friend class QListModel; +/ 54 /+ friend class QListWidget; +/ 55 public: 56 enum ItemType { Type = 0, UserType = 1000 } 57 /+ explicit +/this(QListWidget listview = null, int type = ItemType.Type); 58 /+ explicit +/this(ref const(QString) text, QListWidget listview = null, int type = ItemType.Type); 59 /+ explicit +/this(ref const(QIcon) icon, ref const(QString) text, 60 QListWidget listview = null, int type = ItemType.Type); 61 /+ QListWidgetItem(const QListWidgetItem &other); +/ 62 /+ virtual +/~this(); 63 64 /+ virtual +/ QListWidgetItem clone() const; 65 66 pragma(inline, true) final QListWidget listWidget() const { return cast(QListWidget)view; } 67 68 final void setSelected(bool select); 69 final bool isSelected() const; 70 71 pragma(inline, true) final void setHidden(bool ahide) 72 { if (view) view.setRowHidden(view.row(this), ahide); } 73 pragma(inline, true) final bool isHidden() const 74 { return (view ? view.isRowHidden(view.row(this)) : false); } 75 76 pragma(inline, true) final /+ Qt:: +/qt.core.namespace.ItemFlags flags() const { return itemFlags; } 77 final void setFlags(/+ Qt:: +/qt.core.namespace.ItemFlags flags); 78 79 pragma(inline, true) final QString text() const 80 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole).toString(); } 81 pragma(inline, true) final void setText(ref const(QString) atext) 82 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole, atext); } 83 84 /+ pragma(inline, true) final QIcon icon() const 85 { return qvariant_cast!(QIcon)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole)); } 86 pragma(inline, true) final void setIcon(ref const(QIcon) aicon) 87 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole, aicon); }+/ 88 89 pragma(inline, true) final QString statusTip() const 90 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole).toString(); } 91 pragma(inline, true) final void setStatusTip(ref const(QString) astatusTip) 92 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.StatusTipRole, astatusTip); } 93 94 /+ #ifndef QT_NO_TOOLTIP +/ 95 version(QT_NO_TOOLTIP){}else 96 { 97 pragma(inline, true) final QString toolTip() const 98 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole).toString(); } 99 pragma(inline, true) final void setToolTip(ref const(QString) atoolTip) 100 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ToolTipRole, atoolTip); } 101 } 102 /+ #endif 103 104 #if QT_CONFIG(whatsthis) +/ 105 pragma(inline, true) final QString whatsThis() const 106 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole).toString(); } 107 pragma(inline, true) final void setWhatsThis(ref const(QString) awhatsThis) 108 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.WhatsThisRole, awhatsThis); } 109 /+ #endif +/ 110 111 pragma(inline, true) final QFont font() const 112 { return qvariant_cast!(QFont)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole)); } 113 pragma(inline, true) final void setFont(ref const(QFont) afont) 114 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.FontRole, afont); } 115 116 pragma(inline, true) final int textAlignment() const 117 { return data(/+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole).toInt(); } 118 pragma(inline, true) final void setTextAlignment(int alignment) 119 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.TextAlignmentRole, alignment); } 120 121 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 122 /+ QT_DEPRECATED_X ("Use QListWidgetItem::background() instead") +/ 123 pragma(inline, true) final QColor backgroundColor() const 124 { return qvariant_cast!(QColor)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole)); } 125 /+ #endif +/ 126 // no QT_DEPRECATED_SINCE because it is a virtual function 127 /+ QT_DEPRECATED_X ("Use QListWidgetItem::setBackground() instead") +/ 128 /+ virtual +/ void setBackgroundColor(ref const(QColor) color) 129 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole, QVariant.fromValue(color)); } 130 131 pragma(inline, true) final QBrush background() const 132 { return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole)); } 133 pragma(inline, true) final void setBackground(ref const(QBrush) brush) 134 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.BackgroundRole, brush.style() != /+ Qt:: +/qt.core.namespace.BrushStyle.NoBrush ? QVariant.fromValue(brush) : QVariant()); } 135 136 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 137 /+ QT_DEPRECATED_X ("Use QListWidgetItem::foreground() instead") +/ 138 pragma(inline, true) final QColor textColor() const 139 { return qvariant_cast!(QColor)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole)); } 140 /+ QT_DEPRECATED_X ("Use QListWidgetItem::setForeground() instead") +/ 141 pragma(inline, true) final void setTextColor(ref const(QColor) color) 142 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole, color); } 143 /+ #endif +/ 144 145 pragma(inline, true) final QBrush foreground() const 146 { return qvariant_cast!(QBrush)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole)); } 147 pragma(inline, true) final void setForeground(ref const(QBrush) brush) 148 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.ForegroundRole, brush.style() != /+ Qt:: +/qt.core.namespace.BrushStyle.NoBrush ? QVariant.fromValue(brush) : QVariant()); } 149 150 pragma(inline, true) final /+ Qt:: +/qt.core.namespace.CheckState checkState() const 151 { return static_cast!(/+ Qt:: +/qt.core.namespace.CheckState)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole).toInt()); } 152 pragma(inline, true) final void setCheckState(/+ Qt:: +/qt.core.namespace.CheckState state) 153 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.CheckStateRole, static_cast!(int)(state)); } 154 155 pragma(inline, true) final QSize sizeHint() const 156 { return qvariant_cast!(QSize)(data(/+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole)); } 157 pragma(inline, true) final void setSizeHint(ref const(QSize) size) 158 { setData(/+ Qt:: +/qt.core.namespace.ItemDataRole.SizeHintRole, size.isValid() ? QVariant.fromValue(size) : QVariant()); } 159 160 /+ virtual +/ QVariant data(int role) const; 161 /+ virtual +/ void setData(int role, ref const(QVariant) value); 162 final void setData(T)(int role, T value) 163 { 164 static if(is(const(T) == const(QVariant))) 165 QVariant v = value; 166 else 167 QVariant v = QVariant.fromValue(value); 168 setData(role, v); 169 } 170 171 pragma(mangle, mangleOpLess("QListWidgetItem")) 172 bool opLess(const QListWidgetItem other) const; 173 174 version(QT_NO_DATASTREAM){}else 175 { 176 /+ virtual +/ void read(ref QDataStream in_); 177 /+ virtual +/ void write(ref QDataStream out_) const; 178 } 179 /+ QListWidgetItem &operator=(const QListWidgetItem &other); +/ 180 181 pragma(inline, true) final int type() const { return rtti; } 182 183 private: 184 final QListModel* listModel() const; 185 int rtti; 186 QVector!(void*) dummy; 187 QListWidget view; 188 QListWidgetItemPrivate* d; 189 /+ Qt:: +/qt.core.namespace.ItemFlags itemFlags; 190 } 191 192 /+ #ifndef QT_NO_TOOLTIP 193 #endif 194 195 #if QT_CONFIG(whatsthis) 196 #endif 197 198 #ifndef QT_NO_DATASTREAM 199 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item); 200 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &in, QListWidgetItem &item); 201 #endif +/ 202 203 extern(C++, class) struct QListWidgetPrivate; 204 205 class /+ Q_WIDGETS_EXPORT +/ QListWidget : QListView 206 { 207 mixin(Q_OBJECT); 208 /+ Q_PROPERTY(int count READ count) 209 Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow NOTIFY currentRowChanged USER true) 210 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled) +/ 211 212 /+ friend class QListWidgetItem; +/ 213 /+ friend class QListModel; +/ 214 public: 215 /+ explicit +/this(QWidget parent = null); 216 ~this(); 217 218 override void setSelectionModel(QItemSelectionModel selectionModel); 219 220 final QListWidgetItem item(int row) const; 221 mixin(mangleWindows("?row@QListWidget@@QEBAHPEBVQListWidgetItem@@@Z", q{ 222 final int row(const(QListWidgetItem) item) const; 223 })); 224 final void insertItem(int row, QListWidgetItem item); 225 final void insertItem(int row, ref const(QString) label); 226 final void insertItems(int row, ref const(QStringList) labels); 227 pragma(inline, true) final void addItem(ref const(QString) label) { insertItem(count(), label); } 228 pragma(inline, true) final void addItem(QListWidgetItem aitem) 229 { insertItem(count(), aitem); } 230 final void addItem(const(QString) label) { addItem(label); } 231 pragma(inline, true) final void addItems(ref const(QStringList) labels) { insertItems(count(), labels); } 232 final QListWidgetItem takeItem(int row); 233 final int count() const; 234 235 final QListWidgetItem currentItem() const; 236 final void setCurrentItem(QListWidgetItem item); 237 final void setCurrentItem(QListWidgetItem item, QItemSelectionModel.SelectionFlags command); 238 239 final int currentRow() const; 240 final void setCurrentRow(int row); 241 final void setCurrentRow(int row, QItemSelectionModel.SelectionFlags command); 242 243 final QListWidgetItem itemAt(ref const(QPoint) p) const; 244 pragma(inline, true) final QListWidgetItem itemAt(int ax, int ay) const 245 { auto tmp = QPoint(ax, ay); return itemAt(tmp); } 246 final QRect visualItemRect(const(QListWidgetItem) item) const; 247 248 final void sortItems(/+ Qt:: +/qt.core.namespace.SortOrder order = /+ Qt:: +/qt.core.namespace.SortOrder.AscendingOrder); 249 final void setSortingEnabled(bool enable); 250 final bool isSortingEnabled() const; 251 252 final void editItem(QListWidgetItem item); 253 final void openPersistentEditor(QListWidgetItem item); 254 final void closePersistentEditor(QListWidgetItem item); 255 /+ using QAbstractItemView::isPersistentEditorOpen; +/ 256 final bool isPersistentEditorOpen(QListWidgetItem item) const; 257 258 final QWidget itemWidget(QListWidgetItem item) const; 259 final void setItemWidget(QListWidgetItem item, QWidget widget); 260 pragma(inline, true) final void removeItemWidget(QListWidgetItem aItem) 261 { setItemWidget(aItem, null); } 262 263 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 264 /+ QT_DEPRECATED_X ("Use QListWidgetItem::isSelected() instead") +/ 265 final bool isItemSelected(const(QListWidgetItem) item) const; 266 /+ QT_DEPRECATED_X ("Use QListWidgetItem::setSelected() instead") +/ 267 final void setItemSelected(const(QListWidgetItem) item, bool select); 268 /+ #endif +/ 269 final QList!(QListWidgetItem) selectedItems() const; 270 final QList!(QListWidgetItem) findItems(ref const(QString) text, /+ Qt:: +/qt.core.namespace.MatchFlags flags) const; 271 272 /+ #if QT_DEPRECATED_SINCE(5, 13) +/ 273 /+ QT_DEPRECATED_X ("Use QListWidgetItem::isHidden() instead") +/ 274 final bool isItemHidden(const(QListWidgetItem) item) const; 275 /+ QT_DEPRECATED_X ("Use QListWidgetItem::setHidden() instead") +/ 276 final void setItemHidden(const(QListWidgetItem) item, bool hide); 277 /+ #endif 278 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 279 protected: 280 #endif 281 #if QT_CONFIG(draganddrop) +/ 282 override void dropEvent(QDropEvent event); 283 /+ #endif +/ 284 public /+ Q_SLOTS +/: 285 @QSlot final void scrollToItem(const(QListWidgetItem) item, QAbstractItemView.ScrollHint hint = ScrollHint.EnsureVisible); 286 @QSlot final void clear(); 287 288 /+ Q_SIGNALS +/public: 289 @QSignal final void itemPressed(QListWidgetItem item); 290 @QSignal final void itemClicked(QListWidgetItem item); 291 @QSignal final void itemDoubleClicked(QListWidgetItem item); 292 @QSignal final void itemActivated(QListWidgetItem item); 293 @QSignal final void itemEntered(QListWidgetItem item); 294 // ### Qt 6: add changed roles 295 @QSignal final void itemChanged(QListWidgetItem item); 296 297 @QSignal final void currentItemChanged(QListWidgetItem current, QListWidgetItem previous); 298 @QSignal final void currentTextChanged(ref const(QString) currentText); 299 @QSignal final void currentRowChanged(int currentRow); 300 301 @QSignal final void itemSelectionChanged(); 302 303 protected: 304 override bool event(QEvent e); 305 /+ virtual +/ QStringList mimeTypes() const; 306 /+ #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) 307 virtual QMimeData *mimeData(const QList<QListWidgetItem *> &items) const; 308 #else +/ 309 /+ virtual +/ QMimeData mimeData(const(QList!(QListWidgetItem)) items) const; 310 /+ #endif 311 #if QT_CONFIG(draganddrop) +/ 312 mixin(mangleWindows("?dropMimeData@QListWidget@@MEAA_NHPEBVQMimeData@@W4DropAction@Qt@@@Z", q{ 313 /+ virtual +/ bool dropMimeData(int index, const(QMimeData) data, /+ Qt:: +/qt.core.namespace.DropAction action); 314 })); 315 /+ virtual +/ /+ Qt:: +/qt.core.namespace.DropActions supportedDropActions() const; 316 /+ #endif 317 318 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 319 public: 320 #else +/ 321 protected: 322 /+ #endif +/ 323 final QList!(QListWidgetItem) items(const(QMimeData) data) const; 324 325 final QModelIndex indexFromItem(const(QListWidgetItem) item) const; 326 /+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +/ 327 final QModelIndex indexFromItem(QListWidgetItem item) const; // ### Qt 6: remove 328 /+ #endif +/ 329 final QListWidgetItem itemFromIndex(ref const(QModelIndex) index) const; 330 331 private: 332 mixin(mangleWindows("?setModel@QListWidget@@EEAAXPEAVQAbstractItemModel@@@Z", q{ 333 protected override void setModel(QAbstractItemModel model); 334 })); 335 final /+ Qt:: +/qt.core.namespace.SortOrder sortOrder() const; 336 337 /+ Q_DECLARE_PRIVATE(QListWidget) +/ 338 /+ Q_DISABLE_COPY(QListWidget) +/ 339 340 /+ Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index)) 341 Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index)) 342 Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index)) 343 Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index)) 344 Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index)) 345 Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index)) 346 Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex ¤t)) 347 Q_PRIVATE_SLOT(d_func(), void _q_sort()) 348 Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)) +/ 349 } 350