Esempio n. 1
0
void RichTextEdit::showBar()
{
    if (m_bar)
        return;
    m_bar = new QToolBar(this);

    btnBG = new ColorToolButton(m_bar, m_edit->background());
    set_button(btnBG, "bgcolor", I18N_NOOP("Bac&kground color"));
    connect(btnBG, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor)));

    btnFG = new ColorToolButton(m_bar, m_edit->foreground());
    set_button(btnFG, "fgcolor", I18N_NOOP("&Text color"));
    connect(btnFG, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor)));
    connect(btnFG, SIGNAL(aboutToShow()), this, SLOT(showFgPopup()));

    m_bar->addSeparator();

    btnBold = new QToolButton(m_bar);
    set_button(btnBold, "text_bold", I18N_NOOP("&Bold"));
    btnBold->setToggleButton(true);
    connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(toggleBold(bool)));

    btnItalic = new QToolButton(m_bar);
    set_button(btnItalic, "text_italic", I18N_NOOP("&Italic"));
    btnItalic->setToggleButton(true);
    connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(toggleItalic(bool)));

    btnUnderline = new QToolButton(m_bar);
    set_button(btnUnderline, "text_under", I18N_NOOP("&Underline"));
    btnUnderline->setToggleButton(true);
    connect(btnUnderline, SIGNAL(toggled(bool)), this, SLOT(toggleUnderline(bool)));

    m_bar->addSeparator();

    QToolButton *btn = new QToolButton(m_bar);
    set_button(btn, "text", I18N_NOOP("Text &font"));
    connect(btn, SIGNAL(clicked()), this, SLOT(selectFont()));

    connect(m_edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(fontChanged(const QFont&)));
}
Esempio n. 2
0
void *TextEdit::processEvent(Event *e)
{
    if (m_param == NULL)
        return NULL;
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->param != m_param)
            return NULL;
        switch (cmd->id){
        case CmdBgColor:
        case CmdFgColor:
        case CmdBold:
        case CmdItalic:
        case CmdUnderline:
        case CmdFont:
            if ((textFormat() == RichText) && !isReadOnly()){
                cmd->flags &= ~BTN_HIDE;
            }else{
                cmd->flags |= BTN_HIDE;
            }
            return e->param();
        default:
            return NULL;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->param != m_param)
            return NULL;
        switch (cmd->id){
        case CmdBgColor:{
                Event eWidget(EventCommandWidget, cmd);
                CToolButton *btnBg = (CToolButton*)(eWidget.process());
                if (btnBg){
                    ColorPopup *popup = new ColorPopup(this, background());
                    popup->move(CToolButton::popupPos(btnBg, popup));
                    connect(popup, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor)));
                    popup->show();
                }
                return e->param();
            }
        case CmdFgColor:{
                Event eWidget(EventCommandWidget, cmd);
                CToolButton *btnFg = (CToolButton*)(eWidget.process());
                if (btnFg){
                    ColorPopup *popup = new ColorPopup(this, foreground());
                    popup->move(CToolButton::popupPos(btnFg, popup));
                    connect(popup, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor)));
                    popup->show();
                }
                return e->param();
            }
        case CmdBold:
            m_bSelected = true;
            setBold((cmd->flags & COMMAND_CHECKED) != 0);
            return e->param();
        case CmdItalic:
            m_bSelected = true;
            setItalic((cmd->flags & COMMAND_CHECKED) != 0);
            return e->param();
        case CmdUnderline:
            m_bSelected = true;
            setUnderline((cmd->flags & COMMAND_CHECKED) != 0);
            return e->param();
        case CmdFont:{
#ifdef USE_KDE
                QFont f = font();
                if (KFontDialog::getFont(f, false, topLevelWidget()) != KFontDialog::Accepted)
                    break;
#else
                bool ok = false;
                QFont f = QFontDialog::getFont(&ok, font(), topLevelWidget());
                if (!ok)
                    break;
#endif
                m_bSelected = true;
                setCurrentFont(f);
                break;
            }
        default:
            return NULL;
        }
    }
    return NULL;
}
Esempio n. 3
0
MsgGen::MsgGen(CToolCustom *parent, Message *msg)
        : QObject(parent)
{
    m_client = msg->client();
    m_edit = NULL;
    for (QWidget *p = parent->parentWidget(); p; p = p->parentWidget()){
        if (p->inherits("MsgEdit")){
            m_edit = static_cast<MsgEdit*>(p);
            break;
        }
    }
    connect(m_edit->m_userWnd, SIGNAL(multiplyChanged()), this, SLOT(textChanged()));
    parent->setText(i18n(" "));
    m_edit->m_edit->setTextFormat(RichText);
    QString text = msg->getRichText();
    if (!text.isEmpty()){
        m_edit->m_edit->setText(text);
        m_edit->m_edit->moveCursor(QTextEdit::MoveEnd, false);
        if ((msg->getBackground() != msg->getForeground()) && !CorePlugin::m_plugin->getOwnColors()){
            m_edit->m_edit->setBackground(msg->getBackground());
            m_edit->m_edit->setForeground(msg->getForeground());
        }
    }
    Command cmd;
    cmd->id    = CmdSend;
    cmd->param = m_edit;
    Event e(EventCommandWidget, cmd);
    btnSend = (QToolButton*)(e.process());

    QToolButton *btn = new ColorToolButton(parent, QColor(CorePlugin::m_plugin->getEditBackground()));
    set_button(btn, "bgcolor", I18N_NOOP("Bac&kground color"));
    connect(btn, SIGNAL(colorChanged(QColor)), this, SLOT(bgColorChanged(QColor)));
    parent->addWidget(btn);
    btn->show();

    btn = new ColorToolButton(parent, QColor(CorePlugin::m_plugin->getEditForeground()));
    set_button(btn, "fgcolor", I18N_NOOP("&Text color"));
    connect(btn, SIGNAL(colorChanged(QColor)), this, SLOT(fgColorChanged(QColor)));
    parent->addWidget(btn);
    btn->show();

    btnBold = new QToolButton(parent);
    set_button(btnBold, "text_bold", I18N_NOOP("&Bold"));
    btnBold->setToggleButton(true);
    connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(toggleBold(bool)));
    parent->addWidget(btnBold);
    btnBold->show();

    btnItalic = new QToolButton(parent);
    set_button(btnItalic, "text_italic", I18N_NOOP("&Italic"));
    btnItalic->setToggleButton(true);
    connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(toggleItalic(bool)));
    parent->addWidget(btnItalic);
    btnItalic->show();

    btnUnderline = new QToolButton(parent);
    set_button(btnUnderline, "text_under", I18N_NOOP("&Underline"));
    btnUnderline->setToggleButton(true);
    connect(btnUnderline, SIGNAL(toggled(bool)), this, SLOT(toggleUnderline(bool)));
    parent->addWidget(btnUnderline);
    btnUnderline->show();

    btn = new QToolButton(parent);
    set_button(btn, "text", I18N_NOOP("Text &font"));
    connect(btn, SIGNAL(clicked()), this, SLOT(selectFont()));
    parent->addWidget(btn);
    btn->show();

    connect(m_edit->m_edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(fontChanged(const QFont&)));
    connect(m_edit->m_edit, SIGNAL(textChanged()), this, SLOT(textChanged()));
    fontChanged(m_edit->m_edit->font());
    textChanged();
}