ImapMailbox *ImapPrivate::parseMessages (ImapMailbox *mailbox) { QByteArray response; while (true) { // Read Message response.clear(); do { if (response.size() > 0) { response.remove(response.lastIndexOf('}'), response.size() - response.lastIndexOf('{')); } response.append(readLine()); } while (isMultiline(response)); // Break if End Response Found. if (isResponseEnd(response)) break; // Parse and Add Message to Mailbox ImapMessage *message = _imapParseMessage(response.trimmed()); if (message != NULL) mailbox->addMessage(message); } return(mailbox); }
void TextEditComponent::onCursorChanged() { if(isMultiline()) { Vector2f textSize = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor); if(mScrollOffset.y() + getTextAreaSize().y() < textSize.y() + mFont->getHeight()) //need to scroll down? { mScrollOffset[1] = textSize.y() - getTextAreaSize().y() + mFont->getHeight(); }else if(mScrollOffset.y() > textSize.y()) //need to scroll up? { mScrollOffset[1] = textSize.y(); } }else{ Vector2f cursorPos = mFont->sizeText(mText.substr(0, mCursor)); if(mScrollOffset.x() + getTextAreaSize().x() < cursorPos.x()) { mScrollOffset[0] = cursorPos.x() - getTextAreaSize().x(); }else if(mScrollOffset.x() > cursorPos.x()) { mScrollOffset[0] = cursorPos.x(); } } }
QMenu *CodeLineEdit::createResourcesMenu(QMenu *parentMenu, bool ignoreMultiline) { QMenu *resourceMenu = 0; if(!ignoreMultiline && isMultiline()) { resourceMenu = new QMenu(tr("Cannot insert in a multiline parameter"), parentMenu); resourceMenu->setEnabled(false); } else { Q_ASSERT(mParameterContainer); resourceMenu = mParameterContainer->createResourcesMenu(parentMenu); if(resourceMenu) resourceMenu->setTitle(tr("Insert resource")); else { resourceMenu = new QMenu(tr("No resources to insert"), parentMenu); resourceMenu->setEnabled(false); } } resourceMenu->setIcon(QIcon(":/images/resource.png")); return resourceMenu; }
QMenu *CodeLineEdit::createVariablesMenu(QMenu *parentMenu, bool ignoreMultiline) { QMenu *variablesMenu = 0; if(!ignoreMultiline && isMultiline()) { variablesMenu = new QMenu(tr("Cannot insert in a multiline parameter"), parentMenu); variablesMenu->setEnabled(false); } else { Q_ASSERT(mParameterContainer); variablesMenu = mParameterContainer->createVariablesMenu(parentMenu); if(variablesMenu) { variablesMenu->setTitle(tr("Insert variable")); } else { variablesMenu = new QMenu(tr("No variables to insert"), parentMenu); variablesMenu->setEnabled(false); } } variablesMenu->setIcon(QIcon(":/images/variable.png")); return variablesMenu; }
void TextEditComponent::onTextChanged() { std::string wrappedText = (isMultiline() ? mFont->wrapText(mText, getTextAreaSize().x()) : mText); mTextCache = std::unique_ptr<TextCache>(mFont->buildTextCache(wrappedText, 0, 0, 0x77777700 | getOpacity())); if(mCursor > (int)mText.length()) mCursor = (unsigned int)mText.length(); }
bool TextEditComponent::input(InputConfig* config, Input input) { if(input.value == 0) { if(config->isMappedTo("left", input) || config->isMappedTo("right", input)) mCursorRepeatDir = 0; return false; } if(config->isMappedTo("b", input) && mFocused && !mEditing) { startEditing(); return true; } if(mEditing) { if(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_RETURN) { if(isMultiline()) { textInput("\n"); }else{ stopEditing(); } return true; } if((config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_ESCAPE) || (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("a", input))) { stopEditing(); return true; } if(config->isMappedTo("up", input)) { // TODO }else if(config->isMappedTo("down", input)) { // TODO }else if(config->isMappedTo("left", input) || config->isMappedTo("right", input)) { mCursorRepeatDir = config->isMappedTo("left", input) ? -1 : 1; mCursorRepeatTimer = -(CURSOR_REPEAT_START_DELAY - CURSOR_REPEAT_SPEED); moveCursor(mCursorRepeatDir); } //consume all input when editing text return true; } return false; }
void TextEditComponent::render(const Transform4x4f& parentTrans) { Transform4x4f trans = getTransform() * parentTrans; renderChildren(trans); // text + cursor rendering // offset into our "text area" (padding) trans.translation() += Vector3f(getTextAreaPos().x(), getTextAreaPos().y(), 0); Vector2i clipPos((int)trans.translation().x(), (int)trans.translation().y()); Vector3f dimScaled = trans * Vector3f(getTextAreaSize().x(), getTextAreaSize().y(), 0); // use "text area" size for clipping Vector2i clipDim((int)(dimScaled.x() - trans.translation().x()), (int)(dimScaled.y() - trans.translation().y())); Renderer::pushClipRect(clipPos, clipDim); trans.translate(Vector3f(-mScrollOffset.x(), -mScrollOffset.y(), 0)); trans.round(); Renderer::setMatrix(trans); if(mTextCache) { mFont->renderTextCache(mTextCache.get()); } // pop the clip early to allow the cursor to be drawn outside of the "text area" Renderer::popClipRect(); // draw cursor if(mEditing) { Vector2f cursorPos; if(isMultiline()) { cursorPos = mFont->getWrappedTextCursorOffset(mText, getTextAreaSize().x(), mCursor); }else{ cursorPos = mFont->sizeText(mText.substr(0, mCursor)); cursorPos[1] = 0; } float cursorHeight = mFont->getHeight() * 0.8f; Renderer::drawRect(cursorPos.x(), cursorPos.y() + (mFont->getHeight() - cursorHeight) / 2, 2.0f, cursorHeight, 0x000000FF); } }
bool TextEditComponent::input(InputConfig* config, Input input) { bool const cursor_left = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("left", input)) || (config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_LEFT); bool const cursor_right = (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("right", input)) || (config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_RIGHT); if(input.value == 0) { if(cursor_left || cursor_right) mCursorRepeatDir = 0; return false; } if((config->isMappedTo("a", input) || (config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_RETURN)) && mFocused && !mEditing) { startEditing(); return true; } if(mEditing) { if(config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_RETURN) { if(isMultiline()) { textInput("\n"); }else{ stopEditing(); } return true; } if((config->getDeviceId() == DEVICE_KEYBOARD && input.id == SDLK_ESCAPE) || (config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedTo("b", input))) { stopEditing(); return true; } if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("up", input)) { // TODO }else if(config->getDeviceId() != DEVICE_KEYBOARD && config->isMappedLike("down", input)) { // TODO }else if(cursor_left || cursor_right) { mCursorRepeatDir = cursor_left ? -1 : 1; mCursorRepeatTimer = -(CURSOR_REPEAT_START_DELAY - CURSOR_REPEAT_SPEED); moveCursor(mCursorRepeatDir); } else if(config->getDeviceId() == DEVICE_KEYBOARD) { switch(input.id) { case SDLK_HOME: setCursor(0); break; case SDLK_END: setCursor(std::string::npos); break; case SDLK_DELETE: if(mCursor < mText.length()) { // Fake as Backspace one char to the right moveCursor(1); textInput("\b"); } break; } } //consume all input when editing text return true; } return false; }