Ignore:
Timestamp:
Sep 8, 2013, 7:03:25 PM (10 years ago)
Author:
jordan
Message:

(trunk, qt) #4813: allow launching files in Qt interface

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/qt/file-tree.cc

    r14185 r14196  
    381381}
    382382
     383QString
     384FileTreeItem :: path () const
     385{
     386  QString itemPath;
     387  const FileTreeItem * item = this;
     388
     389  while (item != NULL && !item->name().isEmpty())
     390    {
     391      if (itemPath.isEmpty())
     392        itemPath = item->name();
     393      else
     394        itemPath = item->name() + "/" + itemPath;
     395      item = item->parent ();
     396    }
     397
     398  return itemPath;
     399}
     400
     401bool
     402FileTreeItem :: isComplete () const
     403{
     404  return myHaveSize == totalSize ();
     405}
     406
    383407/***
    384408****
     
    436460  if (role == Qt::EditRole)
    437461    {
    438       QString oldpath;
    439462      FileTreeItem * item = itemFromIndex (index);
    440463
    441       while (item && !item->name().isEmpty())
    442         {
    443           if (oldpath.isEmpty())
    444             oldpath = item->name();
    445           else
    446             oldpath = item->name() + "/" + oldpath;
    447           item = item->parent ();
    448         }
    449 
    450       emit pathEdited (oldpath, newname.toString());
     464      emit pathEdited (item->path (), newname.toString ());
    451465    }
    452466
     
    738752      subtreeChanged(index, column);
    739753    }
     754}
     755
     756void
     757FileTreeModel :: doubleClicked (const QModelIndex& index)
     758{
     759  if (!index.isValid())
     760    return;
     761
     762  const int column (index.column());
     763  if (column == COL_WANTED || column == COL_PRIORITY)
     764    return;
     765
     766  FileTreeItem * item = itemFromIndex (index);
     767
     768  if (item->childCount () == 0 && item->isComplete ())
     769    emit openRequested (item->path ());
    740770}
    741771
     
    897927           this, SLOT(onClicked(const QModelIndex&)));
    898928
     929  connect (this, SIGNAL(doubleClicked(const QModelIndex&)),
     930           this, SLOT(onDoubleClicked(const QModelIndex&)));
     931
    899932  connect (&myModel, SIGNAL(priorityChanged(const QSet<int>&, int)),
    900933           this,     SIGNAL(priorityChanged(const QSet<int>&, int)));
     
    905938  connect (&myModel, SIGNAL(pathEdited(const QString&, const QString&)),
    906939           this,     SIGNAL(pathEdited(const QString&, const QString&)));
     940
     941  connect (&myModel, SIGNAL (openRequested (const QString&)),
     942           this,     SLOT (onOpenRequested (const QString&)),
     943           Qt::QueuedConnection);
    907944}
    908945
     
    917954  const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
    918955  myModel.clicked (modelIndex);
     956}
     957
     958void
     959FileTreeView :: onDoubleClicked (const QModelIndex& proxyIndex)
     960{
     961  const QModelIndex modelIndex = myProxy->mapToSource (proxyIndex);
     962  myModel.doubleClicked (modelIndex);
     963}
     964
     965void
     966FileTreeView :: onOpenRequested (const QString& path)
     967{
     968  if (state () == EditingState)
     969    return;
     970
     971  emit openRequested (path);
    919972}
    920973
Note: See TracChangeset for help on using the changeset viewer.