Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 11359 → Rev 11360

/trunk/Scribus/scribus/story.cpp
81,6 → 81,23
#include "util.h"
#include "util_icon.h"
 
class StyledTextMimeData : public QMimeData
{
protected:
StoryText m_styledText;
 
public:
const StoryText& styledText(void) const { return m_styledText; }
void setStyledText(const StoryText& text)
{
QByteArray styledTextData (sizeof(void*), 0);
m_styledText.clear();
m_styledText.insert(0, text, true);
styledTextData.setNum((quintptr)((quintptr*) &m_styledText));
setData("scribus/se-styled-text", styledTextData);
};
};
 
SideBar::SideBar(QWidget *pa) : QLabel(pa)
{
QPalette pal;
204,7 → 221,6
SelCharStart = 0;
SelParaStart = 0;
StyledText.clear();
cBuffer.clear();
document()->setUndoRedoEnabled(true);
viewport()->setAcceptDrops(false);
ClipData = 0;
287,9 → 303,6
emit SideBarUp(true);
return;
break;
case Qt::Key_C:
copyStyledText();
break;
}
}
if ((k->modifiers() == Qt::NoModifier) ||
449,27 → 462,16
StyledText.insertChars(pos, t, true);
}
 
void SEditor::insStyledText()
void SEditor::insStyledText(const StoryText& styledText)
{
if (cBuffer.length() == 0)
if (styledText.length() == 0)
return;
if (textCursor().hasSelection())
deleteSel();
int pos = qMin(textCursor().position(), StyledText.length());
StyledText.insert(pos, cBuffer);
StyledText.insert(pos, styledText);
}
 
void SEditor::copyStyledText()
{
int start = textCursor().selectionStart();
int end = textCursor().selectionEnd();
if (start < 0 || end <= start)
return;
StyledText.select(start, end-start);
cBuffer.clear();
cBuffer.insert(0, StyledText, true);
}
 
void SEditor::saveItemText(PageItem *currItem)
{
currItem->CPos = 0;
781,12 → 783,9
if ((textCursor().hasSelection()) && (!textCursor().selectedText().isEmpty()))
{
disconnect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
// disconnect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(SelClipChange()));
copyStyledText();
QApplication::clipboard()->setText(tBuffer, QClipboard::Clipboard);
ClipData = 1;
QMimeData* mimeData = createMimeDataFromSelection();
QApplication::clipboard()->setMimeData(mimeData, QClipboard::Clipboard);
connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(ClipChange()));
// connect(QApplication::clipboard(), SIGNAL(selectionChanged()), this, SLOT(SelClipChange()));
emit PasteAvail();
}
emit SideBarUp(true);
808,17 → 807,20
void SEditor::paste()
{
emit SideBarUp(false);
// int currentPara, currentCharPos;
QString data = "";
int newParaCount, lengthLastPara;
int advanceLen = 0;
// bool inserted=false;
// getCursorPosition(&currentPara, &currentCharPos);
int pos = textCursor().position();
if (ClipData == 1)
const QMimeData* mimeData = QApplication::clipboard()->mimeData(QClipboard::Clipboard);
if (mimeData->hasFormat("scribus/se-styled-text"))
{
advanceLen = cBuffer.length();
insStyledText();
const StyledTextMimeData* styledData = dynamic_cast<const StyledTextMimeData*>(mimeData);
if (mimeData)
{
const StoryText& styledText = styledData->styledText();
advanceLen = styledText.length();
insStyledText(styledText);
}
}
else
{
825,7 → 827,7
// QString data = QApplication::clipboard()->text(QClipboard::Selection);
// if (data.isNull())
data = QApplication::clipboard()->text(QClipboard::Clipboard);
if (!data.isNull())
if (!data.isEmpty())
{
data.replace(QRegExp("\r"), "");
newParaCount=data.count("\n");
859,6 → 861,33
emit SideBarUp(true);
emit SideBarUpdate();
}
 
bool SEditor::canInsertFromMimeData( const QMimeData * source ) const
{
if (source->hasText() || source->hasFormat("scribus/se-styled-text"))
return true;
return false;
}
 
QMimeData* SEditor::createMimeDataFromSelection () const
{
StyledTextMimeData* mimeData = new StyledTextMimeData();
int start = textCursor().selectionStart();
int end = textCursor().selectionEnd();
if (start < 0 || end <= start)
return mimeData;
StoryText* that = const_cast<StoryText*> (&StyledText);
that->select(start, end-start);
mimeData->setText(textCursor().selectedText());
mimeData->setStyledText(*that);
return mimeData;
}
 
void SEditor::insertFromMimeData ( const QMimeData * source )
{
paste();
}
 
/*
Q_3PopupMenu* SEditor::createPopupMenu(const QPoint & pos)
{
/trunk/Scribus/scribus/story.h
77,7 → 77,6
class ColorCombo;
class CharSelect;
 
 
class SCRIBUS_API SEditor : public QTextEdit
{
Q_OBJECT
98,8 → 97,7
void setStyle(int Csty);
void setColor(bool marker);
void insChars(QString t);
void insStyledText();
void copyStyledText();
void insStyledText(const StoryText& styledText);
 
StoryText StyledText;
QList<PageItem*> FrameItems;
131,7 → 129,6
QString CurrFont;
QString unicodeInputString;
QString tBuffer;
StoryText cBuffer;
int ClipData;
bool StoredSel;
int SelParaStart;
145,6 → 142,9
void focusOutEvent(QFocusEvent *e);
void focusInEvent(QFocusEvent *e);
void scrollContentsBy(int dx, int dy);
virtual bool canInsertFromMimeData( const QMimeData * source ) const;
virtual QMimeData * createMimeDataFromSelection () const;
virtual void insertFromMimeData ( const QMimeData * source );
// Q3PopupMenu* createPopupMenu(const QPoint & pos);
StoryEditor* parentStoryEditor;