-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>InputWidget</class>
- <widget class="QWidget" name="InputWidget" >
- <property name="geometry" >
+ <widget class="QWidget" name="InputWidget">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>696</width>
- <height>28</height>
+ <width>759</width>
+ <height>202</height>
</rect>
</property>
- <property name="sizePolicy" >
- <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
- <property name="windowTitle" >
+ <property name="windowTitle">
<string>Form</string>
</property>
- <layout class="QHBoxLayout" >
- <property name="leftMargin" >
- <number>0</number>
- </property>
- <property name="topMargin" >
- <number>0</number>
- </property>
- <property name="rightMargin" >
- <number>0</number>
- </property>
- <property name="bottomMargin" >
- <number>0</number>
- </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <widget class="QComboBox" name="ownNick" />
- </item>
- <item>
- <widget class="InputLine" name="inputEdit" />
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QComboBox" name="ownNick"/>
+ </item>
+ <item>
+ <widget class="InputLine" name="inputEdit">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="verticalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="horizontalScrollBarPolicy">
+ <enum>Qt::ScrollBarAlwaysOff</enum>
+ </property>
+ <property name="lineWrapMode">
+ <enum>QTextEdit::NoWrap</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>InputLine</class>
- <extends>QLineEdit</extends>
+ <extends>QTextEdit</extends>
<header>inputline.h</header>
</customwidget>
</customwidgets>
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
+#include <QApplication>
+#include <QMenu>
+#include <QMessageBox>
+
#include "bufferview.h"
#include "graphicalui.h"
#include "inputline.h"
#include "tabcompleter.h"
+const int leftMargin = 3;
+
InputLine::InputLine(QWidget *parent)
:
#ifdef HAVE_KDE
KTextEdit(parent),
#else
- QLineEdit(parent),
+ QTextEdit(parent),
#endif
idx(0),
tabCompleter(new TabCompleter(this))
{
-#ifdef HAVE_KDE
-//This is done to make the KTextEdit look like a lineedit
+ // Make the QTextEdit look like a QLineEdit
#if QT_VERSION >= 0x040500
- document()->setDocumentMargin(0);
+ document()->setDocumentMargin(0); // new in Qt 4.5 and we really don't want it here
#endif
- setMaximumHeight(document()->size().toSize().height());
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAcceptRichText(false);
setLineWrapMode(NoWrap);
+#ifdef HAVE_KDE
enableFindReplace(false);
- connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
#endif
+ resetLine();
+ connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
connect(this, SIGNAL(returnPressed()), this, SLOT(on_returnPressed()));
connect(this, SIGNAL(textChanged(QString)), this, SLOT(on_textChanged(QString)));
}
void InputLine::setCustomFont(const QFont &font) {
setFont(font);
-#ifdef HAVE_KDE
- setMaximumHeight(document()->size().toSize().height() + 2*frameWidth());
-#endif
+}
+
+QSize InputLine::sizeHint() const {
+ // use the style to determine a decent size
+ QFontMetrics fm(font());
+ int h = fm.lineSpacing() + 2 * frameWidth();
+ QStyleOptionFrameV2 opt;
+ opt.initFrom(this);
+ opt.rect = QRect(0, 0, 100, h);
+ opt.lineWidth = lineWidth();
+ opt.midLineWidth = midLineWidth();
+ opt.state |= QStyle::State_Sunken;
+ QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), this);
+ return s;
+}
+
+QSize InputLine::minimumSizeHint() const {
+ return sizeHint();
}
bool InputLine::eventFilter(QObject *watched, QEvent *event) {
}
void InputLine::keyPressEvent(QKeyEvent * event) {
-
-#ifdef HAVE_KDE
if(event->matches(QKeySequence::Find)) {
QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar");
if(act) {
return;
}
}
-#endif
switch(event->key()) {
case Qt::Key_Up:
break;
- case Qt::Key_Select: // for Qtopia
- emit returnPressed();
- break;
-
-#ifdef HAVE_KDE
-//Since this is a ktextedit, we don't have this signal "natively"
case Qt::Key_Return:
case Qt::Key_Enter:
+ case Qt::Key_Select:
event->accept();
emit returnPressed();
break;
-#endif
-
default:
-#ifdef HAVE_KDE
- KTextEdit::keyPressEvent(event);
-#else
- QLineEdit::keyPressEvent(event);
-#endif
+ QTextEdit::keyPressEvent(event);
}
}
void InputLine::on_textChanged(QString newText) {
QStringList lineSeparators;
lineSeparators << QString("\r\n")
- << QString('\n')
- << QString('\r');
+ << QString('\n')
+ << QString('\r');
QString lineSep;
foreach(QString separator, lineSeparators) {
if(lineSep.isEmpty())
return;
- QStringList lines = newText.split(lineSep);
- clear();
+ QStringList lines = newText.split(lineSep, QString::SkipEmptyParts);
if(lines.count() >= 4) {
QString msg = tr("Do you really want to paste %n lines?", "", lines.count());
for(int i = 0; i < 3; i++) {
msg += lines[i].left(40);
if(lines[i].count() > 40)
- msg += "...";
+ 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);
+ question.setWindowFlags(question.windowFlags() | Qt::Sheet); // Qt::Sheet is not ignored on other platforms as it should :/
#endif
if(question.exec() == QMessageBox::No)
return;
foreach(QString line, lines) {
if(!line.isEmpty()) {
- clear();
+ resetLine();
insert(line);
emit returnPressed();
}
}
+
// if(newText.contains(lineSep)) {
// clear();
// QString line = newText.section(lineSep, 0, 0);
// every time the InputLine is cleared we also reset history index
idx = history.count();
clear();
+ QTextBlockFormat format = textCursor().blockFormat();
+ format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
+ textCursor().setBlockFormat(format);
}
void InputLine::showHistoryEntry() {
// if the user changed the history, display the changed line
- QString text = tempHistory.contains(idx) ? tempHistory[idx] : history[idx];
-#ifdef HAVE_KDE
- setPlainText(text);
+ setPlainText(tempHistory.contains(idx) ? tempHistory[idx] : history[idx]);
QTextCursor cursor = textCursor();
+ QTextBlockFormat format = cursor.blockFormat();
+ format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
+ cursor.setBlockFormat(format);
cursor.movePosition(QTextCursor::End);
setTextCursor(cursor);
-#else
- setText(text);
-#endif
}
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#ifndef _INPUTLINE_H_
-#define _INPUTLINE_H_
+#ifndef INPUTLINE_H_
+#define INPUTLINE_H_
-#include <QtGui>
+#include <QKeyEvent>
+#include <QTextEdit>
#ifdef HAVE_KDE
#include <KDE/KTextEdit>
#ifdef HAVE_KDE
KTextEdit
#else
- QLineEdit
+ QTextEdit
#endif
{
Q_OBJECT
void setCustomFont(const QFont &); // should be used instead setFont(), so we can set our size correctly
-#ifdef HAVE_KDE
-//Compatibility methods with the rest of the classes which expects this to be a QLineEdit
- QString text() { return toPlainText(); };
- int cursorPosition() { return textCursor().position(); };
- void insert(const QString &newText) { insertPlainText(newText); };
- void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); };
- bool hasSelectedText() { return textCursor().hasSelection(); };
-#endif
+ // Compatibility methods with the rest of the classes which still expect this to be a QLineEdit
+ inline QString text() { return toPlainText(); }
+ inline int cursorPosition() { return textCursor().position(); }
+ inline void insert(const QString &newText) { insertPlainText(newText); }
+ inline void backspace() { keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier)); }
+ inline bool hasSelectedText() { return textCursor().hasSelection(); }
+
+ virtual QSize sizeHint() const;
+ virtual QSize minimumSizeHint() const;
protected:
- // virtual bool event(QEvent *);
virtual void keyPressEvent(QKeyEvent * event);
virtual bool eventFilter(QObject *watched, QEvent *event);
private slots:
void on_returnPressed();
void on_textChanged(QString newText);
-#ifdef HAVE_KDE
-//Needed to emulate the signal that QLineEdit has
- void on_textChanged() { emit textChanged(toPlainText()); };
-#endif
+
+ // Needed to emulate the signal that QLineEdit has
+ inline void on_textChanged() { emit textChanged(toPlainText()); };
bool addToHistory(const QString &text, bool temporary = false);
signals:
void sendText(QString text);
-#ifdef HAVE_KDE
-//KTextEdit does not provide this signal, so we manually emit it in keyPressEvent()
+
+ // QTextEdit does not provide this signal, so we manually emit it in keyPressEvent()
void returnPressed();
void textChanged(QString newText);
-#endif
private:
QStringList history;