Changeset View
Changeset View
Standalone View
Standalone View
daemon/powerdevilbrightnesslogic.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 43 | int BrightnessLogic::action(BrightnessKeyType type) const { | |||
---|---|---|---|---|---|
51 | } | 51 | } | ||
52 | 52 | | |||
53 | return -1; // We shouldn't get here | 53 | return -1; // We shouldn't get here | ||
54 | } | 54 | } | ||
55 | 55 | | |||
56 | int BrightnessLogic::increased() const | 56 | int BrightnessLogic::increased() const | ||
57 | { | 57 | { | ||
58 | if (m_value == m_valueMax) { | 58 | if (m_value == m_valueMax) { | ||
59 | return -1; // ignore, we are at the maximum | 59 | return m_valueMax; // we are at the maximum already | ||
60 | } | 60 | } | ||
61 | 61 | | |||
62 | // Add 1 and round upwards to the nearest step | 62 | // Add 1 and round upwards to the nearest step | ||
63 | int step = m_steps - (m_valueMax - m_value - 1) * m_steps / m_valueMax; | 63 | int step = m_steps - (m_valueMax - m_value - 1) * m_steps / m_valueMax; | ||
64 | 64 | | |||
65 | if (m_valueMax > 100 && qRound(percentage(stepToValue(step))) <= qRound(percentage(m_value))) { | 65 | if (m_valueMax > 100 && qRound(percentage(stepToValue(step))) <= qRound(percentage(m_value))) { | ||
66 | // When no visible change was made, add 1 step. | 66 | // When no visible change was made, add 1 step. | ||
67 | // This can happen only if valueMax > 100, else 1 >= 1%. | 67 | // This can happen only if valueMax > 100, else 1 >= 1%. | ||
68 | step++; | 68 | step++; | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | return stepToValue(step); | 71 | return stepToValue(step); | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | int BrightnessLogic::decreased() const | 74 | int BrightnessLogic::decreased() const | ||
75 | { | 75 | { | ||
76 | if (m_value == 0) { | 76 | if (m_value == 0) { | ||
77 | return -1; // ignore, we are at the minimum | 77 | return 0; // we are at the minimum already | ||
78 | } | 78 | } | ||
79 | 79 | | |||
80 | // Subtract 1 and round downwards to the nearest Step | 80 | // Subtract 1 and round downwards to the nearest Step | ||
81 | int step = (m_value - 1) * m_steps / m_valueMax; | 81 | int step = (m_value - 1) * m_steps / m_valueMax; | ||
82 | 82 | | |||
83 | if (m_valueMax > 100 && qRound(percentage(stepToValue(step))) >= qRound(percentage(m_value))) { | 83 | if (m_valueMax > 100 && qRound(percentage(stepToValue(step))) >= qRound(percentage(m_value))) { | ||
84 | // When no visible change was made, subtract 1 step. | 84 | // When no visible change was made, subtract 1 step. | ||
85 | // This can happen only if valueMax > 100, else 1 >= 1%. | 85 | // This can happen only if valueMax > 100, else 1 >= 1%. | ||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |