Exemplo n.º 1
0
void PropertyEditor::showDefaultsButton(bool show) {
    int y = viewportToContents(QPoint(0, itemRect(m_editItem).y())).y();
    QRect geometry(columnWidth(0), y, columnWidth(1), m_editItem->height());
    m_defaults->resize(m_baseRowHeight, m_baseRowHeight);

    if (!show) {
        if (m_currentEditor) {
            if (m_currentEditor->leavesTheSpaceForRevertButton()) {
                geometry.setWidth(geometry.width() - m_defaults->width());
            }

            m_currentEditor->resize(geometry.width(), geometry.height());
        }

        m_defaults->hide();

        return;
    }

    QPoint p = contentsToViewport(QPoint(0, geometry.y()));
    m_defaults->move(geometry.x() + geometry.width() - m_defaults->width(), p.y());

    if (m_currentEditor) {
        m_currentEditor->move(m_currentEditor->x(), p.y());
        m_currentEditor->resize(geometry.width() - m_defaults->width(), geometry.height());
    }

    m_defaults->show();
}
Exemplo n.º 2
0
void FolderListView::startDrag()
{
QListViewItem *item = currentItem();
if (!item)
	return;

if (item == firstChild() && item->listView()->rootIsDecorated())
	return;//it's the project folder so we don't want the user to move it

QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );

QPixmap pix;
if (item->rtti() == FolderListItem::ListItemType)
	pix = QPixmap( folder_closed_xpm );
else
	pix = *item->pixmap (0);

QIconDrag *drag = new QIconDrag(viewport());
drag->setPixmap(pix, QPoint(pix.width()/2, pix.height()/2 ) );

QPtrList<QListViewItem> lst;
for (item = firstChild(); item; item = item->itemBelow())
	{
	if (item->isSelected())
		lst.append(item);
	}

