author | wazlaf <wazlaf> | 2002-09-30 08:07:05 (UTC) |
---|---|---|
committer | wazlaf <wazlaf> | 2002-09-30 08:07:05 (UTC) |
commit | a999acbcd1b8bc1715f2ad2dda6acedf423b89ea (patch) (unidiff) | |
tree | 898d433efa8ff3b25a5d10ab4dc4a0a9bc415104 | |
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 | 50 | ||||
-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, 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 | |||
@@ -44,12 +44,13 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW | |||
44 | } | 44 | } |
45 | 45 | ||
46 | void IRCChannelTab::appendText(QString text) { | 46 | void IRCChannelTab::appendText(QString text) { |
47 | /* not using append because it creates layout problems */ | 47 | /* not using append because it creates layout problems */ |
48 | m_textview->setText(m_textview->text() + text); | 48 | m_textview->setText(m_textview->text() + text); |
49 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 49 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
50 | emit changed(this); | ||
50 | } | 51 | } |
51 | 52 | ||
52 | IRCChannelTab::~IRCChannelTab() { | 53 | IRCChannelTab::~IRCChannelTab() { |
53 | m_parentTab->removeChannelTab(this); | 54 | m_parentTab->removeChannelTab(this); |
54 | } | 55 | } |
55 | 56 | ||
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,8 +1,9 @@ | |||
1 | #include <opie/colordialog.h> | 1 | #include <opie/colordialog.h> |
2 | #include <qlayout.h> | 2 | #include <qlayout.h> |
3 | #include <stdio.h> | ||
3 | #include "ircmisc.h" | 4 | #include "ircmisc.h" |
4 | 5 | ||
5 | IRCColorLabel::IRCColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QLabel(parent, name, f) { | 6 | IRCColorLabel::IRCColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QLabel(parent, name, f) { |
6 | m_color = color; | 7 | m_color = color; |
7 | setAlignment(AlignVCenter | AlignCenter); | 8 | setAlignment(AlignVCenter | AlignCenter); |
8 | setFrameStyle(QFrame::StyledPanel); | 9 | setFrameStyle(QFrame::StyledPanel); |
@@ -26,6 +27,40 @@ IRCFramedColorLabel::IRCFramedColorLabel(QColor color, QWidget *parent, const ch | |||
26 | } | 27 | } |
27 | 28 | ||
28 | QColor IRCFramedColorLabel::color() { | 29 | QColor IRCFramedColorLabel::color() { |
29 | return m_label->color(); | 30 | return m_label->color(); |
30 | } | 31 | } |
31 | 32 | ||
33 | IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) { | ||
34 | } | ||
35 | |||
36 | int IRCTabBar::insertTab(QTab *tab, int index = -1) { | ||
37 | if (m_colors.size() == (unsigned int)count()) | ||
38 | m_colors.resize(m_colors.size() * 2 + 1); | ||
39 | if (index == -1) | ||
40 | m_colors.insert(count(), &black); | ||
41 | else | ||
42 | m_colors.insert(index, &black); | ||
43 | return QTabBar::insertTab(tab, index); | ||
44 | } | ||
45 | |||
46 | void IRCTabBar::setTabColor(int index, const QColor *color) { | ||
47 | m_colors.insert(index, color); | ||
48 | update(); | ||
49 | } | ||
50 | |||
51 | void IRCTabBar::paintLabel(QPainter* p, const QRect& br, QTab* t, bool focus) const { | ||
52 | QRect r = br; | ||
53 | QTabBar::paintLabel(p, br, t, focus); | ||
54 | if (t->id == currentTab()) | ||
55 | r.setBottom(r.bottom() - style().defaultFrameWidth()); | ||
56 | p->setPen(*m_colors.at(t->id)); | ||
57 | p->drawText(r, AlignCenter | ShowPrefix, t->label); | ||
58 | } | ||
59 | |||
60 | IRCTabWidget::IRCTabWidget(QWidget *parent, const char *name) : QTabWidget(parent, name) { | ||
61 | setTabBar(new IRCTabBar(this, "tab control")); | ||
62 | } | ||
63 | |||
64 | void IRCTabWidget::setTabColor(int index, const QColor *color) { | ||
65 | ((IRCTabBar *)tabBar())->setTabColor(index, color); | ||
66 | } | ||
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 | |||
@@ -18,27 +18,55 @@ | |||
18 | 18 | ||
19 | */ | 19 | */ |
20 | 20 | ||
21 | #ifndef __IRCMISC_H | 21 | #ifndef __IRCMISC_H |
22 | #define __IRCMISC_H | 22 | #define __IRCMISC_H |
23 | 23 | ||
24 | #include <qtabwidget.h> | ||
25 | #include <qtabbar.h> | ||
24 | #include <qlabel.h> | 26 | #include <qlabel.h> |
25 | #include <qcolor.h> | 27 | #include <qcolor.h> |
28 | #include <qvector.h> | ||
29 | |||
30 | /* IRCFramedColorLabel is used to display a color */ | ||
26 | 31 | ||
27 | class IRCColorLabel : public QLabel { | 32 | class IRCColorLabel : public QLabel { |
28 | public: | 33 | Q_OBJECT |
29 | IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | 34 | public: |
30 | QColor color(); | 35 | IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
31 | void mousePressEvent(QMouseEvent *event); | 36 | QColor color(); |
32 | protected: | 37 | void mousePressEvent(QMouseEvent *event); |
33 | QColor m_color; | 38 | protected: |
39 | QColor m_color; | ||
34 | }; | 40 | }; |
35 | 41 | ||
36 | class IRCFramedColorLabel : public QWidget { | 42 | class IRCFramedColorLabel : public QWidget { |
37 | public: | 43 | Q_OBJECT |
38 | IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); | 44 | public: |
39 | QColor color(); | 45 | IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
40 | protected: | 46 | QColor color(); |
41 | IRCColorLabel *m_label; | 47 | protected: |
48 | IRCColorLabel *m_label; | ||
49 | }; | ||
50 | |||
51 | /* Custom colored QTabWidget */ | ||
52 | |||
53 | class IRCTabWidget : public QTabWidget { | ||
54 | Q_OBJECT | ||
55 | public: | ||
56 | IRCTabWidget(QWidget *parent = 0, const char *name = 0); | ||
57 | void setTabColor(int index, const QColor *color); | ||
58 | }; | ||
59 | |||
60 | class IRCTabBar : public QTabBar { | ||
61 | Q_OBJECT | ||
62 | public: | ||
63 | IRCTabBar(QWidget *parent = 0, const char *name = 0); | ||
64 | void setTabColor(int index, const QColor *color); | ||
65 | protected: | ||
66 | void paintLabel(QPainter*, const QRect&, QTab*, bool) const; | ||
67 | int insertTab(QTab *, int index = -1); | ||
68 | protected: | ||
69 | QVector<QColor> m_colors; | ||
42 | }; | 70 | }; |
43 | 71 | ||
44 | #endif /* __IRCMISC_H */ | 72 | #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 | |||
@@ -22,12 +22,13 @@ IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow | |||
22 | } | 22 | } |
23 | 23 | ||
24 | void IRCQueryTab::appendText(QString text) { | 24 | void IRCQueryTab::appendText(QString text) { |
25 | /* not using append because it creates layout problems */ | 25 | /* not using append because it creates layout problems */ |
26 | m_textview->setText(m_textview->text() + text); | 26 | m_textview->setText(m_textview->text() + text); |
27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
28 | emit changed(this); | ||
28 | } | 29 | } |
29 | 30 | ||
30 | IRCQueryTab::~IRCQueryTab() { | 31 | IRCQueryTab::~IRCQueryTab() { |
31 | m_parentTab->removeQueryTab(this); | 32 | m_parentTab->removeQueryTab(this); |
32 | delete m_person; | 33 | delete m_person; |
33 | } | 34 | } |
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 | |||
@@ -22,12 +22,13 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa | |||
22 | } | 22 | } |
23 | 23 | ||
24 | void IRCServerTab::appendText(QString text) { | 24 | void IRCServerTab::appendText(QString text) { |
25 | /* not using append because it creates layout problems */ | 25 | /* not using append because it creates layout problems */ |
26 | m_textview->setText(m_textview->text() + text); | 26 | m_textview->setText(m_textview->text() + text); |
27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); | 27 | m_textview->ensureVisible(0, m_textview->contentsHeight()); |
28 | emit changed(this); | ||
28 | } | 29 | } |
29 | 30 | ||
30 | IRCServerTab::~IRCServerTab() { | 31 | IRCServerTab::~IRCServerTab() { |
31 | delete m_session; | 32 | delete m_session; |
32 | } | 33 | } |
33 | 34 | ||
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 | |||
@@ -23,6 +23,14 @@ IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, na | |||
23 | close->setPixmap(Resource::loadPixmap("close")); | 23 | close->setPixmap(Resource::loadPixmap("close")); |
24 | connect(close, SIGNAL(clicked()), this, SLOT(remove())); | 24 | connect(close, SIGNAL(clicked()), this, SLOT(remove())); |
25 | descLayout->addWidget(close); | 25 | descLayout->addWidget(close); |
26 | descLayout->setStretchFactor(m_description, 1); | 26 | descLayout->setStretchFactor(m_description, 1); |
27 | } | 27 | } |
28 | 28 | ||
29 | |||
30 | void IRCTab::setID(int id) { | ||
31 | m_id = id; | ||
32 | } | ||
33 | |||
34 | int IRCTab::id() { | ||
35 | return m_id; | ||
36 | } | ||
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 | |||
@@ -32,21 +32,26 @@ | |||
32 | the main GUI tab widget */ | 32 | the main GUI tab widget */ |
33 | 33 | ||
34 | class IRCTab : public QWidget { | 34 | class IRCTab : public QWidget { |
35 | Q_OBJECT | 35 | Q_OBJECT |
36 | public: | 36 | public: |
37 | IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0); | 37 | IRCTab(QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
38 | void setID(int id); | ||
39 | int id(); | ||
38 | virtual QString title() = 0; | 40 | virtual QString title() = 0; |
39 | virtual IRCSession *session() = 0; | 41 | virtual IRCSession *session() = 0; |
40 | virtual void appendText(QString text) = 0; | 42 | virtual void appendText(QString text) = 0; |
43 | signals: | ||
44 | void changed(IRCTab *); | ||
41 | public slots: | 45 | public slots: |
42 | virtual void remove() = 0; | 46 | virtual void remove() = 0; |
43 | virtual void settingsChanged() = 0; | 47 | virtual void settingsChanged() = 0; |
44 | protected: | 48 | protected: |
45 | QLabel *m_description; | 49 | QLabel *m_description; |
46 | QVBoxLayout *m_layout; | 50 | QVBoxLayout *m_layout; |
51 | int m_id; | ||
47 | public: | 52 | public: |
48 | /* Configuration shared accross all instances - contains HTML style colors (#rrggbb) */ | 53 | /* Configuration shared accross all instances - contains HTML style colors (#rrggbb) */ |
49 | static QString m_errorColor; | 54 | static QString m_errorColor; |
50 | static QString m_serverColor; | 55 | static QString m_serverColor; |
51 | static QString m_textColor; | 56 | static QString m_textColor; |
52 | static QString m_backgroundColor; | 57 | static QString m_backgroundColor; |
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 | |||
@@ -7,13 +7,14 @@ | |||
7 | #include "ircservertab.h" | 7 | #include "ircservertab.h" |
8 | #include "ircserverlist.h" | 8 | #include "ircserverlist.h" |
9 | #include "ircsettings.h" | 9 | #include "ircsettings.h" |
10 | 10 | ||
11 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { | 11 | MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { |
12 | setCaption(tr("IRC Client")); | 12 | setCaption(tr("IRC Client")); |
13 | m_tabWidget = new QTabWidget(this); | 13 | m_tabWidget = new IRCTabWidget(this); |
14 | connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *))); | ||
14 | setCentralWidget(m_tabWidget); | 15 | setCentralWidget(m_tabWidget); |
15 | setToolBarsMovable(FALSE); | 16 | setToolBarsMovable(FALSE); |
16 | QPEMenuBar *menuBar = new QPEMenuBar(this); | 17 | QPEMenuBar *menuBar = new QPEMenuBar(this); |
17 | QPopupMenu *irc = new QPopupMenu(this); | 18 | QPopupMenu *irc = new QPopupMenu(this); |
18 | menuBar->insertItem(tr("IRC"), irc); | 19 | menuBar->insertItem(tr("IRC"), irc); |
19 | QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); | 20 | QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); |
@@ -34,18 +35,29 @@ void MainWindow::loadSettings() { | |||
34 | IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); | 35 | IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); |
35 | IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); | 36 | IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); |
36 | IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); | 37 | IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); |
37 | IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); | 38 | IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); |
38 | } | 39 | } |
39 | 40 | ||
41 | void MainWindow::selected(QWidget *) { | ||
42 | m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), &black); | ||
43 | } | ||
44 | |||
40 | void MainWindow::addTab(IRCTab *tab) { | 45 | void MainWindow::addTab(IRCTab *tab) { |
46 | connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *))); | ||
41 | m_tabWidget->addTab(tab, tab->title()); | 47 | m_tabWidget->addTab(tab, tab->title()); |
42 | m_tabWidget->showPage(tab); | 48 | m_tabWidget->showPage(tab); |
49 | tab->setID(m_tabWidget->currentPageIndex()); | ||
43 | m_tabs.append(tab); | 50 | m_tabs.append(tab); |
44 | } | 51 | } |
45 | 52 | ||
53 | void MainWindow::changeEvent(IRCTab *tab) { | ||
54 | if (tab->id() != m_tabWidget->currentPageIndex()) | ||
55 | m_tabWidget->setTabColor(tab->id(), &blue); | ||
56 | } | ||
57 | |||
46 | void MainWindow::killTab(IRCTab *tab) { | 58 | void MainWindow::killTab(IRCTab *tab) { |
47 | m_tabWidget->removePage(tab); | 59 | m_tabWidget->removePage(tab); |
48 | m_tabs.remove(tab); | 60 | m_tabs.remove(tab); |
49 | /* there might be nicer ways to do this .. */ | 61 | /* there might be nicer ways to do this .. */ |
50 | delete tab; | 62 | delete tab; |
51 | } | 63 | } |
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 | |||
@@ -21,28 +21,30 @@ | |||
21 | #ifndef __MAINWINDOW_H | 21 | #ifndef __MAINWINDOW_H |
22 | #define __MAINWINDOW_H | 22 | #define __MAINWINDOW_H |
23 | 23 | ||
24 | #include <qmainwindow.h> | 24 | #include <qmainwindow.h> |
25 | #include <qaction.h> | 25 | #include <qaction.h> |
26 | #include <qlist.h> | 26 | #include <qlist.h> |
27 | #include <qtabwidget.h> | ||
28 | #include "mainwindow.h" | 27 | #include "mainwindow.h" |
28 | #include "ircmisc.h" | ||
29 | #include "irctab.h" | 29 | #include "irctab.h" |
30 | 30 | ||
31 | class MainWindow : public QMainWindow { | 31 | class MainWindow : public QMainWindow { |
32 | Q_OBJECT | 32 | Q_OBJECT |
33 | public: | 33 | public: |
34 | MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0); | 34 | MainWindow(QWidget *parent = 0, const char *name = 0, WFlags f = 0); |
35 | 35 | ||
36 | void addTab(IRCTab *tab); | 36 | void addTab(IRCTab *tab); |
37 | void killTab(IRCTab *tab); | 37 | void killTab(IRCTab *tab); |
38 | protected slots: | 38 | protected slots: |
39 | void newConnection(); | 39 | void newConnection(); |
40 | void settings(); | 40 | void settings(); |
41 | void selected(QWidget *); | ||
42 | void changeEvent(IRCTab *); | ||
41 | protected: | 43 | protected: |
42 | void loadSettings(); | 44 | void loadSettings(); |
43 | protected: | 45 | protected: |
44 | QTabWidget *m_tabWidget; | 46 | IRCTabWidget *m_tabWidget; |
45 | QList<IRCTab> m_tabs; | 47 | QList<IRCTab> m_tabs; |
46 | }; | 48 | }; |
47 | 49 | ||
48 | #endif /* __MAINWINDOW_H */ | 50 | #endif /* __MAINWINDOW_H */ |