本文整理汇总了C++中ItemWidget类的典型用法代码示例。如果您正苦于以下问题:C++ ItemWidget类的具体用法?C++ ItemWidget怎么用?C++ ItemWidget使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ItemWidget类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: max_size
QWidget *ItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
ItemWidget *w = m_cache[index.row()];
QWidget *editor = ( w != NULL) ? w->createEditor(parent) : new QPlainTextEdit(parent);
if (editor == NULL)
return NULL;
editor->setPalette(m_editorPalette);
editor->setFont(m_editorFont);
editor->setObjectName("editor");
// maximal editor size
QRect w_rect = parent->contentsRect();
QRect o_rect = option.rect;
QSize max_size( w_rect.width() - o_rect.left() - 4,
w_rect.height() - o_rect.top() - 4 );
editor->setMaximumSize(max_size);
editor->setMinimumSize(max_size);
connect( editor, SIGNAL(destroyed()),
this, SLOT(editingStops()) );
connect( editor, SIGNAL(textChanged()),
this, SLOT(editingStarts()) );
return editor;
}
示例2: startDrag
void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count)
{
mItem = sourceModel->getItem(index);
mDraggedCount = count;
mSourceModel = sourceModel;
mSourceView = sourceView;
mSourceSortModel = sortModel;
mIsOnDragAndDrop = true;
// If picking up an item that isn't from the player's inventory, the item gets added to player inventory backend
// immediately, even though it's still floating beneath the mouse cursor. A bit counterintuitive,
// but this is how it works in vanilla, and not doing so would break quests (BM_beasts for instance).
ItemModel* playerModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getModel();
if (mSourceModel != playerModel)
{
MWWorld::Ptr item = mSourceModel->moveItem(mItem, mDraggedCount, playerModel);
playerModel->update();
ItemModel::ModelIndex newIndex = -1;
for (unsigned int i=0; i<playerModel->getItemCount(); ++i)
{
if (playerModel->getItem(i).mBase == item)
{
newIndex = i;
break;
}
}
mItem = playerModel->getItem(newIndex);
mSourceModel = playerModel;
SortFilterItemModel* playerFilterModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getSortFilterModel();
mSourceSortModel = playerFilterModel;
}
std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase);
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
if (mSourceSortModel)
{
mSourceSortModel->clearDragItems();
mSourceSortModel->addDragItem(mItem.mBase, count);
}
ItemWidget* baseWidget = MyGUI::Gui::getInstance().createWidget<ItemWidget>("MW_ItemIcon", 0, 0, 42, 42, MyGUI::Align::Default, "DragAndDrop");
Controllers::ControllerFollowMouse* controller =
MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerFollowMouse::getClassTypeName())
->castType<Controllers::ControllerFollowMouse>();
MyGUI::ControllerManager::getInstance().addItem(baseWidget, controller);
mDraggedWidget = baseWidget;
baseWidget->setItem(mItem.mBase);
baseWidget->setNeedMouseFocus(false);
baseWidget->setCount(count);
sourceView->update();
MWBase::Environment::get().getWindowManager()->setDragDrop(true);
}
示例3: QTreeWidgetItem
void Container::refreshView(QTreeWidget *treeView)
{
QTreeWidgetItem *selectedItem=treeView->currentItem();
if(this->getSelectedItem(treeView))
{
this->setSelectedItem(treeView,this->getSelectedItem(treeView));
}
treeView->clear();
if(this->root->size()>0)
{
QTreeWidgetItem * treeWidgetItem = new QTreeWidgetItem(treeView);
ItemWidget * myItem = new ItemWidget(
this->root->getId(),
QString( this->root->getTitle().c_str() ),
QString( this->root->getDate().c_str() ),
this->root->isDoneChecked(),
-1);
myItem->setState(false);
treeView->setItemWidget(treeWidgetItem,0,myItem);
this->addItemsFromList(this->root,treeView,treeWidgetItem);
}
if(!selectedItem&&treeView->itemAt(0,0))
{
this->setSelectedItem(treeView,this->root);
}
treeView->expandAll();
// this->root->afficher();
// std::cout<<std::endl;
}
示例4: setEditorData
void ItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
ItemWidget *w = m_cache[index.row()];
if ( w != NULL)
w->setEditorData(editor, index);
else
editor->setProperty( "plainText", index.data(Qt::EditRole) );
}
示例5: currentIndex
void ClipboardBrowser::updateCurrentItem()
{
const QModelIndex current = currentIndex();
if ( current.isValid() && d.hasCache(current) ) {
ItemWidget *item = d.cache(current);
item->setCurrent(false);
item->setCurrent( hasFocus() );
}
}
示例6: setModelData
void ItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
ItemWidget *w = m_cache[index.row()];
if ( w != NULL) {
w->setModelData(editor, model, index);
} else {
QPlainTextEdit *textEdit = (qobject_cast<QPlainTextEdit*>(editor));
model->setData(index, textEdit->toPlainText());
}
}
示例7: onItemChanged
void ItemDelegate::onItemChanged(ItemWidget *item)
{
for( int i = 0; i < m_cache.length(); ++i ) {
ItemWidget *w = m_cache[i];
if ( w != NULL && w == item ) {
QSize oldSize = w->widget()->size();
emit rowChanged(i, oldSize);
return;
}
}
}
示例8: rowNumberWidth
void ItemDelegate::setItemSizes(const QSize &size, int idealWidth)
{
const int margins = 2 * m_hMargin + rowNumberWidth();
m_maxSize.setWidth(size.width() - margins);
m_idealWidth = idealWidth - margins;
for( int i = 0; i < m_cache.length(); ++i ) {
ItemWidget *w = m_cache[i];
if (w != NULL)
w->updateSize(m_maxSize, m_idealWidth);
}
}
示例9: Q_UNUSED
QWidget* UniversalItemDelegate::createEditor(
QWidget* parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {
Q_UNUSED(option);
editingRow = index.row();
ItemWidget* newEditor = editor->clone(parent);
newEditor->setIndex(index);
return newEditor;
}
示例10: assert
void ResolveRecipientsPage::ListWidget::addEntry( const QString& id, const QString& name, const Mailbox& mbox )
{
assert( !widgets.contains( id ) && !items.contains( id ) );
QListWidgetItem* item = new QListWidgetItem;
item->setData( IdRole, id );
ItemWidget* wid = new ItemWidget( id, name, mbox, this );
connect( wid, SIGNAL(changed()), this, SIGNAL(completeChanged()) );
wid->setProtocol( m_protocol );
item->setSizeHint( wid->sizeHint() );
m_listWidget->addItem( item );
m_listWidget->setItemWidget( item, wid );
widgets[id] = wid;
items[id] = item;
}
示例11: while
void ItemView::update()
{
while (mScrollView->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));
if (!mModel)
return;
mModel->update();
MyGUI::Widget* dragArea = mScrollView->createWidget<MyGUI::Widget>("",0,0,mScrollView->getWidth(),mScrollView->getHeight(),
MyGUI::Align::Stretch);
dragArea->setNeedMouseFocus(true);
dragArea->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedBackground);
dragArea->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheel);
for (ItemModel::ModelIndex i=0; i<static_cast<int>(mModel->getItemCount()); ++i)
{
const ItemStack& item = mModel->getItem(i);
ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
itemWidget->setUserString("ToolTipType", "ItemModelIndex");
itemWidget->setUserData(std::make_pair(i, mModel));
ItemWidget::ItemState state = ItemWidget::None;
if (item.mType == ItemStack::Type_Barter)
state = ItemWidget::Barter;
if (item.mType == ItemStack::Type_Equipped)
state = ItemWidget::Equip;
itemWidget->setItem(item.mBase, state);
itemWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedItem);
itemWidget->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheel);
// text widget that shows item count
// TODO: move to ItemWidget
MyGUI::TextBox* text = itemWidget->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::IntCoord(5, 19, 32, 18), MyGUI::Align::Default, std::string("Label"));
text->setTextAlign(MyGUI::Align::Right);
text->setNeedMouseFocus(false);
text->setTextShadow(true);
text->setTextShadowColour(MyGUI::Colour(0,0,0));
text->setCaption(getCountString(item.mCount));
}
layoutWidgets();
}
示例12: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
bool isSelected = option.state & QStyle::State_Selected;
/* render background (selected, alternate, ...) */
QStyle *style = m_view->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter, m_view);
/* render number */
if (m_showRowNumber) {
const QString num = QString::number(row);
QPalette::ColorRole role = isSelected ? QPalette::HighlightedText : QPalette::Text;
painter->save();
painter->setFont(m_rowNumberFont);
style->drawItemText(painter, rect.translated(m_hMargin / 2, m_vMargin), 0,
m_rowNumberPalette, true, num,
role);
painter->restore();
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QWidget *ww = w->widget();
if ( ww->property(propertySelectedItem) != isSelected ) {
ww->setProperty(propertySelectedItem, isSelected);
if ( !ww->property("CopyQ_no_style").toBool() ) {
ww->setStyle(style);
foreach (QWidget *child, ww->findChildren<QWidget *>())
child->setStyle(style);
ww->update();
}
}
}
示例13: paint
void ItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
int row = index.row();
ItemWidget *w = m_cache[row];
if (w == NULL)
return;
const QRect &rect = option.rect;
/* render background (selected, alternate, ...) */
QStyle *style = m_parent->style();
style->drawControl(QStyle::CE_ItemViewItem, &option, painter);
QPalette::ColorRole role = option.state & QStyle::State_Selected ?
QPalette::HighlightedText : QPalette::Text;
/* render number */
QRect numRect(0, 0, 0, 0);
if (m_showNumber) {
QString num = QString::number(row) + " ";
painter->save();
painter->setFont(m_numberFont);
style->drawItemText(painter, rect.translated(4, 4), 0,
m_numberPalette, true, num,
role);
painter->restore();
numRect = style->itemTextRect( QFontMetrics(m_numberFont), rect, 0,
true, num );
}
/* highlight search string */
w->setHighlight(m_re, m_foundFont, m_foundPalette);
/* text color for selected/unselected item */
QPalette palette = w->widget()->palette();
palette.setColor( QPalette::Text, option.palette.color(role) );
w->widget()->setPalette(palette);
/* render widget */
w->widget()->show();
}
示例14: QFontMetrics
void ItemDelegate::setItemMaximumSize(const QSize &size)
{
int w = size.width() - 8;
if (m_showNumber) {
w -= QFontMetrics(m_numberFont).boundingRect( QString("0123") ).width();
}
if (m_maxSize.width() == w)
return;
m_maxSize.setWidth(w);
for( int i = 0; i < m_cache.length(); ++i ) {
ItemWidget *w = m_cache[i];
if (w != NULL) {
QSize oldSize = w->widget()->size();
w->widget()->setMaximumSize(m_maxSize);
w->updateSize();
emit rowChanged(i, oldSize);
}
}
}
示例15: startDrag
void DragAndDrop::startDrag (int index, SortFilterItemModel* sortModel, ItemModel* sourceModel, ItemView* sourceView, int count)
{
mItem = sourceModel->getItem(index);
mDraggedCount = count;
mSourceModel = sourceModel;
mSourceView = sourceView;
mSourceSortModel = sortModel;
mIsOnDragAndDrop = true;
mDragAndDropWidget->setVisible(true);
std::string sound = mItem.mBase.getClass().getUpSoundId(mItem.mBase);
MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0);
if (mSourceSortModel)
{
mSourceSortModel->clearDragItems();
mSourceSortModel->addDragItem(mItem.mBase, count);
}
ItemWidget* baseWidget = mDragAndDropWidget->createWidget<ItemWidget>
("MW_ItemIcon", MyGUI::IntCoord(0, 0, 42, 42), MyGUI::Align::Default);
mDraggedWidget = baseWidget;
baseWidget->setItem(mItem.mBase);
baseWidget->setNeedMouseFocus(false);
// text widget that shows item count
// TODO: move to ItemWidget
MyGUI::TextBox* text = baseWidget->createWidget<MyGUI::TextBox>("SandBrightText",
MyGUI::IntCoord(0, 14, 32, 18), MyGUI::Align::Default, std::string("Label"));
text->setTextAlign(MyGUI::Align::Right);
text->setNeedMouseFocus(false);
text->setTextShadow(true);
text->setTextShadowColour(MyGUI::Colour(0,0,0));
text->setCaption(ItemView::getCountString(count));
sourceView->update();
MWBase::Environment::get().getWindowManager()->setDragDrop(true);
}