+ return false;
+}
+
+void InputLine::on_returnPressed() {
+ if(!text().isEmpty()) {
+ addToHistory(text());
+ emit sendText(text());
+ resetLine();
+ }
+}
+
+void InputLine::on_textChanged(QString newText) {
+ QStringList lineSeparators;
+ lineSeparators << QString("\r\n")
+ << QString('\n')
+ << QString('\r');
+
+ QString lineSep;
+ foreach(QString separator, lineSeparators) {
+ if(newText.contains(separator)) {
+ lineSep = separator;
+ break;
+ }
+ }
+
+ if(lineSep.isEmpty())
+ return;
+
+ QStringList lines = newText.split(lineSep, QString::SkipEmptyParts);
+
+ if(lines.count() >= 4) {
+ QString msg = tr("Do you really want to paste %n lines?", "", lines.count());
+ msg += "<p>";
+ for(int i = 0; i < 3; i++) {
+ msg += lines[i].left(40);
+ if(lines[i].count() > 40)
+ msg += "...";
+ msg += "<br />";
+ }
+ msg += "...</p>";
+ QMessageBox question(QMessageBox::NoIcon, tr("Paste Protection"), msg, QMessageBox::Yes|QMessageBox::No);
+ question.setDefaultButton(QMessageBox::No);
+#ifdef Q_WS_MAC
+ question.setWindowFlags(question.windowFlags() | Qt::Sheet); // Qt::Sheet is not ignored on other platforms as it should :/
+#endif
+ if(question.exec() == QMessageBox::No) {
+ clear();
+ return;
+ }
+ }
+
+ foreach(QString line, lines) {
+ if(!line.isEmpty()) {
+ resetLine();
+ insert(line);
+ emit returnPressed();
+ }
+ }
+
+// if(newText.contains(lineSep)) {
+// clear();
+// QString line = newText.section(lineSep, 0, 0);
+// QString remainder = newText.section(lineSep, 1);
+// insert(line);
+// emit returnPressed();
+// insert(remainder);
+// }