emit dragItems(lst);
drag->drag();
}
Exemplo n.º 3
0
QDragObject *QtFileIconView::dragObject()
{
    if ( !currentItem() )
        return 0;

    QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
    QtFileIconDrag *drag = new QtFileIconDrag( viewport() );
    drag->setPixmap( *currentItem()->pixmap(),
                     QPoint( currentItem()->pixmapRect().width() / 2, currentItem()->pixmapRect().height() / 2 ) );
    for ( QtFileIconViewItem *item = (QtFileIconViewItem*)firstItem(); item;
            item = (QtFileIconViewItem*)item->nextItem() ) {
        if ( item->isSelected() ) {
            QIconDragItem id;
            id.setData( QCString( item->filename() ) );
            drag->append( id,
                          QRect( item->pixmapRect( FALSE ).x() - orig.x(),
                                 item->pixmapRect( FALSE ).y() - orig.y(),
                                 item->pixmapRect().width(), item->pixmapRect().height() ),
                          QRect( item->textRect( FALSE ).x() - orig.x(),
                                 item->textRect( FALSE ).y() - orig.y(),
                                 item->textRect().width(), item->textRect().height() ),
                          QString( item->filename() ) );
        }
    }

    return drag;
}
Exemplo n.º 4
0
void TextShow::resizeEvent(QResizeEvent *e)
{
#ifdef WIN32
	if (inResize()){
		if (!m_timer->isActive()){
			setHScrollBarMode(AlwaysOff);
			setVScrollBarMode(AlwaysOff);
			m_timer->start(100);
		}
		return;
	}
#endif
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
	int para;
    int pos = charAt(QPoint(x, y), &para);
    QTextEdit::resizeEvent(e);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
	sync();
	viewport()->repaint();
}
void 
PolicyViewClass::onAddPattern()
{
  bool ok = false;
  QString text = QInputDialog::getText(
                    tr( "Add Pattern" ),
                    tr( "Pattern name:" ),
                    QLineEdit::Normal, QString::null, &ok, this );
  if ( ok && !text.isEmpty() ) {
    if (document.addPattern(text, picked_x, picked_y)) {
      PatternWidgetClass* patternWidget = new PatternWidgetClass(this, viewport(), text);
      addChild(patternWidget, picked_x, picked_y);
      patternWidget->show();  
      
      QRect r = viewport()->childrenRect();
      QPoint s = viewportToContents(r.bottomRight());

      resizeContents(s.x(), s.y());
      ensureVisible(picked_x, picked_y);

    }
    else
      QMessageBox::warning(this, 
			   "Add Pattern", 
			   "Pattern " + text + " allready exists.\n" + 
			   "No pattern added.");

  }
}
Exemplo n.º 6
0
void RosegardenScrollView::viewportMouseDoubleClickEvent(QMouseEvent* e)
{
    QMouseEvent ce(e->type(), viewportToContents(e->pos()),
                   e->globalPos(), e->button(), e->buttons(), e->modifiers());
    contentsMouseDoubleClickEvent(&ce);
    if (!ce.isAccepted())
        e->ignore();
}
Exemplo n.º 7
0
void ComponentDiagramView::dropEvent(QDropEvent * e) {
  BrowserNode * bn;
  QPoint p = viewportToContents(e->pos());
  
  if ((bn = UmlDrag::decode(e, UmlComponent)) != 0) {
    history_save();
    
    ComponentCanvas * c = 
      new ComponentCanvas(bn, the_canvas(), p.x(), p.y());
    
    history_protected = TRUE;
    c->show();
    c->upper();
    canvas()->update();
    history_protected = FALSE;
    window()->package_modified();
  }
  else if ((bn = UmlDrag::decode(e, UmlPackage)) != 0) {
    history_save();
    
    PackageCanvas * pk = 
      new PackageCanvas(bn, the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    pk->show();
    pk->upper();
    canvas()->update();
    window()->package_modified();
  }
  else if ((bn = UmlDrag::decode(e, UmlSimpleRelations, TRUE)) != 0) {
    history_save();
    
    history_protected = TRUE;
    SimpleRelationCanvas::drop(bn, the_canvas());
    canvas()->update();
    history_protected = FALSE;
  }
  else if (((bn = UmlDrag::decode(e, UmlClassDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlUseCaseDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlSeqDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlColDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlObjectDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlComponentDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlDeploymentDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlStateDiagram, TRUE)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlActivityDiagram, TRUE)) != 0)) {
    history_save();
    
    IconCanvas * ic = new IconCanvas(bn, the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    ic->show();
    ic->upper();
    canvas()->update();
    history_protected = FALSE;
    window()->package_modified();
  }
}
Exemplo n.º 8
0
void PropertyEditor::createEditor(PropertyEditorItem * i) {
    int y = viewportToContents(QPoint(0, itemRect(i).y())).y();
    QRect geometry(columnWidth(0), y, columnWidth(1), i->height());

    delete m_currentEditor;

    m_editItem = i;
    PropertySubEditor *editor = 0;

    switch (i->type()) {
    case Variant::Type::String:
        editor = new PropertyEditorInput(viewport(), i->property());
        break;
    case Variant::Type::Port:
    case Variant::Type::Pin:
    case Variant::Type::Combo:
    case Variant::Type::VarName:
    case Variant::Type::Select:
    case Variant::Type::PenStyle:
    case Variant::Type::PenCapStyle:
    case Variant::Type::SevenSegment:
    case Variant::Type::KeyPad:
        editor = new PropertyEditorList(viewport(), i->property());
        break;
    case Variant::Type::FileName:
        editor = new PropertyEditorFile(viewport(), i->property());
        break;
    case Variant::Type::Int:
        editor = new PropertyEditorSpin(viewport(), i->property());
        break;
    case Variant::Type::Double:
        editor = new PropertyEditorDblSpin(viewport(), i->property());
        break;
    case Variant::Type::Color:
        editor = new PropertyEditorColor(viewport(), i->property());
        break;
    case Variant::Type::Bool:
        editor = new PropertyEditorBool(viewport(), i->property());
        break;
    case Variant::Type::Raw:
    case Variant::Type::Multiline:
    case Variant::Type::RichText:
    case Variant::Type::None:
        break;
    }

    if (editor) {
        addChild(editor);
        moveChild(editor, geometry.x(), geometry.y());
        editor->show();

        editor->setFocus();
    }

    m_currentEditor = editor;

    showDefaultsButton(i->property()->changed());
}
Exemplo n.º 9
0
void CardView::tryShowFullText()
{
  d->mTimer->stop();
  // if we have an item
  QPoint cpos = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
  CardViewItem *item = itemAt( cpos );
  if ( item ) {
    // query it for a value to display
    QPoint ipos = cpos - itemRect( item ).topLeft();
    item->showFullString( ipos, d->mTip );
  }
}
Exemplo n.º 10
0
void MsgViewBase::reload()
{
    QString t;
    vector<Msg_Id> msgs;
    unsigned i;
    for (i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        Msg_Id id;
        id.id = messageId(s.left(n), client);
        id.client = client;
        unsigned nn;
        for (nn = 0; nn < msgs.size(); nn++){
            if ((msgs[nn].id == id.id) && (msgs[nn].client == id.client))
                break;
        }
        if (nn >= msgs.size())
            msgs.push_back(id);
    }
    for (i = 0; i < msgs.size(); i++){
        Message *msg = History::load(msgs[i].id, msgs[i].client.c_str(), m_id);
        if (msg == NULL)
            continue;
        t += messageText(msg, false);
        delete msg;
    }
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    setText(t);
    if (!CorePlugin::m_plugin->getOwnColors())
        setBackground(0);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
Exemplo n.º 11
0
void TextShow::resizeEvent(QResizeEvent *e)
{
    QPoint p = QPoint(0, height());
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    QTextEdit::resizeEvent(e);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
Exemplo n.º 12
0
QDragObject *KivioIconView::dragObject()
{
  if( !currentItem() || !isReadWrite)
    return 0;

  QPoint orig = viewportToContents( viewport()->mapFromGlobal( QCursor::pos() ) );
  KivioSpawnerDrag *drag = new KivioSpawnerDrag( this, viewport() );

  const char*null_pix[]={
  "1 1 1 1",
  "# c None",
  "#"};
  drag->setPixmap(null_pix);

  KivioIconViewItem *item = (KivioIconViewItem *)currentItem();

  QIconDragItem id;
  QString full;
  full = item->spawner()->set()->dir() + "/" + item->spawner()->info()->title();
  id.setData( QCString(full.ascii()));

  drag->append( id,
      QRect( item->pixmapRect(FALSE).x() - orig.x(),
              item->pixmapRect(FALSE).y() - orig.y(),
              item->pixmapRect().width(),
              item->pixmapRect().height() ),
      QRect( item->textRect(FALSE).x() - orig.x(),
              item->textRect(FALSE).y() - orig.y(),
              item->textRect().width(),
              item->textRect().height() ),
      *(item->spawner()) );


  // Set the current dragged KivioStencilSpawner for use
  // when the drop occurs.  I don't actually encode the
  // data because it's a pain in the ass and I don't understand
  // how to do it.  So I store a pointer here and clear
  // it on the drop.
  m_pCurDrag = item->spawner();

  return drag;
}
Exemplo n.º 13
0
void SchemaEditor::zoom(float factor)
{
  _zoom+=factor;
  if (_zoom < 0.2f)
    _zoom = 0.2f;

  int oldcenterx = visibleWidth()/2;
  int oldcentery = visibleHeight()/2;
  int x, y;
  viewportToContents(oldcenterx, oldcentery, x, y);
  inverseWorldMatrix().map(x, y, &x, &y);
	
  QMatrix wm;
  wm.scale(_zoom, _zoom);
  setWorldMatrix(wm);

  
  //worldMatrix().map(x, y, &x, &y);
  //setContentsPos(x-oldcenterx, y-oldcentery);

}
Exemplo n.º 14
0
void K3bListView::placeEditor( K3bListViewItem* item, int col )
{
  ensureItemVisible( item );
  QRect r = itemRect( item );

  r.setX( contentsToViewport( QPoint(header()->sectionPos( col ), 0) ).x() );
  r.setWidth( header()->sectionSize( col ) - 1 );

  // check if the column is fully visible
  if( visibleWidth() < r.right() )
    r.setRight(visibleWidth());

  r = QRect( viewportToContents( r.topLeft() ), r.size() );

  if( item->pixmap( col ) ) {
    r.setX( r.x() + item->pixmap(col)->width() );
  }

  // the tree-stuff is painted in the first column
  if( col == 0 ) {
    r.setX( r.x() + item->depth() * treeStepSize() );
    if( rootIsDecorated() )
      r.setX( r.x() + treeStepSize() );
  }

  if( item->needButton(col) ) {
    prepareButton( item, col );
    m_editorButton->setFixedHeight( r.height() );
    // for now we make a square button
    m_editorButton->setFixedWidth( m_editorButton->height() );
    r.setWidth( r.width() - m_editorButton->width() );
    moveChild( m_editorButton, r.right(), r.y() );
  }

  if( QWidget* editor = prepareEditor( item, col ) ) {
    editor->resize( r.size() );
    //    editor->resize( QSize( r.width(), editor->minimumSizeHint().height() ) );
    moveChild( editor, r.x(), r.y() );
  }
}
Exemplo n.º 15
0
/**
 * Checks if a tool tip is required for the given position.
 * NOTE: We currently return a tool tip for edges only
 * @param	ptPos	The position to query
 * @param	rc		Holds the tip's rectangle, upon return
 * @return	The tip's text, or QString::null if no tip is required
 */
QString GraphWidget::getTip(const QPoint& ptPos, QRect& rc)
{
	QPoint ptRealPos, ptTopLeft, ptBottomRight;
	QCanvasItemList il;
	QCanvasItemList::Iterator itr;
	GraphEdge* pEdge;
	QString sText, sFile, sLine;
	
	ptRealPos = viewportToContents(ptPos);
	ptRealPos /= m_dZoom;
	pEdge = NULL;
	
	// Check if there is an edge at this position
	il = canvas()->collisions(ptRealPos);
	for (itr = il.begin(); itr != il.end(); ++itr) {
		pEdge = dynamic_cast<GraphEdge*>(*itr);
		if (pEdge != NULL)
			break;
	}
	
	// No tip if no edge was found
	if (pEdge == NULL)
		return QString::null;
	
	// Set the rectangle for the tip (the tip is closed when the mouse leaves
	// this area)
	rc = pEdge->tipRect();
	ptTopLeft = rc.topLeft();
	ptBottomRight = rc.bottomRight();
	ptTopLeft *= m_dZoom;	
	ptBottomRight *= m_dZoom;
	ptTopLeft = contentsToViewport(ptTopLeft);
	ptBottomRight = contentsToViewport(ptBottomRight);
	rc = QRect(ptTopLeft, ptBottomRight);
	
	// Create a tip for this edge
	return pEdge->getTip();
}
void 
PolicyViewClass::init()
{
  // delete all childs
  QObjectList * childs;
  while((childs =  const_cast<QObjectList *>(viewport()->children())) != NULL && 
	!childs->isEmpty()) {
    delete childs->first();
  }

  //-------------------------//
  // rebuild the widget list //
  //-------------------------//

  QStringList list = document.getPatternNames();

  QStringList::Iterator patternIter = list.begin();
  while (patternIter !=list.end()) {
    // generate pattern widget //
    QString patternName = *patternIter;

    PatternWidgetClass* patternWidget = new PatternWidgetClass(this, viewport(), patternName);
    patternWidget->show(); 
    int x = std::max(0, document.getX(patternName));
    int y = std::max(0, document.getY(patternName));
    addChild(patternWidget, x, y);

    patternIter++;
  }

  QRect r = viewport()->childrenRect();
  QPoint s = viewportToContents(r.bottomRight());

  resizeContents(s.x(), s.y());
  setContentsPos(0, 0);
}
Exemplo n.º 17
0
void ActivityDiagramView::dropEvent(QDropEvent * e)
{
    BrowserNode * bn;
    QPoint p = viewportToContents(e->pos());

    if ((bn = UmlDrag::decode(e, UmlActivity, TRUE)) != 0) {
        Q3PopupMenu m(0);

        MenuFactory::createTitle(m, TR("Choose"));
        m.insertSeparator();

        if (!the_canvas()->already_drawn(bn))
            m.insertItem(TR("Draw activity"), 0);

        m.insertItem(TR("Add a call behavior"), 1);

        switch (m.exec(QCursor::pos())) {
        case 0: {
            history_save();
            history_protected = TRUE;

            ActivityCanvas * c =
                new ActivityCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            c->upper();
            history_protected = TRUE;
            c->force_sub_inside(TRUE);

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
        break;

        case 1: {
            bn = BrowserActivityAction::add_call_behavior(container(p), bn);

            if (bn != 0) {
                history_save();
                history_protected = TRUE;

                ActivityActionCanvas * c =
                    new ActivityActionCanvas(bn, the_canvas(), p.x(), p.y());

                history_protected = TRUE;
                c->show();
                (void) ActivityContainerCanvas::force_inside(c, FALSE);
                history_protected = TRUE;

                canvas()->update();
                history_protected = FALSE;
                window()->package_modified();
            }
        }
        break;

        default:
            break;
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlPackage)) != 0) {
        history_save();

        PackageCanvas * pk =
            new PackageCanvas(bn, the_canvas(), p.x(), p.y(), 0);

        history_protected = TRUE;
        pk->show();
        pk->upper();
        canvas()->update();
        history_protected = FALSE;
        window()->package_modified();
    }
    else if ((bn = UmlDrag::decode(e, UmlActivityNode, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();

            ActivityNodeCanvas * c =
                new ActivityNodeCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlInterruptibleActivityRegion, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();

            history_protected = TRUE;

            InterruptibleActivityRegionCanvas * c =
                new InterruptibleActivityRegionCanvas(bn, the_canvas(), p.x(), p.y());
            bool sz;

            history_protected = TRUE;
            c->show();
            sz = !ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;
            c->force_sub_inside(sz);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlExpansionRegion, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();

            history_protected = TRUE;

            ExpansionRegionCanvas * c =
                new ExpansionRegionCanvas(bn, the_canvas(), p.x(), p.y());
            bool sz;

            history_protected = TRUE;
            c->show();
            sz = !ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;
            c->force_sub_inside(sz);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlActivityPartition, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();

            history_protected = TRUE;

            ActivityPartitionCanvas * c =
                new ActivityPartitionCanvas(bn, the_canvas(), p.x(), p.y());
            bool sz;

            history_protected = TRUE;
            c->show();
            sz = !ActivityContainerCanvas::force_inside(c, TRUE);
            history_protected = TRUE;
            c->force_sub_inside(sz);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlActivityAction, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();
            history_protected = TRUE;

            ActivityActionCanvas * c =
                new ActivityActionCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlActivityObject, TRUE)) != 0) {
        if (the_canvas()->already_drawn(bn))
            msg_information("Douml", TR("already drawn"));
        else {
            history_save();
            history_protected = TRUE;

            ActivityObjectCanvas * c =
                new ActivityObjectCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlFlow, TRUE)) != 0) {
        history_save();

        history_protected = TRUE;
        FlowCanvas::drop(bn, the_canvas());
        canvas()->update();
        history_protected = FALSE;
    }
    else if ((bn = UmlDrag::decode(e, UmlSimpleRelations, TRUE)) != 0) {
        history_save();

        history_protected = TRUE;
        SimpleRelationCanvas::drop(bn, the_canvas());
        canvas()->update();
        history_protected = FALSE;
    }
    else if (((bn = UmlDrag::decode(e, UmlClassDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlUseCaseDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlSeqDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlColDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlObjectDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlActivityDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlComponentDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlDeploymentDiagram)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlStateDiagram, TRUE)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlActivityDiagram, TRUE)) != 0)) {
        history_save();

        IconCanvas * ic = new IconCanvas(bn, the_canvas(), p.x(), p.y(), 0);

        history_protected = TRUE;
        ic->show();
        ic->upper();

        canvas()->update();
        history_protected = FALSE;
        window()->package_modified();
    }
    else if ((bn = UmlDrag::decode(e, UmlOperation)) != 0) {
        bn = BrowserActivityAction::add_call_operation(container(p), (BrowserOperation *) bn);

        if (bn != 0) {
            history_save();
            history_protected = TRUE;

            ActivityActionCanvas * c =
                new ActivityActionCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if (((bn = UmlDrag::decode(e, UmlAttribute)) != 0) ||
             ((bn = UmlDrag::decode(e, UmlRelations, TRUE)) != 0)) {
        Q3PopupMenu m(0);

        MenuFactory::createTitle(m, TR("Choose"));
        m.insertSeparator();
        m.insertItem(TR("Add a read variable value action"), 0);
        m.insertItem(TR("Add a clear variable value action"), 1);
        m.insertItem(TR("Add a write variable value action"), 2);
        m.insertItem(TR("Add a add variable value action"), 3);
        m.insertItem(TR("Add a remove variable value action"), 4);

        switch (m.exec(QCursor::pos())) {
        case 0:
            bn = BrowserActivityAction::add_read_variable_value(container(p), bn);
            break;

        case 1:
            bn = BrowserActivityAction::add_clear_variable_value(container(p), bn);
            break;

        case 2:
            bn = BrowserActivityAction::add_write_variable_value(container(p), bn);
            break;

        case 3:
            bn = BrowserActivityAction::add_add_variable_value(container(p), bn);
            break;

        case 4:
            bn = BrowserActivityAction::add_remove_variable_value(container(p), bn);
            break;

        default:
            return;
        }

        if (bn != 0) {
            history_save();
            history_protected = TRUE;

            ActivityActionCanvas * c =
                new ActivityActionCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlClass)) != 0) {
        history_protected = FALSE;

        BrowserActivityObject * obj =
            BrowserActivityObject::add_activityobject(container(p), 0);

        if (obj != 0) {
            ((ActivityObjectData *) obj->get_data())->set_type((BrowserClass *) bn);

            history_save();
            history_protected = TRUE;

            ActivityObjectCanvas * c =
                new ActivityObjectCanvas(obj, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlClassInstance)) != 0) {
        history_protected = FALSE;

        BrowserActivityObject * obj =
            BrowserActivityObject::add_activityobject(container(p), bn->get_name());

        if (obj != 0) {
            ((ActivityObjectData *) obj->get_data())
            ->set_type(((ClassInstanceData *) bn->get_data())->get_class());

            history_save();
            history_protected = TRUE;

            ActivityObjectCanvas * c =
                new ActivityObjectCanvas(obj, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;

            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
    else if ((bn = UmlDrag::decode(e, UmlState, TRUE)) != 0) {
        history_protected = FALSE;

        bn = BrowserActivityAction::add_call_behavior(container(p), bn);

        if (bn != 0) {
            history_save();
            history_protected = TRUE;

            ActivityActionCanvas * c =
                new ActivityActionCanvas(bn, the_canvas(), p.x(), p.y());

            history_protected = TRUE;
            c->show();
            (void) ActivityContainerCanvas::force_inside(c, FALSE);
            history_protected = TRUE;
            canvas()->update();
            history_protected = FALSE;
            window()->package_modified();
        }
    }
}
Exemplo n.º 18
0
void RoutingDrawWidget::mouseReleaseEvent(QMouseEvent *e)
{
	RoutingWidget *parent = (RoutingWidget *)parentWidget();
	StrGlobal *structure = parent->getStructure();
	
	if (!structure)
		return;
		
	if (mode == Select)
	{
		selectEndPoint.setX(e->x());
		selectEndPoint.setY(e->y());
		
		QRect selArea(selectStartPoint, selectEndPoint);
		selArea = selArea.normalize();
		
		// transform
		int xt1;
		int yt1;
		
		int xt2;
		int yt2;
		
		viewportToContents(selArea.x(), selArea.y(), xt1, yt1);
		xt1 = parent->deZoomVal(xt1);
		yt1 = parent->deZoomVal(yt1);
		
		viewportToContents(selArea.right(), selArea.bottom(), xt2, yt2);
		xt2 = parent->deZoomVal(xt2);
		yt2 = parent->deZoomVal(yt2);
		
		// set flag for selected
		QRect selAreaTrans(QPoint(xt1, yt1), QPoint(xt2, yt2));
		
		RSItemBaseWithType *item;		
		for(item = structure->UsedItems.first(); item; item = structure->UsedItems.next() )
		{
			if (selAreaTrans.contains(item->x(), item->y()) &&
				selAreaTrans.contains(item->x() + item->width(), item->y() + item->height()))
			{
				if (!item->flagSelected())
					item->setFlagSelected(true);
			}
			else
			{
				if (!(e->state() & Qt::ControlButton) && item->flagSelected()) 
				{
					item->setFlagSelected(false);
					
					this->updateContents(parent->zoomVal(item->x()),
						parent->zoomVal(item->y()),
						parent->zoomVal(item->width()),
						parent->zoomVal(item->height()));
				}
			}
			
			
		}
		
		//this->updateContents(selArea);
		this->viewport()->update(selArea);
	}
	
	if (mode != DragLink)
		mode = None;
}
Exemplo n.º 19
0
void *MsgViewBase::processEvent(Event *e)
{
    if ((e->type() == EventRewriteMessage) || (e->type() == EventMessageRead)){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        unsigned i;
        for (i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            if ((messageId(s.left(n), client) == msg->id()) && (client == msg->client()))
                break;
        }
        if (i >= (unsigned)paragraphs())
            return NULL;
        Msg_Id id;
        id.id     = msg->id();
        id.client = msg->client();
        m_updated.push_back(id);
        QTimer::singleShot(0, this, SLOT(update()));
        return NULL;
    }
    if (e->type() == EventCutHistory){
        CutHistory *ch = (CutHistory*)(e->param());
        if (ch->contact != m_id)
            return NULL;

        bool bDelete = false;
        vector<unsigned> start_pos;
        vector<unsigned> end_pos;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            unsigned id = messageId(s.left(n), client);
            if ((client == ch->client) && (id >= ch->from) && (id < ch->from + ch->size)){
                if (!bDelete){
                    bDelete = true;
                    start_pos.push_back(i);
                }
            }else{
                if (bDelete){
                    bDelete = false;
                    end_pos.push_back(i);
                }
            }
        }
        if (bDelete)
            end_pos.push_back(paragraphs());
        if (start_pos.size()){
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            QPoint p = QPoint(0, 0);
            p = mapToGlobal(p);
            p = viewport()->mapFromGlobal(p);
            int x, y;
            viewportToContents(p.x(), p.y(), x, y);
            int para;
            int pos = charAt(QPoint(x, y), &para);
            setReadOnly(false);
            for (unsigned i = 0; i < start_pos.size(); i++){
                setSelection(start_pos[i], 0, end_pos[i], 0);
                removeSelectedText();
                if ((unsigned)pos >= start_pos[i])
                    pos = end_pos[i] - start_pos[i];
            }
            if ((paraFrom == -1) && (paraTo == -1)){
                if (pos == -1){
                    scrollToBottom();
                }else{
                    setCursorPosition(para, pos);
                    ensureCursorVisible();
                }
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            setReadOnly(true);
            repaint();
        }
        m_cut.push_back(*ch);
        return NULL;
    }
    if (e->type() == EventMessageDeleted){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_ANCHOR);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_ANCHOR));
            n = s.find("\"");
            if (n < 0)
                continue;
            string client;
            if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client()))
                continue;
            string ss;
            ss = text(i).local8Bit();
            log(L_DEBUG, "?: %s", ss.c_str());

            unsigned j;
            for (j = i + 1; j < (unsigned)paragraphs(); j++){
                QString s = text(j);
                ss = text(j).local8Bit();
                log(L_DEBUG, ">: %s", ss.c_str());
                int n = s.find(MSG_ANCHOR);
                if (n < 0)
                    continue;
                s = s.mid(n + strlen(MSG_ANCHOR));
                n = s.find("\"");
                if (n < 0)
                    continue;
                string client;
                if ((messageId(s.left(n), client) != msg->id()) || (client != msg->client()))
                    break;
            }
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            unsigned pos = 0xFFFF;
            if (j == (unsigned)paragraphs()){
                j++;
                pos = 0;
            }
            setSelection(i, 0, j - 1, pos);
            setReadOnly(false);
            removeSelectedText();
            setReadOnly(true);
            if ((paraFrom == -1) && (paraTo == -1)){
                scrollToBottom();
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            break;
        }
        return NULL;
    }
    if (e->type() == EventHistoryConfig){
        unsigned id = (unsigned)(e->param());
        if (id && (id != m_id))
            return NULL;
        reload();
    }
    if (e->type() == EventHistoryColors)
        setColors();
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED);
            if (!hasSelectedText())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                unsigned type = msg->baseType();
                delete msg;
                CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type);
                if (def == NULL)
                    return NULL;
                cmd->icon = def->icon;
                cmd->flags &= ~COMMAND_CHECKED;
                return e->param();
            }
            return NULL;
        case CmdMsgSpecial:
            msg = currentMessage();
            if (msg){
                Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand);
                CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process());

                unsigned n = 0;
                MessageDef *mdef = NULL;
                unsigned type = msg->baseType();
                const CommandDef *cmdsSpecial = NULL;
                CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                if (msgCmd)
                    mdef = (MessageDef*)(msgCmd->param);

                if (mdef){
                    if (msg->getFlags() & MESSAGE_RECEIVED){
                        cmdsSpecial = mdef->cmdReceived;
                    }else{
                        cmdsSpecial = mdef->cmdSent;
                    }
                    if (cmdsSpecial)
                        for (const CommandDef *d = cmdsSpecial; d->text; d++)
                            n++;
                }

                {
                    CommandsList it(*cmdsMsg, true);
                    while (++it)
                        n++;
                }
                if (n == 0)
                    return NULL;

                n++;
                CommandDef *cmds = new CommandDef[n];
                memset(cmds, 0, sizeof(CommandDef) * n);
                n = 0;
                if (cmdsSpecial){
                    for (const CommandDef *d = cmdsSpecial; d->text; d++){
                        cmds[n] = *d;
                        cmds[n].id = CmdMsgSpecial + n;
                        n++;
                    }
                }
                CommandDef *c;
                CommandsList it(*cmdsMsg, true);
                while ((c = ++it) != NULL){
                    CommandDef cmd = *c;
                    cmd.menu_id = MenuMsgCommand;
                    cmd.param   = msg;
                    Event e(EventCheckState, &cmd);
                    if (!e.process())
                        continue;
                    cmd.flags &= ~COMMAND_CHECK_STATE;
                    cmds[n++] = cmd;
                }
                cmd->param = cmds;
                cmd->flags |= COMMAND_RECURSIVE;
                delete msg;
                return e->param();
            }
            return NULL;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCutHistory:
            msg = currentMessage();
            if (msg){
                History::cut(msg, 0, 0);
                delete msg;
                return e->param();
            }
            return NULL;
        case CmdDeleteMessage:
            msg = currentMessage();
            if (msg){
                History::del(msg);
                delete msg;
                return e->param();
            }
            return NULL;
        case CmdCopy:
            copy();
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                msg->setFlags(msg->getFlags() | MESSAGE_OPEN);
                Event eOpen(EventOpenMessage, &msg);
                eOpen.process();
                delete msg;
                return e->param();
            }
            return NULL;
        default:
            msg = currentMessage();
            if (msg){
                if (cmd->id >= CmdMsgSpecial){
                    MessageDef *mdef = NULL;
                    unsigned type = msg->baseType();
                    CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                    if (msgCmd)
                        mdef = (MessageDef*)(msgCmd->param);
                    const CommandDef *cmds = NULL;
                    if (mdef){
                        if (msg->getFlags() & MESSAGE_RECEIVED){
                            cmds = mdef->cmdReceived;
                        }else{
                            cmds = mdef->cmdSent;
                        }
                    }

                    if (cmds){
                        unsigned n = cmd->id - CmdMsgSpecial;
                        for (const CommandDef *d = cmds; d->text; d++){
                            if (n-- == 0){
                                CommandDef cmd = *d;
                                cmd.param = msg;
                                Event eCmd(EventCommandExec, &cmd);
                                eCmd.process();
                                return e->param();
                            }
                        }
                    }
                }
                Command c;
                c->id = cmd->id;
                c->menu_id = MenuMsgCommand;
                c->param = msg;
                Event e(EventCommandExec, c);
                void *res = e.process();
                delete msg;
                return res;
            }
            return NULL;
        }
    }
    return NULL;
}
Exemplo n.º 20
0
void MsgViewBase::update()
{
    if (m_updated.empty())
        return;
    unsigned i;
    for (i = 0; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        unsigned id = messageId(s.left(n), client);
        list<Msg_Id>::iterator it;
        for (it = m_updated.begin(); it != m_updated.end(); ++it){
            if (((*it).id == id) && ((*it).client == client))
                break;
        }
        if (it != m_updated.end())
            break;
    }
    m_updated.clear();
    if (i >= (unsigned)paragraphs())
        return;
    QPoint p = QPoint(0, 0);
    p = mapToGlobal(p);
    p = viewport()->mapFromGlobal(p);
    int x, y;
    viewportToContents(p.x(), p.y(), x, y);
    int para;
    int pos = charAt(QPoint(x, y), &para);
    p = QPoint(0, viewport()->height());
    p = viewport()->mapToGlobal(p);
    p = mapFromGlobal(p);
    if (p.y() + 2 == height())
        pos = -1;
    unsigned start = i;
    list<Msg_Id> msgs;
    for (; i < (unsigned)paragraphs(); i++){
        QString s = text(i);
        int n = s.find(MSG_ANCHOR);
        if (n < 0)
            continue;
        s = s.mid(n + strlen(MSG_ANCHOR));
        n = s.find("\"");
        if (n < 0)
            continue;
        string client;
        unsigned id = messageId(s.left(n), client);
        list<Msg_Id>::iterator it;
        for (it = msgs.begin(); it != msgs.end(); ++it){
            if (((*it).id == id) && ((*it).client == client))
                break;
        }
        if (it != msgs.end())
            continue;
        Msg_Id m_id;
        m_id.id     = id;
        m_id.client = client;
        msgs.push_back(m_id);
    }
    int paraFrom, indexFrom;
    int paraTo, indexTo;
    getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
    setReadOnly(false);
    setSelection(start, 0, paragraphs() - 1, 0xFFFF);
    removeSelectedText();
    setReadOnly(true);
    QString text;
    for (list<Msg_Id>::iterator it = msgs.begin(); it != msgs.end(); ++it){
        Message *msg = History::load((*it).id, (*it).client.c_str(), m_id);
        if (msg == NULL)
            continue;
        bool bUnread = false;
        for (list<msg_id>::iterator itu = CorePlugin::m_plugin->unread.begin(); itu != CorePlugin::m_plugin->unread.end(); ++itu){
            msg_id &m = (*itu);
            if ((m.contact == msg->contact()) &&
                    (m.id == msg->id()) &&
                    (m.client == msg->client())){
                bUnread = true;
                break;
            }
        }
        text += messageText(msg, bUnread);
    }
    append(text);
    if (!CorePlugin::m_plugin->getOwnColors())
        setBackground(0);
    if ((paraFrom != paraTo) || (indexFrom != indexTo))
        setSelection(paraFrom, indexFrom, paraTo, indexTo);
    if (pos == -1){
        scrollToBottom();
    }else{
        setCursorPosition(para, pos);
        ensureCursorVisible();
    }
}
Exemplo n.º 21
0
void RoutingDrawWidget::mouseMoveEvent(QMouseEvent *e)
{
	RoutingWidget *parent = (RoutingWidget *)parentWidget();
	StrGlobal *structure = parent->getStructure();
	
	if (!structure)
		return;
		
	if (mode == Select && 
		(e->x() != selectStartPoint.x() || e->y() != selectStartPoint.y()))
	{
		QPainter p(this->viewport());
		
		p.drawWinFocusRect(selectStartPoint.x(),
			selectStartPoint.y(),
			selectEndPoint.x() - selectStartPoint.x(),
			selectEndPoint.y() - selectStartPoint.y());
			
		selectEndPoint.setX(e->x());
		selectEndPoint.setY(e->y());
			
		p.drawWinFocusRect(selectStartPoint.x(),
			selectStartPoint.y(),
			selectEndPoint.x() - selectStartPoint.x(),
			selectEndPoint.y() - selectStartPoint.y());
	}
	else
	{
		int dx = parent->deZoomVal((selectEndPoint.x() - selectStartPoint.x()));
		int dy = parent->deZoomVal((selectEndPoint.y() - selectStartPoint.y()));
		
		if (mode == Move)
		{
			RSItemBaseWithType *item;
			for(item = structure->UsedItems.first(); item; item = structure->UsedItems.next() )
			{
				if (item->flagSelected())
				{
					// update old
					item->updateContents(this, parent->getZoomLevel());
						
					item->moveRel(dx, dy);
					// update new
					item->updateContents(this, parent->getZoomLevel());
				}
			}
		}
		else if (mode == HandleMove)
		{
			// update old
			resizeItem->updateContents(this, parent->getZoomLevel());
				
			resizeItem->moveHandleRel(linkHandle, dx, dy);
			// update new
			resizeItem->updateContents(this, parent->getZoomLevel());
		}
		else if (mode == ResizeTopLeft || 
			mode == ResizeTopRight ||
			mode == ResizeBottomLeft ||
			mode == ResizeBottomRight)
		{
			int nx = resizeItem->x();
			int ny = resizeItem->y();
			int nw = resizeItem->width();
			int nh = resizeItem->height();
								
			switch (mode)
			{
				case ResizeTopLeft:
					nx = nx + dx;
					ny = ny + dy;
					nw = nw - dx;
					nh = nh - dy;
					break;
				case ResizeTopRight:
					ny = ny + dy;
					nw = nw + dx;
					nh = nh - dy;
					break;
				case ResizeBottomLeft:
					nx = nx + dx;
					nw = nw - dx;
					nh = nh + dy;
					break;
				case ResizeBottomRight:
					nw = nw + dx;
					nh = nh + dy;
					break;
				default:
					break;
			}
			
			if (nx < 0)
				nx = 0;
			if (ny < 0)
				ny = 0;

			if (nw < resizeItem->minWidth())
				nw = resizeItem->minWidth();
			if (nh < resizeItem->minHeight())
				nh = resizeItem->minHeight();
				
			resizeItem->updateContents(this, parent->getZoomLevel());

			resizeItem->setPosition(nx, ny);
			resizeItem->setSize(nw, nh);
			// update new
			resizeItem->updateContents(this, parent->getZoomLevel());
		}
		else if (mode == DragLink)
		{
			updateDragLink();
		}
		
		selectStartPoint = selectEndPoint;
	
		selectEndPoint.setX(e->x());
		selectEndPoint.setY(e->y());
		
		if (mode == DragLink)
		{
			int ex = selectEndPoint.x();
			int ey = selectEndPoint.y();
			
			viewportToContents(parent->deZoomVal(ex), parent->deZoomVal(ey), ex, ey);
			
			selectEndPoint.setX(ex);
			selectEndPoint.setY(ey);
		}
	}
}
Exemplo n.º 22
0
void ObjectDiagramView::dropEvent(QDropEvent * e) {
  BrowserNode * bn;
  QPoint p = viewportToContents(e->pos());
  
  if ((bn = UmlDrag::decode(e, UmlClassInstance)) != 0) {
    history_save();
    
    OdClassInstCanvas * i = 
      new OdClassInstCanvas((BrowserClassInstance *) bn,
			    the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    i->show();
    i->upper();
    canvas()->update();
    history_protected = FALSE;
    window()->package_modified();
  }
  else if ((bn = UmlDrag::decode(e, UmlClass)) != 0) {
    history_save();
    
    BrowserNode * parent =
      ((BrowserNode *) window()->browser_diagram()->parent());
    BrowserClassInstance * cli =
      new BrowserClassInstance("", (BrowserClass *) bn, parent);
    OdClassInstCanvas * i = 
      new OdClassInstCanvas(cli, the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    i->show();
    i->upper();
    canvas()->update();
    history_protected = FALSE;
    window()->package_modified();
  }
  else if ((bn = UmlDrag::decode(e, UmlPackage)) != 0) {
    history_save();
    
    PackageCanvas * pk = 
      new PackageCanvas(bn, the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    pk->show();
    pk->upper();
    canvas()->update();
    window()->package_modified();
  }
  else if (((bn = UmlDrag::decode(e, UmlClassDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlUseCaseDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlSeqDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlObjectDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlComponentDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlDeploymentDiagram)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlStateDiagram, TRUE)) != 0) ||
	   ((bn = UmlDrag::decode(e, UmlActivityDiagram, TRUE)) != 0)) {
    history_save();
    
    IconCanvas * ic = new IconCanvas(bn, the_canvas(), p.x(), p.y(), 0);
    
    history_protected = TRUE;
    ic->show();
    ic->upper();
    canvas()->update();
    history_protected = FALSE;
    window()->package_modified();
  }
}
Exemplo n.º 23
0
void *MsgViewBase::processEvent(Event *e)
{
    if (e->type() == EventMessageRead){
        Message *msg = (Message*)(e->param());
        if (msg->contact() != m_id)
            return NULL;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_HREF);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_HREF));
            n = s.find("\"");
            if (n < 0)
                continue;
            s = s.left(n);
            unsigned id = atol(getToken(s, ',').latin1());
            if (id != msg->id())
                continue;
            getToken(s, ',');
            if (s != msg->client())
                continue;
            int paraFrom, indexFrom;
            int paraTo, indexTo;
            getSelection(&paraFrom, &indexFrom, &paraTo, &indexTo);
            setSelection(i, 0, i, 0xFFFF);
            setBold(false);
            if ((paraFrom == -1) && (paraTo == -1)){
                removeSelection();
                scrollToBottom();
            }else{
                setSelection(paraFrom, indexFrom, paraTo, indexTo);
            }
            break;
        }
        return NULL;
    }
    if (e->type() == EventHistoryConfig){
        unsigned id = (unsigned)(e->param());
        if (id && (id != m_id))
            return NULL;
        QString t;
        for (unsigned i = 0; i < (unsigned)paragraphs(); i++){
            QString s = text(i);
            int n = s.find(MSG_HREF);
            if (n < 0)
                continue;
            s = s.mid(n + strlen(MSG_HREF));
            n = s.find("\"");
            if (n < 0)
                continue;
            s = s.left(n);
            unsigned id = atol(getToken(s, ',').latin1());
            getToken(s, ',');
            Message *msg = History::load(id, s.utf8(), m_id);
            if (msg == NULL)
                continue;
            t += messageText(msg);
            delete msg;
        }
        QPoint p = QPoint(0, height());
        p = mapToGlobal(p);
        p = viewport()->mapFromGlobal(p);
        int x, y;
        viewportToContents(p.x(), p.y(), x, y);
        int para;
        int pos = charAt(QPoint(x, y), &para);
        setText(t);
        setBackground(0);
        if (pos == -1){
            scrollToBottom();
        }else{
            setCursorPosition(para, pos);
            ensureCursorVisible();
        }
    }
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            cmd->flags &= ~(COMMAND_DISABLED | COMMAND_CHECKED);
            if (!hasSelectedText())
                cmd->flags |= COMMAND_DISABLED;
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                unsigned type = msg->type();
                delete msg;
                for (;;){
                    CommandDef *def = CorePlugin::m_plugin->messageTypes.find(type);
                    if (def == NULL){
                        return NULL;
                    }
                    MessageDef *mdef = (MessageDef*)(def->param);
                    if (mdef->base_type){
                        type = mdef->base_type;
                        continue;
                    }
                    cmd->icon = def->icon;
                    cmd->flags &= ~COMMAND_CHECKED;
                    return e->param();
                }
            }
            return NULL;
        case CmdMsgSpecial:
            msg = currentMessage();
            if (msg){
                Event eMenu(EventGetMenuDef, (void*)MenuMsgCommand);
                CommandsDef *cmdsMsg = (CommandsDef*)(eMenu.process());

                unsigned n = 0;
                MessageDef *mdef = NULL;
                if (msg->getFlags() & MESSAGE_RECEIVED){
                    unsigned type = msg->type();
                    for (;;){
                        CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                        if (msgCmd == NULL)
                            break;
                        mdef = (MessageDef*)(msgCmd->param);
                        if (mdef->base_type == 0)
                            break;
                        type = mdef->base_type;
                    }
                }
                if (mdef && mdef->cmd){
                    for (const CommandDef *d = mdef->cmd; d->text; d++)
                        n++;
                }

                {
                    CommandsList it(*cmdsMsg, true);
                    while (++it)
                        n++;
                }
                if (n == 0)
                    return NULL;

                n++;
                CommandDef *cmds = new CommandDef[n];
                memset(cmds, 0, sizeof(CommandDef) * n);
                n = 0;
                if (mdef && mdef->cmd){
                    for (const CommandDef *d = mdef->cmd; d->text; d++){
                        cmds[n] = *d;
                        cmds[n].id = CmdMsgSpecial + n;
                        n++;
                    }
                }
                CommandDef *c;
                CommandsList it(*cmdsMsg, true);
                while ((c = ++it) != NULL){
                    CommandDef cmd = *c;
                    cmd.menu_id = MenuMsgCommand;
                    cmd.param   = msg;
                    Event e(EventCheckState, &cmd);
                    if (!e.process())
                        continue;
                    cmd.flags &= ~COMMAND_CHECK_STATE;
                    cmds[n++] = cmd;
                }
                cmd->param = cmds;
                cmd->flags |= COMMAND_RECURSIVE;
                delete msg;
                return e->param();
            }
            return NULL;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if ((cmd->param != this) || (cmd->menu_id != MenuMsgView))
            return NULL;
        Message *msg;
        switch (cmd->id){
        case CmdCopy:
            copy();
            return e->param();
        case CmdMsgOpen:
            msg = currentMessage();
            if (msg){
                Event eOpen(EventOpenMessage, msg);
                eOpen.process();
                delete msg;
                return e->param();
            }
            return NULL;
        default:
            msg = currentMessage();
            if (msg){
                if (cmd->id >= CmdMsgSpecial){
                    MessageDef *mdef = NULL;
                    unsigned type = msg->type();
                    for (;;){
                        CommandDef *msgCmd = CorePlugin::m_plugin->messageTypes.find(type);
                        if (msgCmd == NULL)
                            break;
                        mdef = (MessageDef*)(msgCmd->param);
                        if (mdef->base_type == 0)
                            break;
                        type = mdef->base_type;
                    }
                    if (mdef && mdef->cmd){
                        unsigned n = cmd->id - CmdMsgSpecial;
                        for (const CommandDef *d = mdef->cmd; d->text; d++){
                            if (n-- == 0){
                                CommandDef cmd = *d;
                                cmd.param = msg;
                                Event eCmd(EventCommandExec, &cmd);
                                eCmd.process();
                                return e->param();
                            }
                        }
                    }
                }
                Command c;
                c->id = cmd->id;
                c->menu_id = MenuMsgCommand;
                c->param = msg;
                Event e(EventCommandExec, c);
                void *res = e.process();
                delete msg;
                return res;
            }
            return NULL;
        }
    }
    return NULL;
}
Exemplo n.º 24
0
void RoutingDrawWidget::mousePressEvent(QMouseEvent *e)
{
	QScrollView::mousePressEvent(e);
	setFocus();
	
	RoutingWidget *parent = (RoutingWidget *)parentWidget();
	StrGlobal *structure = parent->getStructure();
	
	if (!structure)
		return;
		
	//treba prepocet na zoom a ofset qscrollview - a niekde to pada
	int xp = e->x();
	int yp = e->y();
	
	viewportToContents(xp, yp, xp, yp);
	
	xp = parent->deZoomVal(xp);
	yp = parent->deZoomVal(yp);
	
	RSItemBaseWithType *item;
	
	QPtrList <RSItemBaseWithType> toClear;
	
	if (e->button() == MidButton)
		return;

	if (mode == DragLink)
	{
		QPoint tmpp = mapToGlobal(QPoint(e->x(), e->y()));
		connectLinkDrag(xp, yp, tmpp.x(), tmpp.y());
		return;
	}
		
	// get mode
	if (parent->getWidgetMode() != RoutingWidget::Normal &&
		e->button() == LeftButton)
	{
		parent->putNewObjectAt(xp, yp);
		return;
	}
		
		
	// find item under this point
	bool oneSelected = false;
	bool clearOthers = false;
	
	RSItemBase::RSItemHandle resHandle = RSItemBase::None;
	RSItemBaseWithType *itemToResize = NULL;
	RSItemBaseWithType *itemOn = NULL;
	linkHandle = -1;
	
	for(item = structure->UsedItems.first(); item; item = structure->UsedItems.next())
	{
		bool redraw = false;
		
		if (!oneSelected && item->containsPoint(xp, yp))
		{
			if (!item->flagSelected())
			{
				item->setFlagSelected(true);
				redraw = true;
				clearOthers = true;
			}
			else if (e->state() & Qt::ControlButton)
			{
				item->setFlagSelected(false);
				redraw = true;
			}
			oneSelected = true;
			
			itemOn = item;
			
			// check resize point
			resHandle = item->getHandlePoint(xp, yp);
			if (resHandle == RSItemBase::Other)
			{
				itemToResize = item;
				linkHandle = item->getHandlePointNum(xp, yp);
			}
			else
			{
				linkHandle = -1;			
				if (resHandle != RSItemBase::None)
					itemToResize = item;
			}
		}
		else
		{
			if (item->flagSelected())
				toClear.append(item);
		}
				
		if (redraw)
		{
			this->updateContents(parent->zoomVal(item->x()),
				parent->zoomVal(item->y()),
				parent->zoomVal(item->width()),
				parent->zoomVal(item->height()));
		}
	}
	
	EditMode newMode = None;
	RoutingWidget::MenuMode newMenuMode = RoutingWidget::MenuNone;
	
	parent->itemOn = NULL;
	
	bool doClearOthers = false;
	
	if (e->button() == LeftButton)
	{
		if (!oneSelected)
		{
			// set select mode
			newMode = Select;
		}
		else 
		{
			if (e->state() & Qt::ControlButton)
			{
				newMode = None;
			}
			else
			{
				if (clearOthers)
					doClearOthers = true;
				if (itemToResize)
				{
					resizeItem = itemToResize;
						
					if (linkHandle < 0)
					{
						switch (resHandle)
						{
							case RSItemBase::TopLeft:
								newMode = ResizeTopLeft;
								break;
							case RSItemBase::TopRight:
								newMode = ResizeTopRight;
								break;
							case RSItemBase::BottomLeft:
								newMode = ResizeBottomLeft;
								break;
							case RSItemBase::BottomRight:
								newMode = ResizeBottomRight;
								break;
							default:
								break;
						}
					}
					else
						newMode = HandleMove;
				}
				else if(itemOn->type() != RSItemBaseWithType::Link)
					newMode = Move;
				else
					newMode = None;
			}
		}
	}
	else
	{
		if (!oneSelected)
		{
			newMenuMode = RoutingWidget::MenuNone;
			doClearOthers = true;
		}
		else
		{
			if (clearOthers)
			{
				doClearOthers = true;
			}
				
			if (!doClearOthers && toClear.count() > 0)
				newMenuMode = RoutingWidget::MenuObjects;
			else
			{
				switch (itemOn->type())
				{
					case RSItemBaseWithType::In:
					case RSItemBaseWithType::Out:
					case RSItemBaseWithType::FX:
						newMenuMode = RoutingWidget::MenuIO;
						break;
					case RSItemBaseWithType::Link:
						newMenuMode = RoutingWidget::MenuLink;
						break;
					case RSItemBaseWithType::Patch:
						newMenuMode = RoutingWidget::MenuPatch;
						break;
					default:
						break;
				}
			}
		}
		
		parent->itemOn = itemOn;
		parent->posXOn = xp;
		parent->posYOn = yp;
	}
	
	if (doClearOthers)
	{
		for(item = toClear.first(); item; item = toClear.next())
		{
			item->setFlagSelected(false);
			
			this->updateContents(parent->zoomVal(item->x()),
				parent->zoomVal(item->y()),
				parent->zoomVal(item->width()),
				parent->zoomVal(item->height()));
		}		
	}
	
	if (e->button() == LeftButton)
		mode = newMode;
	else
	{
		QPoint p = mapToGlobal(QPoint(e->x(), e->y()));
		parent->openObjectMenuAt(itemOn, newMenuMode, xp, yp, p.x(), p.y());
	}
	
	selectStartPoint.setX(e->x());
	selectStartPoint.setY(e->y());
	selectEndPoint = selectStartPoint;

}