Warning, file /graphics/tikzkit/src/ui/propertybrowser/OpacityPropertyManager.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the TikZKit project. 0002 * 0003 * Copyright (C) 2014 Dominik Haumann <dhaumann@kde.org> 0004 * 0005 * This library is free software; you can redistribute it and/or modify 0006 * it under the terms of the GNU Library General Public License as published 0007 * by the Free Software Foundation, either version 2 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, see 0017 * <http://www.gnu.org/licenses/>. 0018 */ 0019 0020 #include "OpacityPropertyManager.h" 0021 0022 #include <QDebug> 0023 0024 namespace tikz { 0025 namespace ui { 0026 0027 class OpacityPropertyManagerPrivate 0028 { 0029 public: 0030 struct Data 0031 { 0032 qreal val = 1.0; 0033 bool readOnly = false; 0034 }; 0035 0036 typedef QMap<const QtProperty *, Data> PropertyValueMap; 0037 PropertyValueMap m_values; 0038 }; 0039 0040 OpacityPropertyManager::OpacityPropertyManager(QObject *parent) 0041 : QtAbstractPropertyManager(parent) 0042 , d_ptr(new OpacityPropertyManagerPrivate()) 0043 { 0044 } 0045 0046 OpacityPropertyManager::~OpacityPropertyManager() 0047 { 0048 clear(); 0049 delete d_ptr; 0050 } 0051 0052 qreal OpacityPropertyManager::value(const QtProperty *property) const 0053 { 0054 const auto it = d_ptr->m_values.constFind(property); 0055 if (it == d_ptr->m_values.constEnd()) 0056 return qreal(0); 0057 return it.value().val; 0058 } 0059 0060 bool OpacityPropertyManager::isReadOnly(const QtProperty *property) const 0061 { 0062 const auto it = d_ptr->m_values.constFind(property); 0063 if (it == d_ptr->m_values.constEnd()) 0064 return false; 0065 return it.value().readOnly; 0066 } 0067 0068 QString OpacityPropertyManager::valueText(const QtProperty *property) const 0069 { 0070 const auto it = d_ptr->m_values.constFind(property); 0071 if (it == d_ptr->m_values.constEnd()) 0072 return QString(); 0073 return QString::number(qRound(it.value().val * 100.0)) + QLatin1Char('%'); 0074 } 0075 0076 void OpacityPropertyManager::setValue(QtProperty *property, qreal val) 0077 { 0078 const auto it = d_ptr->m_values.find(property); 0079 if (it == d_ptr->m_values.end()) 0080 return; 0081 0082 auto & data = it.value(); 0083 0084 if (data.val == val) 0085 return; 0086 0087 const qreal oldVal = data.val; 0088 data.val = val < 0.0 ? 0.0 0089 : val > 1.0 ? 1.0 0090 : val; 0091 0092 if (data.val == oldVal) 0093 return; 0094 0095 qDebug() << "emiting new value:" << data.val; 0096 Q_EMIT propertyChanged(property); 0097 Q_EMIT valueChanged(property, data.val); 0098 } 0099 0100 void OpacityPropertyManager::setReadOnly(QtProperty *property, bool readOnly) 0101 { 0102 const auto it = d_ptr->m_values.find(property); 0103 if (it == d_ptr->m_values.end()) 0104 return; 0105 0106 OpacityPropertyManagerPrivate::Data data = it.value(); 0107 0108 if (data.readOnly == readOnly) 0109 return; 0110 0111 data.readOnly = readOnly; 0112 it.value() = data; 0113 0114 Q_EMIT propertyChanged(property); 0115 Q_EMIT readOnlyChanged(property, data.readOnly); 0116 } 0117 0118 void OpacityPropertyManager::initializeProperty(QtProperty *property) 0119 { 0120 d_ptr->m_values[property] = OpacityPropertyManagerPrivate::Data(); 0121 } 0122 0123 0124 void OpacityPropertyManager::uninitializeProperty(QtProperty *property) 0125 { 0126 d_ptr->m_values.remove(property); 0127 } 0128 0129 } 0130 } 0131 0132 // kate: indent-width 4; replace-tabs on;