Example #1
0
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;
}
Example #2
0
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);
}
Example #3
0
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;
}
Example #4
0
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) );
}
Example #5
0
void ClipboardBrowser::updateCurrentItem()
{
    const QModelIndex current = currentIndex();
    if ( current.isValid() && d.hasCache(current) ) {
        ItemWidget *item = d.cache(current);
        item->setCurrent(false);
        item->setCurrent( hasFocus() );
    }
}
Example #6
0
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());
    }
}
Example #7
0
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;
        }
    }
}
Example #8
0
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);
    }
}
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;
}
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;
}
Example #11
0
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();
}
Example #12
0
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();
        }
    }
}
Example #13
0
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();
}
Example #14
0
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);
        }
    }
}
Example #15
0
    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);
    }
Example #16
0
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::onMouseWheelMoved);

    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->setCount(item.mCount);

        itemWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemView::onSelectedItem);
        itemWidget->eventMouseWheel += MyGUI::newDelegate(this, &ItemView::onMouseWheelMoved);
    }

    layoutWidgets();
}
Example #17
0
void ItemDelegate::updateRowPosition(int row, const QPoint &position)
{
    ItemWidget *w = m_cache[row];
    if (w == NULL)
        return;

    int x = position.x();
    int y = position.y();

    if (m_showNumber)
        x += QFontMetrics(m_numberFont).boundingRect( QString("0123") ).width();

    w->widget()->move(x, y);

    y += w->widget()->height();
    for (int i = row + 1; i < m_cache.size(); ++i ) {
        w = m_cache[i];
        if (w == NULL)
            continue;

        if (w->widget()->y() < y)
            w->widget()->hide();
    }
}
Example #18
0
bool ItemDelegate::eventFilter(QObject *object, QEvent *event)
{
    if (object->objectName() == "editor") {
        QPlainTextEdit *editor = qobject_cast<QPlainTextEdit*>(object);
        if (editor == NULL)
            return false;

        QEvent::Type type = event->type();
        if ( type == QEvent::KeyPress ) {
            QKeyEvent *keyevent = static_cast<QKeyEvent *>(event);
            switch ( keyevent->key() ) {
                case Qt::Key_Enter:
                case Qt::Key_Return:
                    // Commit data on Ctrl+Return or Enter?
                    if (m_saveOnReturnKey) {
                        if (keyevent->modifiers() == Qt::ControlModifier) {
                            editor->insertPlainText("\n");
                            return true;
                        } else if (keyevent->modifiers() != Qt::NoModifier) {
                            return false;
                        }
                    } else {
                        if (keyevent->modifiers() != Qt::ControlModifier)
                            return false;
                    }
                    emit commitData(editor);
                    emit closeEditor(editor);
                    return true;
                case Qt::Key_S:
                    // Commit data on Ctrl+S.
                    if (keyevent->modifiers() != Qt::ControlModifier)
                        return false;
                    emit commitData(editor);
                    emit closeEditor(editor);
                    return true;
                case Qt::Key_F2:
                    // Commit data on F2.
                    emit commitData(editor);
                    emit closeEditor(editor);
                    return true;
                case Qt::Key_Escape:
                    // Close editor without committing data.
                    emit closeEditor(editor, QAbstractItemDelegate::RevertModelCache);
                    return true;
                default:
                    return false;
            }
        } else if ( type == QEvent::ContextMenu ) {
            QAction *act;
            QMenu *menu = editor->createStandardContextMenu();
            connect( menu, SIGNAL(aboutToHide()), menu, SLOT(deleteLater()) );
            menu->setParent(editor);

            act = menu->addAction( tr("&Save Item") );
            act->setShortcut( QKeySequence(tr("F2, Ctrl+Enter")) );
            connect( act, SIGNAL(triggered()), this, SLOT(editorSave()) );

            act = menu->addAction( tr("Cancel Editing") );
            act->setShortcut( QKeySequence(tr("Escape")) );
            connect( act, SIGNAL(triggered()), this, SLOT(editorCancel()) );

            QContextMenuEvent *menuEvent = static_cast<QContextMenuEvent *>(event);
            menu->popup( menuEvent->globalPos() );
        }
    } else {
        // resize event for items
        if (event->type() == QEvent::Resize) {
            QResizeEvent *resize = static_cast<QResizeEvent *>(event);
            ItemWidget *item = dynamic_cast<ItemWidget *>(object);
            if (item != NULL) {
                item->widget()->resize(resize->size());
                onItemChanged(item);
                return true;
            }
        }
    }

    return false;
}
Example #19
0
void ItemDelegate::hideRow(int row)
{
    ItemWidget *w = m_cache[row];
    if (w != NULL)
        w->widget()->hide();
}
Example #20
0
void Recharge::updateView()
{
    MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>();

    std::string soul = gem.getCellRef().getSoul();
    const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul);

    mChargeLabel->setCaptionWithReplacing("#{sCharges} " + MyGUI::utility::toString(creature->mData.mSoul));

    bool toolBoxVisible = (gem.getRefData().getCount() != 0);
    mGemBox->setVisible(toolBoxVisible);

    bool toolBoxWasVisible = (mBox->getPosition().top != mGemBox->getPosition().top);

    if (toolBoxVisible && !toolBoxWasVisible)
    {
        // shrink
        mBox->setPosition(mBox->getPosition() + MyGUI::IntPoint(0, mGemBox->getSize().height));
        mBox->setSize(mBox->getSize() - MyGUI::IntSize(0,mGemBox->getSize().height));
    }
    else if (!toolBoxVisible && toolBoxWasVisible)
    {
        // expand
        mBox->setPosition(MyGUI::IntPoint (mBox->getPosition().left, mGemBox->getPosition().top));
        mBox->setSize(mBox->getSize() + MyGUI::IntSize(0,mGemBox->getSize().height));
    }

    while (mView->getChildCount())
        MyGUI::Gui::getInstance().destroyWidget(mView->getChildAt(0));

    int currentY = 0;

    MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
    MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
    for (MWWorld::ContainerStoreIterator iter (store.begin());
         iter!=store.end(); ++iter)
    {
        std::string enchantmentName = iter->getClass().getEnchantment(*iter);
        if (enchantmentName.empty())
            continue;
        const ESM::Enchantment* enchantment = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().find(enchantmentName);
        if (iter->getCellRef().getEnchantmentCharge() >= enchantment->mData.mCharge
                || iter->getCellRef().getEnchantmentCharge() == -1)
            continue;

        MyGUI::TextBox* text = mView->createWidget<MyGUI::TextBox> (
                    "SandText", MyGUI::IntCoord(8, currentY, mView->getWidth()-8, 18), MyGUI::Align::Default);
        text->setCaption(iter->getClass().getName(*iter));
        text->setNeedMouseFocus(false);
        currentY += 19;

        ItemWidget* icon = mView->createWidget<ItemWidget> (
                    "MW_ItemIconSmall", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default);
        icon->setItem(*iter);
        icon->setUserString("ToolTipType", "ItemPtr");
        icon->setUserData(*iter);
        icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onItemClicked);
        icon->eventMouseWheel += MyGUI::newDelegate(this, &Recharge::onMouseWheel);

        Widgets::MWDynamicStatPtr chargeWidget = mView->createWidget<Widgets::MWDynamicStat>
                ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default);
        chargeWidget->setValue(static_cast<int>(iter->getCellRef().getEnchantmentCharge()), enchantment->mData.mCharge);
        chargeWidget->setNeedMouseFocus(false);

        currentY += 32 + 4;
    }

    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mView->setVisibleVScroll(false);
    mView->setCanvasSize (MyGUI::IntSize(mView->getWidth(), std::max(mView->getHeight(), currentY)));
    mView->setVisibleVScroll(true);
}
Example #21
0
void Repair::updateRepairView()
{
    MWWorld::LiveCellRef<ESM::Repair> *ref =
        mRepair.getTool().get<ESM::Repair>();

    int uses = mRepair.getTool().getClass().getItemHealth(mRepair.getTool());

    float quality = ref->mBase->mData.mQuality;

    std::stringstream qualityStr;
    qualityStr << std::setprecision(3) << quality;

    mUsesLabel->setCaptionWithReplacing("#{sUses} " + boost::lexical_cast<std::string>(uses));
    mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str());

    bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0);
    mToolBox->setVisible(toolBoxVisible);

    bool toolBoxWasVisible = (mRepairBox->getPosition().top != mToolBox->getPosition().top);

    if (toolBoxVisible && !toolBoxWasVisible)
    {
        // shrink
        mRepairBox->setPosition(mRepairBox->getPosition() + MyGUI::IntPoint(0,mToolBox->getSize().height));
        mRepairBox->setSize(mRepairBox->getSize() - MyGUI::IntSize(0,mToolBox->getSize().height));
    }
    else if (!toolBoxVisible && toolBoxWasVisible)
    {
        // expand
        mRepairBox->setPosition(MyGUI::IntPoint (mRepairBox->getPosition().left, mToolBox->getPosition().top));
        mRepairBox->setSize(mRepairBox->getSize() + MyGUI::IntSize(0,mToolBox->getSize().height));
    }

    while (mRepairView->getChildCount())
        MyGUI::Gui::getInstance().destroyWidget(mRepairView->getChildAt(0));

    int currentY = 0;

    MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
    MWWorld::ContainerStore& store = player.getClass().getContainerStore(player);
    int categories = MWWorld::ContainerStore::Type_Weapon | MWWorld::ContainerStore::Type_Armor;
    for (MWWorld::ContainerStoreIterator iter (store.begin(categories));
         iter!=store.end(); ++iter)
    {
        if (iter->getClass().hasItemHealth(*iter))
        {
            int maxDurability = iter->getClass().getItemMaxHealth(*iter);
            int durability = iter->getClass().getItemHealth(*iter);
            if (maxDurability == durability)
                continue;

            MyGUI::TextBox* text = mRepairView->createWidget<MyGUI::TextBox> (
                        "SandText", MyGUI::IntCoord(8, currentY, mRepairView->getWidth()-8, 18), MyGUI::Align::Default);
            text->setCaption(iter->getClass().getName(*iter));
            text->setNeedMouseFocus(false);
            currentY += 19;

            ItemWidget* icon = mRepairView->createWidget<ItemWidget> (
                        "MW_ItemIconSmall", MyGUI::IntCoord(16, currentY, 32, 32), MyGUI::Align::Default);
            icon->setItem(*iter);
            icon->setUserString("ToolTipType", "ItemPtr");
            icon->setUserData(*iter);
            icon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onRepairItem);
            icon->eventMouseWheel += MyGUI::newDelegate(this, &Repair::onMouseWheel);

            Widgets::MWDynamicStatPtr chargeWidget = mRepairView->createWidget<Widgets::MWDynamicStat>
                    ("MW_ChargeBar", MyGUI::IntCoord(72, currentY+2, 199, 20), MyGUI::Align::Default);
            chargeWidget->setValue(durability, maxDurability);
            chargeWidget->setNeedMouseFocus(false);

            currentY += 32 + 4;
        }
    }
    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mRepairView->setVisibleVScroll(false);
    mRepairView->setCanvasSize (MyGUI::IntSize(mRepairView->getWidth(), std::max(mRepairView->getHeight(), currentY)));
    mRepairView->setVisibleVScroll(true);
}
Example #22
0
    void AlchemyWindow::update()
    {
        std::string suggestedName = mAlchemy->suggestPotionName();
        if (suggestedName != mSuggestedPotionName)
            mNameEdit->setCaptionWithReplacing(suggestedName);
        mSuggestedPotionName = suggestedName;

        mSortModel->clearDragItems();

        MWMechanics::Alchemy::TIngredientsIterator it = mAlchemy->beginIngredients ();
        for (int i=0; i<4; ++i)
        {
            ItemWidget* ingredient = mIngredients[i];

            MWWorld::Ptr item;
            if (it != mAlchemy->endIngredients ())
            {
                item = *it;
                ++it;
            }

            if (!item.isEmpty())
                mSortModel->addDragItem(item, item.getRefData().getCount());

            if (ingredient->getChildCount())
                MyGUI::Gui::getInstance().destroyWidget(ingredient->getChildAt(0));

            ingredient->clearUserStrings ();

            ingredient->setItem(item);

            if (item.isEmpty ())
                continue;

            ingredient->setUserString("ToolTipType", "ItemPtr");
            ingredient->setUserData(item);

            ingredient->setCount(ingredient->getUserData<MWWorld::Ptr>()->getRefData().getCount());
        }

        mItemView->update();

        std::set<MWMechanics::EffectKey> effectIds = mAlchemy->listEffects();
        Widgets::SpellEffectList list;
        for (std::set<MWMechanics::EffectKey>::iterator it = effectIds.begin(); it != effectIds.end(); ++it)
        {
            Widgets::SpellEffectParams params;
            params.mEffectID = it->mId;
            const ESM::MagicEffect* magicEffect = MWBase::Environment::get().getWorld()->getStore().get<ESM::MagicEffect>().find(it->mId);
            if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetSkill)
                params.mSkill = it->mArg;
            else if (magicEffect->mData.mFlags & ESM::MagicEffect::TargetAttribute)
                params.mAttribute = it->mArg;
            params.mIsConstant = true;
            params.mNoTarget = true;

            list.push_back(params);
        }

        while (mEffectsBox->getChildCount())
            MyGUI::Gui::getInstance().destroyWidget(mEffectsBox->getChildAt(0));

        MyGUI::IntCoord coord(0, 0, mEffectsBox->getWidth(), 24);
        Widgets::MWEffectListPtr effectsWidget = mEffectsBox->createWidget<Widgets::MWEffectList>
            ("MW_StatName", coord, MyGUI::Align::Left | MyGUI::Align::Top);

        effectsWidget->setEffectList(list);

        std::vector<MyGUI::Widget*> effectItems;
        effectsWidget->createEffectWidgets(effectItems, mEffectsBox, coord, false, 0);
        effectsWidget->setCoord(coord);
    }
