summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc
authorwazlaf <wazlaf>2002-09-30 08:07:05 (UTC)
committer wazlaf <wazlaf>2002-09-30 08:07:05 (UTC)
commita999acbcd1b8bc1715f2ad2dda6acedf423b89ea (patch) (side-by-side diff)
tree898d433efa8ff3b25a5d10ab4dc4a0a9bc415104 /noncore/net/opieirc
parent75dccdfe90324e9ff2426930ae185c3a6bdab734 (diff)
downloadopie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.zip
opie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.tar.gz
opie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.tar.bz2
tabs now change their color when actions occur
Diffstat (limited to 'noncore/net/opieirc') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opieirc/ircchanneltab.cpp1
-rw-r--r--noncore/net/opieirc/ircmisc.cpp35
-rw-r--r--noncore/net/opieirc/ircmisc.h50
-rw-r--r--noncore/net/opieirc/ircquerytab.cpp1
-rw-r--r--noncore/net/opieirc/ircservertab.cpp1
-rw-r--r--noncore/net/opieirc/irctab.cpp8
-rw-r--r--noncore/net/opieirc/irctab.h5
-rw-r--r--noncore/net/opieirc/mainwindow.cpp14
-rw-r--r--noncore/net/opieirc/mainwindow.h6
9 files changed, 107 insertions, 14 deletions
diff --git a/noncore/net/opieirc/ircchanneltab.cpp b/noncore/net/opieirc/ircchanneltab.cpp
index c1695db..ddd6cf1 100644
--- a/noncore/net/opieirc/ircchanneltab.cpp
+++ b/noncore/net/opieirc/ircchanneltab.cpp
@@ -26,48 +26,49 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW
m_popup = new QPopupMenu(m_list);
/* Required so that embedded-style "right" clicks work */
QPEApplication::setStylusOperation(m_list->viewport(), QPEApplication::RightOnHold);
connect(m_list, SIGNAL(mouseButtonPressed(int, QListBoxItem *, const QPoint&)), this, SLOT(mouseButtonPressed(int, QListBoxItem *, const QPoint &)));
/* Construct the popup menu */
QPopupMenu *ctcpMenu = new QPopupMenu(m_list);
m_popup->insertItem(Resource::loadPixmap("opieirc/ctcp"), tr("CTCP"), ctcpMenu);
m_popup->insertItem(Resource::loadPixmap("opieirc/query"), tr("Query"), this, SLOT(popupQuery()));
ctcpMenu->insertItem(Resource::loadPixmap("opieirc/ping"), tr("Ping"), this, SLOT(popupPing()));
ctcpMenu->insertItem(Resource::loadPixmap("opieirc/version"), tr("Version"), this, SLOT(popupVersion()));
ctcpMenu->insertItem(Resource::loadPixmap("opieirc/whois"), tr("Whois"), this, SLOT(popupWhois()));
m_layout->add(hbox);
hbox->show();
m_layout->add(m_field);
m_field->setFocus();
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
settingsChanged();
}
void IRCChannelTab::appendText(QString text) {
/* not using append because it creates layout problems */
m_textview->setText(m_textview->text() + text);
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
IRCChannelTab::~IRCChannelTab() {
m_parentTab->removeChannelTab(this);
}
void IRCChannelTab::processCommand() {
QString text = m_field->text();
if (text.length()>0) {
if (session()->isSessionActive()) {
if (text.startsWith("/") && !text.startsWith("//")) {
/* Command mode */
m_parentTab->executeCommand(this, text);;
} else {
if (text.startsWith("//"))
text = text.right(text.length()-1);
session()->sendMessage(m_channel, m_field->text());
appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">&gt; "+IRCOutput::toHTML(m_field->text())+"</font><br>");
}
} else {
appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>");
}
}
m_field->clear();
diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp
index f41a89a..dd7292c 100644
--- a/noncore/net/opieirc/ircmisc.cpp
+++ b/noncore/net/opieirc/ircmisc.cpp
@@ -1,31 +1,66 @@
#include <opie/colordialog.h>
#include <qlayout.h>
+#include <stdio.h>
#include "ircmisc.h"
IRCColorLabel::IRCColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QLabel(parent, name, f) {
m_color = color;
setAlignment(AlignVCenter | AlignCenter);
setFrameStyle(QFrame::StyledPanel);
setFrameShadow(QFrame::Sunken);
setBackgroundColor(m_color);
}
void IRCColorLabel::mousePressEvent(QMouseEvent *) {
m_color = OColorDialog::getColor(m_color);
setBackgroundColor(m_color);
}
QColor IRCColorLabel::color() {
return m_color;
}
IRCFramedColorLabel::IRCFramedColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) {
QVBoxLayout *layout = new QVBoxLayout(this, 10, 0);
m_label = new IRCColorLabel(color, this);
layout->addWidget(m_label);
}
QColor IRCFramedColorLabel::color() {
return m_label->color();
}
+IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) {
+}
+
+int IRCTabBar::insertTab(QTab *tab, int index = -1) {
+ if (m_colors.size() == (unsigned int)count())
+ m_colors.resize(m_colors.size() * 2 + 1);
+ if (index == -1)
+ m_colors.insert(count(), &black);
+ else
+ m_colors.insert(index, &black);
+ return QTabBar::insertTab(tab, index);
+}
+
+void IRCTabBar::setTabColor(int index, const QColor *color) {
+ m_colors.insert(index, color);
+ update();
+}
+
+void IRCTabBar::paintLabel(QPainter* p, const QRect& br, QTab* t, bool focus) const {
+ QRect r = br;
+ QTabBar::paintLabel(p, br, t, focus);
+ if (t->id == currentTab())
+ r.setBottom(r.bottom() - style().defaultFrameWidth());
+ p->setPen(*m_colors.at(t->id));
+ p->drawText(r, AlignCenter | ShowPrefix, t->label);
+}
+
+IRCTabWidget::IRCTabWidget(QWidget *parent, const char *name) : QTabWidget(parent, name) {
+ setTabBar(new IRCTabBar(this, "tab control"));
+}
+
+void IRCTabWidget::setTabColor(int index, const QColor *color) {
+ ((IRCTabBar *)tabBar())->setTabColor(index, color);
+}
diff --git a/noncore/net/opieirc/ircmisc.h b/noncore/net/opieirc/ircmisc.h
index 1ea04c8..4df6ce0 100644
--- a/noncore/net/opieirc/ircmisc.h
+++ b/noncore/net/opieirc/ircmisc.h
@@ -1,44 +1,72 @@
/*
OpieIRC - An embedded IRC client
Copyright (C) 2002 Wenzel Jakob
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __IRCMISC_H
#define __IRCMISC_H
+#include <qtabwidget.h>
+#include <qtabbar.h>
#include <qlabel.h>
#include <qcolor.h>
+#include <qvector.h>
+
+/* IRCFramedColorLabel is used to display a color */
class IRCColorLabel : public QLabel {
- public:
- IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
- QColor color();
- void mousePressEvent(QMouseEvent *event);
- protected:
- QColor m_color;
+ Q_OBJECT
+public:
+ IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
+ QColor color();
+ void mousePressEvent(QMouseEvent *event);
+protected:
+ QColor m_color;
};
class IRCFramedColorLabel : public QWidget {
- public:
- IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
- QColor color();
- protected:
- IRCColorLabel *m_label;
+ Q_OBJECT
+public:
+ IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0);
+ QColor color();
+protected:
+ IRCColorLabel *m_label;
+};
+
+/* Custom colored QTabWidget */
+
+class IRCTabWidget : public QTabWidget {
+ Q_OBJECT
+public:
+ IRCTabWidget(QWidget *parent = 0, const char *name = 0);
+ void setTabColor(int index, const QColor *color);
+};
+
+class IRCTabBar : public QTabBar {
+ Q_OBJECT
+public:
+ IRCTabBar(QWidget *parent = 0, const char *name = 0);
+ void setTabColor(int index, const QColor *color);
+protected:
+ void paintLabel(QPainter*, const QRect&, QTab*, bool) const;
+ int insertTab(QTab *, int index = -1);
+protected:
+ QVector<QColor> m_colors;
};
#endif /* __IRCMISC_H */
diff --git a/noncore/net/opieirc/ircquerytab.cpp b/noncore/net/opieirc/ircquerytab.cpp
index c6b8211..b946174 100644
--- a/noncore/net/opieirc/ircquerytab.cpp
+++ b/noncore/net/opieirc/ircquerytab.cpp
@@ -4,48 +4,49 @@
IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
m_mainWindow = mainWindow;
m_parentTab = parentTab;
m_person = new IRCPerson(*person); /* We need this (the person might sign off and the original IRCPerson gets deleted) */
m_description->setText(tr("Talking to ") + " <b>" + person->nick() + "</b>");
QHBox *hbox = new QHBox(this);
m_textview = new QTextView(hbox);
m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
m_textview->setTextFormat(RichText);
m_field = new QLineEdit(this);
m_layout->add(hbox);
hbox->show();
m_layout->add(m_field);
m_field->setFocus();
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
settingsChanged();
}
void IRCQueryTab::appendText(QString text) {
/* not using append because it creates layout problems */
m_textview->setText(m_textview->text() + text);
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
IRCQueryTab::~IRCQueryTab() {
m_parentTab->removeQueryTab(this);
delete m_person;
}
void IRCQueryTab::processCommand() {
QString text = m_field->text();
if (text.length()>0) {
if (session()->isSessionActive()) {
if (text.startsWith("/") && !text.startsWith("//")) {
/* Command mode */
m_parentTab->executeCommand(this, text);;
} else {
if (text.startsWith("//"))
text = text.right(text.length()-1);
session()->sendMessage(m_person, m_field->text());
appendText("<font color=\"" + m_textColor + "\">&lt;</font><font color=\"" + m_selfColor + "\">"+m_parentTab->server()->nick()+"</font><font color=\"" + m_textColor + "\">&gt; "+IRCOutput::toHTML(m_field->text())+"</font><br>");
}
} else {
appendText("<font color=\"" + m_errorColor + "\">"+tr("Disconnected")+"</font><br>");
}
}
diff --git a/noncore/net/opieirc/ircservertab.cpp b/noncore/net/opieirc/ircservertab.cpp
index d16c05f..4ed5364 100644
--- a/noncore/net/opieirc/ircservertab.cpp
+++ b/noncore/net/opieirc/ircservertab.cpp
@@ -4,48 +4,49 @@
IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *parent, const char *name, WFlags f) : IRCTab(parent, name, f) {
m_server = server;
m_session = new IRCSession(&m_server);
m_mainWindow = mainWindow;
m_close = FALSE;
m_description->setText(tr("Connection to")+" <b>" + server.hostname() + ":" + QString::number(server.port()) + "</b>");
m_textview = new QTextView(this);
m_textview->setHScrollBarMode(QScrollView::AlwaysOff);
m_textview->setVScrollBarMode(QScrollView::AlwaysOn);
m_textview->setTextFormat(RichText);
m_layout->add(m_textview);
m_field = new QLineEdit(this);
m_layout->add(m_field);
connect(m_field, SIGNAL(returnPressed()), this, SLOT(processCommand()));
m_field->setFocus();
connect(m_session, SIGNAL(outputReady(IRCOutput)), this, SLOT(display(IRCOutput)));
settingsChanged();
}
void IRCServerTab::appendText(QString text) {
/* not using append because it creates layout problems */
m_textview->setText(m_textview->text() + text);
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
IRCServerTab::~IRCServerTab() {
delete m_session;
}
void IRCServerTab::removeChannelTab(IRCChannelTab *tab) {
m_channelTabs.remove(tab);
}
void IRCServerTab::removeQueryTab(IRCQueryTab *tab) {
m_queryTabs.remove(tab);
}
void IRCServerTab::addQueryTab(IRCQueryTab *tab) {
m_queryTabs.append(tab);
}
QString IRCServerTab::title() {
return "Server";
}
IRCSession *IRCServerTab::session() {
return m_session;
diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp
index 6b578d1..a4dd7e2 100644
--- a/noncore/net/opieirc/irctab.cpp
+++ b/noncore/net/opieirc/irctab.cpp
@@ -5,24 +5,32 @@
QString IRCTab::m_errorColor;
QString IRCTab::m_serverColor;
QString IRCTab::m_textColor;
QString IRCTab::m_backgroundColor;
QString IRCTab::m_selfColor;
QString IRCTab::m_otherColor;
QString IRCTab::m_notificationColor;
IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) {
m_layout = new QVBoxLayout(this);
QHBoxLayout *descLayout = new QHBoxLayout(m_layout);
descLayout->setMargin(5);
m_description = new QLabel(tr("Missing description"), this);
descLayout->addWidget(m_description);
descLayout->setStretchFactor(m_description, 5);
QPushButton *close = new QPushButton(this);
close->setPixmap(Resource::loadPixmap("close"));
connect(close, SIGNAL(clicked()), this, SLOT(remove()));
descLayout->addWidget(close);
descLayout->setStretchFactor(m_description, 1);
}
+
+void IRCTab::setID(int id) {
+ m_id = id;
+}
+
+int IRCTab::id() {
+ return m_id;
+}
diff --git a/noncore/net/opieirc/irctab.h b/noncore/net/opieirc/irctab.h
index 248ea13..e3a1857 100644
--- a/noncore/net/opieirc/irctab.h
+++ b/noncore/net/opieirc/irctab.h
@@ -14,45 +14,50 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __IRCTAB_H
#define __IRCTAB_H
#include <qwidget.h>
#include <qtextview.h>
#include <qlineedit.h>
#include <qlabel.h>
#include <qlayout.h>
#include "ircsession.h"
/* This is the base class for any tabs which need to be integrated into
the main GUI tab widget */
class IRCTab : public QWidget {
Q_OBJECT
public:
IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
+ void setID(int id);
+ int id();
virtual QString title() = 0;
virtual IRCSession *session() = 0;
virtual void appendText(QString text) = 0;
+signals:
+ void changed(IRCTab *);
public slots:
virtual void remove() = 0;
virtual void settingsChanged() = 0;
protected:
QLabel *m_description;
QVBoxLayout *m_layout;
+ int m_id;
public:
/* Configuration shared accross all instances - contains HTML style colors (#rrggbb) */
static QString m_errorColor;
static QString m_serverColor;
static QString m_textColor;
static QString m_backgroundColor;
static QString m_selfColor;
static QString m_otherColor;
static QString m_notificationColor;
};
#endif /* __IRCTAB_H */
diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp
index d78e5ab..fe59c3b 100644
--- a/noncore/net/opieirc/mainwindow.cpp
+++ b/noncore/net/opieirc/mainwindow.cpp
@@ -1,69 +1,81 @@
#include <qpe/qpemenubar.h>
#include <qpe/resource.h>
#include <qpe/config.h>
#include <qpopupmenu.h>
#include "mainwindow.h"
#include "ircservertab.h"
#include "ircserverlist.h"
#include "ircsettings.h"
MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) {
setCaption(tr("IRC Client"));
- m_tabWidget = new QTabWidget(this);
+ m_tabWidget = new IRCTabWidget(this);
+ connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *)));
setCentralWidget(m_tabWidget);
setToolBarsMovable(FALSE);
QPEMenuBar *menuBar = new QPEMenuBar(this);
QPopupMenu *irc = new QPopupMenu(this);
menuBar->insertItem(tr("IRC"), irc);
QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0);
connect(a, SIGNAL(activated()), this, SLOT(newConnection()));
a->addTo(irc);
a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0);
connect(a, SIGNAL(activated()), this, SLOT(settings()));
a->addTo(irc);
loadSettings();
}
void MainWindow::loadSettings() {
Config config("OpieIRC");
config.setGroup("OpieIRC");
IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF");
IRCTab::m_textColor = config.readEntry("TextColor", "#000000");
IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000");
IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000");
IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB");
IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF");
IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300");
}
+void MainWindow::selected(QWidget *) {
+ m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), &black);
+}
+
void MainWindow::addTab(IRCTab *tab) {
+ connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *)));
m_tabWidget->addTab(tab, tab->title());
m_tabWidget->showPage(tab);
+ tab->setID(m_tabWidget->currentPageIndex());
m_tabs.append(tab);
}
+void MainWindow::changeEvent(IRCTab *tab) {
+ if (tab->id() != m_tabWidget->currentPageIndex())
+ m_tabWidget->setTabColor(tab->id(), &blue);
+}
+
void MainWindow::killTab(IRCTab *tab) {
m_tabWidget->removePage(tab);
m_tabs.remove(tab);
/* there might be nicer ways to do this .. */
delete tab;
}
void MainWindow::newConnection() {
IRCServerList list(this, "ServerList", TRUE);
if (list.exec() == QDialog::Accepted && list.hasServer()) {
IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget);
addTab(serverTab);
serverTab->doConnect();
}
}
void MainWindow::settings() {
IRCSettings settings(this, "Settings", TRUE);
if (settings.exec() == QDialog::Accepted) {
QListIterator<IRCTab> it(m_tabs);
for (; it.current(); ++it) {
/* Inform all tabs about the new settings */
it.current()->settingsChanged();
}
diff --git a/noncore/net/opieirc/mainwindow.h b/noncore/net/opieirc/mainwindow.h
index d057178..9946f10 100644
--- a/noncore/net/opieirc/mainwindow.h
+++ b/noncore/net/opieirc/mainwindow.h
@@ -3,46 +3,48 @@
Copyright (C) 2002 Wenzel Jakob
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __MAINWINDOW_H
#define __MAINWINDOW_H
#include <qmainwindow.h>
#include <qaction.h>
#include <qlist.h>
-#include <qtabwidget.h>
#include "mainwindow.h"
+#include "ircmisc.h"
#include "irctab.h"
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
void addTab(IRCTab *tab);
void killTab(IRCTab *tab);
protected slots:
void newConnection();
void settings();
+ void selected(QWidget *);
+ void changeEvent(IRCTab *);
protected:
void loadSettings();
protected:
- QTabWidget *m_tabWidget;
+ IRCTabWidget *m_tabWidget;
QList<IRCTab> m_tabs;
};
#endif /* __MAINWINDOW_H */