Theory:

How to derive the meaning of an idiom?
Idioms generally have a subtle and coherent meaning but do not have a literal meaning. Let us try to understand a few idioms and the basis of their formation in this unit:
Idiom
Literal meaning
Idiom meaning
Basics
A piece of cakeA pastrySimple to accomplishEating a piece of cake is a simple thing to do and be accomplished easily.
Took to heelsUse the heel part of the legRan awayUse the heel/leg to disappear quickly.
To come off with flying coloursTo emerge out with a colourful displayTo succeed with brillianceCome off means to emerge; flying and colours depict success, exuberance.
Couch potatoA vegetable on the couchSomeone who sits the whole day and barely movesA potato on the sofa/couch barely moves and stays still the whole day.
At the drop of a hatDropping a hatIn a quick move, without any second thoughtA hat when dropped, falls immediately and does not stop to think again whether it should fall.
 
Thus, idioms have been formed by usage of the set of words in various situations by different sources. It is easier to understand the meaning of the idiom if we examine its origin and try to derive it from the literal meaning.