示例#1
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void UserInitArea::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    if (!isSelected() && scene()) {
        scene()->clearSelection();
        setSelected(true);
    }

    QMenu menu;

    QAction *propertiesAction = menu.addAction("Properties");
    menu.addSeparator();
    QAction *delAction = menu.addAction("Delete");

	//    QAction *growAction = menu.addAction("Grow");
	//    QAction *shrinkAction = menu.addAction("Shrink");

    QAction *selectedAction = menu.exec(event->screenPos());


    if (selectedAction == delAction)
        deleteSelectedItems(scene());
    else if (selectedAction == propertiesAction)
        propertiesSelectedItems(scene());
	//    else if (selectedAction == growAction)
	//        growSelectedItems(scene());
	//    else if (selectedAction == shrinkAction)
	//        shrinkSelectedItems(scene());
}
示例#2
0
void KURLListRequester::keyPressEvent(QKeyEvent *e)
{
    if (e->key() == Qt::Key_Delete) {
        if (urlListBox->hasFocus()) {
            deleteSelectedItems();
            return;
        }
    }

    QWidget::keyPressEvent(e);
}
示例#3
0
void IconView::moveToTrash( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers )
{
    if ( modifiers & Qt::ShiftModifier ) {
        deleteSelectedItems();
        return;
    }

    KUrl::List urls;
    foreach (const QModelIndex &index, m_selectionModel->selectedIndexes()) {
        KFileItem item = m_model->itemForIndex( m_proxyModel->mapToSource( index ) );
        urls.append( item.url() );
    }
    KonqOperations::del( QApplication::desktop(), KonqOperations::TRASH, urls );
}
示例#4
0
void KURLListRequester::slotRightClicked(QListWidgetItem *item, const QPoint &pos)
{
    if (item == 0)
        return;

    QMenu popupMenu(this);
    QAction * menuAction = popupMenu.addAction(i18n("Delete"));

    if (menuAction == popupMenu.exec(pos)) {
        if (item->isSelected())
            deleteSelectedItems();
        else {
            delete item;
            emit changed();
        }
    }
}
示例#5
0
void ArchiveListWidget::keyPressEvent(QKeyEvent *event)
{
    switch(event->key())
    {
    case Qt::Key_Delete:
        deleteSelectedItems();
        break;
    case Qt::Key_Escape:
        if(!selectedItems().isEmpty())
            clearSelection();
        else
            QListWidget::keyPressEvent(event);
        break;
    default:
        QListWidget::keyPressEvent(event);
    }
}
void MainWindow::createActions()
{
    //actions painter mode
    actionGroupModes = new QActionGroup(this);
    actionGroupModes->setExclusive(true);

    actionSetModeSelect = new QAction(QIcon(":/images/arrow.png"), tr("Selection mode"), this);
    actionSetModeSelect->setCheckable(true);
    actionGroupModes->addAction(actionSetModeSelect);
    connect(actionSetModeSelect, SIGNAL(toggled(bool)), graphScene, SLOT(setSelectMode()));

    actionSetModeAddPoint = new QAction(QIcon(":/images/round.png"), tr("Add point mode"), this);
    actionSetModeAddPoint->setCheckable(true);
    actionGroupModes->addAction(actionSetModeAddPoint);
    connect(actionSetModeAddPoint, SIGNAL(toggled(bool)), graphScene, SLOT(setAddPoinrMode()));
    actionSetModeAddPoint->setChecked(true);

    actionSetModeAddLine = new QAction(QIcon(":/images/line.png"), tr("Add line mode"), this);
    actionSetModeAddLine->setCheckable(true);
    actionGroupModes->addAction(actionSetModeAddLine);
    connect(actionSetModeAddLine, SIGNAL(toggled(bool)), graphScene, SLOT(setAddLineMode()));

    //actions context point menu
    actionSetPointModeInitial = new QAction(tr("Начальая вершина"), this);
    connect(actionSetPointModeInitial, SIGNAL(triggered()), graphScene, SLOT(setInitialPoint()));

    actionSetPointModeIntermediate = new QAction(tr("Промежуточная вершина"), this);
    connect(actionSetPointModeIntermediate, SIGNAL(triggered()), graphScene, SLOT(setIntermediatePoint()));

    actionSetPointModeFinit = new QAction(tr("Конечная вершина"), this);
    connect(actionSetPointModeFinit, SIGNAL(triggered()), graphScene, SLOT(setFinitPoint()));

    actionRemovePoint = new QAction(QIcon(":/images/minus.png"), tr("Удалить"), this);
    actionRemovePoint->setShortcut(QKeySequence::Delete);
    connect(actionRemovePoint, SIGNAL(triggered()), graphScene, SLOT(deleteSelectedItems()));

    //actions algorithm
    actionRunAlgorithm = new QAction(tr("Запустить"), this);
    connect(actionRunAlgorithm, SIGNAL(triggered()), this, SLOT(runAnts()));
}
示例#7
0
文件: qtbox.cpp 项目: maxxant/qt
void ItemBase::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
    if (!isSelected() && scene()) {
        scene()->clearSelection();
        setSelected(true);
    }

    QMenu menu;
    QAction *delAction = menu.addAction("Delete");
    QAction *newAction = menu.addAction("New");
    QAction *growAction = menu.addAction("Grow");
    QAction *shrinkAction = menu.addAction("Shrink");

    QAction *selectedAction = menu.exec(event->screenPos());

    if (selectedAction == delAction)
        deleteSelectedItems(scene());
    else if (selectedAction == newAction)
        duplicateSelectedItems(scene());
    else if (selectedAction == growAction)
        growSelectedItems(scene());
    else if (selectedAction == shrinkAction)
        shrinkSelectedItems(scene());
}
示例#8
0
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
    selectInteractor(0), newLineItemInteractor(0),
    newRectItemInteractor(0), newTextItemInteractor(0) {

    setObjectName(QStringLiteral("MainWindow"));
    resize(1024, 768);

    graphicsSheet = new GraphicsSheet(this);
    QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(graphicsSheet);
    shadow->setBlurRadius(20);
    shadow->setColor(QColor(0xa0, 0xa0, 0xa0));
    graphicsSheet->setGraphicsEffect(shadow);

    graphicsSheet->setScaleBackground(QColor(0xFF, 0xFF, 0xF8));

    QLayout* layout = new ScrollAreaLayout();
    layout->addWidget(graphicsSheet);

    QWidget *centralwidget = new QWidget(this);
    centralwidget->setLayout(layout);
    setCentralWidget(centralwidget);

/*****************************************************************************/
    menubar = new QMenuBar(this);
    menubar->setObjectName(QStringLiteral("menubar"));
    menubar->setGeometry(QRect(0, 0, 401, 21));
    setMenuBar(menubar);

    statusbar = new QStatusBar(this);
    statusbar->setObjectName(QStringLiteral("statusbar"));
    setStatusBar(statusbar);

    toolBar = new QToolBar(this);
    toolBar->setObjectName(QStringLiteral("toolBar"));
    addToolBar(Qt::TopToolBarArea, toolBar);
/*****************************************************************************/

/* Initialize zoom, scale, and paper formats */
    graphicsSheet->addScale("1:10",  0.1);
    graphicsSheet->addScale("1:5",   0.2);
    graphicsSheet->addScale("1:2",   0.5);
    graphicsSheet->addScale("1:1",   1.0);
    graphicsSheet->addScale("2:1",   2.0);
    graphicsSheet->addScale("5:1",   5.0);
    graphicsSheet->addScale("10:1", 10.0);

    LabelledComboBox* scaleWidget = new LabelledComboBox(toolBar, "Scale: ");
    scaleWidget->getComboBox()->addItems(graphicsSheet->getScaleNames());
    toolBar->addWidget(scaleWidget);
    QObject::connect(scaleWidget->getComboBox(), SIGNAL(currentIndexChanged(int)),
                     graphicsSheet, SLOT(setScale(int)));

    graphicsSheet->addZoom("50%",  0.5);
    graphicsSheet->addZoom("75%",  0.75);
    graphicsSheet->addZoom("100%", 1.0);
    graphicsSheet->addZoom("125%", 1.25);
    graphicsSheet->addZoom("150%", 1.5);
    graphicsSheet->addZoom("200%", 2.0);

    LabelledComboBox* zoomWidget = new LabelledComboBox(toolBar, "Zoom: ");
    zoomWidget->getComboBox()->addItems(graphicsSheet->getZoomNames());
    toolBar->addWidget(zoomWidget);
    QObject::connect(zoomWidget->getComboBox(), SIGNAL(currentIndexChanged(int)),
                     graphicsSheet, SLOT(setZoom(int)));

    graphicsSheet->setUnit("mm");
    graphicsSheet->addSize("DIN A3", QSizeF(297.0, 420.0));
    graphicsSheet->addSize("DIN A4", QSizeF(210.0, 297.0));
    graphicsSheet->addSize("Letter", QSizeF(215.9, 279.4));
    graphicsSheet->addSize("DIN A5", QSizeF(148.0, 210.0));

    LabelledComboBox* sizeWidget = new LabelledComboBox(toolBar, "Sheet Size: ");
    sizeWidget->getComboBox()->addItems(graphicsSheet->getSizeNames());
    toolBar->addWidget(sizeWidget);
    QObject::connect(sizeWidget->getComboBox(), SIGNAL(currentIndexChanged(int)),
                     graphicsSheet, SLOT(setSize(int)));

    QCheckBox* checkbox = new QCheckBox("Landscape", toolBar);
    toolBar->addWidget(checkbox);
    QObject::connect(checkbox, SIGNAL(stateChanged(int)),
                     graphicsSheet, SLOT(setDirection(int)));

    QIcon icon;
    icon.addFile(QStringLiteral(":/Icons/file-load.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionLoad = new QAction(icon, "Load drawing ...", this);
    toolBar->addAction(actionLoad);
    QObject::connect(actionLoad, SIGNAL(triggered()), this, SLOT(doActionLoad()));

    QIcon icon2;
    icon2.addFile(QStringLiteral(":/Icons/file-save.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionSave = new QAction(icon2, "Save drawing", this);
    toolBar->addAction(actionSave);
    QObject::connect(actionSave, SIGNAL(triggered()), this, SLOT(doActionSave()));

    QIcon icon3;
    icon3.addFile(QStringLiteral(":/Icons/file-save-as.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionSaveAs = new QAction(icon3, "Save drawing as ...", this);
    toolBar->addAction(actionSaveAs);
    QObject::connect(actionSaveAs, SIGNAL(triggered()), this, SLOT(doActionSaveAs()));

    QIcon icon4;
    icon4.addFile(QStringLiteral(":/Icons/object-select.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionSelect = new QAction(icon4, "Edit object", this);
    actionSelect->setCheckable(true);
    toolBar->addAction(actionSelect);
    QObject::connect(actionSelect, SIGNAL(triggered()), this, SLOT(doActionSelect()));

    QIcon icon5;
    icon5.addFile(QStringLiteral(":/Icons/object-newline.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewLineItem = new QAction(icon5, "New line", this);
    actionNewLineItem->setCheckable(true);
    toolBar->addAction(actionNewLineItem);
    QObject::connect(actionNewLineItem, SIGNAL(triggered()), this, SLOT(doActionNewLineItem()));

    QIcon icon6;
    icon6.addFile(QStringLiteral(":/Icons/object-newrect.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewRectItem = new QAction(icon6, "New rectangle", this);
    actionNewRectItem->setCheckable(true);
    toolBar->addAction(actionNewRectItem);
    QObject::connect(actionNewRectItem, SIGNAL(triggered()), this, SLOT(doActionNewRectItem()));

    QIcon icon7;
    icon7.addFile(QStringLiteral(":/Icons/object-newtext.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewTextItem = new QAction(icon7, "New text rectangle", this);
    actionNewTextItem->setCheckable(true);
    toolBar->addAction(actionNewTextItem);
    QObject::connect(actionNewTextItem, SIGNAL(triggered()), this, SLOT(doActionNewTextItem()));

    QIcon icon8;
    icon8.addFile(QStringLiteral(":/Icons/object-newcircle.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewCircleItem = new QAction(icon8, "New circle", this);
    actionNewCircleItem->setCheckable(true);
    toolBar->addAction(actionNewCircleItem);
    QObject::connect(actionNewCircleItem, SIGNAL(triggered()), this, SLOT(doActionNewCircleItem()));

    QIcon icon9;
    icon9.addFile(QStringLiteral(":/Icons/object-newellipse.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewEllipseItem = new QAction(icon9, "New ellipse", this);
    actionNewEllipseItem->setCheckable(true);
    toolBar->addAction(actionNewEllipseItem);
    QObject::connect(actionNewEllipseItem, SIGNAL(triggered()), this, SLOT(doActionNewEllipseItem()));

    QIcon icon10;
    icon10.addFile(QStringLiteral(":/Icons/object-newbezier.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionNewBezierItem = new QAction(icon10, "New bezier curve", this);
    actionNewBezierItem->setCheckable(true);
    toolBar->addAction(actionNewBezierItem);
    QObject::connect(actionNewBezierItem, SIGNAL(triggered()), this, SLOT(doActionNewBezierItem()));

    QIcon icon11;
    icon11.addFile(QStringLiteral(":/Icons/object-delete.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionDeleteItem = new QAction(icon11, "Delete selected objects", this);
    toolBar->addAction(actionDeleteItem);
    QObject::connect(actionDeleteItem, SIGNAL(triggered()), graphicsSheet, SLOT(deleteSelectedItems()));

    QIcon icon12;
    icon12.addFile(QStringLiteral(":/Icons/edit-redo.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionRedo = new QAction(icon12, "Redo last undone action", this);
    toolBar->addAction(actionRedo);
    QObject::connect(actionRedo, SIGNAL(triggered()), this, SLOT(doActionRedo()));

    QIcon icon13;
    icon13.addFile(QStringLiteral(":/Icons/edit-undo.png"), QSize(), QIcon::Normal, QIcon::Off);
    actionUndo = new QAction(icon13, "Undo last action", this);
    toolBar->addAction(actionUndo);
    QObject::connect(actionUndo, SIGNAL(triggered()), this, SLOT(doActionUndo()));

    QActionGroup* actionGroup = new QActionGroup(this);
    actionGroup->addAction(actionSelect);
    actionGroup->addAction(actionNewLineItem);
    actionGroup->addAction(actionNewRectItem);
    actionGroup->addAction(actionNewTextItem);
    actionGroup->addAction(actionNewCircleItem);
    actionGroup->addAction(actionNewEllipseItem);
    actionGroup->addAction(actionNewBezierItem);
    actionSelect->setChecked(true);

#if 0
    QAction* actionInfo = new QAction("Info", this);
    toolBar->addAction(actionInfo);
    QObject::connect(actionInfo, SIGNAL(triggered(bool)),
                     this, SLOT(printInfo()));

    QAction* actionRotate = new QAction("Rotate", this);
    toolBar->addAction(actionRotate);
    QObject::connect(actionRotate, SIGNAL(triggered(bool)),
                     this, SLOT(rotateItem()));

    QAction* actionResize = new QAction("ResizeHandle", this);
    toolBar->addAction(actionResize);
    QObject::connect(actionResize, SIGNAL(triggered(bool)),
                     this, SLOT(resizeItem()));
#endif

    zoomWidget->getComboBox()->setCurrentIndex(2);
    sizeWidget->getComboBox()->setCurrentIndex(3);
    scaleWidget->getComboBox()->setCurrentIndex(2);
    checkbox->setChecked(true);

/*****************************************************************************/

    GraphicsScene* scene = dynamic_cast<GraphicsScene*>(graphicsSheet->scene());
    QObject::connect(scene, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
    scene->loadFromFile("sample.drw");

    selectInteractor = new EditItemInteractor();
// TODO: get all registered items from the factory!
#if 0
    newLineItemInteractor = new NewItemInteractor(LineItem::create, 1); // LineItem::P2Handle);
    QObject::connect(newLineItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
    newRectItemInteractor = new NewItemInteractor(RectItem::create, 1); // RectItem::BottomRightHandle);
    QObject::connect(newRectItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
    newTextItemInteractor = new NewItemInteractor(TextItem::create, 1); // TextItem::BottomRightHandle);
    QObject::connect(newTextItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
    newCircleItemInteractor = new NewItemInteractor(CircleItem::create, 1); // CircleItem::RadHandle);
    QObject::connect(newCircleItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
    newEllipseItemInteractor = new NewItemInteractor(EllipseItem::create, 1); // EllipseItem::BottomRightHandle);
    QObject::connect(newEllipseItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
    newBezierItemInteractor = new NewItemInteractor(BezierItem::create, 1); // BezierItem::P2Handle);
    QObject::connect(newBezierItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect()));
#endif

    graphicsSheet->setInteractor(selectInteractor);
    graphicsSheet->setSnapper(new EdgeSnapper(new GridSnapper()));

    propertyEditor = new ObjectController();
    QDockWidget* propertiesDock = new QDockWidget(this);
    propertiesDock->setObjectName(QStringLiteral("propertiesDock"));
    propertiesDock->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable);
    propertiesDock->setWindowTitle("Item properties");
    propertiesDock->setWidget(propertyEditor);
    addDockWidget(static_cast<Qt::DockWidgetArea>(2), propertiesDock);
}
示例#9
0
void IconView::init()
{
    KConfig config;
    KConfigGroup generalGroup( &config, "General" );
    m_wallpaper = generalGroup.readEntry( "Wallpaper", DEFAULT_WALLPAPER );

    delete m_pixmap;
    m_pixmap = new QPixmap( m_wallpaper );
    QPalette p;
    p.setBrush( QPalette::Base, QBrush( *m_pixmap ) );
    setPalette( p );

    m_model = new KDirModel( this );
    KDirLister* lister = new KDirLister( this );
    lister->openUrl( KUrl( QDir::homePath() ) );
    m_model->setDirLister( lister );

    m_delegate = new KFileItemDelegate( this );
    m_delegate->setMaximumSize( QSize( 64, 64 ) );
    m_delegate->setShadowOffset( QPointF( 1, 1 ) );
    m_delegate->setShadowColor( QColor( 0xff, 0xff, 0xff ) );
    m_delegate->setShadowBlur( 1 );
    m_delegate->setWrapMode( QTextOption::WrapAtWordBoundaryOrAnywhere );

    m_proxyModel = new KDirSortFilterProxyModel( this );
    m_proxyModel->setSourceModel( m_model );

    setModel( m_proxyModel );
    setItemDelegate( m_delegate );

    m_selectionModel = new QItemSelectionModel( m_proxyModel );
    setSelectionModel( m_selectionModel );

    /// create actions
    KAction* cut = KStandardAction::cut( this, SLOT(cut()), this );
    KAction* copy = KStandardAction::copy( this, SLOT(copy()), this );

    KIO::FileUndoManager* manager = KIO::FileUndoManager::self();
    KAction* undo = KStandardAction::undo( manager, SLOT(undo()), this );
    connect( manager, SIGNAL(undoAvailable(bool)), undo, SLOT(setEnabled(bool)) );
    connect( manager, SIGNAL(undoTextChanged(const QString&)), SLOT(undoTextChanged(const QString&)) );
    undo->setEnabled( manager->undoAvailable() );

    KAction* paste = KStandardAction::paste( this, SLOT(paste()), this );
    KAction* pasteTo = KStandardAction::paste( this, SLOT(pasteTo()), this );
    pasteTo->setEnabled( false ); // Only enabled during popupMenu()

    QString actionText = KIO::pasteActionText();
    if ( !actionText.isEmpty() )
        paste->setText( actionText );
    else
        paste->setEnabled( false );

    KAction* refresh = new KAction(KIcon("user-desktop"), i18n("&Refresh Desktop"), this);
    connect( refresh, SIGNAL(triggered()), this, SLOT(refresh()) );

    KAction* wallpaper = new KAction(KIcon("tools-wizard"), i18n("&Change Wallpaper..."), this);
    connect( wallpaper, SIGNAL(triggered()), this, SLOT(changeWallpaper()) );

    KAction* rename = new KAction(KIcon("edit-rename"), i18n("&Rename"), this);
    rename->setShortcut( Qt::Key_F2 );
    connect( rename, SIGNAL(triggered()), SLOT(rename()) );

    KAction* trash = new KAction(KIcon("user-trash"), i18n("&Move to Trash"), this);
    trash->setShortcut( Qt::Key_Delete );
    connect( trash, SIGNAL(triggered(Qt::MouseButtons, Qt::KeyboardModifiers)),
             this, SLOT(moveToTrash(Qt::MouseButtons, Qt::KeyboardModifiers)) );

    KAction* del = new KAction(KIcon("edit-delete"), i18n("&Delete"), this);
    del->setShortcut( Qt::SHIFT + Qt::Key_Delete );
    connect( del, SIGNAL(triggered()), this, SLOT(deleteSelectedItems()) );

    KAction* emptyTrash = new KAction(KIcon("trash-empty"), i18n("&Empty Trash Bin"), this);
    KConfig trashConfig( "trashrc", KConfig::SimpleConfig );
    emptyTrash->setEnabled( !trashConfig.group( "Status" ).readEntry( "Empty", true ) );
    connect( emptyTrash, SIGNAL(triggered()), this, SLOT(emptyTrashBin()) );

    // Create the new menu
    m_newMenu = new KNewFileMenu(&m_actionCollection, "new_menu", this);
    connect( m_newMenu->menu(), SIGNAL(aboutToShow()), this, SLOT(aboutToShowCreateNew()) );

    m_actionCollection.addAction( "undo", undo );
    m_actionCollection.addAction( "cut", cut );
    m_actionCollection.addAction( "copy", copy );
    m_actionCollection.addAction( "paste", paste );
    m_actionCollection.addAction( "pasteto", pasteTo );
    m_actionCollection.addAction( "refresh", refresh );
    m_actionCollection.addAction( "wallpaper", wallpaper );
    m_actionCollection.addAction( "rename", rename );
    m_actionCollection.addAction( "trash", trash );
    m_actionCollection.addAction( "del", del );
    m_actionCollection.addAction( "empty_trash", emptyTrash );
}
示例#10
0
void MainWindow::on_action_Delete_triggered()
{
	// мне не хочется connect руками прописывать
	deleteSelectedItems();
}