File indexing completed on 2024-05-05 17:04:25
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2012 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library 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 GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "Constants.h" 0021 0022 #include <QApplication> 0023 #include <QWidget> 0024 0025 Constants::Constants(QObject* parent) 0026 : QObject(parent) 0027 { 0028 m_gridWidth = qApp->activeWindow()->width() / gridColumns(); 0029 m_gridHeight = qApp->activeWindow()->height() / gridRows(); 0030 m_toolbarButtonSize = m_gridHeight; 0031 m_toolbarHeight = (m_gridHeight * gridRows()) / 12.55814; // magic number which /should/ yield a nice, solid 84 if we're running at 1080p 0032 } 0033 0034 int Constants::animationDuration() const 0035 { 0036 return 150; 0037 } 0038 0039 qreal Constants::gridHeight() const 0040 { 0041 return m_gridHeight; 0042 } 0043 0044 void Constants::setGridHeight( qreal height ) 0045 { 0046 m_gridHeight = height; 0047 m_toolbarButtonSize = m_gridHeight; 0048 m_toolbarHeight = (m_gridHeight * gridRows()) / 12.55814; // magic number which /should/ yield a nice, solid 84 if we're running at 1080p 0049 emit gridSizeChanged(); 0050 } 0051 0052 qreal Constants::gridWidth() const 0053 { 0054 return m_gridWidth; 0055 } 0056 0057 void Constants::setGridWidth( qreal width ) 0058 { 0059 m_gridWidth = width; 0060 m_toolbarButtonSize = m_gridHeight; 0061 m_toolbarHeight = (m_gridHeight * gridRows()) / 12.55814; // magic number which /should/ yield a nice, solid 84 if we're running at 1080p 0062 emit gridSizeChanged(); 0063 } 0064 0065 qreal Constants::toolbarButtonSize() const 0066 { 0067 return m_toolbarButtonSize; 0068 } 0069 0070 qreal Constants::toolbarHeight() const 0071 { 0072 return m_toolbarHeight; 0073 } 0074 0075 int Constants::gridRows() const 0076 { 0077 if (isLandscape()) 0078 return 12; 0079 return 18; 0080 } 0081 0082 int Constants::gridColumns() const 0083 { 0084 return 12; 0085 } 0086 0087 qreal Constants::defaultMargin() const 0088 { 0089 return 0.1 * m_gridHeight; 0090 } 0091 0092 qreal Constants::smallFontSize() const 0093 { 0094 return 0.2 * m_gridHeight; 0095 } 0096 0097 qreal Constants::defaultFontSize() const 0098 { 0099 return 0.3 * m_gridHeight; 0100 } 0101 0102 qreal Constants::largeFontSize() const 0103 { 0104 return 0.4 * m_gridHeight; 0105 } 0106 0107 qreal Constants::hugeFontSize() const 0108 { 0109 return 0.9 * m_gridHeight; 0110 } 0111 0112 bool Constants::isLandscape() const 0113 { 0114 // If user switches certain settings in windows, activeWindow can become null. 0115 if(qApp->activeWindow()) 0116 return qApp->activeWindow()->height() < qApp->activeWindow()->width(); 0117 return true; 0118 }