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), ...@@ -109,6 +109,8 @@ CommandEntry::CommandEntry(Worksheet* worksheet) : WorksheetEntry(worksheet),
connect(m_commandItem, &WorksheetTextItem::receivedFocus, worksheet, &Worksheet::highlightItem); connect(m_commandItem, &WorksheetTextItem::receivedFocus, worksheet, &Worksheet::highlightItem);
connect(m_promptItem, &WorksheetTextItem::drag, this, &CommandEntry::startDrag); connect(m_promptItem, &WorksheetTextItem::drag, this, &CommandEntry::startDrag);
connect(worksheet, &Worksheet::updatePrompt, this, [=]() { updatePrompt();} ); connect(worksheet, &Worksheet::updatePrompt, this, [=]() { updatePrompt();} );
m_defaultDefaultTextColor = m_commandItem->defaultTextColor();
} }
CommandEntry::~CommandEntry() CommandEntry::~CommandEntry()
...@@ -150,14 +152,23 @@ void CommandEntry::initMenus() { ...@@ -150,14 +152,23 @@ void CommandEntry::initMenus() {
m_backgroundColorMenu = new QMenu(i18n("Background Color")); m_backgroundColorMenu = new QMenu(i18n("Background Color"));
m_backgroundColorMenu->setIcon(QIcon::fromTheme(QLatin1String("format-fill-color"))); m_backgroundColorMenu->setIcon(QIcon::fromTheme(QLatin1String("format-fill-color")));
QPixmap pix(16,16); QPixmap pix(16,16);
QPainter p(&pix); QPainter p(&pix);
for (int i=0; i<colorsCount; ++i) { for (int i=0; i<colorsCount+1; ++i) {
p.fillRect(pix.rect(), colors[i]); QAction* action;
QAction* action = new QAction(QIcon(pix), colorNames[i], m_backgroundColorActionGroup); if (i == 0) {
action->setCheckable(true); KColorScheme scheme = KColorScheme(QPalette::Normal, KColorScheme::View);
m_backgroundColorMenu->addAction(action); 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 //text color
m_textColorActionGroup = new QActionGroup(this); m_textColorActionGroup = new QActionGroup(this);
...@@ -168,14 +179,22 @@ void CommandEntry::initMenus() { ...@@ -168,14 +179,22 @@ void CommandEntry::initMenus() {
m_textColorMenu->setIcon(QIcon::fromTheme(QLatin1String("format-text-color"))); m_textColorMenu->setIcon(QIcon::fromTheme(QLatin1String("format-text-color")));
for (int i=0; i<colorsCount; ++i) { for (int i=0; i<colorsCount; ++i) {
p.fillRect(pix.rect(), colors[i]); QAction* action;
QAction* action = new QAction(QIcon(pix), colorNames[i], m_textColorActionGroup); if (i == 0) {
action->setCheckable(true); p.fillRect(pix.rect(), m_defaultDefaultTextColor);
m_textColorMenu->addAction(action); action = new QAction(QIcon(pix), i18n("Default system color"), m_textColorActionGroup);
} } else {
p.fillRect(pix.rect(), colors[i-1]);
//font action = new QAction(QIcon(pix), colorNames[i-1], m_textColorActionGroup);
m_fontMenu = new QMenu(i18n("Font")); }
action->setCheckable(true);
m_textColorMenu->addAction(action);
if (i == 0)
action->setChecked(true);
}
//font
m_fontMenu = new QMenu(i18n("Font"));
m_fontMenu->setIcon(QIcon::fromTheme(QLatin1String("preferences-desktop-font"))); m_fontMenu->setIcon(QIcon::fromTheme(QLatin1String("preferences-desktop-font")));
QAction* action = new QAction(QIcon::fromTheme(QLatin1String("format-text-bold")), i18n("Bold")); QAction* action = new QAction(QIcon::fromTheme(QLatin1String("format-text-bold")), i18n("Bold"));
...@@ -202,6 +221,10 @@ void CommandEntry::initMenus() { ...@@ -202,6 +221,10 @@ void CommandEntry::initMenus() {
connect(action, &QAction::triggered, this, &CommandEntry::fontSelectTriggered); connect(action, &QAction::triggered, this, &CommandEntry::fontSelectTriggered);
m_fontMenu->addAction(action); 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; m_menusInitialized = true;
} }
...@@ -210,7 +233,13 @@ void CommandEntry::backgroundColorChanged(QAction* action) { ...@@ -210,7 +233,13 @@ void CommandEntry::backgroundColorChanged(QAction* action) {
if (index == -1 || index>=colorsCount) if (index == -1 || index>=colorsCount)
index = 0; 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) { void CommandEntry::textColorChanged(QAction* action) {
...@@ -218,7 +247,12 @@ void CommandEntry::textColorChanged(QAction* action) { ...@@ -218,7 +247,12 @@ void CommandEntry::textColorChanged(QAction* action) {
if (index == -1 || index>=colorsCount) if (index == -1 || index>=colorsCount)
index = 0; 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() void CommandEntry::fontBoldTriggered()
...@@ -229,6 +263,11 @@ void CommandEntry::fontBoldTriggered() ...@@ -229,6 +263,11 @@ void CommandEntry::fontBoldTriggered()
m_commandItem->setFont(font); m_commandItem->setFont(font);
} }
void CommandEntry::resetFontTriggered()
{
m_commandItem->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
}
void CommandEntry::fontItalicTriggered() void CommandEntry::fontItalicTriggered()
{ {
QAction* action = static_cast<QAction*>(QObject::sender()); QAction* action = static_cast<QAction*>(QObject::sender());
...@@ -440,20 +479,27 @@ void CommandEntry::setContent(const QDomElement& content, const KZip& file) ...@@ -440,20 +479,27 @@ void CommandEntry::setContent(const QDomElement& content, const KZip& file)
{ {
//text color //text color
QDomElement colorElem = textElem.firstChildElement(QLatin1String("Color")); QDomElement colorElem = textElem.firstChildElement(QLatin1String("Color"));
QColor color; if (!colorElem.isNull() && !colorElem.hasAttribute(QLatin1String("compatibility")))
color.setRed(colorElem.attribute(QLatin1String("red")).toInt()); {
color.setGreen(colorElem.attribute(QLatin1String("green")).toInt()); m_defaultDefaultTextColor = m_commandItem->defaultTextColor();
color.setBlue(colorElem.attribute(QLatin1String("blue")).toInt()); QColor color;
m_commandItem->setDefaultTextColor(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 //font properties
QDomElement fontElem = textElem.firstChildElement(QLatin1String("Font")); QDomElement fontElem = textElem.firstChildElement(QLatin1String("Font"));
QFont font; if (!fontElem.isNull() && !fontElem.hasAttribute(QLatin1String("compatibility")))
font.setFamily(fontElem.attribute(QLatin1String("family"))); {
font.setPointSize(fontElem.attribute(QLatin1String("pointSize")).toInt()); QFont font;
font.setWeight(fontElem.attribute(QLatin1String("weight")).toInt()); font.setFamily(fontElem.attribute(QLatin1String("family")));
font.setItalic(fontElem.attribute(QLatin1String("italic")).toInt()); font.setPointSize(fontElem.attribute(QLatin1String("pointSize")).toInt());
m_commandItem->setFont(font); font.setWeight(fontElem.attribute(QLatin1String("weight")).toInt());
font.setItalic(fontElem.attribute(QLatin1String("italic")).toInt());
m_commandItem->setFont(font);
}
} }
setExpression(expr); setExpression(expr);
...@@ -636,12 +682,17 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive) ...@@ -636,12 +682,17 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive)
//save the text properties if they differ from default values //save the text properties if they differ from default values
const QFont& font = m_commandItem->font(); 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")); QDomElement textElem = doc.createElement(QLatin1String("Text"));
//font properties //font properties
QDomElement fontElem = doc.createElement(QLatin1String("Font")); QDomElement fontElem = doc.createElement(QLatin1String("Font"));
if (!isFontNotDefault)
fontElem.setAttribute(QLatin1String("compatibility"), true);
fontElem.setAttribute(QLatin1String("family"), font.family()); fontElem.setAttribute(QLatin1String("family"), font.family());
fontElem.setAttribute(QLatin1String("pointSize"), QString::number(font.pointSize())); fontElem.setAttribute(QLatin1String("pointSize"), QString::number(font.pointSize()));
fontElem.setAttribute(QLatin1String("weight"), QString::number(font.weight())); fontElem.setAttribute(QLatin1String("weight"), QString::number(font.weight()));
...@@ -649,8 +700,9 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive) ...@@ -649,8 +700,9 @@ QDomElement CommandEntry::toXml(QDomDocument& doc, KZip* archive)
textElem.appendChild(fontElem); textElem.appendChild(fontElem);
//text color //text color
const QColor& textColor = m_commandItem->defaultTextColor();
QDomElement colorElem = doc.createElement( QLatin1String("Color") ); QDomElement colorElem = doc.createElement( QLatin1String("Color") );
if (!isTextColorNotDefault)
colorElem.setAttribute(QLatin1String("compatibility"), true);
colorElem.setAttribute(QLatin1String("red"), QString::number(textColor.red())); colorElem.setAttribute(QLatin1String("red"), QString::number(textColor.red()));
colorElem.setAttribute(QLatin1String("green"), QString::number(textColor.green())); colorElem.setAttribute(QLatin1String("green"), QString::number(textColor.green()));
colorElem.setAttribute(QLatin1String("blue"), QString::number(textColor.blue())); colorElem.setAttribute(QLatin1String("blue"), QString::number(textColor.blue()));
......
...@@ -151,6 +151,7 @@ class CommandEntry : public WorksheetEntry ...@@ -151,6 +151,7 @@ class CommandEntry : public WorksheetEntry
void fontIncreaseTriggered(); void fontIncreaseTriggered();
void fontDecreaseTriggered(); void fontDecreaseTriggered();
void fontSelectTriggered(); void fontSelectTriggered();
void resetFontTriggered();
void animatePromptItem(); void animatePromptItem();
void setMidPrompt(); void setMidPrompt();
...@@ -180,6 +181,7 @@ class CommandEntry : public WorksheetEntry ...@@ -180,6 +181,7 @@ class CommandEntry : public WorksheetEntry
QActionGroup* m_backgroundColorActionGroup; QActionGroup* m_backgroundColorActionGroup;
QMenu* m_backgroundColorMenu; QMenu* m_backgroundColorMenu;
QActionGroup* m_textColorActionGroup; QActionGroup* m_textColorActionGroup;
QColor m_defaultDefaultTextColor;
QMenu* m_textColorMenu; QMenu* m_textColorMenu;
QMenu* m_fontMenu; 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