Commit 82f12d66 authored by Renaud Guezennec's avatar Renaud Guezennec
Browse files

clang format

parent 9b31997e
/***************************************************************************
* Copyright (C) 2015 by Renaud Guezennec *
* http://www.rolisteam.org/contact *
* *
* rolisteam is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
* Copyright (C) 2015 by Renaud Guezennec *
* http://www.rolisteam.org/contact *
* *
* rolisteam is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "charactersheetbutton.h"
#include <QPainter>
#include <QMouseEvent>
#include <QJsonArray>
#include <QJsonObject>
#include <QMouseEvent>
#include <QPainter>
CharacterSheetButton::CharacterSheetButton(QPointF topleft,QGraphicsItem* parent)
: CSItem(parent)
CharacterSheetButton::CharacterSheetButton(QPointF topleft, QGraphicsItem* parent) : CSItem(parent)
{
m_rect.setTopLeft(topleft);
m_rect.setBottomRight(topleft);
m_bgColor = QColor(Qt::red);
m_textColor = QColor(Qt::white);
m_value = QStringLiteral("value %1").arg(m_count);
m_bgColor= QColor(Qt::red);
m_textColor= QColor(Qt::white);
m_value= QStringLiteral("value %1").arg(m_count);
init();
}
CharacterSheetButton::CharacterSheetButton(QGraphicsItem* parent)
: CSItem(parent)
CharacterSheetButton::CharacterSheetButton(QGraphicsItem* parent) : CSItem(parent)
{
init();
}
void CharacterSheetButton::init()
{
++m_count;
m_id = QStringLiteral("id_%1").arg(m_count);
setFlags(QGraphicsItem::ItemIsSelectable|QGraphicsItem::ItemSendsGeometryChanges|QGraphicsItem::ItemIsMovable|QGraphicsItem::ItemIsFocusable);
m_id= QStringLiteral("id_%1").arg(m_count);
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges | QGraphicsItem::ItemIsMovable
| QGraphicsItem::ItemIsFocusable);
connect(this,&CharacterSheetButton::xChanged,[=](){
emit updateNeeded(this);
});
connect(this,&CharacterSheetButton::yChanged,[=](){
emit updateNeeded(this);
});
connect(this, &CharacterSheetButton::xChanged, [=]() { emit updateNeeded(this); });
connect(this, &CharacterSheetButton::yChanged, [=]() { emit updateNeeded(this); });
}
QRectF CharacterSheetButton::boundingRect() const
{
return m_rect;
}
QVariant CharacterSheetButton::getValueFrom(CharacterSheetItem::ColumnId id,int role) const
QVariant CharacterSheetButton::getValueFrom(CharacterSheetItem::ColumnId id, int role) const
{
switch(id)
{
......@@ -100,16 +94,16 @@ void CharacterSheetButton::setValueFrom(CharacterSheetItem::ColumnId id, QVarian
switch(id)
{
case ID:
m_id = var.toString();
m_id= var.toString();
break;
case LABEL:
m_label = var.toString();
m_label= var.toString();
break;
case VALUE:
m_value = var.toString();
m_value= var.toString();
break;
case X:
m_rect.setX(var.toReal());
m_rect.setX(var.toReal());
break;
case Y:
m_rect.setY(var.toReal());
......@@ -121,7 +115,7 @@ void CharacterSheetButton::setValueFrom(CharacterSheetItem::ColumnId id, QVarian
m_rect.setHeight(var.toReal());
break;
case BORDER:
m_border = (BorderLine)var.toInt();
m_border= (BorderLine)var.toInt();
break;
case TEXT_ALIGN:
break;
......@@ -134,109 +128,105 @@ void CharacterSheetButton::setValueFrom(CharacterSheetItem::ColumnId id, QVarian
}
update();
}
void CharacterSheetButton::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
void CharacterSheetButton::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
painter->save();
painter->fillRect(m_rect,m_bgColor);
painter->drawText(m_rect,Qt::AlignCenter,m_value);
painter->fillRect(m_rect, m_bgColor);
painter->drawText(m_rect, Qt::AlignCenter, m_value);
painter->restore();
}
void CharacterSheetButton::setNewEnd(QPointF nend)
{
m_rect.setBottomRight(nend);
}
void CharacterSheetButton::save(QJsonObject &json, bool exp)
void CharacterSheetButton::save(QJsonObject& json, bool exp)
{
json["type"]="button";
json["id"]=m_id;
json["value"]=m_value;
json["label"]=m_label;
json["type"]= "button";
json["id"]= m_id;
json["value"]= m_value;
json["label"]= m_label;
QJsonObject bgcolor;
bgcolor["r"]=QJsonValue(m_bgColor.red());
bgcolor["g"]=m_bgColor.green();
bgcolor["b"]=m_bgColor.blue();
bgcolor["a"]=m_bgColor.alpha();
json["bgcolor"]=bgcolor;
bgcolor["r"]= QJsonValue(m_bgColor.red());
bgcolor["g"]= m_bgColor.green();
bgcolor["b"]= m_bgColor.blue();
bgcolor["a"]= m_bgColor.alpha();
json["bgcolor"]= bgcolor;
QJsonObject textcolor;
textcolor["r"]=m_textColor.red();
textcolor["g"]=m_textColor.green();
textcolor["b"]=m_textColor.blue();
textcolor["a"]=m_textColor.alpha();
json["textcolor"]=textcolor;
json["x"]=m_rect.x();
json["y"]=m_rect.y();
json["width"]=m_rect.width();
json["height"]=m_rect.height();
json["page"]=m_page;
textcolor["r"]= m_textColor.red();
textcolor["g"]= m_textColor.green();
textcolor["b"]= m_textColor.blue();
textcolor["a"]= m_textColor.alpha();
json["textcolor"]= textcolor;
json["x"]= m_rect.x();
json["y"]= m_rect.y();
json["width"]= m_rect.width();
json["height"]= m_rect.height();
json["page"]= m_page;
}
void CharacterSheetButton::load(QJsonObject &json, QList<QGraphicsScene*> scene)
void CharacterSheetButton::load(QJsonObject& json, QList<QGraphicsScene*> scene)
{
m_id= json["id"].toString();
m_value= json["value"].toString();
m_id = json["id"].toString();
m_value = json["value"].toString();
m_label = json["label"].toString();
QJsonObject bgcolor = json["bgcolor"].toObject();
int r,g,b,a;
r = bgcolor["r"].toInt();
g = bgcolor["g"].toInt();
b = bgcolor["b"].toInt();
a = bgcolor["a"].toInt();
m_label= json["label"].toString();
m_bgColor=QColor(r,g,b,a);
QJsonObject bgcolor= json["bgcolor"].toObject();
int r, g, b, a;
r= bgcolor["r"].toInt();
g= bgcolor["g"].toInt();
b= bgcolor["b"].toInt();
a= bgcolor["a"].toInt();
QJsonObject textcolor = json["textcolor"].toObject();
m_bgColor= QColor(r, g, b, a);
r = textcolor["r"].toInt();
g = textcolor["g"].toInt();
b = textcolor["b"].toInt();
m_textColor=QColor(r,g,b,a);
QJsonObject textcolor= json["textcolor"].toObject();
qreal x,y,w,h;
x=json["x"].toDouble();
y=json["y"].toDouble();
w=json["width"].toDouble();
h=json["height"].toDouble();
r= textcolor["r"].toInt();
g= textcolor["g"].toInt();
b= textcolor["b"].toInt();
m_textColor= QColor(r, g, b, a);
m_rect.setRect(x,y,w,h);
qreal x, y, w, h;
x= json["x"].toDouble();
y= json["y"].toDouble();
w= json["width"].toDouble();
h= json["height"].toDouble();
m_page = json["page"].toInt();
m_rect.setRect(x, y, w, h);
m_page= json["page"].toInt();
update();
}
void CharacterSheetButton::generateQML(QTextStream &out,CharacterSheetItem::QMLSection sec)
void CharacterSheetButton::generateQML(QTextStream& out, CharacterSheetItem::QMLSection sec)
{
if(sec==CharacterSheetItem::FieldSec)
if(sec == CharacterSheetItem::FieldSec)
{
out << "DiceButton {\n";
out << " id:_"<<m_id<< "\n";
out << " text: "<<m_id<<".label\n";
out << " textColor:\""<< m_textColor.name(QColor::HexArgb) <<"\"\n";
out << " x:" << m_rect.x() << "*parent.realscale"<<"\n";
out << " y:" << m_rect.y()<< "*parent.realscale"<<"\n";
out << " width:" << m_rect.width() <<"*parent.realscale"<<"\n";
out << " height:"<< m_rect.height()<<"*parent.realscale"<<"\n";
out << " color: \"" << m_bgColor.name(QColor::HexArgb)<<"\"\n";
out << " onClicked:rollDiceCmd("<<m_id<<".value)\n";
out << " id:_" << m_id << "\n";
out << " text: " << m_id << ".label\n";
out << " textColor:\"" << m_textColor.name(QColor::HexArgb) << "\"\n";
out << " x:" << m_rect.x() << "*parent.realscale"
<< "\n";
out << " y:" << m_rect.y() << "*parent.realscale"
<< "\n";
out << " width:" << m_rect.width() << "*parent.realscale"
<< "\n";
out << " height:" << m_rect.height() << "*parent.realscale"
<< "\n";
out << " color: \"" << m_bgColor.name(QColor::HexArgb) << "\"\n";
out << " onClicked:rollDiceCmd(" << m_id << ".value)\n";
out << "}\n";
}
}
CharacterSheetItem::TypeField CharacterSheetButton::getCurrentType()const
CharacterSheetItem::TypeField CharacterSheetButton::getCurrentType() const
{
return Field::BUTTON;
}
......@@ -250,31 +240,30 @@ CharacterSheetItem::CharacterSheetItemType CharacterSheetButton::getItemType() c
return CharacterSheetItem::ButtonItem;
}
void CharacterSheetButton::saveDataItem(QJsonObject &json)
void CharacterSheetButton::saveDataItem(QJsonObject& json)
{
json["type"]="button";
json["id"]=m_id;
json["label"]=m_label;
json["value"]=m_value;
json["type"]= "button";
json["id"]= m_id;
json["label"]= m_label;
json["value"]= m_value;
}
void CharacterSheetButton::loadDataItem(QJsonObject &json)
void CharacterSheetButton::loadDataItem(QJsonObject& json)
{
m_id = json["id"].toString();
m_id= json["id"].toString();
m_value= json["value"].toString();
m_label = json["label"].toString();
m_label= json["label"].toString();
}
void CharacterSheetButton::copyField(CharacterSheetItem* newBtn)
{
CharacterSheetButton* newField = dynamic_cast<CharacterSheetButton*>(newBtn);
if(nullptr!=newField)
CharacterSheetButton* newField= dynamic_cast<CharacterSheetButton*>(newBtn);
if(nullptr != newField)
{
setId(newField->getId());
//setValue(newField->value());
// setValue(newField->value());
setRect(newField->getRect());
setBgColor(newField->bgColor());
setTextColor(newField->textColor());
setLabel(newField->getLabel());
}
}
/***************************************************************************
* Copyright (C) 2015 by Renaud Guezennec *
* http://www.rolisteam.org/contact *
* *
* rolisteam is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
* Copyright (C) 2015 by Renaud Guezennec *
* http://www.rolisteam.org/contact *
* *
* rolisteam is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef CHARACTERSHEETBUTTON_H
#define CHARACTERSHEETBUTTON_H
#include <QWidget>
#include <QLabel>
#include <QGraphicsItem>
#include "charactersheetitem.h"
#include "csitem.h"
#include "field.h"
#include <QGraphicsItem>
#include <QLabel>
#include <QWidget>
/**
* @brief The CharacterSheetButton class is dedicated to manage button.
*/
class CharacterSheetButton : public CSItem
{
Q_OBJECT
Q_OBJECT
public:
CharacterSheetButton(QPointF topleft,QGraphicsItem* parent = 0);
CharacterSheetButton(QGraphicsItem* parent = 0);
CharacterSheetButton(QPointF topleft, QGraphicsItem* parent= 0);
CharacterSheetButton(QGraphicsItem* parent= 0);
virtual QVariant getValueFrom(CharacterSheetItem::ColumnId,int role) const;
virtual QVariant getValueFrom(CharacterSheetItem::ColumnId, int role) const;
virtual void setValueFrom(CharacterSheetItem::ColumnId id, QVariant var);
virtual void save(QJsonObject& json,bool exp=false);
virtual void load(const QJsonObject &json,QList<QGraphicsScene*> scene);
virtual void save(QJsonObject& json, bool exp= false);
virtual void load(const QJsonObject& json, QList<QGraphicsScene*> scene);
virtual void generateQML(QTextStream& out,CharacterSheetItem::QMLSection sec);
virtual void generateQML(QTextStream& out, CharacterSheetItem::QMLSection sec);
void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 );
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget= 0);
virtual void setNewEnd(QPointF nend);
QRectF boundingRect() const;
CharacterSheetItem::TypeField getFieldType()const;
CharacterSheetItem::TypeField getFieldType() const;
CharacterSheetItem* getChildAt(QString) const;
......@@ -67,17 +67,17 @@ public:
*/
virtual void loadDataItem(const QJsonObject& json);
void copyField(CharacterSheetItem *newField);
void copyField(CharacterSheetItem* newField);
/**
* @brief fillNetworkMessage
* @param msg
*/
//virtual void fillNetworkMessage(NetworkMessageWriter* msg);
// virtual void fillNetworkMessage(NetworkMessageWriter* msg);
/**
* @brief readNetworkMessage
* @param msg
*/
//virtual void readNetworkMessage(NetworkMessageReader* msg);
// virtual void readNetworkMessage(NetworkMessageReader* msg);
signals:
void updateNeeded(CSItem* c);
......
/***************************************************************************
* Copyright (C) 2014 by Renaud Guezennec *
* http://www.rolisteam.org/ *
* *
* This file is part of rcse *
* *
* rcse is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* rcse is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
* Copyright (C) 2014 by Renaud Guezennec *
* http://www.rolisteam.org/ *
* *
* This file is part of rcse *
* *
* rcse is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* rcse is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "charactersheetitem.h"
#include <QDebug>
#include <QTextDocument>
//////////////////////////////
//Item
// Item
/////////////////////////////
CharacterSheetItem::CharacterSheetItem()
: m_parent(nullptr),m_orig(nullptr),m_page(0),m_readOnly(false),m_hasDefaultValue(false)
: m_parent(nullptr), m_orig(nullptr), m_page(0), m_readOnly(false), m_hasDefaultValue(false)
{
}
......@@ -40,14 +40,13 @@ int CharacterSheetItem::getChildrenCount() const
return 0;
}
QVariant CharacterSheetItem::getValueFrom(CharacterSheetItem::ColumnId i,int role) const
QVariant CharacterSheetItem::getValueFrom(CharacterSheetItem::ColumnId i, int role) const
{
Q_UNUSED(i);
Q_UNUSED(role);
return QVariant();
}
bool CharacterSheetItem::isReadOnly() const
{
return m_readOnly;
......@@ -57,7 +56,7 @@ void CharacterSheetItem::setReadOnly(bool readOnly)
{
if(m_readOnly != readOnly)
{
m_readOnly = readOnly;
m_readOnly= readOnly;
emit readOnlyChanged();
emit sendOffData(this);
}
......@@ -72,7 +71,7 @@ void CharacterSheetItem::setPage(int page)
{
if(page != m_page)
{
m_page = page;
m_page= page;
emit pageChanged();
}
}
......@@ -82,54 +81,51 @@ QString CharacterSheetItem::getFormula() const
return m_formula;
}
void CharacterSheetItem::setFormula(const QString &formula)
void CharacterSheetItem::setFormula(const QString& formula)
{
m_formula = formula;
m_formula= formula;
}
CharacterSheetItem *CharacterSheetItem::getOrig() const
CharacterSheetItem* CharacterSheetItem::getOrig() const
{
return m_orig;
}
void CharacterSheetItem::setOrig(CharacterSheetItem* orig)
{
m_orig = orig;
m_orig= orig;
if(nullptr != m_orig)
{
connect(m_orig,SIGNAL(labelChanged()),this,SLOT(updateLabelFromOrigin()));
connect(m_orig, SIGNAL(labelChanged()), this, SLOT(updateLabelFromOrigin()));
}
}
void CharacterSheetItem::updateLabelFromOrigin()
{
if(nullptr!=m_orig)
if(nullptr != m_orig)
{
QString oldKey =m_label;
QString oldKey= m_label;
setLabel(m_orig->getLabel());
setLabel(m_orig->getLabel());
if(nullptr != m_parent)
{
m_parent->changeKeyChild(oldKey,m_label,this);
}
if(nullptr != m_parent)
{
m_parent->changeKeyChild(oldKey, m_label, this);
}
}
}
void CharacterSheetItem::updateNeeded()
{
}
void CharacterSheetItem::updateNeeded() {}
QString CharacterSheetItem::getTooltip() const
{
return m_tooltip;
}
void CharacterSheetItem::setTooltip(const QString &tooltip)
void CharacterSheetItem::setTooltip(const QString& tooltip)
{
m_tooltip = tooltip;
m_tooltip= tooltip;
}
void CharacterSheetItem::changeKeyChild(QString oldkey, QString newKey,CharacterSheetItem* child)
void CharacterSheetItem::changeKeyChild(QString oldkey, QString newKey, CharacterSheetItem* child)
{
Q_UNUSED(oldkey);
Q_UNUSED(newKey);
......@@ -141,30 +137,30 @@ QString CharacterSheetItem::value() const
return m_value;
}
void CharacterSheetItem::setValue(const QString &value,bool fromNetwork)
void CharacterSheetItem::setValue(const QString& value, bool fromNetwork)
{