void RKProgressControlDialog::addOutput (const ROutput *output) { RK_TRACE (MISC); // scrolled all the way to the bottom? bool at_end = true; QScrollBar *bar = output_text->verticalScrollBar (); if (bar && (bar->value () < bar->maximum ())) at_end = false; if (output->type != last_output_type) { last_output_type = output->type; output_text->insertPlainText ("\n"); if (output->type == ROutput::Output) { output_text->setTextColor (Qt::black); } else { output_text->setTextColor (Qt::red); if (!isDetailsWidgetVisible ()) setDetailsWidgetVisible (true); error_indicator->show (); } } output_text->insertPlainText (output->output); // if previously at end, auto-scroll if (at_end && output_text->isVisible ()) scrollDown (); }
RKProgressControlDialog::RKProgressControlDialog (const QString &text, const QString &caption, int mode_flags, bool modal) : KDialog (0) { RK_TRACE (MISC); setAttribute (Qt::WA_DeleteOnClose, true); setModal (modal); setCaption (caption); KVBox *vbox = new KVBox (this); vbox->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); setMainWidget (vbox); QLabel *label = new QLabel (text, vbox); label->setWordWrap (true); error_indicator = new QLabel (i18n ("<b>There have been errors and / or warnings! See below for a transcript</b>"), vbox); QPalette palette = error_indicator->palette (); palette.setColor (error_indicator->foregroundRole (), QColor (255, 0, 0)); error_indicator->setPalette (palette); error_indicator->hide (); KVBox* output_box = new KVBox (); if (mode_flags & (RKProgressControl::IncludeErrorOutput | RKProgressControl::IncludeRegularOutput)) { QString ocaption; if (mode_flags & RKProgressControl::IncludeRegularOutput) { output_button_text = i18n ("Output"); ocaption = i18n ("Output:"); } else { output_button_text = i18n ("Errors / Warnings"); ocaption = i18n ("Errors / Warnings:"); } new QLabel (ocaption, output_box); output_text = new QTextEdit (output_box); output_text->setReadOnly (true); output_text->setPlainText (QString ()); output_text->setUndoRedoEnabled (false); output_text->setLineWrapMode (QTextEdit::NoWrap); output_text->setMinimumWidth (QFontMetrics (output_text->font ()).averageCharWidth () * RKSettingsModuleR::getDefaultWidth ()); output_box->setStretchFactor (output_text, 10); } setDetailsWidget (output_box); // it's important to use a queued connection, here. Otherwise, if the details widget gets shown due to error output, scrollDown() would only scroll to the position directly *above* the new output. connect (this, SIGNAL(aboutToShowDetails()), this, SLOT(scrollDown()), Qt::QueuedConnection); KDialog::ButtonCodes button_codes = KDialog::Cancel; if (mode_flags & RKProgressControl::OutputSwitchable) button_codes |= KDialog::Details; setButtons (button_codes); if (button_codes & KDialog::Details) setButtonText (KDialog::Details, output_button_text); if (mode_flags & RKProgressControl::AllowCancel) setButtonText (KDialog::Cancel, i18n ("Cancel")); else (setCloseTextToClose ()); if (mode_flags & RKProgressControl::OutputShownByDefault) setDetailsWidgetVisible (true); prevent_close = (mode_flags & RKProgressControl::PreventClose); last_output_type = ROutput::Output; is_done = false; }