Density matrix approach for quantum free-electron lasers