// public static int kpTextSelection::PreferredMinimumHeightForTextStyle (const kpTextStyle &textStyle) { const int preferredMinHeight = kpTextSelection::TextBorderSize () * 2 + textStyle.fontMetrics ().height (); return qMax (kpTextSelection::MinimumHeightForTextStyle (textStyle), qMin (150, preferredMinHeight)); }
// public static int kpTextSelection::PreferredMinimumWidthForTextStyle (const kpTextStyle &textStyle) { const int about15CharsWidth = textStyle.fontMetrics ().width ( QLatin1String ("1234567890abcde")); const int preferredMinWidth = qMax (150, kpTextSelection::TextBorderSize () * 2 + about15CharsWidth); return qMax (kpTextSelection::MinimumWidthForTextStyle (textStyle), qMin (250, preferredMinWidth)); }
// public void kpMainWindow::pasteText (const QString &text, bool forceNewTextSelection, const QPoint &newTextSelectionTopLeft) { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "kpMainWindow::pasteText(" << text << ",forceNewTextSelection=" << forceNewTextSelection << ",newTextSelectionTopLeft=" << newTextSelectionTopLeft << ")" << endl; #endif if (text.isEmpty ()) return; // sync: restoreOverrideCursor() in all exit paths QApplication::setOverrideCursor (Qt::waitCursor); if (toolHasBegunShape ()) tool ()->endShapeInternal (); QValueVector <QString> textLines (1, QString::null); for (int i = 0; i < (int) text.length (); i++) { if (text [i] == '\n') textLines.push_back (QString::null); else textLines [textLines.size () - 1].append (text [i]); } if (!forceNewTextSelection && m_document && m_document->selection () && m_document->selection ()->isText () && m_commandHistory && m_viewManager) { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "\treusing existing Text Selection" << endl; #endif kpMacroCommand *macroCmd = new kpMacroCommand (i18n ("Text: Paste"), this); for (int i = 0; i < (int) textLines.size (); i++) { if (i > 0) { macroCmd->addCommand ( new kpToolTextEnterCommand ( QString::null/*uninteresting child of macroCmd*/, m_viewManager->textCursorRow (), m_viewManager->textCursorCol (), this)); } macroCmd->addCommand ( new kpToolTextInsertCommand ( QString::null/*uninteresting child of macroCmd*/, m_viewManager->textCursorRow (), m_viewManager->textCursorCol (), textLines [i], this)); } m_commandHistory->addCommand (macroCmd, false/*no exec*/); } else { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "\tcreating Text Selection" << endl; #endif const kpTextStyle ts = textStyle (); const QFontMetrics fontMetrics = ts.fontMetrics (); int height = textLines.size () * fontMetrics.height (); if (textLines.size () >= 1) height += (textLines.size () - 1) * fontMetrics.leading (); int width = 0; for (QValueVector <QString>::const_iterator it = textLines.begin (); it != textLines.end (); it++) { const int w = fontMetrics.width (*it); if (w > width) width = w; } const int selWidth = QMAX (kpSelection::minimumWidthForTextStyle (ts), width + kpSelection::textBorderSize () * 2); const int selHeight = QMAX (kpSelection::minimumHeightForTextStyle (ts), height + kpSelection::textBorderSize () * 2); kpSelection sel (QRect (0, 0, selWidth, selHeight), textLines, ts); if (newTextSelectionTopLeft != KP_INVALID_POINT) { sel.moveTo (newTextSelectionTopLeft); paste (sel, true/*force topLeft*/); } else { paste (sel); } } QApplication::restoreOverrideCursor (); }