File indexing completed on 2024-04-28 16:55:15
0001 /*************************************************************************** 0002 * Copyright (C) 2014 by Nikita Skovoroda <chalkerx@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 0018 ***************************************************************************/ 0019 0020 #include "powerdevilscreenbrightnesslogic.h" 0021 #include "powerdevil_debug.h" 0022 #include <QDebug> 0023 0024 namespace PowerDevil 0025 { 0026 0027 int ScreenBrightnessLogic::toggled() const 0028 { 0029 // ignore, we won't toggle the display off 0030 return -1; 0031 } 0032 0033 int ScreenBrightnessLogic::calculateSteps(int maxValue) const 0034 { 0035 // We assume that the preferred number of steps for screen brightness is 20, but we don't want more. 0036 0037 if (maxValue <= 20) { 0038 // Too few steps, return the number of actual steps. 0039 // Those would be uniform, but not round in some cases. 0040 return maxValue; 0041 } 0042 0043 if (maxValue >= 100 || maxValue % 20 == 0 || (maxValue >= 80 && maxValue % 4 == 0)) { 0044 // In this case all 20 steps are perfect. 0045 return 20; 0046 } 0047 0048 // At this point we have maxValue in the range 21-79 which probably is a rare case. 0049 0050 if (maxValue >= 34 || maxValue == 32 || maxValue == 28) { 0051 // In this case all 20 steps are matched +-1%, which is fine. 0052 return 20; 0053 } 0054 0055 // At this point we have maxValue in the range 21-33. 0056 // Trying to make 20 steps from here will make them not uniform. 0057 0058 if (maxValue % 5 == 0) { 0059 // For maxValue == 30 there are 10 even and round steps. 0060 // For maxValue == 25 steps are shown as 0061 // 0% 12% 20% 32% 40% 52% 60% 72% 80% 92% 100%, which is also fine. 0062 return 10; 0063 } 0064 0065 // Trying hard to find an uniform steps set 0066 for (int steps = 9; steps <= 14; steps++) { 0067 if (maxValue % steps == 0) { 0068 return steps; 0069 } 0070 } 0071 0072 // 4 different maxValue values left: 21, 23, 29, 31. 0073 // Those produce +-2% on 10 steps, there is nothing better we can do here. 0074 return 10; 0075 } 0076 0077 };