File indexing completed on 2024-04-28 09:25:26

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "viewdata.h"
0007 
0008 namespace Latte {
0009 namespace Data {
0010 
0011 const int View::ISCLONEDNULL = -1;
0012 
0013 View::View()
0014     : Generic()
0015 {
0016 }
0017 
0018 View::View(View &&o)
0019     : Generic(o),
0020       isActive(o.isActive),
0021       isMoveOrigin(o.isMoveOrigin),
0022       isMoveDestination(o.isMoveDestination),
0023       onPrimary(o.onPrimary),
0024       isClonedFrom(o.isClonedFrom),
0025       screen(o.screen),
0026       screenEdgeMargin(o.screenEdgeMargin),
0027       screensGroup(o.screensGroup),
0028       maxLength(o.maxLength),
0029       edge(o.edge),
0030       alignment(o.alignment),
0031       m_state(o.m_state),
0032       m_originFile(o.m_originFile),
0033       m_originLayout(o.m_originLayout),
0034       m_originView(o.m_originView),
0035       errors(o.errors),
0036       warnings(o.warnings),
0037       subcontainments(o.subcontainments)
0038 {
0039 }
0040 
0041 View::View(const View &o)
0042     : Generic(o),
0043       isActive(o.isActive),
0044       isMoveOrigin(o.isMoveOrigin),
0045       isMoveDestination(o.isMoveDestination),
0046       onPrimary(o.onPrimary),
0047       isClonedFrom(o.isClonedFrom),
0048       screen(o.screen),
0049       screenEdgeMargin(o.screenEdgeMargin),
0050       screensGroup(o.screensGroup),
0051       maxLength(o.maxLength),
0052       edge(o.edge),
0053       alignment(o.alignment),
0054       m_state(o.m_state),
0055       m_originFile(o.m_originFile),
0056       m_originLayout(o.m_originLayout),
0057       m_originView(o.m_originView),
0058       errors(o.errors),
0059       warnings(o.warnings),
0060       subcontainments(o.subcontainments)
0061 {
0062 }
0063 
0064 View::View(const QString &newid, const QString &newname)
0065     : Generic(newid, newname)
0066 {
0067 }
0068 
0069 View &View::operator=(const View &rhs)
0070 {
0071     id = rhs.id;
0072     name = rhs.name;
0073     isActive = rhs.isActive;
0074     isMoveOrigin = rhs.isMoveOrigin;
0075     isMoveDestination = rhs.isMoveDestination;
0076     onPrimary = rhs.onPrimary;
0077     isClonedFrom = rhs.isClonedFrom;
0078     screen = rhs.screen;
0079     screenEdgeMargin = rhs.screenEdgeMargin;
0080     screensGroup = rhs.screensGroup;
0081     maxLength = rhs.maxLength;
0082     edge = rhs.edge;
0083     alignment = rhs.alignment;
0084     m_state = rhs.m_state;
0085     m_originFile = rhs.m_originFile;
0086     m_originLayout = rhs.m_originLayout;
0087     m_originView = rhs.m_originView;
0088     errors = rhs.errors;
0089     warnings = rhs.warnings;
0090 
0091     subcontainments = rhs.subcontainments;
0092 
0093     return (*this);
0094 }
0095 
0096 View &View::operator=(View &&rhs)
0097 {
0098     id = rhs.id;
0099     name = rhs.name;
0100     isActive = rhs.isActive;
0101     isMoveOrigin = rhs.isMoveOrigin;
0102     isMoveDestination = rhs.isMoveDestination;
0103     onPrimary = rhs.onPrimary;
0104     isClonedFrom = rhs.isClonedFrom;
0105     screen = rhs.screen;
0106     screenEdgeMargin = rhs.screenEdgeMargin;
0107     screensGroup = rhs.screensGroup;
0108     maxLength = rhs.maxLength;
0109     edge = rhs.edge;
0110     alignment = rhs.alignment;
0111     m_state = rhs.m_state;
0112     m_originFile = rhs.m_originFile;
0113     m_originLayout = rhs.m_originLayout;
0114     m_originView = rhs.m_originView;
0115     errors = rhs.errors;
0116     warnings = rhs.warnings;
0117 
0118     subcontainments = rhs.subcontainments;
0119 
0120     return (*this);
0121 }
0122 
0123 bool View::operator==(const View &rhs) const
0124 {
0125     return (id == rhs.id)
0126             && (name == rhs.name)
0127             //&& (isActive == rhs.isActive) /*Disabled because this is not needed in order to track view changes for saving*/
0128             //&& (isMoveOrigin == rhs.isMoveOrigin) /*Disabled because this is not needed in order to track view changes for saving*/
0129             //&& (isMoveDestination == rhs.isMoveDestination) /*Disabled because this is not needed in order to track view changes for saving*/
0130             && (onPrimary == rhs.onPrimary)
0131             && (isClonedFrom == rhs.isClonedFrom)
0132             && (screen == rhs.screen)
0133             && (screenEdgeMargin == rhs.screenEdgeMargin)
0134             && (screensGroup == rhs.screensGroup)
0135             && (maxLength == rhs.maxLength)
0136             && (edge == rhs.edge)
0137             && (alignment == rhs.alignment)
0138             && (m_state == rhs.m_state)
0139             && (m_originFile == rhs.m_originFile)
0140             && (m_originLayout == rhs.m_originLayout)
0141             && (m_originView == rhs.m_originView)
0142             //&& (errors == rhs.errors) /*Disabled because this is not needed in order to track view changes for saving*/
0143             //&& (warnings == rhs.warnings) /*Disabled because this is not needed in order to track view changes for saving*/
0144             && (subcontainments == rhs.subcontainments);
0145 }
0146 
0147 bool View::operator!=(const View &rhs) const
0148 {
0149     return !(*this == rhs);
0150 }
0151 
0152 View::operator QString() const
0153 {
0154     QString result;
0155 
0156     result += id;
0157     result +=" : ";
0158     result += isActive ? "Active" : "Inactive";
0159     result +=" : ";
0160     if (m_state==OriginFromLayout && isMoveOrigin) {
0161         result += " ↑ ";
0162     } else if (m_state==OriginFromLayout && isMoveDestination) {
0163         result += " ↓ ";
0164     } else if (m_state==OriginFromLayout && isMoveOrigin && isMoveDestination) {
0165         result += " ↑↓ ";
0166     } else {
0167         result += " - ";
0168     }
0169 
0170     result += " : ";
0171 
0172     if (m_state == IsInvalid) {
0173         result += "IsInvalid";
0174     } else if (m_state == IsCreated) {
0175         result += "IsCreated";
0176     } else if (m_state == OriginFromViewTemplate) {
0177         result += "OriginFromViewTemplate";
0178     } else if (m_state == OriginFromLayout) {
0179         result += "OriginFromLayout";
0180     }
0181 
0182     result += " : ";
0183     if (isCloned()) {
0184         result += ("Cloned from:"+ isClonedFrom);
0185     } else {
0186         result += "Original";
0187     }
0188 
0189     result += " : ";
0190     if (screensGroup == Latte::Types::SingleScreenGroup) {
0191         result += onPrimary ? "Primary" : "Explicit";
0192     } else if (screensGroup == Latte::Types::AllScreensGroup) {
0193         result += "All Screens";
0194     } else if (screensGroup == Latte::Types::AllSecondaryScreensGroup) {
0195         result += "All Secondary Screens";
0196     }
0197 
0198     result += onPrimary ? "Primary" : "Explicit";
0199     result += " : ";
0200     result += QString::number(screen);
0201     result += " : ";
0202     if (edge == Plasma::Types::BottomEdge) {
0203         result += "BottomEdge";
0204     } else if (edge == Plasma::Types::TopEdge) {
0205         result += "TopEdge";
0206     } else if (edge == Plasma::Types::LeftEdge) {
0207         result += "LeftEdge";
0208     } else if (edge == Plasma::Types::RightEdge) {
0209         result += "RightEdge";
0210     }
0211 
0212     result += " : ";
0213 
0214     if (alignment == Latte::Types::Center) {
0215         result += "CenterAlignment";
0216     } else if (alignment == Latte::Types::Left) {
0217         result += "LeftAlignment";
0218     } else if (alignment == Latte::Types::Right) {
0219         result += "RightAlignment";
0220     } else if (alignment == Latte::Types::Top) {
0221         result += "TopAlignment";
0222     } else if (alignment == Latte::Types::Bottom) {
0223         result += "BottomAlignment";
0224     } else if (alignment == Latte::Types::Justify) {
0225         result += "JustifyAlignment";
0226     }
0227 
0228     result += " : ";
0229     result += QString::number(maxLength) + "%";
0230 
0231     result += " || ";
0232     result += "{" + subcontainments + "}";
0233 
0234     return result;
0235 }
0236 
0237 bool View::isCreated() const
0238 {
0239     return m_state == IsCreated;
0240 }
0241 
0242 bool View::isOriginal() const
0243 {
0244     return !isCloned();
0245 }
0246 
0247 bool View::isCloned() const
0248 {
0249     return isClonedFrom != ISCLONEDNULL;
0250 }
0251 
0252 bool View::isValid() const
0253 {
0254     return m_state != IsInvalid;
0255 }
0256 
0257 bool View::isHorizontal() const
0258 {
0259     return !isVertical();
0260 }
0261 
0262 bool View::isVertical() const
0263 {
0264     return (edge == Plasma::Types::LeftEdge || edge == Plasma::Types::RightEdge);
0265 }
0266 
0267 bool View::hasViewTemplateOrigin() const
0268 {
0269     return m_state == OriginFromViewTemplate;
0270 }
0271 
0272 bool View::hasLayoutOrigin() const
0273 {
0274     return m_state == OriginFromLayout;
0275 }
0276 
0277 bool View::hasSubContainment(const QString &subId) const
0278 {
0279     return subcontainments.containsId(subId);
0280 }
0281 
0282 QString View::originFile() const
0283 {
0284     return m_originFile;
0285 }
0286 
0287 QString View::originLayout() const
0288 {
0289     return m_originLayout;
0290 }
0291 
0292 QString View::originView() const
0293 {
0294     return m_originView;
0295 }
0296 
0297 View::State View::state() const
0298 {
0299     return m_state;
0300 }
0301 
0302 void View::setState(View::State state, QString file, QString layout, QString view)
0303 {
0304     m_state = state;
0305     m_originFile = file;
0306     m_originLayout = layout;
0307     m_originView = view;
0308 }
0309 
0310 }
0311 }