Lagrangians of the (2+1)-dimensional KP equation with variable coefficients and cross terms