void TaskStatusItemModel::setProject( Project *project )
{
    clear();
    if ( m_project ) {
        disconnect( m_project, SIGNAL( localeChanged() ), this, SLOT( slotLayoutChanged() ) );
        disconnect( m_project, SIGNAL( wbsDefinitionChanged() ), this, SLOT( slotWbsDefinitionChanged() ) );
        disconnect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotNodeChanged( Node* ) ) );
        disconnect( m_project, SIGNAL( nodeToBeAdded( Node*, int ) ), this, SLOT( slotNodeToBeInserted(  Node*, int ) ) );
        disconnect( m_project, SIGNAL( nodeToBeRemoved( Node* ) ), this, SLOT( slotNodeToBeRemoved( Node* ) ) );
        disconnect(m_project, SIGNAL(nodeToBeMoved(Node*,int,Node*,int)), this, SLOT(slotNodeToBeMoved(Node*,int,Node*,int)));
    
        disconnect( m_project, SIGNAL( nodeAdded( Node* ) ), this, SLOT( slotNodeInserted( Node* ) ) );
        disconnect( m_project, SIGNAL( nodeRemoved( Node* ) ), this, SLOT( slotNodeRemoved( Node* ) ) );
        disconnect(m_project, SIGNAL(nodeMoved(Node*)), this, SLOT(slotNodeMoved(Node*)));
    }
    m_project = project;
    m_nodemodel.setProject( project );
    if ( project ) {
        connect( m_project, SIGNAL( localeChanged() ), this, SLOT( slotLayoutChanged() ) );
        connect( m_project, SIGNAL( wbsDefinitionChanged() ), this, SLOT( slotWbsDefinitionChanged() ) );
        connect( m_project, SIGNAL( nodeChanged( Node* ) ), this, SLOT( slotNodeChanged( Node* ) ) );
        connect( m_project, SIGNAL( nodeToBeAdded( Node*, int ) ), this, SLOT( slotNodeToBeInserted(  Node*, int ) ) );
        connect( m_project, SIGNAL( nodeToBeRemoved( Node* ) ), this, SLOT( slotNodeToBeRemoved( Node* ) ) );
        connect(m_project, SIGNAL(nodeToBeMoved(Node*,int,Node*,int)), this, SLOT(slotNodeToBeMoved(Node*,int,Node*,int)));

        connect( m_project, SIGNAL( nodeAdded( Node* ) ), this, SLOT( slotNodeInserted( Node* ) ) );
        connect( m_project, SIGNAL( nodeRemoved( Node* ) ), this, SLOT( slotNodeRemoved( Node* ) ) );
        connect(m_project, SIGNAL(nodeMoved(Node*)), this, SLOT(slotNodeMoved(Node*)));

    }
    reset();
}
Example #2
0
AutoCompletion::AutoCompletion(QTreeView* parent) : QWidget(parent)
{
   setVisible(false);
   QVBoxLayout* l = new QVBoxLayout(this);
   m_pLabel = new QLabel(this);
   m_pLabel->setText(i18n("Use ⬆ up and ⬇ down arrows to select one of these numbers"));
   m_pLabel->setStyleSheet(QString("color:%1;font-weight:bold;").arg(QApplication::palette().base().color().name()));
   m_pLabel->setWordWrap(true);
   m_pView = new QListView(this);
   l->addWidget(m_pLabel);
   l->addWidget(m_pView);

   m_pModel = new NumberCompletionModel();
   m_pView->setModel(m_pModel);

   connect(m_pModel,SIGNAL(enabled(bool))  ,this, SLOT(slotVisibilityChange(bool))   );
   connect(m_pModel,SIGNAL(layoutChanged()),this, SLOT(slotLayoutChanged()));
   connect(m_pView,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(slotDoubleClicked(QModelIndex)));

   if (parent) {
      connect(parent->selectionModel(),SIGNAL(currentChanged(QModelIndex,QModelIndex)),this,SLOT(selectionChanged(QModelIndex)));
      parent->installEventFilter(this);
      QResizeEvent r(size(),size());
      eventFilter(nullptr,&r);
   }
   setMinimumSize(0,125);
   m_pDelegate = new AutoCompletionDelegate();
   m_pView->setItemDelegate(m_pDelegate);
}
///How to paint
void DelegateDropOverlay::paintEvent(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index)
{
   if (!m_lpButtons)
      return;
   static bool initSignals = false;
   if (!initSignals) {
      connect(index.model(),SIGNAL(layoutChanged()),this,SLOT(slotLayoutChanged()));
      initSignals = true;
   }
   int step = index.data(ContactModel::Role::DropState).toInt();
   if ((step == 1 || step == -1) && m_lActiveIndexes.indexOf(index) == -1) {
      m_lActiveIndexes << index;
      //Create tge timer
      if (!m_pTimer) {
         m_pTimer = new QTimer(this);
         connect(m_pTimer, SIGNAL(timeout()), this, SLOT(changeVisibility()));
      }

      //Start it if it's nor already
      if (!m_pTimer->isActive()) {
         m_pTimer->start(10);
      }
   }
   int i =0;
   QMapIterator<QString, OverlayButton*> it(*m_lpButtons);
   const int dropPosition = index.data(Call::Role::DropPosition).toInt();
   while (it.hasNext()) {
      it.next();
      if (step) {
         const bool highlight = dropPosition == it.value()->role;
         const int tmpStep = (step>0)?step:15+step;
         painter->save();
         painter->setOpacity(1);
         painter->setRenderHint(QPainter::Antialiasing, true);
         QPen pen = highlight?QApplication::palette().color(QPalette::Highlight): QColor(235,235,235,235);
         pen.setWidth(1);
         painter->setPen(pen);
         QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, 100));
         linearGrad.setColorAt(0, QColor(130,130,130,(0.7*tmpStep*tmpStep)));
         linearGrad.setColorAt(1, QColor(0,0,0,(0.75*tmpStep*tmpStep)));
         painter->setBrush(linearGrad);
         const QRect buttonRect = QRect(
            option.rect.x()+(option.rect.width()/m_lpButtons->size())*i+4,
            option.rect.y()+2,
            option.rect.width()/m_lpButtons->size() - 10,
            option.rect.height()-4);
         painter->drawRoundedRect(buttonRect, 10, 10);
         painter->setPen(highlight?QColor(Qt::white):m_Pen);

         if (it.value()->m_pImage) {
            painter->drawImage(QRect(
               buttonRect.x()+buttonRect.width()-(buttonRect.height()-10)-10/*padding*/,
               buttonRect.y()+5,
               (buttonRect.height()-10),
               (buttonRect.height()-10)),*it.value()->m_pImage);
         }

         QFont font = painter->font();
         font.setBold(true);
         painter->setFont(font);
         painter->drawText (buttonRect, Qt::AlignVCenter|Qt::AlignHCenter, QString(it.key()).remove('&') );
         painter->restore();
         i++;

         if (highlight) {
            QColor col = pen.color();
            for(int i=1;i<=4;i++) {
               painter->setBrush(Qt::NoBrush);
               pen.setWidth(i);
               col.setAlpha(205*(0.5/((float)i)));
               pen.setColor(col);
               painter->setPen(pen);
               painter->drawRoundedRect(buttonRect, 10, 10);
            }
         }
      }
   }
}//paintEvent