Changeset View
Changeset View
Standalone View
Standalone View
kstyle/widgets/linedit.cpp
- This file was added.
1 | #include "breezestyle.h" | ||||
---|---|---|---|---|---|
2 | | ||||
3 | namespace Breeze | ||||
4 | { | ||||
5 | //___________________________________________________________________________________________________________________ | ||||
6 | QRect Style::lineEditContentsRect(const QStyleOption *option, const QWidget *widget) const | ||||
7 | { | ||||
8 | // cast option and check | ||||
9 | const auto frameOption(qstyleoption_cast<const QStyleOptionFrame *>(option)); | ||||
10 | if (!frameOption) | ||||
11 | return option->rect; | ||||
12 | | ||||
13 | // check flatness | ||||
14 | const bool flat(frameOption->lineWidth == 0); | ||||
15 | if (flat) | ||||
16 | return option->rect; | ||||
17 | | ||||
18 | // copy rect and take out margins | ||||
19 | auto rect(option->rect); | ||||
20 | | ||||
21 | // take out margins if there is enough room | ||||
22 | const int frameWidth(pixelMetric(PM_DefaultFrameWidth, option, widget)); | ||||
23 | if (rect.height() >= option->fontMetrics.height() + 2 * frameWidth) | ||||
24 | return insideMargin(rect, frameWidth); | ||||
25 | else | ||||
26 | return rect; | ||||
27 | } | ||||
28 | | ||||
29 | //______________________________________________________________ | ||||
30 | QSize Style::lineEditSizeFromContents(const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const | ||||
31 | { | ||||
32 | // cast option and check | ||||
33 | const auto frameOption(qstyleoption_cast<const QStyleOptionFrame *>(option)); | ||||
34 | if (!frameOption) | ||||
35 | return contentsSize; | ||||
36 | | ||||
37 | const bool flat(frameOption->lineWidth == 0); | ||||
38 | const int frameWidth(pixelMetric(PM_DefaultFrameWidth, option, widget)); | ||||
39 | return flat ? contentsSize : expandSize(contentsSize, frameWidth); | ||||
40 | } | ||||
41 | | ||||
42 | //______________________________________________________________ | ||||
43 | bool Style::drawFrameLineEditPrimitive(const QStyleOption *option, QPainter *painter, const QWidget *widget) const | ||||
44 | { | ||||
45 | // copy palette and rect | ||||
46 | const auto &palette(option->palette); | ||||
47 | const auto &rect(option->rect); | ||||
48 | | ||||
49 | // make sure there is enough room to render frame | ||||
50 | if (rect.height() < 2 * Metrics::LineEdit_FrameWidth + option->fontMetrics.height()) { | ||||
51 | const auto &background = palette.color(QPalette::Base); | ||||
52 | | ||||
53 | painter->setPen(Qt::NoPen); | ||||
54 | painter->setBrush(background); | ||||
55 | painter->drawRect(rect); | ||||
56 | return true; | ||||
57 | | ||||
58 | } else { | ||||
59 | // copy state | ||||
60 | const State &state(option->state); | ||||
61 | const bool enabled(state & State_Enabled); | ||||
62 | const bool mouseOver(enabled && (state & State_MouseOver)); | ||||
63 | const bool hasFocus(enabled && (state & State_HasFocus)); | ||||
64 | | ||||
65 | // focus takes precedence over mouse over | ||||
66 | _animations->inputWidgetEngine().updateState(widget, AnimationFocus, hasFocus); | ||||
67 | _animations->inputWidgetEngine().updateState(widget, AnimationHover, mouseOver && !hasFocus); | ||||
68 | | ||||
69 | // retrieve animation mode and opacity | ||||
70 | const AnimationMode mode(_animations->inputWidgetEngine().frameAnimationMode(widget)); | ||||
71 | const qreal opacity(_animations->inputWidgetEngine().frameOpacity(widget)); | ||||
72 | | ||||
73 | // render | ||||
74 | const auto &background = palette.color(QPalette::Base); | ||||
75 | const auto outline(_helper->frameOutlineColor(palette, mouseOver, hasFocus, opacity, mode)); | ||||
76 | _helper->renderFrame(painter, rect, background, outline); | ||||
77 | } | ||||
78 | | ||||
79 | return true; | ||||
80 | } | ||||
81 | | ||||
82 | } |