Queen or Queen Mother?

We have had quite a few discussions about the government and monarchy of the UK. One of our discussions has revolved around the succession of rulers. If the King dies and leaves behind a queen who is not of the royal line, what happens?
A brief answer is this, in order to keep the monarchy “pure”, only those who are a direct descendent may rule. Therefore, because the previous queen was not in the line, but her husband was, when he died she became the “Queen Mother” and her daughter, Queen Elizabeth II ruled. And, because Queen Elizabeth was in the line, and not her husband, the Duke of Edinburgh, she rules and he is called The Duke not the King.

The monarch’s oldest son becomes the Prince of Wales and the Duke of Cornwall. It then gets complicated.