File indexing completed on 2024-12-15 04:51:46

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "notedisplayattribute.h"
0008 
0009 #include <QByteArray>
0010 #include <QDataStream>
0011 #include <QFontDatabase>
0012 #include <QIODevice>
0013 
0014 using namespace NoteShared;
0015 
0016 NoteDisplayAttribute::NoteDisplayAttribute()
0017     : Akonadi::Attribute()
0018     , mFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont))
0019     , mTitleFont(QFontDatabase::systemFont(QFontDatabase::TitleFont))
0020     //@krazy:cond=qenums because everyone expects yellow postit notes
0021     , mBackgroundColor(Qt::yellow)
0022     , mForegroundgroundColor(Qt::black)
0023     //@krazy:endcond=qenums
0024     , mSize(300, 300)
0025     , mPosition(QPoint(-10000, -10000))
0026     , mTabSize(4)
0027     , mDesktop(-10)
0028     , mRememberDesktop(true)
0029     , mAutoIndent(true)
0030     , mHide(false)
0031     , mShowInTaskbar(false)
0032     , mKeepAbove(false)
0033     , mKeepBelove(false)
0034     , mKeepBelow(false)
0035 {
0036 }
0037 
0038 NoteDisplayAttribute::~NoteDisplayAttribute() = default;
0039 
0040 NoteDisplayAttribute *NoteDisplayAttribute::clone() const
0041 {
0042     auto attr = new NoteDisplayAttribute();
0043     attr->setBackgroundColor(backgroundColor());
0044     attr->setForegroundColor(foregroundColor());
0045     attr->setSize(size());
0046     attr->setRememberDesktop(rememberDesktop());
0047     attr->setTabSize(tabSize());
0048     attr->setFont(font());
0049     attr->setTitleFont(titleFont());
0050     attr->setDesktop(desktop());
0051     attr->setIsHidden(isHidden());
0052     attr->setPosition(position());
0053     attr->setShowInTaskbar(showInTaskbar());
0054     attr->setKeepAbove(keepAbove());
0055     attr->setKeepBelow(keepBelow());
0056     attr->setAutoIndent(autoIndent());
0057     return attr;
0058 }
0059 
0060 void NoteDisplayAttribute::deserialize(const QByteArray &data)
0061 {
0062     QDataStream s(data);
0063     s.setVersion(QDataStream::Qt_5_11);
0064     s >> mFont;
0065     s >> mTitleFont;
0066     s >> mBackgroundColor;
0067     s >> mForegroundgroundColor;
0068     s >> mSize;
0069     s >> mPosition;
0070     s >> mTabSize;
0071     s >> mDesktop;
0072     s >> mRememberDesktop;
0073     s >> mAutoIndent;
0074     s >> mHide;
0075     s >> mShowInTaskbar;
0076     s >> mKeepAbove;
0077     s >> mKeepBelove;
0078     s >> mKeepBelow;
0079 }
0080 
0081 QByteArray NoteDisplayAttribute::serialized() const
0082 {
0083     QByteArray result;
0084     QDataStream s(&result, QIODevice::WriteOnly);
0085     s.setVersion(QDataStream::Qt_5_11);
0086     s << mFont;
0087     s << mTitleFont;
0088     s << mBackgroundColor;
0089     s << mForegroundgroundColor;
0090     s << mSize;
0091     s << mPosition;
0092     s << mTabSize;
0093     s << mDesktop;
0094     s << mRememberDesktop;
0095     s << mAutoIndent;
0096     s << mHide;
0097     s << mShowInTaskbar;
0098     s << mKeepAbove;
0099     s << mKeepBelove;
0100     s << mKeepBelow;
0101     return result;
0102 }
0103 
0104 QByteArray NoteDisplayAttribute::type() const
0105 {
0106     static const QByteArray sType("NoteDisplayAttribute");
0107     return sType;
0108 }
0109 
0110 void NoteDisplayAttribute::setBackgroundColor(const QColor &color)
0111 {
0112     mBackgroundColor = color;
0113 }
0114 
0115 QColor NoteDisplayAttribute::backgroundColor() const
0116 {
0117     return mBackgroundColor;
0118 }
0119 
0120 void NoteDisplayAttribute::setForegroundColor(const QColor &color)
0121 {
0122     mForegroundgroundColor = color;
0123 }
0124 
0125 QSize NoteDisplayAttribute::size() const
0126 {
0127     return mSize;
0128 }
0129 
0130 void NoteDisplayAttribute::setSize(const QSize &size)
0131 {
0132     mSize = size;
0133 }
0134 
0135 QColor NoteDisplayAttribute::foregroundColor() const
0136 {
0137     return mForegroundgroundColor;
0138 }
0139 
0140 bool NoteDisplayAttribute::rememberDesktop() const
0141 {
0142     return mRememberDesktop;
0143 }
0144 
0145 void NoteDisplayAttribute::setRememberDesktop(bool b)
0146 {
0147     mRememberDesktop = b;
0148 }
0149 
0150 int NoteDisplayAttribute::tabSize() const
0151 {
0152     return mTabSize;
0153 }
0154 
0155 void NoteDisplayAttribute::setTabSize(int value)
0156 {
0157     mTabSize = value;
0158 }
0159 
0160 bool NoteDisplayAttribute::autoIndent() const
0161 {
0162     return mAutoIndent;
0163 }
0164 
0165 void NoteDisplayAttribute::setAutoIndent(bool b)
0166 {
0167     mAutoIndent = b;
0168 }
0169 
0170 void NoteDisplayAttribute::setFont(const QFont &f)
0171 {
0172     mFont = f;
0173 }
0174 
0175 QFont NoteDisplayAttribute::font() const
0176 {
0177     return mFont;
0178 }
0179 
0180 void NoteDisplayAttribute::setTitleFont(const QFont &f)
0181 {
0182     mTitleFont = f;
0183 }
0184 
0185 QFont NoteDisplayAttribute::titleFont() const
0186 {
0187     return mTitleFont;
0188 }
0189 
0190 void NoteDisplayAttribute::setDesktop(int v)
0191 {
0192     mDesktop = v;
0193 }
0194 
0195 int NoteDisplayAttribute::desktop() const
0196 {
0197     return mDesktop;
0198 }
0199 
0200 void NoteDisplayAttribute::setIsHidden(bool b)
0201 {
0202     mHide = b;
0203 }
0204 
0205 bool NoteDisplayAttribute::isHidden() const
0206 {
0207     return mHide;
0208 }
0209 
0210 void NoteDisplayAttribute::setPosition(const QPoint &pos)
0211 {
0212     mPosition = pos;
0213 }
0214 
0215 QPoint NoteDisplayAttribute::position() const
0216 {
0217     return mPosition;
0218 }
0219 
0220 void NoteDisplayAttribute::setShowInTaskbar(bool b)
0221 {
0222     mShowInTaskbar = b;
0223 }
0224 
0225 bool NoteDisplayAttribute::showInTaskbar() const
0226 {
0227     return mShowInTaskbar;
0228 }
0229 
0230 void NoteDisplayAttribute::setKeepAbove(bool b)
0231 {
0232     mKeepAbove = b;
0233 }
0234 
0235 bool NoteDisplayAttribute::keepAbove() const
0236 {
0237     return mKeepAbove;
0238 }
0239 
0240 void NoteDisplayAttribute::setKeepBelow(bool b)
0241 {
0242     mKeepBelow = b;
0243 }
0244 
0245 bool NoteDisplayAttribute::keepBelow() const
0246 {
0247     return mKeepBelow;
0248 }
0249 
0250 bool NoteDisplayAttribute::operator==(const NoteDisplayAttribute &other) const
0251 {
0252     return (backgroundColor() == other.backgroundColor()) && (foregroundColor() == other.foregroundColor()) && (size() == other.size())
0253         && (rememberDesktop() == other.rememberDesktop()) && (tabSize() == other.tabSize()) && (font() == other.font()) && (titleFont() == other.titleFont())
0254         && (desktop() == other.desktop()) && (isHidden() == other.isHidden()) && (position() == other.position()) && (showInTaskbar() == other.showInTaskbar())
0255         && (keepAbove() == other.keepAbove()) && (keepBelow() == other.keepBelow()) && (autoIndent() == other.autoIndent());
0256 }