void DesktopWindow::onStickToCurrentPos(bool toggled) {
    QModelIndexList indexes = listView_->selectionModel()->selectedIndexes();
    if(!indexes.isEmpty()) {
        bool relayout(false);
        QModelIndexList::const_iterator it;
        for(it = indexes.constBegin(); it != indexes.constEnd(); ++it) {
            auto file = proxyModel_->fileInfoFromIndex(*it);
            auto name = file->name();
            if(toggled) { // remember the current custom position
                QRect itemRect = listView_->rectForIndex(*it);
                customItemPos_[name] = itemRect.topLeft();
            }
            else { // cancel custom position and perform relayout
                auto item = customItemPos_.find(name);
                if(item != customItemPos_.end()) {
                    customItemPos_.erase(item);
                    relayout = true;
                }
            }
        }
        saveItemPositions();
        if(relayout) {
            relayoutItems();
        }
    }
}
Example #2
0
void DesktopWindow::onStickToCurrentPos(bool toggled) {
  QAction* action = static_cast<QAction*>(sender());
  Fm::FileMenu* menu = static_cast<Fm::FileMenu*>(action->parent());

  QModelIndexList indexes = listView_->selectionModel()->selectedIndexes();
  if(!indexes.isEmpty()) {
    FmFileInfo* file = menu->firstFile();
    QByteArray name = fm_file_info_get_name(file);
    QModelIndex index = indexes.first();
    if(toggled) { // remember to current custom position
      QRect itemRect = listView_->rectForIndex(index);
      customItemPos_[name] = itemRect.topLeft();
      saveItemPositions();
    }
    else { // cancel custom position and perform relayout
      QHash<QByteArray, QPoint>::iterator it = customItemPos_.find(name);
      if(it != customItemPos_.end()) {
        customItemPos_.erase(it);
        saveItemPositions();
        relayoutItems();
      }
    }
  }
}