Commit c1d3fd7f authored by Nikita Sirgienko's avatar Nikita Sirgienko

Fix bug with missing default values of format parameters in Command Entry,...

Fix bug with missing default values of format parameters in Command Entry, which made it impossible to reset formating parameters. Also, fix bug with save/load text color parameter, with saving forward and backward compability.
parent 3ee4cdf6
......@@ -109,6 +109,8 @@ CommandEntry::CommandEntry(Worksheet* worksheet) : WorksheetEntry(worksheet),
connect(m_commandItem, &WorksheetTextItem::receivedFocus, worksheet, &Worksheet::highlightItem);
connect(m_promptItem, &WorksheetTextItem::drag, this, &CommandEntry::startDrag);
connect(worksheet, &Worksheet::updatePrompt, this, [=]() { updatePrompt();} );
m_defaultDefaultTextColor = m_commandItem->defaultTextColor();
}
CommandEntry::~CommandEntry()
......@@ -152,11 +154,20 @@ void CommandEntry::initMenus() {
QPixmap pix(16,16);
QPainter p(&pix);
for (int i=0; i<colorsCount; ++i) {
p.fillRect(pix.rect(), colors[i]);
QAction* action = new QAction(QIcon(pix), colorNames[i], m_backgroundColorActionGroup);
for (int i=0; i<colorsCount+1; ++i) {
QAction* action;
if (i == 0) {
KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View);
p.fillRect(pix.rect(), scheme.background(KColorScheme::AlternateBackground).color());
action = new QAction(QIcon(pix), i18n("Default system color"), m_backgroundColorActionGroup);
} else {
p.fillRect(pix.rect(), colors[i-1]);
action = new QAction(QIcon(pix), colorNames[i-1], m_backgroundColorActionGroup);
}
action->setCheckable(true);
m_backgroundColorMenu->addAction(action);
if (i == 0)
action->setChecked(true);
}
//text color
......@@ -168,10 +179,18 @@ void CommandEntry::initMenus() {
m_textColorMenu->setIcon(QIcon::fromTheme(QLatin1String("format-text-color")));
for (int i=0; i<colorsCount; ++i) {
p.fillRect(pix.rect(), colors[i]);
QAction* action = new QAction(QIcon(pix), colorNames[i], m_textColorActionGroup);
QAction* action;
if (i == 0) {
p.fillRect(pix.rect(), m_defaultDefaultTextColor);
action = new QAction(QIcon(pix), i18n("Default system color"), m_textColorActionGroup);
} else {
p.fillRect(pix.rect(), colors[i-1]);
action = new QAction(QIcon(pix), colorNames[i-1], m_textColorActionGroup);
}
action->setCheckable(true);
m_textColorMenu->addAction(action);
if (i == 0)
action->setChecked(true);
}
//font
......@@ -202,6 +221,10 @@ void CommandEntry::initMenus() {
connect(action, &QAction::triggered, this, &CommandEntry::fontSelectTriggered);
m_fontMenu->addAction(action);
action = new QAction(QIcon::fromTheme(QLatin1String("preferences-desktop-font")), i18n("Reset Font to Default"));
connect(action, &QAction::triggered, this, &CommandEntry::resetFontTriggered);
m_fontMenu->addAction(action);
m_menusInitialized = true;
}
......@@ -210,7 +233,13 @@ void CommandEntry::backgroundColorChanged(QAction* action) {
if (index == -1 || index>=colorsCount)
index = 0;
m_commandItem->setBackgroundColor(colors[index]);
if (index == 0)
{
KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View);
m_commandItem->setBackgroundColor(scheme.background(KColorScheme::AlternateBackground).color());
}
else
m_commandItem->setBackgroundColor(colors[index-1]);
}
void CommandEntry::textColorChanged(QAction* action) {
......@@ -218,7 +247,12 @@ void CommandEntry::textColorChanged(QAction* action) {
if (index == -1 || index>=colorsCount)
index = 0;
m_commandItem->setDefaultTextColor(colors[index]);
if (index == 0)
{
m_commandItem->setDefaultTextColor(m_defaultDefaultTextColor);
}
else
m_commandItem->setDefaultTextColor(colors[index-1]);
}
void CommandEntry::fontBoldTriggered()
......@@ -229,6 +263,11 @@ void CommandEntry::fontBoldTriggered()
m_commandItem->setFont(font);
}
void CommandEntry::resetFontTriggered()
{
m_commandItem->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
}
void CommandEntry::fontItalicTriggered()
{
QAction* action = static_cast<QAction*>(QObject::sender());
......@@ -440,14 +479,20 @@ void CommandEntry::setContent(const QDomElement& content, const KZip& file)
{
//text color
QDomElement colorElem = textElem.firstChildElement(QLatin1String("Color"));
if (!colorElem.isNull() && !colorElem.hasAttribute(QLatin1String("compatibility")))
{
m_defaultDefaultTextColor = m_commandItem->defaultTextColor();
QColor color;
color.setRed(colorElem.attribute(QLatin1String("red")).toInt());
color.setGreen(colorElem.attribute(QLatin1String("green")).toInt());
color.setBlue(colorElem.attribute(QLatin1String("blue")).toInt());
m_commandItem->setDefaultTextColor(color);
}
//font properties
QDomElement fontElem = textElem.firstChildElement(QLatin1String("Font"));
if (!fontElem.isNull() && !fontElem.hasAttribute(QLatin1String("compatibility")))
{
QFont font;
font.setFamily(fontElem.attribute(QLatin1String("family")));
font.setPointSize(fontElem.attribute(QLatin1String("pointSize")).toInt());
......@@ -455,6 +500,7 @@ void CommandEntry::setContent(const QDomElement& content, const KZip& file)
font.setItalic(fontElem.attribute(QLatin1String("italic")).toInt());
m_commandItem->setFont(font);
}
}
setExpression(expr);
}
......@@ -636,12 +682,17 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive)
//save the text properties if they differ from default values
const QFont& font = m_commandItem->font();
if (font != QFontDatabase::systemFont(QFontDatabase::FixedFont))
const QColor& textColor = m_commandItem->defaultTextColor();
bool isFontNotDefault = font != QFontDatabase::systemFont(QFontDatabase::FixedFont);
bool isTextColorNotDefault = textColor != m_defaultDefaultTextColor;
if (isFontNotDefault || isTextColorNotDefault)
{
QDomElement textElem = doc.createElement(QLatin1String("Text"));
//font properties
QDomElement fontElem = doc.createElement(QLatin1String("Font"));
if (!isFontNotDefault)
fontElem.setAttribute(QLatin1String("compatibility"), true);
fontElem.setAttribute(QLatin1String("family"), font.family());
fontElem.setAttribute(QLatin1String("pointSize"), QString::number(font.pointSize()));
fontElem.setAttribute(QLatin1String("weight"), QString::number(font.weight()));
......@@ -649,8 +700,9 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive)
textElem.appendChild(fontElem);
//text color
const QColor& textColor = m_commandItem->defaultTextColor();
QDomElement colorElem = doc.createElement( QLatin1String("Color") );
if (!isTextColorNotDefault)
colorElem.setAttribute(QLatin1String("compatibility"), true);
colorElem.setAttribute(QLatin1String("red"), QString::number(textColor.red()));
colorElem.setAttribute(QLatin1String("green"), QString::number(textColor.green()));
colorElem.setAttribute(QLatin1String("blue"), QString::number(textColor.blue()));
......
......@@ -151,6 +151,7 @@ class CommandEntry : public WorksheetEntry
void fontIncreaseTriggered();
void fontDecreaseTriggered();
void fontSelectTriggered();
void resetFontTriggered();
void animatePromptItem();
void setMidPrompt();
......@@ -180,6 +181,7 @@ class CommandEntry : public WorksheetEntry
QActionGroup* m_backgroundColorActionGroup;
QMenu* m_backgroundColorMenu;
QActionGroup* m_textColorActionGroup;
QColor m_defaultDefaultTextColor;
QMenu* m_textColorMenu;
QMenu* m_fontMenu;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment