예제 #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();
}
예제 #2
0
KateWordCompletionView::KateWordCompletionView( KTextEditor::View *view, KActionCollection* ac )
  : QObject( view ),
    m_view( view ),
    m_dWCompletionModel( KateGlobal::self()->wordCompletionModel() ),
    d( new KateWordCompletionViewPrivate )
{
  d->isCompleting = false;
  d->dcRange = KTextEditor::Range::invalid();

  d->liRange = static_cast<KateDocument*>(m_view->document())->newMovingRange(KTextEditor::Range::invalid(), KTextEditor::MovingRange::DoNotExpand);

  KColorScheme colors(QPalette::Active);
  KTextEditor::Attribute::Ptr a = KTextEditor::Attribute::Ptr( new KTextEditor::Attribute() );
  a->setBackground( colors.background(KColorScheme::ActiveBackground) );
  a->setForeground( colors.foreground(KColorScheme::ActiveText) ); // ### this does 0
  d->liRange->setAttribute( a );

  KTextEditor::CodeCompletionInterface *cci = qobject_cast<KTextEditor::CodeCompletionInterface *>(view);

  KAction *action;

  if (cci)
  {
    cci->registerCompletionModel( m_dWCompletionModel );

    action = new KAction( i18n("Shell Completion"), this );
    ac->addAction( "doccomplete_sh", action );
    connect( action, SIGNAL(triggered()), this, SLOT(shellComplete()) );
  }


  action = new KAction( i18n("Reuse Word Above"), this );
  ac->addAction( "doccomplete_bw", action );
  action->setShortcut( Qt::CTRL+Qt::Key_8 );
  connect( action, SIGNAL(triggered()), this, SLOT(completeBackwards()) );

  action = new KAction( i18n("Reuse Word Below"), this );
  ac->addAction( "doccomplete_fw", action );
  action->setShortcut( Qt::CTRL+Qt::Key_9 );
  connect( action, SIGNAL(triggered()), this, SLOT(completeForwards()) );
}
예제 #3
0
void KateStyleTreeWidgetItem::changeProperty( int p )
{
  if ( p == Bold )
    currentStyle->setFontBold( ! currentStyle->fontBold() );
  else if ( p == Italic )
    currentStyle->setFontItalic( ! currentStyle->fontItalic() );
  else if ( p == Underline )
    currentStyle->setFontUnderline( ! currentStyle->fontUnderline() );
  else if ( p == StrikeOut )
    currentStyle->setFontStrikeOut( ! currentStyle->fontStrikeOut() );
  else if ( p == UseDefaultStyle )
    toggleDefStyle();
  else
    setColor( p );

  updateStyle ();

  treeWidget()->emitChanged();
}
예제 #4
0
void exportText(QString& ret,
                const QString& text,
                const KTextEditor::Attribute::Ptr& attrib)
{
    if ( !attrib || !attrib->hasAnyProperty()) {
        ret.append(text);
        return;
    }

    if ( attrib->fontBold() ) {
        ret.append("<b>");
    }
    if ( attrib->fontItalic() ) {
        ret.append("<i>");
    }

    bool writeForeground = attrib->hasProperty(QTextCharFormat::ForegroundBrush);
    bool writeBackground = attrib->hasProperty(QTextCharFormat::BackgroundBrush);

    if ( writeForeground || writeBackground ) {
        ret.append(QString("<span style='%1%2'>")
            .arg(writeForeground ? QString(QLatin1String("color:") 
                                            + attrib->foreground().color().name() 
                                            + QLatin1Char(';')) 
                                    : QString())
            .arg(writeBackground ? QString(QLatin1String("background:") 
                                            + attrib->background().color().name() 
                                            + QLatin1Char(';')) 
                                    : QString()));
    }
    ret.append(text);

    if ( writeBackground || writeForeground ) {
        ret.append("</span>");
    }
    if ( attrib->fontItalic() ) {
        ret.append("</i>");
    }
    if ( attrib->fontBold() ) {
        ret.append("</b>");
    }
}
예제 #5
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();
}
예제 #6
0
/* only true for a hl mode item using its default style */
bool KateStyleTreeWidgetItem::defStyle() const { return actualStyle && actualStyle->properties() != defaultStyle->properties(); }
예제 #7
0
void KateStyleTreeWidgetItem::updateStyle()
{
  // nothing there, not update it, will crash
  if (!actualStyle)
    return;

  if ( currentStyle->hasProperty(QTextFormat::FontWeight) )
  {
    if ( currentStyle->fontWeight() != actualStyle->fontWeight())
      actualStyle->setFontWeight( currentStyle->fontWeight() );
  }
  else actualStyle->clearProperty( QTextFormat::FontWeight );

  if ( currentStyle->hasProperty(QTextFormat::FontItalic) )
  {
    if ( currentStyle->fontItalic() != actualStyle->fontItalic())
      actualStyle->setFontItalic( currentStyle->fontItalic() );
  }
  else actualStyle->clearProperty( QTextFormat::FontItalic );

  if ( currentStyle->hasProperty(QTextFormat::FontStrikeOut) )
  {
    if ( currentStyle->fontStrikeOut() != actualStyle->fontStrikeOut())
      actualStyle->setFontStrikeOut( currentStyle->fontStrikeOut() );
  }
  else actualStyle->clearProperty( QTextFormat::FontStrikeOut );

  if ( currentStyle->hasProperty(QTextFormat::FontUnderline) )
  {
    if ( currentStyle->fontUnderline() != actualStyle->fontUnderline())
      actualStyle->setFontUnderline( currentStyle->fontUnderline() );
  }
  else actualStyle->clearProperty( QTextFormat::FontUnderline );

  if ( currentStyle->hasProperty(KTextEditor::Attribute::Outline) )
  {
    if ( currentStyle->outline() != actualStyle->outline())
      actualStyle->setOutline( currentStyle->outline() );
  }
  else actualStyle->clearProperty( KTextEditor::Attribute::Outline );

  if ( currentStyle->hasProperty(QTextFormat::ForegroundBrush) )
  {
    if ( currentStyle->foreground() != actualStyle->foreground())
      actualStyle->setForeground( currentStyle->foreground() );
  }
  else actualStyle->clearProperty( QTextFormat::ForegroundBrush );

  if ( currentStyle->hasProperty(KTextEditor::Attribute::SelectedForeground) )
  {
    if ( currentStyle->selectedForeground() != actualStyle->selectedForeground())
      actualStyle->setSelectedForeground( currentStyle->selectedForeground() );
  }
  else actualStyle->clearProperty( KTextEditor::Attribute::SelectedForeground );

  if ( currentStyle->hasProperty(QTextFormat::BackgroundBrush) )
  {
    if ( currentStyle->background() != actualStyle->background())
      actualStyle->setBackground( currentStyle->background() );
  }
  else actualStyle->clearProperty( QTextFormat::BackgroundBrush );

  if ( currentStyle->hasProperty(KTextEditor::Attribute::SelectedBackground) )
  {
    if ( currentStyle->selectedBackground() != actualStyle->selectedBackground())
      actualStyle->setSelectedBackground( currentStyle->selectedBackground() );
  }
  else actualStyle->clearProperty( KTextEditor::Attribute::SelectedBackground );
}
예제 #8
0
QVariant KateStyleTreeWidgetItem::data( int column, int role ) const
{
  if (column == Context) {
    switch (role) {
      case Qt::ForegroundRole:
        if (style()->hasProperty(QTextFormat::ForegroundBrush))
          return style()->foreground().color();
        break;

      case Qt::BackgroundRole:
        if (style()->hasProperty(QTextFormat::BackgroundBrush))
          return style()->background().color();
        break;

      case Qt::FontRole:
        return style()->font();
        break;
    }
  }

  if (role == Qt::CheckStateRole) {
    switch (column) {
      case Bold:
        return toCheckState(style()->fontBold());
      case Italic:
        return toCheckState(style()->fontItalic());
      case Underline:
        return toCheckState(style()->fontUnderline());
      case StrikeOut:
        return toCheckState(style()->fontStrikeOut());
      case UseDefaultStyle:
        /* can't compare all attributes, currentStyle has always more than defaultStyle (e.g. the item's name),
         * so we just compare the important ones:*/
        return toCheckState(
               currentStyle->foreground() == defaultStyle->foreground()
            && currentStyle->background() == defaultStyle->background()
            && currentStyle->selectedForeground() == defaultStyle->selectedForeground()
            && currentStyle->selectedBackground() == defaultStyle->selectedBackground()
            && currentStyle->fontBold() == defaultStyle->fontBold()
            && currentStyle->fontItalic() == defaultStyle->fontItalic()
            && currentStyle->fontUnderline() == defaultStyle->fontUnderline()
            && currentStyle->fontStrikeOut() == defaultStyle->fontStrikeOut());
    }
  }

  if (role == Qt::DisplayRole) {
    switch (column) {
      case Foreground:
        return style()->foreground();
      case SelectedForeground:
        return style()->selectedForeground();
      case Background:
        return style()->background();
      case SelectedBackground:
        return style()->selectedBackground();
    }
  }

  return QTreeWidgetItem::data(column, role);
}
예제 #9
0
void KateStyleTreeWidget::contextMenuEvent( QContextMenuEvent * event )
{
  KateStyleTreeWidgetItem *i = dynamic_cast<KateStyleTreeWidgetItem*>(itemAt(event->pos()));
  if (!i) return;

  KMenu m( this );
  KTextEditor::Attribute::Ptr currentStyle = i->style();
  // the title is used, because the menu obscures the context name when
  // displayed on behalf of spacePressed().
  QPainter p;
  p.setPen(Qt::black);

  QIcon cl = brushIcon( i->style()->foreground().color() );
  QIcon scl = brushIcon( i->style()->selectedForeground().color() );
  QIcon bgcl = brushIcon( i->style()->hasProperty(QTextFormat::BackgroundBrush) ? i->style()->background().color() : viewport()->palette().base().color() );
  QIcon sbgcl = brushIcon( i->style()->hasProperty(KTextEditor::Attribute::SelectedBackground) ? i->style()->selectedBackground().color() : viewport()->palette().base().color() );

  m.addTitle( i->contextName() );

  QAction* a = m.addAction( i18n("&Bold"), this, SLOT(changeProperty()) );
  a->setCheckable(true);
  a->setChecked( currentStyle->fontBold() );
  a->setData(KateStyleTreeWidgetItem::Bold);

  a = m.addAction( i18n("&Italic"), this, SLOT(changeProperty()) );
  a->setCheckable(true);
  a->setChecked( currentStyle->fontItalic() );
  a->setData(KateStyleTreeWidgetItem::Italic);

  a = m.addAction( i18n("&Underline"), this, SLOT(changeProperty()) );
  a->setCheckable(true);
  a->setChecked( currentStyle->fontUnderline() );
  a->setData(KateStyleTreeWidgetItem::Underline);

  a = m.addAction( i18n("S&trikeout"), this, SLOT(changeProperty()) );
  a->setCheckable(true);
  a->setChecked( currentStyle->fontStrikeOut() );
  a->setData(KateStyleTreeWidgetItem::StrikeOut);

  m.addSeparator();

  a = m.addAction( cl, i18n("Normal &Color..."), this, SLOT(changeProperty()) );
  a->setData(KateStyleTreeWidgetItem::Foreground);

  a = m.addAction( scl, i18n("&Selected Color..."), this, SLOT(changeProperty()) );
  a->setData(KateStyleTreeWidgetItem::SelectedForeground);

  a = m.addAction( bgcl, i18n("&Background Color..."), this, SLOT(changeProperty()) );
  a->setData(KateStyleTreeWidgetItem::Background);

  a = m.addAction( sbgcl, i18n("S&elected Background Color..."), this, SLOT(changeProperty()) );
  a->setData(KateStyleTreeWidgetItem::SelectedBackground);

  // Unset [some] colors. I could show one only if that button was clicked, but that
  // would disable setting this with the keyboard (how many aren't doing just
  // that every day? ;)
  // ANY ideas for doing this in a nicer way will be warmly wellcomed.
  KTextEditor::Attribute::Ptr style = i->style();
  if ( style->hasProperty( QTextFormat::BackgroundBrush) || style->hasProperty( KTextEditor::Attribute::SelectedBackground ) )
  {
    m.addSeparator();
    if ( style->hasProperty( QTextFormat::BackgroundBrush) ) {
      a = m.addAction( i18n("Unset Background Color"), this, SLOT(unsetColor()) );
      a->setData(100);
    }
    if ( style->hasProperty( KTextEditor::Attribute::SelectedBackground ) ) {
      a = m.addAction( i18n("Unset Selected Background Color"), this, SLOT(unsetColor()) );
      a->setData(101);
    }
  }

  if ( ! i->isDefault() && ! i->defStyle() ) {
    m.addSeparator();
    a = m.addAction( i18n("Use &Default Style"), this, SLOT(changeProperty()) );
    a->setCheckable(true);
    a->setChecked( i->defStyle() );
    a->setData(KateStyleTreeWidgetItem::UseDefaultStyle);
  }
  m.exec( event->globalPos() );
}
예제 #10
0
QList<QTextLayout::FormatRange> KateRenderer::decorationsForLine( const Kate::TextLine& textLine, int line, bool selectionsOnly, KateRenderRange* completionHighlight, bool completionSelected ) const
{
  QList<QTextLayout::FormatRange> newHighlight;

  // Don't compute the highlighting if there isn't going to be any highlighting
  QList<Kate::TextRange *> rangesWithAttributes = m_doc->buffer().rangesForLine (line, m_printerFriendly ? 0 : m_view, true);
  if (selectionsOnly || textLine->attributesList().count() || rangesWithAttributes.count()) {
    RenderRangeList renderRanges;

    // Add the inbuilt highlighting to the list
    NormalRenderRange* inbuiltHighlight = new NormalRenderRange();
    const QVector<Kate::TextLineData::Attribute> &al = textLine->attributesList();
    for (int i = 0; i < al.count(); ++i)
      if (al[i].length > 0 && al[i].attributeValue > 0)
        inbuiltHighlight->addRange(new KTextEditor::Range(KTextEditor::Cursor(line, al[i].offset), al[i].length), specificAttribute(al[i].attributeValue));
    renderRanges.append(inbuiltHighlight);

    if (!completionHighlight) {
      // check for dynamic hl stuff
      const QSet<Kate::TextRange *> *rangesMouseIn = m_view ? m_view->rangesMouseIn () : 0;
      const QSet<Kate::TextRange *> *rangesCaretIn = m_view ? m_view->rangesCaretIn () : 0;
      bool anyDynamicHlsActive = m_view && (!rangesMouseIn->empty() || !rangesCaretIn->empty());

      // sort all ranges, we want that the most specific ranges win during rendering, multiple equal ranges are kind of random, still better than old smart rangs behavior ;)
      qSort (rangesWithAttributes.begin(), rangesWithAttributes.end(), rangeLessThanForRenderer);

      // loop over all ranges
      for (int i = 0; i < rangesWithAttributes.size(); ++i) {
        // real range
        Kate::TextRange *kateRange = rangesWithAttributes[i];

        // calculate attribute, default: normal attribute
        KTextEditor::Attribute::Ptr attribute = kateRange->attribute();
        if (anyDynamicHlsActive) {
          // check mouse in
          if (KTextEditor::Attribute::Ptr attributeMouseIn = attribute->dynamicAttribute (KTextEditor::Attribute::ActivateMouseIn)) {
            if (rangesMouseIn->contains (kateRange))
              attribute = attributeMouseIn;
          }

          // check caret in
          if (KTextEditor::Attribute::Ptr attributeCaretIn = attribute->dynamicAttribute (KTextEditor::Attribute::ActivateCaretIn)) {
            if (rangesCaretIn->contains (kateRange))
              attribute = attributeCaretIn;
          }
        }

        // span range
        NormalRenderRange *additionaHl = new NormalRenderRange();
        additionaHl->addRange(new KTextEditor::Range (*kateRange), attribute);
        renderRanges.append(additionaHl);
      }
    } else {
      // Add the code completion arbitrary highlight to the list
      renderRanges.append(completionHighlight);
    }

    // Add selection highlighting if we're creating the selection decorations
    if ((selectionsOnly && showSelections() && m_view->selection()) || (completionHighlight && completionSelected) || m_view->blockSelection()) {
      NormalRenderRange* selectionHighlight = new NormalRenderRange();

      // Set up the selection background attribute TODO: move this elsewhere, eg. into the config?
      static KTextEditor::Attribute::Ptr backgroundAttribute;
      if (!backgroundAttribute)
        backgroundAttribute = KTextEditor::Attribute::Ptr(new KTextEditor::Attribute());

      backgroundAttribute->setBackground(config()->selectionColor());
      backgroundAttribute->setForeground(attribute(KTextEditor::HighlightInterface::dsNormal)->selectedForeground().color());

      // Create a range for the current selection
      if (completionHighlight && completionSelected)
        selectionHighlight->addRange(new KTextEditor::Range(line, 0, line + 1, 0), backgroundAttribute);
      else
        if(m_view->blockSelection() && m_view->selectionRange().overlapsLine(line))
          selectionHighlight->addRange(new KTextEditor::Range(m_doc->rangeOnLine(m_view->selectionRange(), line)), backgroundAttribute);
        else {
          selectionHighlight->addRange(new KTextEditor::Range(m_view->selectionRange()), backgroundAttribute);
        }

      renderRanges.append(selectionHighlight);
    // highlighting for the vi visual modes
    }

    KTextEditor::Cursor currentPosition, endPosition;

    // Calculate the range which we need to iterate in order to get the highlighting for just this line
    if (selectionsOnly) {
      if(m_view->blockSelection()) {
        KTextEditor::Range subRange = m_doc->rangeOnLine(m_view->selectionRange(), line);
        currentPosition = subRange.start();
        endPosition = subRange.end();
      } else {
        KTextEditor::Range rangeNeeded = m_view->selectionRange() & KTextEditor::Range(line, 0, line + 1, 0);

        currentPosition = qMax(KTextEditor::Cursor(line, 0), rangeNeeded.start());
        endPosition = qMin(KTextEditor::Cursor(line + 1, 0), rangeNeeded.end());
      }
    } else {
      currentPosition = KTextEditor::Cursor(line, 0);
      endPosition = KTextEditor::Cursor(line + 1, 0);
    }

    // Main iterative loop.  This walks through each set of highlighting ranges, and stops each
    // time the highlighting changes.  It then creates the corresponding QTextLayout::FormatRanges.
    while (currentPosition < endPosition) {
      renderRanges.advanceTo(currentPosition);

      if (!renderRanges.hasAttribute()) {
        // No attribute, don't need to create a FormatRange for this text range
        currentPosition = renderRanges.nextBoundary();
        continue;
      }

      KTextEditor::Cursor nextPosition = renderRanges.nextBoundary();

      // Create the format range and populate with the correct start, length and format info
      QTextLayout::FormatRange fr;
      fr.start = currentPosition.column();

      if (nextPosition < endPosition || endPosition.line() <= line) {
        fr.length = nextPosition.column() - currentPosition.column();

      } else {
        // +1 to force background drawing at the end of the line when it's warranted
        fr.length = textLine->length() - currentPosition.column() + 1;
      }

      KTextEditor::Attribute::Ptr a = renderRanges.generateAttribute();
      if (a) {
        fr.format = *a;

        if(selectionsOnly) {
              assignSelectionBrushesFromAttribute(fr, *a);
        }
      }

      newHighlight.append(fr);

      currentPosition = nextPosition;
    }

    if (completionHighlight)
      // Don't delete external completion render range
      renderRanges.removeAll(completionHighlight);

    qDeleteAll(renderRanges);
  }

  return newHighlight;
}
예제 #11
0
void KateHlManager::setDefaults(const QString &schema, KateAttributeList &list,KConfig *cfg)
{  
  cfg=cfg?cfg:KateHlManager::self()->self()->getKConfig();
  KConfigGroup config(cfg,
                      "Default Item Styles - Schema " + schema);

  for (uint z = 0; z < defaultStyles(); z++)
  {
    QStringList settings;
    KTextEditor::Attribute::Ptr p = list.at(z);

    settings<<(p->hasProperty(QTextFormat::ForegroundBrush)?QString::number(p->foreground().color().rgb(),16):"");
    settings<<(p->hasProperty(KTextEditor::Attribute::SelectedForeground)?QString::number(p->selectedForeground().color().rgb(),16):"");
    settings<<(p->hasProperty(QTextFormat::FontWeight)?(p->fontBold()?"1":"0"):"");
    settings<<(p->hasProperty(QTextFormat::FontItalic)?(p->fontItalic()?"1":"0"):"");
    settings<<(p->hasProperty(QTextFormat::FontStrikeOut)?(p->fontStrikeOut()?"1":"0"):"");
    settings<<(p->hasProperty(QTextFormat::FontUnderline)?(p->fontUnderline()?"1":"0"):"");
    settings<<(p->hasProperty(QTextFormat::BackgroundBrush)?QString::number(p->background().color().rgb(),16):"-");
    settings<<(p->hasProperty(KTextEditor::Attribute::SelectedBackground)?QString::number(p->selectedBackground().color().rgb(),16):"-");
    settings<<(p->hasProperty(QTextFormat::FontFamily)?(p->fontFamily()):QString());
    settings<<"---";

    config.writeEntry(defaultStyleName(z),settings);
  }

  emit changed();
}
예제 #12
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);
    }
  }
}
예제 #13
0
void HTMLExporter::exportText(const QString &text, const KTextEditor::Attribute::Ptr &attrib)
{
    if (!attrib || !attrib->hasAnyProperty() || attrib == m_defaultAttribute) {
        m_output << text.toHtmlEscaped();
        return;
    }

    if (attrib->fontBold()) {
        m_output << "<b>";
    }
    if (attrib->fontItalic()) {
        m_output << "<i>";
    }

    bool writeForeground = attrib->hasProperty(QTextCharFormat::ForegroundBrush)
                           && (!m_defaultAttribute || attrib->foreground().color() != m_defaultAttribute->foreground().color());
    bool writeBackground = attrib->hasProperty(QTextCharFormat::BackgroundBrush)
                           && (!m_defaultAttribute || attrib->background().color() != m_defaultAttribute->background().color());

    if (writeForeground || writeBackground) {
        m_output << QStringLiteral("<span style='%1%2'>")
                 .arg(writeForeground ? QString(QLatin1String("color:") + attrib->foreground().color().name() + QLatin1Char(';')) : QString())
                 .arg(writeBackground ? QString(QLatin1String("background:") + attrib->background().color().name() + QLatin1Char(';')) : QString());
    }

    m_output << text.toHtmlEscaped();

    if (writeBackground || writeForeground) {
        m_output << "</span>";
    }
    if (attrib->fontItalic()) {
        m_output << "</i>";
    }
    if (attrib->fontBold()) {
        m_output << "</b>";
    }
}