File indexing completed on 2024-12-22 04:13:16
0001 /* 0002 * SPDX-FileCopyrightText: 2022 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #include "KisLodAvailabilityModel.h" 0007 0008 #include <lager/lenses/tuple.hpp> 0009 #include <KisZug.h> 0010 0011 namespace { 0012 KisLodAvailabilityModel::AvailabilityStatePack 0013 calcLodAvailabilityState(const KisLodAvailabilityData &data, qreal effectiveBrushSize, const KisPaintopLodLimitations &l) { 0014 KisLodAvailabilityModel::AvailabilityState state = KisLodAvailabilityModel::Available; 0015 0016 if (!l.blockers.isEmpty()) { 0017 state = KisLodAvailabilityModel::BlockedFully; 0018 } else if (data.isLodSizeThresholdSupported && 0019 effectiveBrushSize < data.lodSizeThreshold) { 0020 0021 state = KisLodAvailabilityModel::BlockedByThreshold; 0022 } else if (!l.limitations.isEmpty()) { 0023 state = KisLodAvailabilityModel::Limited; 0024 } 0025 0026 return std::make_tuple(state, l, data.isLodUserAllowed); 0027 } 0028 } 0029 0030 KisLodAvailabilityModel::KisLodAvailabilityModel(lager::cursor<KisLodAvailabilityData> _data, lager::reader<qreal> _effectiveBrushSize, lager::reader<KisPaintopLodLimitations> _lodLimitations) 0031 : data(_data) 0032 , effectiveBrushSize(_effectiveBrushSize) 0033 , lodLimitations(_lodLimitations) 0034 , LAGER_QT(isLodUserAllowed) {data[&KisLodAvailabilityData::isLodUserAllowed]} 0035 , LAGER_QT(isLodSizeThresholdSupported) {data[&KisLodAvailabilityData::isLodSizeThresholdSupported]} 0036 , LAGER_QT(lodSizeThreshold) {data[&KisLodAvailabilityData::lodSizeThreshold]} 0037 , LAGER_QT(availabilityState) {lager::with(data, effectiveBrushSize, lodLimitations).map(&calcLodAvailabilityState)} 0038 , LAGER_QT(effectiveLodAvailable) {LAGER_QT(availabilityState) 0039 .zoom(lager::lenses::first) 0040 .xform(kiszug::map_less_equal<int>(static_cast<int>(Limited)))} 0041 { 0042 data.watch(std::bind(&KisLodAvailabilityModel::sigConfigurationItemChanged, this)); 0043 }