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; }
bool TextEdit::processEvent(Event *e) { if (m_param == NULL) return false; if (e->type() == eEventCheckCommandState){ EventCheckCommandState *ecs = static_cast<EventCheckCommandState*>(e); CommandDef *cmd = ecs->cmd(); if (cmd->param != m_param) return false; switch (cmd->id){ case CmdBgColor: case CmdFgColor: case CmdBold: case CmdItalic: case CmdUnderline: case CmdFont: if (!isReadOnly()){ cmd->flags &= ~BTN_HIDE; }else{ cmd->flags |= BTN_HIDE; } return true; default: break; } } else if (e->type() == eEventCommandExec){ EventCommandExec *ece = static_cast<EventCommandExec*>(e); CommandDef *cmd = ece->cmd(); if (cmd->param != m_param) return false; switch (cmd->id){ case CmdBgColor:{ EventCommandWidget eWidget(cmd); eWidget.process(); CToolButton *btnBg = dynamic_cast<CToolButton*>(eWidget.widget()); 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 true; } case CmdFgColor:{ EventCommandWidget eWidget(cmd); eWidget.process(); CToolButton *btnFg = dynamic_cast<CToolButton*>(eWidget.widget()); 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 true; } case CmdBold: if (!m_bChanged){ m_bSelected = true; setFontWeight((cmd->flags & COMMAND_CHECKED) != 0 ? QFont::Bold : QFont::Normal); } return true; case CmdItalic: if (!m_bChanged){ m_bSelected = true; setFontItalic((cmd->flags & COMMAND_CHECKED) != 0); } return true; case CmdUnderline: if (!m_bChanged){ m_bSelected = true; setFontUnderline((cmd->flags & COMMAND_CHECKED) != 0); } return true; 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 false; } } return false; }