[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.3/kdeplasma-addons/applets/notes
From: Darío Andrés Rodríguez <andresbajotierra () gmail ! co
Date: 2009-08-22 15:38:50
Message-ID: 1250955530.058715.4062.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1014363 by darioandres:
Backport to 4.3(tested) of:
SVN commit 1014360 by darioandres:
- Reverting the last change to use CSS to global formatting, as it has major
problems:
- All the text is saved as html and that includes the proper formatting as
html/css; so
setting a global CSS style will not affect future changes. ("local css" >
"global css" in priority)
- It also conflicts with the way KRichTextEdit works
- Set all the font changes using the KTextEdit "set*()" methods, but previously
selecting all the text
using QTextCursor (and then restoring the old cursor (restore text
selection))
- On updateTextGeometry(), only the font family and size changes are applied.
This are non-destructive changes
as the user has no other way to set this settings beside using the
Configuration Dialog; so we can do them
at any time
- Bold and italic settings are destructive (as setting a global bold/italic
will override the custom
formatting the user could have done when manually changing them using the
Notes controls at the bottom)
- So, we are going to apply this destructive global changes only if needed
(if any of them changed in the
configuration dialog)
- Small fix on load: Do not load the font properties on the Configuration
Dialog as the font() property
of the textedit. This is not true, we should use our stored var "m_font"
which properly loads the settings
from the config file
CCBUG: 204308
M +39 -9 notes.cpp
--- branches/KDE/4.3/kdeplasma-addons/applets/notes/notes.cpp #1014362:1014363
@@ -412,12 +412,20 @@
m_layout->setContentsMargins(xpad, ypad, xpad, ypad);
m_font.setPointSize(fontSize());
- QString cssWeight = m_font.bold() ? "bold" : "normal";
- QString cssStyle = m_font.italic() ? "italic" : "normal";
- QString cssSize = QString::number(m_font.pointSize()) + QString("pt");
- QString css = QString("QTextEdit { font-family:%1; font-size:%2; font-weight:%3;"
- "font-style:%4; }").arg(m_font.family(), cssSize, cssWeight, cssStyle);
- m_textEdit->nativeWidget()->setStyleSheet(css);
+ //Save the current text selection
+ QTextCursor oldTextCursor = m_textEdit->nativeWidget()->textCursor();
+
+ //Select all the text to set the new style
+ QTextCursor allSelection = oldTextCursor;
+ allSelection.select(QTextCursor::Document);
+ m_textEdit->nativeWidget()->setTextCursor(allSelection);
+
+ //Apply the new font family and size
+ m_textEdit->nativeWidget()->setFontFamily(m_font.family());
+ m_textEdit->nativeWidget()->setFontPointSize(m_font.pointSize());
+
+ //Restore the text selection
+ m_textEdit->nativeWidget()->setTextCursor(oldTextCursor);
}
}
@@ -517,9 +525,9 @@
ui.textColorButton->setColor(m_textColor);
ui.textBackgroundColorButton->setColor(m_textBackgroundColor);
- ui.fontStyleComboBox->setCurrentFont(m_textEdit->nativeWidget()->font());
- ui.fontBoldCheckBox->setChecked(m_textEdit->nativeWidget()->font().bold());
- ui.fontItalicCheckBox->setChecked(m_textEdit->nativeWidget()->font().italic());
+ ui.fontStyleComboBox->setCurrentFont(m_font);
+ ui.fontBoldCheckBox->setChecked(m_font.bold());
+ ui.fontItalicCheckBox->setChecked(m_font.italic());
ui.autoFont->setChecked(m_autoFont);
ui.autoFontPercent->setEnabled(m_autoFont);
ui.customFont->setChecked(!m_autoFont);
@@ -561,6 +569,28 @@
QFont newFont = ui.fontStyleComboBox->currentFont();
newFont.setBold(ui.fontBoldCheckBox->isChecked());
newFont.setItalic(ui.fontItalicCheckBox->isChecked());
+
+ //Apply bold and italic changes (if any) here (this is destructive formatting)
+ bool boldChanged = (m_font.bold() != newFont.bold());
+ bool italicChanged = (m_font.italic() != newFont.italic());
+ if (boldChanged || italicChanged) {
+ //Save previous selection
+ QTextCursor oldCursor = m_textEdit->nativeWidget()->textCursor();
+ //Apply new global formatting
+ QTextCursor allSelection = oldCursor;
+ allSelection.select(QTextCursor::Document);
+ m_textEdit->nativeWidget()->setTextCursor(allSelection);
+ if (boldChanged) {
+ m_textEdit->nativeWidget()->setFontWeight(newFont.weight());
+ }
+ if (italicChanged) {
+ m_textEdit->nativeWidget()->setFontItalic(newFont.italic());
+ }
+ //Restore previous selection
+ m_textEdit->nativeWidget()->setTextCursor(oldCursor);
+ }
+
+ //Save font settings to config
if (m_font != newFont) {
changed = true;
cg.writeEntry("font", newFont);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic