author | wazlaf <wazlaf> | 2002-09-30 08:07:05 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-30 08:07:05 (UTC) |
commit | a999acbcd1b8bc1715f2ad2dda6acedf423b89ea (patch) (side-by-side diff) | |
tree | 898d433efa8ff3b25a5d10ab4dc4a0a9bc415104 /noncore/net | |
parent | 75dccdfe90324e9ff2426930ae185c3a6bdab734 (diff) | |
download | opie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.zip opie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.tar.gz opie-a999acbcd1b8bc1715f2ad2dda6acedf423b89ea.tar.bz2 |
tabs now change their color when actions occur
-rw-r--r-- | noncore/net/opieirc/ircchanneltab.cpp | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 35 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 28 | ||||
-rw-r--r-- | noncore/net/opieirc/ircquerytab.cpp | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservertab.cpp | 1 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.cpp | 8 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.h | 5 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 14 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.h | 6 |
9 files changed, 96 insertions, 3 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 @@ -46,8 +46,9 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW 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); 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,6 +1,7 @@ #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; @@ -28,4 +29,38 @@ IRCFramedColorLabel::IRCFramedColorLabel(QColor color, QWidget *parent, const ch 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 @@ -20,12 +20,18 @@ #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 { + Q_OBJECT public: IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); QColor color(); void mousePressEvent(QMouseEvent *event); @@ -33,12 +39,34 @@ class IRCColorLabel : public QLabel { QColor m_color; }; class IRCFramedColorLabel : public QWidget { + 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 @@ -24,8 +24,9 @@ IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow 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); 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 @@ -24,8 +24,9 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa 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; 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 @@ -25,4 +25,12 @@ IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, na 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 @@ -34,17 +34,22 @@ 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; 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 @@ -9,9 +9,10 @@ #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); @@ -36,14 +37,25 @@ void MainWindow::loadSettings() { 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 .. */ 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 @@ -23,10 +23,10 @@ #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 @@ -37,12 +37,14 @@ public: 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 */ |