[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    New Feature (sort of): new DCOP method for KNotes
From:       Michael Brade <brade () kde ! org>
Date:       2006-06-09 16:18:49
Message-ID: 200606091818.54769.brade () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi,

I got a request for KNotes to expose the color of a note on its DCOP 
interface. The patch is obviously small, it adds to the DCOP interfaces

virtual QString fgColor( const QString& noteId ) const = 0;
virtual QString bgColor( const QString& noteId ) const = 0;
virtual ASYNC setColor( const QString& noteId, const QString& fgColor,
                                               const QString& bgColor ) = 0;

and makes KNotes::setColor() public and stores the new colors in the config 
object.

Is this ok to add to KDE 3.5.4? If so, I will update Kontact/KNotes as well.

Thanks,
-- 
Rohan (Michael) Brade;         KDE Developer, Student of Computer Science
  |-mail: echo brade !#|tr -d "c oh"|s\e\d 's/e/\@/2;s/$/.org/;s/bra/k/2'
  °--web: http://www.kde.org/people/michaelb.html

KDE 4: Beyond Your Expectations

["PATCH.dcop-color" (text/x-diff)]

Index: KNotesIface.h
===================================================================
--- KNotesIface.h	(revision 536898)
+++ KNotesIface.h	(working copy)
@@ -86,6 +86,29 @@
     virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0;
 
     /**
+     * Returns the foreground/text color of a note.
+     * @param noteId the id of the note in question
+     * @return the foreground/text color as a QString
+     */
+    virtual QString fgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Returns the background color of a note.
+     * @param noteId the id of the note in question
+     * @return the background color as a QString
+     */
+    virtual QString bgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Sets the color (foreground and background color) of a note.
+     * @param noteId the id of the note
+     * @param fgColor the new text color for the note
+     * @param bgColor the new background color for the note
+     */
+    virtual ASYNC setColor( const QString& noteId, const QString& fgColor,
+                                                   const QString& bgColor ) = 0;
+
+    /**
      * Returns the title/name of a note.
      * @param noteId the id of the note in question
      * @return the name as a QString
Index: KNotesAppIface.h
===================================================================
--- KNotesAppIface.h	(revision 536898)
+++ KNotesAppIface.h	(working copy)
@@ -96,6 +96,29 @@
     virtual ASYNC setText( const QString& noteId, const QString& newText ) = 0;
 
     /**
+     * Returns the foreground/text color of a note.
+     * @param noteId the id of the note in question
+     * @return the foreground/text color as a QString
+     */
+    virtual QString fgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Returns the background color of a note.
+     * @param noteId the id of the note in question
+     * @return the background color as a QString
+     */
+    virtual QString bgColor( const QString& noteId ) const = 0;
+
+    /**
+     * Sets the color (foreground and background color) of a note.
+     * @param noteId the id of the note
+     * @param fgColor the new text color for the note
+     * @param bgColor the new background color for the note
+     */
+    virtual ASYNC setColor( const QString& noteId, const QString& fgColor,
+                                                   const QString& bgColor ) = 0;
+
+    /**
      * Returns the title/name of a note.
      * @param noteId the id of the note in question
      * @return the name as a QString
Index: knotesapp.h
===================================================================
--- knotesapp.h	(revision 536898)
+++ knotesapp.h	(working copy)
@@ -72,6 +72,12 @@
     void setName( const QString& id, const QString& newName );
     void setText( const QString& id, const QString& newText );
 
+    QString fgColor( const QString& id ) const;
+    QString bgColor( const QString& id ) const;
+
+    void setColor( const QString& id, const QString& fgColor,
+                                      const QString& bgColor );
+
     QMap<QString,QString> notes() const;
 
     void sync( const QString& app );
Index: knote.cpp
===================================================================
--- knote.cpp	(revision 536898)
+++ knote.cpp	(working copy)
@@ -372,7 +372,7 @@
 void KNote::slotKill( bool force )
 {
     if ( !force &&
-         KMessageBox::warningContinueCancel( this, 
+         KMessageBox::warningContinueCancel( this,
              i18n("<qt>Do you really want to delete note <b>%1</b>?</qt>").arg( m_label->text() ),
              i18n("Confirm Delete"), KGuiItem( i18n("&Delete"), "editdelete" ),
              "ConfirmDeleteNote"
@@ -474,6 +474,74 @@
     saveData();
 }
 
+QColor KNote::fgColor() const
+{
+    return m_config->fgColor();
+}
+
+QColor KNote::bgColor() const
+{
+    return m_config->bgColor();
+}
+
+void KNote::setColor( const QColor& fg, const QColor& bg )
+{
+    m_config->setFgColor( fg );
+    m_config->setBgColor( bg );
+
+    QPalette newpalette = palette();
+    newpalette.setColor( QColorGroup::Background, bg );
+    newpalette.setColor( QColorGroup::Foreground, fg );
+    newpalette.setColor( QColorGroup::Base,       bg ); // text background
+    newpalette.setColor( QColorGroup::Text,       fg ); // text color
+    newpalette.setColor( QColorGroup::Button,     bg );
+    newpalette.setColor( QColorGroup::ButtonText, fg );
+
+//    newpalette.setColor( QColorGroup::Highlight,  bg );
+//    newpalette.setColor( QColorGroup::HighlightedText, fg );
+
+    // the shadow
+    newpalette.setColor( QColorGroup::Midlight, bg.light(150) );
+    newpalette.setColor( QColorGroup::Shadow, bg.dark(116) );
+    newpalette.setColor( QColorGroup::Light, bg.light(180) );
+    if ( s_ppOffset )
+        newpalette.setColor( QColorGroup::Dark, bg.dark(200) );
+    else
+        newpalette.setColor( QColorGroup::Dark, bg.dark(108) );
+    setPalette( newpalette );
+
+    // set the text color
+    m_editor->setTextColor( fg );
+
+    // set the background color or gradient
+    updateBackground();
+
+    // set darker value for the hide button...
+    QPalette darker = palette();
+    darker.setColor( QColorGroup::Button, bg.dark(116) );
+    m_button->setPalette( darker );
+
+    // update the icon color
+    KIconEffect effect;
+    QPixmap icon = effect.apply( kapp->icon(), KIconEffect::Colorize, 1, bg, false );
+    QPixmap miniIcon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, bg, false );
+    KWin::setIcons( winId(), icon, miniIcon );
+
+    // set the color for the selection used to highlight the find stuff
+    QColor sel = palette().color( QPalette::Active, QColorGroup::Base ).dark();
+    if ( sel == Qt::black )
+        sel = palette().color( QPalette::Active, QColorGroup::Base ).light();
+
+    m_editor->setSelectionAttributes( 1, sel, true );
+
+    // update the color of the fold
+    createFold();
+
+    // update the color of the title
+    updateFocus();
+    emit sigColorChanged();
+}
+
 void KNote::find( const QString& pattern, long options )
 {
     delete m_find;
@@ -926,61 +994,6 @@
         KWin::setOnDesktop( winId(), desktop );
 }
 
-void KNote::setColor( const QColor &fg, const QColor &bg )
-{
-    QPalette newpalette = palette();
-    newpalette.setColor( QColorGroup::Background, bg );
-    newpalette.setColor( QColorGroup::Foreground, fg );
-    newpalette.setColor( QColorGroup::Base,       bg ); // text background
-    newpalette.setColor( QColorGroup::Text,       fg ); // text color
-    newpalette.setColor( QColorGroup::Button,     bg );
-    newpalette.setColor( QColorGroup::ButtonText, fg );
-    
-//    newpalette.setColor( QColorGroup::Highlight,  bg );
-//    newpalette.setColor( QColorGroup::HighlightedText, fg );
-
-    // the shadow
-    newpalette.setColor( QColorGroup::Midlight, bg.light(150) );
-    newpalette.setColor( QColorGroup::Shadow, bg.dark(116) );
-    newpalette.setColor( QColorGroup::Light, bg.light(180) );
-    if ( s_ppOffset )
-        newpalette.setColor( QColorGroup::Dark, bg.dark(200) );
-    else
-        newpalette.setColor( QColorGroup::Dark, bg.dark(108) );
-    setPalette( newpalette );
-
-    // set the text color
-    m_editor->setTextColor( fg );
-
-    // set the background color or gradient
-    updateBackground();
-
-    // set darker value for the hide button...
-    QPalette darker = palette();
-    darker.setColor( QColorGroup::Button, bg.dark(116) );
-    m_button->setPalette( darker );
-
-    // update the icon color
-    KIconEffect effect;
-    QPixmap icon = effect.apply( kapp->icon(), KIconEffect::Colorize, 1, bg, false );
-    QPixmap miniIcon = effect.apply( kapp->miniIcon(), KIconEffect::Colorize, 1, bg, false );
-    KWin::setIcons( winId(), icon, miniIcon );
-
-    // set the color for the selection used to highlight the find stuff
-    QColor sel = palette().color( QPalette::Active, QColorGroup::Base ).dark();
-    if ( sel == Qt::black )
-        sel = palette().color( QPalette::Active, QColorGroup::Base ).light();
-
-    m_editor->setSelectionAttributes( 1, sel, true );
-
-    // update the color of the fold
-    createFold();
-
-    // update the color of the title
-    updateFocus();
-    emit sigColorChanged();
-}
-
 void KNote::createFold()
 {
     QPixmap fold( 15, 15 );
Index: knotesapp.cpp
===================================================================
--- knotesapp.cpp	(revision 536898)
+++ knotesapp.cpp	(working copy)
@@ -355,6 +355,33 @@
         kdWarning(5500) << "setText: no note with id: " << id << endl;
 }
 
+QString KNotesApp::fgColor( const QString& id ) const
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        return note->fgColor().name();
+    else
+        return QString::null;
+}
+
+QString KNotesApp::bgColor( const QString& id ) const
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        return note->bgColor().name();
+    else
+        return QString::null;
+}
+
+void KNotesApp::setColor( const QString& id, const QString& fgColor, const QString& bgColor )
+{
+    KNote* note = m_noteList[id];
+    if ( note )
+        note->setColor( QColor( fgColor ), QColor( bgColor ) );
+    else
+        kdWarning(5500) << "setColor: no note with id: " << id << endl;
+}
+
 void KNotesApp::sync( const QString& app )
 {
     QDictIterator<KNote> it( m_noteList );
Index: knote.h
===================================================================
--- knote.h	(revision 536898)
+++ knote.h	(working copy)
@@ -1,7 +1,7 @@
 /*******************************************************************
  KNotes -- Notes for the KDE project
 
- Copyright (c) 1997-2005, The KNotes Developers
+ Copyright (c) 1997-2006, The KNotes Developers
 
  This program is free software; you can redistribute it and/or
  modify it under the terms of the GNU General Public License
@@ -60,6 +60,7 @@
     void saveConfig() const;
 
     QString noteId() const;
+
     QString name() const;
     QString text() const;
     QString plainText() const;
@@ -67,6 +68,10 @@
     void setName( const QString& name );
     void setText( const QString& text );
 
+    QColor fgColor() const;
+    QColor bgColor() const;
+    void setColor( const QColor& fg, const QColor& bg );
+
     void find( const QString& pattern, long options );
 
     bool isModified() const;
@@ -136,8 +141,6 @@
     void updateLabelAlignment();
     void updateBackground( int offset = -1 );
 
-    void setColor( const QColor&, const QColor& );
-
     void createFold();
 
     void toDesktop( int desktop );

[Attachment #6 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

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