Index: branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.h =================================================================== --- branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.h (revision 296406) +++ branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.h (revision 296407) @@ -1,280 +1,284 @@ /* This file is part of the KDE libraries Copyright (C) 2001-2003 Christoph Cullmann Copyright (C) 2002, 2003 Anders Lund - + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __KATE_SCHEMA_H__ #define __KATE_SCHEMA_H__ #include "katehighlight.h" #include "katedialogs.h" #include #include #include #include #include class KateView; class KateStyleListItem; class KColorButton; class QPopupMenu; class KateSchemaManager { public: KateSchemaManager (); ~KateSchemaManager (); /** * Schema Config changed, update all renderers */ void update (bool readfromfile = true); /** * return kconfig with right group set or set to Normal if not there */ KConfig *schema (uint number); void addSchema (const QString &t); void removeSchema (uint number); - + /** * is this schema valid ? (does it exist ?) */ bool validSchema (uint number); /** * if not found, defaults to 0 */ uint number (const QString &name); /** * group names in the end, no i18n involved */ QString name (uint number); /** * Don't modify, list with the names of the schemas (i18n name for the default ones) */ const QStringList &list () { return m_schemas; } - + static QString normalSchema (); static QString printingSchema (); private: KConfig m_config; QStringList m_schemas; }; class KateViewSchemaAction : public KActionMenu { Q_OBJECT public: KateViewSchemaAction(const QString& text, QObject* parent = 0, const char* name = 0) : KActionMenu(text, parent, name) { init(); }; ~KateViewSchemaAction(){;}; void updateMenu (KateView *view); private: void init(); QGuardedPtr m_view; QStringList names; int last; public slots: void slotAboutToShow(); private slots: void setSchema (int mode); }; // // DIALOGS // /* QListView that automatically adds columns for KateStyleListItems and provides a popup menu and a slot to edit a style using the keyboard. Added by anders, jan 23 2002. */ class KateStyleListView : public QListView { Q_OBJECT - + friend class KateStyleListItem; - + public: KateStyleListView( QWidget *parent=0, bool showUseDefaults=false); ~KateStyleListView() {}; /* Display a popupmenu for item i at the specified global position, eventually with a title, promoting the context name of that item */ void showPopupMenu( KateStyleListItem *i, const QPoint &globalPos, bool showtitle=false ); void emitChanged() { emit changed(); }; - + + void setBgCol( const QColor &c ) { bgcol = c; } + void setSelCol( const QColor &c ) { selcol = c; } + void setNormalCol( const QColor &c ) { normalcol = c; } + private slots: /* Display a popupmenu for item i at item position */ void showPopupMenu( QListViewItem *i ); /* call item to change a property, or display a menu */ void slotMousePressed( int, QListViewItem*, const QPoint&, int ); /* asks item to change the property in q */ void mSlotPopupHandler( int z ); - + signals: void changed(); - + private: QColor bgcol, selcol, normalcol; QFont docfont; }; class KateSchemaConfigColorTab : public QWidget { Q_OBJECT public: KateSchemaConfigColorTab( QWidget *parent = 0, const char *name = 0 ); ~KateSchemaConfigColorTab(); private: KColorButton *m_back; KColorButton *m_selected; KColorButton *m_current; KColorButton *m_bracket; KColorButton *m_wwmarker; KColorButton *m_iconborder; KColorButton *m_tmarker; public: void readConfig (KConfig *config); void writeConfig (KConfig *config); }; class KateSchemaConfigFontTab : public QWidget { Q_OBJECT public: KateSchemaConfigFontTab( QWidget *parent = 0, const char *name = 0 ); ~KateSchemaConfigFontTab(); public: void readConfig (KConfig *config); void writeConfig (KConfig *config); private: class KFontChooser *m_fontchooser; QFont myFont; private slots: void slotFontSelected( const QFont &font ); }; class KateSchemaConfigFontColorTab : public QWidget { Q_OBJECT public: KateSchemaConfigFontColorTab( QWidget *parent = 0, const char *name = 0 ); ~KateSchemaConfigFontColorTab(); public: void schemaChanged (uint schema); void reload (); void apply (); - + KateAttributeList *attributeList (uint schema); private: KateStyleListView *m_defaultStyles; QIntDict m_defaultStyleLists; }; class KateSchemaConfigHighlightTab : public QWidget { Q_OBJECT public: KateSchemaConfigHighlightTab( QWidget *parent = 0, const char *name = 0, KateSchemaConfigFontColorTab *page = 0 ); ~KateSchemaConfigHighlightTab(); public: void schemaChanged (uint schema); void reload (); void apply (); - + protected slots: void hlChanged(int z); private: KateSchemaConfigFontColorTab *m_defaults; - + QComboBox *hlCombo; KateStyleListView *m_styles; - + uint m_schema; int m_hl; - + QIntDict< QIntDict > m_hlDict; }; class KateSchemaConfigPage : public KateConfigPage { Q_OBJECT public: KateSchemaConfigPage ( QWidget *parent ); ~KateSchemaConfigPage (); public slots: void apply(); void reload(); void reset(); void defaults(); private slots: void update (); void deleteSchema (); void newSchema (); void schemaChanged (int schema); - + void newCurrentPage (QWidget *w); private: int m_lastSchema; class QTabWidget *m_tabWidget; class QPushButton *btndel; class QComboBox *defaultSchemaCombo; class QComboBox *schemaCombo; KateSchemaConfigColorTab *m_colorTab; KateSchemaConfigFontTab *m_fontTab; KateSchemaConfigFontColorTab *m_fontColorTab; KateSchemaConfigHighlightTab *m_highlightTab; }; #endif // kate: space-indent on; indent-width 2; replace-tabs on; Index: branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.cpp =================================================================== --- branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.cpp (revision 296406) +++ branches/KDE_3_2_BRANCH/kdelibs/kate/part/kateschema.cpp (revision 296407) @@ -1,1184 +1,1232 @@ /* This file is part of the KDE libraries Copyright (C) 2001-2003 Christoph Cullmann Copyright (C) 2002, 2003 Anders Lund This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "kateschema.h" #include "kateschema.moc" #include "kateconfig.h" #include "katefactory.h" #include "kateview.h" #include "katerenderer.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* QListViewItem subclass to display/edit a style, bold/italic is check boxes, normal and selected colors are boxes, which will display a color chooser when activated. The context name for the style will be drawn using the editor default font and the chosen colors. This widget id designed to handle the default as well as the individual hl style lists. This widget is designed to work with the KateStyleListView class exclusively. Added by anders, jan 23 2002. */ class KateStyleListItem : public QListViewItem { public: KateStyleListItem( QListView *parent=0, const QString & stylename=0, class KateAttribute* defaultstyle=0, class ItemData *data=0 ); ~KateStyleListItem() { if (st) delete is; }; /* mainly for readability */ enum Property { ContextName, Bold, Italic, Underline, Strikeout, Color, SelColor, BgColor, SelBgColor, UseDefStyle }; /* updates the hldata's style */ void updateStyle(); /* reimp */ virtual int width ( const QFontMetrics & fm, const QListView * lv, int c ) const; /* calls changeProperty() if it makes sense considering pos. */ void activate( int column, const QPoint &localPos ); /* For bool fields, toggles them, for color fields, display a color chooser */ void changeProperty( Property p ); /* style context name */ QString contextName() { return text(0); }; /* only true for a hl mode item using it's default style */ bool defStyle(); /* true for default styles */ bool isDefault(); /* whichever style is active (st for hl mode styles not using the default style, ds otherwise) */ class KateAttribute* style() { return is; }; - + protected: /* reimp */ void paintCell(QPainter *p, const QColorGroup& cg, int col, int width, int align); - + private: /* private methods to change properties */ void toggleDefStyle(); void setColor( int ); /* helper function to copy the default style into the ItemData, when a property is changed and we are using default style. */ void setCustStyle(); class KateAttribute *is, // the style currently in use *ds; // default style for hl mode contexts and default styles class ItemData *st; // itemdata for hl mode contexts }; QString KateSchemaManager::normalSchema () { return KApplication::kApplication()->aboutData()->appName () + QString (" - Normal"); } QString KateSchemaManager::printingSchema () { return KApplication::kApplication()->aboutData()->appName () + QString (" - Printing"); } KateSchemaManager::KateSchemaManager () : m_config ("kateschemarc", false, false) { update (); } KateSchemaManager::~KateSchemaManager () { } // // read the types from config file and update the internal list // void KateSchemaManager::update (bool readfromfile) { if (readfromfile) m_config.reparseConfiguration (); m_schemas = m_config.groupList(); m_schemas.sort (); m_schemas.remove (printingSchema()); m_schemas.remove (normalSchema()); m_schemas.prepend (printingSchema()); m_schemas.prepend (normalSchema()); } // // get the right group // special handling of the default schemas ;) // KConfig *KateSchemaManager::schema (uint number) { if ((number>1) && (number < m_schemas.count())) m_config.setGroup (m_schemas[number]); else if (number == 1) m_config.setGroup (printingSchema()); else m_config.setGroup (normalSchema()); return &m_config; } void KateSchemaManager::addSchema (const QString &t) { m_config.setGroup (t); m_config.writeEntry("Color Background", KGlobalSettings::baseColor()); update (false); } void KateSchemaManager::removeSchema (uint number) { if (number >= m_schemas.count()) return; if (number < 2) return; m_config.deleteGroup (name (number)); update (false); } bool KateSchemaManager::validSchema (uint number) { if (number < m_schemas.count()) return true; return false; } uint KateSchemaManager::number (const QString &name) { if (name == normalSchema()) return 0; if (name == printingSchema()) return 1; int i; if ((i = m_schemas.findIndex(name)) > -1) return i; return 0; } QString KateSchemaManager::name (uint number) { if ((number>1) && (number < m_schemas.count())) return m_schemas[number]; else if (number == 1) return printingSchema(); return normalSchema(); } // // // // DIALOGS !!! // // //BEGIN KateSchemaConfigColorTab KateSchemaConfigColorTab::KateSchemaConfigColorTab( QWidget *parent, const char * ) : QWidget (parent) { QHBox *b; QLabel *label; QVBoxLayout *blay=new QVBoxLayout(this, 0, KDialog::spacingHint()); QVGroupBox *gbTextArea = new QVGroupBox(i18n("Text Area Background"), this); b = new QHBox (gbTextArea); label = new QLabel( i18n("Normal text:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_back = new KColorButton(b); connect( m_back, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); b = new QHBox (gbTextArea); label = new QLabel( i18n("Selected text:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_selected = new KColorButton(b); connect( m_selected, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); b = new QHBox (gbTextArea); label = new QLabel( i18n("Current line:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_current = new KColorButton(b); connect( m_current, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); blay->addWidget(gbTextArea); QVGroupBox *gbBorder = new QVGroupBox(i18n("Additional Elements"), this); b = new QHBox (gbBorder); label = new QLabel( i18n("Left border background:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_iconborder = new KColorButton(b); connect( m_iconborder, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); b = new QHBox (gbBorder); label = new QLabel( i18n("Bracket highlight:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_bracket = new KColorButton(b); connect( m_bracket, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); b = new QHBox (gbBorder); label = new QLabel( i18n("Word wrap markers:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_wwmarker = new KColorButton(b); connect( m_wwmarker, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); b = new QHBox (gbBorder); label = new QLabel( i18n("Tab markers:"), b); label->setAlignment( AlignLeft|AlignVCenter); m_tmarker = new KColorButton(b); connect( m_tmarker, SIGNAL( changed( const QColor & ) ), parent->parentWidget(), SLOT( slotChanged() ) ); blay->addWidget(gbBorder); blay->addStretch(); // QWhatsThis help QWhatsThis::add(m_back, i18n("

