int Widgets::textInputBox(QWidget *parent, int width, int height, const QString& title, const QStringList& args, QString &result) { // KTextBox dlg(parent, 0, true, width, height, file); KDialog dlg( parent ); dlg.setCaption( title ); dlg.setButtons( KDialog::Ok ); dlg.setModal( true ); kapp->setTopWidget( &dlg ); KVBox* vbox = new KVBox(&dlg); dlg.setMainWidget(vbox); if( args.count() > 0 ) { QLabel *label = new QLabel(vbox); label->setText(args[0]); } KTextEdit *edit = new KTextEdit( vbox ); edit->setReadOnly(false); edit->setFocus(); if( args.count() > 1 ) edit->insertPlainText( args[1] ); if ( width > 0 && height > 0 ) dlg.setInitialSize( QSize( width, height ) ); handleXGeometry(&dlg); dlg.setCaption(title); const int returnDialogCode = dlg.exec(); result = edit->toPlainText(); return (returnDialogCode == KDialog::Accepted ? 0 : 1); }
void Klipper::slotEditData() { const HistoryStringItem* item = dynamic_cast<const HistoryStringItem*>(m_history->first()); KDialog dlg; dlg.setModal( true ); dlg.setCaption( i18n("Edit Contents") ); dlg.setButtons( KDialog::Ok | KDialog::Cancel ); KTextEdit *edit = new KTextEdit( &dlg ); if (item) { edit->setText( item->text() ); } edit->setFocus(); edit->setMinimumSize( 300, 40 ); dlg.setMainWidget( edit ); dlg.adjustSize(); if ( dlg.exec() == KDialog::Accepted ) { QString text = edit->toPlainText(); if (item) { m_history->remove( item ); } m_history->insert( new HistoryStringItem(text) ); if (m_myURLGrabber) { m_myURLGrabber->checkNewData( m_history->first() ); } } }
bool Item::mouseDoubleClickEvent( const EventInfo & eventInfo ) { Q_UNUSED(eventInfo); Property * property = 0l; Variant::Type::Value type = Variant::Type::None; const VariantDataMap::iterator variantDataEnd = m_variantData.end(); for ( VariantDataMap::iterator it = m_variantData.begin(); it != variantDataEnd; ++it ) { Property * current = *it; if ( current->type() == Variant::Type::Multiline || current->type() == Variant::Type::RichText ) { property = current; type = current->type(); break; } } if ( !property ) return false; if ( type == Variant::Type::Multiline ) { //KDialog * dlg = new KDialog( 0l, "", true, property->editorCaption(), KDialog::Ok|KDialog::Cancel|KDialog::User1, KDialog::Ok, // false, KStandardGuiItem::clear() ); KDialog * dlg = new KDialog( 0 ); dlg->setModal(true); dlg->setCaption( property->editorCaption() ); dlg->setButtons(KDialog::Ok|KDialog::Cancel|KDialog::User1); dlg->setDefaultButton(KDialog::Ok); dlg->showButtonSeparator(false); dlg->setButtonText(KDialog::User1, KStandardGuiItem::clear().text()); //QFrame *frame = dlg->makeMainWidget(); QFrame *frame = new QFrame(dlg); dlg->setMainWidget(frame); QVBoxLayout *layout = new QVBoxLayout( frame ); layout->setMargin(0); layout->setSpacing(dlg->spacingHint()); KTextEdit *textEdit = new KTextEdit( frame ); //textEdit->setTextFormat( Qt::PlainText ); // 2018.12.02 textEdit->setAcceptRichText(false); textEdit->setText( property->value().toString() ); layout->addWidget( textEdit, 10 ); textEdit->setFocus(); connect( dlg, SIGNAL( user1Clicked() ), textEdit, SLOT( clear() ) ); dlg->setMinimumWidth( 600 ); if ( dlg->exec() == KDialog::Accepted ) { property->setValue( textEdit->toPlainText() ); dataChanged(); p_itemDocument->setModified(true); } delete dlg; } else { // Is rich text RichTextEditorDlg * dlg = new RichTextEditorDlg( 0l, property->editorCaption() ); dlg->setText( property->value().toString() ); if ( dlg->exec() == KDialog::Accepted ) { property->setValue( dlg->text() ); dataChanged(); p_itemDocument->setModified(true); } delete dlg; } return true; }
/*! This function constructs a dialog which contains a label and a linedit for the given variable It return either the entered value or an empty string if the user hit cancel */ QString SnippetWidget::showSingleVarDialog(QString var, QMap<QString, QString> * mapSave, QRect & dlgSize) { // --BEGIN-- building a dynamic dialog QDialog dlg(this); dlg.setCaption(i18n("Enter Values for Variables")); QGridLayout * layout = new QGridLayout( &dlg, 1, 1, 11, 6, "layout"); QGridLayout * layoutTop = new QGridLayout( 0, 1, 1, 0, 6, "layoutTop"); QGridLayout * layoutVar = new QGridLayout( 0, 1, 1, 0, 6, "layoutVar"); QGridLayout * layoutBtn = new QGridLayout( 0, 2, 1, 0, 6, "layoutBtn"); KTextEdit *te = NULL; QLabel * labTop = NULL; QCheckBox * cb = NULL; labTop = new QLabel( &dlg, "label" ); layoutTop->addWidget(labTop, 0, 0); labTop->setText(i18n("Enter the replacement values for %1:").arg( var )); layout->addMultiCellLayout( layoutTop, 0, 0, 0, 1 ); cb = new QCheckBox( &dlg, "cbVar" ); cb->setChecked( FALSE ); cb->setText(i18n( "Make value &default" )); te = new KTextEdit( &dlg, "teVar" ); layoutVar->addWidget( te, 0, 1, Qt::AlignTop); layoutVar->addWidget( cb, 1, 1, Qt::AlignTop); if ((*mapSave)[var].length() > 0) { cb->setChecked( TRUE ); te->setText((*mapSave)[var]); } QToolTip::add( cb, i18n("Enable this to save the value entered to the right as the default value for this variable") ); QWhatsThis::add( cb, i18n("If you enable this option, the value entered to the right will be saved. " "If you use the same variable later, even in another snippet, the value entered to the right " "will be the default value for that variable.") ); layout->addMultiCellLayout( layoutVar, 1, 1, 0, 1 ); KPushButton * btn1 = new KPushButton( &dlg, "pushButton1" ); btn1->setText(i18n("&Cancel")); layoutBtn->addWidget( btn1, 0, 0 ); KPushButton * btn2 = new KPushButton( &dlg, "pushButton2" ); btn2->setText(i18n("&Apply")); btn2->setDefault( TRUE ); layoutBtn->addWidget( btn2, 0, 1 ); layout->addMultiCellLayout( layoutBtn, 2, 2, 0, 1 ); te->setFocus(); // --END-- building a dynamic dialog //connect the buttons to the QDialog default slots connect(btn1, SIGNAL(clicked()), &dlg, SLOT(reject()) ); connect(btn2, SIGNAL(clicked()), &dlg, SLOT(accept()) ); //execute the dialog QString strReturn = ""; if (dlgSize.isValid()) dlg.setGeometry(dlgSize); if ( dlg.exec() == QDialog::Accepted ) { if (cb->isChecked()) //if the checkbox is on; save the values for later (*mapSave)[var] = te->text(); else (*mapSave).erase(var); strReturn = te->text(); //copy the entered values back the the given map dlgSize = dlg.geometry(); } //do some cleanup delete cb; delete te; delete labTop; delete btn1; delete btn2; delete layoutTop; delete layoutVar; delete layoutBtn; delete layout; return strReturn; }