Example #1
0
void BGMultiWallpaperDialog::setEnabledMoveButtons()
{
    bool hasSelection = dlg->m_listImages->hasSelection();
    QListWidgetItem * item;

    item = dlg->m_listImages->item(0);
    dlg->m_buttonMoveUp->setEnabled( hasSelection && item && !item->isSelected() );
    item  = dlg->m_listImages->item( dlg->m_listImages->count() - 1 );
    dlg->m_buttonMoveDown->setEnabled( hasSelection && item && !item->isSelected() );
}
Example #2
0
void MainWindow::on_action_EditPassword_triggered()
{
    int row = ui->listWidget->currentRow();
    QListWidgetItem *widgetItem = ui->listWidget->currentItem();

    if(row >= 0 && widgetItem && widgetItem->isSelected())
    {
        QList<PasswordItem> list = this->accountFile->getPasswordList();
        PasswordDialog dialog;

        dialog.setWindowTitle("编辑密码项");
        dialog.setPasswordItem(list.at(row));
        if(dialog.exec() == QDialog::Accepted)
        {
            PasswordItem item = dialog.getPasswordItem();
            bool ok;

            list[row].name = item.name;
            list[row].password = item.password;
            this->accountFile->setPasswordList(list);
            ok = this->accountFile->save(this->accountFileName);
            if(ok)
                ui->listWidget->item(row)->setText(item.name);
        }
    }
}
Example #3
0
std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures() {

    int index = 0;
    std::vector<App::DocumentObject*> result;
    auto activeBody = PartDesignGui::getBody(false);
    if (!activeBody)
        return result;
    auto activePart = PartDesignGui::getPartFor(activeBody, false);

    for (std::vector<featureStatus>::const_iterator st = statuses.begin(); st != statuses.end(); st++) {
        QListWidgetItem* item = ui->listWidget->item(index);

        if(item->isSelected() && !item->isHidden()) {

            QString t = item->text();
            t = t.left(t.indexOf(QString::fromLatin1("(")) - 1);
            auto obj = App::GetApplication().getActiveDocument()->getObject(t.toLatin1().data());

            //build the dependend copy or reference if wanted by the user
            if(*st == otherBody  ||
               *st == otherPart  ||
               *st == notInBody ) {

                if(!ui->radioXRef->isChecked()) {
                    auto copy = makeCopy(obj, "", ui->radioIndependent->isChecked());

                    if(*st == otherBody)
                        activeBody->addFeature(copy);
                    else if(*st == otherPart) {
                        auto oBody = PartDesignGui::getBodyFor(obj, false);
                        if(!oBody)
                            activePart->addObject(copy);
                        else
                            activeBody->addFeature(copy);
                    }
                    else if(*st == notInBody) {
                        activeBody->addFeature(copy);
                        // doesn't supposed to get here anything but sketch but to be on the safe side better to check
                        if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
                            Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(copy);
                            PartDesignGui::fixSketchSupport(sketch);
                        }
                    }
                    result.push_back(copy);
                }
                else
                    result.push_back(obj);
            }
            else
                result.push_back(obj);

            break;
        }

        index++;
    }

    return result;
}
Example #4
0
bool LASOpenDlg::doLoadEVLR(size_t index) const
{
	if (!extraFieldGroupBox->isChecked())
		return false;
	
	QListWidgetItem* item = evlrListWidget->item(static_cast<int>(index));
	return item && item->isSelected();
}
Example #5
0
	//-------------------------------------------------------------------------
	void HandleRootsDialog::_invertSelection()
	{
		for( int i = 0; i < _ui->rootFolders->count(); i++ )
		{
			QListWidgetItem* item = _ui->rootFolders->item( i );
			item->setSelected( !item->isSelected() );
		}
	}
Example #6
0
void BaseForm::listerSelected(QStringList& output)
{
    qint32 i = m_cnlist->count();
    while (i--)
    {
        QListWidgetItem* itm = m_cnlist->item(i);
        if (itm && itm->isSelected())
            output << itm->text();
    }
}
Example #7
0
void ClsQSAList::slotDeleteItem() {
    int iCount = qlbox->count();
    for(int ii=(iCount-1); ii>=0; ii--) {
        QListWidgetItem *item =  qlbox->item(ii);
        if(item!=NULL) {
            if(item->isSelected()) {
                qlbox->takeItem(ii);
            }
        }
    }
}
Example #8
0
void MosaicForm::removeFilesClicked() {
	std::vector<std::string> lst;
	for (int i = 0; i < lstFiles->count(); ++i) {
		QListWidgetItem *item = lstFiles->item(i);
		if (!item->isSelected())
			lst.push_back(m_tifFiles[i]);
	}
	m_tifFiles.clear();
	m_tifFiles.assign(lst.begin(), lst.end());
	updateFileList();
	checkRun();
}
Example #9
0
void FileList::removeSelectedFilesClicked() {
	std::vector<std::string> lst;
	size_t i = 0;
	for (const std::string &file : m_files) {
		QListWidgetItem *item = m_lstFiles->item(i);
		if (!item->isSelected())
			lst.push_back(file);
		++i;
	}
	m_files.clear();
	m_files.assign(lst.begin(), lst.end());
	updateFileList();
}
/**
 * \brief Retrieve a list of selected task ids
 *
 * This method scans the task list and constructs a list of tasks that
 * are selected.
 */
