Ejemplo n.º 1
0
void KateStyleTreeWidgetItem::unsetColor( int c )
{
  if ( c == 100 && currentStyle->hasProperty(QTextFormat::BackgroundBrush) )
    currentStyle->clearProperty(QTextFormat::BackgroundBrush);
  else if ( c == 101 && currentStyle->hasProperty(KTextEditor::Attribute::SelectedBackground) )
    currentStyle->clearProperty(KTextEditor::Attribute::SelectedBackground);
  updateStyle();

  treeWidget()->emitChanged();
}
Ejemplo n.º 2
0
void KateStyleTreeWidgetItem::setColor( int column )
{
  QColor c; // use this
  QColor d; // default color
  if ( column == Foreground)
  {
    c = currentStyle->foreground().color();
    d = defaultStyle->foreground().color();
  }
  else if ( column == SelectedForeground )
  {
    c = currentStyle->selectedForeground().color();
    d = defaultStyle->selectedForeground().color();
  }
  else if ( column == Background )
  {
    c = currentStyle->background().color();
    d = defaultStyle->background().color();
  }
  else if ( column == SelectedBackground )
  {
    c = currentStyle->selectedBackground().color();
    d = defaultStyle->selectedBackground().color();
  }

  if ( KColorDialog::getColor( c, d, treeWidget() ) != QDialog::Accepted) return;

  bool def = ! c.isValid();

  // if set default, and the attrib is set in the default style use it
  // else if set default, unset it
  // else set the selected color
  switch (column)
  {
    case Foreground:
      if ( def )
      {
        if ( defaultStyle->hasProperty(QTextFormat::ForegroundBrush) )
          currentStyle->setForeground( defaultStyle->foreground());
        else
          currentStyle->clearProperty(QTextFormat::ForegroundBrush);
      }
      else
        currentStyle->setForeground( c );
    break;
    case SelectedForeground:
      if ( def )
      {
        if ( defaultStyle->hasProperty(KTextEditor::Attribute::SelectedForeground) )
          currentStyle->setSelectedForeground( defaultStyle->selectedForeground());
        else
          currentStyle->clearProperty(KTextEditor::Attribute::SelectedForeground);
      }
      else
        currentStyle->setSelectedForeground( c );
    break;
    case Background:
      if ( def )
      {
        if ( defaultStyle->hasProperty(QTextFormat::BackgroundBrush) )
          currentStyle->setBackground( defaultStyle->background());
        else
          currentStyle->clearProperty(QTextFormat::BackgroundBrush);
      }
      else
        currentStyle->setBackground( c );
    break;
    case SelectedBackground:
      if ( def )
      {
        if ( defaultStyle->hasProperty(KTextEditor::Attribute::SelectedBackground) )
          currentStyle->setSelectedBackground( defaultStyle->selectedBackground());
        else
          currentStyle->clearProperty(KTextEditor::Attribute::SelectedBackground);
      }
      else
        currentStyle->setSelectedBackground( c );
    break;
  }

  //FIXME
  //repaint();
}
Ejemplo n.º 3
0
void KateHlManager::getDefaults(const QString &schema, KateAttributeList &list, KConfig *cfg)
{
  KColorScheme scheme(QPalette::Active, KColorScheme::View);
  KColorScheme schemeSelected(QPalette::Active, KColorScheme::Selection);

  ///NOTE: it's important to append in the order of the HighlightInterface::DefaultStyle
  ///      enum, to make KateDocument::defaultStyle() work properly.

  { // dsNormal
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground().color() );
    attrib->setSelectedForeground( schemeSelected.foreground().color() );
    list.append(attrib);
  }
  { // dsKeyword
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground().color() );
    attrib->setSelectedForeground( schemeSelected.foreground().color() );
    attrib->setFontBold(true);
    list.append(attrib);
  }
  { // dsDataType
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() );
    list.append(attrib);
  }
  { // dsDecVal
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
    list.append(attrib);
  }
  { // dsBaseN
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
    list.append(attrib);
  }
  { // dsFloat
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NeutralText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NeutralText).color() );
    list.append(attrib);
  }
  { // dsChar
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::ActiveText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::ActiveText).color() );
    list.append(attrib);
  }
  { // dsString
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
    list.append(attrib);
  }
  { // dsComment
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::InactiveText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::InactiveText).color() );
    attrib->setFontItalic(true);
    list.append(attrib);
  }
  { // dsOthers
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::PositiveText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::PositiveText).color() );
    list.append(attrib);
  }
  { // dsAlert
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NegativeText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
    attrib->setFontBold(true);
    attrib->setBackground( scheme.background(KColorScheme::NegativeBackground).color() );
    list.append(attrib);
  }
  { // dsFunction
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::VisitedText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::VisitedText).color() );
    list.append(attrib);
  }
  { // dsRegionMarker
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::LinkText).color() );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::LinkText).color() );
    attrib->setBackground( scheme.background(KColorScheme::LinkBackground).color() );
    list.append(attrib);
  }
  { // dsError
    Attribute::Ptr attrib(new KTextEditor::Attribute());
    attrib->setForeground( scheme.foreground(KColorScheme::NegativeText) );
    attrib->setSelectedForeground( schemeSelected.foreground(KColorScheme::NegativeText).color() );
    attrib->setFontUnderline(true);
    list.append(attrib);
  }

  KConfigGroup config(cfg?cfg:KateHlManager::self()->self()->getKConfig(),
                      "Default Item Styles - Schema " + schema);

  for (uint z = 0; z < defaultStyles(); z++)
  {
    KTextEditor::Attribute::Ptr i = list.at(z);
    QStringList s = config.readEntry(defaultStyleName(z), QStringList());
    if (!s.isEmpty())
    {
      while( s.count()<9)
        s << "";

      QString tmp;
      QRgb col;

      tmp=s[0]; if (!tmp.isEmpty()) {
         col=tmp.toUInt(0,16); i->setForeground(QColor(col)); }

      tmp=s[1]; if (!tmp.isEmpty()) {
         col=tmp.toUInt(0,16); i->setSelectedForeground(QColor(col)); }

      tmp=s[2]; if (!tmp.isEmpty()) i->setFontBold(tmp!="0");

      tmp=s[3]; if (!tmp.isEmpty()) i->setFontItalic(tmp!="0");

      tmp=s[4]; if (!tmp.isEmpty()) i->setFontStrikeOut(tmp!="0");

      tmp=s[5]; if (!tmp.isEmpty()) i->setFontUnderline(tmp!="0");

      tmp=s[6]; if (!tmp.isEmpty()) {
        if ( tmp != "-" )
        {
          col=tmp.toUInt(0,16);
          i->setBackground(QColor(col));
        }
        else
          i->clearBackground();
      }
      tmp=s[7]; if (!tmp.isEmpty()) {
        if ( tmp != "-" )
        {
          col=tmp.toUInt(0,16);
          i->setSelectedBackground(QColor(col));
        }
        else
          i->clearProperty(KTextEditor::Attribute::SelectedBackground);
      }
      tmp=s[8]; if (!tmp.isEmpty() && tmp!=QLatin1String("---")) i->setFontFamily(tmp);
    }
  }
}