RKReadLineDialog::RKReadLineDialog (QWidget *parent, const QString &caption, const QString &prompt, RCommand *command) : KDialogBase (parent, 0, true, caption, KDialogBase::Ok | KDialogBase::Cancel) { RK_TRACE (DIALOGS); RK_ASSERT (command); QVBox *page = makeVBoxMainWidget (); new QLabel (caption, page); int screen_width = qApp->desktop ()->width () - 2*marginHint() - 2*spacingHint (); // TODO is this correct on xinerama? QString context = command->fullOutput (); if (!context.isEmpty ()) { new QLabel (i18n ("Context:"), page); QTextEdit *output = new QTextEdit (page); output->setUndoRedoEnabled (false); output->setTextFormat (QTextEdit::PlainText); output->setCurrentFont (QFont ("Courier")); output->setWordWrap (QTextEdit::NoWrap); output->setText (context); output->setReadOnly (true); int cwidth = output->contentsWidth (); output->setMinimumWidth (screen_width < cwidth ? screen_width : cwidth); output->scrollToBottom (); output->setFocusPolicy (QWidget::NoFocus); } QLabel *promptl = new QLabel (prompt, page); promptl->setAlignment (Qt::WordBreak | promptl->alignment ()); input = new QLineEdit (QString (), page); input->setMinimumWidth (fontMetrics ().maxWidth ()*20); input->setFocus (); }
bool ResizableMessageBox::event(QEvent *e) { bool result = QMessageBox::event(e); //QMessageBox::event in this case will call setFixedSize on the dialog frame, making it not resizable by the user if ( (e->type() == QEvent::LayoutRequest) || (e->type() == QEvent::Resize) ) { setMinimumHeight(0); setMaximumHeight(QWIDGETSIZE_MAX); setMinimumWidth(0); setMaximumWidth(QWIDGETSIZE_MAX); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // make the detailed text expanding QTextEdit *textEdit = findChild<QTextEdit *>(); if (textEdit) { textEdit->setMinimumHeight(0); textEdit->setMaximumHeight(QWIDGETSIZE_MAX); textEdit->setMinimumWidth(0); textEdit->setMaximumWidth(QWIDGETSIZE_MAX); textEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); } } return result; }
// Extract the wrapped text from a text edit, which performs // the wrapping only optically. void SubmitEditorWidget::wrapDescription() { if (!lineWrap()) return; const QChar newLine = QLatin1Char('\n'); QTextEdit e; e.setVisible(false); e.setMinimumWidth(1000); e.setFontPointSize(1.0); e.setLineWrapColumnOrWidth(d->m_ui.description->lineWrapColumnOrWidth()); e.setLineWrapMode(d->m_ui.description->lineWrapMode()); e.setWordWrapMode(d->m_ui.description->wordWrapMode()); e.setPlainText(d->m_description); d->m_description.clear(); QTextCursor cursor(e.document()); cursor.movePosition(QTextCursor::Start); while (!cursor.atEnd()) { const QString block = cursor.block().text(); if (block.startsWith(QLatin1Char('\t'))) { // Don't wrap d->m_description += block + newLine; cursor.movePosition(QTextCursor::EndOfBlock); } else { forever { cursor.select(QTextCursor::LineUnderCursor); d->m_description += cursor.selectedText(); d->m_description += newLine; cursor.clearSelection(); if (cursor.atBlockEnd()) break; cursor.movePosition(QTextCursor::NextCharacter); } } cursor.movePosition(QTextCursor::NextBlock); } }
void ItemHandlerMultiLine::Handle (const QDomElement& item, QWidget *pwidget) { QGridLayout *lay = qobject_cast<QGridLayout*> (pwidget->layout ()); QLabel *label = new QLabel (XSD_->GetLabel (item)); label->setWordWrap (false); const QVariant& value = XSD_->GetValue (item); QTextEdit *edit = new QTextEdit (); XSD_->SetTooltip (edit, item); edit->setPlainText (value.toStringList ().join ("\n")); edit->setObjectName (item.attribute ("property")); edit->setMinimumWidth (QApplication::fontMetrics () .width ("thisismaybeadefaultsetting")); connect (edit, SIGNAL (textChanged ()), this, SLOT (updatePreferences ())); edit->setProperty ("ItemHandler", QVariant::fromValue<QObject*> (this)); edit->setProperty ("SearchTerms", label->text ()); int row = lay->rowCount (); QString pos = item.attribute ("position"); if (pos == "bottom") { lay->addWidget (label, row, 0, Qt::AlignLeft); lay->addWidget (edit, row + 1, 0); } else if (pos == "right") { lay->addWidget (label, row, 0, Qt::AlignRight | Qt::AlignTop); lay->addWidget (edit, row, 1); } else if (pos == "left") { lay->addWidget (label, row, 1, Qt::AlignLeft | Qt::AlignTop); lay->addWidget (edit, row, 0); } else if (pos == "top") { lay->addWidget (edit, row, 0); lay->addWidget (label, row + 1, 0, Qt::AlignLeft); } else { lay->addWidget (label, row, 0, Qt::AlignRight | Qt::AlignTop); lay->addWidget (edit, row, 1); } lay->setContentsMargins (2, 2, 2, 2); }