A semi-analytic model for the co-evolution of galaxies, black holes and active galactic nuclei