Mestre to Trieste to Piran to Ljubliana is a long hike! A lot longer and slower than it looks on the map.
Unless you have a lot of time to spare, I would suggest going directly from Mestre to Ljubliana via Trieste.
A more interesting and romantic option might be to go to Gorizia via Udine, cross the Italy/Slovenia border at Nova Gorica and catch a train directly to Bled. The Nova Gorica-Bled train is a bit slow and rough and ready but brings you through some beautiful scenery.
I would not bother staying in Trieste. Its a bit of a dump and the people, in my experience, tend to be surly towards tourists.
Piran is nice in itself but may not be worth going so far out of your way for. Much better imo spending a longer time in Bled or Bohinj in the Julian Alps.