Beispiel #1
0
ExtenderGroup::ExtenderGroup(Extender *parent, uint groupId)
             : ExtenderItem(parent, groupId),
               d(new ExtenderGroupPrivate(this))
{
    connect(extender(), SIGNAL(itemAttached(Plasma::ExtenderItem*)),
            this, SLOT(addItemToGroup(Plasma::ExtenderItem*)));
    connect(extender(), SIGNAL(itemDetached(Plasma::ExtenderItem*)),
            this, SLOT(removeItemFromGroup(Plasma::ExtenderItem*)));

    //this isn't actually connected to anything, we will just check if it's running or not
    d->resizeTimer = new QTimer(this);
    d->resizeTimer->setSingleShot(true);

    config().writeEntry("isGroup", true);

    setAcceptDrops(true);

    QGraphicsLinearLayout *lay = static_cast<QGraphicsLinearLayout *>(layout());
    d->childsWidget = new QGraphicsWidget(this);
    d->childsWidget->installEventFilter(this);
    d->layout = new QGraphicsLinearLayout(Qt::Vertical, d->childsWidget);
    d->childsWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    lay->addItem(d->childsWidget);

    QAction *expand = new QAction(this);
    expand->setVisible(false);
    expand->setToolTip(i18n("Show this group."));
    connect(expand, SIGNAL(triggered()), this, SLOT(expandGroup()));
    addAction("expand", expand);

    QAction *collapse = new QAction(this);
    collapse->setVisible(true);
    collapse->setToolTip(i18n("Hide this group."));
    connect(collapse, SIGNAL(triggered()), this, SLOT(collapseGroup()));
    addAction("collapse", collapse);

    d->themeChanged();

    QString groupName;
    foreach (ExtenderItem *item, extender()->attachedItems()) {
        groupName = item->config().readEntry("group", "");
        if (!groupName.isEmpty() && groupName == name()) {
            item->setGroup(this);
        }
    }
    void relayoutExtender()
    {
        if (!m_extenders.contains(q->scene())
            || !m_extenders[q->scene()]
            || q != m_extenders[q->scene()]->parentItem()) return;
        QRectF geometry = QRectF(QPointF(0, 0), q->size());

        // extender()->borders = Plasma::FrameSvg::AllBorders;
        borders = Plasma::FrameSvg::AllBorders;

        switch (extenderPosition) {
        case TopExtender:
            geometry.setHeight(EXTENDER_SIZE);
            geometry.moveTop(- EXTENDER_SIZE);
            // borders &= ~ Plasma::FrameSvg::TopBorder;
            // extender()->borders &= ~ Plasma::FrameSvg::BottomBorder;
            break;
        case BottomExtender:
            geometry.moveTop(geometry.bottom());
            geometry.setHeight(EXTENDER_SIZE);
            // borders &= ~ Plasma::FrameSvg::BottomBorder;
            // extender()->borders &= ~ Plasma::FrameSvg::TopBorder;
            break;
        case LeftExtender:
            geometry.setWidth(EXTENDER_SIZE);
            geometry.moveLeft(- EXTENDER_SIZE);
            // borders &= ~ Plasma::FrameSvg::LeftBorder;
            // extender()->borders &= ~ Plasma::FrameSvg::RightBorder;
            break;
        case RightExtender:
            geometry.moveLeft(geometry.right());
            geometry.setWidth(EXTENDER_SIZE);
            // borders &= ~ Plasma::FrameSvg::RightBorder;
            // extender()->borders &= ~ Plasma::FrameSvg::LeftBorder;
            break;
        case NoExtender:
            break;
        }
        extender()->setGeometry(geometry);
        extender()->setPreferredSize(geometry.size());

        // qreal left, top, right, bottom;
        // q->getContentsMargins(&left, &top, &right, &bottom);
    }
    void releaseExtender() {
        ExtenderObject * ext = extender(false);
        if (ext) {
            ext->setVisible(false);
            ext->hoverLeaveEvent(NULL);
            ext->setParentItem(NULL);
        }

        disconnectTimer();
    }
void ActivityManager::init() {
  Plasma::ToolTipManager::self()->registerWidget(this);
  extender()->setEmptyExtenderMessage(i18n("No Activities..."));
  // don't grow too much height
  extender()->setMaximumHeight(300);
  if (extender()->item("Activities") == 0) {
    // create the item
    Plasma::ExtenderItem *item = new Plasma::ExtenderItem(extender());
    // initialize the item
    initExtenderItem(item);
    // set item name and title
    item->setName("Activities");
    item->setTitle("Activities");
  }
  // connect data sources
  Plasma::DataEngine *engine = dataEngine("org.kde.activities");
  foreach (const QString source, engine->sources())
    activityAdded(source);
  // activity addition and removal
  connect(engine, SIGNAL(sourceAdded(QString)), this, SLOT(activityAdded(QString)));
  connect(engine, SIGNAL(sourceRemoved(QString)), this, SLOT(activityRemoved(QString)));
}
  /*synchronized*/Property::Pointer
  TypeExtensionManager::GetProperty(
      Object::Pointer receiver, const std::string& namespaze,
      const std::string& method, bool forcePluginActivation)
  {
    std::clock_t start= 0;
    if (Expressions::TRACING)
    start = std::clock();

    // if we call a static method than the receiver is the class object
    //Class clazz= receiver instanceof Class ? (Class)receiver : receiver.getClass();

    Property::Pointer result(new Property(receiver, namespaze, method));
    Property::Pointer cached(fPropertyCache->Get(result));
    if (!cached.isNull())
    {
      if (cached->IsValidCacheEntry(forcePluginActivation))
      {
        if (Expressions::TRACING)
        {
          BERRY_INFO << "[Type Extension] - method " <<
          receiver->ToString() << "#" << method <<
          " found in cache: " <<
          (double(std::clock() - start))/(CLOCKS_PER_SEC/1000) << " ms.";
        }
        return cached;
      }
      // The type extender isn't loaded in the cached method but can be loaded
      // now. So remove method from cache and do the normal look up so that the
      // implementation class gets loaded.
      fPropertyCache->Remove(cached);
    }
    TypeExtension::Pointer extension(this->Get(receiver->GetClassName()));
    IPropertyTester::Pointer extender(extension->FindTypeExtender(*this, namespaze, method, false /*receiver instanceof Class*/, forcePluginActivation));
    if (!extender.Cast<TypeExtension::CONTINUE_>().IsNull() || extender.IsNull())
    {
      std::string msg("Unknown method for ");
      msg.append(receiver->GetClassName());
      throw CoreException(msg, method);
    }
    result->SetPropertyTester(extender);
    fPropertyCache->Put(result);
    if (Expressions::TRACING)
    {
      BERRY_INFO << "[Type Extension] - method " <<
      typeid(receiver).name() << "#" << method <<
      " not found in cache: " <<
      (double(std::clock() - start))/(CLOCKS_PER_SEC/1000) << " ms.";
    }
    return result;
  }
    std::vector<Solution> HeuristicsSolver::solve_elem_on_generic_graph(bool smart) const {
        // std::vector<Solution> sols;
        auto local_erased = smart ? g->smart_reduce_graph(0, prob->params.p_acceleration_max_arcs_share, erased)
                                  : g->reduce_graph(prob->params.cp_acceleration_arcs_share, erased);        
        //
        // std::vector<Path> optimal_paths;
        // std::vector<ElementaryLabel> optimal_labels;
        //
        // NodeIdFunctor nf(g);
        // ArcIdFunctor af(g);
        //
        // auto vc = g->vessel_class;
        // VisitablePorts pf = prob->data.get_ports_list();
        //
        // try {
        //     boost::r_c_shortest_paths(
        //         g->graph,
        //         make_property_map<Vertex>(nf),
        //         make_property_map<Edge>(af),
        //         g->get_source_vertex().second,
        //         g->get_sink_vertex().second,
        //         optimal_paths,
        //         optimal_labels,
        //         ElementaryLabel(g, vc->capacity, vc->capacity, 0, pf),
        //         LabelExtender(local_erased),
        //         Dominance(),
        //         std::allocator<boost::r_c_shortest_paths_label<BGraph, ElementaryLabel>>(),
        //         boost::default_r_c_shortest_paths_visitor()
        //     );
        // } catch(...) {
        //     g->dump();
        //     throw;
        // }
        //
        // for(auto i = 0u; i < optimal_paths.size(); i++) {
        //     sols.push_back(
        //         Solution(optimal_paths[i], g->calculate_path_cost(optimal_paths[i]), optimal_labels[i].cost, vc, g));
        // }
        //
        // return sols;

        LabelExtender extender(local_erased);
        LabellingAlgorithm<ElementaryLabel, LabelExtender> alg(g);
        return alg.solve(g->get_source_vertex().second, g->get_sink_vertex().second, ElementaryLabel(*g, prob->data.get_ports_list()), extender);
    }
void ActivityManager::activityAdded(QString id) {
  // skip the Status source
  if (id == "Status")
    return;
  // create a new activity object
  ActivityWidget *activity = new ActivityWidget(extender()->item("Activities"), id);
  // add activity to the list
  m_activities.insert(id, activity);
  // connect activity update signal
  dataEngine("org.kde.activities")->connectSource(id, this);
  // connect activity start/stop signals
  connect(activity, SIGNAL(setCurrent(QString)), this, SLOT(setCurrent(QString)));
  connect(activity, SIGNAL(startActivity(QString)), this, SLOT(start(QString)));
  connect(activity, SIGNAL(stopActivity(QString)), this, SLOT(stop(QString)));
  connect(activity, SIGNAL(addActivity(QString)), this, SLOT(add(QString)));
  connect(activity, SIGNAL(removeActivity(QString)), this, SLOT(remove(QString)));
  connect(activity, SIGNAL(renameActivity(QString,QString)), this, SLOT(setName(QString,QString)));
}
void ActivityManager::sortActivities() {
  QGraphicsLinearLayout *layout = static_cast<QGraphicsLinearLayout *>(static_cast<QGraphicsWidget *>(extender()->item("Activities")->widget())->layout());
  // remove all activities from the layout
  while (layout->count())
    layout->removeAt(0);
  // insert all activities to a map
  QMap<QString, ActivityWidget *> activities;
  foreach (ActivityWidget *activity, m_activities.values())
    activities.insertMulti(activity->name(), activity);
  // add activities into the layout at ascending order of their names
  foreach (ActivityWidget *activity, activities.values())
    layout->addItem(activity);
}