summaryrefslogtreecommitdiff
path: root/noncore/net/opieirc/ircmisc.cpp
blob: dd7292c562c80a446960e39c6750a491de961d87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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);
}