Sets the background color of the editing area.

")); QWhatsThis::add(m_selected, i18n("

Sets the background color of the selection.

" "

To set the text color for selected text, use the \"Configure " "Highlighting\" dialog.

")); QWhatsThis::add(m_current, i18n("

Sets the background color of the currently " "active line, which means the line where your cursor is positioned.

")); QWhatsThis::add(m_bracket, i18n("

Sets the bracket matching color. This means, " "if you place the cursor e.g. at a (, the matching ) will " "be highlighted with this color.

")); QWhatsThis::add(m_wwmarker, i18n( "

Sets the color of Word Wrap-related markers:

" "
Static Word Wrap
A vertical line which shows the column where " "text is going to be wrapped
" "
Dynamic Word Wrap
An arrow shown to the left of " "visually-wrapped lines
")); QWhatsThis::add(m_tmarker, i18n( "

Sets the color of the tabulator marks:

")); } KateSchemaConfigColorTab::~KateSchemaConfigColorTab() { } void KateSchemaConfigColorTab::readConfig (KConfig *config) { QColor tmp0 (KGlobalSettings::baseColor()); QColor tmp1 (KGlobalSettings::highlightColor()); QColor tmp2 (KGlobalSettings::alternateBackgroundColor()); QColor tmp3 ( "#FFFF99" ); QColor tmp4 (tmp2.dark()); QColor tmp5 ( KGlobalSettings::textColor() ); QColor tmp6 ( "#EAE9E8" ); m_back->setColor(config->readColorEntry("Color Background", &tmp0)); m_selected->setColor(config->readColorEntry("Color Selection", &tmp1)); m_current->setColor(config->readColorEntry("Color Highlighted Line", &tmp2)); m_bracket->setColor(config->readColorEntry("Color Highlighted Bracket", &tmp3)); m_wwmarker->setColor(config->readColorEntry("Color Word Wrap Marker", &tmp4)); m_tmarker->setColor(config->readColorEntry("Color Tab Marker", &tmp5)); m_iconborder->setColor(config->readColorEntry("Color Icon Bar", &tmp6)); } void KateSchemaConfigColorTab::writeConfig (KConfig *config) { config->writeEntry("Color Background", m_back->color()); config->writeEntry("Color Selection", m_selected->color()); config->writeEntry("Color Highlighted Line", m_current->color()); config->writeEntry("Color Highlighted Bracket", m_bracket->color()); config->writeEntry("Color Word Wrap Marker", m_wwmarker->color()); config->writeEntry("Color Tab Marker", m_tmarker->color()); config->writeEntry("Color Icon Bar", m_iconborder->color()); } //END KateSchemaConfigColorTab -//BEGIN FontConfig +//BEGIN KateSchemaConfigFontTab KateSchemaConfigFontTab::KateSchemaConfigFontTab( QWidget *parent, const char * ) : QWidget (parent) { // sizemanagment QGridLayout *grid = new QGridLayout( this, 1, 1 ); m_fontchooser = new KFontChooser ( this, 0L, false, QStringList(), false ); m_fontchooser->enableColumn(KFontChooser::StyleList, false); grid->addWidget( m_fontchooser, 0, 0); connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), this, SLOT (slotFontSelected( const QFont & ))); connect (m_fontchooser, SIGNAL (fontSelected( const QFont & )), parent->parentWidget(), SLOT (slotChanged())); } KateSchemaConfigFontTab::~KateSchemaConfigFontTab() { } void KateSchemaConfigFontTab::slotFontSelected( const QFont &font ) { myFont = font; } void KateSchemaConfigFontTab::readConfig (KConfig *config) { QFont f (KGlobalSettings::fixedFont()); m_fontchooser->setFont (config->readFontEntry("Font", &f)); } void KateSchemaConfigFontTab::writeConfig (KConfig *config) { config->writeEntry("Font", myFont); } -//END FontConfig +//END KateSchemaConfigFontTab -//BEGIN FontColorConfig +//BEGIN KateSchemaConfigFontTab KateSchemaConfigFontColorTab::KateSchemaConfigFontColorTab( QWidget *parent, const char * ) : QWidget (parent) { m_defaultStyleLists.setAutoDelete(true); // sizemanagment QGridLayout *grid = new QGridLayout( this, 1, 1 ); m_defaultStyles = new KateStyleListView( this, false ); grid->addWidget( m_defaultStyles, 0, 0); connect (m_defaultStyles, SIGNAL (changed()), parent->parentWidget(), SLOT (slotChanged())); } KateSchemaConfigFontColorTab::~KateSchemaConfigFontColorTab() { } KateAttributeList *KateSchemaConfigFontColorTab::attributeList (uint schema) { if (!m_defaultStyleLists[schema]) { KateAttributeList *list = new KateAttributeList (); HlManager::self()->getDefaults(schema, *list); m_defaultStyleLists.insert (schema, list); } return m_defaultStyleLists[schema]; } void KateSchemaConfigFontColorTab::schemaChanged (uint schema) { m_defaultStyles->clear (); KateAttributeList *l = attributeList (schema); + // set colors + QPalette p ( m_defaultStyles->palette() ); + QColor _c ( KGlobalSettings::baseColor() ); + p.setColor( QPalette::Normal, QColorGroup::Base, + KateFactory::self()->schemaManager()->schema(schema)-> + readColorEntry( "Color Background", &_c ) ); + _c = KGlobalSettings::highlightColor(); + p.setColor( QPalette::Normal, QColorGroup::Highlight, + KateFactory::self()->schemaManager()->schema(schema)-> + readColorEntry( "Color Selection", &_c ) ); + _c = l->at(0)->textColor(); // not quite as much of an assumption ;) + p.setColor( QPalette::Normal, QColorGroup::Text, _c ); + m_defaultStyles->viewport()->setPalette( p ); + for ( uint i = 0; i < HlManager::self()->defaultStyles(); i++ ) { m_defaultStyles->insertItem( new KateStyleListItem( m_defaultStyles, HlManager::self()->defaultStyleName(i), l->at( i ) ) ); } } void KateSchemaConfigFontColorTab::reload () { m_defaultStyles->clear (); m_defaultStyleLists.clear (); } void KateSchemaConfigFontColorTab::apply () { for ( QIntDictIterator it( m_defaultStyleLists ); it.current(); ++it ) HlManager::self()->setDefaults(it.currentKey(), *(it.current())); } -//END FontColorConfig +//END KateSchemaConfigFontColorTab -//BEGIN FontColorConfig +//BEGIN KateSchemaConfigFontColorTab KateSchemaConfigHighlightTab::KateSchemaConfigHighlightTab( QWidget *parent, const char *, KateSchemaConfigFontColorTab *page ) : QWidget (parent) { m_defaults = page; m_schema = 0; m_hl = 0; m_hlDict.setAutoDelete (true); QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); // hl chooser QHBox *hbHl = new QHBox( this ); layout->add (hbHl); hbHl->setSpacing( KDialog::spacingHint() ); QLabel *lHl = new QLabel( i18n("H&ighlight:"), hbHl ); hlCombo = new QComboBox( false, hbHl ); lHl->setBuddy( hlCombo ); connect( hlCombo, SIGNAL(activated(int)), this, SLOT(hlChanged(int)) ); for( int i = 0; i < HlManager::self()->highlights(); i++) { if (HlManager::self()->hlSection(i).length() > 0) hlCombo->insertItem(HlManager::self()->hlSection(i) + QString ("/") + HlManager::self()->hlName(i)); else hlCombo->insertItem(HlManager::self()->hlName(i)); } hlCombo->setCurrentItem(0); // styles listview m_styles = new KateStyleListView( this, true ); layout->addWidget (m_styles, 999); hlCombo->setCurrentItem ( 0 ); hlChanged ( 0 ); QWhatsThis::add( m_styles, i18n("This list displays the contexts of the current syntax highlight mode and offers the means to edit them. The context name reflects the current style settings.

