Pentax DSLRs can use their K lenses and also M42 lenses with an adapter, there's no glass involved but you have to use the lens like a preset one. It's worth getting the genuine adapter as 3rd party ones aren't usually machined as perfectly. The adapter will also allow you to fit M42 lenses to a K mount film SLR.
What features you get with film lenses on a digital body depend on the age of the lens.
SMC Pentax and Pentax-M lenses - manual focus and stop-down metering in M mode, by pressing either the green button or the exposure compensation button. You can also shoot in Av mode but the lens will be held wide open regardless of the aperture you select, in M you have control over the aperture.
Pentax-A lenses - all exposure modes with aperture ring set to A, manual focus.
Pentax-F/FA/FA-J/DFA/DA lenses - all AF, all exposure modes available, set aperture ring (if fitted) to A, lenses report focal length to body so you don't have to dial it in for shake reduction when you turn the camera on.
There is now an official adapter to use K lenses on the mirrorless Q, I have seen 3rd party ones to fit Auto 110 lenses to it. The K-01 uses the same K mount as the DSLRs but is mirrorless, ergonomics are apparently a bit of an acquired taste.