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 | |
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 @@ -38,24 +38,25 @@ IRCChannelTab::IRCChannelTab(IRCChannel *channel, IRCServerTab *parentTab, MainW 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 */ 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,14 +1,15 @@ #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); @@ -20,12 +21,46 @@ QColor IRCColorLabel::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 @@ -12,33 +12,61 @@ 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 @@ -16,24 +16,25 @@ IRCQueryTab::IRCQueryTab(IRCPerson *person, IRCServerTab *parentTab, MainWindow 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("//")) { 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 @@ -16,24 +16,25 @@ IRCServerTab::IRCServerTab(IRCServer server, MainWindow *mainWindow, QWidget *pa 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); 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 @@ -17,12 +17,20 @@ IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, na 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 @@ -26,33 +26,38 @@ #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,25 +1,26 @@ #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(); @@ -28,30 +29,41 @@ MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindo 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); 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 @@ -15,34 +15,36 @@ 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 */ |