To edit using the keyboard, press <SPACE> and choose a property from the popup menu.

To edit the colors, click the colored squares, or select the color to edit from the popup menu.") ); connect (m_styles, SIGNAL (changed()), parent->parentWidget(), SLOT (slotChanged())); } KateSchemaConfigHighlightTab::~KateSchemaConfigHighlightTab() { } void KateSchemaConfigHighlightTab::hlChanged(int z) { m_hl = z; schemaChanged (m_schema); } void KateSchemaConfigHighlightTab::schemaChanged (uint schema) { m_schema = schema; kdDebug () << "NEW SCHEMA: " << m_schema << " NEW HL: " << m_hl << endl; m_styles->clear (); if (!m_hlDict[m_schema]) { kdDebug () << "NEW SCHEMA, create dict" << endl; m_hlDict.insert (schema, new QIntDict); m_hlDict[m_schema]->setAutoDelete (true); } if (!m_hlDict[m_schema]->find(m_hl)) { kdDebug () << "NEW HL, create list" << endl; ItemDataList *list = new ItemDataList (); HlManager::self()->getHl( m_hl )->getItemDataListCopy (m_schema, *list); m_hlDict[m_schema]->insert (m_hl, list); } KateAttributeList *l = m_defaults->attributeList (schema); + // Set listview colors + // We do that now, because we can now get the "normal text" color. + // TODO this reads of the KConfig object, which should be changed when + // the color tab is fixed. + QPalette p ( m_styles->palette() ); + QColor _c ( KGlobalSettings::baseColor() ); + p.setColor( QPalette::Normal, QColorGroup::Base, + KateFactory::self()->schemaManager()->schema(m_schema)-> + readColorEntry( "Color Background", &_c ) ); + _c = KGlobalSettings::highlightColor(); + p.setColor( QPalette::Normal, QColorGroup::Highlight, + KateFactory::self()->schemaManager()->schema(m_schema)-> + readColorEntry( "Color Selection", &_c ) ); + // ahem, *assuming* that normal text is the first item :o + _c = m_hlDict[m_schema]->find(m_hl)->first()->textColor(); + if ( ! _c.isValid() ) + _c = l->at(0)->textColor(); // not quite as much of an assumption ;) + p.setColor( QPalette::Normal, QColorGroup::Text, _c ); + m_styles->viewport()->setPalette( p ); + + for ( ItemData *itemData = m_hlDict[m_schema]->find(m_hl)->first(); itemData != 0L; itemData = m_hlDict[m_schema]->find(m_hl)->next()) { kdDebug () << "insert items " << itemData->name << endl; m_styles->insertItem( new KateStyleListItem( m_styles, itemData->name, l->at(itemData->defStyleNum), itemData ) ); } } void KateSchemaConfigHighlightTab::reload () { m_styles->clear (); m_hlDict.clear (); hlChanged (0); } void KateSchemaConfigHighlightTab::apply () { for ( QIntDictIterator< QIntDict > it( m_hlDict ); it.current(); ++it ) for ( QIntDictIterator< ItemDataList > it2( *it.current() ); it2.current(); ++it2 ) HlManager::self()->getHl( it2.currentKey() )->setItemDataList (it.currentKey(), *(it2.current())); } -//END HighlightConfig +//END KateSchemaConfigHighlightTab KateSchemaConfigPage::KateSchemaConfigPage( QWidget *parent ) : KateConfigPage( parent ), m_lastSchema (-1) { QVBoxLayout *layout = new QVBoxLayout(this, 0, KDialog::spacingHint() ); QHBox *hbHl = new QHBox( this ); layout->add (hbHl); hbHl->setSpacing( KDialog::spacingHint() ); QLabel *lHl = new QLabel( i18n("&Schema:"), hbHl ); schemaCombo = new QComboBox( false, hbHl ); lHl->setBuddy( schemaCombo ); connect( schemaCombo, SIGNAL(activated(int)), this, SLOT(schemaChanged(int)) ); btndel = new QPushButton( i18n("&Delete"), hbHl ); connect( btndel, SIGNAL(clicked()), this, SLOT(deleteSchema()) ); QPushButton *btnnew = new QPushButton( i18n("&New..."), hbHl ); connect( btnnew, SIGNAL(clicked()), this, SLOT(newSchema()) ); m_tabWidget = new QTabWidget ( this ); m_tabWidget->setMargin (KDialog::marginHint()); layout->add (m_tabWidget); connect (m_tabWidget, SIGNAL (currentChanged (QWidget *)), this, SLOT (newCurrentPage (QWidget *))); m_colorTab = new KateSchemaConfigColorTab (m_tabWidget); m_tabWidget->addTab (m_colorTab, i18n("Colors")); m_fontTab = new KateSchemaConfigFontTab (m_tabWidget); m_tabWidget->addTab (m_fontTab, i18n("Font")); m_fontColorTab = new KateSchemaConfigFontColorTab (m_tabWidget); m_tabWidget->addTab (m_fontColorTab, i18n("Normal Text Styles")); m_highlightTab = new KateSchemaConfigHighlightTab (m_tabWidget, "", m_fontColorTab); m_tabWidget->addTab (m_highlightTab, i18n("Highlighting Text Styles")); hbHl = new QHBox( this ); layout->add (hbHl); hbHl->setSpacing( KDialog::spacingHint() ); lHl = new QLabel( i18n("&Default schema for %1:").arg(KApplication::kApplication()->aboutData()->programName ()), hbHl ); defaultSchemaCombo = new QComboBox( false, hbHl ); lHl->setBuddy( defaultSchemaCombo ); - + reload(); - + connect( defaultSchemaCombo, SIGNAL(activated(int)), this, SLOT(slotChanged()) ); } KateSchemaConfigPage::~KateSchemaConfigPage () { // just reload config from disc KateFactory::self()->schemaManager()->update (); } void KateSchemaConfigPage::apply() { if (m_lastSchema > -1) { m_colorTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema)); m_fontTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema)); } // just sync the config KateFactory::self()->schemaManager()->schema (0)->sync(); KateFactory::self()->schemaManager()->update (); KateRendererConfig::global()->setSchema (defaultSchemaCombo->currentItem()); // special for the highlighting stuff m_fontColorTab->apply (); m_highlightTab->apply (); // sync the hl config for real HlManager::self()->getKConfig()->sync (); } void KateSchemaConfigPage::reload() { // just reload the config from disc KateFactory::self()->schemaManager()->update (); // special for the highlighting stuff m_fontColorTab->reload (); update (); defaultSchemaCombo->setCurrentItem (KateRendererConfig::global()->schema()); } void KateSchemaConfigPage::reset() { reload (); } void KateSchemaConfigPage::defaults() { reload (); } void KateSchemaConfigPage::update () { // soft update, no load from disk KateFactory::self()->schemaManager()->update (false); schemaCombo->clear (); schemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ()); defaultSchemaCombo->clear (); defaultSchemaCombo->insertStringList (KateFactory::self()->schemaManager()->list ()); schemaCombo->setCurrentItem (0); schemaChanged (0); schemaCombo->setEnabled (schemaCombo->count() > 0); } void KateSchemaConfigPage::deleteSchema () { int t = schemaCombo->currentItem (); KateFactory::self()->schemaManager()->removeSchema (t); update (); } void KateSchemaConfigPage::newSchema () { QString t = KInputDialog::getText (i18n("Name for New Schema"), i18n ("Name:"), i18n("New Schema"), 0, this); KateFactory::self()->schemaManager()->addSchema (t); // soft update, no load from disk KateFactory::self()->schemaManager()->update (false); int i = KateFactory::self()->schemaManager()->list ().findIndex (t); update (); if (i > -1) { schemaCombo->setCurrentItem (i); schemaChanged (i); } } void KateSchemaConfigPage::schemaChanged (int schema) { if (schema < 2) { btndel->setEnabled (false); } else { btndel->setEnabled (true); } if (m_lastSchema > -1) { m_colorTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema)); m_fontTab->writeConfig (KateFactory::self()->schemaManager()->schema(m_lastSchema)); } m_colorTab->readConfig (KateFactory::self()->schemaManager()->schema(schema)); m_fontTab->readConfig (KateFactory::self()->schemaManager()->schema(schema)); m_fontColorTab->schemaChanged (schema); m_highlightTab->schemaChanged (schema); m_lastSchema = schema; } void KateSchemaConfigPage::newCurrentPage (QWidget *w) { if (w == m_highlightTab) m_highlightTab->schemaChanged (m_lastSchema); } // BEGIN SCHEMA ACTION void KateViewSchemaAction::init() { m_view = 0; last = 0; connect(popupMenu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow())); } void KateViewSchemaAction::updateMenu (KateView *view) { m_view = view; } void KateViewSchemaAction::slotAboutToShow() { KateView *view=m_view; int count = KateFactory::self()->schemaManager()->list().count(); for (int z=0; zschemaManager()->list().operator[](z); if (names.contains(hlName) < 1) { names << hlName; popupMenu()->insertItem ( hlName, this, SLOT(setSchema(int)), 0, z+1); } } if (!view) return; popupMenu()->setItemChecked (last, false); popupMenu()->setItemChecked (view->renderer()->config()->schema()+1, true); last = view->renderer()->config()->schema()+1; } void KateViewSchemaAction::setSchema (int mode) { KateView *view=m_view; if (view) view->renderer()->config()->setSchema (mode-1); } // END SCHEMA ACTION //BEGIN KateStyleListView KateStyleListView::KateStyleListView( QWidget *parent, bool showUseDefaults ) : QListView( parent ) { addColumn( i18n("Context") ); - addColumn( SmallIconSet("text_bold"), QString::null/*i18n("Bold")*/ ); - addColumn( SmallIconSet("text_italic"), QString::null/*i18n("Italic")*/ ); + addColumn( SmallIconSet("text_bold"), QString::null ); + addColumn( SmallIconSet("text_italic"), QString::null ); addColumn( SmallIconSet("text_under"), QString::null ); addColumn( SmallIconSet("text_strike"), QString::null ); addColumn( i18n("Normal") ); addColumn( i18n("Selected") ); addColumn( i18n("Background") ); addColumn( i18n("Background Selected") ); if ( showUseDefaults ) addColumn( i18n("Use Default Style") ); connect( this, SIGNAL(mouseButtonPressed(int, QListViewItem*, const QPoint&, int)), this, SLOT(slotMousePressed(int, QListViewItem*, const QPoint&, int)) ); connect( this, SIGNAL(spacePressed(QListViewItem*)), this, SLOT(showPopupMenu(QListViewItem*)) ); // grap the bg color, selected color and default font normalcol = KGlobalSettings::textColor(); bgcol = *KateRendererConfig::global()->backgroundColor(); selcol = *KateRendererConfig::global()->selectionColor(); docfont = *KateRendererConfig::global()->font(); viewport()->setPaletteBackgroundColor( bgcol ); } void KateStyleListView::showPopupMenu( KateStyleListItem *i, const QPoint &globalPos, bool showtitle ) { KPopupMenu m( this ); KateAttribute *is = i->style(); int id; // the title is used, because the menu obscures the context name when // displayed on behalf of spacePressed(). QPixmap cl(16,16); cl.fill( i->style()->textColor() ); QPixmap scl(16,16); scl.fill( i->style()->selectedTextColor() ); if ( showtitle ) m.insertTitle( i->contextName(), KateStyleListItem::ContextName ); id = m.insertItem( i18n("&Bold"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Bold ); m.setItemChecked( id, is->bold() ); id = m.insertItem( i18n("&Italic"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Italic ); m.setItemChecked( id, is->italic() ); m.insertItem( QIconSet(cl), i18n("Normal &Color..."), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::Color ); m.insertItem( QIconSet(scl), i18n("&Selected Color..."), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::SelColor ); if ( ! i->isDefault() ) { id = m.insertItem( i18n("Use &Default Style"), this, SLOT(mSlotPopupHandler(int)), 0, KateStyleListItem::UseDefStyle ); m.setItemChecked( id, i->defStyle() ); } m.exec( globalPos ); } void KateStyleListView::showPopupMenu( QListViewItem *i ) { showPopupMenu( (KateStyleListItem*)i, viewport()->mapToGlobal(itemRect(i).topLeft()), true ); } void KateStyleListView::mSlotPopupHandler( int z ) { ((KateStyleListItem*)currentItem())->changeProperty( (KateStyleListItem::Property)z ); } // Because QListViewItem::activatePos() is going to become deprecated, // and also because this attempt offers more control, I connect mousePressed to this. void KateStyleListView::slotMousePressed(int btn, QListViewItem* i, const QPoint& pos, int c) { if ( i ) { if ( btn == Qt::RightButton ) { showPopupMenu( (KateStyleListItem*)i, /*mapToGlobal(*/pos/*)*/ ); } else if ( btn == Qt::LeftButton && c > 0 ) { // map pos to item/column and call KateStyleListItem::activate(col, pos) ((KateStyleListItem*)i)->activate( c, viewport()->mapFromGlobal( pos ) - QPoint( 0, itemRect(i).top() ) ); } } } //END //BEGIN KateStyleListItem static const int BoxSize = 16; static const int ColorBtnWidth = 32; KateStyleListItem::KateStyleListItem( QListView *parent, const QString & stylename, KateAttribute *style, ItemData *data ) : QListViewItem( parent, stylename ), ds( style ), st( data ) { if (!st) is = ds; else { is = new KateAttribute (*style); if (data->isSomethingSet()) *is += *data; } } void KateStyleListItem::updateStyle() { // nothing there, not update it, will crash if (!st) return; if ( is->itemSet(KateAttribute::Weight) ) { if ( is->weight() != st->weight()) st->setWeight( is->weight() ); } if ( is->itemSet(KateAttribute::Italic) ) { if ( is->italic() != st->italic()) st->setItalic( is->italic() ); } if ( is->itemSet(KateAttribute::StrikeOut) ) { if ( is->strikeOut() != st->strikeOut()) st->setStrikeOut( is->strikeOut() ); } if ( is->itemSet(KateAttribute::Underline) ) { if ( is->underline() != st->underline()) st->setUnderline( is->underline() ); } if ( is->itemSet(KateAttribute::Outline) ) { if ( is->outline() != st->outline()) st->setOutline( is->outline() ); } if ( is->itemSet(KateAttribute::TextColor) ) { if ( is->textColor() != st->textColor()) st->setTextColor( is->textColor() ); } if ( is->itemSet(KateAttribute::SelectedTextColor) ) { if ( is->selectedTextColor() != st->selectedTextColor()) st->setSelectedTextColor( is->selectedTextColor() ); } if ( is->itemSet(KateAttribute::BGColor) ) { if ( is->bgColor() != st->bgColor()) st->setBGColor( is->bgColor() ); } if ( is->itemSet(KateAttribute::SelectedBGColor) ) { if ( is->selectedBGColor() != st->selectedBGColor()) st->setSelectedBGColor( is->selectedBGColor() ); } //kdDebug()<<"after update: "<itemsSet()<bold()<<" ("<bold()<<")"<isSomethingSet(); } /* true for default styles */ bool KateStyleListItem::isDefault() { return st ? false : true; } int KateStyleListItem::width( const QFontMetrics & /*fm*/, const QListView * lv, int col ) const { int m = lv->itemMargin() * 2; switch ( col ) { case ContextName: // FIXME: width for name column should reflect bold/italic // (relevant for non-fixed fonts only - nessecary?) return QFontMetrics( ((KateStyleListView*)lv)->docfont).width( text(0) ) + m; case Bold: case Italic: case UseDefStyle: return BoxSize + m; case Color: case SelColor: case BgColor: case SelBgColor: return ColorBtnWidth +m; default: return 0; } } void KateStyleListItem::activate( int column, const QPoint &localPos ) { QListView *lv = listView(); int x = 0; for( int c = 0; c < column-1; c++ ) x += lv->columnWidth( c ); int w; switch( column ) { case Bold: case Italic: case Underline: case Strikeout: case UseDefStyle: w = BoxSize; break; case Color: case SelColor: case BgColor: case SelBgColor: w = ColorBtnWidth; break; default: return; } if ( !QRect( x, 0, w, BoxSize ).contains( localPos ) ) changeProperty( (Property)column ); } void KateStyleListItem::changeProperty( Property p ) { if ( p == Bold ) is->setBold( ! is->bold() ); else if ( p == Italic ) is->setItalic( ! is->italic() ); else if ( p == Underline ) is->setUnderline( ! is->underline() ); else if ( p == Strikeout ) is->setStrikeOut( ! is->strikeOut() ); else if ( p == UseDefStyle ) toggleDefStyle(); else setColor( p ); updateStyle (); ((KateStyleListView*)listView())->emitChanged(); } void KateStyleListItem::toggleDefStyle() { if ( *is == *ds ) { KMessageBox::information( listView(), i18n("\"Use Default Style\" will be automatically unset when you change any style properties."), i18n("Kate Styles"), "Kate hl config use defaults" ); } else { delete is; is = new KateAttribute( *ds ); repaint(); } } void KateStyleListItem::setColor( int column ) { QColor c; if ( column == Color) c = is->textColor(); else if ( column == SelColor ) c = is->selectedTextColor(); else if ( column == BgColor ) c = is->bgColor(); else if ( column == SelBgColor ) c = is->selectedBGColor(); if ( KColorDialog::getColor( c, listView() ) != QDialog::Accepted) return; - if (st && st->isSomethingSet()) setCustStyle(); + //if (st && st->isSomethingSet()) setCustStyle(); if ( column == Color) is->setTextColor( c ); else if ( column == SelColor ) is->setSelectedTextColor( c ); else if ( column == BgColor ) is->setBGColor( c ); else if ( column == SelBgColor ) is->setSelectedBGColor( c ); repaint(); } void KateStyleListItem::setCustStyle() { // is = st; // *is += *ds; // st->defStyle = 0; } -void KateStyleListItem::paintCell( QPainter *p, const QColorGroup& cg, int col, int width, int align ) +void KateStyleListItem::paintCell( QPainter *p, const QColorGroup& /*cg*/, int col, int width, int align ) { if ( !p ) return; QListView *lv = listView(); if ( !lv ) return; Q_ASSERT( lv ); //### p->fillRect( 0, 0, width, height(), QBrush( ((KateStyleListView*)lv)->bgcol ) ); + + // use a private color group and set the text/highlighted text colors + QColorGroup mcg = lv->viewport()->colorGroup(); + + if ( col ) // col 0 is drawn by the superclass method + p->fillRect( 0, 0, width, height(), QBrush( mcg.base() ) ); + + int marg = lv->itemMargin(); - // use a provate color group and set the text/highlighted text colors - QColorGroup mcg = cg; QColor c; switch ( col ) { case ContextName: { mcg.setColor(QColorGroup::Text, is->textColor()); mcg.setColor(QColorGroup::HighlightedText, is->selectedTextColor()); + // text background color + c = is->bgColor(); + if ( c.isValid() ) + mcg.setColor( QColorGroup::Base, c ); + if ( isSelected() ) + { + c = is->selectedBGColor(); + if ( c.isValid() ) + mcg.setColor( QColorGroup::Highlight, c ); + } QFont f ( ((KateStyleListView*)lv)->docfont ); p->setFont( is->font(f) ); // FIXME - repainting when text is cropped, and the column is enlarged is buggy. // Maybe I need painting the string myself :( QListViewItem::paintCell( p, mcg, col, width, align ); } break; case Bold: case Italic: case Underline: case Strikeout: case UseDefStyle: { // Bold/Italic/use default checkboxes // code allmost identical to QCheckListItem - // I use the text color of defaultStyles[0], normalcol in parent listview - mcg.setColor( QColorGroup::Text, ((KateStyleListView*)lv)->normalcol ); int x = 0; if ( align == AlignCenter ) { QFontMetrics fm( lv->font() ); x = (width - BoxSize - fm.width(text(0)))/2; } int y = (height() - BoxSize) / 2; if ( isEnabled() ) p->setPen( QPen( mcg.text(), 2 ) ); else p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ), 2 ) ); - if ( isSelected() && lv->header()->mapToSection( 0 ) != 0 ) +/* if ( isSelected() && lv->header()->mapToSection( 0 ) != 0 ) { p->fillRect( 0, 0, x + marg + BoxSize + 4, height(), mcg.brush( QColorGroup::Highlight ) ); if ( isEnabled() ) p->setPen( QPen( mcg.highlightedText(), 2 ) ); // FIXME! - use defaultstyles[0].selecol. luckily not used :) - } + }*/ p->drawRect( x+marg, y+2, BoxSize-4, BoxSize-4 ); x++; y++; if ( (col == Bold && is->bold()) || (col == Italic && is->italic()) || (col == Underline && is->underline()) || (col == Strikeout && is->strikeOut()) || (col == UseDefStyle && *is == *ds ) ) { QPointArray a( 7*2 ); int i, xx, yy; xx = x+1+marg; yy = y+5; for ( i=0; i<3; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy++; } yy -= 2; for ( i=3; i<7; i++ ) { a.setPoint( 2*i, xx, yy ); a.setPoint( 2*i+1, xx, yy+2 ); xx++; yy--; } p->drawLineSegments( a ); } } break; case Color: case SelColor: case BgColor: case SelBgColor: { if ( col == Color) c = is->textColor(); else if ( col == SelColor ) c = is->selectedTextColor(); - else if ( col == BgColor ) c = is->itemSet(KateAttribute::BGColor) ? is->bgColor() : ((KateStyleListView*)lv)->bgcol; - else if ( col == SelBgColor ) c = is->itemSet(KateAttribute::SelectedBGColor) ? is->selectedBGColor(): ((KateStyleListView*)lv)->bgcol; + else if ( col == BgColor ) c = is->itemSet(KateAttribute::BGColor) ? is->bgColor() : mcg.base(); + else if ( col == SelBgColor ) c = is->itemSet(KateAttribute::SelectedBGColor) ? is->selectedBGColor(): mcg.base(); // color "buttons" - mcg.setColor( QColorGroup::Text, ((KateStyleListView*)lv)->normalcol ); int x = 0; int y = (height() - BoxSize) / 2; if ( isEnabled() ) p->setPen( QPen( mcg.text(), 2 ) ); else p->setPen( QPen( lv->palette().color( QPalette::Disabled, QColorGroup::Text ), 2 ) ); p->drawRect( x+marg, y+2, ColorBtnWidth-4, BoxSize-4 ); p->fillRect( x+marg+1,y+3,ColorBtnWidth-7,BoxSize-7,QBrush( c ) ); } //case default: // no warning... } } //END // kate: space-indent on; indent-width 2; replace-tabs on;