std::list<long>	TaskMainWindow::selectedTaskids() {
	debug(LOG_DEBUG, DEBUG_LOG, 0, "retrieve a list of selected items");
	std::list<long>	taskids;
	for (int i = 0; i < ui->tasklistWidget->count(); i++) {
		QListWidgetItem	*item = ui->tasklistWidget->item(i);
		if (item->isSelected()) {
			TaskItem	*ti = (TaskItem *)ui->tasklistWidget->itemWidget(item);
			taskids.push_back(ti->id());
		}
	}
	debug(LOG_DEBUG, DEBUG_LOG, 0, "%d selected task ids", taskids.size());
	return taskids;
}
Example #11
0
void BGMultiWallpaperDialog::slotMoveDown()
{
    for ( int i = dlg->m_listImages->count() - 1; i > 0; i--)
    {
        QListWidgetItem * item = dlg->m_listImages->item( i - 1 );
        if ( item && item->isSelected())
        {
            dlg->m_listImages->takeItem( i - 1 );
            dlg->m_listImages->insertItem( i , item );
        }
    }
    dlg->m_listImages->ensureSelectionVisible();
    setEnabledMoveButtons();
}
std::vector<unsigned int> GetConvolveParametersDialog::getBandSelectionIndices() const
{
    std::vector<unsigned int> bands;
    bands.reserve(mpBandSelect->count());
    for (int i = 0; i < mpBandSelect->count(); ++i)
    {
        QListWidgetItem* pItem = mpBandSelect->item(i);
        if (pItem != NULL && pItem->isSelected())
        {
            bands.push_back(i);
        }
    }
    return bands;
}
QString LancelotAppletConfig::icon() const
{
    foreach (const QString & id, icons.keys()) //krazy:exclude=foreach
    {
        QListWidgetItem * item = icons[id];
        if (item->isSelected()) {
            if (id == "custom") {
                return customIcon;
            }
            return id;
        }
    }
    return "lancelot";
}
Example #14
0
void MainWindow::on_action_CopyPassword_triggered()
{
    int row = ui->listWidget->currentRow();
    QListWidgetItem *widgetItem = ui->listWidget->currentItem();

    if(row >= 0 && widgetItem && widgetItem->isSelected())
    {
        QClipboard *clipboard = QApplication::clipboard();
        QList<PasswordItem> list = this->accountFile->getPasswordList();
        QString password = list.at(row).password;

        clipboard->setText(password);
        QTimer::singleShot(60 * 1000, this, SLOT(on_action_ClearClipboard_triggered()));
    }
}
//=============================================================================
void DialogMeteotableOptions::slotChangeVisibleItems()
{
	// copy visible items order from widget
	for (int i=0; i<listVisibleData->count(); i++)
	{
		QListWidgetItem *widgitem = listVisibleData->item(i);
		MeteotableOptionItem *item = getOptionItemByCode (widgitem->type());
		item->pos = i;
	}

	// change visibility of selected items
	QListWidget *listWidgetSource;
	if (sender() == btAddVisibleItem) {
		listWidgetSource = listHiddenData;
	}
	else {
		listWidgetSource = listVisibleData;
	}
	for (int i=0; i<listWidgetSource->count(); i++)
	{
		QListWidgetItem *widgitem = listWidgetSource->item(i);
		if (widgitem->isSelected()) 
		{
			// put all selected items at the end of the other list
			MeteotableOptionItem *item = getOptionItemByCode (widgitem->type());
			if (item) {
				item->visible = ! item->visible;    // reverse visibility
				item->pos = nbOptionItems(item->visible)-1;  // to the end of his category
			}
		}
	}
	// update positions after movings (numerate from 0)
	qSort (listAllOptionItems.begin(), listAllOptionItems.end(), 
								MeteotableOptionItem::lessThan_byPos);
	int posVis = 0;
	int posNotVis = 0;
	for (int i = 0; i < listAllOptionItems.size(); ++i) {
		MeteotableOptionItem *item = listAllOptionItems.at(i);
		if (item->visible) {
			item->pos = posVis++;
		}
		else {
			item->pos = posNotVis++;
		}
	}
	
	updateListWidgetsItems ();
}
Example #16
0
void TaskFeaturePick::onItemSelectionChanged()
{
    if (doSelection)
        return;
    doSelection = true;
    ui->listWidget->blockSignals(true);
    Gui::Selection().clearSelection();
    for (int row = 0; row < ui->listWidget->count(); row++) {
        QListWidgetItem *item = ui->listWidget->item(row);
        QString t = item->data(Qt::UserRole).toString();
        if (item->isSelected()) {
            Gui::Selection().addSelection(documentName.c_str(), t.toLatin1());
        }
    }
    ui->listWidget->blockSignals(false);
    doSelection = false;
}
Example #17
0
void GroupObjectDialog::iconViewSelectionChanged()
{
    if (fwbdebug) qDebug("GroupObjectDialog::iconViewSelectionChanged()");

    selectedObjects.clear();

    for (int it=0; it<iconView->count(); ++it)
    {
        QListWidgetItem *itm = iconView->item(it);
        if (itm->isSelected())
        {
            int obj_id = itm->data(Qt::UserRole).toInt();
            if (fwbdebug) qDebug("obj_id=%d", obj_id);
            selectedObjects.push_back(obj_id);
        }
    }
}
Example #18
0
void AddListDialog::getFields( std::vector<wsNotificationFilter>& notifications, bool& changed )
{
    for (int i = 0; i < listWidget->count(); i++)
    {
        QListWidgetItem* item = listWidget->item(i);
        if (item->isSelected())
        {
            int id = item->data(Qt::UserRole).toInt();
            for (int j = 0; j < notificationList.size(); j++)
            {
                if (notificationList[j].additionalMapId == id)
                {
                    changed = true;
                    notifications.push_back(notificationList[j]);
                    break;
                }
            }
        }
    }
}
Example #19
0
void MainWindow::on_action_DeletePassword_triggered()
{
    int row = ui->listWidget->currentRow();
    QListWidgetItem *widgetItem = ui->listWidget->currentItem();

    if(row >= 0 && widgetItem && widgetItem->isSelected())
    {
        QList<PasswordItem> list = this->accountFile->getPasswordList();
        QString name = list.at(row).name;

        if(QMessageBox::question(this, "删除密码项", QString("确定要删除“%1”?").arg(name),
                                 QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
                != QMessageBox::Yes)
            return;

        delete ui->listWidget->takeItem(row);
        list.removeAt(row);
        this->accountFile->setPasswordList(list);
        this->accountFile->save(this->accountFileName);
    }
}
Example #20
0
void BGMultiWallpaperDialog::slotRemove()
{
    int current = -1;
    for ( int i = 0; i < dlg->m_listImages->count();)
    {
        QListWidgetItem * item = dlg->m_listImages->item( i );
        if ( item && item->isSelected())
        {
            delete dlg->m_listImages->takeItem(i);
            if (current == -1)
               current = i;
        }
        else
            i++;
    }
    if ((current != -1) && (current < (signed)dlg->m_listImages->count()))
       dlg->m_listImages->item(current)->setSelected(true);

    dlg->m_buttonRemove->setEnabled(dlg->m_listImages->hasSelection());

    setEnabledMoveButtons();
}
Example #21
0
void SkDebuggerGUI::actionDelete() {

    for (int row = 0; row < fListWidget.count(); ++row) {
        QListWidgetItem* item = fListWidget.item(row);

        if (!item->isSelected()) {
            continue;
        }

        if (fDebugger.isCommandVisible(row)) {
            item->setData(Qt::UserRole + 2, QPixmap(":/delete.png"));
            fDebugger.setCommandVisible(row, false);
            fSkipCommands[row] = true;
        } else {
            item->setData(Qt::UserRole + 2, QPixmap(":/blank.png"));
            fDebugger.setCommandVisible(row, true);
            fSkipCommands[row] = false;
        }
    }

    this->updateImage();
}
void
QvisPlotListBox::clickHandler(const QPoint &clickLocation, bool rightClick,
    bool doubleClicked, Qt::KeyboardModifiers modifiers)
{
    QPoint itemClickLocation(clickLocation);
    int action = -1, opId = -1;
    bool bs = signalsBlocked();

    QvisPlotListBoxItem *actionItem = 0;

    // Walk through all of the items, checking if we've clicked in each one.
    for (int i = 0; i < count(); ++i)
    {
        QListWidgetItem *current = item(i);
        QvisPlotListBoxItem *item2 = (QvisPlotListBoxItem *)current;
        int y = visualItemRect(current).y();
        int h = visualItemRect(current).height();
        if (clickLocation.y() >= y && clickLocation.y() < (y + h))
        {
            if(!rightClick &&
               (modifiers & (Qt::ControlModifier | Qt::MetaModifier)) > 0)
            {
                // If we're using Ctrl or Meta + mouse click then switch
                // the item to its reverse selection.
                blockSignals(false);
                current->setSelected(!current->isSelected());
                blockSignals(bs);
            }
            else
            {
                // If the item is not selected, select it.
                blockSignals(false);
                current->setSelected(true);
                blockSignals(bs);

                // Reduce the y location of the click location to be local
                // to the item
                itemClickLocation.setY(clickLocation.y() - y);

                // Handle the click.
                if (action == -1)
                {
                    action = item2->clicked(itemClickLocation, doubleClicked, opId);
                    if(action >= 0 && action <= 7)
                        actionItem = item2;
                }
            }
        }
        else if(rightClick || doubleClicked)
        {
            blockSignals(false);
            current->setSelected(false);
            blockSignals(bs);
        }
    }

    switch(action)
    {
    case 0: // expand clicked
        emit itemExpansionChanged();
        reset();
        break;
    case 1: // subset clicked
         emit activateSubsetWindow();
        break;
    case 2: // plot clicked
         emit activatePlotWindow(opId);
        break;
    case 3: // operator clicked
         emit activateOperatorWindow(opId);
        break;
    case 4: // promote clicked
         emit promoteOperator(opId);
        break;
    case 5: // demote clicked
        emit demoteOperator(opId);
        break;
    case 6: // delete clicked
         emit removeOperator(opId);
        break;
    case 7: // selection clicked
         emit activateSelectionsWindow(actionItem->GetSelectionName());
        break;
    default:
        if(rightClick)
        {
            emit itemSelectionChanged();
        }
        break;
    }
}
Example #23
0
void 
KxListWidget::keyPressEvent ( QKeyEvent * event )
{
	if ((NULL != event) && (event->key() == Qt::Key_Delete)) {
	
        //KxQtHelper::executeCommandScript("deleteCommand", this);
		event->accept();
		return;
	}  

	// In the following lines, we may be creating a new key event for QListWidget to process instead of
	// the original, so create another pointer for this new event so that we can safely delete it from memory
	// without touching the original event pointer (which may be handled by Qt later on).
	QKeyEvent *processEvent = NULL;

	// The left and right arrow keys are supposed to behave like the up and down arrow keys, respectively.
	// However, QListWidget doesn't interpret those key presses as such, so create a new event that is just
	// like the original but registers up/down keys rather than left/right and pass that to QListWidget's
	// keyPressEvent to process.
	if(event->key() == Qt::Key_Left) {
		processEvent = new QKeyEvent(event->type(), Qt::Key_Up, event->modifiers(),
								event->text(), event->isAutoRepeat(), event->count());
	} else if(event->key() == Qt::Key_Right) {
		processEvent = new QKeyEvent(event->type(), Qt::Key_Down, event->modifiers(),
								event->text(), event->isAutoRepeat(), event->count());
	}

	// Key presses with the control modifier are supposed to behave like normal key presses (i.e. as if the
	// control key was not pressed). However, QListWidget internally handles such key presses in a completely
	// different way, so create a new event that is just like the original but doesn't involve the control modifier
	// and pass that to QListWidget's keyPressEvent to process.
	bool controlPressed = (event->modifiers() & Qt::ControlModifier) && event->key() != Qt::Key_Control;
	if (controlPressed) {
		processEvent = new QKeyEvent(event->type(), event->key(), (event->modifiers() & ~Qt::ControlModifier),
								QString(QChar(event->key())), event->isAutoRepeat(), event->count());
	}

	// If we didn't have to replace the original key event, just make an exact copy of it for us to process.
	if(processEvent == NULL) {
		processEvent = new QKeyEvent(event->type(), event->key(), event->modifiers(),
								event->text(), event->isAutoRepeat(), event->count());
	}

	bool shiftPressed = (processEvent->modifiers() & Qt::ShiftModifier) && processEvent->key() != Qt::Key_Shift;
	QListWidgetItem * shiftSelectEndItem = currentItem();
	bool curItemWasSelected = shiftSelectEndItem?shiftSelectEndItem->isSelected():false;

	// Key presses with the shift modifier with a non-continguous multi-item selection are supposed to behave
	// the same way as if the selection only consisted of the continguous block that contains the current item.
	// However, QListWidget still includes the non-continguous blocks in the new selection. To accommodate,
	// we will first find and record the item in that one block that will be the other end of the new selection
	// (the first end, of course, being the new current item after the key press).
	if(shiftPressed && curItemWasSelected) {
		// If the current item is at the top of the block, search down for the other end. If it is at the bottom
		// of the block, search up. Otherwise, it is the only item in the block, and is thus the item that will be
		// the other end of the new selection.
		int r = row(currentItem());
		// If r==count()-1, we need to bail to the "else if" portion, else
		// we would dereference item(count()) and crash; see bug #335803.
		//
		if(r == 0 || ( (r != (count()-1)) && item(r + 1)->isSelected() && !item(r - 1)->isSelected())) {
			while(r < count() - 1) {
				QListWidgetItem * nextItemDown = item(r + 1);
				if(!nextItemDown->isSelected()) {
					break;
				} else {
					shiftSelectEndItem = nextItemDown;
					r++;
				}
			}
		} else if(r == count() - 1 || (item(r - 1)->isSelected() && !item(r + 1)->isSelected())) {
			while(r > 0) {
				QListWidgetItem * nextItemUp = item(r - 1);
				if(!nextItemUp->isSelected()) {
					break;
				} else {
					shiftSelectEndItem = nextItemUp;
					r--;
				}
			}
		}
	}

	QList<QListWidgetItem *> beforeSelected = selectedItems();
	QListWidget::keyPressEvent(processEvent);
	QList<QListWidgetItem *> afterSelected = selectedItems();

	if(shiftPressed) {
		// If the previous current item had not been selected before a key press with the Shift
		// modifier, all selected items on the list get deselected.
		if(!curItemWasSelected) {
			bool blocked = blockSignals(true);
			for(int i = 0; i < afterSelected.count(); i++) {
				QListWidgetItem *listItem = afterSelected[i];
				if(listItem) {
					listItem->setSelected(false);
				}
			}
			blockSignals(blocked);
			executeSelectCommand();
			event->accept();
			return;
		} else if(beforeSelected != afterSelected) {
			// Now, to emulate the expected behaviour, we select all the items between and 
			// including the new current item and the item we saved from before, and deselect
			// everything else.
			int shiftSelectFirstIndex = row(shiftSelectEndItem);
			int shiftSelectLastIndex = row(currentItem());

			if(shiftSelectFirstIndex > shiftSelectLastIndex) {
				int temp = shiftSelectFirstIndex;
				shiftSelectFirstIndex = shiftSelectLastIndex;
				shiftSelectLastIndex = temp;
			}

			bool blocked = blockSignals(true);
			for(int i = 0; i < count(); i++) {
				QListWidgetItem *listItem = item(i);
				if(listItem) {
					bool itemWithinSelection = (i >= shiftSelectFirstIndex && i <= shiftSelectLastIndex);
					if((itemWithinSelection && !listItem->isSelected()) || (!itemWithinSelection && listItem->isSelected())) {
						listItem->setSelected(!listItem->isSelected());
					}			
				}
			}
			blockSignals(blocked);
			afterSelected = selectedItems();
		}
	} else if((controlPressed && beforeSelected != afterSelected) || processEvent->key() == Qt::Key_Space) {
		// For whatever reason, Qt still picks up the control modifier and multi-selects on
		// alphanumeric key presses. To emulate the correct behaviour, we deselect every
		// selected item unless it is the current item. Space bar presses are supposed to do
		// the same thing (except with the Shift modifier, which should already be handled
		// above), so we include that case as well.
		bool blocked = blockSignals(true);

		QListWidgetItem *curItem = currentItem();
		for(int i = 0; i < afterSelected.count(); i++) {
			QListWidgetItem *listItem = afterSelected[i];
			if(listItem && listItem != curItem) {
				listItem->setSelected(false);
			}
		}

		// Select the current item if it wasn't already.
		if( curItem && !curItem->isSelected()) {
			curItem->setSelected(true);
		}

		blockSignals(blocked);
		afterSelected.clear();
		if( curItem ){
			afterSelected.append(curItem);
		}
	}

	// The keys listed below should always trigger a selection, even if the selection doesn't
	// actually change from before the key press.
	bool actionKeyPressed = processEvent->key() == Qt::Key_Up || processEvent->key() == Qt::Key_Down
								|| processEvent->key() == Qt::Key_Home || processEvent->key() == Qt::Key_End
								|| processEvent->key() == Qt::Key_PageUp || processEvent->key() == Qt::Key_PageDown
								|| processEvent->key() == Qt::Key_Enter || processEvent->key() == Qt::Key_Return
								|| processEvent->key() == Qt::Key_Space;

	// If the selection has changed, or one of the action keys listed above was pressed, or an
	// alphanumeric key press occurred that just happened to result in the same selection as
	// before, then execute the select command.
	if((beforeSelected != afterSelected) || actionKeyPressed
		|| ((beforeSelected.count() == 1) && (!processEvent->text().isEmpty())
		&& (beforeSelected[0]->text().startsWith(processEvent->text(), Qt::CaseInsensitive)))) {
		executeSelectCommand();
	}

	delete processEvent;
	event->accept();
}
Example #24
0
void
KxListWidget::mousePressEvent(QMouseEvent* event)
{
	if( event->button() == Qt::MidButton ){
		// Let KxDragManager handle drag 'n drop.
		//
		event->ignore();
	} else if (!KxQtHelper::handlePopupMenu(this, event) && itemAt(event->pos()) != NULL) {
		/*
		Although the eventFilter in KxQtHelper does get installed on
		this widget, QListWidget eats the mouse click events and only a
		QContextMenuEvent is sent to the filter. So I'm overriding the
		press event here and calling the handlePopupMenu function directly.
		*/
	
		fMousePressed = true;

		// Mouse presses with the shift modifier with a non-continguous multi-item selection are supposed to behave
		// the same way as if the selection only consisted of the continguous block that contains the current item.
		// However, QListWidget still includes the non-continguous blocks in the new selection. To accommodate,
		// we will first find and record the item in that one block that will be the other end of the new selection
		// (the first end, of course, being the new current item after the mouse press).
		bool shiftPressed = (event->modifiers() & Qt::ShiftModifier);
		QListWidgetItem * shiftSelectEndItem = currentItem();
		bool curItemWasSelected = shiftSelectEndItem?shiftSelectEndItem->isSelected():false;
		if(shiftPressed && curItemWasSelected) {
			// If the current item is at the top of the block, search down for the other end. If it is at the bottom
			// of the block, search up. Otherwise, it is the only item in the block, and is thus the item that will be
			// the other end of the new selection.
			int r = row(currentItem());
			// If r==count()-1, we need to bail to the "else if" portion, else
			// we would dereference item(count()) and crash; see bug #335803.
			//
			if(r == 0 || ( (r != (count()-1)) && item(r + 1)->isSelected() && !item(r - 1)->isSelected())) {
				while(r < count() - 1) {
					QListWidgetItem * nextItemDown = item(r + 1);
					if(!nextItemDown->isSelected()) {
						break;
					} else {
						shiftSelectEndItem = nextItemDown;
						r++;
					}
				}
			} else if(r == count() - 1 || (item(r - 1)->isSelected() && !item(r + 1)->isSelected())) {
				while(r > 0) {
					QListWidgetItem * nextItemUp = item(r - 1);
					if(!nextItemUp->isSelected()) {
						break;
					} else {
						shiftSelectEndItem = nextItemUp;
						r--;
					}
				}
			}
		}

		QListWidget::mousePressEvent(event);

		if(shiftPressed && shiftSelectEndItem) {
			int shiftSelectFirstIndex = row(shiftSelectEndItem);
			int shiftSelectLastIndex = row(currentItem());

			// If the previous current item had not been selected before a mouse press with the
			// Shift modifier, the item on the other end of the new selection will actually be
			// either the one just before the previous current item (if the new current item is
			// above the previous) or just after (if the new current item is below the previous).
			if(shiftSelectFirstIndex > shiftSelectLastIndex) {
				if(!curItemWasSelected) {
					shiftSelectFirstIndex--;
				}

				int temp = shiftSelectFirstIndex;
				shiftSelectFirstIndex = shiftSelectLastIndex;
				shiftSelectLastIndex = temp;
			} else if(!curItemWasSelected) {
				shiftSelectFirstIndex++;
			}

			// Now, to emulate the expected behaviour, we deselect all the selected items that
			// aren't in the block between and including the new current item and the item we
			// saved from before (the items in the block itself should already be selected).
			bool blocked = blockSignals(true);
			QList<QListWidgetItem *> afterSelected = selectedItems();
			for(int i = 0; i < afterSelected.count(); i++) {
				QListWidgetItem *listItem = afterSelected[i];
				if(listItem) {
					int index = row(listItem);
					bool itemWithinSelection = (index >= shiftSelectFirstIndex && index <= shiftSelectLastIndex);
					if(!itemWithinSelection) {
						listItem->setSelected(false);
					}		
				}
			}
			blockSignals(blocked);
		}
	}
}
Example #25
0
bool wxListBox::IsSelected(int n) const
{
    QListWidgetItem* item = m_qtListWidget->item(n);
    return item->isSelected();
}
int main (int argc, char** argv) {
    // Handle input
    float pointSize;
    float pointStep;
    float alpha;
    int applyTransform;
    int step;
    string logFilename;
    string configFilename;
    float di_scaleFactor;
    float scale;

    g2o::CommandArgs arg;
    arg.param("vz_pointSize", pointSize, 1.0f, "Size of the points where are visualized");
    arg.param("vz_transform", applyTransform, 1, "Choose if you want to apply the absolute transform of the point clouds");
    arg.param("vz_step", step, 1, "Visualize a point cloud each vz_step point clouds");
    arg.param("vz_alpha", alpha, 1.0f, "Alpha channel value used for the color points");
    arg.param("vz_pointStep", pointStep, 1, "Step at which point are drawn");
    arg.param("vz_scale", scale, 2, "Depth image size reduction factor");
    arg.param("di_scaleFactor", di_scaleFactor, 0.001f, "Scale factor to apply to convert depth images in meters");
    arg.paramLeftOver("configFilename", configFilename, "", "Configuration filename", true);
    arg.paramLeftOver("logFilename", logFilename, "", "Log filename", true);
    arg.parseArgs(argc, argv);

    // Create GUI
    QApplication application(argc,argv);
    QWidget *mainWindow = new QWidget();
    mainWindow->setWindowTitle("pwn_tracker_log_viewer");
    QHBoxLayout *hlayout = new QHBoxLayout();
    mainWindow->setLayout(hlayout);
    QVBoxLayout *vlayout = new QVBoxLayout();
    hlayout->addItem(vlayout);
    QVBoxLayout *vlayout2 = new QVBoxLayout();
    hlayout->addItem(vlayout2);
    hlayout->setStretch(1, 1);

    QListWidget* listWidget = new QListWidget(mainWindow);
    listWidget->setSelectionMode(QAbstractItemView::MultiSelection);
    vlayout->addWidget(listWidget);
    PWNQGLViewer* viewer = new PWNQGLViewer(mainWindow);
    vlayout2->addWidget(viewer);
    Eigen::Isometry3f T;
    T.setIdentity();
    T.matrix().row(3) << 0.0f, 0.0f, 0.0f, 1.0f;

    // Read config file
    cout << "Loading config file..." << endl;
    Aligner *aligner;
    DepthImageConverter *converter;
    std::vector<Serializable*> instances = readConfig(aligner, converter, configFilename.c_str());
    converter->projector()->scale(1.0f/scale);
    cout << "... done" << endl;

    // Read and parse log file
    std::vector<boss::Serializable*> objects;
    std::vector<PwnTrackerFrame*> trackerFrames;
    std::vector<PwnTrackerRelation*> trackerRelations;
    Deserializer des;
    des.setFilePath(logFilename);
    cout << "Loading log file..." << endl;
    load(trackerFrames, trackerRelations, objects, des, step);
    cout << "... done" << endl;

    // Load the drawable list with the PwnTrackerFrame objects
    std::vector<Frame*> pointClouds;
    pointClouds.resize(trackerFrames.size());
    Frame *dummyFrame = 0;
    std::fill(pointClouds.begin(), pointClouds.end(), dummyFrame);
    for(size_t i = 0; i < trackerFrames.size(); i++) {
        PwnTrackerFrame *pwnTrackerFrame = trackerFrames[i];
        char nummero[1024];
        sprintf(nummero, "%05d", (int)i);
        listWidget->addItem(QString(nummero));
        QListWidgetItem *lastItem = listWidget->item(listWidget->count() - 1);

        Isometry3f transform = Isometry3f::Identity();
        if(applyTransform) {
            isometry3d2f(transform, pwnTrackerFrame->transform());
            transform = transform*pwnTrackerFrame->sensorOffset;
        }
        transform.matrix().row(3) << 0.0f, 0.0f, 0.0f, 1.0f;

        GLParameterFrame *frameParams = new GLParameterFrame();
        frameParams->setStep(pointStep);
        frameParams->setShow(false);
        DrawableFrame* drawableFrame = new DrawableFrame(transform, frameParams, pointClouds[i]);
        viewer->addDrawable(drawableFrame);
    }

    // Manage GUI
    viewer->init();
    mainWindow->show();
    viewer->show();
    listWidget->show();
    viewer->setAxisIsDrawn(true);
    bool selectionChanged = false;
    QListWidgetItem *item = 0;
    DepthImage depthImage;
    DepthImage scaledDepthImage;
    while (mainWindow->isVisible()) {
        selectionChanged = false;
        for (int i = 0; i<listWidget->count(); i++) {
            item = 0;
            item = listWidget->item(i);
            DrawableFrame *drawableFrame = dynamic_cast<DrawableFrame*>(viewer->drawableList()[i]);
            if (item && item->isSelected()) {
                if(!drawableFrame->parameter()->show()) {
                    drawableFrame->parameter()->setShow(true);
                    selectionChanged = true;
                }
                if(pointClouds[i] == 0) {
                    pointClouds[i] = new Frame();
                    boss_map::ImageBLOB* fromDepthBlob = trackerFrames[i]->depthImage.get();
                    DepthImage depthImage;
                    depthImage.fromCvMat(fromDepthBlob->cvImage());
                    DepthImage::scale(scaledDepthImage, depthImage, scale);
                    converter->compute(*pointClouds[i], scaledDepthImage);
                    drawableFrame->setFrame(pointClouds[i]);
                    delete fromDepthBlob;
                }
            } else {
                drawableFrame->parameter()->setShow(false);
                selectionChanged = true;
            }
        }
        if (selectionChanged)
            viewer->updateGL();

        application.processEvents();
    }

    return 0;
}
Example #27
0
void VAttachmentList::handleContextMenuRequested(QPoint p_pos)
{
    // @p_pos is the position in the coordinate of VAttachmentList, no m_attachmentList.
    QListWidgetItem *item = m_attachmentList->itemAt(m_attachmentList->mapFromParent(p_pos));
    QMenu menu(this);
    menu.setToolTipsVisible(true);

    if (!m_file) {
        return;
    }

    int selectedSize = m_attachmentList->selectedItems().size();
    if (item) {
        if (!item->isSelected()) {
            m_attachmentList->setCurrentItem(item, QItemSelectionModel::ClearAndSelect);
        }

        if (selectedSize == 1) {
            QAction *openAct = new QAction(tr("&Open"), &menu);
            openAct->setToolTip(tr("Open current attachment file"));
            connect(openAct, &QAction::triggered,
                    this, [this]() {
                        QListWidgetItem *item = m_attachmentList->currentItem();
                        handleItemActivated(item);
                    });
            menu.addAction(openAct);
        }

        QAction *deleteAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_attachment.svg"),
                                         tr("&Delete"),
                                         &menu);
        deleteAct->setToolTip(tr("Delete selected attachments"));
        connect(deleteAct, &QAction::triggered,
                this, &VAttachmentList::deleteSelectedItems);
        menu.addAction(deleteAct);
    }

    m_attachmentList->update();

    if (m_file->getAttachments().size() > 1) {
        if (!menu.actions().isEmpty()) {
            menu.addSeparator();
        }

        QAction *sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
                                       tr("&Sort"),
                                       &menu);
        sortAct->setToolTip(tr("Sort attachments manually"));
        connect(sortAct, &QAction::triggered,
                this, &VAttachmentList::sortItems);
        menu.addAction(sortAct);
    }

    if (selectedSize == 1) {
        menu.addSeparator();

        QAction *fileInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
                                           tr("&Info (Rename)\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)),
                                           &menu);
        fileInfoAct->setToolTip(tr("View and edit current attachment's information"));
        connect(fileInfoAct, &QAction::triggered,
                this, &VAttachmentList::attachmentInfo);
        menu.addAction(fileInfoAct);
    }

    if (!menu.actions().isEmpty()) {
        menu.exec(mapToGlobal(p_pos));
    }
}
Example #28
0
std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures()
{
    int index = 0;
    std::vector<App::DocumentObject*> result;
    try {
        auto activeBody = PartDesignGui::getBody(false);
        if (!activeBody)
            return result;

        auto activePart = PartDesignGui::getPartFor(activeBody, false);

        for (std::vector<featureStatus>::const_iterator st = statuses.begin(); st != statuses.end(); st++) {
            QListWidgetItem* item = ui->listWidget->item(index);

            if (item->isSelected() && !item->isHidden()) {
                QString t = item->data(Qt::UserRole).toString();
                auto obj = App::GetApplication().getDocument(documentName.c_str())->getObject(t.toLatin1().data());

                //build the dependent copy or reference if wanted by the user
                if (*st == otherBody || *st == otherPart || *st == notInBody) {
                    if (!ui->radioXRef->isChecked()) {
                        auto copy = makeCopy(obj, "", ui->radioIndependent->isChecked());

                        if (*st == otherBody) {
                            activeBody->addObject(copy);
                        }
                        else if (*st == otherPart) {
                            auto oBody = PartDesignGui::getBodyFor(obj, false);
                            if (!oBody)
                                activePart->addObject(copy);
                            else
                                activeBody->addObject(copy);
                        }
                        else if (*st == notInBody) {
                            activeBody->addObject(copy);
                            // doesn't supposed to get here anything but sketch but to be on the safe side better to check
                            if (copy->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) {
                                Sketcher::SketchObject *sketch = static_cast<Sketcher::SketchObject*>(copy);
                                PartDesignGui::fixSketchSupport(sketch);
                            }
                        }
                        result.push_back(copy);
                    }
                    else {
                        result.push_back(obj);
                    }
                }
                else {
                    result.push_back(obj);
                }

                break;
            }

            index++;
        }
    }
    catch (const Base::Exception& e) {
        e.ReportException();
    }
    catch (Py::Exception& e) {
        // reported by code analyzers
        e.clear();
        Base::Console().Warning("Unexpected PyCXX exception\n");
    }
    catch (const boost::exception&) {
        // reported by code analyzers
        Base::Console().Warning("Unexpected boost exception\n");
    }

    return result;
}