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
@@ -49,2 +49,3 @@ void IRCChannelTab::appendText(QString text) {
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
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
@@ -2,2 +2,3 @@
#include <qlayout.h>
+#include <stdio.h>
#include "ircmisc.h"
@@ -31 +32,35 @@ QColor IRCFramedColorLabel::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
@@ -23,12 +23,18 @@
+#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;
};
@@ -36,7 +42,29 @@ class IRCColorLabel : public QLabel {
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;
};
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
@@ -27,2 +27,3 @@ void IRCQueryTab::appendText(QString text) {
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
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
@@ -27,2 +27,3 @@ void IRCServerTab::appendText(QString text) {
m_textview->ensureVisible(0, m_textview->contentsHeight());
+ emit changed(this);
}
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
@@ -28 +28,9 @@ IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, na
+
+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
@@ -37,2 +37,4 @@ public:
IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0);
+ void setID(int id);
+ int id();
virtual QString title() = 0;
@@ -40,2 +42,4 @@ public:
virtual void appendText(QString text) = 0;
+signals:
+ void changed(IRCTab *);
public slots:
@@ -46,2 +50,3 @@ protected:
QVBoxLayout *m_layout;
+ int m_id;
public:
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
@@ -12,3 +12,4 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindo
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);
@@ -39,5 +40,11 @@ void MainWindow::loadSettings() {
+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);
@@ -45,2 +52,7 @@ void MainWindow::addTab(IRCTab *tab) {
+void MainWindow::changeEvent(IRCTab *tab) {
+ if (tab->id() != m_tabWidget->currentPageIndex())
+ m_tabWidget->setTabColor(tab->id(), &blue);
+}
+
void MainWindow::killTab(IRCTab *tab) {
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
@@ -26,4 +26,4 @@
#include <qlist.h>
-#include <qtabwidget.h>
#include "mainwindow.h"
+#include "ircmisc.h"
#include "irctab.h"
@@ -40,2 +40,4 @@ protected slots:
void settings();
+ void selected(QWidget *);
+ void changeEvent(IRCTab *);
protected:
@@ -43,3 +45,3 @@ protected:
protected:
- QTabWidget *m_tabWidget;
+ IRCTabWidget *m_tabWidget;
QList<IRCTab> m_tabs;