Example #23
0
void ItemDelegate::setRowVisible(int row, bool visible)
{
    ItemWidget *w = m_cache[row];
    if (w != NULL)
        w->widget()->setVisible(visible);
}
Example #24
0
void ItemView::update()
{
    while (mScrollView->getChildCount())
        MyGUI::Gui::getInstance().destroyWidget(mScrollView->getChildAt(0));

    if (!mModel)
        return;

    int x = 0;
    int y = 0;
    int maxHeight = mScrollView->getSize().height - 58;

    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);

        /// \todo performance improvement: don't create/destroy all the widgets everytime the container window changes size, only reposition them
        ItemWidget* itemWidget = dragArea->createWidget<ItemWidget>("MW_ItemIcon",
            MyGUI::IntCoord(x, y, 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));

        y += 42;
        if (y > maxHeight)
        {
            x += 42;
            y = 0;
        }

    }
    x += 42;
    MyGUI::IntSize size = MyGUI::IntSize(std::max(mScrollView->getSize().width, x), mScrollView->getSize().height);

    // Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
    mScrollView->setVisibleVScroll(false);
    mScrollView->setVisibleHScroll(false);
    mScrollView->setCanvasSize(size);
    mScrollView->setVisibleVScroll(true);
    mScrollView->setVisibleHScroll(true);
    dragArea->setSize(size);
}
Example #25
0
void StartMenu::do_search(QString search, bool force){
  search = search.simplified(); //remove unneccesary whitespace
  if(search == CSearch && !force){ 
    //nothing new - just ensure the page is visible
    if(ui->stackedWidget->currentWidget()!=ui->page_search  ){ ui->stackedWidget->setCurrentWidget(ui->page_search); }
    return; 
  }else if(search.isEmpty()){
    CSearch.clear();
    if(ui->stackedWidget->currentWidget()==ui->page_search  ){ on_tool_back_clicked(); }
    return;
  }
  //Got a search term - check it
  CSearch = search; //save this for comparison later
  qDebug() << "Search for term:" << search;
  ClearScrollArea(ui->scroll_search);
  topsearch.clear();
  //Now find any items which match the search
  QStringList found; //syntax: [<sorter>::::<mimetype>::::<filepath>]
  QString tmp = search;
  if(LUtils::isValidBinary(tmp)){ found << "0::::application/x-executable::::"+tmp; }
  QList<XDGDesktop> apps = sysapps->value("All");
  for(int i=0; i<apps.length(); i++){
    int priority = -1;
    if(apps[i].name.toLower()==search.toLower()){ priority = 10; }
    else if(apps[i].name.startsWith(search, Qt::CaseInsensitive)){ priority = 15; }
    else if(apps[i].name.contains(search, Qt::CaseInsensitive)){ priority = 19; }
    else if(apps[i].genericName.contains(search, Qt::CaseInsensitive)){ priority = 20; }
    else if(apps[i].comment.contains(search, Qt::CaseInsensitive)){ priority = 30; }
    //Can add other filters here later

    if(priority>0){
      found << QString::number(priority)+"::::app::::"+apps[i].filePath;
    }
  }
  found.sort(Qt::CaseInsensitive); //sort by priority/type (lower numbers are higher on list)
  //qDebug() << "Sorted Items:" << found;
  //Now add the items to the menu in order
  for(int i=0; i<found.length(); i++){
    if( !QFile::exists(found[i].section("::::",2,-1)) ){ continue; } //invalid favorite - skip it
    if(topsearch.isEmpty()){ topsearch = found[i].section("::::",2,-1); }
    ItemWidget *it = 0;
    if( found[i].section("::::",2,-1).endsWith(".desktop")){
      bool ok = false;
      XDGDesktop item = LXDG::loadDesktopFile(found[i].section("::::",2,-1), ok);
      if(ok){ ok = LXDG::checkValidity(item); }
      if(ok){ it = new ItemWidget(ui->scroll_favs->widget(), item); }
    }else{
      it = new ItemWidget(ui->scroll_favs->widget(), found[i].section("::::",2,-1), found[i].section("::::",1,1) );
    }
    if(it==0){ continue; }
    if(!it->gooditem){ it->deleteLater(); continue; } //invalid for some reason
    ui->scroll_search->widget()->layout()->addWidget(it);
    connect(it, SIGNAL(NewShortcut()), this, SLOT(UpdateFavs()) );
    connect(it, SIGNAL(RemovedShortcut()), this, SLOT(UpdateFavs()) );
    connect(it, SIGNAL(RunItem(QString)), this, SLOT(LaunchItem(QString)) );
    connect(it, SIGNAL(toggleQuickLaunch(QString, bool)), this, SLOT(UpdateQuickLaunch(QString, bool)) );
    if(i%3==0){ 
      QApplication::processEvents();
      if(searchTimer->isActive()){ return; } //search changed - go ahead and stop here
    }
  }
  ui->stackedWidget->setCurrentWidget(ui->page_search);
}
Example #26
0
void ItemDelegate::updateRowPosition(int row, int y)
{
    ItemWidget *w = m_cache[row];
    if (w != NULL)
        w->widget()->move( QPoint(rowNumberWidth() + m_hMargin, y + m_vMargin) );
}