Diffstat (limited to 'noncore/net/opieirc/ircquerytab.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp index b946174..869e4f7 100644 --- a/noncore/net/opieirc/ircquerytab.cpp +++ b/noncore/net/opieirc/ircquerytab.cpp | |||
@@ -1,83 +1,94 @@ | |||
1 | #include <qhbox.h> | 1 | #include <qhbox.h> |
2 | #include "ircquerytab.h" | 2 | #include "ircquerytab.h" |
3 | #include "ircservertab.h" | 3 | #include "ircservertab.h" |
4 | 4 | ||
5 | IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { | 5 | IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) { |
6 | m_mainWindow = mainWindow; | 6 | m_mainWindow = mainWindow; |
7 | m_parentTab = parentTab; | 7 | m_parentTab = parentTab; |
8 | m_lines = 0; | ||
8 | m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */ | 9 | m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */ |
9 | m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>"); | 10 | m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>"); |
10 | QHBox *hbox = new QHBox(this); | 11 | QHBox *hbox = new QHBox(this); |
11 | m_textview = new QTextView(hbox); | 12 | m_textview = new QTextView(hbox); |
12 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); | 13 | m_textview->setHScrollBarMode(QScrollView::AlwaysOff); |
13 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); | 14 | m_textview->setVScrollBarMode(QScrollView::AlwaysOn); |
14 | m_textview->setTextFormat(RichText); | 15 | m_textview->setTextFormat(RichText); |
15 | m_field = new QLineEdit(this); | 16 | m_field = new IRCHistoryLineEdit(this); |
16 | m_layout->add(hbox); | 17 | m_layout->add(hbox); |
17 | hbox->show(); | 18 | hbox->show(); |
18 | m_layout->add(m_field); | 19 | m_layout->add(m_field); |
19 | m_field->setFocus(); | 20 | m_field->setFocus(); |
20 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); | 21 | connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand())); |
21 | settingsChanged(); | 22 | settingsChanged(); |
22 | } | 23 | } |
23 | 24 | ||
24 | void IRCQueryTab::appendText(QString text) { | 25 | void IRCQueryTab::appendText(QString text) { |
25 | /* not using append because it creates layout problems */ | 26 | /* not using append because it creates layout problems */ |
26 | m_textview->setText(m_textview->text() + text); | 27 | QString txt = m_textview->text() + text + "\n"; |
28 | if (m_maxLines > 0 && m_lines >= m_maxLines) { | ||
29 | int firstBreak = txt.find('\n'); | ||
30 | if (firstBreak != -1) { | ||
31 | txt = "<qt bgcolor=\"" + m_backgroundColor + "\"/>" + txt.right(txt.length() - (firstBreak + 1)); | ||
32 | } | ||
33 | } else { | ||
34 | m_lines++; | ||
35 | } | ||
36 | m_textview->setText(txt); | ||
27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 37 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
28 | emit changed(this); | 38 | emit changed(this); |
29 | } | 39 | } |
30 | 40 | ||
31 | IRCQueryTab::~IRCQueryTab() { | 41 | IRCQueryTab::~IRCQueryTab() { |
32 | m_parentTab->removeQueryTab(this); | 42 | m_parentTab->removeQueryTab(this); |
33 | delete m_person; | 43 | delete m_person; |
34 | } | 44 | } |
35 | 45 | ||
36 | void IRCQueryTab::processCommand() { | 46 | void IRCQueryTab::processCommand() { |
37 | QString text = m_field->text(); | 47 | QString text = m_field->text(); |
38 | if (text.length()>0) { | 48 | if (text.length()>0) { |
39 | if (session()->isSessionActive()) { | 49 | if (session()->isSessionActive()) { |
40 | if (text.startsWith("/") && !text.startsWith("//")) { | 50 | if (text.startsWith("/") && !text.startsWith("//")) { |
41 | /* Command mode */ | 51 | /* Command mode */ |
42 | m_parentTab->executeCommand(this, text);; | 52 | m_parentTab->executeCommand(this, text);; |
43 | } else { | 53 | } else { |
44 | if (text.startsWith("//")) | 54 | if (text.startsWith("//")) |
45 | text = text.right(text.length()-1); | 55 | text = text.right(text.length()-1); |
46 | session()->sendMessage(m_person, m_field->text()); | 56 | session()->sendMessage(m_person, m_field->text()); |
47 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">> "+IRCOutput::toHTML(m_field->text())+"</font><br>"); | 57 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">> "+IRCOutput::toHTML(m_field->text())+"</font><br>"); |
48 | } | 58 | } |
49 | } else { | 59 | } else { |
50 | appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); | 60 | appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>"); |
51 | } | 61 | } |
52 | } | 62 | } |
53 | m_field->clear(); | 63 | m_field->clear(); |
54 | } | 64 | } |
55 | 65 | ||
56 | void IRCQueryTab::display(IRCOutput output) { | 66 | void IRCQueryTab::display(IRCOutput output) { |
57 | if (output.type() == OUTPUT_QUERYPRIVMSG) { | 67 | if (output.type() == OUTPUT_QUERYPRIVMSG) { |
58 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+m_person->nick()+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage() + "</font><br>"); | 68 | appendText("<font color=\"" + m_textColor + "\"><</font><font color=\"" + m_otherColor + "\">"+m_person->nick()+"</font><font color=\"" + m_textColor + "\">> " + output.htmlMessage() + "</font><br>"); |
59 | } else if (output.type() == OUTPUT_QUERYACTION) { | 69 | } else if (output.type() == OUTPUT_QUERYACTION) { |
60 | appendText("<font color=\"" + m_otherColor + "\">" + output.htmlMessage() + "<br>"); | 70 | appendText("<font color=\"" + m_otherColor + "\">" + output.htmlMessage() + "<br>"); |
61 | } | 71 | } |
62 | } | 72 | } |
63 | 73 | ||
64 | void IRCQueryTab::settingsChanged() { | 74 | void IRCQueryTab::settingsChanged() { |
65 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); | 75 | m_textview->setText("<qt bgcolor=\"" + m_backgroundColor + "\"/>"); |
76 | m_lines = 0; | ||
66 | } | 77 | } |
67 | 78 | ||
68 | QString IRCQueryTab::title() { | 79 | QString IRCQueryTab::title() { |
69 | return m_person->nick(); | 80 | return m_person->nick(); |
70 | } | 81 | } |
71 | 82 | ||
72 | IRCSession *IRCQueryTab::session() { | 83 | IRCSession *IRCQueryTab::session() { |
73 | return m_parentTab->session(); | 84 | return m_parentTab->session(); |
74 | } | 85 | } |
75 | 86 | ||
76 | void IRCQueryTab::remove() { | 87 | void IRCQueryTab::remove() { |
77 | m_mainWindow->killTab(this); | 88 | m_mainWindow->killTab(this); |
78 | } | 89 | } |
79 | 90 | ||
80 | IRCPerson *IRCQueryTab::person() { | 91 | IRCPerson *IRCQueryTab::person() { |
81 | return m_person; | 92 | return m_person; |
82 | } | 93 | } |
83 | 94 | ||