File indexing completed on 2024-04-28 04:02:31
0001 /*************************************************************************** 0002 dlgmultiline.cpp - multi-line input dialog 0003 This file is a part of KMuddy distribution. 0004 ------------------- 0005 begin : Po Aug 26 2002 0006 copyright : (C) 2002 by Tomas Mecir 0007 email : kmuddy@kmuddy.com 0008 ***************************************************************************/ 0009 0010 /*************************************************************************** 0011 * * 0012 * This program is free software; you can redistribute it and/or modify * 0013 * it under the terms of the GNU General Public License as published by * 0014 * the Free Software Foundation; either version 2 of the License, or * 0015 * (at your option) any later version. * 0016 * * 0017 ***************************************************************************/ 0018 0019 #include "dlgmultiline.h" 0020 0021 #include <qlabel.h> 0022 #include <QTextEdit> 0023 #include <QVBoxLayout> 0024 #include <QHBoxLayout> 0025 #include <QPushButton> 0026 #include <QLineEdit> 0027 0028 #include <KLocalizedString> 0029 0030 dlgMultiLine::dlgMultiLine (QWidget *parent) : QDockWidget (parent) 0031 { 0032 //initial size 0033 setWindowTitle (i18n ("Multi-line input")); 0034 0035 //main widget 0036 QWidget *page = new QWidget (this); 0037 QVBoxLayout *layout = new QVBoxLayout (page); 0038 0039 setWidget (page); 0040 setFocusPolicy (Qt::StrongFocus); 0041 0042 //editor 0043 editor = new QTextEdit (page); 0044 editor->setAcceptRichText (false); 0045 editor->setWhatsThis( i18n ("Enter commands that are to be sent to the MUD. " 0046 "Each line represents one command.")); 0047 editor->setWordWrapMode (QTextOption::NoWrap); 0048 0049 layout->setSpacing (5); 0050 layout->addWidget (editor); 0051 0052 //prefix/suffix 0053 QFrame *ps = new QFrame (page); 0054 layout->addWidget (ps); 0055 QHBoxLayout *pslayout = new QHBoxLayout (ps); 0056 QLabel *l1 = new QLabel (i18n ("&Prefix:"), ps); 0057 prefix = new QLineEdit (ps); 0058 l1->setBuddy (prefix); 0059 QLabel *l2 = new QLabel (i18n ("&Suffix:"), ps); 0060 suffix = new QLineEdit (ps); 0061 l2->setBuddy (suffix); 0062 pslayout->setSpacing (5); 0063 pslayout->addWidget (l1); 0064 pslayout->addWidget (prefix); 0065 pslayout->addSpacing (5); 0066 pslayout->addWidget (l2); 0067 pslayout->addWidget (suffix); 0068 0069 QString hlptext = i18n ("Prefix and suffix may contain text, that will " 0070 "be added to the beginning (prefix) or ending (suffix) of every " 0071 "line written to the multi-line editor."); 0072 0073 prefix->setWhatsThis (hlptext); 0074 suffix->setWhatsThis (hlptext); 0075 0076 QFrame *bt = new QFrame (page); 0077 layout->addWidget (bt); 0078 QHBoxLayout *btlayout = new QHBoxLayout (bt); 0079 QPushButton *bt1 = new QPushButton (i18n ("&Send"), bt); 0080 bt1->setToolTip ( i18n ("Sends current text to the MUD.")); 0081 bt1->setWhatsThis (i18n ("This will send all the commands you've " 0082 "entered to the MUD. If you've entered prefix and/or suffix, they will be added " 0083 "to the beginning and ending of each command.")); 0084 QPushButton *bt2 = new QPushButton (i18n ("&Clear"), bt); 0085 bt2->setToolTip ( i18n ("Clears window contents.")); 0086 btlayout->addWidget (bt1); 0087 btlayout->addWidget (bt2); 0088 connect (bt1, &QPushButton::clicked, this, &dlgMultiLine::sendClicked); 0089 connect (bt2, &QPushButton::clicked, editor, &QTextEdit::clear); 0090 } 0091 0092 dlgMultiLine::~dlgMultiLine () 0093 { 0094 } 0095 0096 QSize dlgMultiLine::sizeHint() const 0097 { 0098 return QSize (400, 250); 0099 } 0100 0101 void dlgMultiLine::setFont (const QFont &font) 0102 { 0103 editor->setFont (font); 0104 } 0105 0106 void dlgMultiLine::sendClicked () 0107 { 0108 QStringList text = editor->toPlainText().split ("\n"); 0109 QString s1 = prefix->text(); 0110 QString s2 = suffix->text(); 0111 if ((!s1.isEmpty()) && (!s1.endsWith (' '))) s1 += " "; 0112 if ((!s2.isEmpty()) && (!s2.endsWith (' '))) s2 = " " + s2; 0113 QStringList cmds; 0114 // append prefix/suffix 0115 QStringList::iterator it; 0116 for (it = text.begin(); it != text.end(); ++it) { 0117 cmds << (s1 + *it + s2); 0118 } 0119 emit commands (cmds); 0120 } 0121 0122 #include "moc_dlgmultiline.cpp"