MsgEdit::MsgEdit(QWidget *parent, UserWnd *userWnd) : QMainWindow(parent, NULL, 0) { m_userWnd = userWnd; m_msg = NULL; m_bTyping = false; m_type = NO_TYPE; m_flags = 0; m_retry.msg = NULL; m_bReceived = false; m_processor = NULL; m_recvProcessor = NULL; m_cmd.param = NULL; connect(CorePlugin::m_plugin, SIGNAL(modeChanged()), this, SLOT(modeChanged())); m_frame = new QFrame(this); setCentralWidget(m_frame); m_layout = new QVBoxLayout(m_frame); m_edit = new MsgTextEdit(this, m_frame); m_edit->setBackground(QColor(CorePlugin::m_plugin->getEditBackground() & 0xFFFFFF)); m_edit->setForeground(QColor(CorePlugin::m_plugin->getEditForeground() & 0xFFFFFF), true); m_edit->setFont(CorePlugin::m_plugin->editFont); m_edit->setCtrlMode(!CorePlugin::m_plugin->getSendOnEnter()); setFocusProxy(m_edit); QStyleSheet *style = new QStyleSheet(m_edit); QStyleSheetItem *style_p = style->item("p"); // Disable top and bottom margins for P tags. This will make sure // paragraphs have no more spacing than regular lines, thus matching // RTFs defaut look for paragraphs. style_p->setMargin(QStyleSheetItem::MarginTop, 0); style_p->setMargin(QStyleSheetItem::MarginBottom, 0); m_edit->setStyleSheet(style); connect(m_edit, SIGNAL(lostFocus()), this, SLOT(editLostFocus())); connect(m_edit, SIGNAL(textChanged()), this, SLOT(editTextChanged())); connect(m_edit, SIGNAL(ctrlEnterPressed()), this, SLOT(editEnterPressed())); connect(m_edit, SIGNAL(colorsChanged()), this, SLOT(colorsChanged())); connect(m_edit, SIGNAL(finished()), this, SLOT(editFinished())); connect(m_edit, SIGNAL(fontSelected(const QFont&)), this, SLOT(editFontChanged(const QFont&))); QFontMetrics fm(m_edit->font()); m_edit->setMinimumSize(QSize(fm.maxWidth(), fm.height() + 10)); m_layout->addWidget(m_edit); BarShow b; b.bar_id = ToolBarMsgEdit; b.parent = this; Event e(EventShowBar, &b); m_bar = (CToolBar*)(e.process()); m_bar->setParam(this); if (CorePlugin::m_plugin->getContainerMode() == 0) showCloseSend(false); setDockEnabled(m_bar, Left, false); setDockEnabled(m_bar, Right, false); }
void TextEdit::keyPressEvent(QKeyEvent *e) { if (((e->key() == Key_Enter) || (e->key() == Key_Return))){ if (!m_bCtrlMode || (e->state() & ControlButton)){ emit ctrlEnterPressed(); return; } } if (!isReadOnly()){ if ((e->state() == ShiftButton) && (e->key() == Key_Insert)){ paste(); return; } if ((e->state() == ControlButton) && (e->key() == Key_Delete)){ cut(); return; } } #if (COMPAT_QT_VERSION >= 0x030000) && (COMPAT_QT_VERSION < 0x030100) // Workaround about autoformat feature in qt 3.0.x if ((e->text()[0] == '-') || (e->text()[0] == '*')){ if (isOverwriteMode() && !hasSelectedText()) moveCursor(MoveForward, true); insert( e->text(), TRUE, FALSE ); return; } #endif // Note: We no longer translate Enter to Ctrl-Enter since we need // to know about paragraph breaks now. TextShow::keyPressEvent(e); }
void MainWindow::addTeam() { int tc = teams.count(); if (tc) { teams.last()->button->disconnect(); teams.last()->button->setIcon(QIcon(":/images/images/remove.png")); connect(teams.last()->button, SIGNAL(clicked()), this, SLOT(removeTeam())); } team *n = new team; n->number = new QLabel; n->number->setText(QString::number(teams.count() + 1) + ")"); n->name = new QLineEdit; n->button = new QToolButton; teams.append(n); QGridLayout *layout = static_cast <QGridLayout *> (ui->list->layout()); layout->addWidget(n->number, lli, 0); connect(n->name, SIGNAL(returnPressed()), this, SLOT(drawCouples())); QShortcut *sh = new QShortcut(QKeySequence("Ctrl+Return"), n->name); sh->setContext(Qt::WidgetShortcut); connect(sh, SIGNAL(activated()), this, SLOT(ctrlEnterPressed())); QShortcut *sh1 = new QShortcut(QKeySequence("Tab"), n->name); sh1->setContext(Qt::WidgetShortcut); connect(sh1, SIGNAL(activated()), this, SLOT(tabPressed())); QShortcut *sh2 = new QShortcut(QKeySequence("Shift+Tab"), n->name); sh2->setContext(Qt::WidgetShortcut); connect(sh2, SIGNAL(activated()), this, SLOT(shiftTabPressed())); layout->addWidget(n->name, lli, 1); n->button->setIcon(QIcon(":/images/images/add.png")); connect(n->button, SIGNAL(clicked()), this, SLOT(addTeam())); layout->addWidget(n->button, lli, 2); ++lli; n->name->setFocus(); }
EditSpell::EditSpell(QWidget *parent) : QTextEdit(parent) { #if USE_SPELL pSpell = NULL; #endif bgTransparent = new TransparentBg(this); setWordWrap(WidgetWidth); baseBG = colorGroup().color(QColorGroup::Base); baseFG = colorGroup().color(QColorGroup::Text); curFG = baseFG; QAccel *a = new QAccel( this ); a->connectItem(a->insertItem(Key_Enter + CTRL), this, SIGNAL(ctrlEnterPressed())); a->connectItem(a->insertItem(Key_Return + CTRL), this, SIGNAL(ctrlEnterPressed())); }
void TextEdit::keyPressEvent(QKeyEvent *e) { if (((e->key() == Key_Enter) || (e->key() == Key_Return))){ if (!m_bCtrlMode || (e->state() & ControlButton)){ emit ctrlEnterPressed(); return; } } if (!isReadOnly()){ if ((e->state() == ShiftButton) && (e->key() == Key_Insert)){ paste(); return; } if ((e->state() == ControlButton) && (e->key() == Key_Delete)){ cut(); return; } } #if (QT_VERSION >= 300) && (QT_VERSION < 0x030100) // Workaround about autoformat feature in qt 3.0.x if ((e->text()[0] == '-') || (e->text()[0] == '*')){ if (isOverwriteMode() && !hasSelectedText()) moveCursor(MoveForward, true); insert( e->text(), TRUE, FALSE ); return; } #endif #if QT_VERSION >= 300 if ((e->key() == Key_Return) || (e->key() == Key_Enter)){ QKeyEvent e1(QEvent::KeyPress, e->key(), e->ascii(), e->state() | ControlButton, e->text(), e->count()); QTextEdit::keyPressEvent(&e1); return; } #endif TextShow::keyPressEvent(e); }
// For managing selection and cursor void CFileListView::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Up || event->key() == Qt::Key_PageDown || event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Home || event->key() == Qt::Key_End) { if ((event->modifiers() & (~Qt::KeypadModifier) & (~Qt::ShiftModifier)) == Qt::NoModifier) { const bool shiftPressed = (event->modifiers() & Qt::ShiftModifier) != 0; if (event->key() == Qt::Key_Down) moveCursorToNextItem(shiftPressed); else if (event->key() == Qt::Key_Up) moveCursorToPreviousItem(shiftPressed); else if (event->key() == Qt::Key_Home) moveCursorToItem(model()->index(0, 0), shiftPressed); else if (event->key() == Qt::Key_End) moveCursorToItem(model()->index(model()->rowCount()-1, 0), shiftPressed); else if (event->key() == Qt::Key_PageUp) pgUp(shiftPressed); else if (event->key() == Qt::Key_PageDown) pgDn(shiftPressed); event->accept(); return; } } else if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { if (event->modifiers() == Qt::NoModifier) { bool returnPressConsumed = false; for(FileListViewEventObserver* observer: _eventObservers) { returnPressConsumed = observer->fileListReturnPressed(); if (returnPressConsumed) break; } if (!returnPressConsumed) for (FileListViewEventObserver* observer: _eventObservers) { if (currentIndex().isValid()) { returnPressConsumed = observer->fileListReturnPressOrDoubleClickPerformed(currentIndex()); if (returnPressConsumed) break; } } } else if (event->modifiers() == Qt::ControlModifier) emit ctrlEnterPressed(); else if (event->modifiers() == (Qt::ControlModifier | Qt::ShiftModifier)) emit ctrlShiftEnterPressed(); return; } else if (event->key() == Qt::Key_Shift) { _shiftPressedItemSelected = currentIndex().isValid() ? selectionModel()->isSelected(currentIndex()) : false; } else emit keyPressed(event->text(), event->key(), event->modifiers()); QTreeView::keyPressEvent(event); #ifdef __linux__ // FIXME: find out why this hack is necessary if (event->key() == Qt::Key_Down || event->key() == Qt::Key_Up || event->key() == Qt::Key_PageDown || event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Home || event->key() == Qt::Key_End) if ((event->modifiers() & Qt::ShiftModifier) != 0) scrollTo(currentIndex()); #endif }
MsgEdit::MsgEdit(QWidget *p, unsigned long uin) : QFrame(p), Uin(this, "Uin") { Uin = uin; msg = NULL; tabId = -1; tab = NULL; sendEvent = NULL; mHistory = NULL; bMultiply = false; setWFlags(WDestructiveClose); QVBoxLayout *lay = new QVBoxLayout(this); boxSend = new QVGroupBox(this); lay->addWidget(boxSend); QFrame *frmHead = new QFrame(boxSend); QHBoxLayout *hLay = new QHBoxLayout(frmHead); btnBgColor = new CPushButton(frmHead); btnBgColor->setTip(i18n("Background color")); btnBgColor->setPixmap(Pict("bgcolor")); connect(btnBgColor, SIGNAL(clicked()), this, SLOT(setMsgBackgroundColor())); btnBgColor->hide(); hLay->addWidget(btnBgColor); btnReply = new QPushButton(i18n("&Reply"), frmHead); btnReply->hide(); hLay->addWidget(btnReply); connect(btnReply, SIGNAL(clicked()), this, SLOT(replyClick())); btnGrant = new QPushButton(i18n("&Grant"), frmHead); btnGrant->hide(); hLay->addWidget(btnGrant); connect(btnGrant, SIGNAL(clicked()), this, SLOT(grantClick())); btnAccept = new QPushButton(i18n("&Accept"), frmHead); btnAccept->hide(); hLay->addWidget(btnAccept); connect(btnAccept, SIGNAL(clicked()), this, SLOT(acceptMessage())); btnFgColor = new CPushButton(frmHead); btnFgColor->setTip(i18n("Text color")); btnFgColor->setPixmap(Pict("fgcolor")); connect(btnFgColor, SIGNAL(clicked()), this, SLOT(setMsgForegroundColor())); hLay->addSpacing(2); btnFgColor->hide(); hLay->addWidget(btnFgColor); btnQuote = new QPushButton(i18n("&Quote"), frmHead); btnQuote->hide(); hLay->addWidget(btnQuote); connect(btnQuote, SIGNAL(clicked()), this, SLOT(quoteClick())); btnRefuse = new QPushButton(i18n("&Refuse"), frmHead); btnRefuse->hide(); hLay->addWidget(btnRefuse); declineMenu = new QPopupMenu(this); connect(btnRefuse, SIGNAL(clicked()), this, SLOT(refuseClick())); connect(declineMenu, SIGNAL(activated(int)), this, SLOT(declineMessage(int))); declineMenu->insertItem(reason_string(DECLINE_WITHOUT_REASON), DECLINE_WITHOUT_REASON); declineMenu->insertItem(reason_string(DECLINE_REASON_BUSY), DECLINE_REASON_BUSY); declineMenu->insertItem(reason_string(DECLINE_REASON_LATER), DECLINE_REASON_LATER); declineMenu->insertItem(reason_string(DECLINE_REASON_INPUT), DECLINE_REASON_INPUT); btnDecline = new QPushButton(i18n("&Decline"), frmHead); btnDecline->hide(); btnDecline->setPopup(declineMenu); hLay->addWidget(btnDecline); btnBold = new CPushButton(frmHead); btnBold->setTip(i18n("Bold")); btnBold->setPixmap(Pict("text_bold")); btnBold->setToggleButton(true); connect(btnBold, SIGNAL(toggled(bool)), this, SLOT(setBold(bool))); hLay->addSpacing(2); btnBold->hide(); hLay->addWidget(btnBold); btnForward = new QPushButton(i18n("&Forward"), frmHead); connect(btnForward, SIGNAL(clicked()), this, SLOT(forwardClick())); btnForward->hide(); hLay->addWidget(btnForward); btnItalic = new CPushButton(frmHead); btnItalic->setTip(i18n("Italic")); btnItalic->setPixmap(Pict("text_italic")); btnItalic->setToggleButton(true); connect(btnItalic, SIGNAL(toggled(bool)), this, SLOT(setItalic(bool))); hLay->addSpacing(2); btnItalic->hide(); hLay->addWidget(btnItalic); btnUnder = new CPushButton(frmHead); btnUnder->setTip(i18n("Underline")); btnUnder->setPixmap(Pict("text_under")); btnUnder->setToggleButton(true); connect(btnUnder, SIGNAL(toggled(bool)), this, SLOT(setUnder(bool))); hLay->addSpacing(2); btnUnder->hide(); hLay->addWidget(btnUnder); btnFont = new CPushButton(frmHead); btnFont->setTip(i18n("Text font")); btnFont->setPixmap(Pict("text")); connect(btnFont, SIGNAL(clicked()), this, SLOT(setFont())); hLay->addSpacing(2); btnFont->hide(); hLay->addWidget(btnFont); #ifdef USE_SPELL btnSpell = new CPushButton(frmHead); btnSpell->setTip(i18n("Spell check")); btnSpell->setPixmap(Pict("spellcheck")); connect(btnSpell, SIGNAL(clicked()), this, SLOT(spell())); hLay->addSpacing(2); btnSpell->hide(); hLay->addWidget(btnSpell); #endif hLay->addSpacing(2); hLay->addStretch(); chkClose = new QCheckBox(i18n("C&lose after send"), frmHead); chkClose->setChecked(pMain->CloseAfterSend()); connect(chkClose, SIGNAL(toggled(bool)), this, SLOT(closeToggle(bool))); hLay->addWidget(chkClose); btnSend = new QPushButton(frmHead); connect(btnSend, SIGNAL(clicked()), this, SLOT(sendClick())); hLay->addWidget(btnSend); btnNext = new PictPushButton(frmHead); connect(btnNext, SIGNAL(clicked()), this, SLOT(nextClick())); btnNext->hide(); hLay->addWidget(btnNext); phone = new QFrame(boxSend); phone->hide(); QHBoxLayout *hlay = new QHBoxLayout(phone); QLabel *title = new QLabel(i18n("Phone:"), phone); hlay->addWidget(title); phoneEdit = new QComboBox(phone); phoneEdit->setEditable(true); phoneEdit->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed)); hlay->addWidget(phoneEdit); connect(phoneEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&))); url = new QFrame(boxSend); url->hide(); hlay = new QHBoxLayout(url); title = new QLabel(i18n("URL:"), url); hlay->addWidget(title); urlEdit = new QLineEdit(url); hlay->addWidget(urlEdit); connect(urlEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&))); file = new QFrame(boxSend); file->hide(); hlay = new QHBoxLayout(file); title = new QLabel(i18n("File:"), file); hlay->addWidget(title); fileEdit = new EditFile(file); hlay->addWidget(fileEdit); connect(fileEdit, SIGNAL(textChanged(const QString&)), this, SLOT(textChanged(const QString&))); btnMultiply = new CPushButton(frmHead); btnMultiply->setTip(i18n("Multiply send")); btnMultiply->setPixmap(Pict("1rightarrow")); connect(btnMultiply, SIGNAL(clicked()), this, SLOT(toggleMultiply())); hLay->addSpacing(2); hLay->addWidget(btnMultiply); lblUsers = new QLabel(i18n("Drag users here"), boxSend); edit = new EditSpell(this); edit->hide(); lay->addWidget(edit); users = new UserTbl(this); users->hide(); lay->addWidget(users); view = new TextShow(this); view->hide(); lay->addWidget(view); connect(edit, SIGNAL(textChanged()), this, SLOT(editTextChanged())); connect(edit, SIGNAL(currentFontChanged(const QFont&)), this, SLOT(editFontChanged(const QFont&))); connect(edit, SIGNAL(ctrlEnterPressed()), this, SLOT(sendClick())); connect(users, SIGNAL(changed()), this, SLOT(textChanged())); connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*))); connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*))); connect(pMain, SIGNAL(chatChanged()), this, SLOT(chatChanged())); connect(pMain, SIGNAL(ftChanged()), this, SLOT(ftChanged())); setState(); setUin(uin); }