[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 18:08:59
Message-ID: 1250964539.232700.10028.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1014389 by darioandres:

Backport to 4.3 of:
SVN commit 1014374 by darioandres:

- When the text is deleted the format will always reverted to zero; as
KTextEdit calls only work on
  local/selected text, but they won't set a "default" format.
  - To fix this, I adapted the patch by anmma at
http://reviewboard.kde.org/r/679/
    - On "lineChange", detect if the character entered is the first one
      (that means the previous text (if any) was deleted) and set the default
char text format
      to use the defined font style/size/family and foreground color.
  So, the global format/style settings will be always honored

- Do not change the QPalette of the KTextEdit as this is not needed anymore
(was it needed before?)

and:
SVN commit 1014384 by darioandres:

- Simplify the code to selectAll+change some text property

- On "updateTextGeometry" it is not necessary to set the font family again.
  - Set the font family only on "configAccepted" (if the font was changed)

- Fix a bug in the following workflow:
  - Text written, deleted, widget resized, text written again will have the previous size
  (calculated before the "updateTextGeometry" call). That is why we need to call "lineChanged" again

CCBUG: 176266


 M  +18 -21    notes.cpp  


--- branches/KDE/4.3/kdeplasma-addons/applets/notes/notes.cpp #1014388:1014389
@@ -323,9 +323,6 @@
     m_textColor = cg.readEntry("textColor", QColor(Qt::black));
     m_textBackgroundColor = cg.readEntry("textBackgroundColor", QColor(Qt::transparent));
     m_textEdit->nativeWidget()->setTextColor(m_textColor);
-    QPalette palette = m_textEdit->nativeWidget()->palette();
-    palette.setColor(QPalette::Text, m_textColor);
-    m_textEdit->nativeWidget()->setPalette(palette);
 
     QString text = cg.readEntry("autoSaveHtml", QString());
     if (text.isEmpty()) {
@@ -368,6 +365,14 @@
 */
 void Notes::lineChanged()
 {
+    //Re-set the formatting if previous text was deleted
+    if (m_textEdit->nativeWidget()->document()->characterCount() == 1) {
+        QTextCharFormat fmt;
+        fmt.setForeground(QBrush(m_textColor));
+        fmt.setFont(m_font);
+        m_textEdit->nativeWidget()->setCurrentCharFormat(fmt);   
+    }
+    
     if (m_useNoColor) {
         return;
     }
@@ -412,20 +417,12 @@
         m_layout->setContentsMargins(xpad, ypad, xpad, ypad);
         m_font.setPointSize(fontSize());
 
-        //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()->selectAll();
         m_textEdit->nativeWidget()->setFontPointSize(m_font.pointSize());
-        
-        //Restore the text selection
         m_textEdit->nativeWidget()->setTextCursor(oldTextCursor);
+        
+        lineChanged();
     }
 }
 
@@ -576,10 +573,7 @@
     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);
+        m_textEdit->nativeWidget()->selectAll();
         if (boldChanged) {
             m_textEdit->nativeWidget()->setFontWeight(newFont.weight());
         }
@@ -596,6 +590,12 @@
         cg.writeEntry("font", newFont);
         m_font = newFont;
         m_font.setPointSize(fontSize());
+        
+        //Apply font size
+        QTextCursor oldCursor = m_textEdit->nativeWidget()->textCursor();
+        m_textEdit->nativeWidget()->selectAll();
+        m_textEdit->nativeWidget()->setFontFamily(m_font.family());
+        m_textEdit->nativeWidget()->setTextCursor(oldCursor);
     }
 
     if (m_customFontSize != ui.customFontSizeSpinBox->value()) {
@@ -637,9 +637,6 @@
         m_textEdit->nativeWidget()->selectAll();
         m_textEdit->nativeWidget()->setTextColor(m_textColor);
         m_textEdit->nativeWidget()->setTextCursor(textCursor);
-        QPalette palette = m_textEdit->nativeWidget()->palette();
-        palette.setColor(QPalette::Text, m_textColor);
-        m_textEdit->nativeWidget()->setPalette(palette);
     }
 
     if (m_useNoColor != ui.useNoColor->isChecked()) {
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic