/*******************  FUNCTION  *********************/
void svutResultFormatterStdColored::printMethodAndStatus(std::ostream& out, std::string name, svutStatus status)
{
	//sprintf(buffer," * %-40s     [ %s ]\n",testName.c_str(),statusName.c_str());
	//               " \033[32m*\033[0m %-40s     [ \033[%dm%s\033[0m ]\n"
	out << setColor(SVUT_STD_COLOR_GREEN) <<  " * " << unsetColor()
		<< setw(40) << left << name << "     [ "
		<< setStatusColor(status) << svutStatusInfo::getStatusName(status) << unsetColor()
		<< " ]" << endl;
}
    ColoredGraph solve(const Graph& gr) {
        GC_Naive_2 naive;
        auto result = naive.solve(gr);

        for (;;) {
            auto c_gr = result;

            auto colorCount = result.colorCount()-1;
            for (auto i = 0; i < c_gr.nodeCount(); ++i) {
                if (c_gr.color(i) == colorCount) c_gr.unsetColor(i);
            }

            for (;;) {
                auto uncolored = c_gr.uncoloredNodes();
                for (auto i : uncolored) {

                    bool success = c_gr.setColor(i);
                    if (success) continue;

                    SetColorUsingKempeChain(c_gr, i);
                }

                if (uncolored.size() == c_gr.uncoloredNodeCount()) break;
            }

            if (c_gr.uncoloredNodeCount() > 0) break;
            else {
                cout << "new sol: " << c_gr.colorCount() << endl;
                assert(isFeasibleColoring(c_gr));
                result = c_gr;
            }
        }
        return result;
    }
/*******************  FUNCTION  *********************/
void svutResultFormatterStdColored::printSummaryFinalStatus(std::ostream& out, svutStatus status)
{
	//sprintf(buffer,"|  STATUS   : %-12s  |\n",name);
	//               "|  STATUS   : \033[%dm%-12s\033[0m  |\n"
	out << "|  STATUS   : " << setStatusColor(status) << setw(12) << left
		<< svutStatusInfo::getStatusName(status) << unsetColor() << "  |" << endl;
}
/*******************  FUNCTION  *********************/
void svutResultFormatterStdColored::printSummaryStat(std::ostream& out, svutStatus status, unsigned int nb, unsigned int tot)
{
	 //sprintf(buffer,"|  %-9s: %4d (%3d %%)  |\n",name,nb,100*nb/tot);
	 //               "|  \033[%dm%-9s: %4d (%3d %%)\033[0m  |\n"
	 unsigned int perc;

	 //calc percentage
	 if (tot == 0)
		 perc = 0;
	 else
		 perc = (100*nb)/tot;

	 //display
	 out << "|  "
		<< setStatusColor(status) << setw(9) << left << svutStatusInfo::getStatusName(status) << ": "
		<< setw(4) << right << nb << " (" << setw(3) << right << perc << " %)" << unsetColor()
		<< "  |" << endl;
}
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() );
}