void TeQtViewsListView::selectViewItem(TeView *view)
{
	if (view == 0)
		return;

	QListViewItem *child = firstChild();
    while (child)
	{
		TeQtViewItem *viewItem = (TeQtViewItem*)child;
		if (viewItem->getView() == view)
		{
			if (viewItem == currentViewItem_)
				break;
			else
			{
				unselectAllItems();
				child->setSelected(true);
				child->repaint();
				currentViewItem_ = viewItem;
				currentThemeItem_ = 0;
				emit itemChanged(child);
				return;
			}
		}
        child = child->nextSibling();
	}
}
Пример #2
0
void OSItemSelectionController::setAllowMultipleSelections(bool multipleSelections)
{
  m_allowMultipleSelections = multipleSelections;

  if( ! m_allowMultipleSelections )
  {
    unselectAllItems();
  }
}
void TeQtViewsListView::contentsDragMoveEvent(QDragMoveEvent *e)
{
	if(pressedThemeItem_)
		pressedThemeItem_->setOpen(themeOpen_);

	if(e->source() != viewport())
	{
		e->ignore();
		e->acceptAction(false);
		return;
	}

    QPoint p = contentsToViewport(((QDragMoveEvent*)e)->pos());
    TeQtCheckListItem *item = (TeQtCheckListItem*)itemAt(p);
    if (item)
	{
		if (p.x() < treeStepSize() * (item->depth() + (rootIsDecorated() ? 1 : 0)) + itemMargin())
		{
			e->ignore();
			e->acceptAction(false);
		}
		else
		{
			if(item->getType() == TeQtCheckListItem::THEME || item->getType() == TeQtCheckListItem::VIEW)
			{
				e->accept();
				e->acceptAction();
			}
			else
			{
				e->ignore();
				e->acceptAction(false);
				if(currentThemeItem_)
				{
					unselectAllItems();
					currentThemeItem_->parent()->setSelected(true);
					currentThemeItem_->parent()->repaint();
					currentThemeItem_->setSelected(true);
					repaint();
				}
			}
		}
    }
	else
	{
		e->ignore();
		e->acceptAction(false);
	}
}
void TeQtViewsListView::contentsMouseReleaseEvent(QMouseEvent *e)
{
	leftButtonPressed_ = false;
	QListView::contentsMouseReleaseEvent(e);

	if(currentThemeItem_)
	{
		unselectAllItems();
		currentThemeItem_->parent()->setSelected(true);
		currentThemeItem_->parent()->repaint();
		currentThemeItem_->setSelected(true);
		repaint();
	}
	drag_ = false;
}
void TeQtViewsListView::contextMenuRequested(QListViewItem *item, const QPoint&, int)
{
	popupItem_ = (TeQtCheckListItem*)item;

	unselectAllItems();
	if (currentViewItem_)
	{
		currentViewItem_->setSelected(true);
		currentViewItem_->repaint();
	}

	if (currentThemeItem_)
	{
		currentThemeItem_->setSelected(true);
		currentThemeItem_->repaint();
	}

	emit popupSignal();	
}
void TeQtViewsListView::contentsDropEvent(QDropEvent *e)
{
	if(e->source() != viewport())
	{
		e->ignore();
		e->acceptAction(false);
		pressedThemeItem_ = 0;
		if(currentThemeItem_)
		{
			unselectAllItems();
			currentThemeItem_->parent()->setSelected(true);
			currentThemeItem_->parent()->repaint();
			currentThemeItem_->setSelected(true);
			repaint();
		}
		return;
	}

	int itemPriority;
	TeQtThemeItem *themeItem;
	bool viewChanged = false;

    QPoint p = contentsToViewport(((QDragMoveEvent*)e)->pos());
	TeQtCheckListItem *dropItem = (TeQtCheckListItem*)itemAt(p);

	if (dropItem == 0)
	{
		e->ignore();
		e->acceptAction(false);
		pressedThemeItem_ = 0;
		if(currentThemeItem_)
		{
			unselectAllItems();
			currentThemeItem_->parent()->setSelected(true);
			currentThemeItem_->parent()->repaint();
			currentThemeItem_->setSelected(true);
			repaint();
		}
		return;
	}

	if (dropItem == pressedThemeItem_)
	{
		e->ignore();
		e->acceptAction(false);
		pressedThemeItem_ = 0;
		if(currentThemeItem_)
		{
			unselectAllItems();
			currentThemeItem_->parent()->setSelected(true);
			currentThemeItem_->parent()->repaint();
			currentThemeItem_->setSelected(true);
			repaint();
		}
		return;
	}

	e->accept();
	e->acceptAction();

	//Set the view item of the pressed item and the drop item
	TeQtViewItem *pressedViewItem = (TeQtViewItem*)pressedThemeItem_->parent();
	TeQtViewItem *dropViewItem;
	if(dropItem->getType() == TeQtCheckListItem::THEME)
		dropViewItem = (TeQtViewItem*)dropItem->parent();
	else
		dropViewItem = (TeQtViewItem*)dropItem;

	//set a flag to indicate whether there was a view change
	if (pressedViewItem != dropViewItem)
		viewChanged = true;

	//update the priorities and move the items accordingly
	if (viewChanged)
	{
		vector<QListViewItem*> themeItemVector = dropViewItem->getChildren();
		for (unsigned int i = 0; i < themeItemVector.size(); ++i)
		{
			themeItem = (TeQtThemeItem*)themeItemVector[i];
			if(pressedThemeItem_->text(0) == themeItem->text(0))
			{
				emit dragDropItems(0, 0, 0);
				pressedThemeItem_ = 0;
				return;
			}
		}

		if (dropItem->getType() == TeQtCheckListItem::THEME)
		{
			TeQtThemeItem *dropThemeItem = (TeQtThemeItem*)dropItem;
			itemPriority = dropThemeItem->order();
			pressedThemeItem_->order(itemPriority);
			themeItem = dropThemeItem;
		}
		else
		{
			itemPriority = 0;
			pressedThemeItem_->order(itemPriority);
			themeItem = (TeQtThemeItem*)dropViewItem->firstChild();
		}

		while (themeItem)
		{
			themeItem->order(++itemPriority);
			themeItem = (TeQtThemeItem*)themeItem->nextSibling();
		}
		pressedViewItem->takeItem(pressedThemeItem_);
		dropViewItem->insertItem(pressedThemeItem_);
	}
	else
	{
		if (dropItem->getType() == TeQtCheckListItem::THEME)
		{
			TeQtThemeItem *dropThemeItem = (TeQtThemeItem*)dropItem;
			int pressedItemPriority = pressedThemeItem_->order();
			int droppedItemPriority = dropThemeItem->order();
			if (pressedItemPriority < droppedItemPriority)
			{
				itemPriority = pressedItemPriority;
				pressedThemeItem_->order(droppedItemPriority);
				themeItem = (TeQtThemeItem*)pressedThemeItem_->nextSibling();
				while (themeItem != dropThemeItem)
				{
					themeItem->order(itemPriority++);
					themeItem = (TeQtThemeItem*)themeItem->nextSibling();
				}
				dropThemeItem->order(itemPriority);
			}
			else
			{
				itemPriority = droppedItemPriority;
				pressedThemeItem_->order(itemPriority);
				themeItem = (TeQtThemeItem*)dropThemeItem;

				while (themeItem != pressedThemeItem_)
				{
					themeItem->order(++itemPriority);
					themeItem = (TeQtThemeItem*)themeItem->nextSibling();
				}
			}
			pressedThemeItem_->moveItem(dropThemeItem);
		}
		else
		{
			itemPriority = 0;
			pressedThemeItem_->order(itemPriority);
			themeItem = (TeQtThemeItem*)dropItem->firstChild();
			while (themeItem != pressedThemeItem_)
			{
				themeItem->order(++itemPriority);
				themeItem = (TeQtThemeItem*)themeItem->nextSibling();
			}
			pressedViewItem->takeItem(pressedThemeItem_);
			pressedViewItem->insertItem(pressedThemeItem_);
			dropViewItem->setOpen(true);
		}
	}

	if (pressedViewItem != dropViewItem)
	{
		// the drag and drop theme items belong to different views
		if (pressedThemeItem_ == currentThemeItem_)
		{
			currentViewItem_ = dropViewItem;
			clicked(pressedThemeItem_);
		}
	}

//	emit dragDropItems(pressedViewItem, dropViewItem);
	emit dragDropItems(pressedThemeItem_, pressedViewItem, dropViewItem);
	pressedThemeItem_->setOpen(themeOpen_);

	pressedThemeItem_ = 0;

	if(currentThemeItem_)
	{
		unselectAllItems();
		currentThemeItem_->parent()->setSelected(true);
		currentThemeItem_->parent()->repaint();
		currentThemeItem_->setSelected(true);
		repaint();
	}
}
void TeQtViewsListView::clicked(QListViewItem *item)
{
	if(item == 0)
		return;
	if(drag_ && pressedThemeItem_)
		return;

	unselectAllItems();

	TeQtCheckListItem *checkListItem = (TeQtCheckListItem*)item;

	if(	checkItemStateChanged_ && (checkListItem->getType() == TeQtCheckListItem::THEME))
	{
		checkItemStateChanged_ = false;
		TeQtThemeItem* themeItem = (TeQtThemeItem*)checkListItem;
		if(themeItem->isThemeItemInvalid())
			themeItem->setOn(false);

		if(currentThemeItem_)
		{
			currentThemeItem_->parent()->setSelected(true);
			currentThemeItem_->parent()->repaint();
			currentThemeItem_->setSelected(true);
			currentThemeItem_->repaint();
			return;
		}
	}

	if(checkListItem->getType() != TeQtCheckListItem::THEME)
	{
		if (rightMouseWasClicked_ == true || checkItemStateChanged_ == true ||
			drag_ == true || checkListItem->getType() == TeQtCheckListItem::LEGEND ||
			checkListItem->getType() == TeQtCheckListItem::CHART)
		{
			if (checkListItem->getType() == TeQtCheckListItem::LEGEND ||
				checkListItem->getType() == TeQtCheckListItem::CHART)
			{
				checkListItem->setSelected(false);
				checkListItem->repaint();
			}

			if (currentViewItem_ != 0)
			{
				currentViewItem_->setSelected(true);
				currentViewItem_->repaint();
			}

			if (currentThemeItem_ != 0)
			{
				currentThemeItem_->setSelected(true);
				currentThemeItem_->repaint();
			}
			rightMouseWasClicked_ = false;
			checkItemStateChanged_ = false;
			return;
		}
	}

	if (checkListItem->getType() == TeQtCheckListItem::VIEW)
	{
		item->setSelected(true);
		item->repaint();

		TeQtViewItem *viewItem = (TeQtViewItem*)item;
		if (viewItem != currentViewItem_)
		{
			currentViewItem_ = viewItem;
			currentThemeItem_ = 0;
			emit itemChanged(item);
		}
		else
		{
			if (currentThemeItem_ != 0)
			{
				currentThemeItem_->setSelected(true);
				currentThemeItem_->repaint();
			}
		}
	}
	else if(checkListItem->getType() == TeQtCheckListItem::THEME)
	{
		TeQtThemeItem* themeItem = (TeQtThemeItem*)checkListItem;
		if(themeItem->isThemeItemInvalid())
			return;
		item->parent()->setSelected(true);
		item->parent()->repaint();
		item->setSelected(true);
		item->repaint();

		TeQtViewItem *viewItem = (TeQtViewItem*)item->parent();
		if (currentViewItem_ != viewItem && rightMouseWasClicked_ == false)
		{
			currentViewItem_ = viewItem;
			emit itemChanged(item->parent());
		}

		themeItem = (TeQtThemeItem*)item;
		if (themeItem != currentThemeItem_ && rightMouseWasClicked_ == false)
		{
			currentThemeItem_ = themeItem;
			emit itemChanged(item);
		}
	}
	rightMouseWasClicked_ = false;
	checkItemStateChanged_ = false;
}
void TeQtViewsListView::reset()
{
	unselectAllItems();
	currentViewItem_ = 0;
	currentThemeItem_ = 0;
}